From a440ec3bfaa1363f5841100b8948d852971a2eb1 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期二, 10 十二月 2024 13:19:58 +0800
Subject: [PATCH] MmPredictAlarmConfigService

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java |  187 ++++++++++++++++++++++++++++------------------
 1 files changed, 113 insertions(+), 74 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 810f29d..7f4dfec 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
@@ -1,37 +1,36 @@
 package com.iailab.module.model.mcs.pre.service.impl;
 
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.iailab.framework.common.page.PageData;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.iailab.framework.common.pojo.PageResult;
-import com.iailab.framework.common.service.impl.BaseServiceImpl;
+import com.iailab.framework.common.util.object.BeanUtils;
 import com.iailab.module.model.mcs.pre.dao.MmPredictItemDao;
 import com.iailab.module.model.mcs.pre.dto.MmPredictItemDTO;
 import com.iailab.module.model.mcs.pre.entity.*;
 import com.iailab.module.model.mcs.pre.enums.ItemIncreaseCodeEnum;
 import com.iailab.module.model.mcs.pre.enums.ItemTypeEnum;
 import com.iailab.module.model.mcs.pre.service.MmPredictItemService;
-import com.iailab.module.model.mcs.pre.service.SequenceNumService;
+import com.iailab.module.model.mcs.pre.service.MmSequenceNumService;
+import com.iailab.module.model.mcs.pre.vo.MmPredictItemPageReqVO;
 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;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 /**
  * @author PanZhibao
  * @date 2021年04月26日 14:03
  */
-@Service("mmPredictItemService")
-public class MmPredictItemServiceImpl extends BaseServiceImpl<MmPredictItemDao, MmPredictItemEntity> implements MmPredictItemService {
+@Service
+public class MmPredictItemServiceImpl extends ServiceImpl<MmPredictItemDao, MmPredictItemEntity> implements MmPredictItemService {
 
     @Autowired
     private DmModuleItemServiceImpl dmModuleItemService;
@@ -55,41 +54,46 @@
     private MmItemTypeImpl mmItemTypeImpl;
 
     @Autowired
-    private SequenceNumService sequenceNumService;
+    private MmSequenceNumService sequenceNumService;
+
+    @Autowired
+    private MmPredictItemDao mmPredictItemDao;
+
+    private static HashMap<String, ItemVO> itemVOHashMap = new HashMap<>();
 
     @Override
-    public PageResult<MmPredictItemRespVO> getPageList(Map<String, Object> params) {
-        PageResult<MmPredictItemRespVO> result = new PageResult();
-        IPage<MmPredictItemRespVO> page = baseDao.getPageList(
-                getPage(params, "CREATE_TIME", false),
-                params
-        );
-        result.setList(page.getRecords());
-        result.setTotal(page.getTotal());
-        return result;
-    }
+    public PageResult<MmPredictItemRespVO> queryPage(MmPredictItemPageReqVO reqVO) {
+        IPage<MmPredictItemRespVO> page = mmPredictItemDao.selectPage(reqVO);
 
-    private QueryWrapper<MmPredictItemEntity> getWrapper(Map<String, Object> params) {
-        QueryWrapper<MmPredictItemEntity> wrapper = new QueryWrapper<>();
-        return wrapper;
+        return new PageResult<>(page.getRecords(), page.getTotal());
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void savePredictItem(MmPredictItemDTO mmPredictItemDto) {
+    public List<MmPredictItemRespVO> list(Map<String, Object> params) {
+        return mmPredictItemDao.queryList(params);
+    }
+
+    @Override
+    public MmPredictItemEntity getById(String id) {
+        return  mmPredictItemDao.selectById(id);
+    }
+
+    @DSTransactional(rollbackFor = Exception.class)
+    @Override
+    public void add(MmPredictItemDTO mmPredictItemDto) {
         MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem();
         predictItem.setId(UUID.randomUUID().toString());
         predictItem.setCreateTime(new Date());
         predictItem.setUpdateTime(new Date());
 
         MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid());
-        if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
-            SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString());
+        if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
+            MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IM.toString());
             String str = String.format("%010d", sequenceNumEntity.getSequenceNum());
             predictItem.setItemno(sequenceNumEntity.getPrefix() + str);
 
             MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel();
-            SequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString());
+            MmSequenceNumEntity preMdlSequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.PRE_MDL.toString());
             String preMdlStr = String.format("%04d", preMdlSequenceNumEntity.getSequenceNum());
             mmPredictModel.setModelno(preMdlSequenceNumEntity.getPrefix() + preMdlStr);
             mmPredictModel.setItemid(predictItem.getId());
@@ -106,8 +110,8 @@
                 item.setModelid(mmPredictModel.getId());
             });
             mmModelParamService.saveList(mmModelParamList);
