创建设备接口支持传入id和自动生成

This commit is contained in:
wanxiaoli 2026-01-16 09:58:38 +08:00
parent 10900e3e52
commit 645df52290
8 changed files with 92 additions and 2 deletions

View File

@ -0,0 +1,12 @@
package com.yfd.business.css.common.exception;
public class BizException extends RuntimeException {
public BizException(String message) {
super(message);
}
public BizException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -34,3 +34,27 @@ public class MybatisConfig {
}
}
// @Configuration
// public class MybatisConfig {
// @Bean
// public MybatisPlusInterceptor mybatisPlusInterceptor() {
// return new MybatisPlusInterceptor();
// }
// @Bean
// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
// MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
// factoryBean.setDataSource(dataSource);
// factoryBean.setMapperLocations(
// new PathMatchingResourcePatternResolver()
// .getResources("classpath*:/mapper/**/*.xml"));
// return factoryBean.getObject();
// }
// @Bean
// public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
// return new SqlSessionTemplate(sqlSessionFactory);
// }
// }

View File

@ -77,7 +77,7 @@ public class AlgorithmModelController {
@DeleteMapping
@Operation(summary = "删除模型版本(批量)", description = "请求体传入模型ID列表批量删除模型版本")
public boolean deleteBatch(@RequestBody List<String> ids) {
return algorithmModelService.removeByIds(ids);
return algorithmModelService.deleteBatchWithCheck(ids);
}
//返回该算法+设备类型的版本列表

View File

@ -3,6 +3,8 @@ package com.yfd.business.css.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.business.css.domain.AlgorithmModel;
import java.util.List;
public interface AlgorithmModelService extends IService<AlgorithmModel> {
/**
@ -13,5 +15,7 @@ public interface AlgorithmModelService extends IService<AlgorithmModel> {
* @return 激活版本的模型文件路径如果不存在则返回null
*/
String getCurrentModelPath(String algorithmType, String deviceType) ;
boolean deleteBatchWithCheck(List<String> ids);
}

View File

@ -8,4 +8,6 @@ public interface DeviceService extends IService<Device> {
* 导入设备
*/
boolean importDevices(MultipartFile file, String deviceType);
public boolean createDevice(Device device) ;
}

View File

@ -5,8 +5,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfd.business.css.domain.AlgorithmModel;
import com.yfd.business.css.mapper.AlgorithmModelMapper;
import com.yfd.business.css.service.AlgorithmModelService;
import com.yfd.business.css.common.exception.BizException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class AlgorithmModelServiceImpl extends ServiceImpl<AlgorithmModelMapper, AlgorithmModel> implements AlgorithmModelService {
@ -19,4 +23,32 @@ public class AlgorithmModelServiceImpl extends ServiceImpl<AlgorithmModelMapper,
AlgorithmModel model = getOne(queryWrapper);
return model != null ? model.getModelPath() : null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteBatchWithCheck(List<String> ids) {
if (ids == null || ids.isEmpty()) {
return true;
}
// 1. 查询是否存在当前激活版本
List<AlgorithmModel> currentModels = this.list(
new QueryWrapper<AlgorithmModel>()
.in("id", ids)
.eq("is_current", 1)
.select("id", "model_name")
);
// 2. 若存在激活版本拒绝删除
if (!currentModels.isEmpty()) {
String names = currentModels.stream()
.map(m -> m.getAlgorithmType() + "-" + m.getDeviceType())
.collect(Collectors.joining(", "));
throw new BizException("以下模型为当前激活版本,不允许删除:" + names);
}
// 3. 执行批量删除
return this.removeByIds(ids);
}
}

View File

@ -5,6 +5,10 @@ import com.yfd.business.css.domain.Device;
import com.yfd.business.css.mapper.DeviceMapper;
import com.yfd.business.css.service.DeviceService;
import com.yfd.platform.system.service.IUserService;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.security.core.context.SecurityContextHolder;
@ -52,6 +56,18 @@ public class DeviceServiceImpl
}
}
@Override
public boolean createDevice(Device device) {
// 1. 如果前端没有传 deviceId显式生成
if (StrUtil.isBlank(device.getDeviceId())) {
device.setDeviceId(IdUtil.fastUUID());
}
// 2. 如果前端传了 deviceId直接使用
return this.save(device);
}
private boolean importExcel(Workbook workbook, String deviceType) {
try (Workbook wb = workbook) {
Sheet sheet = wb.getSheetAt(0);

View File

@ -1282,7 +1282,7 @@ public class ProjectServiceImpl
}
System.out.println();
}
//6. 调用模型进行推理
//6. 调用模型进行推理,把结果写入推理结果表
deviceInferService.processDeviceInference(projectId, scenarioId, groupedDevices);