提交 | 用户 | 时间
|
87d7ae
|
1 |
package com.iailab.module.model.mcs.sche.service.impl; |
潘 |
2 |
|
b3674c
|
3 |
import com.alibaba.fastjson.JSONArray; |
潘 |
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
87d7ae
|
5 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
b3674c
|
6 |
import com.iailab.framework.common.util.date.DateUtils; |
87d7ae
|
7 |
import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
潘 |
8 |
import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
|
9 |
import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
b3674c
|
10 |
import com.iailab.module.model.mdk.vo.DataValueVO; |
87d7ae
|
11 |
import lombok.extern.slf4j.Slf4j; |
b3674c
|
12 |
import org.apache.commons.lang3.StringUtils; |
87d7ae
|
13 |
import org.springframework.stereotype.Service; |
b3674c
|
14 |
import org.springframework.util.CollectionUtils; |
潘 |
15 |
|
|
16 |
import java.util.Date; |
|
17 |
import java.util.List; |
|
18 |
import java.util.Map; |
|
19 |
import java.util.UUID; |
|
20 |
import java.util.stream.Collectors; |
87d7ae
|
21 |
|
潘 |
22 |
/** |
|
23 |
* @author PanZhibao |
|
24 |
* @Description |
|
25 |
* @createTime 2025年02月23日 |
|
26 |
*/ |
|
27 |
@Slf4j |
|
28 |
@Service |
|
29 |
public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
b3674c
|
30 |
|
潘 |
31 |
@Override |
|
32 |
public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId) { |
|
33 |
for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
|
34 |
StAdjustResultEntity entity = new StAdjustResultEntity(); |
|
35 |
entity.setId(UUID.randomUUID().toString()); |
|
36 |
entity.setScheduleModelId(scheduleModelId); |
|
37 |
entity.setAdjustTime(predictTime); |
|
38 |
entity.setAdjustValue(adjustValue); |
|
39 |
entity.setOutputId(entry.getKey()); |
|
40 |
List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList()); |
|
41 |
entity.setAdjustValue(JSONArray.toJSONString(jsonValueList)); |
|
42 |
baseDao.insert(entity); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
|
48 |
double[] result = new double[predictLength]; |
|
49 |
QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
|
50 |
wrapper.eq("output_id", outputId) |
|
51 |
.eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
52 |
StAdjustResultEntity data = baseDao.selectOne(wrapper); |
|
53 |
if (data == null || StringUtils.isBlank(data.getAdjustValue())) { |
|
54 |
return null; |
|
55 |
} |
|
56 |
List<Double> valueList = JSONArray.parseArray(data.getAdjustValue(), Double.class); |
|
57 |
if (CollectionUtils.isEmpty(valueList)) { |
|
58 |
return result; |
|
59 |
} |
|
60 |
for (int i = 0; i < predictLength; i++) { |
|
61 |
result[i] = valueList.get(i); |
|
62 |
} |
|
63 |
return result; |
|
64 |
} |
87d7ae
|
65 |
} |