Merge branch 'develop-business-css' of http://121.37.111.42:3000/ThbTech/JavaProjectRepo into develop-business-css

This commit is contained in:
limengnan 2025-12-26 17:27:19 +08:00
commit 4b9fbb8a7f
8 changed files with 257 additions and 4 deletions

View File

@ -15,7 +15,7 @@ import java.util.List;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@RestController @RestController
@RequestMapping("/api/algorithms") @RequestMapping("/algorithms")
public class AlgorithmController { public class AlgorithmController {
@Autowired @Autowired
@ -32,6 +32,8 @@ public class AlgorithmController {
@PostMapping @PostMapping
public boolean createAlgorithm(@RequestBody Algorithm algorithm) { public boolean createAlgorithm(@RequestBody Algorithm algorithm) {
algorithm.setModifier(currentUsername()); algorithm.setModifier(currentUsername());
algorithm.setCreatedAt(LocalDateTime.now());
algorithm.setUpdatedAt(LocalDateTime.now());
return algorithmService.save(algorithm); return algorithmService.save(algorithm);
} }

View File

@ -0,0 +1,124 @@
package com.yfd.business.css.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.business.css.domain.AlgorithmModel;
import com.yfd.business.css.service.AlgorithmModelService;
import com.yfd.platform.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.Authentication;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@RequestMapping("/algorithm-models")
public class AlgorithmModelController {
@Autowired
private AlgorithmModelService algorithmModelService;
@Autowired
private IUserService userService;
@GetMapping("/{id}")
public AlgorithmModel getById(@PathVariable String id) {
return algorithmModelService.getById(id);
}
@PostMapping
public boolean create(@RequestBody AlgorithmModel model) {
model.setModifier(currentUsername());
model.setCreatedAt(LocalDateTime.now());
model.setUpdatedAt(LocalDateTime.now());
return algorithmModelService.save(model);
}
@PutMapping
public boolean update(@RequestBody AlgorithmModel model) {
model.setModifier(currentUsername());
model.setUpdatedAt(LocalDateTime.now());
return algorithmModelService.updateById(model);
}
@DeleteMapping("/{id}")
public boolean delete(@PathVariable String id) {
return algorithmModelService.removeById(id);
}
@DeleteMapping
public boolean deleteBatch(@RequestBody List<String> ids) {
return algorithmModelService.removeByIds(ids);
}
//返回该算法+设备类型的版本列表
@GetMapping("/search")
public Page<AlgorithmModel> search(@RequestParam(required = false) String algorithmType,
@RequestParam(required = false) String deviceType,
@RequestParam(defaultValue = "1") long pageNum,
@RequestParam(defaultValue = "20") long pageSize) {
QueryWrapper<AlgorithmModel> qw = new QueryWrapper<>();
if (algorithmType != null && !algorithmType.isEmpty()) qw.eq("algorithm_type", algorithmType);
if (deviceType != null && !deviceType.isEmpty()) qw.eq("device_type", deviceType);
qw.orderByDesc("updated_at");
Page<AlgorithmModel> page = new Page<>(pageNum, pageSize, true);
return algorithmModelService.page(page, qw);
}
//返回该算法+设备类型的当前激活版本
@GetMapping("/current")
public AlgorithmModel getCurrent(@RequestParam String algorithmType,
@RequestParam String deviceType) {
QueryWrapper<AlgorithmModel> qw = new QueryWrapper<>();
qw.eq("algorithm_type", algorithmType);
qw.eq("device_type", deviceType);
qw.eq("is_current", 1);
qw.orderByDesc("updated_at");
return algorithmModelService.getOne(qw);
}
//版本激活
@PostMapping("/activate")
public boolean activate(@RequestParam String algorithmModelId) {
AlgorithmModel model = algorithmModelService.getById(algorithmModelId);
if (model == null) return false;
// 先将所有版本设为非当前
QueryWrapper<AlgorithmModel> qw = new QueryWrapper<>();
qw.eq("algorithm_type", model.getAlgorithmType());
qw.eq("device_type", model.getDeviceType());
AlgorithmModel upd = new AlgorithmModel();
upd.setIsCurrent(0);
algorithmModelService.update(upd, qw);
// 设置当前版本
model.setIsCurrent(1);
model.setModifier(currentUsername());
model.setUpdatedAt(LocalDateTime.now());
return algorithmModelService.updateById(model);
}
//在线训练
@PostMapping("/train")
public boolean train(@RequestParam String algorithmModelId) {
AlgorithmModel model = algorithmModelService.getById(algorithmModelId);
if (model == null) return false;
// 调用训练接口
// ...
return true;
}
private String currentUsername() {
try {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null || auth instanceof AnonymousAuthenticationToken) {
return "anonymous";
}
return userService.getUsername();
} catch (Exception e) {
return "anonymous";
}
}
}

View File

@ -33,9 +33,32 @@ public class ScenarioController {
@PostMapping @PostMapping
public boolean create(@RequestBody Scenario scenario) { public boolean create(@RequestBody Scenario scenario) {
scenario.setModifier(currentUsername()); scenario.setModifier(currentUsername());
scenario.setCreatedAt(LocalDateTime.now());
scenario.setUpdatedAt(LocalDateTime.now());
scenario.setStatus("0");
return scenarioService.save(scenario); return scenarioService.save(scenario);
} }
/**
* 1.1 新增情景并返回对象
* 输入参数请求体中的情景对象
* 输出参数标准响应包含情景对象含生成的ID
* @param scenario 情景对象
* @return 标准响应结构
*/
@PostMapping("/createAndReturn")
public java.util.Map<String, Object> createAndReturn(@RequestBody Scenario scenario) {
scenario.setModifier(currentUsername());
scenario.setCreatedAt(LocalDateTime.now());
scenario.setUpdatedAt(LocalDateTime.now());
scenario.setStatus("0");
boolean ok = scenarioService.save(scenario);
if (!ok) {
return java.util.Map.of("code", 1, "msg", "新增失败");
}
return java.util.Map.of("code", 0, "msg", "新增成功", "data", scenario, "scenarioId", scenario.getScenarioId());
}
/** /**
* 2. 修改情景 * 2. 修改情景
* 输入参数请求体中的情景对象需包含主键 * 输入参数请求体中的情景对象需包含主键

View File

@ -18,6 +18,9 @@ public class Algorithm implements Serializable {
@TableId(value = "algorithm_id", type = IdType.ASSIGN_UUID) @TableId(value = "algorithm_id", type = IdType.ASSIGN_UUID)
private String algorithmId; private String algorithmId;
@TableField("algorithm_type")
private String algorithmType;
@TableField("name") @TableField("name")
private String name; private String name;
@ -30,15 +33,33 @@ public class Algorithm implements Serializable {
@TableField("principle") @TableField("principle")
private String principle; private String principle;
@TableField("updated_at")
private LocalDateTime updatedAt;
@TableField("input_params") @TableField("input_params")
private String inputParams; private String inputParams;
@TableField("output_params") @TableField("output_params")
private String outputParams; private String outputParams;
@TableField("infer_base_url")
private String inferBaseUrl;
@TableField("train_base_url")
private String trainBaseUrl;
@TableField("supported_device_types")
private String supportedDeviceTypes;
@TableField("default_hyper_params")
private String defaultHyperParams;
@TableField("status")
private String status;
@TableField("updated_at")
private LocalDateTime updatedAt;
@TableField("created_at")
private LocalDateTime createdAt;
@TableField("modifier") @TableField("modifier")
private String modifier; private String modifier;
} }

View File

@ -0,0 +1,56 @@
package com.yfd.business.css.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@TableName("algorithm_model")
public class AlgorithmModel implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "algorithm_model_id", type = IdType.ASSIGN_UUID)
private String algorithmModelId;
@TableField("algorithm_type")
private String algorithmType;
@TableField("device_type")
private String deviceType;
@TableField("version_tag")
private String versionTag;
@TableField("model_path")
private String modelPath;
@TableField("feature_map_snapshot")
private String featureMapSnapshot;
@TableField("metrics")
private String metrics;
@TableField("metrics_image_path")
private String metricsImagePath;
@TableField("trained_at")
private LocalDateTime trainedAt;
@TableField("is_current")
private Integer isCurrent;
@TableField("created_at")
private LocalDateTime createdAt;
@TableField("updated_at")
private LocalDateTime updatedAt;
@TableField("modifier")
private String modifier;
}

View File

@ -0,0 +1,9 @@
package com.yfd.business.css.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yfd.business.css.domain.AlgorithmModel;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface AlgorithmModelMapper extends BaseMapper<AlgorithmModel> {
}

View File

@ -0,0 +1,7 @@
package com.yfd.business.css.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yfd.business.css.domain.AlgorithmModel;
public interface AlgorithmModelService extends IService<AlgorithmModel> {
}

View File

@ -0,0 +1,11 @@
package com.yfd.business.css.service.impl;
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 org.springframework.stereotype.Service;
@Service
public class AlgorithmModelServiceImpl extends ServiceImpl<AlgorithmModelMapper, AlgorithmModel> implements AlgorithmModelService {
}