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/MmItemOutputServiceImpl.java |  102 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 64 insertions(+), 38 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
index 4868760..3ab68e9 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemOutputServiceImpl.java
@@ -1,78 +1,104 @@
 package com.iailab.module.model.mcs.pre.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.iailab.framework.common.service.impl.BaseServiceImpl;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.iailab.module.model.mcs.pre.dao.MmItemOutputDao;
+import com.iailab.module.model.mcs.pre.dto.MmItemOutputDTO;
 import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity;
 import com.iailab.module.model.mcs.pre.service.MmItemOutputService;
-import com.iailab.module.model.mcs.pre.dto.MmItemOutputDTO;
-import com.iailab.module.model.mdk.vo.MmItemOutputVO;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @author PanZhibao
  * @date 2021年04月27日 9:22
  */
-@Service("mmItemOutputService")
-public class MmItemOutputServiceImpl extends BaseServiceImpl<MmItemOutputDao, MmItemOutputEntity> implements MmItemOutputService {
+@Service
+public class MmItemOutputServiceImpl extends ServiceImpl<MmItemOutputDao, MmItemOutputEntity> implements MmItemOutputService {
 
+    @Autowired
+    private MmItemOutputDao mmItemOutputDao;
+
+    private static Map<String, MmItemOutputEntity> outputMap = new ConcurrentHashMap<>();
+
+    private static Map<String, List<MmItemOutputEntity>> itemMap = new ConcurrentHashMap<>();
+    
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public void saveMmItemOutput(MmItemOutputEntity mmItemOutput) {
-        mmItemOutput.setId(UUID.randomUUID().toString());
-        baseDao.insert(mmItemOutput);
+    public void saveMmItemOutput(List<MmItemOutputEntity> mmItemOutput) {
+        mmItemOutput.forEach(e -> {
+            e.setId(e.getId().replace("+","").replace("-",""));
+        });
+        mmItemOutputDao.insert(mmItemOutput);
+        // 清空缓存
+        clearCache();
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
     public void update(MmItemOutputEntity mmItemOutput) {
-        this.updateById(mmItemOutput);
+        mmItemOutputDao.updateById(mmItemOutput);
+        // 清空缓存
+        clearCache();
     }
 
     public void deleteBatch(String[] itemIds) {
-        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<MmItemOutputEntity>();
+        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>();
         queryWrapper.in("itemid", itemIds);
-        baseDao.delete(queryWrapper);
+        mmItemOutputDao.delete(queryWrapper);
+        // 清空缓存
+        clearCache();
+    }
+
+    private void clearCache() {
+        outputMap.clear();
+        itemMap.clear();
     }
 
     @Override
-    public MmItemOutputEntity getByItemid(String itemid) {
-        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<MmItemOutputEntity>();
-        queryWrapper.eq("itemid", itemid);
-        List<MmItemOutputEntity> list = baseDao.selectList(queryWrapper);
-        if (CollectionUtils.isEmpty(list)) {
-            return new MmItemOutputEntity();
+    public List<MmItemOutputEntity> getByItemid(String itemId) {
+        if (itemMap.containsKey(itemId)) {
+            return itemMap.get(itemId);
         }
-        return list.get(0);
+        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("itemid", itemId).orderByAsc("outputorder");
+        List<MmItemOutputEntity> list = mmItemOutputDao.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return null;
+        }
+        itemMap.put(itemId, list);
+        return itemMap.get(itemId);
+    }
+
+    @Override
+    public MmItemOutputEntity getByItemid(String itemid, String resultstr) {
+        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("itemid", itemid).eq("resultstr", resultstr);
+        return mmItemOutputDao.selectOne(queryWrapper);
+    }
+
+    @Override
+    public void deleteByItemId(String itemId) {
+        QueryWrapper<MmItemOutputEntity> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("itemid", itemId);
+        mmItemOutputDao.delete(queryWrapper);
     }
 
     @Override
     public List<MmItemOutputDTO> queryList(Map<String, Object> params) {
-        return baseDao.queryList(params);
+        return mmItemOutputDao.queryList(params);
     }
 
     @Override
-    public MmItemOutputVO getOutPutById(String outputid) {
-        List<MmItemOutputVO> list = baseDao.getOutPutById(outputid);
-        if (CollectionUtils.isEmpty(list)) {
-            return null;
+    public MmItemOutputEntity getOutPutById(String outputid) {
+        if (outputMap.containsKey(outputid)) {
+            return outputMap.get(outputid);
         }
-        return list.get(0);
-    }
-
-    @Override
-    public List<MmItemOutputVO> getOutPutByItemId(String itemid) {
-        return baseDao.getOutPutByItemId(itemid);
-    }
-
-    @Override
-    public List<MmItemOutputVO> getOutPutByPointId(String pointid) {
-        return baseDao.getOutPutByPointId(pointid);
+        MmItemOutputEntity entity = mmItemOutputDao.selectById(outputid);
+        outputMap.put(outputid, entity);
+        return entity;
     }
 }

--
Gitblit v1.9.3