houzhongjian
2024-12-05 a709abfd8ffec1524cefff30c3581f4425695433
提交 | 用户 | 时间
7fd198 1 package com.iailab.module.model.mcs.pre.service.impl;
2
3 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5c6007 4 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7fd198 5 import com.iailab.module.model.mcs.pre.dao.MmModelParamDao;
6 import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity;
7 import com.iailab.module.model.mcs.pre.service.MmModelParamService;
5c6007 8 import org.springframework.beans.factory.annotation.Autowired;
7fd198 9 import org.springframework.stereotype.Service;
10 import org.springframework.util.CollectionUtils;
11
91343d 12 import java.util.*;
13 import java.util.concurrent.ConcurrentHashMap;
7fd198 14
15 /**
16  * @author PanZhibao
17  * @date 2021年04月27日 9:25
18  */
5c6007 19 @Service
L 20 public class MmModelParamServiceImpl extends ServiceImpl<MmModelParamDao, MmModelParamEntity> implements MmModelParamService {
7fd198 21
5c6007 22     @Autowired
L 23     private MmModelParamDao mmModelParamDao;
91343d 24
25     private static Map<String, List<MmModelParamEntity>> modelInputParamMap = new ConcurrentHashMap<>();
5c6007 26     
7fd198 27     @Override
28     public void saveList(List<MmModelParamEntity> list) {
29         QueryWrapper<MmModelParamEntity> queryWrapper = new QueryWrapper();
30         queryWrapper.eq("modelid", list.get(0).getModelid());
5c6007 31         mmModelParamDao.delete(queryWrapper);
7fd198 32         list.forEach(item -> {
33             item.setId(UUID.randomUUID().toString());
5c6007 34             mmModelParamDao.insert(item);
7fd198 35         });
91343d 36
37         // 清空缓存
38         clearCache();
7fd198 39     }
40
41     @Override
91343d 42     public void clearCache() {
43         modelInputParamMap.clear();
44     }
45
46     @Override
45520a 47     public List<MmModelParamEntity> getByModelidFromCache(String modelId) {
91343d 48         if (!modelInputParamMap.containsKey(modelId)) {
49             List<MmModelParamEntity> list = getByModelid(modelId);
50             if (list != null) {
51                 modelInputParamMap.put(modelId, list);
52             } else {
53                 return null;
54             }
55         }
56         return modelInputParamMap.get(modelId);
57     }
58
59
60     @Override
7fd198 61     public List<MmModelParamEntity> getByModelid(String modelid) {
62         QueryWrapper<MmModelParamEntity> queryWrapper = new QueryWrapper();
63         queryWrapper.eq("modelid", modelid);
64         queryWrapper.orderByAsc("MODELPARAMPORTORDER");
65         queryWrapper.orderByAsc("MODELPARAMORDER");
5c6007 66         List<MmModelParamEntity> list = mmModelParamDao.selectList(queryWrapper);
7fd198 67         if (CollectionUtils.isEmpty(list)) {
68             return new ArrayList<>();
69         }
70         return list;
71     }
72 }