Compare commits

...

3 Commits

Author SHA1 Message Date
lpz
bcf44161b5 Merge pull request 'nh' (#12) from nh into main
Reviewed-on: #12
2025-05-26 10:08:49 +08:00
9f348280ea [冲突]:解决合并冲突
# Conflicts:
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/constant/MessageConstant.java
#	src/main/resources/application.properties
2025-05-25 19:41:42 +08:00
999fd82ccc 保留从main分支暂存的所有修改
# Conflicts:
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/ModelController.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/mapper/ModelMapper.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/pojo/ModelDTO.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/Impl/ModelServiceImpl.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/ModelService.java
#	src/main/resources/mapper/ModelMapper.xml

# Conflicts:
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/controller/ModelController.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/mapper/ModelMapper.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/pojo/ModelDTO.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/Impl/ModelServiceImpl.java
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/service/ModelService.java
#	src/main/resources/mapper/ModelMapper.xml
2025-05-25 19:31:25 +08:00
12 changed files with 553 additions and 0 deletions

View File

@ -3,4 +3,12 @@ package com.bipt.intelligentapplicationorchestrationservice.constant;
public class MessageConstant { public class MessageConstant {
public static final String UNKNOWN_ERROR = "未知错误"; public static final String UNKNOWN_ERROR = "未知错误";
public static final String ALREADY_EXISTS = "已存在"; public static final String ALREADY_EXISTS = "已存在";
//生命周期相关常量
public static final String LifeCycle_No_Exist = "生命周期不存在";
public static final String LifeCycle_Undefined = "生命周期未定义";
public static final String ERROR_DEPLOYED_TO_DESIGNING = "已部署的模型不能直接调整成设计,需先下线再设计";
public static final String ERROR_ABANDONED_CANNOT_UPDATE = "已废弃的模型只能查看信息,不能更新生命周期";
public static final String ERROR_TRAINING_INVALID_TRANSITION = "训练中的模型只能调整成设计和评估";
public static final String UPDATE_FAILURE = "更新模型生命周期失败";
} }

View File

@ -0,0 +1,79 @@
package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/model")
@Tag(name = "模型部分相关接口")
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
public class ModelController {
@Autowired
private ModelService modelService;
@Operation(summary = "创建模型")
@PostMapping("/createModel")
public OptResult creatModel(@RequestBody ModelDTO dto){
log.info("创建模型");
modelService.createModel(dto);
return OptResult.success();
}
@Operation(summary = "新增模型版本")
@PostMapping("/createModelVersion")
public OptResult createModelVersion(@RequestBody ModelDTO dto){
log.info("新增模型版本");
modelService.createModelVersion(dto);
return OptResult.success();
}
@Operation(summary = "查询模型列表")
@GetMapping("list")
public OptResult list(){
log.info("查询模型列表");
List<ModelVO> modelVOList = modelService.list();
return OptResult.success(modelVOList);
}
@Operation(summary = "查询模型详情")
@GetMapping("detail")
public OptResult detail(Long id){
log.info("查询模型详情");
ModelVersion modelVersion = modelService.detail(id);
return OptResult.success(modelVersion);
}
@Operation(summary = "模型更新")
@PutMapping("/updateModel")
public OptResult updateModel(@RequestBody ModelVersionDTO dto){
log.info("模型更新");
modelService.updateModel(dto);
return OptResult.success();
}
@Operation(summary = "模型版本删除")
@DeleteMapping("/deleteModelVersion")
public OptResult deleteModelVersion(Long id){
log.info("模型版本删除");
modelService.deleteModelVersion(id);
return OptResult.success();
}
@Operation(summary = "更新生命周期")
@PutMapping("/updateLifeCycle")
public OptResult updateLifeCycle(Long id,String lifeCycle){
log.info("更新生命周期");
modelService.updateLifeCycle(id,lifeCycle);
return OptResult.success();
}
}

View File

@ -0,0 +1,51 @@
package com.bipt.intelligentapplicationorchestrationservice.enumeration;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
/**
* 模型生命周期状态枚举
*/
public enum ModelLifecycle {
DESIGNING("设计中"),
TRAINING("训练中"),
EVALUATING("评估中"),
DEPLOYED("已部署"),
OFFLINE("已下线"),
ABANDONED("已废弃");
private final String description;
private ModelLifecycle(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
// 将枚举名称转换成数据库存储的字符串
public String getDbValue() {
return name();
}
// 将数据库存储的字符串转换为枚举实例
public static ModelLifecycle getDbValueFromDb(String dbValue) {
if(dbValue == null) return null;
try {
return ModelLifecycle.valueOf(dbValue);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(MessageConstant.LifeCycle_No_Exist + ":" + dbValue);
}
}
// 从前端传的中文描述 -> 转换为枚举
public static ModelLifecycle fromDescription(String description) {
for (ModelLifecycle lifecycle : ModelLifecycle.values()) {
if (lifecycle.getDescription().equals(description)) {
return lifecycle;
}
}
throw new IllegalArgumentException("生命周期描述非法: " + description);
}
}

View File

@ -0,0 +1,75 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersionDTO;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface ModelMapper {
/**
* 插入模型基本信息
* @param modelInfo
*/
@Options(useGeneratedKeys = true, keyProperty = "id") //能够拿到主键值并设置给modelInfo对象
@Insert("insert into model_info(model_name) values(#{modelName})")
void insertModelInfo(ModelInfo modelInfo);
/**
* 插入模型版本信息
* @param modelVersion
*/
void insertModelVersion(ModelVersion modelVersion);
/*
* 查询模型列表
*/
List<ModelVO> list();
/**
* 根据id查询模型详情
* @param id 版本表id
* @return
*/
ModelVersion selectById(Long id);
/**
* 更新模型信息
* @param dto
*/
void update(ModelVersionDTO dto);
/**
* 删除模型版本
* @param id 版本表id
*/
@Delete("delete from model_version where id=#{id}")
void deleteModelVersion(Long id);
/**
* 删除模型
* @param id 模型id
*/
@Delete("delete from model_info where id= #{id}")
void deleteModel(Long id);
/**
* 查询模型生命周期
* @param id 模型版本表id
* 返回模型生命周期
*/
@Select("select life_cycle from model_version where id=#{id}")
String selectLifeCycleById(Long id);
/**
* 更新模型生命周期
* @param id 模型版本表id
* @param dbValue 数据库中存储的生命周期
* @return
*/
@Update("update model_version set life_cycle=#{dbValue} where id=#{id}")
int updateLifeCycleById(Long id, String dbValue);
}

View File

@ -0,0 +1,31 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ModelDTO {
private Long id; // 模型id
private String modelName; // 模型名称
private String version; // 模型版本
private Integer datasetId; // 数据集id
private String modelConfig; // 模型配置信息
private String modelPath; // 模型存储路径
private Integer status; // 模型状态1代表上线0代表不上线D
private Integer modelSize; // 模型大小
private String dataPreHandleFile; // 数据预处理文件存储路径
private String modelSuperArgs; // 模型超参数
private String modelArgsSize; // 模型参数量
private String modelSourceCodeUrl; // 模型源代码路径
private String modelFile; // 模型文件存储路径
private String modelDesignDocument; // 模型设计文档存储路径
private String lifeCycle; // 模型生命周期
private String operateUser; // 操作人
}

View File

@ -0,0 +1,24 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ModelVO {
private Long id; // 模型id
private Long versionId; // 用于保证react的map中key的唯一性
private String modelName; // 模型名称
private String version; // 模型版本
private String dataPreHandleFile; // 数据预处理文件存储路径
private String operateUser; // 操作人
private LocalDateTime updateTime; // 修改时间
private Integer status; // 模型状态1代表上线0代表不上线
}

View File

@ -24,5 +24,23 @@ public class ModelVersion implements Serializable {
private String modelPath; // 模型存储路径 private String modelPath; // 模型存储路径
private Integer status; // 模型状态1代表上线0代表不上线 private Integer status; // 模型状态1代表上线0代表不上线
private LocalDateTime createTime; // 创建时间 private LocalDateTime createTime; // 创建时间
//补充更新时间字段
private LocalDateTime updateTime; // 更新时间
//创建模型部分补充的字段
private Integer modelSize; // 模型大小
private String dataPreHandleFile; // 数据预处理文件存储路径
//模型信息管理部分补充的字段
private String modelSuperArgs; // 模型超参数
private String modelArgsSize; // 模型参数量
private String modelSourceCodeUrl; // 模型源代码路径
private String modelFile; // 模型文件存储路径
private String modelDesignDocument; // 模型设计文档存储路径
private String lifeCycle; // 模型生命周期
private String operateUser; // 操作人
private String modelName; //模型名称
} }

View File

@ -0,0 +1,31 @@
package com.bipt.intelligentapplicationorchestrationservice.pojo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ModelVersionDTO {
private Long id; // 模型id
private String version; // 模型版本
private Integer datasetId; // 数据集id
private String modelConfig; // 模型配置信息
private String modelPath; // 模型存储路径
private Integer status; // 模型状态1代表上线0代表不上线
private LocalDateTime createTime; // 创建时间
private LocalDateTime updateTime; // 更新时间
private Integer modelSize; // 模型大小
private String dataPreHandleFile; // 数据预处理文件存储路径
private String modelSuperArgs; // 模型超参数
private String modelArgsSize; // 模型参数量
private String modelSourceCodeUrl; // 模型源代码路径
private String modelFile; // 模型文件存储路径
private String modelDesignDocument; // 模型设计文档存储路径
private String lifeCycle; // 模型生命周期
private String operateUser; // 操作人
}

View File

@ -0,0 +1,148 @@
package com.bipt.intelligentapplicationorchestrationservice.service.Impl;
import com.bipt.intelligentapplicationorchestrationservice.constant.MessageConstant;
import com.bipt.intelligentapplicationorchestrationservice.enumeration.ModelLifecycle;
import com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
public class ModelServiceImpl implements ModelService {
@Autowired
private ModelMapper modelMapper;
/**
* 创建模型
* @param dto
*/
@Transactional //事务注解
@Override
public void createModel(ModelDTO dto) {
log.info("创建模型");
//1.插入模型基本信息
ModelInfo modelInfo = new ModelInfo();
BeanUtils.copyProperties(dto, modelInfo, "id");
modelMapper.insertModelInfo(modelInfo);
log.info("模型id: {}", modelInfo.getId());
//2.插入模型版本信息
ModelVersion modelVersion = new ModelVersion();
//使用工具类将dto属性复制给modelVersion
BeanUtils.copyProperties(dto, modelVersion, "id");
modelVersion.setModelId(modelInfo.getId());
modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
modelMapper.insertModelVersion(modelVersion);
}
/**
* 新增模型版本
* @param dto
*/
@Override
public void createModelVersion(ModelDTO dto) {
log.info("新增模型版本");
ModelVersion modelVersion = new ModelVersion();
BeanUtils.copyProperties(dto, modelVersion, "id");
modelVersion.setModelId(dto.getId());
modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
modelMapper.insertModelVersion(modelVersion);
}
/**
* 查询模型列表
*/
@Override
public List<ModelVO> list() {
log.info("查询模型列表");
List<ModelVO> modelVOList = modelMapper.list();
return modelVOList;
}
@Override
public ModelVersion detail(Long id) {
log.info("查询模型详情");
ModelVersion modelVersion = modelMapper.selectById(id);
return modelVersion;
}
@Override
public void updateModel(ModelVersionDTO dto) {
log.info("更新模型");
modelMapper.update(dto);
}
@Override
public void deleteModelVersion(Long id) {
log.info("删除模型版本");
modelMapper.deleteModelVersion(id);
}
/**
* 更新模型生命周期
* @param id 版本表id
* @param
*/
@Override
public void updateLifeCycle(Long id, String lifeCycleDescription) {
log.info("更新模型生命周期");
// 1. 查询当前生命周期并转为枚举
String currentLifeCycleStr = modelMapper.selectLifeCycleById(id);
if (currentLifeCycleStr == null) {
log.error("未找到对应模型信息,无法更新生命周期");
throw new IllegalArgumentException(MessageConstant.LifeCycle_No_Exist);
}
ModelLifecycle currentLifeCycle;
ModelLifecycle targetLifeCycle;
try {
currentLifeCycle = ModelLifecycle.valueOf(currentLifeCycleStr.trim()); // 数据库中是英文
targetLifeCycle = ModelLifecycle.fromDescription((lifeCycleDescription).trim()); // 前端传中文
} catch (IllegalArgumentException e) {
log.error(MessageConstant.LifeCycle_Undefined + ":{}", e.getMessage());
throw e;
}
// 2. 业务逻辑校验
switch (currentLifeCycle) {
case DEPLOYED:
if (targetLifeCycle == ModelLifecycle.DESIGNING) {
log.error("已部署的模型不能直接调整成设计,需先下线再设计");
throw new IllegalArgumentException(MessageConstant.ERROR_DEPLOYED_TO_DESIGNING);
}
break;
case ABANDONED:
log.error("已废弃的模型只能查看信息,不能更新生命周期");
throw new IllegalArgumentException(MessageConstant.ERROR_ABANDONED_CANNOT_UPDATE);
case TRAINING:
if (targetLifeCycle != ModelLifecycle.DESIGNING && targetLifeCycle != ModelLifecycle.EVALUATING) {
log.error("训练中的模型只能调整成设计和评估");
throw new IllegalArgumentException(MessageConstant.ERROR_TRAINING_INVALID_TRANSITION);
}
break;
default:
break;
}
// 3. 执行更新
int affectedRows = modelMapper.updateLifeCycleById(id, targetLifeCycle.getDbValue());
if (affectedRows == 0) {
log.error("更新模型生命周期失败");
throw new RuntimeException(MessageConstant.UPDATE_FAILURE);
}
log.info("模型生命周期更新成功,新状态为: {}", targetLifeCycle);
}
}

View File

@ -0,0 +1,24 @@
package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelDTO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersionDTO;
import java.util.List;
public interface ModelService {
void createModel(ModelDTO dto);
void createModelVersion(ModelDTO dto);
List<ModelVO> list();
ModelVersion detail(Long id);
void updateModel(ModelVersionDTO dto);
void deleteModelVersion(Long id);
void updateLifeCycle(Long id, String lifeCycle);
}

View File

@ -27,3 +27,8 @@ spring.data.redis.password=Jbjhhzstsl97@
spring.data.redis.database = 0 spring.data.redis.database = 0
# 连接超时时间(毫秒) # 连接超时时间(毫秒)
spring.data.redis.timeout = 3000 spring.data.redis.timeout = 3000
#SQL 语句日志输出配置
logging.level.com.bipt.intelligentapplicationorchestrationservice.mapper=DEBUG
mybatis.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper">
<!--(新增新的模型)插入模型版本信息-->
<insert id="insertModelVersion">
insert into model_version (
model_id, version, dataset_id, model_config,
model_path, status, create_time, update_time, model_size,
data_pre_handle_file, model_super_args, model_args_size, model_source_code_url, model_file,
model_design_document, life_cycle, operate_user
)
values (
#{modelId}, #{version}, #{datasetId}, #{modelConfig},
#{modelPath}, #{status}, #{createTime}, #{updateTime}, #{modelSize},
#{dataPreHandleFile}, #{modelSuperArgs}, #{modelArgsSize}, #{modelSourceCodeUrl}, #{modelFile},
#{modelDesignDocument}, #{lifeCycle}, #{operateUser}
)
</insert>
<!--查询模型列表-->
<select id="list" resultType="modelVO">
select t1.*,
t2.id as versionId,t2.version, t2.version, t2.data_pre_handle_file, t2.operate_user, t2.update_time,
t2.status
from model_info t1
left join model_version t2 on t1.id = t2.model_id
order by t2.update_time desc
</select>
<!--查询模型详细信息-->
<select id="selectById" resultType="modelVersion">
SELECT
t1.model_name,
t2.version, t2.dataset_id, t2.model_config,
t2.model_path, t2.status, t2.create_time, t2.update_time, t2.model_size,
t2.data_pre_handle_file, t2.model_super_args, t2.model_args_size, t2.model_source_code_url, t2.model_file,
t2.model_design_document, t2.life_cycle, t2.operate_user
FROM model_info t1 JOIN model_version t2 ON t1.id = t2.model_id
where t2.id = #{id}
</select>
<!--更新模型信息-->
<update id="update">
UPDATE model_version
<set>
<if test="modelSize != null">
model_size = #{modelSize},
</if>
<if test="modelSuperArgs != null">
model_super_args = #{modelSuperArgs},
</if>
<if test="modelArgsSize != null">
model_args_size = #{modelArgsSize},
</if>
</set>
WHERE id = #{id
</update>
</mapper>