-        } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
-            SequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString());
+        } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
+            MmSequenceNumEntity sequenceNumEntity = sequenceNumService.getAndIncreaseByCode(ItemIncreaseCodeEnum.IC.toString());
             String str = String.format("%010d", sequenceNumEntity.getSequenceNum());
             predictItem.setItemno(sequenceNumEntity.getPrefix() + str);
 
@@ -115,24 +119,30 @@
             mMmPredictMergeItem.setItemid(predictItem.getId());
             mmPredictMergeItemService.savePredictMergeItem(mMmPredictMergeItem);
         }
-        insert(predictItem);
+        mmPredictItemDao.insert(predictItem);
         DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem();
         dmModuleItem.setItemid(predictItem.getId());
         dmModuleItemService.saveModuleItem(dmModuleItem);
 
-        MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput();
-        mmItemOutput.setItemid(predictItem.getId());
+        List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList();
+        mmItemOutput.forEach(e -> {
+            e.setId(UUID.randomUUID().toString());
+            e.setItemid(predictItem.getId());
+        });
         mmItemOutputService.saveMmItemOutput(mmItemOutput);
+
+        // 清空缓存
+        clearCatch();
     }
 
+    @DSTransactional(rollbackFor = Exception.class)
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public void update(MmPredictItemDTO mmPredictItemDto) {
         MmPredictItemEntity predictItem = mmPredictItemDto.getMmPredictItem();
         predictItem.setUpdateTime(new Date());
-        this.updateById(predictItem);
+        mmPredictItemDao.updateById(predictItem);
         MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid());
-        if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
+        if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
             MmPredictModelEntity mmPredictModel = mmPredictItemDto.getMmPredictModel();
             mmPredictModelService.update(mmPredictModel);
 
@@ -147,52 +157,66 @@
                 item.setModelid(mmPredictModel.getId());
             });
             mmModelParamService.saveList(mmModelParamList);
-        } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
+        } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
             MmPredictMergeItemEntity mMmPredictMergeItem = mmPredictItemDto.getMmPredictMergeItem();
             mmPredictMergeItemService.update(mMmPredictMergeItem);
         }
         DmModuleItemEntity dmModuleItem = mmPredictItemDto.getDmModuleItem();
-        dmModuleItemService.update(dmModuleItem);
+        if (!"".equals(dmModuleItem.getId()) && dmModuleItem.getId() != null) {
+            dmModuleItemService.update(dmModuleItem);
+        }
+        mmItemOutputService.deleteByItemId(predictItem.getId());
+        List<MmItemOutputEntity> mmItemOutput = mmPredictItemDto.getMmItemOutputList();
+        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);
+        }
 
-        MmItemOutputEntity mmItemOutput = mmPredictItemDto.getMmItemOutput();
-        mmItemOutputService.update(mmItemOutput);
+
+        // 清空缓存
+        clearCatch();
     }
 
+    @DSTransactional(rollbackFor = Exception.class)
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public void deleteBatch(String[] itemIds) {
-        deleteBatchIds(Arrays.asList(itemIds));
+        mmPredictItemDao.deleteBatchIds(Arrays.asList(itemIds));
         mmPredictMergeItemService.deleteBatch(itemIds);
         mmPredictModelService.deleteBatch(itemIds);
         mmItemOutputService.deleteBatch(itemIds);
+
+        // 清空缓存
+        clearCatch();
     }
 
     @Override
