package com.ruoyi.project.mobile.service; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.pagehelper.util.StringUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.project.mobile.controller.ApiController; import com.ruoyi.project.mobile.domain.ApiRequestHeader; import com.ruoyi.project.mobile.domain.ApiResult; import com.ruoyi.project.system.company.domain.Company; import com.ruoyi.project.system.company.service.ICompanyService; import com.ruoyi.project.system.dict.domain.DictData; import com.ruoyi.project.system.dict.domain.DictDataSonByCompanyIndustryType; import com.ruoyi.project.system.dict.service.IDictTypeService; import com.ruoyi.project.system.role.service.IRoleService; import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.system.user.service.IUserService; import com.ruoyi.project.tr.dataStatistics.domain.DataStatistics; import com.ruoyi.project.tr.dataStatistics.service.DataStatisticsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.*; @Service public class ApiAllDataStatisticsService extends BaseApiService { private static Logger logger = LoggerFactory.getLogger(ApiAllDataStatisticsService.class); @Autowired private DataStatisticsService dataStatisticsService; @Autowired private IRoleService roleService; @Autowired IUserService userService;//用户Service @Autowired private IDictTypeService dictTypeService; @Autowired private ICompanyService companyService; /** * 获取所有区域 */ public ApiResult getAllRegion(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } List dictDataList = dictTypeService.selectDictDataByType("tr_region_list");//获取区域列表 return ApiResult.success("请求数据成功", dictDataList); } /** * 根据区域账号用户名,获取区域下公司数据统计 */ public ApiResult getAllDataStatisticsByUserName(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } DataStatistics dataStatisticsByCompany = new DataStatistics(); String userName = ""; try { Map map = new ObjectMapper().readValue(str, HashMap.class); String companyName = map.get("companyName"); if (!StringUtils.isEmpty(companyName)) { dataStatisticsByCompany.setCompanyName(companyName); } userName = map.get("userName"); } catch (Exception e) { return ApiResult.error("异常"); } Set stringSet = roleService.selectRoleKeys(Long.valueOf(header.userId)); if (stringSet.contains("regionUser") || stringSet.contains("straightRegionUser")) { if (!StringUtils.isEmpty(userName)) { DataStatistics dataStatisticsByRegion = new DataStatistics(); // if (stringSet.contains("straightRegionUser")) { // dataStatisticsByRegion.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 // dataStatisticsByCompany.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 // }else if (stringSet.contains("regionUser")) { // dataStatisticsByRegion.setCompanyRegion(userName); // dataStatisticsByRegion.setCompanyRegion(userName); // } if (("漯河市应急管理局").equals(userName)) { dataStatisticsByRegion.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 dataStatisticsByCompany.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 } else { dataStatisticsByRegion.setCompanyRegion(userName); dataStatisticsByCompany.setCompanyRegion(userName); } List listByRegion = dataStatisticsService.selectCompanyDataStatistics(dataStatisticsByRegion); BigDecimal seriesRiskCount = new BigDecimal(0); BigDecimal middleRiskCount = new BigDecimal(0); BigDecimal normalRiskCount = new BigDecimal(0); BigDecimal lowRiskCount = new BigDecimal(0); BigDecimal thisMonthHighDangerCount = new BigDecimal(0); BigDecimal thisMonthNormalDangerCount = new BigDecimal(0); BigDecimal unRectifyDangerCount = new BigDecimal(0); BigDecimal allDangers = new BigDecimal(0); String dangerRectifyPercent = "100%"; for (DataStatistics temp : listByRegion) { seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount())); middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount())); normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount())); lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount())); thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount())); thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount())); unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount())); allDangers = allDangers.add(new BigDecimal(temp.getAllDangers())); } DataStatistics sumDataStatistics = new DataStatistics(); sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue()); sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue()); sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue()); sumDataStatistics.setLowRiskCount(lowRiskCount.longValue()); sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue()); sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue()); sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue()); if (allDangers.longValue() != 0) { BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4); //下面将结果转化成百分比 NumberFormat percent5 = NumberFormat.getPercentInstance(); percent5.setMaximumFractionDigits(2); dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue()); } sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent); List listByCompany = new ArrayList<>(); if (StringUtils.isEmpty(dataStatisticsByCompany.getCompanyName())) { dataStatisticsByCompany.setCompanyName(""); } for (DataStatistics temp : listByRegion) { if (temp.getCompanyName().contains(dataStatisticsByCompany.getCompanyName())) { temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major"); temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger"); temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general"); temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low"); temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger"); temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger"); temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger"); temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId()); temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId()); temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId()); temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId()); temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId()); temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId()); listByCompany.add(temp); } } Map resultMap = new HashMap<>(); resultMap.put("dataStatisticsList", listByCompany); resultMap.put("sumDataStatistics", sumDataStatistics); return ApiResult.success("请求数据成功", resultMap); } else { return ApiResult.error("未传输用户名userName!"); } } else { return ApiResult.error("用户所在角色不能调用!"); } } //获取总的数据统计 public DataStatistics getDataStatistics(List listTotal) { BigDecimal seriesRiskCount = new BigDecimal(0); BigDecimal middleRiskCount = new BigDecimal(0); BigDecimal normalRiskCount = new BigDecimal(0); BigDecimal lowRiskCount = new BigDecimal(0); BigDecimal thisMonthHighDangerCount = new BigDecimal(0); BigDecimal thisMonthNormalDangerCount = new BigDecimal(0); BigDecimal unRectifyDangerCount = new BigDecimal(0); BigDecimal allDangers = new BigDecimal(0); String dangerRectifyPercent = "100%"; for (DataStatistics temp : listTotal) { seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount())); middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount())); normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount())); lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount())); thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount())); thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount())); unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount())); allDangers = allDangers.add(new BigDecimal(temp.getAllDangers())); } DataStatistics sumDataStatistics = new DataStatistics(); sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue()); sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue()); sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue()); sumDataStatistics.setLowRiskCount(lowRiskCount.longValue()); sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue()); sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue()); sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue()); if (allDangers.longValue() != 0) { BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4); //下面将结果转化成百分比 NumberFormat percent5 = NumberFormat.getPercentInstance(); percent5.setMaximumFractionDigits(2); dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue()); } sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent); return sumDataStatistics; } /** * 查询总的数据统计,获取区域列表 */ public ApiResult getAllDataStatisticsByStraightRegion(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } DataStatistics query = new DataStatistics(); query.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 //查询 List listTotal = dataStatisticsService.selectCompanyDataStatistics(query); DataStatistics sumDataStatistics = getDataStatistics(listTotal); Map resultMap = new HashMap<>(); resultMap.put("sumDataStatistics", sumDataStatistics); List regionList = dictTypeService.selectDictDataByType("tr_region_list");//获取区域列表 resultMap.put("regionList", regionList); // /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major //重大风险列表 // /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger //较大风险列表 // /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general //一般风险列表 // /tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low //低风险列表 // /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger //当月重大隐患 // /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger //当月一般隐患 // /tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger //未整改隐患 // /tr/dataStatisticsTotalByApp/dangerLedgerListTotal //隐患台账 String suffix = "?pageLevel=firstPage"; resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix); resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix); resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix); resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix); resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix); resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix); resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix); resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix); return ApiResult.success("请求数据成功", resultMap); } /** * 查询某个区域数据统计,获取行业类型列表 */ public ApiResult getAllDataStatisticsByRegion(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } String companyRegion = ""; try { Map map = new ObjectMapper().readValue(str, HashMap.class); companyRegion = map.get("companyRegion"); } catch (Exception e) { return ApiResult.error("异常"); } if (StringUtil.isEmpty(companyRegion)) { return ApiResult.error("companyRegion参数必填,不能为空!"); } DataStatistics query = new DataStatistics(); query.setCompanyRegion(companyRegion); //查询 List listTotal = dataStatisticsService.selectCompanyDataStatistics(query); DataStatistics sumDataStatistics = getDataStatistics(listTotal); Map resultMap = new HashMap<>(); resultMap.put("sumDataStatistics", sumDataStatistics); List companyIndustryTypeListTemp = dictTypeService.selectDictDataByType("company_industry_type");//获取公司行业类型列表 List companySubIndustryTypeByWeihua = dictTypeService.selectDictDataByType("company_sub_industry_type_by_weihua");//危化行业子分类 List companyIndustryTypeList = new ArrayList<>(); for (DictData temp : companyIndustryTypeListTemp) { DictDataSonByCompanyIndustryType dictDataSonByCompanyIndustryType = new DictDataSonByCompanyIndustryType(); BeanUtils.copyProperties(temp, dictDataSonByCompanyIndustryType); if ("危化".equals(temp.getDictValue())) { dictDataSonByCompanyIndustryType.setCompanySubIndustryTypeList(companySubIndustryTypeByWeihua); } companyIndustryTypeList.add(dictDataSonByCompanyIndustryType); } resultMap.put("companyIndustryTypeList", companyIndustryTypeList); String suffix = ""; // String pageLevel,第几个层级 // String companyRegion,公司区域 // String companyIndustryType,行业分类 // String companySubIndustryType,行业子分类 suffix = "?pageLevel=secondPage&companyRegion=" + companyRegion; resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix); resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix); resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix); resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix); resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix); resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix); resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix); resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix); return ApiResult.success("请求数据成功", resultMap); } /** * 查询某个区域数据和某个行业数据统计 */ public ApiResult getAllDataStatisticsByRegionAndIndustryType(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } String companyRegion = ""; String companyIndustryType = ""; String companySubIndustryType = ""; String companyName = ""; try { Map map = new ObjectMapper().readValue(str, HashMap.class); companyRegion = map.get("companyRegion"); companyIndustryType = map.get("companyIndustryType"); companySubIndustryType = map.get("companySubIndustryType"); companyName = map.get("companyName"); } catch (Exception e) { return ApiResult.error("异常"); } if (StringUtil.isEmpty(companyRegion)) { return ApiResult.error("companyRegion参数必填,不能为空!"); } if (StringUtil.isEmpty(companyIndustryType)) { return ApiResult.error("companyIndustryType参数必填,不能为空!"); } DataStatistics query = new DataStatistics(); query.setCompanyIndustry(companyIndustryType); query.setCompanySubIndustry(companySubIndustryType); query.setCompanyRegion(companyRegion); //查询 List listTotal = dataStatisticsService.selectCompanyDataStatistics(query); DataStatistics sumDataStatistics = getDataStatistics(listTotal); List listQueryResultByCompanyName = new ArrayList<>(); if (StringUtils.isEmpty(companyName)) { companyName = ""; } for (DataStatistics temp : listTotal) { if (temp.getCompanyName().contains(companyName)) { temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major"); temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger"); temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general"); temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low"); temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger"); temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger"); temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger"); temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId()); temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId()); temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId()); temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId()); temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId()); temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId()); listQueryResultByCompanyName.add(temp); } } Map resultMap = new HashMap<>(); resultMap.put("sumDataStatistics", sumDataStatistics); resultMap.put("dataStatisticsList", listQueryResultByCompanyName); String suffix = ""; // String pageLevel,第几个层级 // String companyRegion,公司区域 // String companyIndustryType,行业分类 // String companySubIndustryType,行业子分类 if (StringUtil.isEmpty(companySubIndustryType)) { suffix = "?pageLevel=thirdPage&companyRegion=" + companyRegion + "&companyIndustryType=" + companyIndustryType; } else { suffix = "?pageLevel=thirdPage&companyRegion=" + companyRegion + "&companyIndustryType=" + companyIndustryType + "&companySubIndustryType=" + companySubIndustryType; } if (!StringUtil.isEmpty(suffix)) { resultMap.put("ledgerTotalAndRiskLevelMajorUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/major" + suffix); resultMap.put("ledgerTotalAndRiskLevelLargerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/larger" + suffix); resultMap.put("ledgerTotalAndRiskLevelGeneralUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/general" + suffix); resultMap.put("ledgerTotalAndRiskLevelLowUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/riskCheckPoint/ledger/low" + suffix); resultMap.put("dangerLedgerListTotalByThisMonthHighDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthHighDanger" + suffix); resultMap.put("dangerLedgerListToatalByThisMonthNormalDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/thisMonthNormalDanger" + suffix); resultMap.put("dangerLedgerListTotalByUnRectifyDangerUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal/unRectifyDanger" + suffix); resultMap.put("dangerLedgerListTotalUrl", "https://lhaxsyf.com/tr/dataStatisticsTotalByApp/dangerLedgerListTotal" + suffix); } return ApiResult.success("请求数据成功", resultMap); } /** * 根据角色名称查询数据统计(用于总公司账号数据统计,区域账号不再涉及) */ public ApiResult getAllDataStatisticsByRoleName(String str, ApiRequestHeader header) { //验证userId,loginName,token,deviceType,deviceId,appType 是否一致 ApiRequestHeader requestHeader = getHeader(header); if (!(header.equals(requestHeader))) { return ApiResult.errorToken("验证userId,loginName,token,deviceType,deviceId,appType 不一致"); } String companyName = ""; String userId = ""; try { Map map = new ObjectMapper().readValue(str, HashMap.class); companyName = map.get("companyName"); userId = map.get("userId"); } catch (Exception e) { return ApiResult.error("异常"); } if (StringUtil.isEmpty(userId)) { return ApiResult.error("userId参数必填,不能为空!"); } Set stringSet = roleService.selectRoleKeys(Long.valueOf(userId)); User user = userService.selectUserById(Long.valueOf(userId)); DataStatistics query = new DataStatistics(); if (stringSet.contains("regionUser") || stringSet.contains("straightRegionUser")) { if (!StringUtils.isEmpty(user.getUserName())) { if (("漯河市应急管理局").equals(user.getUserName())) { query.setSelectAllCompanyHasRegion("selectAllCompanyHasRegion");//市直账号,查询所有有区域的公司 } else { query.setCompanyRegion(user.getUserName()); } } else { return ApiResult.error("用户未找到!"); } } else if (stringSet.contains("common")) { //判断是否有子公司 Company sonQuery = new Company(); sonQuery.setParentId(user.getCompanyId()); List sonList = companyService.selectCompanyList(sonQuery); if (sonList.size() == 0) { return ApiResult.error("用户不能调用!"); } else { List companyIdList = new ArrayList<>(); for (Company company : sonList) { companyIdList.add(company.getCompanyId().toString()); } companyIdList.add(user.getCompanyId().toString()); query.setCompanyIdList(companyIdList); } } else { return ApiResult.error("用户所在角色不能调用!"); } //查询 List listTotal = dataStatisticsService.selectCompanyDataStatistics(query); BigDecimal seriesRiskCount = new BigDecimal(0); BigDecimal middleRiskCount = new BigDecimal(0); BigDecimal normalRiskCount = new BigDecimal(0); BigDecimal lowRiskCount = new BigDecimal(0); BigDecimal thisMonthHighDangerCount = new BigDecimal(0); BigDecimal thisMonthNormalDangerCount = new BigDecimal(0); BigDecimal unRectifyDangerCount = new BigDecimal(0); BigDecimal allDangers = new BigDecimal(0); String dangerRectifyPercent = "100%"; for (DataStatistics temp : listTotal) { seriesRiskCount = seriesRiskCount.add(new BigDecimal(temp.getSeriesRiskCount())); middleRiskCount = middleRiskCount.add(new BigDecimal(temp.getMiddleRiskCount())); normalRiskCount = normalRiskCount.add(new BigDecimal(temp.getNormalRiskCount())); lowRiskCount = lowRiskCount.add(new BigDecimal(temp.getLowRiskCount())); thisMonthHighDangerCount = thisMonthHighDangerCount.add(new BigDecimal(temp.getThisMonthHighDangerCount())); thisMonthNormalDangerCount = thisMonthNormalDangerCount.add(new BigDecimal(temp.getThisMonthNormalDangerCount())); unRectifyDangerCount = unRectifyDangerCount.add(new BigDecimal(temp.getUnRectifyDangerCount())); allDangers = allDangers.add(new BigDecimal(temp.getAllDangers())); } DataStatistics sumDataStatistics = new DataStatistics(); sumDataStatistics.setSeriesRiskCount(seriesRiskCount.longValue()); sumDataStatistics.setMiddleRiskCount(middleRiskCount.longValue()); sumDataStatistics.setNormalRiskCount(normalRiskCount.longValue()); sumDataStatistics.setLowRiskCount(lowRiskCount.longValue()); sumDataStatistics.setThisMonthHighDangerCount(thisMonthHighDangerCount.longValue()); sumDataStatistics.setThisMonthNormalDangerCount(thisMonthNormalDangerCount.longValue()); sumDataStatistics.setUnRectifyDangerCount(unRectifyDangerCount.longValue()); if (allDangers.longValue() != 0) { BigDecimal tempBigDecimal = ApiHiddenDangerCheckService.divide((allDangers.intValue() - unRectifyDangerCount.intValue()), allDangers.intValue(), 4); //下面将结果转化成百分比 NumberFormat percent5 = NumberFormat.getPercentInstance(); percent5.setMaximumFractionDigits(2); dangerRectifyPercent = percent5.format(tempBigDecimal.doubleValue()); } sumDataStatistics.setDangerRectifyPercent(dangerRectifyPercent); List listQueryResultByCompanyName = new ArrayList<>(); if (StringUtils.isEmpty(companyName)) { companyName = ""; } for (DataStatistics temp : listTotal) { if (temp.getCompanyName().contains(companyName)) { temp.setLedgerByCompanyIdAndRiskLevelMajorUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/major"); temp.setLedgerByCompanyIdAndRiskLevelLargerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/larger"); temp.setLedgerByCompanyIdAndRiskLevelGeneralUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/general"); temp.setLedgerByCompanyIdAndRiskLevelLowUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId() + "/low"); temp.setDangerLedgerListByCompanyIdByThisMonthHighDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthHighDanger"); temp.setDangerLedgerListByCompanyIdByThisMonthNormalDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/thisMonthNormalDanger"); temp.setDangerLedgerListByCompanyIdByUnRectifyDangerUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId() + "/unRectifyDanger"); temp.setDangerPlanExecuteByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerPlanExecuteByCompanyId/" + temp.getCompanyId()); temp.setDangerScheduleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerScheduleByCompanyId/" + temp.getCompanyId()); temp.setDangerLedgerListByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/dangerLedgerListByCompanyId/" + temp.getCompanyId()); temp.setLedgerByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/riskCheckPoint/ledger/" + temp.getCompanyId()); temp.setArticleByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleByCompanyId/" + temp.getCompanyId()); temp.setArticleRegulationByCompanyIdUrl("https://lhaxsyf.com/tr/dataStatisticsByApp/articleRegulationByCompanyId/" + temp.getCompanyId()); listQueryResultByCompanyName.add(temp); } } Map resultMap = new HashMap<>(); resultMap.put("dataStatisticsList", listQueryResultByCompanyName); resultMap.put("sumDataStatistics", sumDataStatistics); return ApiResult.success("请求数据成功", resultMap); } }