数据集生命周期版本2.0

This commit is contained in:
2025-05-15 23:02:53 +08:00
parent 64abd2d824
commit e096b52c7b
16 changed files with 207 additions and 57 deletions

View File

@ -11,3 +11,16 @@
### 📅 明日计划 ### 📅 明日计划
写完删除代码,进行测试 写完删除代码,进行测试
## 2025年5月15日
### ✅ 今日完成
完成删除数据集增加数据集,部分测试
### 🚧 进行中
测试(或添加具体异常处理)
### ⚠️ 问题/障碍
暂无
### 📅 明日计划
测试完毕,开下一个模块

View File

@ -57,8 +57,14 @@
<artifactId>pagehelper-spring-boot-starter</artifactId> <artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version> <version>1.4.7</version>
</dependency> </dependency>
<!--swagger相关依赖生成接口文档-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version> <!-- 最新稳定版 -->
</dependency>
KingbaseES V8/V9 数据库 JDBC 驱动 <!--KingbaseES V8/V9 数据库 JDBC 驱动-->
<dependency> <dependency>
<groupId>com.kingbase8</groupId> <groupId>com.kingbase8</groupId>
<artifactId>kingbase8</artifactId> <artifactId>kingbase8</artifactId>

View File

@ -1,15 +1,20 @@
package com.bipt.intelligentapplicationorchestrationservice; package com.bipt.intelligentapplicationorchestrationservice;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@MapperScan("com.bipt.intelligentapplicationorchestrationservice.mapper")//指定扫描Mapper接口的包 @MapperScan("com.bipt.intelligentapplicationorchestrationservice.mapper")//指定扫描Mapper接口的包
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement
@Slf4j
public class IntelligentApplicationOrchestrationServiceApplication { public class IntelligentApplicationOrchestrationServiceApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(IntelligentApplicationOrchestrationServiceApplication.class, args); SpringApplication.run(IntelligentApplicationOrchestrationServiceApplication.class, args);
log.info("server started");
} }
} }

View File

@ -0,0 +1,47 @@
package com.bipt.intelligentapplicationorchestrationservice.config;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.ArrayList;
import java.util.List;
/**
* 配置类注册web层相关组件
*/
@Configuration
@Slf4j
public class WebMvcConfiguration{
/**
* 配置OpenAPI信息
*/
@Bean
public OpenAPI customOpenAPI() {
// 设置服务器信息(可选)
List<Server> servers = new ArrayList<>();
servers.add(new Server().url("/").description("本地服务器"));
return new OpenAPI()
.info(new Info()
.title("智能应用服务管理")
.version("2.0")
.description("智能应用服务管理接口文档"))
.servers(servers);
}
// /**
// * 设置静态资源映射Springdoc不需要特殊配置保留可能的其他资源映射
// */
// @Override
// protected void addResourceHandlers(ResourceHandlerRegistry registry) {
// // 保留其他静态资源映射(如果有)
// // registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
// }
}

View File

@ -0,0 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.constant;
public class MessageConstant {
public static final String UNKNOWN_ERROR = "未知错误";
public static final String ALREADY_EXISTS = "数据集已存在";
}

View File

@ -2,7 +2,6 @@ package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*; import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.DatasetService; import com.bipt.intelligentapplicationorchestrationservice.service.DatasetService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -28,6 +27,11 @@ public class DatasetController {
return OptResult.success(); return OptResult.success();
} }
/**
* 分页查询
* @param dataSetPageQueryDTO
* @return
*/
@GetMapping("/page") @GetMapping("/page")
public OptResult<PageResult> page(DatasetPageQueryDTO dataSetPageQueryDTO) { public OptResult<PageResult> page(DatasetPageQueryDTO dataSetPageQueryDTO) {
log.info("数据集分页查询:{}", dataSetPageQueryDTO); log.info("数据集分页查询:{}", dataSetPageQueryDTO);
@ -38,32 +42,28 @@ public class DatasetController {
/** /**
* 修改数据集 * 修改数据集
* @param datasetEntity * @param datasetDTO
* @return * @return
*/ */
@PutMapping @PutMapping
public OptResult update(@RequestBody DatasetEntity datasetEntity){ public OptResult update(@RequestBody DatasetDTO datasetDTO){
log.info("修改数据集",datasetEntity); log.info("修改数据集",datasetDTO);
datasetService.update(datasetEntity); datasetService.update(datasetDTO);
return OptResult.success(); return OptResult.success();
} }
/** /**
* 批量删除数据集 * 批量删除数据集
* @param datasetIds 数据集ID列表 * @param datasetIds 数据集ID列表
* @return 操作结果 * @return 操作结果
*/ */
@DeleteMapping @DeleteMapping
public OptResult<String> deleteBatch(@RequestBody List<Integer> datasetIds) { public OptResult<String> deleteBatch(@RequestBody List<Long> datasetIds) {
log.info("批量删除数据集ID列表{}", datasetIds); log.info("批量删除数据集ID列表{}", datasetIds);
datasetService.deleteBatch(datasetIds); datasetService.deleteBatch(datasetIds);
return OptResult.success("批量删除成功"); return OptResult.success("批量删除成功");
} }
} }

View File

@ -0,0 +1,34 @@
package com.bipt.intelligentapplicationorchestrationservice.handler;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.sql.SQLIntegrityConstraintViolationException;
/**
* 全局异常处理器,处理项目中抛出的业务异常
*/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
/*
* 捕获SQL异常
* */
@ExceptionHandler
public OptResult exceptionHandler(SQLIntegrityConstraintViolationException ex){
String message = ex.getMessage();
if(message.contains("Duplicate entry")) {
String[] split = message.split(" ");
String username = split[2];
String msg = username + MessageConstant.ALREADY_EXISTS;
return OptResult.error(msg);
}else {
return OptResult.error(MessageConstant.UNKNOWN_ERROR);
}
}
}

