dengzedong
2 天以前 9ca51bfce6582bb0fbb61fb20312b58d4c915aba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.iailab.module.model.mcs.pre.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iailab.module.model.mcs.pre.dao.MmModelArithSettingsDao;
import com.iailab.module.model.mcs.pre.entity.MmModelArithSettingsEntity;
import com.iailab.module.model.mcs.pre.service.MmModelArithSettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * @author PanZhibao
 * @date 2021年04月27日 9:24
 */
@Service
public class MmModelArithSettingsServiceImpl extends ServiceImpl<MmModelArithSettingsDao, MmModelArithSettingsEntity>
        implements MmModelArithSettingsService {
 
    @Autowired
    private MmModelArithSettingsDao mmModelArithSettingsDao;
 
    private static Map<String, List<MmModelArithSettingsEntity>> modelIdMap = new ConcurrentHashMap<>();
 
    @Override
    public void saveList(List<MmModelArithSettingsEntity> list) {
        QueryWrapper<MmModelArithSettingsEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq("modelid", list.get(0).getModelid());
        mmModelArithSettingsDao.delete(queryWrapper);
        list.forEach(item -> {
            item.setId(UUID.randomUUID().toString());
        });
        mmModelArithSettingsDao.insertList(list);
 
        // 清空缓存
        modelIdMap.clear();
    }
 
    @Override
    public List<MmModelArithSettingsEntity> getByModelId(String modelId) {
        if (modelIdMap.containsKey(modelId)) {
            return modelIdMap.get(modelId);
        }
        Map<String, Object> params = new HashMap<>(1);
        params.put("modelid", modelId);
        List<MmModelArithSettingsEntity> list =  mmModelArithSettingsDao.getMmModelArithSettings(params);
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
        }
        modelIdMap.put(modelId, list);
        return list;
    }
 
    @Override
    public void updatePyFile(String pyModule, String fileName) {
        baseMapper.updatePyFile(pyModule + "." + fileName.substring(0,fileName.lastIndexOf("_")+1),pyModule + "." + fileName);
        // 清空缓存
        modelIdMap.clear();
    }
}