From a6e46fe2b5729e7468b6f3c4e079232801c22520 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期一, 16 十二月 2024 18:19:37 +0800
Subject: [PATCH] 模型输出类型添加double类型

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java |   64 ++++++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
index f595abc..d058b4c 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java
@@ -17,6 +17,7 @@
 import com.iailab.module.model.mcs.pre.vo.MmPredictItemRespVO;
 import com.iailab.module.model.mdk.vo.ItemVO;
 import com.iailab.module.model.mdk.vo.MergeItemVO;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -57,6 +58,8 @@
 
     @Autowired
     private MmPredictItemDao mmPredictItemDao;
+
+    private static HashMap<String, ItemVO> itemVOHashMap = new HashMap<>();
 
     @Override
     public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) {
@@ -127,6 +130,9 @@
             e.setItemid(predictItem.getId());
         });
         mmItemOutputService.saveMmItemOutput(mmItemOutput);
+
+        // 清空缓存
+        clearCatch();
     }
 
     @DSTransactional(rollbackFor = Exception.class)
@@ -161,11 +167,20 @@
         }
         mmItemOutputService.deleteByItemId(predictItem.getId());
         List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList();
-        mmItemOutput.forEach(e -> {
-            e.setId(UUID.randomUUID().toString());
-            e.setItemid(predictItem.getId());
-        });
-        mmItemOutputService.saveMmItemOutput(mmItemOutput);
+        if (!CollectionUtils.isEmpty(mmItemOutput)) {
+            mmItemOutput.forEach(e -> {
+                // 尽量保存原有id
+                if (StringUtils.isBlank(e.getId())) {
+                    e.setId(UUID.randomUUID().toString());
+                }
+                e.setItemid(predictItem.getId());
+            });
+            mmItemOutputService.saveMmItemOutput(mmItemOutput);
+        }
+
+
+        // 清空缓存
+        clearCatch();
     }
 
     @DSTransactional(rollbackFor = Exception.class)
@@ -175,6 +190,9 @@
         mmPredictMergeItemService.deleteBatch(itemIds);
         mmPredictModelService.deleteBatch(itemIds);
         mmItemOutputService.deleteBatch(itemIds);
+
+        // 清空缓存
+        clearCatch();
     }
 
     @Override
@@ -235,11 +253,30 @@
     }
 
     @Override
-    public ItemVO getItemById(String itemId) {
+    public void clearCatch() {
+        itemVOHashMap.clear();
+    }
+
+    @Override
+    public ItemVO getItemByIdFromCache(String itemId) {
         if (StringUtils.isBlank(itemId)) {
             return null;
         }
-        Map<String, Object> params = new HashMap(1);
+        if (!itemVOHashMap.containsKey(itemId)) {
+            Map<String, Object> params = new HashMap<>(1);
+            params.put("ITEMID", itemId);
+            List<ItemVO> list = mmPredictItemDao.getItem(params);
+            if (CollectionUtils.isEmpty(list)) {
+                return null;
+            }
+            itemVOHashMap.put(itemId, list.get(0));
+        }
+        return itemVOHashMap.get(itemId);
+    }
+
+    @Override
+    public ItemVO getItemById(String itemId) {
+        Map<String, Object> params = new HashMap<>(1);
         params.put("ITEMID", itemId);
         List<ItemVO> list = mmPredictItemDao.getItem(params);
         if (CollectionUtils.isEmpty(list)) {
@@ -249,6 +286,19 @@
     }
 
     @Override
+    public ItemVO getItemByOutPutId(String outPutId) {
+        if (StringUtils.isBlank(outPutId)) {
+            return null;
+        }
+        MmItemOutputEntity outPutById = mmItemOutputService.getOutPutById(outPutId);
+        if (ObjectUtils.isEmpty(outPutById)) {
+            return null;
+        }
+        String itemId = outPutById.getItemid();
+        return getItemByIdFromCache(itemId);
+    }
+
+    @Override
     public MergeItemVO getMergeItemByItemId(String itemId) {
         if (StringUtils.isBlank(itemId)) {
             return null;

--
Gitblit v1.9.3