From cf2287d43a3e6e6a87b799b484c1c6073226c1bf Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 05 十一月 2024 18:17:31 +0800
Subject: [PATCH] MDK包名管理

---
 iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkPredictReqDTO.java           |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/PackController.java    |   72 ++++++++++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/vo/PackPageReqVO.java                   |   28 ++++
 iailab-module-model/iailab-module-model-biz/db/mysql.sql                                                                      |   13 ++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/PackServiceImpl.java       |   89 ++++++++++++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/entity/PackEntity.java                  |   44 +++++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/PackService.java                |   32 +++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/dao/PackDao.java                        |   25 ++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java       |    2 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java |    6 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/factory/PredictItemFactory.java         |    7 
 11 files changed, 314 insertions(+), 6 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkPredictReqDTO.java b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkPredictReqDTO.java
index c8d1297..6b44ced 100644
--- a/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkPredictReqDTO.java
+++ b/iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mdk/dto/MdkPredictReqDTO.java
@@ -19,7 +19,7 @@
     @NotNull(message="预测时间不能为空")
     private Date predictTime;
 
-    @Schema(description = "预测模块")
+    @Schema(description = "预测模块(管网类型)")
     private String moduleType;
 
     @Schema(description = "预测项编号")
diff --git a/iailab-module-model/iailab-module-model-biz/db/mysql.sql b/iailab-module-model/iailab-module-model-biz/db/mysql.sql
index ecd5752..3e0fc36 100644
--- a/iailab-module-model/iailab-module-model-biz/db/mysql.sql
+++ b/iailab-module-model/iailab-module-model-biz/db/mysql.sql
@@ -630,4 +630,15 @@
                                     PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '模型文件分组' ROW_FORMAT = Dynamic;
 
-alter table t_mm_predict_model add column `mpkprojectid` varchar(36) DEFAULT NULL;
\ No newline at end of file
+alter table t_mm_predict_model add column `mpkprojectid` varchar(36) DEFAULT NULL;
+
+DROP TABLE IF EXISTS `t_mpk_pack`;
+CREATE TABLE `t_mpk_pack`  (
+                               `id` varchar(36) NOT NULL COMMENT 'id',
+                               `pack_name` varchar(50) NOT NULL COMMENT '包名称',
+                               `pack_desc` varchar(50) DEFAULT NULL COMMENT '包描述',
+                               `model_path` varchar(50) DEFAULT NULL COMMENT '模型路径',
+                               `sort` integer DEFAULT NULL COMMENT '排序',
+                               PRIMARY KEY (`id`) USING BTREE,
+                               UNIQUE INDEX uk_pack_name (pack_name)
+) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = 'MDK包名管理' ROW_FORMAT = Dynamic;
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/factory/PredictItemFactory.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/factory/PredictItemFactory.java
index 1290ff6..0095127 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/factory/PredictItemFactory.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/factory/PredictItemFactory.java
@@ -1,6 +1,7 @@
 package com.iailab.module.model.mdk.factory;
 
 import com.iailab.module.model.mcs.pre.entity.MmItemTypeEntity;
+import com.iailab.module.model.mdk.predict.PredictItemHandler;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
@@ -25,16 +26,16 @@
      * @param itemId
      * @return
      */
