[冲突]:解决合并冲突

# Conflicts:
#	src/main/java/com/bipt/intelligentapplicationorchestrationservice/constant/MessageConstant.java
#	src/main/resources/application.properties
This commit is contained in:
2025-05-25 19:29:52 +08:00
parent 999fd82ccc
commit 9f348280ea
12 changed files with 400 additions and 16 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

@ -1,7 +1,6 @@
package com.bipt.intelligentapplicationorchestrationservice.controller; package com.bipt.intelligentapplicationorchestrationservice.controller;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.pojo.OptResult;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService; import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -9,10 +8,13 @@ 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.*;
import java.util.List;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/model") @RequestMapping("/model")
@Tag(name = "模型部分相关接口") @Tag(name = "模型部分相关接口")
@CrossOrigin(origins = "http://localhost:3000") // 生产环境指定具体域名
public class ModelController { public class ModelController {
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@ -32,4 +34,46 @@ public class ModelController {
return OptResult.success(); 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

@ -1,9 +1,12 @@
package com.bipt.intelligentapplicationorchestrationservice.mapper; package com.bipt.intelligentapplicationorchestrationservice.mapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelInfo; import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVO;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion; import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
import org.apache.ibatis.annotations.Insert; import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersionDTO;
import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.*;
import java.util.List;
public interface ModelMapper { public interface ModelMapper {
@ -21,4 +24,52 @@ public interface ModelMapper {
*/ */
void insertModelVersion(ModelVersion 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

@ -5,6 +5,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data @Data
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@ -12,9 +14,18 @@ import lombok.NoArgsConstructor;
public class ModelDTO { public class ModelDTO {
private Long id; // 模型id private Long id; // 模型id
private String modelName; // 模型名称 private String modelName; // 模型名称
private String version; // 模型版本
private Integer datasetId; // 数据集id private Integer datasetId; // 数据集id
private String modelConfig; // 模型配置信息
private String modelPath; // 模型存储路径
private Integer status; // 模型状态1代表上线0代表不上线D
private Integer modelSize; // 模型大小 private Integer modelSize; // 模型大小
private String dataPreHandleFile; // 数据预处理文件存储路 private String dataPreHandleFile; // 数据预处理文件存储路
private String modelSuperArgs; // 模型超参数
private String version; //模型版本 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

@ -37,4 +37,10 @@ public class ModelVersion implements Serializable {
private String modelDesignDocument; // 模型设计文档存储路径 private String modelDesignDocument; // 模型设计文档存储路径
private String lifeCycle; // 模型生命周期 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

@ -1,9 +1,9 @@
package com.bipt.intelligentapplicationorchestrationservice.service.Impl; 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.mapper.ModelMapper;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelDTO; import com.bipt.intelligentapplicationorchestrationservice.pojo.*;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelInfo;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelVersion;
import com.bipt.intelligentapplicationorchestrationservice.service.ModelService; import com.bipt.intelligentapplicationorchestrationservice.service.ModelService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -12,6 +12,7 @@ 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.List;
@Slf4j @Slf4j
@Service @Service
@ -38,6 +39,7 @@ public class ModelServiceImpl implements ModelService {
modelVersion.setModelId(modelInfo.getId()); modelVersion.setModelId(modelInfo.getId());
modelVersion.setCreateTime(LocalDateTime.now()); modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now()); modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
modelMapper.insertModelVersion(modelVersion); modelMapper.insertModelVersion(modelVersion);
} }
@ -53,6 +55,94 @@ public class ModelServiceImpl implements ModelService {
modelVersion.setModelId(dto.getId()); modelVersion.setModelId(dto.getId());
modelVersion.setCreateTime(LocalDateTime.now()); modelVersion.setCreateTime(LocalDateTime.now());
modelVersion.setUpdateTime(LocalDateTime.now()); modelVersion.setUpdateTime(LocalDateTime.now());
modelVersion.setOperateUser("zs");
modelMapper.insertModelVersion(modelVersion); 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

@ -1,10 +1,24 @@
package com.bipt.intelligentapplicationorchestrationservice.service; package com.bipt.intelligentapplicationorchestrationservice.service;
import com.bipt.intelligentapplicationorchestrationservice.pojo.ModelDTO; 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 { public interface ModelService {
void createModel(ModelDTO dto); void createModel(ModelDTO dto);
void createModelVersion(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

@ -2,9 +2,58 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!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"> <mapper namespace="com.bipt.intelligentapplicationorchestrationservice.mapper.ModelMapper">
<!--插入模型版本信息--> <!--(新增新的模型)插入模型版本信息-->
<insert id="insertModelVersion"> <insert id="insertModelVersion">
insert into model_version (model_id, dataset_id, model_size, data_pre_handle_file, create_time, update_time, version) insert into model_version (
values (#{modelId}, #{datasetId}, #{modelSize}, #{dataPreHandleFile}, #{createTime}, #{updateTime}, #{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> </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> </mapper>