|
|
@@ -0,0 +1,87 @@
|
|
|
+package com.cyksj.web.controller.manage.aimodel;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.model.entity.AiModel;
|
|
|
+import com.cyksj.service.aimodel.AiModelService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管理端 - AI 模型管理
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("/manage/aiModel")
|
|
|
+@RestController
|
|
|
+public class CmsAiModelController {
|
|
|
+
|
|
|
+ private final AiModelService aiModelService;
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ /** 分页查询模型列表 */
|
|
|
+ @GetMapping("/get")
|
|
|
+ public Result<SearchResult<AiModel>> get() {
|
|
|
+ SearchResult<AiModel> result = beanSearcher.search(AiModel.class,
|
|
|
+ MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .orderBy(AiModel::getSort).asc()
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 新增模型 */
|
|
|
+ @PostMapping("/post")
|
|
|
+ public Result<String> add(@RequestBody AiModel aiModel) {
|
|
|
+ validateModelCode(aiModel.getModelCode(), null);
|
|
|
+ aiModelService.save(aiModel);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 编辑模型 */
|
|
|
+ @PutMapping("/put")
|
|
|
+ public Result<String> update(@RequestBody AiModel aiModel) {
|
|
|
+ if (aiModel.getId() == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("模型不存在");
|
|
|
+ }
|
|
|
+ validateModelCode(aiModel.getModelCode(), aiModel.getId());
|
|
|
+ aiModelService.updateById(aiModel);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("编辑成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 删除模型 */
|
|
|
+ @DeleteMapping("/delete/{id}")
|
|
|
+ public Result<String> delete(@PathVariable Long id) {
|
|
|
+ aiModelService.removeById(id);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 启用/禁用 */
|
|
|
+ @PutMapping("/status/{id}/{status}")
|
|
|
+ public Result<String> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
|
|
|
+ aiModelService.update(Wrappers.lambdaUpdate(AiModel.class)
|
|
|
+ .set(AiModel::getStatus, status)
|
|
|
+ .eq(AiModel::getId, id));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validateModelCode(String modelCode, Long excludeId) {
|
|
|
+ if (modelCode == null || modelCode.isBlank()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("模型标识不能为空");
|
|
|
+ }
|
|
|
+ long count = aiModelService.count(Wrappers.lambdaQuery(AiModel.class)
|
|
|
+ .eq(AiModel::getModelCode, modelCode)
|
|
|
+ .ne(excludeId != null, AiModel::getId, excludeId));
|
|
|
+ if (count > 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("模型标识已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|