From 5b952f77058a9da5af5e143a6c2c7ba195aa736d Mon Sep 17 00:00:00 2001
From: liriming <1343021927@qq.com>
Date: 星期二, 26 十一月 2024 16:08:10 +0800
Subject: [PATCH] 预测消息配置

---
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictModelServiceImpl.java |   59 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictModelServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictModelServiceImpl.java
index eb61a05..12221fc 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictModelServiceImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictModelServiceImpl.java
@@ -1,10 +1,11 @@
 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.MmPredictModelDao;
 import com.iailab.module.model.mcs.pre.entity.MmPredictModelEntity;
 import com.iailab.module.model.mcs.pre.service.MmPredictModelService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -12,34 +13,61 @@
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @author PanZhibao
  * @date 2021年04月27日 11:30
  */
-@Service("mmPredictModelService")
-public class MmPredictModelServiceImpl extends BaseServiceImpl<MmPredictModelDao, MmPredictModelEntity> implements MmPredictModelService {
+@Service
+public class MmPredictModelServiceImpl extends ServiceImpl<MmPredictModelDao, MmPredictModelEntity> implements MmPredictModelService {
+
+    @Autowired
+    private MmPredictModelDao mmPredictModelDao;
+
+    private static Map<String, MmPredictModelEntity> modelEntityMap = new ConcurrentHashMap<>();
+
+    private static Map<String, MmPredictModelEntity> activeModelMap = new ConcurrentHashMap<>();
 
     @Override
     public void savePredictModel(MmPredictModelEntity predictModel) {
         predictModel.setId(UUID.randomUUID().toString());
-        baseDao.insert(predictModel);
+        mmPredictModelDao.insert(predictModel);
+        clearCache();
     }
 
     @Override
     public void update(MmPredictModelEntity predictModel) {
         this.updateById(predictModel);
+        clearCache();
+    }
+
+    @Override
+    public MmPredictModelEntity getInfoFromCatch(String id) {
+        if (!modelEntityMap.containsKey(id)) {
+            MmPredictModelEntity modelEntity = getInfo(id);
+            if (modelEntity != null) {
+                modelEntityMap.put(id, modelEntity);
+            }
+        }
+        return modelEntityMap.get(id);
+    }
+
+    @Override
+    public void clearCache() {
+        modelEntityMap.clear();
+        activeModelMap.clear();
     }
 
     @Override
     public MmPredictModelEntity getInfo(String id) {
-        return baseDao.selectById(id);
+        return mmPredictModelDao.selectById(id);
     }
 
     @Override
     public BigDecimal getSampleLength(String id) {
         BigDecimal result = BigDecimal.ZERO;
-        List<MmPredictModelEntity> list = baseDao.getSampleLength(id);
+        List<MmPredictModelEntity> list = mmPredictModelDao.getSampleLength(id);
         if (CollectionUtils.isEmpty(list)) {
             return result;
         }
@@ -51,13 +79,14 @@
     public void deleteBatch(String[] itemIds) {
         QueryWrapper<MmPredictModelEntity> queryWrapper = new QueryWrapper<>();
         queryWrapper.in("itemid", itemIds);
-        baseDao.delete(queryWrapper);
+        mmPredictModelDao.delete(queryWrapper);
+        clearCache();
     }
 
     public MmPredictModelEntity getByItemid(String itemid) {
         QueryWrapper<MmPredictModelEntity> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("itemid", itemid);
-        List<MmPredictModelEntity> list = baseDao.selectList(queryWrapper);
+        List<MmPredictModelEntity> list = mmPredictModelDao.selectList(queryWrapper);
         if (CollectionUtils.isEmpty(list)) {
             return new MmPredictModelEntity();
         }
@@ -66,11 +95,19 @@
 
     @Override
     public List<MmPredictModelEntity> getNoSettingmapPredictModel(Map<String, Object> params) {
-        return baseDao.getNoSettingmapPredictModel(params);
+        return mmPredictModelDao.getNoSettingmapPredictModel(params);
     }
 
     @Override
-    public List<MmPredictModelEntity> getActiveModelByItemId(String itemId) {
-        return baseDao.getActiveModelByItemId(itemId);
+    public MmPredictModelEntity getActiveModelByItemId(String itemId) {
+        if (activeModelMap.containsKey(itemId)) {
+            return activeModelMap.get(itemId);
+        }
+        List<MmPredictModelEntity> list = mmPredictModelDao.getActiveModelByItemId(itemId);
+        if (CollectionUtils.isEmpty(list)) {
+            return null;
+        }
+        activeModelMap.put(itemId, list.get(0));
+        return activeModelMap.get(itemId);
     }
 }

--
Gitblit v1.9.3