package com.gk.hotwork.Service.ServiceImpl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gk.hotwork.Domain.*; import com.gk.hotwork.Domain.Do.CompanyInspectionCountDO; import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO; import com.gk.hotwork.Domain.Do.SubordinateOrganizationInfoDO; import com.gk.hotwork.Domain.Utils.BeanUtils; import com.gk.hotwork.Domain.Utils.Msg; import com.gk.hotwork.Domain.Utils.StringUtils; import com.gk.hotwork.Domain.dto.resp.AreaInspectionCountRespDTO; import com.gk.hotwork.Domain.dto.resp.CompanyInspectionCountRespDTO; import com.gk.hotwork.Domain.query.CountQuery; import com.gk.hotwork.Service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @email 1603559716@qq.com * @author: zf * @date: 2023/8/22 * @time: 15:41 */ @Service public class SafetyInspectionStatisticServiceImpl implements SafetyInspectionStatisticService { private final static String province = "新疆维吾尔自治区"; @Autowired private DistrictService districtService; @Autowired private CompanyService companyService; @Autowired private InspectionHiddenDangerService hiddenDangerService; @Autowired private SafetySelfInspectionService selfInspectionService; @Override public Msg getCountByArea(CountQuery query, UserInfo user) { List organizationInfos = null; Integer type = user.getType(); //如果传来的区县级不为空,则表明是到县级 if(StringUtils.isNotBlank(query.getArea())){ return getAreaDataCount(query); } //如果传来市级不为空 if(StringUtils.isNotBlank(query.getCity())){ List districtInfos = districtService.selectDistrictByName("3", query.getCity(), "2"); organizationInfos = districtInfos.stream().map((districtInfo)->{ SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO(); organizationInfoDO.setProvince(province); organizationInfoDO.setCity(query.getCity()); organizationInfoDO.setArea(districtInfo.getName()); return organizationInfoDO; }).collect(Collectors.toList()); }else { //管理员 if(type.equals(1)){ List districtInfos = districtService.selectDistrictByName("2", province, "1"); organizationInfos = districtInfos.stream().map((districtInfo)->{ SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO(); organizationInfoDO.setProvince(province); organizationInfoDO.setCity(districtInfo.getName()); return organizationInfoDO; }).collect(Collectors.toList()); } //监护人员 if(type.equals(2)){ //属于县级 if(StringUtils.isNotBlank(user.getCounty())){ query.setArea(user.getCounty()); return getAreaDataCount(query); } //属于市级 if(StringUtils.isNotBlank(user.getCity())){ List districtInfos = districtService.selectDistrictByName("3", user.getCity(), "2"); organizationInfos = districtInfos.stream().map((districtInfo)->{ SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO(); organizationInfoDO.setProvince(user.getProvince()); organizationInfoDO.setCity(user.getCity()); organizationInfoDO.setArea(districtInfo.getName()); return organizationInfoDO; }).collect(Collectors.toList()); } //属于省级 if(StringUtils.isNotBlank(user.getProvince())){ List districtInfos = districtService.selectDistrictByName("2", user.getProvince(), "1"); organizationInfos = districtInfos.stream().map((districtInfo)->{ SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO(); organizationInfoDO.setProvince(user.getProvince()); organizationInfoDO.setCity(districtInfo.getName()); return organizationInfoDO; }).collect(Collectors.toList()); } } } List list = getDataCountSelfCheckInfo(query,organizationInfos); Msg msg = new Msg(); msg.setCode("200"); msg.setResult("查询成功"); msg.setResult(list); return msg; } @Override public Msg getUnCheckCompany(CountQuery query) { Page uncheckCompanyByArea = companyService.getUncheckCompanyByArea(query); Msg msg = new Msg(); msg.setCode("200"); msg.setResult("查询成功"); msg.setResult(uncheckCompanyByArea); return msg; } private List getDataCountSelfCheckInfo(CountQuery query, List organizationInfos) { List respDTOList = new ArrayList<>(); for (SubordinateOrganizationInfoDO organizationInfo : organizationInfos) { AreaInspectionCountRespDTO areaInspectionCountRespDTO = new AreaInspectionCountRespDTO(); //统计检查企业数量以及清单数量等 Map map = new HashMap<>(); map.put("startTime",query.getStartTime()); map.put("endTime",query.getEndTime()); map.put("province",organizationInfo.getProvince()); map.put("city",organizationInfo.getCity()); map.put("area",organizationInfo.getArea()); CompanyStatisticInspectionDO companyStatisticInspection = selfInspectionService.companyStatisticInspection(map); BeanUtils.copyProperties(companyStatisticInspection,areaInspectionCountRespDTO); areaInspectionCountRespDTO.setProvince(organizationInfo.getProvince()); areaInspectionCountRespDTO.setCity(organizationInfo.getCity()); areaInspectionCountRespDTO.setArea(organizationInfo.getArea()); areaInspectionCountRespDTO.setRectifyRate(areaInspectionCountRespDTO.getHdTotal() == 0 ? new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP) : new BigDecimal(areaInspectionCountRespDTO.getRectifyTotal()).divide(new BigDecimal(areaInspectionCountRespDTO.getHdTotal()), 2, BigDecimal.ROUND_HALF_UP)); //统计公司总数量 int companyCount = companyService.getCountByArea(map); areaInspectionCountRespDTO.setCompanyTotal(companyService.getCountByArea(map)); areaInspectionCountRespDTO.setUnCheckCompanyCount(companyCount-areaInspectionCountRespDTO.getCheckCompanyCount()); respDTOList.add(areaInspectionCountRespDTO); } return respDTOList; } private Msg getAreaDataCount(CountQuery query) { if(query.getPageIndex() == null){ query.setPageIndex(1); } if(query.getPageSize() == null){ query.setPageSize(10); } //获取该地区所有企业隐患统计 List statisticHiddenDangerList = hiddenDangerService.getStatisticHiddenDanger(query); //获取相关企业 Page companyInfoPage = companyService.getByArea(query); List list = new ArrayList<>(); for (CompanyInfo companyInfo : companyInfoPage.getRecords()) { CompanyInspectionCountRespDTO inspectionCountRespDTO = new CompanyInspectionCountRespDTO(); List collect = statisticHiddenDangerList .stream() .filter(statistic -> statistic.getCompanyId().equals(companyInfo.getId())) .collect(Collectors.toList()); if(collect.size() > 0){ CompanyInspectionCountDO companyInspectionCountDO = collect.get(0); BeanUtils.copyProperties(companyInspectionCountDO,inspectionCountRespDTO); inspectionCountRespDTO.setRectifyRate(companyInspectionCountDO.getSHdTotal() == 0 ? new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP) : new BigDecimal(companyInspectionCountDO.getSReTotal()).divide(new BigDecimal(companyInspectionCountDO.getSHdTotal()), 2, BigDecimal.ROUND_HALF_UP)); }else { inspectionCountRespDTO.setCheckTotal(0); inspectionCountRespDTO.setSHdTotal(0); inspectionCountRespDTO.setSMaTotal(0); inspectionCountRespDTO.setSMaReTotal(0); inspectionCountRespDTO.setSReTotal(0); inspectionCountRespDTO.setSUnReTotal(0); inspectionCountRespDTO.setSSaTotal(0); inspectionCountRespDTO.setSSaReTotal(0); inspectionCountRespDTO.setRectifyRate(new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP)); inspectionCountRespDTO.setCompanyId(companyInfo.getId()); } inspectionCountRespDTO.setCompanyName(companyInfo.getCompany()); inspectionCountRespDTO.setLastTime(selfInspectionService.selectLastTimeByCompanyId(companyInfo.getId(),query.getStartTime(),query.getEndTime())); list.add(inspectionCountRespDTO); } Page page = new Page<>(); BeanUtils.copyProperties(companyInfoPage,page); page.setRecords(list); Msg msg = new Msg(); msg.setCode("200"); msg.setMessage("查询成功"); msg.setResult(page); return msg; } }