View File

@ -7,7 +7,6 @@ import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
public interface DatasetMapper { public interface DatasetMapper {
@ -19,7 +18,7 @@ public interface DatasetMapper {
Page<DatasetVO> pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO); Page<DatasetVO> pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO);
@Select("select * from dataset where dataset_id=#{datasetId}") @Select("select * from dataset where dataset_id=#{datasetId}")
DatasetEntity getById(Integer datasetId); DatasetEntity getById(Long datasetId);
@Delete("delete from dataset where dataset_id = #{datasetId}")
void deleteBatch(List<Integer> datasetIds); void deleteBatch(@Param("datasetIds") List<Long> datasetIds);
} }

View File

@ -1,6 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.Map;
@ -9,9 +12,14 @@ import java.util.Map;
* @author hky * @author hky
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatasetDTO implements Serializable { public class DatasetDTO implements Serializable {
private Integer datasetId; private Long datasetId;
private String datasetName; private String datasetName;
private Integer datasetType; private int datasetType;
private Map<String,String> args; private String dsPath;
// private Map<String,String> args;
private String args;
} }

View File

@ -17,12 +17,13 @@ import java.util.Map;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class DatasetEntity implements Serializable { public class DatasetEntity implements Serializable {
private Integer datasetId; private Long datasetId;
private String datasetName; private String datasetName;
private Integer datasetType; private int datasetType;
private Integer datasetStatus; private int datasetStatus;
private String dsPath; private String dsPath;
private Map<String,String> args; // private Map<String,String> args;
private String args;
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;
} }

View File

@ -1,6 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -10,9 +13,18 @@ import java.util.Map;
* @author hky * @author hky
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatasetPageQueryDTO implements Serializable{ public class DatasetPageQueryDTO implements Serializable{
private int page; private int page;
private int pageSize; private int pageSize;
private Integer datasetType; private String datasetName;
private Integer datasetStatus; private int datasetType;
private int datasetStatus;
private String dsPath;
private String args;
private LocalDateTime createTime;
private LocalDateTime updateTime;
} }

View File

@ -1,5 +1,10 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo; package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
@ -7,12 +12,17 @@ import java.util.Map;
/** /**
* @author hky * @author hky
*/ */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DatasetVO implements Serializable { public class DatasetVO implements Serializable {
private String datasetName; private String datasetName;
private Integer datasetType; private Integer datasetType;
private Integer datasetStatus; private Integer datasetStatus;
private String dsPath; private String dsPath;
private Map<String,String> args; // private Map<String,String> args;
private String args;
private LocalDateTime createTime; private LocalDateTime createTime;
private LocalDateTime updateTime; private LocalDateTime updateTime;
} }

View File

@ -4,16 +4,17 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List; import java.util.List;
/** /**
* 分页 * 分页
* @param <T>
*/ */
@Data @Data
@NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class PageResult<T> { @NoArgsConstructor
private Long total; public class PageResult implements Serializable {
private List<T> rows; private long total;
private List records;
} }

View File

@ -1,7 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetEntity;
import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetPageQueryDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetPageQueryDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.PageResult; import com.bipt.intelligentapplicationorchestrationservice.pojo.PageResult;
@ -13,9 +12,9 @@ import java.util.List;
public interface DatasetService { public interface DatasetService {
void save(DatasetDTO datasetDTO); void save(DatasetDTO datasetDTO);
void update(DatasetEntity datasetEntity); void update(DatasetDTO datasetDTO);
PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO); PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO);
void deleteBatch(List<Integer> datasetIds); void deleteBatch(List<Long> datasetIds);
} }

View File

