| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
| | | import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
| | | import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
| | | |
| | | @Override |
| | | public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId) { |
| | | for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
| | | StAdjustResultEntity entity = new StAdjustResultEntity(); |
| | | entity.setId(UUID.randomUUID().toString()); |
| | | entity.setScheduleModelId(scheduleModelId); |
| | | entity.setAdjustTime(predictTime); |
| | | entity.setAdjustValue(adjustValue); |
| | | entity.setOutputId(entry.getKey()); |
| | | List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList()); |
| | | entity.setAdjustValue(JSONArray.toJSONString(jsonValueList)); |
| | | baseDao.insert(entity); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
| | | double[] result = new double[predictLength]; |
| | | QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("output_id", outputId) |
| | | .eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | StAdjustResultEntity data = baseDao.selectOne(wrapper); |
| | | if (data == null || StringUtils.isBlank(data.getAdjustValue())) { |
| | | return null; |
| | | } |
| | | List<Double> valueList = JSONArray.parseArray(data.getAdjustValue(), Double.class); |
| | | if (CollectionUtils.isEmpty(valueList)) { |
| | | return result; |
| | | } |
| | | for (int i = 0; i < predictLength; i++) { |
| | | result[i] = valueList.get(i); |
| | | } |
| | | return result; |
| | | } |
| | | } |