提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.ind.collection.handler; |
H |
2 |
|
|
3 |
import com.iailab.module.data.ind.service.IndItemService; |
|
4 |
import com.iailab.module.data.ind.service.IndItemService; |
|
5 |
import com.iailab.module.data.ind.collection.utils.IndSqlUtils; |
|
6 |
import com.iailab.module.data.ind.dao.IndItemValueDao; |
|
7 |
import com.iailab.module.data.ind.dto.IndItemDTO; |
|
8 |
import com.iailab.module.data.ind.dto.IndItemValueDTO; |
|
9 |
import com.iailab.module.data.ind.service.IndItemService; |
|
10 |
import com.iailab.module.data.ind.service.IndItemService; |
|
11 |
import lombok.extern.slf4j.Slf4j; |
|
12 |
import javax.annotation.Resource; |
|
13 |
import org.springframework.stereotype.Component; |
|
14 |
|
|
15 |
import javax.annotation.Resource; |
|
16 |
import java.math.BigDecimal; |
|
17 |
import java.util.ArrayList; |
|
18 |
import java.util.List; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author PanZhibao |
|
22 |
* @Description |
|
23 |
* @createTime 2024年05月25日 |
|
24 |
*/ |
|
25 |
@Slf4j |
|
26 |
@Component |
|
27 |
public class AtomItemHandle { |
|
28 |
|
|
29 |
@Resource |
|
30 |
private IndItemService indItemService; |
|
31 |
|
|
32 |
@Resource |
|
33 |
private IndItemValueDao indItemValueDao; |
|
34 |
|
|
35 |
|
|
36 |
public List<IndItemValueDTO> getItemSourceValue(String itemNo) { |
|
37 |
List<IndItemValueDTO> result = new ArrayList<>(); |
|
38 |
IndItemDTO indItemDTO = indItemService.getItemAtom(itemNo); |
|
39 |
if (indItemDTO == null) { |
|
40 |
return result; |
|
41 |
} |
|
42 |
try { |
|
43 |
StringBuilder sqlSelect = new StringBuilder(); |
|
44 |
sqlSelect.append(" data_value, data_time "); |
|
45 |
indItemDTO.setSqlSelect(sqlSelect.toString()); |
|
46 |
indItemDTO.setSqlWhere(IndSqlUtils.getSqlWhere(indItemDTO.getTimeRange(), indItemDTO.getTimeGranularity())); |
|
47 |
result = indItemValueDao.getSourceValue(indItemDTO); |
|
48 |
} catch (Exception ex) { |
|
49 |
ex.printStackTrace(); |
|
50 |
} |
|
51 |
|
|
52 |
result.forEach(item -> { |
|
53 |
if (indItemDTO.getCoefficient() != null) { |
|
54 |
item.setDataValue(item.getDataValue().multiply(indItemDTO.getCoefficient())); |
|
55 |
} |
|
56 |
if (indItemDTO.getPrecision() != null) { |
|
57 |
item.setDataValue(item.getDataValue().setScale(indItemDTO.getPrecision(), BigDecimal.ROUND_HALF_UP)); |
|
58 |
} |
|
59 |
item.setItemNo(itemNo); |
|
60 |
}); |
|
61 |
return result; |
|
62 |
} |
|
63 |
|
|
64 |
public List<IndItemValueDTO> getItemSourceValue(String itemNo, String start, String end) { |
|
65 |
List<IndItemValueDTO> result = new ArrayList<>(); |
|
66 |
IndItemDTO indItemDTO = indItemService.getItemAtom(itemNo); |
|
67 |
if (indItemDTO == null) { |
|
68 |
return result; |
|
69 |
} |
|
70 |
try { |
|
71 |
StringBuilder sqlSelect = new StringBuilder(); |
|
72 |
sqlSelect.append(" data_value, data_time "); |
|
73 |
indItemDTO.setSqlSelect(sqlSelect.toString()); |
|
74 |
indItemDTO.setSqlWhere(IndSqlUtils.getSqlWhereByRange(start, end)); |
|
75 |
result = indItemValueDao.getSourceValue(indItemDTO); |
|
76 |
} catch (Exception ex) { |
|
77 |
ex.printStackTrace(); |
|
78 |
} |
|
79 |
|
|
80 |
result.forEach(item -> { |
|
81 |
if (indItemDTO.getCoefficient() != null) { |
|
82 |
item.setDataValue(item.getDataValue().multiply(indItemDTO.getCoefficient())); |
|
83 |
} |
|
84 |
if (indItemDTO.getPrecision() != null) { |
|
85 |
item.setDataValue(item.getDataValue().setScale(indItemDTO.getPrecision(), BigDecimal.ROUND_HALF_UP)); |
|
86 |
} |
|
87 |
item.setItemNo(itemNo); |
|
88 |
}); |
|
89 |
return result; |
|
90 |
} |
|
91 |
} |