@ -12,8 +12,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
@ -26,20 +26,22 @@ public class DatasetServiceImpl implements DatasetService {
* @param datasetDTO * @param datasetDTO
*/ */
@Override @Override
@Transactional
public void save(DatasetDTO datasetDTO) { public void save(DatasetDTO datasetDTO) {
//判断数据集类型,如果是本地上传则保存,若用调用数据仓库进入下一步 //判断数据集类型,如果是本地上传则保存,若用调用数据仓库进入下一步
if (datasetDTO.getDatasetType()==0){ if (datasetDTO.getDatasetType()==0){
//TODO 保存到分布式文件系统 //TODO 保存到分布式文件系统
}else { }else {
Map<String,String> args = datasetDTO.getArgs(); // Map<String,String> args = datasetDTO.getArgs();
Integer datasetType = datasetDTO.getDatasetType(); String args = datasetDTO.getArgs();
int datasetType = datasetDTO.getDatasetType();
//TODO 根据筛选条件调用数据仓库中的数据 //TODO 根据筛选条件调用数据仓库中的数据
//TODO 调用数据仓库保存到分布式文件系统 //TODO 调用数据仓库保存到分布式文件系统
} }
DatasetEntity datasetEntity = new DatasetEntity(); DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetEntity,datasetDTO); BeanUtils.copyProperties(datasetDTO,datasetEntity);
datasetEntity.setDatasetStatus(1); datasetEntity.setDatasetStatus(1);
datasetEntity.setCreateTime(LocalDateTime.now()); datasetEntity.setCreateTime(LocalDateTime.now());
datasetEntity.setUpdateTime(LocalDateTime.now()); datasetEntity.setUpdateTime(LocalDateTime.now());
@ -50,12 +52,14 @@ public class DatasetServiceImpl implements DatasetService {
/** /**
* 修改数据集 * 修改数据集
* *
* @param datasetEntity * @param datasetDTO
*/ */
@Override @Override
@Transactional @Transactional
public void update(DatasetEntity datasetEntity) { public void update(DatasetDTO datasetDTO) {
if (datasetEntity.getDatasetType()==0){ /*DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);*/
if (datasetDTO.getDatasetType()==0){
//TODO 覆盖保存到分布式文件系统中 //TODO 覆盖保存到分布式文件系统中
}else { }else {
@ -63,10 +67,13 @@ public class DatasetServiceImpl implements DatasetService {
//TODO //TODO
}
DatasetEntity datasetEntity = new DatasetEntity();
BeanUtils.copyProperties(datasetDTO,datasetEntity);
datasetEntity.setUpdateTime(LocalDateTime.now()); datasetEntity.setUpdateTime(LocalDateTime.now());
datasetMapper.updata(datasetEntity); datasetMapper.updata(datasetEntity);
} }
}
/** /**
* 分页查询 * 分页查询
@ -75,9 +82,7 @@ public class DatasetServiceImpl implements DatasetService {
*/ */
@Override @Override
public PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO) { public PageResult pageQuery(DatasetPageQueryDTO dataSetPageQueryDTO) {
int pageNum = dataSetPageQueryDTO.getPage(); PageHelper.startPage(dataSetPageQueryDTO.getPage(), dataSetPageQueryDTO.getPageSize());
int pageSize = dataSetPageQueryDTO.getPageSize();
PageHelper.startPage(pageNum, pageSize);
Page<DatasetVO> page = datasetMapper.pageQuery(dataSetPageQueryDTO); Page<DatasetVO> page = datasetMapper.pageQuery(dataSetPageQueryDTO);
return new PageResult(page.getTotal(), page.getResult()); return new PageResult(page.getTotal(), page.getResult());
} }
@ -88,16 +93,16 @@ public class DatasetServiceImpl implements DatasetService {
*/ */
@Override @Override
@Transactional @Transactional
public void deleteBatch(List<Integer> datasetIds) { public void deleteBatch(List<Long> datasetIds) {
for (Integer datasetId : datasetIds) { for (Long datasetId : datasetIds) {
DatasetEntity datasetEntity = datasetMapper.getById(datasetId); DatasetEntity datasetEntity = datasetMapper.getById(datasetId);
if (datasetEntity == null) { if (datasetEntity == null) {
throw new IllegalArgumentException("数据集不存在ID" + datasetId); throw new IllegalArgumentException("数据集不存在ID" + datasetId);
} }
} }
//TODO 在分布式文件系统中删除 //TODO 在分布式文件系统中删除
datasetMapper.deleteBatch(datasetIds); datasetMapper.deleteBatch(datasetIds);
} }

View File

@ -25,15 +25,19 @@
<if test="args != null"> <if test="args != null">
args=#{args}, args=#{args},
</if> </if>
<if test="create_time != null"> <if test="updateTime != null">
create_time=#{createTime},
</if>
<if test="update_time != null">
update_time=#{updateTime} update_time=#{updateTime}
</if> </if>
</set> </set>
where dataset_id = #{datasetId} where dataset_id = #{datasetId}
</update> </update>
<delete id="deleteBatch">
DELETE FROM dataset
WHERE dataset_id IN
<foreach collection="datasetIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="pageQuery" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetVO"> <select id="pageQuery" resultType="com.bipt.intelligentapplicationorchestrationservice.pojo.DatasetVO">
SELECT * FROM dataset SELECT * FROM dataset
<where> <where>
@ -49,8 +53,8 @@
<if test="dsPath != null"> <if test="dsPath != null">
and ds_path=#{dsPath} and ds_path=#{dsPath}
</if> </if>
<if test="createTime != null"> <if test="args != null">
and create_time=#{createTime} and args=#{args}
</if> </if>
<if test="createTime != null"> <if test="createTime != null">
and create_time=#{createTime} and create_time=#{createTime}