Commit eafc944f authored by caotao's avatar caotao

修复如果es数据为空接口报错问题

parent 179470b5
...@@ -49,7 +49,7 @@ import java.util.stream.Collectors; ...@@ -49,7 +49,7 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class CommonServiceImpl { public class CommonServiceImpl {
// @Autowired // @Autowired
// InfluxdbUtil influxdbUtil; // InfluxdbUtil influxdbUtil;
@Autowired @Autowired
SjglZsjZsbtzMapper sjglZsjZsbtzMapper; SjglZsjZsbtzMapper sjglZsjZsbtzMapper;
...@@ -246,7 +246,7 @@ public class CommonServiceImpl { ...@@ -246,7 +246,7 @@ public class CommonServiceImpl {
} catch (Exception e) { } catch (Exception e) {
return totalvalue; return totalvalue;
} }
return Double.valueOf(String.format("%.4f", totalvalue )); return Double.valueOf(String.format("%.4f", totalvalue));
} }
// public Double getTotalByIndicatiorAndParams(String gatewayId, String indicator, String querySql) { // public Double getTotalByIndicatiorAndParams(String gatewayId, String indicator, String querySql) {
...@@ -371,10 +371,10 @@ public class CommonServiceImpl { ...@@ -371,10 +371,10 @@ public class CommonServiceImpl {
coal.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.standardCoal))); coal.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.standardCoal)));
socialContributionDtoList.add(coal); socialContributionDtoList.add(coal);
toner.setUnit(CommonConstans.TAN_FEN_CHEN_ZHUBIANDIYACE); toner.setUnit(CommonConstans.TAN_FEN_CHEN_ZHUBIANDIYACE);
toner.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.toner ))); toner.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.toner)));
socialContributionDtoList.add(toner); socialContributionDtoList.add(toner);
so2.setUnit(CommonConstans.ER_YANG_HUA_LIU_ZHUBIANDIYACE); so2.setUnit(CommonConstans.ER_YANG_HUA_LIU_ZHUBIANDIYACE);
so2.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.sulfurDioxide ))); so2.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.sulfurDioxide)));
socialContributionDtoList.add(so2); socialContributionDtoList.add(so2);
socialContributionDtoPage.setRecords(socialContributionDtoList); socialContributionDtoPage.setRecords(socialContributionDtoList);
socialContributionDtoPage.setTotal(100); socialContributionDtoPage.setTotal(100);
...@@ -392,10 +392,10 @@ public class CommonServiceImpl { ...@@ -392,10 +392,10 @@ public class CommonServiceImpl {
List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name")); List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name"));
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area")); List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area"));
//.isNotNull("fan_gateway_id")); //.isNotNull("fan_gateway_id"));
List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzMapper.selectList(new QueryWrapper<SjglZsjZsbtz>().isNotNull("CAPACITYL").eq("is_del","0").isNotNull("WERKS")); List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzMapper.selectList(new QueryWrapper<SjglZsjZsbtz>().isNotNull("CAPACITYL").eq("is_del", "0").isNotNull("WERKS"));
for (int i = 0; i < stationBasicList.size(); i++) { for (int i = 0; i < stationBasicList.size(); i++) {
StationBasic stationBasic = stationBasicList.get(i); StationBasic stationBasic = stationBasicList.get(i);
Double StationCapactity = sjglZsjZsbtzList.stream().filter(sjglZsjZsbtz -> sjglZsjZsbtz.getWerks().equals(stationBasic.getStationNumber())&& !StringUtils.isEmpty(sjglZsjZsbtz.getCapacityl())).collect(Collectors.toList()).stream().mapToDouble(l->Double.valueOf(l.getCapacityl())).sum(); Double StationCapactity = sjglZsjZsbtzList.stream().filter(sjglZsjZsbtz -> sjglZsjZsbtz.getWerks().equals(stationBasic.getStationNumber()) && !StringUtils.isEmpty(sjglZsjZsbtz.getCapacityl())).collect(Collectors.toList()).stream().mapToDouble(l -> Double.valueOf(l.getCapacityl())).sum();
StationCacheInfoDto stationCacheInfoDto = new StationCacheInfoDto(); StationCacheInfoDto stationCacheInfoDto = new StationCacheInfoDto();
stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString()); stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString());
stationCacheInfoDto.setStationName(stationBasic.getStationName()); stationCacheInfoDto.setStationName(stationBasic.getStationName());
...@@ -561,14 +561,15 @@ public class CommonServiceImpl { ...@@ -561,14 +561,15 @@ public class CommonServiceImpl {
public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) { public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00; Double result = 0.00;
if (!ObjectUtils.isEmpty(equipments)) {
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).average().getAsDouble(); result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).average().getAsDouble();
}
return result; return result;
} }
public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) { public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00; Double result = 0.00;
if(equipments!=null) if (equipments != null) {
{
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).sum(); result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).sum();
} }
return result; return result;
......
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