-    public Object create(String itemId) {
+    public PredictItemHandler create(String itemId) {
         MmItemTypeEntity itemTypeEntity = itemEntityFactory.getMmItemTypeEntity(itemId);
         //获取预测项的预测程序的类
         Object itemObject = null;
         try {
-            Class clazz = Class.forName(itemTypeEntity.getItemclasstype());
+            Class<?> clazz = Class.forName(itemTypeEntity.getItemclasstype());
             itemObject = applicationContext.getBean(clazz);
         } catch (Exception e) {
             log.error("exception message : {}", e.getMessage());
         }
-        return itemObject;
+        return (PredictItemHandler) itemObject;
     }
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
index a43780e..d5f4515 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictModuleHandler.java
@@ -42,7 +42,7 @@
                 continue;
             }
             try {
-                PredictItemHandler predictItemHandler = (PredictItemHandler)predictItemFactory.create(predictItem.getId());
+                PredictItemHandler predictItemHandler = predictItemFactory.create(predictItem.getId());
                 Instant start = Instant.now();
                 try {
                     predictResult = predictItemHandler.predict(predictTime, predictItem);
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
index 8f8ebed..74f7a1b 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -4,6 +4,7 @@
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.module.model.mpk.dto.MpkFileDTO;
 import com.iailab.module.model.mpk.service.MpkFileService;
+import com.iailab.module.model.mpk.service.PackService;
 import io.swagger.v3.oas.annotations.Operation;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -29,6 +30,9 @@
 public class MpkFileController {
     @Autowired
     private MpkFileService mpkFileService;
+
+    @Autowired
+    private PackService packService;
 
     @GetMapping("page")
     @Operation(summary = "分页")
@@ -66,6 +70,7 @@
                 dto.setGroupName(dto.getMenuAndGroup().get(1));
             }
         }
+        dto.setPyModule(packService.getModelPath(dto.getClassName()));
         mpkFileService.save(dto);
         return CommonResult.success(true);
     }
@@ -86,6 +91,7 @@
                 dto.setGroupName(dto.getMenuAndGroup().get(1));
             }
         }
+        dto.setPyModule(packService.getModelPath(dto.getClassName()));
         mpkFileService.update(dto);
         return CommonResult.success(true);
     }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/PackController.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/PackController.java
