From 154b38709aa8151222382240392f120ae5542a69 Mon Sep 17 00:00:00 2001
From: Jay <csj123456>
Date: 星期二, 18 二月 2025 15:29:05 +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/service/impl/MmPredictItemServiceImpl.java |  136 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 128 insertions(+), 8 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 5b1b9e5..5dd3eb6 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;
@@ -58,6 +59,8 @@
     @Autowired
     private MmPredictItemDao mmPredictItemDao;
 
+    private static HashMap<String, ItemVO> itemVOHashMap = new HashMap<>();
+
     @Override
     public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) {
         IPage<MmPredictItemRespVO> page = mmPredictItemDao.selectPage(reqVO);
@@ -73,6 +76,34 @@
     @Override
     public MmPredictItemEntity getById(String id) {
         return  mmPredictItemDao.selectById(id);
+    }
+
+    @Override
+    public List<MmPredictItemRespVO> getDoubleOutPutsByItemNos(List<String> itemNos) {
+        List<Integer> resultType = new ArrayList<Integer>(){{
+           add(3);
+        }};
+        return getOutPutsByItemNosAndResultType(itemNos,resultType);
+    }
+
+    @Override
+    public List<MmPredictItemRespVO> getArrayOutPutsByItemNos(List<String> itemNos) {
+        List<Integer> resultType = new ArrayList<Integer>(){{
+            add(1);
+            add(2);
+        }};
+        return getOutPutsByItemNosAndResultType(itemNos,resultType);
+    }
+
+    public List<MmPredictItemRespVO> getOutPutsByItemNosAndResultType(List<String> itemNos,List<Integer> resultType) {
+        if (CollectionUtils.isEmpty(itemNos) || CollectionUtils.isEmpty(resultType)) {
+            return new ArrayList<>();
+        }
+        Map<String, Object> params = new HashMap(1);
+        params.put("itemNos", itemNos);
+        params.put("resultType", resultType);
+        List<MmPredictItemRespVO> list = mmPredictItemDao.getOutPutsByItemNosAndResultType(params);
+        return list;
     }
 
     @DSTransactional(rollbackFor = Exception.class)
@@ -115,6 +146,18 @@
             MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem();
             mMmPredictMergeItem.setItemid(predictItem.getId());
             mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem);
+            // 添加一条默认output
+            List<MmItemOutputEntity> mergeItemOutput = new ArrayList<>(1);
+            MmItemOutputEntity entity = new MmItemOutputEntity();
+            entity.setPointid(mmPredictItemDto.getPointId());
+            entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname());
+            entity.setResultstr("result");
+            //累计配置
+            entity.setIscumulant(mmPredictItemDto.getIscumulant());
+            entity.setCumuldivisor(mmPredictItemDto.getCumuldivisor());
+            entity.setCumulpoint(mmPredictItemDto.getCumulpoint());
+            mergeItemOutput.add(entity);
+            mmPredictItemDto.setMmItemOutputList(mergeItemOutput);
         }
         mmPredictItemDao.insert(predictItem);
         DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem();
@@ -127,6 +170,9 @@
             e.setItemid(predictItem.getId());
         });
         mmItemOutputService.saveMmItemOutput(mmItemOutput);
+
+        // 清空缓存
+        clearCatch();
     }
 
     @DSTransactional(rollbackFor = Exception.class)
@@ -154,6 +200,29 @@
         } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
             MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem();
             mmPredictMergeItemService.update(mMmPredictMergeItem);
+            // 修改默认output
+            List<MmItemOutputEntity> mmItemOutputList = mmPredictItemDto.getMmItemOutputList();
+            if (CollectionUtils.isEmpty(mmItemOutputList)) {
+                mmItemOutputList = new ArrayList<>(1);
+                MmItemOutputEntity entity = new MmItemOutputEntity();
+                entity.setPointid(mmPredictItemDto.getPointId());
+                entity.setResultName(mmPredictItemDto.getMmPredictItem().getItemname());
+                entity.setResultstr("result");
+                //累计配置
+                entity.setIscumulant(mmPredictItemDto.getIscumulant());
+                entity.setCumuldivisor(mmPredictItemDto.getCumuldivisor());
+                entity.setCumulpoint(mmPredictItemDto.getCumulpoint());
+                mmItemOutputList.add(entity);
+                mmPredictItemDto.setMmItemOutputList(mmItemOutputList);
+            } else {
+                mmPredictItemDto.getMmItemOutputList().forEach(entity -> {
+                    entity.setPointid(mmPredictItemDto.getPointId());
+                    //累计配置
+                    entity.setIscumulant(mmPredictItemDto.getIscumulant());
+                    entity.setCumuldivisor(mmPredictItemDto.getCumuldivisor());
+                    entity.setCumulpoint(mmPredictItemDto.getCumulpoint());
+                });
+            }
         }
         DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem();
         if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) {
@@ -161,11 +230,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 +253,9 @@
         mmPredictMergeItemService.deleteBatch(itemIds);
         mmPredictModelService.deleteBatch(itemIds);
         mmItemOutputService.deleteBatch(itemIds);
+
+        // 清空缓存
+        clearCatch();
     }
 
     @Override
@@ -188,7 +269,7 @@
         if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
             MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id);
             mmPredictItemDto.setMmPredictModel(mmPredictModel);
-            mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId()));
+            mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelId(mmPredictModel.getId()));
             mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId()));
             mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity());
         } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
@@ -197,6 +278,13 @@
             mmPredictItemDto.setMmModelParamList(new ArrayList<>());
             mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity());
             mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id));
+            if (!CollectionUtils.isEmpty(mmPredictItemDto.getMmItemOutputList())) {
+                mmPredictItemDto.setPointId(mmPredictItemDto.getMmItemOutputList().get(0).getPointid());
+                //累计配置
+                mmPredictItemDto.setIscumulant(mmPredictItemDto.getMmItemOutputList().get(0).getIscumulant());
+                mmPredictItemDto.setCumuldivisor(mmPredictItemDto.getMmItemOutputList().get(0).getCumuldivisor());
+                mmPredictItemDto.setCumulpoint(mmPredictItemDto.getMmItemOutputList().get(0).getCumulpoint());
+            }
         }
         return mmPredictItemDto;
     }
@@ -235,11 +323,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 +356,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