提交 | 用户 | 时间
|
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; |
047676
|
5 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
L |
6 |
import com.iailab.framework.common.pojo.PageResult; |
87d7ae
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
b3674c
|
8 |
import com.iailab.framework.common.util.date.DateUtils; |
047676
|
9 |
import com.iailab.framework.common.util.object.ConvertUtils; |
L |
10 |
import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
|
11 |
import com.iailab.module.model.mcs.pre.service.MmItemOutputService; |
87d7ae
|
12 |
import com.iailab.module.model.mcs.sche.dao.StAdjustResultDao; |
潘 |
13 |
import com.iailab.module.model.mcs.sche.entity.StAdjustResultEntity; |
|
14 |
import com.iailab.module.model.mcs.sche.service.StAdjustResultService; |
047676
|
15 |
import com.iailab.module.model.mcs.sche.vo.StAdjustResultPageReqVO; |
L |
16 |
import com.iailab.module.model.mcs.sche.vo.StAdjustResultRespVO; |
b3674c
|
17 |
import com.iailab.module.model.mdk.vo.DataValueVO; |
87d7ae
|
18 |
import lombok.extern.slf4j.Slf4j; |
b3674c
|
19 |
import org.apache.commons.lang3.StringUtils; |
047676
|
20 |
import org.springframework.beans.factory.annotation.Autowired; |
87d7ae
|
21 |
import org.springframework.stereotype.Service; |
b3674c
|
22 |
import org.springframework.util.CollectionUtils; |
潘 |
23 |
|
67f59a
|
24 |
import java.util.*; |
b3674c
|
25 |
import java.util.stream.Collectors; |
87d7ae
|
26 |
|
潘 |
27 |
/** |
|
28 |
* @author PanZhibao |
|
29 |
* @Description |
|
30 |
* @createTime 2025年02月23日 |
|
31 |
*/ |
|
32 |
@Slf4j |
|
33 |
@Service |
|
34 |
public class StAdjustResultServiceImpl extends BaseServiceImpl<StAdjustResultDao, StAdjustResultEntity> implements StAdjustResultService { |
047676
|
35 |
|
L |
36 |
@Autowired |
|
37 |
private MmItemOutputService mmItemOutputService; |
b3674c
|
38 |
|
潘 |
39 |
@Override |
67f59a
|
40 |
public void saveResult(Map<String, List<DataValueVO>> resultMap, Date predictTime, String adjustValue, String scheduleModelId, String configId) { |
D |
41 |
List<StAdjustResultEntity> list = new ArrayList<>(resultMap.size()); |
b3674c
|
42 |
for (Map.Entry<String, List<DataValueVO>> entry : resultMap.entrySet()) { |
潘 |
43 |
StAdjustResultEntity entity = new StAdjustResultEntity(); |
|
44 |
entity.setId(UUID.randomUUID().toString()); |
67f59a
|
45 |
entity.setConfigId(configId); |
D |
46 |
entity.setOutputId(entry.getKey()); |
b3674c
|
47 |
entity.setScheduleModelId(scheduleModelId); |
潘 |
48 |
entity.setAdjustTime(predictTime); |
|
49 |
entity.setAdjustValue(adjustValue); |
67f59a
|
50 |
List<Double> jsonValueList = entry.getValue().stream().map(DataValueVO::getDataValue).collect(Collectors.toList()); |
D |
51 |
entity.setJsonValue(JSONArray.toJSONString(jsonValueList)); |
|
52 |
list.add(entity); |
b3674c
|
53 |
} |
67f59a
|
54 |
baseDao.insert(list); |
b3674c
|
55 |
} |
潘 |
56 |
|
|
57 |
@Override |
|
58 |
public double[] getSimpleData(String outputId, Date predictTime, int predictLength) { |
|
59 |
double[] result = new double[predictLength]; |
|
60 |
QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
|
61 |
wrapper.eq("output_id", outputId) |
|
62 |
.eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
63 |
StAdjustResultEntity data = baseDao.selectOne(wrapper); |
67f59a
|
64 |
if (data == null || StringUtils.isBlank(data.getJsonValue())) { |
b3674c
|
65 |
return null; |
潘 |
66 |
} |
67f59a
|
67 |
List<Double> valueList = JSONArray.parseArray(data.getJsonValue(), Double.class); |
b3674c
|
68 |
if (CollectionUtils.isEmpty(valueList)) { |
潘 |
69 |
return result; |
|
70 |
} |
|
71 |
for (int i = 0; i < predictLength; i++) { |
|
72 |
result[i] = valueList.get(i); |
|
73 |
} |
|
74 |
return result; |
|
75 |
} |
047676
|
76 |
|
L |
77 |
@Override |
67f59a
|
78 |
public List<Object[]> getData(String outputId, Date predictTime, String timeFormat) { |
D |
79 |
List<Object[]> result = new ArrayList<>(); |
|
80 |
QueryWrapper<StAdjustResultEntity> wrapper = new QueryWrapper<>(); |
|
81 |
wrapper.eq("output_id", outputId) |
|
82 |
.eq("adjust_time", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
|
83 |
StAdjustResultEntity data = baseDao.selectOne(wrapper); |
|
84 |
if (data == null || StringUtils.isBlank(data.getJsonValue())) { |
|
85 |
return result; |
|
86 |
} |
|
87 |
List<Double> valueList = JSONArray.parseArray(data.getJsonValue(), Double.class); |
|
88 |
if (CollectionUtils.isEmpty(valueList)) { |
|
89 |
return result; |
|
90 |
} |
|
91 |
Calendar calendar = Calendar.getInstance(); |
|
92 |
calendar.setTime(predictTime); |
|
93 |
valueList.forEach(value -> { |
|
94 |
Object[] dv = {DateUtils.format(calendar.getTime(), timeFormat), value}; |
|
95 |
calendar.add(Calendar.MINUTE, 1); |
|
96 |
result.add(dv); |
|
97 |
}); |
|
98 |
return result; |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
047676
|
102 |
public StAdjustResultRespVO getInfo(String id) { |
L |
103 |
StAdjustResultEntity entity = baseDao.selectById(id); |
|
104 |
StAdjustResultRespVO result = ConvertUtils.sourceToTarget(entity, StAdjustResultRespVO.class); |
|
105 |
MmItemOutputEntity mmItemOutputEntity = mmItemOutputService.getOutPutById(entity.getOutputId()); |
|
106 |
result.setOutputName(mmItemOutputEntity.getResultName()); |
|
107 |
return result; |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public PageResult<StAdjustResultRespVO> page(StAdjustResultPageReqVO pageVO) { |
|
112 |
IPage<StAdjustResultRespVO> page = baseDao.selectPage(pageVO); |
|
113 |
return new PageResult<>(page.getRecords(), page.getTotal()); |
|
114 |
} |
87d7ae
|
115 |
} |