dengzedong
2024-12-05 45520aea38a87bfb262149d5c7b89d482cab07b9
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.iailab.module.model.mcs.sche.service.impl;
 
import com.iailab.framework.common.service.impl.BaseServiceImpl;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.iailab.module.model.mcs.sche.dao.StScheduleModelParamDao;
import com.iailab.module.model.mcs.sche.entity.StScheduleModelParamEntity;
import com.iailab.module.model.mcs.sche.service.StScheduleModelParamService;
import com.iailab.module.model.mcs.sche.vo.StScheduleModelParamSaveReqVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2024年09月06日
 */
@Service
public class StScheduleModelParamServiceImpl extends BaseServiceImpl<StScheduleModelParamDao, StScheduleModelParamEntity>
        implements StScheduleModelParamService {
 
    private static Map<String, List<StScheduleModelParamEntity>> modelInputParamMap = new ConcurrentHashMap<>();
 
    @Override
    public List<StScheduleModelParamEntity> getByModelId(String modelId) {
        return baseDao.selectList(
                new LambdaQueryWrapperX<StScheduleModelParamEntity>()
                        .likeIfPresent(StScheduleModelParamEntity::getModelid, modelId)
                        .orderByAsc(StScheduleModelParamEntity::getModelparamportorder)
                        .orderByAsc(StScheduleModelParamEntity::getModelparamorder)
        );
    }
 
    @Override
    public void deleteByModelId(String modelId) {
        baseDao.delete(new LambdaQueryWrapperX<StScheduleModelParamEntity>()
                .likeIfPresent(StScheduleModelParamEntity::getModelid, modelId)
        );
    }
 
    @Override
    public void saveList(String modelId, List<StScheduleModelParamSaveReqVO> saveList) {
        deleteByModelId(modelId);
        if (CollectionUtils.isEmpty(saveList)) {
            return;
        }
        saveList.forEach(item -> {
            StScheduleModelParamEntity entity = BeanUtils.toBean(item, StScheduleModelParamEntity.class);
            entity.setId(UUID.randomUUID().toString());
            entity.setModelid(modelId);
            baseDao.insert(entity);
        });
        clearCache();
    }
 
    @Override
    public List<StScheduleModelParamEntity> getByModelidFromCache(String modelId) {
        if (!modelInputParamMap.containsKey(modelId)) {
            List<StScheduleModelParamEntity> list = getByModelId(modelId);
            if (list != null) {
                modelInputParamMap.put(modelId, list);
            } else {
                return null;
            }
        }
        return modelInputParamMap.get(modelId);
    }
 
    public void clearCache() {
        modelInputParamMap.clear();
    }
}