From 21427594e600cf501e227706f229b7b767d8db4c Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期四, 14 十一月 2024 18:11:44 +0800 Subject: [PATCH] 增加缓存 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java | 30 +++++++++++++++--------------- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java | 8 +++++++- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java | 2 +- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java index 15daa2d..c9b2c35 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java @@ -261,8 +261,8 @@ } valueDTOS.forEach(item -> { Object[] values = new Object[2]; - values[0] = DateUtils.format(item.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); - values[1] = new BigDecimal(item.getDataValue()).setScale(2, BigDecimal.ROUND_HALF_UP); + values[0] = DateUtils.format(item.getT(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); result.add(values); }); return result; diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java index e84ba70..8059a9f 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmModelArithSettingsServiceImpl.java @@ -1,10 +1,7 @@ package com.iailab.module.model.mcs.pre.service.impl; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.iailab.framework.common.service.impl.BaseServiceImpl; -import com.iailab.module.model.mcs.pre.dao.MmItemTypeDao; 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; @@ -13,6 +10,7 @@ import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** * @author PanZhibao @@ -25,6 +23,8 @@ @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(); @@ -34,23 +34,23 @@ item.setId(UUID.randomUUID().toString()); }); mmModelArithSettingsDao.insertList(list); - } - public List<MmModelArithSettingsEntity> getByModelid(String modelid) { - Map<String, Object> params = new HashMap<>(1); - params.put("modelid", modelid); - List<MmModelArithSettingsEntity> list = mmModelArithSettingsDao.getMmModelArithSettings(params); - - if (CollectionUtils.isEmpty(list)) { - return new ArrayList<>(); - } - return list; + // 清空缓存 + modelIdMap.clear(); } @Override public List<MmModelArithSettingsEntity> getByModelId(String modelId) { - Map<String, Object> params = new HashMap<>(); + if (modelIdMap.containsKey(modelId)) { + return modelIdMap.get(modelId); + } + Map<String, Object> params = new HashMap<>(1); params.put("modelid", modelId); - return mmModelArithSettingsDao.getMmModelArithSettings(params); + List<MmModelArithSettingsEntity> list = mmModelArithSettingsDao.getMmModelArithSettings(params); + if (CollectionUtils.isEmpty(list)) { + list = new ArrayList<>(); + } + modelIdMap.put(modelId, list); + return list; } } diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java index 5b1b9e5..f595abc 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmPredictItemServiceImpl.java @@ -188,7 +188,7 @@ if (itemType != null && ItemTypeEnum.NORMAL_ITEM.getName().equals(itemType.getItemtypename())) { MmPredictModelEntity mmPredictModel = mmPredictModelService.getByItemid(id); mmPredictItemDto.setMmPredictModel(mmPredictModel); - mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelid(mmPredictModel.getId())); + mmPredictItemDto.setMmModelArithSettingsList(mmModelArithSettingsService.getByModelId(mmPredictModel.getId())); mmPredictItemDto.setMmModelParamList(mmModelParamService.getByModelid(mmPredictModel.getId())); mmPredictItemDto.setMmPredictMergeItem(new MmPredictMergeItemEntity()); } else if (itemType != null && ItemTypeEnum.MERGE_ITEM.getName().equals(itemType.getItemtypename())) { diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java index c9a6afa..bb4171f 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/PredictSampleDataConstructor.java @@ -20,6 +20,7 @@ import java.math.BigDecimal; import java.util.*; +import java.util.stream.Collectors; /** * 预测样本数据构造 @@ -129,7 +130,12 @@ queryDto.setStart(columnItem.getStartTime()); queryDto.setEnd(columnItem.getEndTime()); List<ApiPointValueDTO> pointValueList = dataPointApi.queryPointHistoryValue(queryDto); - dataList = ConvertUtils.sourceToTarget(pointValueList, DataValueVO.class); + dataList = pointValueList.stream().map( t-> { + DataValueVO vo = new DataValueVO(); + vo.setDataTime(t.getT()); + vo.setDataValue(t.getV()); + return vo; + }).collect(Collectors.toList()); break; case "PREDICTITEM": MmItemOutputVO outPut = itemEntityFactory.getItemOutPutById(columnItem.getId()); -- Gitblit v1.9.3