| | |
| | | import com.ruoyi.http.vo.StatisticEleRecordVo; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | |
| | | |
| | | private static void fillConsumption(TqdianbiaoEleRecord entity, JSONArray d, Integer ratio, |
| | | JSONArray sArr, JSONArray eArr) { |
| | | BigDecimal rawTotal = null; |
| | | if (d != null && !d.isEmpty()) { |
| | | rawTotal = d.getBigDecimal(0); |
| | | entity.setSharpConsumption(d.size() >= 2 ? d.getBigDecimal(1) : null); |
| | | entity.setPeakConsumption(d.size() >= 3 ? d.getBigDecimal(2) : null); |
| | | entity.setFlatConsumption(d.size() >= 4 ? d.getBigDecimal(3) : null); |
| | | entity.setValleyConsumption(d.size() >= 5 ? d.getBigDecimal(4) : null); |
| | | entity.setDeepValleyConsumption(d.size() >= 6 ? d.getBigDecimal(5) : null); |
| | | entity.setTotalConsumption(StatisticEleReadingUtil.calcConsumptionFromRaw(d.getBigDecimal(0), ratio)); |
| | | entity.setSharpConsumption(consumptionAt(d, 1, ratio)); |
| | | entity.setPeakConsumption(consumptionAt(d, 2, ratio)); |
| | | entity.setFlatConsumption(consumptionAt(d, 3, ratio)); |
| | | entity.setValleyConsumption(consumptionAt(d, 4, ratio)); |
| | | entity.setDeepValleyConsumption(consumptionAt(d, 5, ratio)); |
| | | } else { |
| | | rawTotal = StatisticEleReadingUtil.calcConsumption( |
| | | BigDecimal rawTotal = StatisticEleReadingUtil.calcConsumption( |
| | | StatisticEleReadingUtil.firstReading(sArr), |
| | | StatisticEleReadingUtil.firstReading(eArr), |
| | | 1); |
| | | entity.setTotalConsumption(StatisticEleReadingUtil.calcConsumptionFromRaw(rawTotal, ratio)); |
| | | } |
| | | entity.setTotalConsumption(StatisticEleReadingUtil.calcConsumptionFromRaw(rawTotal, ratio)); |
| | | } |
| | | |
| | | private static BigDecimal consumptionAt(JSONArray d, int index, Integer ratio) { |
| | | if (d.size() <= index) { |
| | | return null; |
| | | } |
| | | return StatisticEleReadingUtil.calcConsumptionFromRaw(d.getBigDecimal(index), ratio); |
| | | } |
| | | |
| | | private static Double toDouble(BigDecimal value) { |
| | | return value == null ? null : value.doubleValue(); |
| | | if (value == null) { |
| | | return null; |
| | | } |
| | | return value.setScale(StatisticEleReadingUtil.CONSUMPTION_SCALE, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | } |