From e88fba9645a57535d858ce48da8e9d9a3dc84adc Mon Sep 17 00:00:00 2001
From: dongyukun <1208714201@qq.com>
Date: 星期四, 02 一月 2025 16:48:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java |   86 +++++++++++++++++++++++-------------------
 1 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
index c84413b..8c080f8 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/controller/admin/MmPredictItemController.java
@@ -1,34 +1,42 @@
 package com.iailab.module.model.mcs.pre.controller.admin;
 
+import cn.hutool.core.io.FileUtil;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.framework.common.pojo.PageResult;
-import com.iailab.framework.common.util.object.BeanUtils;
+import com.iailab.module.model.common.enums.CommonConstant;
 import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO;
-import com.iailab.module.model.mcs.pre.entity.MmPredictItemEntity;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
 import com.iailab.module.model.mcs.pre.vo.*;
+import com.iailab.module.model.mpk.common.utils.IAILModelUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import javax.annotation.security.PermitAll;
+import java.io.File;
+import java.util.*;
 
-import static com.iailab.framework.common.pojo.CommonResult.error;
 import static com.iailab.framework.common.pojo.CommonResult.success;
 
 /**
  * @author PanZhibao
  * @date 2021年04月26日 14:42
  */
+@Slf4j
 @RestController
-@RequestMapping("/model/pre/predict-item")
+@RequestMapping("/model/pre/item")
 public class MmPredictItemController {
+
+    @Value("${mpk.model-file-path}")
+    private String modelPath;
+
+    @Autowired
+    private IAILModelUtil iAILModelUtil;
 
     @Autowired
     private MmPredictItemService mmPredictItemService;
@@ -37,18 +45,24 @@
      * 预测项列表
      */
     @GetMapping("/page")
-    @PreAuthorize("@ss.hasPermission('model:pre-predict:query')")
+    @PreAuthorize("@ss.hasPermission('model:pre-item:query')")
     public CommonResult<PageResult<MmPredictItemRespVO>> page(@Validated MmPredictItemPageReqVO reqVO) {
-        PageResult<MmPredictItemEntity> page = mmPredictItemService.queryPage(reqVO);
-        return success(BeanUtils.toBean(page, MmPredictItemRespVO.class));
+        PageResult<MmPredictItemRespVO> page = mmPredictItemService.queryPage(reqVO);
+        return success(page);
+    }
+
+    @GetMapping("/list")
+    public CommonResult<List<MmPredictItemRespVO>> list(@RequestParam Map<String, Object> params) {
+        List<MmPredictItemRespVO> list = mmPredictItemService.list(params);
+        return success(list);
     }
 
     /**
      * 预测项信息
      */
     @GetMapping("/get/{id}")
-    @PreAuthorize("@ss.hasPermission('model:pre-predict:query')")
-    public CommonResult<MmPredictItemDTO> info(@PathVariable("id") String id){
+    @PreAuthorize("@ss.hasPermission('model:pre-item:query')")
+    public CommonResult<MmPredictItemDTO> info(@PathVariable("id") String id) {
         MmPredictItemDTO predictItem = mmPredictItemService.info(id);
         return success(predictItem);
     }
@@ -57,12 +71,10 @@
      * 保存预测项
      */
     @PostMapping("/create")
-    @PreAuthorize("@ss.hasPermission('model:pre-predict:create')")
-    @DSTransactional(rollbackFor= Exception.class)
-    public CommonResult<Boolean> save(@RequestBody MmPredictItemEntity mmPredictItemEntity){
-        String id = UUID.randomUUID().toString();
-        mmPredictItemEntity.setId(id);
-        mmPredictItemService.add(mmPredictItemEntity);
+    @PreAuthorize("@ss.hasPermission('model:pre-item:create')")
+    @DSTransactional(rollbackFor = Exception.class)
+    public CommonResult<Boolean> save(@RequestBody MmPredictItemDTO mmPredictItemDto) {
+        mmPredictItemService.add(mmPredictItemDto);
         return success(true);
     }
 
@@ -70,10 +82,10 @@
      * 修改预测项
      */
     @PutMapping("/update")
-    @PreAuthorize("@ss.hasPermission('model:pre-predict:update')")
-    @DSTransactional(rollbackFor= Exception.class)
-    public CommonResult<Boolean> update(@RequestBody MmPredictItemEntity mmPredictItemEntity){
-        mmPredictItemService.update(mmPredictItemEntity);
+    @PreAuthorize("@ss.hasPermission('model:pre-item:update')")
+    @DSTransactional(rollbackFor = Exception.class)
+    public CommonResult<Boolean> update(@RequestBody MmPredictItemDTO mmPredictItemDTO) {
+        mmPredictItemService.update(mmPredictItemDTO);
         return success(true);
     }
 
@@ -81,8 +93,8 @@
      * 删除预测项
      */
     @DeleteMapping("/delete")
-    @PreAuthorize("@ss.hasPermission('model:pre-predict:delete')")
-    @DSTransactional(rollbackFor= Exception.class)
+    @PreAuthorize("@ss.hasPermission('model:pre-item:delete')")
+    @DSTransactional(rollbackFor = Exception.class)
     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
         mmPredictItemService.deleteBatch(new String[]{id});
         return success(true);
@@ -92,26 +104,22 @@
      * 预测项列表
      */
     @GetMapping("/count-itemtype")
-    public CommonResult<List<CountItemtypeVO>> countItemtype(@RequestParam Map<String, Object> params){
+    public CommonResult<List<CountItemtypeVO>> countItemtype(@RequestParam Map<String, Object> params) {
         List<CountItemtypeVO> list = new ArrayList<>();
         return success(list);
     }
 
-//    /**
-//     * 数量
-//     */
-//    @GetMapping("/count")
-//    public CommonResult<Long> count() {
-//        Long count = mmPredictItemService.count();
-//        return success(count);
-//    }
-
     /**
      * 上传模型
      */
-    @PostMapping("/uploadModel")
-    public CommonResult<Boolean> uploadModel(@RequestParam("file") MultipartFile file) throws Exception {
-
-        return success(true);
+    @PermitAll
+    @PostMapping("/upload-model")
+    public CommonResult<Map<String, Object>> uploadModel(@RequestParam("file") MultipartFile file) throws Exception {
+        String uploadDir = modelPath + file.getOriginalFilename();
+        FileUtil.mkParentDirs(uploadDir);
+        file.transferTo(new File(uploadDir));
+        Map<String, Object> result = iAILModelUtil.parseModel(uploadDir);
+        result.put("originalFilename", file.getOriginalFilename().replace(CommonConstant.MDK_SUFFIX, ""));
+        return success(result);
     }
 }

--
Gitblit v1.9.3