Commit eafc944f authored by caotao's avatar caotao

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

parent 179470b5
......@@ -49,7 +49,7 @@ import java.util.stream.Collectors;
@Slf4j
public class CommonServiceImpl {
// @Autowired
// @Autowired
// InfluxdbUtil influxdbUtil;
@Autowired
SjglZsjZsbtzMapper sjglZsjZsbtzMapper;
......@@ -246,7 +246,7 @@ public class CommonServiceImpl {
} catch (Exception e) {
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) {
......@@ -371,10 +371,10 @@ public class CommonServiceImpl {
coal.setTitle(String.format("%.2f", (totalSocialContribution * CommonConstans.standardCoal)));
socialContributionDtoList.add(coal);
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);
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);
socialContributionDtoPage.setRecords(socialContributionDtoList);
socialContributionDtoPage.setTotal(100);
......@@ -391,11 +391,11 @@ public class CommonServiceImpl {
List<Region> regionList = regionMapper.selectList(new QueryWrapper<Region>().eq("LEVEL", 1));
List<MapRegion> mapRegionList = mapRegionMapper.selectList(new QueryWrapper<MapRegion>().isNotNull("name"));
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area"));
//.isNotNull("fan_gateway_id"));
List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzMapper.selectList(new QueryWrapper<SjglZsjZsbtz>().isNotNull("CAPACITYL").eq("is_del","0").isNotNull("WERKS"));
//.isNotNull("fan_gateway_id"));
List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzMapper.selectList(new QueryWrapper<SjglZsjZsbtz>().isNotNull("CAPACITYL").eq("is_del", "0").isNotNull("WERKS"));
for (int i = 0; i < stationBasicList.size(); 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.setStationId(stationBasic.getSequenceNbr().toString());
stationCacheInfoDto.setStationName(stationBasic.getStationName());
......@@ -561,15 +561,16 @@ public class CommonServiceImpl {
public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00;
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).average().getAsDouble();
if (!ObjectUtils.isEmpty(equipments)) {
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).average().getAsDouble();
}
return result;
}
public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00;
if(equipments!=null)
{
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).sum();
if (equipments != null) {
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).filter(esEquipments -> esEquipments.getValueF() != null).mapToDouble(ESEquipments::getValueF).sum();
}
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