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.MmModelParamDao; import com.iailab.module.model.mcs.pre.entity.MmModelParamEntity; import com.iailab.module.model.mcs.pre.service.MmModelParamService; 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:25 */ @Service public class MmModelParamServiceImpl extends ServiceImpl implements MmModelParamService { @Autowired private MmModelParamDao mmModelParamDao; private static Map> modelInputParamMap = new ConcurrentHashMap<>(); @Override public void saveList(List list) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("modelid", list.get(0).getModelid()); mmModelParamDao.delete(queryWrapper); list.forEach(item -> { item.setId(UUID.randomUUID().toString()); mmModelParamDao.insert(item); }); // 清空缓存 clearCache(); } @Override public void clearCache() { modelInputParamMap.clear(); } @Override public List getByModelidFromCache(String modelId) { if (!modelInputParamMap.containsKey(modelId)) { List list = getByModelid(modelId); if (list != null) { modelInputParamMap.put(modelId, list); } else { return null; } } return modelInputParamMap.get(modelId); } @Override public List getByModelid(String modelid) { QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.eq("modelid", modelid); queryWrapper.orderByAsc("MODELPARAMPORTORDER"); queryWrapper.orderByAsc("MODELPARAMORDER"); List list = mmModelParamDao.selectList(queryWrapper); if (CollectionUtils.isEmpty(list)) { return new ArrayList<>(); } return list; } }