Compare commits

...

2 Commits

Author SHA1 Message Date
lpz
c13ff70f6b Merge pull request '算法生命周期管理' (#10) from my-feature-one into main
Reviewed-on: #10
2025-05-18 14:46:11 +08:00
84b9711c57 生命周期 2025-05-16 23:21:04 +08:00
5 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,60 @@
package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/algorithm")
public class AlgorithmInfoController {
@Autowired
private AlgorithmInfoService algorithmInfoService;
@GetMapping("/{id}")
public ResponseEntity<AlgorithmInfo> getById(@PathVariable Long id) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id);
return algorithmInfo != null ?
ResponseEntity.ok(algorithmInfo) :
ResponseEntity.notFound().build();
}
@GetMapping("/name/{algorithmName}")
public ResponseEntity<AlgorithmInfo> getByName(@PathVariable String algorithmName) {
AlgorithmInfo algorithmInfo = algorithmInfoService.getByName(algorithmName);
return algorithmInfo != null ?
ResponseEntity.ok(algorithmInfo) :
ResponseEntity.notFound().build();
}
@GetMapping("/type/{algorithmType}")
public ResponseEntity<List<AlgorithmInfo>> getByType(@PathVariable String algorithmType) {
List<AlgorithmInfo> algorithmInfos = algorithmInfoService.getByType(algorithmType);
return ResponseEntity.ok(algorithmInfos);
}
@PutMapping("/{id}")
public ResponseEntity<String> update(@PathVariable Long id, @RequestBody AlgorithmInfo algorithmInfo) {
algorithmInfo.setId(id);
if (!algorithmInfoService.validateAlgorithmInfo(algorithmInfo)) {
return ResponseEntity.badRequest().body("Invalid algorithm information");
}
boolean success = algorithmInfoService.update(algorithmInfo);
return success ?
ResponseEntity.ok("Update successful") :
ResponseEntity.badRequest().body("Update failed");
}
@DeleteMapping("/{id}")
public ResponseEntity<String> delete(@PathVariable Long id) {
boolean success = algorithmInfoService.delete(id);
return success ?
ResponseEntity.ok("Delete successful") :
ResponseEntity.badRequest().body("Delete failed");
}
}

View File

@ -0,0 +1,32 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface AlgorithmInfoMapper {
@Select("SELECT * FROM algorithm_info WHERE id = #{id}")
AlgorithmInfo selectById(Long id);
@Select("SELECT * FROM algorithm_info WHERE algorithm_name = #{algorithmName}")
AlgorithmInfo selectByName(String algorithmName);
@Select("SELECT * FROM algorithm_info WHERE algorithm_type = #{algorithmType}")
List<AlgorithmInfo> selectByType(String algorithmType);
@Insert("INSERT INTO algorithm_info(algorithm_name, algorithm_file, algorithm_type, description, created_by, file_size) " +
"VALUES(#{algorithmName}, #{algorithmFile}, #{algorithmType}, #{description}, #{createdBy}, #{fileSize})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int insert(AlgorithmInfo algorithmInfo);
@Update("UPDATE algorithm_info SET algorithm_name = #{algorithmName}, algorithm_file = #{algorithmFile}, " +
"algorithm_type = #{algorithmType}, description = #{description}, file_size = #{fileSize} " +
"WHERE id = #{id}")
int update(AlgorithmInfo algorithmInfo);
@Delete("DELETE FROM algorithm_info WHERE id = #{id}")
int deleteById(Long id);
}

View File

@ -0,0 +1,78 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import java.time.LocalDateTime;
public class AlgorithmInfo {
private Long id;
private String algorithmName;
private String algorithmFile;
private String algorithmType;
private String description;
private String createdBy;
private LocalDateTime createTime;
private Long fileSize;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getAlgorithmName() {
return algorithmName;
}
public void setAlgorithmName(String algorithmName) {
this.algorithmName = algorithmName;
}
public String getAlgorithmFile() {
return algorithmFile;
}
public void setAlgorithmFile(String algorithmFile) {
this.algorithmFile = algorithmFile;
}
public String getAlgorithmType() {
return algorithmType;
}
public void setAlgorithmType(String algorithmType) {
this.algorithmType = algorithmType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
}

View File

@ -0,0 +1,14 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import java.util.List;
public interface AlgorithmInfoService {
AlgorithmInfo getById(Long id);
AlgorithmInfo getByName(String algorithmName);
List<AlgorithmInfo> getByType(String algorithmType);
boolean update(AlgorithmInfo algorithmInfo);
boolean delete(Long id);
boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo);
}

View File

@ -0,0 +1,63 @@
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.mapper.AlgorithmInfoMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.AlgorithmInfo;
import com.bipt.intelligentapplicationorchestrationservice.service.AlgorithmInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
@Service
public class AlgorithmInfoServiceImpl implements AlgorithmInfoService {
@Autowired
private AlgorithmInfoMapper algorithmInfoMapper;
@Override
public AlgorithmInfo getById(Long id) {
return algorithmInfoMapper.selectById(id);
}
@Override
public AlgorithmInfo getByName(String algorithmName) {
return algorithmInfoMapper.selectByName(algorithmName);
}
@Override
public List<AlgorithmInfo> getByType(String algorithmType) {
return algorithmInfoMapper.selectByType(algorithmType);
}
@Override
@Transactional
public boolean update(AlgorithmInfo algorithmInfo) {
if (!validateAlgorithmInfo(algorithmInfo)) {
return false;
}
return algorithmInfoMapper.update(algorithmInfo) > 0;
}
@Override
@Transactional
public boolean delete(Long id) {
return algorithmInfoMapper.deleteById(id) > 0;
}
@Override
public boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo) {
if (algorithmInfo == null) {
return false;
}
if (!StringUtils.hasText(algorithmInfo.getAlgorithmName()) ||
!StringUtils.hasText(algorithmInfo.getAlgorithmFile()) ||
!StringUtils.hasText(algorithmInfo.getAlgorithmType())) {
return false;
}
return true;
}
}