Commit b98d2ad5 authored by suhuiguang's avatar suhuiguang

1.大屏-气瓶-区域安全指数统计接口新写

parent 6f37533a
......@@ -41,18 +41,16 @@ public class AQZSDPStatisticsController {
Map<String, Object> result = statisticsService.getSecurityIndex(dpFilterParamDto);
return ResponseHelper.buildResponse(result);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "大屏-气瓶-区域安全指数统计")
@RequestMapping(value = "/earlyWarning/child", method = RequestMethod.POST)
public ResponseModel<Map<String, Object>> getChildEarlyWarning(@RequestBody Map<String, Object> map) throws Exception {
Object regionCode = map.get("cityCode");
if (ObjectUtils.isEmpty(regionCode)) {
regionCode = "610000";
public ResponseModel<Map<String, Object>> getChildEarlyWarning(@Validated @RequestBody DPFilterParamDto dpFilterParamDto, BindingResult bindingResult) throws Exception {
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
if (!fieldErrors.isEmpty()) {
throw new BadRequest(fieldErrors.get(0).getDefaultMessage());
}
return ResponseHelper.buildResponse(statisticsService.getChildEarlyWarning(regionCode.toString()));
return ResponseHelper.buildResponse(statisticsService.getChildEarlyWarning(dpFilterParamDto));
}
......
......@@ -10,10 +10,7 @@ import com.yeejoin.amos.boot.module.statistics.api.dto.SecurityIndexCountItemDto
import com.yeejoin.amos.boot.module.statistics.api.mapper.AQZSDPStatisticsMapper;
import com.yeejoin.amos.boot.module.statistics.api.mapper.CylinderStatisticsMapper;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentClassifityEnum;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import joptsimple.internal.Strings;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
......@@ -23,7 +20,6 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.io.IOException;
import java.math.BigDecimal;
......@@ -123,73 +119,28 @@ public class AQZSDPStatisticsServiceImpl {
}
}
public Map<String, Object> getChildEarlyWarning(String regionCode) throws Exception {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(regionCode);
List<String> collect = regionModels.stream().map(c -> c.getRegionCode().toString()).collect(Collectors.toList());
List<CompanyModel> companyModelList = Privilege.companyClient.queryListByCompanyCode(Strings.join(collect, ",")).getResult();
Map<String, CompanyModel> companyMap = companyModelList.stream().collect(Collectors.toMap(CompanyModel::getCompanyCode, c -> c));
Set<String> legendData = new HashSet<>();
List<String> xdata = new ArrayList<>();
public Map<String, Object> getChildEarlyWarning(DPFilterParamDto dpFilterParamDto) throws Exception {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto.getCityCode());
Map<String, SecurityIndexCountItemDto> regionCodeSecurityIndexMap = getSecurityIndexCountItemDtoMap(regionModels);
Set<String> legendData = getLegendForCyArea();
List<String> xuke = new ArrayList<>();
List<String> shiyongdengji = new ArrayList<>();
List<String> jianyanchaoqi = new ArrayList<>();
List<String> jianyanhege = new ArrayList<>();
List<String> czjc = new ArrayList<>();
List<String> czjchege = new ArrayList<>();
// List<String> renyuan = new ArrayList<>();
legendData.add("许可有效率");
legendData.add("使用登记办理率");
legendData.add("检验超期率");
legendData.add("检验合格率");
legendData.add("充装检查率");
legendData.add("充装检查合格率");
for (RegionModel region : regionModels) {
CompanyModel companyModel = companyMap.get(region.getRegionCode().toString());
if (ObjectUtils.isEmpty(companyModel)) {
continue;
}
// 是否有充装企业在指定区域下
Boolean isHavingUnitInRegion = true;
String orgCode = companyModel.getOrgCode();
xdata.add(region.getRegionName());
// 1.许可有效率
if (!ValidationUtil.isEmpty(companyModel)) {
String value = this.getLicenseEfficiencyByRegion(orgCode);
if (NO_DATA_STR.equals(value)) {
xuke.add("0");
} else {
xuke.add(String.format("%.4f", Double.parseDouble(value) / 100.0000));
}
}
// 2.使用登记办理率
shiyongdengji.add("1");
// 3.检验超期率
jianyanchaoqi.add(String.format("%.4f", Double.parseDouble(statisticsMapper.getInspectionExpiredRate(orgCode, null).get("expiredRate").toString()) / 100.0000));
// 4.检验合格率
jianyanhege.add(String.format("%.4f", Double.parseDouble(statisticsMapper.getInspectionResultRate(orgCode, null).get("resultRate").toString()) / 100.0000));
// 5.充装检查率
long totalAll = searchEsCount(false, false, orgCode, null);
long totalCheck = searchEsCount(true, false, orgCode, null);
long totalResult = searchEsCount(false, true, orgCode, null);
if (totalAll != 0) {
czjc.add(new DecimalFormat("#.0000").format(((double) totalCheck / totalAll)));
} else {
czjc.add("0");
}
// 6.充装检查合格率
if (totalAll != 0) {
czjchege.add(new DecimalFormat("#.0000").format(((double) totalResult / totalAll)));
} else {
czjchege.add("0");
}
}
//TODO 多线程处理后,regionCodeSecurityIndexMap顺序与regionModels的顺序不一致,需让数据和x轴的顺序保存一致
List<String> xdata = stCommonService.buildXData(regionModels);
regionModels.forEach(r -> {
SecurityIndexCountItemDto countItemDto = regionCodeSecurityIndexMap.get(r.getRegionCode().toString());
xuke.add(countItemDto.getXuke());
shiyongdengji.add(countItemDto.getShiyongdengji());
jianyanchaoqi.add(countItemDto.getJianyanchaoqi());
jianyanhege.add(countItemDto.getJianyanhege());
czjc.add(countItemDto.getCzjc());
czjchege.add(countItemDto.getCzjchege());
});
Map<String, Object> result = new HashMap<>();
result.put("xdata", xdata);
result.put("legendData", legendData);
result.put("xuke", xuke);
......@@ -198,10 +149,20 @@ public class AQZSDPStatisticsServiceImpl {
result.put("jianyanhege", jianyanhege);
result.put("czjc", czjc);
result.put("czjchege", czjchege);
return result;
}
private Set<String> getLegendForCyArea() {
Set<String> legendData = new HashSet<>();
legendData.add("许可有效率");
legendData.add("使用登记办理率");
legendData.add("检验超期率");
legendData.add("检验合格率");
legendData.add("充装检查率");
legendData.add("充装检查合格率");
return legendData;
}
public Map<String, Object> getSecurityIndex(DPFilterParamDto dpFilterParamDto) throws Exception {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto.getCityCode());
......@@ -249,6 +210,7 @@ public class AQZSDPStatisticsServiceImpl {
}
private Map<String, SecurityIndexCountItemDto> getSecurityIndexCountItemDtoMap(List<RegionModel> regionModels) {
// 多线程处理后,顺序与regionModels的顺序不一致,故生成list
List<SecurityIndexCountItemDto> countItemDtoList = getSecurityIndexCountDtoList(regionModels);
return countItemDtoList.stream().collect(Collectors.toMap(SecurityIndexCountItemDto::getRegionCode, Function.identity(), (k1, k2) -> k2));
}
......
......@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* @author Administrator
......@@ -78,4 +79,9 @@ public class StCommonServiceImpl {
}
return regionList;
}
public List<String> buildXData(List<RegionModel> regionList) {
return regionList.stream().map(RegionModel::getRegionName).collect(Collectors.toList());
}
}
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