new file mode 100644
index 0000000..86ea0e9
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/PackController.java
@@ -0,0 +1,72 @@
+package com.iailab.module.model.mpk.controller.admin;
+
+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.mpk.entity.PackEntity;
+import com.iailab.module.model.mpk.service.PackService;
+import com.iailab.module.model.mpk.vo.PackPageReqVO;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
+
+import static com.iailab.framework.common.pojo.CommonResult.success;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+@Tag(name = "模型服务 - MDK包名管理")
+@RestController
+@RequestMapping("/model/mpk/pack")
+public class PackController {
+
+    @Autowired
+    private PackService packService;
+
+    @GetMapping("/page")
+    @Operation(summary = "获得分页")
+    public CommonResult<PageResult<PackEntity>> page(@Valid PackPageReqVO reqVO) {
+        PageResult<PackEntity> page = packService.page(reqVO);
+        return success(BeanUtils.toBean(page, PackEntity.class));
+    }
+
+    @GetMapping("/list")
+    @Operation(summary = "获得列表")
+    public CommonResult<List<PackEntity>> list() {
+        List<PackEntity> list = packService.list();
+        return success(list);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得详情")
+    public CommonResult<PackEntity> get(@RequestParam("id") String id) {
+        PackEntity data = packService.get(id);
+        return success(data);
+    }
+
+    @PostMapping("/create")
+    @Operation(summary = "创建")
+    public CommonResult<Boolean> save(@Valid @RequestBody PackEntity entity) {
+        packService.create(entity);
+        return success(true);
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新")
+    public CommonResult<Boolean> update(@Valid @RequestBody PackEntity entity) {
+        packService.update(entity);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
+        packService.delete(id);
+        return success(true);
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/dao/PackDao.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/dao/PackDao.java
new file mode 100644
index 0000000..d0e212d
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/dao/PackDao.java
@@ -0,0 +1,25 @@
+package com.iailab.module.model.mpk.dao;
+
+import com.iailab.framework.common.pojo.PageResult;
+import com.iailab.framework.mybatis.core.mapper.BaseMapperX;
+import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
+import com.iailab.framework.tenant.core.db.dynamic.TenantDS;
+import com.iailab.module.model.mpk.entity.PackEntity;
+import com.iailab.module.model.mpk.vo.PackPageReqVO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+@TenantDS
+@Mapper
+public interface PackDao extends BaseMapperX<PackEntity> {
+
+    default PageResult<PackEntity> selectPage(PackPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<PackEntity>()
+                .likeIfPresent(PackEntity::getPackName, reqVO.getPackName())
+                .orderByDesc(PackEntity::getSort).orderByAsc(PackEntity::getPackName));
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/entity/PackEntity.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/entity/PackEntity.java
new file mode 100644
index 0000000..addf9fa
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/entity/PackEntity.java
@@ -0,0 +1,44 @@
+package com.iailab.module.model.mpk.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+@Data
+@TableName("t_mpk_pack")
+public class PackEntity implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @TableId
+    private String id;
+
+    /**
+     * 包名称
+     */
+    private String packName;
+
+    /**
+     * 包描述
+     */
+    private String packDesc;
+
+    /**
+     * 模型路径
+     */
+    private String modelPath;
+
+    /**
+     * 排序
+     */
+    private Integer sort;
+}
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/PackService.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/PackService.java
new file mode 100644
index 0000000..a9c660b
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/PackService.java
@@ -0,0 +1,32 @@
+package com.iailab.module.model.mpk.service;
+
+import com.iailab.framework.common.pojo.PageResult;
+import com.iailab.module.model.mpk.entity.PackEntity;
+import com.iailab.module.model.mpk.vo.PackPageReqVO;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+public interface PackService {
+
+    PageResult<PackEntity> page(PackPageReqVO reqVO);
+
+    List<PackEntity> list();
+
+    void create(PackEntity entity);
+
+    void update(PackEntity entity);
+
+    PackEntity get(String id);
+
+    void delete(String id);
+
+    Map<String, PackEntity> getNameMap();
+
+    String getModelPath(String packName);
+}
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/PackServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/PackServiceImpl.java
new file mode 100644
index 0000000..2816e08
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/PackServiceImpl.java
@@ -0,0 +1,89 @@
+package com.iailab.module.model.mpk.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.iailab.framework.common.pojo.PageResult;
+import com.iailab.module.model.mpk.dao.PackDao;
+import com.iailab.module.model.mpk.entity.PackEntity;
+import com.iailab.module.model.mpk.service.PackService;
+import com.iailab.module.model.mpk.vo.PackPageReqVO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+@Slf4j
+@Service
+public class PackServiceImpl implements PackService {
+
+    @Autowired
+    private PackDao iconDao;
+
+    @Override
+    public PageResult<PackEntity> page(PackPageReqVO reqVO) {
+        return iconDao.selectPage(reqVO);
+    }
+
+    @Override
+    public List<PackEntity> list() {
+        QueryWrapper<PackEntity> qw = new QueryWrapper<>();
+        qw.orderByAsc("sort");
+        return iconDao.selectList(qw);
+    }
+
+    @Override
+    public Map<String, PackEntity> getNameMap() {
+        Map<String, PackEntity> map = new HashMap<>();
+        QueryWrapper<PackEntity> qw = new QueryWrapper<>();
+        List<PackEntity> list = iconDao.selectList(qw);
+        if (CollectionUtils.isEmpty(list)) {
+            return map;
+        }
+        list.forEach(packEntity -> {
+            map.put(packEntity.getPackName(), packEntity);
+        });
+        return map;
+    }
+
+    @Override
+    public String getModelPath(String packName) {
+        QueryWrapper<PackEntity> qw = new QueryWrapper<>();
+        qw.eq("pack_name", packName);
+        PackEntity packEntity = iconDao.selectOne(qw);
+
+        if (packEntity == null) {
+            return null;
+        }
+        return packEntity.getModelPath();
+    }
+
+    @Override
+    public void create(PackEntity entity) {
+        entity.setId(UUID.randomUUID().toString());
+        iconDao.insert(entity);
+    }
+
+    @Override
+    public void update(PackEntity entity) {
+        iconDao.updateById(entity);
+    }
+
+    @Override
+    public PackEntity get(String id) {
+        return iconDao.selectById(id);
+    }
+
+    @Override
+    public void delete(String id) {
+        iconDao.deleteById(id);
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/vo/PackPageReqVO.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/vo/PackPageReqVO.java
new file mode 100644
index 0000000..3e5d4f2
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/vo/PackPageReqVO.java
@@ -0,0 +1,28 @@
+package com.iailab.module.model.mpk.vo;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月05日
+ */
+
+import com.iailab.framework.common.pojo.PageParam;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年09月22日
+ */
+@Schema(description = "模型服务 - MDK包名称分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class PackPageReqVO extends PageParam {
+
+    @Schema(description = "包名称名称,模糊匹配", example = "")
+    private String packName;
+}
\ No newline at end of file

--
Gitblit v1.9.3