From f1fe397df175a7ee809ea28530419116af84af28 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期二, 31 十二月 2024 17:32:45 +0800 Subject: [PATCH] t_mm_item_result 索引优化 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java | 42 ++++++++++++++++++++++++++++++------------ 1 files changed, 30 insertions(+), 12 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java index 7bd1223..26f58e5 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.mcs.pre.dao.MmItemResultDao; +import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity; import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity; import com.iailab.module.model.mcs.pre.service.MmItemResultService; @@ -14,8 +15,6 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -75,20 +74,24 @@ resultJson.setId(UUID.randomUUID().toString()); resultJson.setOutputid(entry.getKey()); resultJson.setPredicttime(predictTime); - resultJson.setJsonvalue(JSONArray.toJSONString(entry.getValue())); + List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> { + return valueVO.getDataValue(); + }).collect(Collectors.toList()); + resultJson.setJsonvalue(JSONArray.toJSONString(jsonValueList)); Map<String, Object> map4 = new HashMap(2); map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON"); map4.put("entity", resultJson); mmItemResultDao.savePredictJsonValue(map4); - Map<String, Object> params = new HashMap(4); - params.put("TABLENAME", T_MM_ITEM_RESULT); - params.put("OUTPUTID", entry.getKey()); - params.put("STARTTIME", importList.get(0).getDatatime()); - params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); - mmItemResultDao.deletePredictValue(params); +// Map<String, Object> params = new HashMap(4); +// params.put("TABLENAME", T_MM_ITEM_RESULT); +// params.put("OUTPUTID", entry.getKey()); +// params.put("STARTTIME", importList.get(0).getDatatime()); +// params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); +// mmItemResultDao.deletePredictValue(params); } - mmItemResultDao.insertBatch(importList,max_group_count); + // 存在则修改,不存在插入 + mmItemResultDao.saveOrUpdateItemResult(importList); Map<String, Object> map3 = new HashMap<>(2); map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT"); @@ -117,7 +120,7 @@ } @Override - public List<Object[]> getData(String outputid, Date startTime, Date endTime) { + public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); QueryWrapper<MmItemResultEntity> queryWrapper = new QueryWrapper<MmItemResultEntity>() .eq("outputid", outputid) @@ -129,10 +132,25 @@ } list.forEach(item -> { Object[] dataItem = new Object[2]; - dataItem[0] = DateUtils.format(item.getDatatime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + dataItem[0] = DateUtils.format(item.getDatatime(), timeFormat); dataItem[1] = item.getDatavalue().setScale(2, BigDecimal.ROUND_HALF_UP); result.add(dataItem); }); return result; } + + @Override + public void savePredictValue(Map<MmItemOutputEntity, Double> predictDoubleValues, Date predictTime) { + for (Map.Entry<MmItemOutputEntity, Double> entry : predictDoubleValues.entrySet()) { + MmItemResultJsonEntity resultJson = new MmItemResultJsonEntity(); + resultJson.setId(UUID.randomUUID().toString()); + resultJson.setOutputid(entry.getKey().getId()); + resultJson.setPredicttime(predictTime); + resultJson.setCumulant(String.valueOf(entry.getValue())); + Map<String, Object> map4 = new HashMap(2); + map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON"); + map4.put("entity", resultJson); + mmItemResultDao.savePredictJsonValue(map4); + } + } } -- Gitblit v1.9.3