-    public MmPredictItemDTO getDetailById(String id, Map<String, Object> params) {
-        MmPredictItemDTO mmPredictItemDto = new MmPredictItemDTO();
-        MmPredictItemEntity predictItem = selectById(id);
+    public MmPredictItemDTO info(String id) {
+        MmPredictItemEntity predictItem = mmPredictItemDao.selectById(id);
+        MmPredictItemDTO mmPredictItemDto = BeanUtils.toBean(predictItem, MmPredictItemDTO.class);
         mmPredictItemDto.setMmPredictItem(predictItem);
         mmPredictItemDto.setDmModuleItem(dmModuleItemService.getByItemid(id));
-        mmPredictItemDto.setMmItemOutput(mmItemOutputService.getByItemid(id));
+        mmPredictItemDto.setMmItemOutputList(mmItemOutputService.getByItemid(id));
         MmItemTypeEntity itemType = mmItemTypeImpl.getById(predictItem.getItemtypeid());
-        if (ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) {
+        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()));
-        } else if (ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
+            mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity());
+        } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) {
+            mmPredictItemDto.setMmPredictModel(new MmPredictModelEntity());
+            mmPredictItemDto.setMmModelArithSettingsList(new ArrayList<>());
+            mmPredictItemDto.setMmModelParamList(new ArrayList<>());
+            mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity());
             mmPredictItemDto.setMmPredictMergeItem(mmPredictMergeItemService.getByItemid(id));
         }
-
         return mmPredictItemDto;
-    }
-
-    @Override
-    public boolean exportItemResult(HttpServletResponse response, HttpServletRequest request, String id, Map<String, Object> params) {
-        //MmPredictItemDTO mmPredictItemDto = this.getPredictValuesById(id, params);
-        //List<MmItemResultEntity> itemResultList = mmPredictItemDto.getMmItemResultList();
-
-        return true;
     }
 
     @Override
@@ -203,21 +227,15 @@
         QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>();
         queryWrapper.ne(StringUtils.isNotBlank(id), "id", id);
         queryWrapper.and(wrapper -> wrapper.eq("itemname", itemname).or().eq("itemno", itemno));
-        List<MmPredictItemEntity> list = baseDao.selectList(queryWrapper);
+        List<MmPredictItemEntity> list = mmPredictItemDao.selectList(queryWrapper);
         return list.size();
-    }
-
-    @Override
-    public Long count() {
-        QueryWrapper<MmPredictItemEntity> queryWrapper = new QueryWrapper<>();
-        return baseDao.selectCount(queryWrapper);
     }
 
     @Override
     public List<ItemVO> getByModuleId(String moduleId) {
         Map<String, Object> params = new HashMap<>();
-
-        return baseDao.getByModuleId(params);
+        params.put("MODULEID",moduleId);
+        return mmPredictItemDao.getByModuleId(params);
     }
 
     @Override
@@ -227,7 +245,7 @@
         }
         Map<String, Object> params = new HashMap(1);
         params.put("ITEMNO", itemNo);
-        List<ItemVO> list = baseDao.getItem(params);
+        List<ItemVO> list = mmPredictItemDao.getItem(params);
         if (CollectionUtils.isEmpty(list)) {
             return null;
         }
@@ -235,17 +253,38 @@
     }
 
     @Override
+    public void clearCatch() {
+        itemVOHashMap.clear();
+    }
+
+    @Override
     public ItemVO getItemById(String itemId) {
         if (StringUtils.isBlank(itemId)) {
             return null;
         }
-        Map<String, Object> params = new HashMap(1);
-        params.put("ITEMID", itemId);
-        List<ItemVO> list = baseDao.getItem(params);
-        if (CollectionUtils.isEmpty(list)) {
+        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 getItemByOutPutId(String outPutId) {
+        if (StringUtils.isBlank(outPutId)) {
             return null;
         }
-        return list.get(0);
+        MmItemOutputEntity outPutById = mmItemOutputService.getOutPutById(outPutId);
+        if (ObjectUtils.isEmpty(outPutById)) {
+            return null;
+        }
+        String itemId = outPutById.getItemid();
+        return getItemById(itemId);
     }
 
     @Override
@@ -255,7 +294,7 @@
         }
         Map<String, Object> params = new HashMap(1);
         params.put("ITEMID", itemId);
-        List<MergeItemVO> list = baseDao.getMergeItemByItemId(params);
+        List<MergeItemVO> list = mmPredictItemDao.getMergeItemByItemId(params);
         if (CollectionUtils.isEmpty(list)) {
             return null;
         }

--
Gitblit v1.9.3