Commit ae0d3b3f authored by suhuiguang's avatar suhuiguang

1.气瓶大屏-气瓶-区域统计接口统计接口增加单位换算,数据大于10万时图列为万并进行单位换算

parent 4f467c0e
...@@ -30,6 +30,8 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; ...@@ -30,6 +30,8 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
...@@ -51,12 +53,16 @@ public class CylinderDPStatisticsServiceImpl { ...@@ -51,12 +53,16 @@ public class CylinderDPStatisticsServiceImpl {
private TzBaseEnterpriseInfoMapper baseEnterpriseInfoMapper; private TzBaseEnterpriseInfoMapper baseEnterpriseInfoMapper;
private CylinderAreaDataMapper cylinderAreaDataMapper; private CylinderAreaDataMapper cylinderAreaDataMapper;
;
private CylinderStatisticsMapper cylinderStatisticsMapper; private CylinderStatisticsMapper cylinderStatisticsMapper;
private CylinderInfoMapper cylinderInfoMapper; private CylinderInfoMapper cylinderInfoMapper;
/**
* 气瓶图列换算单位上限
*/
private final static Long CYLINDER_LEGEND_UPPER_LIMIT = 100000L;
public CylinderDPStatisticsServiceImpl(StCommonServiceImpl stCommonService, RestHighLevelClient restHighLevelClient, TzBaseEnterpriseInfoMapper baseEnterpriseInfoMapper, CylinderAreaDataMapper cylinderAreaDataMapper, CylinderStatisticsMapper cylinderStatisticsMapper, CylinderInfoMapper cylinderInfoMapper) { public CylinderDPStatisticsServiceImpl(StCommonServiceImpl stCommonService, RestHighLevelClient restHighLevelClient, TzBaseEnterpriseInfoMapper baseEnterpriseInfoMapper, CylinderAreaDataMapper cylinderAreaDataMapper, CylinderStatisticsMapper cylinderStatisticsMapper, CylinderInfoMapper cylinderInfoMapper) {
this.stCommonService = stCommonService; this.stCommonService = stCommonService;
this.restHighLevelClient = restHighLevelClient; this.restHighLevelClient = restHighLevelClient;
...@@ -128,19 +134,43 @@ public class CylinderDPStatisticsServiceImpl { ...@@ -128,19 +134,43 @@ public class CylinderDPStatisticsServiceImpl {
List<Map<String, Object>> legendData = new ArrayList<>(); List<Map<String, Object>> legendData = new ArrayList<>();
List<String> xdata = this.buildXData(regionList); List<String> xdata = this.buildXData(regionList);
List<Long> qiping = getYDataForQP(regionList); List<Long> qiping = getYDataForQP(regionList);
Long totalCyNum = qiping.stream().mapToLong(e -> e).sum();
List<Long> qizhan = getYDataForQZ(regionList); List<Long> qizhan = getYDataForQZ(regionList);
Map<String, Object> qiLegend = getQZLegend("气瓶数量", "qiping"); Map<String, Object> qiLegend = getQPLegend(totalCyNum);
Map<String, Object> zhanLegend = getQZLegend("气站数量", "qizhan"); Map<String, Object> zhanLegend = getQZLegend("气站数量", "qizhan");
legendData.add(qiLegend); legendData.add(qiLegend);
legendData.add(zhanLegend); legendData.add(zhanLegend);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("qizhan", qizhan); result.put("qizhan", qizhan);
result.put("qiping", qiping); result.put("qiping", this.changeNum2Million(totalCyNum, qiping));
result.put("xdata", xdata); result.put("xdata", xdata);
result.put("legendData", legendData); result.put("legendData", legendData);
return result; return result;
} }
private List changeNum2Million(Long totalCyNum, List<Long> qiping) {
if (totalCyNum > CYLINDER_LEGEND_UPPER_LIMIT) {
return qiping.stream().map(num -> {
BigDecimal numDecimal = new BigDecimal(num.toString());
BigDecimal millionNum = numDecimal.divide(new BigDecimal("10000"), 4, RoundingMode.HALF_UP);
return millionNum.toPlainString();
}).collect(Collectors.toList());
} else {
return qiping;
}
}
private Map<String, Object> getQPLegend(Long totalCyNum) {
Map<String, Object> qiLegend = new HashMap<>();
if (totalCyNum > CYLINDER_LEGEND_UPPER_LIMIT) {
qiLegend.put("value", "气瓶数量(万)");
} else {
qiLegend.put("value", "气瓶数量");
}
qiLegend.put("dataKey", "qiping");
return qiLegend;
}
private Map<String, Object> getQZLegend(String label, String key) { private Map<String, Object> getQZLegend(String label, String key) {
Map<String, Object> qiLegend = new HashMap<>(); Map<String, Object> qiLegend = new HashMap<>();
qiLegend.put("value", label); qiLegend.put("value", label);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment