diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java new file mode 100644 index 0000000..df1f0e8 --- /dev/null +++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/AlgorithmInfoController.java @@ -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 getById(@PathVariable Long id) { + AlgorithmInfo algorithmInfo = algorithmInfoService.getById(id); + return algorithmInfo != null ? + ResponseEntity.ok(algorithmInfo) : + ResponseEntity.notFound().build(); + } + + @GetMapping("/name/{algorithmName}") + public ResponseEntity getByName(@PathVariable String algorithmName) { + AlgorithmInfo algorithmInfo = algorithmInfoService.getByName(algorithmName); + return algorithmInfo != null ? + ResponseEntity.ok(algorithmInfo) : + ResponseEntity.notFound().build(); + } + + @GetMapping("/type/{algorithmType}") + public ResponseEntity> getByType(@PathVariable String algorithmType) { + List algorithmInfos = algorithmInfoService.getByType(algorithmType); + return ResponseEntity.ok(algorithmInfos); + } + + @PutMapping("/{id}") + public ResponseEntity 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 delete(@PathVariable Long id) { + boolean success = algorithmInfoService.delete(id); + return success ? + ResponseEntity.ok("Delete successful") : + ResponseEntity.badRequest().body("Delete failed"); + } +} \ No newline at end of file diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/mapper/AlgorithmInfoMapper.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/mapper/AlgorithmInfoMapper.java new file mode 100644 index 0000000..0faf44e --- /dev/null +++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/mapper/AlgorithmInfoMapper.java @@ -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 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); +} \ No newline at end of file diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/pojo/AlgorithmInfo.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/pojo/AlgorithmInfo.java new file mode 100644 index 0000000..49e0d5e --- /dev/null +++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/pojo/AlgorithmInfo.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/AlgorithmInfoService.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/AlgorithmInfoService.java new file mode 100644 index 0000000..e7d73d1 --- /dev/null +++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/AlgorithmInfoService.java @@ -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 getByType(String algorithmType); + boolean update(AlgorithmInfo algorithmInfo); + boolean delete(Long id); + boolean validateAlgorithmInfo(AlgorithmInfo algorithmInfo); +} \ No newline at end of file diff --git a/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/Impl/AlgorithmInfoServiceImpl.java b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/Impl/AlgorithmInfoServiceImpl.java new file mode 100644 index 0000000..a16a117 --- /dev/null +++ b/src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/Impl/AlgorithmInfoServiceImpl.java @@ -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 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; + } +} \ No newline at end of file