package com.zd.security.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.pagehelper.PageHelper; import com.zd.common.core.annotation.Log; import com.zd.common.core.annotation.PreAuthorize; import com.zd.common.core.log.BusinessType; import com.zd.common.core.security.TokenService; import com.zd.common.core.utils.Convert; import com.zd.common.core.utils.DateUtils; import com.zd.common.core.utils.ExcelUtil; import com.zd.common.core.utils.StringUtils; import com.zd.common.core.web.controller.AbstractController; import com.zd.laboratory.api.feign.RemoteLaboratoryService; import com.zd.model.constant.HttpStatus; import com.zd.model.domain.AjaxResult; import com.zd.model.domain.R; import com.zd.model.domain.ResultData; import com.zd.model.domain.per.PerFun; import com.zd.model.domain.per.PerPrefix; import com.zd.model.entity.LoginModel; import com.zd.model.entity.SysDept; import com.zd.model.page.TableDataInfo; import com.zd.security.api.bo.CheckHazardBo; import com.zd.security.api.bo.CheckManageBo; import com.zd.security.api.vo.*; import com.zd.security.entity.*; import com.zd.security.scope.DataPermission; import com.zd.security.scope.DataPermissionAspect; import com.zd.security.service.*; import com.zd.system.api.feign.RemoteDeptService; import com.zd.system.api.feign.RemoteUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; import java.util.*; import java.util.stream.Collectors; /** * @Author: xxf * @Date: 2023/05/04/10:48 * @Description: */ @Api(tags = "数据统计") @RestController @RequestMapping("/DataStatistics") public class DataStatisticsController extends AbstractController { @Autowired private CheckHazardService checkHazardService; @Autowired private CheckManageService checkManageService; @Autowired private CheckMemberService checkMemberService; @Autowired private CheckRectifyService checkRectifyService; @Autowired private CheckStaffUserService checkStaffUserService; @Autowired private RemoteLaboratoryService remoteLaboratoryService; @Autowired private TokenService tokenService; @Autowired private RemoteUserService remoteUserService; @Autowired private CheckPlanService checkPlanService; @Autowired private CheckOptionService checkOptionService; @Autowired private RemoteDeptService remoteDeptService; @Value("${check.manageSign}") private String manageSign; @DataPermission() @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @ApiOperation("实验室列表") @GetMapping(value = "/subList") public ResultData subList(CheckManageBo bo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ bo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page page = new Page<>(bo.getPageNum(), bo.getPageSize()); return ResultData.success(getSubList(page, bo)); } private Page getSubList(Page page, CheckManageBo bo) { Page list = checkManageService.selecSubCheckManageList(page, bo); if (list != null && list.getRecords().size() > 0) { Long[] ids = list.getRecords().stream().map(a -> a.getSubId()).toArray(Long[]::new); ResultData rd = remoteLaboratoryService.selectLabSubSafeInfoByIds(ids); if (rd.getCode() != HttpStatus.SUCCESS) { log.info("数据统计实验室列表,查询负责人电话异常:" + rd.getMsg()); } else { if (list.getRecords().size() > 0) { List> linkedHashMap = (List>) rd.getData(); //实验室负责人、安全负责人数据整合 for (CheckManageVo vo : list.getRecords()) { for (int i = 0; i < linkedHashMap.size(); i++) { if (linkedHashMap != null && vo.getSubId().equals(Long.valueOf(linkedHashMap.get(i).get("id").toString()))) { vo.setSafeUserNameAdminPhone(linkedHashMap.get(i).get("safeUserNameAdminPhone") != null ? linkedHashMap.get(i).get("safeUserNameAdminPhone").toString().replace("@", "-") : null); vo.setAdminNameAndPhone(linkedHashMap.get(i).get("adminNameAndPhone") != null ? linkedHashMap.get(i).get("adminNameAndPhone").toString().replace("@", "-") : null); } } //查询实验室下的危险源 R hazardRd = remoteLaboratoryService.getBySubjectId(vo.getSubId()); if (rd.getCode() == HttpStatus.SUCCESS) { List> linkedHazardRdMap = (List>) hazardRd.getData(); if (linkedHazardRdMap != null) { String anotherName = ""; for (int j = 0; j < linkedHazardRdMap.size(); j++) { if (vo.getSubId().equals(Long.valueOf(linkedHazardRdMap.get(j).get("subjectId").toString()))) { anotherName += linkedHazardRdMap.get(j).get("anotherName") + ","; } } vo.setHazardName(anotherName.length() > 1 ? anotherName.substring(0, anotherName.length() - 1) : anotherName); } } //该实验室所有隐患整改数 CheckHazardBo checkHazardBo = new CheckHazardBo(); checkHazardBo.setSubId(vo.getSubId()); checkHazardBo.setCheckTimeOrder(100);//已整改并,包含无法整改 Long rectifyCount = checkHazardService.hiddenDangerCount(checkHazardBo); //该实验室检查不符合数(隐患总数) checkHazardBo = new CheckHazardBo(); checkHazardBo.setSubId(vo.getSubId()); Long resultCount = checkHazardService.hiddenDangerCount(checkHazardBo); //整改率 vo.setPercent(WorkSchoolController.myPercent(Convert.toInt(rectifyCount), Convert.toInt(resultCount), "##.##%")); //该实验室复核总数 checkHazardBo = new CheckHazardBo(); checkHazardBo.setSubId(vo.getSubId()); checkHazardBo.setCheckTimeOrder(101); Long FhCount = checkHazardService.hiddenDangerCount(checkHazardBo); //该实验室所有整改复核通过数 checkHazardBo.setExamineResult(1); Long TgCount = checkHazardService.hiddenDangerCount(checkHazardBo); //复核通过率 vo.setPercent2(WorkSchoolController.myPercent(Convert.toInt(TgCount), Convert.toInt(FhCount), "##.##%")); } } } } return list; } /*** *实验室头部数据统计 * @param bo * @return */ @DataPermission() @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @ApiOperation("实验室列表头部数据统计") @GetMapping(value = "/subListTop") public ResultData subListTop(CheckManageBo bo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ bo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } return ResultData.success(getSubListTop(bo)); } private Map getSubListTop(CheckManageBo bo) { Map map = new HashMap<>(); //安全分级 Map classmap = new HashMap<>(); //安全分类 Map classTypemap = new HashMap<>(); //安全分级 List classListVo = new ArrayList<>(); //安全分类 List classTypeListVo = new ArrayList<>(); //总数 Integer sumTotal = 0; //存在危险源的实验室数量 Integer hazardSubjectTotal = 0; //危险源总数 Integer hazardTotal = 0; //特种设备总数 Integer specialTotal = 0; Page page = new Page().setSize(-1); Page list = checkManageService.selecSubCheckManageList(page, bo); if (list != null && list.getRecords().size() > 0) { sumTotal = list.getRecords().size(); //安全检查实验室集合 Long[] ids = list.getRecords().stream().map(a -> a.getSubId()).toArray(Long[]::new); //查询关联危险源的实验室 R rHd = remoteLaboratoryService.getBySubjectIds(ids); if (rHd.getCode() == HttpStatus.SUCCESS) { List> linkedHashMap = (List>) rHd.getData(); if (linkedHashMap != null && !linkedHashMap.isEmpty()) { hazardSubjectTotal = linkedHashMap.size(); for (int i = 0; i < linkedHashMap.size(); i++) { Integer count = Integer.valueOf(linkedHashMap.get(i).get("count").toString()); hazardTotal = hazardTotal + count; } } } //查询安全分级列表 R rClassified = remoteLaboratoryService.classifiedListAll(); if (rClassified.getCode() == HttpStatus.SUCCESS) { List> linkedHashMap = (List>) rClassified.getData(); if (linkedHashMap != null && !linkedHashMap.isEmpty()) { for (int i = 0; i < linkedHashMap.size(); i++) { classmap.put(Long.valueOf(linkedHashMap.get(i).get("id").toString()), 0); CheckManageVo vo = new CheckManageVo(); vo.setLevelName(linkedHashMap.get(i).get("classifiedName").toString()); vo.setAmount(0); vo.setLevel(Long.valueOf(linkedHashMap.get(i).get("id").toString())); classListVo.add(vo); } } } //查询安全分类列表 R rClassiType = remoteLaboratoryService.classtypeListAll(); if (rClassiType.getCode() == HttpStatus.SUCCESS) { List> linkedHashMap = (List>) rClassiType.getData(); if (linkedHashMap != null && !linkedHashMap.isEmpty()) { for (int i = 0; i < linkedHashMap.size(); i++) { classTypemap.put(Long.valueOf(linkedHashMap.get(i).get("id").toString()), 0); CheckManageVo vo = new CheckManageVo(); vo.setTypeName(linkedHashMap.get(i).get("typeName").toString()); vo.setAmount2(0); vo.setTypeId(Long.valueOf(linkedHashMap.get(i).get("id").toString())); classTypeListVo.add(vo); } } } //循环实验室集合计算各个安全等级数量 for (CheckManageVo vo : list.getRecords()) { //安全等级数量 if (classmap.containsKey(vo.getLevel())) { Integer value = classmap.get(vo.getLevel()); value = value + 1; classmap.put(vo.getLevel(), value); } //特种设备 if (vo.getTypeName() != null && vo.getTypeName().indexOf("特种设备") != -1) { specialTotal++; } //安全分类数量 if (classTypemap.containsKey(vo.getTypeId())) { Integer value2 = classTypemap.get(vo.getTypeId()); value2 = value2 + 1; classTypemap.put(vo.getTypeId(), value2); } } //将各个等级的安全数量赋值给安全等级集合列表 for (CheckManageVo v : classListVo) { for (Long key : classmap.keySet()) { if (v.getLevel().equals(key)) { v.setAmount(classmap.get(key)); } } } //将各个安全分类的安全数量赋值给安全分类集合列表 for (CheckManageVo v : classTypeListVo) { for (Long key : classTypemap.keySet()) { if (v.getTypeId().equals(key)) { v.setAmount2(classTypemap.get(key)); } } } } map.put("sumTotal", sumTotal); map.put("hazardSubjectTotal", hazardSubjectTotal); map.put("hazardTotal", hazardTotal); map.put("classListVo", classListVo); map.put("classTypeListVo", classTypeListVo); map.put("specialTotal", specialTotal); return map; } /** * 数据统计-按实验室导出 */ @DataPermission() @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.EXPORT) @Log(title = "数据统计-按实验室导出", businessType = BusinessType.EXPORT) @PostMapping("/subExport") public void export(HttpServletResponse response, CheckManageBo bo) throws IOException { List excelList = new ArrayList<>(); Page page = new Page().setSize(-1); bo.setSubListIds(bo.getIds()); Page list = getSubList(page, bo); if (list != null && list.getRecords().size() > 0) { for (CheckManageVo vo : list.getRecords()) { SubjectExcel excel = new SubjectExcel(); BeanUtils.copyProperties(vo, excel); excelList.add(excel); } } String fw = "全部";//范围 String aufl = "全部";//安全分类 String audj = "全部";//安全等级 //String zq = "全部";//统计周期 String audjList = "";//安全等级描述 String auflList = "";//安全分类描述 //获取列表集合 if (list.getRecords().size() > 0) { fw = bo.getSubIds() == null ? fw : list.getRecords().get(0).getCollegeName(); aufl = bo.getTypeId() == null ? aufl : list.getRecords().get(0).getTypeName(); audj = bo.getLevel() == null ? audj : list.getRecords().get(0).getLevelName(); } //获取头部数据 Map map = getSubListTop(bo); //安全等级 List classListVoList = (List) map.get("classListVo"); if (classListVoList != null && !classListVoList.isEmpty()) { for (CheckManageVo vo : classListVoList) { audjList += vo.getLevelName() + ":" + vo.getAmount() + " "; } } //安全分类 List classTypeList = (List) map.get("classTypeListVo"); if (classTypeList != null && !classTypeList.isEmpty()) { for (CheckManageVo vo : classTypeList) { auflList += vo.getTypeName() + ":" + vo.getAmount2() + " "; } } //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); String tips = "统计范围:" + fw + " 安全分类:" + aufl + " 安全等级:" + audj + " \n" + "生成时间:" + DateUtils.getTime() + " 生成者:" + sysUser.getNickName() + " \n" + "实验室总数:" + map.get("sumTotal") + " 存在危险源的实验室数:" + map.get("hazardSubjectTotal") + " 危险源总数:" + map.get("hazardTotal") + " \n" + audjList + "\n" + auflList + "\n"; ExcelUtil util = new ExcelUtil<>(SubjectExcel.class); util.exportExcel(response, excelList, "实验室安全检查统计", tips, "实验室安全检查统计导出报表" + LocalDate.now()); } /*** * 安全隐患列表 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("安全隐患列表") @GetMapping(value = "/hazardList") public ResultData hazardList(CheckHazardBo hazardBo) { // 获取数据 List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page page = new Page<>(hazardBo.getPageNum(), hazardBo.getPageSize()); //排序标识 hazardBo.setAppFlag(1); Page list = checkHazardService.hiddenDataStatisticsList(page, hazardBo); return ResultData.success(list); } /*** *安全隐患列表头部数据统计 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("安全隐患列表头部数据统计") @GetMapping(value = "/hazardListTop") public ResultData hazardListTop(CheckHazardBo hazardBo) { // 获取数据 List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } return ResultData.success(getHazardListTop(hazardBo)); } private Map getHazardListTop(CheckHazardBo hazardBo) { Map map = new HashMap<>(); //总数 Integer sumTotal = 0; //重大隐患 Integer zdHazardTotal = 0; //一般隐患 Integer ybHazardTotal = 0; //管理隐患 Integer glHazardTotal = 0; //待整改 Integer rectifiedTotal = 0; //复核总数 Integer resultTotal = 0; //复核通过总数 Integer ratifyTotal = 0; //通过率 String rate = "0%"; Page page = new Page().setSize(-1); Page list = checkHazardService.hiddenDataStatisticsList(page, hazardBo); if (list.getRecords().size() > 0) { sumTotal = list.getRecords().size(); for (CheckHazardVo vo : list.getRecords()) { if (StringUtils.isNotNull(vo.getHazardLevel()) && vo.getHazardLevel().equals(1)) { zdHazardTotal++; } else if (StringUtils.isNotNull(vo.getHazardLevel()) && vo.getHazardLevel().equals(2)) { ybHazardTotal++; } else if (StringUtils.isNotNull(vo.getHazardLevel()) && vo.getHazardLevel().equals(3)) { glHazardTotal++; } //驳回的也按照未整改统计 if (StringUtils.isNotNull(vo.getRectifyStatus()) && vo.getRectifyStatus().equals(2)) { rectifiedTotal++; } if (StringUtils.isNotNull(vo.getExamineResult())) { resultTotal++; } if (StringUtils.isNotNull(vo.getExamineResult()) && vo.getExamineResult().equals(1)) { ratifyTotal++; } } } rate = WorkSchoolController.myPercent(ratifyTotal, resultTotal, "##.##%"); map.put("sumTotal", sumTotal); map.put("zdHazardTotal", zdHazardTotal); map.put("ybHazardTotal", ybHazardTotal); map.put("glHazardTotal", glHazardTotal); map.put("rectifiedTotal", rectifiedTotal); map.put("resultTotal", resultTotal); map.put("rate", rate); return map; } /**** * 数据统计-按照安全隐患列表导出 * @param hazardBo * @return */ @DataPermission() @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.EXPORT) @ApiOperation("安全隐患列表导出") @PostMapping(value = "/hazardExport") public void hazardExport(HttpServletResponse response, CheckHazardBo hazardBo) throws IOException { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page page = new Page().setSize(-1); List excelList = new ArrayList<>(); Page list = checkHazardService.hiddenDataStatisticsList(page, hazardBo); for (CheckHazardVo vo : list.getRecords()) { HazardExcel excel = new HazardExcel(); BeanUtils.copyProperties(vo, excel); //整改状态 excel.setRectifyStatusStr(getRectifyStatusName(vo.getRectifyStatus())); //隐患级别 excel.setHazardLevelStr(StringUtils.isNotNull(vo.getHazardLevel()) ? getHazardLevelName(vo.getHazardLevel()) : ""); excel.setHazardCheckName(vo.getHazardCheckCode() + vo.getHazardCheckName()); excelList.add(excel); } Map map = getHazardListTop(hazardBo); //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); String fw = "全部";//范围 String zgzt = "全部";//整改状态 String yhdj = "全部";//隐患等级 String zq = "全部";//统计周期 if (list.getRecords().size() > 0) { fw = hazardBo.getSubId() == null ? fw : list.getRecords().get(0).getCollegeName(); zgzt = hazardBo.getRectifyStatus() == null ? zgzt : getRectifyStatusName(list.getRecords().get(0).getRectifyStatus()); yhdj = hazardBo.getHdLevel() == null ? yhdj : getHazardLevelName(list.getRecords().get(0).getHazardLevel()); zq = StringUtils.isEmpty(hazardBo.getBeginTime()) ? zq : (hazardBo.getBeginTime() + "-" + hazardBo.getEndTime()); } String tips = "统计范围:" + fw + " 整改状态:" + zgzt + " 隐患等级:" + yhdj + " 统计周期:" + zq + "\n" + "生成时间:" + DateUtils.getTime() + " 生成者:" + sysUser.getNickName() + " \n" + "隐患总数:" + map.get("sumTotal") + " 重大隐患数:" + map.get("zdHazardTotal") + " 一般隐患数:" + map.get("ybHazardTotal") + " 管理问题数:" + map.get("glHazardTotal") + " 待整改总数:" + map.get("rectifiedTotal") + " 复核总数:" + map.get("resultTotal") + " 复核通过率:" + map.get("rate"); ExcelUtil util = new ExcelUtil<>(HazardExcel.class); util.exportExcel(response, excelList, "实验室安全检查统计", tips, "实验室安全检查统计导出报表" + LocalDate.now()); } /*** * 检查内容列表 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("检查内容列表") @GetMapping(value = "/contentList") public ResultData contentList(CheckHazardBo hazardBo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page page = new Page<>(hazardBo.getPageNum(), hazardBo.getPageSize()); Page list = getCountList(page, hazardBo); return ResultData.success(list); } /*** *检查内容列表头部数据统计 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("检查内容列表头部数据统计") @GetMapping(value = "/hazardContentTop") public ResultData hazardContenttTop(CheckHazardBo hazardBo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } return ResultData.success(getHazardContentTop(hazardBo)); } private Map getHazardContentTop(CheckHazardBo hazardBo) { Map map = new HashMap<>(); //总数 Integer sumTotal = 0; //已整改 Integer sumYzg = 0; //未整改 Integer sumWzg = 0; //整改率 String rate = "0%"; Page page = new Page().setSize(-1); Page pageList = getCountList(page, hazardBo); if (pageList.getRecords() != null && pageList.getRecords().size() > 0) { for (CheckHazardVo vo : pageList.getRecords()) { sumTotal = sumTotal + vo.getSumTotal(); sumYzg = sumYzg + vo.getSumYzg(); sumWzg = sumWzg + vo.getSumWzg(); } } rate = WorkSchoolController.myPercent(sumYzg, sumTotal, "##.##%"); map.put("sumTotal", sumTotal); map.put("sumYzg", sumYzg); map.put("sumWzg", sumWzg); map.put("rate", rate); return map; } private Page getCountList(Page page, CheckHazardBo bo) { Page list = checkHazardService.hiddenDataContentList(page, bo); if (list.getRecords() != null && list.getRecords().size() > 0) { //查询检查内容危险源总数 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(CheckHazard::getCheckCategory, 2); Integer total = checkHazardService.list(queryWrapper).size(); for (CheckHazardVo vo : list.getRecords()) { //隐患占比 vo.setPercent(WorkSchoolController.myPercent(vo.getSumTotal(), total, "##.##%")); //整改率 vo.setPercent2(WorkSchoolController.myPercent(vo.getSumYzg(), total, "##.##%")); } } return list; } /**** * 数据统计-按照安全隐患列表导出 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.EXPORT) @ApiOperation("安全隐患列表导出") @PostMapping(value = "/contentExport") public void contentExport(HttpServletResponse response, CheckHazardBo hazardBo) throws IOException { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } //查询检查内容危险源总数 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(CheckHazard::getCheckCategory, 2); if(users!=null && !users.isEmpty()){ queryWrapper.lambda().in(CheckHazard::getCreateBy,users); } Integer total = checkHazardService.list(queryWrapper).size(); Page page = new Page().setSize(-1); List excelList = new ArrayList<>(); Page list = checkHazardService.hiddenDataContentList(page, hazardBo); for (CheckHazardVo vo : list.getRecords()) { ContentExcel excel = new ContentExcel(); BeanUtils.copyProperties(vo, excel); //隐患占比 if (vo.getSumTotal() != null && vo.getSumTotal() > 0) { excel.setPercent(WorkSchoolController.myPercent(vo.getSumTotal(), total, "##.##%")); } else { excel.setPercent("0%"); } //整改率 if (vo.getSumYzg() != null && vo.getSumYzg() > 0) { excel.setPercent2(WorkSchoolController.myPercent(vo.getSumYzg(), total, "##.##%")); } else { excel.setPercent2("0%"); } excelList.add(excel); } Map map = getHazardContentTop(hazardBo); //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); String jcnr = "全部";//检查内容 String deptName = "全部";//学院 String subName = "全部";//实验室 String zq = "全部";//统计周期 if (list.getRecords().size() > 0) { jcnr = hazardBo.getHazardTypeMode() == null ? jcnr : list.getRecords().get(0).getHazardTypeModeName(); deptName = hazardBo.getDeptId() == null ? deptName : list.getRecords().get(0).getCollegeName(); subName = hazardBo.getSubId() == null ? subName : list.getRecords().get(0).getSubjectName(); zq = StringUtils.isEmpty(hazardBo.getBeginTime()) ? zq : (hazardBo.getBeginTime() + " ~ " + hazardBo.getEndTime()); } String tips = " 检查内容:" + jcnr + "\n" + " 学院:" + deptName + "\n" + " 实验室:" + subName + "\n" + " 统计周期:" + zq + "\n" + " 生成时间:" + DateUtils.getTime() + "\n" + " 生成者:" + sysUser.getNickName() + " \n" + " 隐患总数:" + map.get("sumTotal") + " 已整改:" + map.get("sumYzg") + " 未整改:" + map.get("sumWzg") + " 整改率:" + map.get("rate"); ExcelUtil util = new ExcelUtil<>(ContentExcel.class); util.exportExcel(response, excelList, "实验室安全检查统计", tips, "实验室安全检查统计导出报表" + LocalDate.now()); } /*** * 根据整改状态获取描述 * @param key * @return */ private static String getRectifyStatusName(Integer key) { String value = null; switch (key) { case 1: value = "复核完毕"; break; case 2: value = "未整改"; break; case 3: value = "已整改"; break; case 4: value = "暂无法整改"; break; default: value = "未知"; } return value; } /*** * 根据隐患级别获取 隐患描述 * @param key * @return */ private static String getHazardLevelName(Integer key) { String value = null; switch (key) { case 1: value = "重大隐患"; break; case 2: value = "一般隐患"; break; case 3: value = "管理问题"; break; default: value = "未知"; } return value; } /*** * 安全指标列表 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("安全指标列表") @GetMapping(value = "/itemsList") public ResultData itemsList(CheckHazardBo hazardBo) { // 获取数据 List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page list = checkHazardService.hiddenDataItemsList(hazardBo); if (list.getRecords().size() > 0) { for (CheckHazardVo vo : list.getRecords()) { vo.setPercent(WorkSchoolController.myPercent(vo.getItemsTotal1(), vo.getSchoolItemsTotal1(), "##.##%")); vo.setPercent2(WorkSchoolController.myPercent(vo.getItemsTotal2(), vo.getSchoolItemsTotal2(), "##.##%")); vo.setPercent3(WorkSchoolController.myPercent(vo.getItemsTotal3(), vo.getSchoolItemsTotal3(), "##.##%")); vo.setPercent4(WorkSchoolController.myPercent(vo.getItemsTotal4(), vo.getSchoolItemsTotal4(), "##.##%")); } } return ResultData.success(list); } /*** * 安全指标列表头部统计 * @param hazardBo * @return */ @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.LIST) @DataPermission() @ApiOperation("安全指标列表头部统计") @GetMapping(value = "/itemsListTop") public ResultData itemsListTitle(CheckHazardBo hazardBo) { // 获取数据 List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } return ResultData.success(getItemsListTop(hazardBo)); } private Map getItemsListTop(CheckHazardBo hazardBo) { Map map = new HashMap<>(); //总数 Integer sumTotal = 0; //1级隐患 Integer level1 = 0; //2级隐患 Integer level2 = 0; //3级隐患 Integer level3 = 0; //4级隐患 Integer level4 = 0; //1级指标占比 String percent1 = "0%"; //2级指标占比 String percent2 = "0%"; //3级指标占比 String percent3 = "0%"; //4级指标占比 String percent4 = "0%"; hazardBo.setPageSize(-1); Page list = checkHazardService.hiddenDataItemsList(hazardBo); if (list.getRecords().size() > 0) { for (CheckHazardVo vo : list.getRecords()) { sumTotal += vo.getSumTotal(); level1 += vo.getItemsTotal1(); level2 += vo.getItemsTotal2(); level3 += vo.getItemsTotal3(); level4 += vo.getItemsTotal4(); } percent1 = WorkSchoolController.myPercent(level1, sumTotal, "##.##%"); percent2 = WorkSchoolController.myPercent(level2, sumTotal, "##.##%"); percent3 = WorkSchoolController.myPercent(level3, sumTotal, "##.##%"); percent4 = WorkSchoolController.myPercent(level4, sumTotal, "##.##%"); } map.put("sumTotal", sumTotal); map.put("level1", level1); map.put("level2", level2); map.put("level3", level3); map.put("level4", level4); map.put("percent1", percent1); map.put("percent2", percent2); map.put("percent3", percent3); map.put("percent4", percent4); return map; } /**** * 数据统计-按照安全指标列表导出 * @param hazardBo * @return */ @DataPermission() @PreAuthorize(hasPermi = PerPrefix.SECURITY_DATA_SUB + PerFun.EXPORT) @ApiOperation("安全指标列表导出") @PostMapping(value = "/itemsExport") public void itemsExport(HttpServletResponse response, CheckHazardBo hazardBo) throws IOException { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ hazardBo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } List excelList = new ArrayList<>(); Page list = checkHazardService.hiddenDataItemsList(hazardBo); if (list.getRecords().size() > 0) { for (CheckHazardVo vo : list.getRecords()) { ItemsExcel excel = new ItemsExcel(); vo.setPercent(WorkSchoolController.myPercent(vo.getItemsTotal1(), vo.getSchoolItemsTotal1(), "##.##%")); vo.setPercent2(WorkSchoolController.myPercent(vo.getItemsTotal2(), vo.getSchoolItemsTotal2(), "##.##%")); vo.setPercent3(WorkSchoolController.myPercent(vo.getItemsTotal3(), vo.getSchoolItemsTotal3(), "##.##%")); vo.setPercent4(WorkSchoolController.myPercent(vo.getItemsTotal4(), vo.getSchoolItemsTotal4(), "##.##%")); BeanUtils.copyProperties(vo, excel); excelList.add(excel); } } Map map = getItemsListTop(hazardBo); //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); String fw = "全部";//范围 String zq = "全部";//统计周期 if (list.getRecords().size() > 0) { zq = StringUtils.isEmpty(hazardBo.getBeginTime()) ? zq : (hazardBo.getBeginTime() + "-" + hazardBo.getEndTime()); fw = hazardBo.getDeptId() == null ? fw : list.getRecords().get(0).getCollegeName(); } String tips = "统计范围:" + fw + " 统计周期:" + zq + "\n" + "生成时间:" + DateUtils.getTime() + " 生成者:" + sysUser.getNickName() + " \n" + "隐患总数:" + map.get("sumTotal") + " ,一级指标隐患总数:" + map.get("level1") + " 占比:" + map.get("percent1") + " ,二级指标隐患总数:" + map.get("level2") + " 占比:" + map.get("percent2") + " ,三级指标隐患总数:" + map.get("level3") + " 占比:" + map.get("percent3") + " ,四级指标隐患总数:" + map.get("level4") + " 占比:" + map.get("percent4"); ExcelUtil util = new ExcelUtil<>(ItemsExcel.class); util.exportExcel(response, excelList, "实验室安全检查统计", tips, "实验室安全检查统计导出报表" + LocalDate.now()); } /*** * 判断当前登录用户安全检查身份类型 * 管理员:1 检查人员:2 整改人员:3 * @return */ public Integer getUserIdentity() { //等级 Integer level = 3; //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); //查看用户是否管理员 AjaxResult arOption = remoteUserService.optionselect(); if (HttpStatus.SUCCESS == Integer.valueOf(arOption.get("code").toString())) { List> linkedHashMap = (List>) arOption.get("data"); if (linkedHashMap != null) { for (int i = 0; i < linkedHashMap.size(); i++) { String postCode = linkedHashMap.get(i).get("postCode").toString(); String postId = linkedHashMap.get(i).get("postId").toString(); if (sysUser.getPosition() != null && manageSign.equals(postCode) && sysUser.getPosition().equals(postId)) { return 1; } } } } QueryWrapper userQueryWrapper = new QueryWrapper<>(); //是否实验室检查人员 userQueryWrapper.lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId()).eq(CheckStaffUser::getStaffType, 1); if (checkStaffUserService.list(userQueryWrapper).size() > 0) { return 2; } QueryWrapper memberQueryWrapper = new QueryWrapper<>(); //是否检查组成员 memberQueryWrapper.lambda().eq(CheckMember::getUserId, sysUser.getUserId()); if (checkMemberService.list(memberQueryWrapper).size() > 0) { return 2; } //是否实验室整改人员 QueryWrapper userQueryWrapper2 = new QueryWrapper<>(); userQueryWrapper2.lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId()).eq(CheckStaffUser::getStaffType, 2); if (checkStaffUserService.list(userQueryWrapper2).size() > 0) { return level; } return level; } /*** * 安全检查统计-小程序端使用 * @param flg * 人员身份 3整改人 2检查人 1管理员 * @return */ @ApiOperation("安全检查统计-小程序端使用") @GetMapping(value = "/countApp") public ResultData countApp(Integer flg) { //本月检查数 Integer checkTotal = 0; //本月隐患数 Integer hazardTotal = 0; //本月已整改 Integer rectifyTotal = 0; //本月检查合格率 String qualifyRate = "0%"; //本月整改率 String rectificationRate = "0%"; //本月复核通过率 String passRate = "0%"; Map map = new HashMap<>(); LocalDate now = LocalDate.now(); //获取当前登录用户 LoginModel sysUser = tokenService.getLoginUser(); if (StringUtils.isNull(flg)) { return ResultData.success(map); } if (3 == flg) { //本月已整改=已整改的次数(不含暂无法整改) LambdaQueryWrapper rectifyWrapper = new LambdaQueryWrapper<>(); rectifyWrapper.eq(CheckRectify::getCreateBy, sysUser.getUserId()).notIn(CheckRectify::getRectifyResult, 0); rectifyWrapper.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); rectifyTotal = checkRectifyService.list(rectifyWrapper).size(); //查询该用户关联实验室集合 QueryWrapper staffUserWrapper = new QueryWrapper<>(); staffUserWrapper.select("sub_id subId ,count(1) sumCount").groupBy("sub_id").lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId()); List> subListMap = checkStaffUserService.listMaps(staffUserWrapper); Long[] ids = subListMap.stream().map(a -> a.get("subId")).toArray(Long[]::new); CheckHazardBo bo = new CheckHazardBo(); bo.setBeginTime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString()); bo.setEndTime(DateUtils.getDate()); if (ids != null && ids.length > 0) { bo.setSubIds(ids); } bo.setManageStatus(2); //当月检查隐患总数 List hazardVoList = checkHazardService.seletHazardList(bo); hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0); //已整改数(已整改的次数(不含暂无法整改)) LambdaQueryWrapper rectifyWrapper2 = new LambdaQueryWrapper<>(); rectifyWrapper2.eq(CheckRectify::getCreateBy, sysUser.getUserId()).notIn(CheckRectify::getRectifyResult, 0); if (!hazardVoList.isEmpty()) { Long[] hazardIds = hazardVoList.stream().map(CheckHazardVo::getId).toArray(Long[]::new); rectifyWrapper2.in(CheckRectify::getCheckHazardId, hazardIds); } rectifyWrapper2.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')").groupBy(CheckRectify::getCheckHazardId); Integer yzgHazard = checkRectifyService.list(rectifyWrapper2).size(); //本月整改率(用户整改的隐患数/隐患总数) rectificationRate = WorkSchoolController.myPercent(Convert.toInt(yzgHazard), hazardTotal, "##.##%"); CheckHazardBo checkHazardBo = new CheckHazardBo(); checkHazardBo.setCheckTimeOrder(2);//按照整改时间查询 checkHazardBo.setBeginTime(now.with(TemporalAdjusters.firstDayOfMonth()).toString()); checkHazardBo.setEndTime(DateUtils.getDate()); //复核通过 checkHazardBo.setExamineResult(1); Long tgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //复核未通过 checkHazardBo.setCreateBy(sysUser.getUserId()); checkHazardBo.setExamineResult(0); Long wtgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //本月复核通过率 passRate = WorkSchoolController.myPercent(Convert.toInt(tgCheck), Convert.toInt((tgCheck + wtgCheck)), "##.##%"); } else if (2 == flg) { //本月已检查数 sec_check_manage=2 的数据 LambdaQueryWrapper manageWrapper = new LambdaQueryWrapper<>(); manageWrapper.eq(CheckManage::getCheckUserId, sysUser.getUserId()).eq(CheckManage::getManageStatus, 2); manageWrapper.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); checkTotal = checkManageService.list(manageWrapper).size(); //查询该用户关联实验室集合 QueryWrapper staffUserWrapper = new QueryWrapper<>(); staffUserWrapper.select("sub_id subId ,count(1) sumCount").groupBy("sub_id").lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId()); List> subListMap = checkStaffUserService.listMaps(staffUserWrapper); Long[] ids = subListMap.stream().map(a -> a.get("subId")).toArray(Long[]::new); CheckHazardBo bo = new CheckHazardBo(); bo.setBeginTime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString()); bo.setEndTime(DateUtils.getDate()); if (ids != null && ids.length > 0) { bo.setSubIds(ids); } bo.setManageStatus(2); //当月检查隐患总数 List hazardVoList = checkHazardService.seletHazardList(bo); hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0); //已整改数(已整改的次数(不含暂无法整改)) LambdaQueryWrapper rectifyWrapper = new LambdaQueryWrapper<>(); rectifyWrapper.eq(CheckRectify::getCreateBy, sysUser.getUserId()).notIn(CheckRectify::getRectifyResult, 0); rectifyWrapper.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); rectifyTotal = checkRectifyService.list(rectifyWrapper).size(); //用户当月整改的隐患数 /*CheckHazardBo haBo = new CheckHazardBo(); haBo.setCheckTimeOrder(2);//按整改时间查询 haBo.setBeginTime(now.with(TemporalAdjusters.firstDayOfMonth()).toString()); haBo.setEndTime(DateUtils.getDate()); haBo.setCreateBy(sysUser.getUserId()); //haBo.setExamineResult(1);//审核通过 haBo.setZgTermOrder(1);//已整改,且不包含无法整改 Long yzgHazard = checkHazardService.hiddenDangerRectifyCount(haBo);*/ LambdaQueryWrapper rectifyWrapper2 = new LambdaQueryWrapper<>(); rectifyWrapper2.eq(CheckRectify::getCreateBy, sysUser.getUserId()).notIn(CheckRectify::getRectifyResult, 4).isNotNull(CheckRectify::getRectifyResult); if (!hazardVoList.isEmpty()) { Long[] hazardIds = hazardVoList.stream().map(CheckHazardVo::getId).toArray(Long[]::new); rectifyWrapper2.in(CheckRectify::getCheckHazardId, hazardIds); } rectifyWrapper2.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')").groupBy(CheckRectify::getCheckHazardId); Integer yzgHazard = checkRectifyService.list(rectifyWrapper2).size(); //检查通过 补充时间条件 LambdaQueryWrapper manWrapper = new LambdaQueryWrapper<>(); manWrapper.eq(CheckManage::getCheckUserId, sysUser.getUserId()).eq(CheckManage::getCheckResult, 1); manWrapper.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); Integer tgTotal = checkManageService.list(manWrapper).size(); //检查不通过 补充时间条件 LambdaQueryWrapper manWrapper2 = new LambdaQueryWrapper<>(); manWrapper2.eq(CheckManage::getCheckUserId, sysUser.getUserId()).eq(CheckManage::getCheckResult, 0); manWrapper2.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); Integer bhTotal = checkManageService.list(manWrapper2).size(); //合格率 qualifyRate = WorkSchoolController.myPercent(tgTotal, (tgTotal + bhTotal), "##.##%"); //本月整改率 :已整改数(不含暂无法整改)÷检查隐患数 rectificationRate = WorkSchoolController.myPercent(Convert.toInt(yzgHazard), hazardTotal, "##.##%"); CheckHazardBo checkHazardBo = new CheckHazardBo(); checkHazardBo.setCheckTimeOrder(1);//按照复核时间查询 checkHazardBo.setBeginTime(now.with(TemporalAdjusters.firstDayOfMonth()).toString()); checkHazardBo.setEndTime(DateUtils.getDate()); checkHazardBo.setReviewedBy(sysUser.getUserId()); //复核未通过 checkHazardBo.setExamineResult(0); Long wtgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //复核通过 checkHazardBo.setExamineResult(1); Long tgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //本月复核通过率 passRate = WorkSchoolController.myPercent(Convert.toInt(tgCheck), Convert.toInt((tgCheck + wtgCheck)), "##.##%"); } else if (1 == flg || 11 == flg) { LoginModel loginModel = tokenService.getLoginUser(); List userIds = null; if (11 == flg) { //如果是院级查询本部门子集集合 ResultData> listResultData = remoteDeptService.getDeptListBySubset(loginModel.getDeptId()); if (listResultData.getCode().equals(HttpStatus.SUCCESS)) { List deptList = listResultData.getData(); if (!deptList.isEmpty()) { List deptIds = deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()); deptIds.add(loginModel.getDeptId()); //查询部门下的用户集合 ResultData> userDeptIDS = remoteUserService.getSysCustomRoleUserIds(deptIds); if (userDeptIDS.getCode().equals(HttpStatus.SUCCESS) && !userDeptIDS.getData().isEmpty()) { userIds = userDeptIDS.getData(); } } } } //本月已检查数 sec_check_manage=2 的数据 LambdaQueryWrapper manageWrapper = new LambdaQueryWrapper<>(); manageWrapper.eq(CheckManage::getManageStatus, 2); manageWrapper.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); if (userIds != null) { manageWrapper.in(CheckManage::getCreateBy, userIds); } checkTotal = checkManageService.list(manageWrapper).size(); CheckHazardBo bo = new CheckHazardBo(); bo.setBeginTime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString()); bo.setEndTime(DateUtils.getDate()); //当月检查隐患总数 bo.setManageStatus(2); if (userIds != null) { bo.setUserIds(userIds.stream().toArray(Long[]::new)); } //hazardTotal = Integer.valueOf(checkHazardService.hiddenDangerCount(bo).toString()); List hazardVoList = checkHazardService.seletHazardList(bo); hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0); //本月已整改(已整改的次数(不含暂无法整改)) LambdaQueryWrapper rectifyWrapper = new LambdaQueryWrapper<>(); rectifyWrapper.notIn(CheckRectify::getRectifyResult, 0); rectifyWrapper.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); if (userIds != null) { rectifyWrapper.in(CheckRectify::getCreateBy, userIds); //bo.setUserIds(userIds.stream().toArray(Long[]::new)); } rectifyTotal = checkRectifyService.list(rectifyWrapper).size(); //当月整改的隐患数 /*CheckHazardBo haBo = new CheckHazardBo(); haBo.setCheckTimeOrder(2);//按照整改时间查询 haBo.setBeginTime(now.with(TemporalAdjusters.firstDayOfMonth()).toString()); haBo.setEndTime(DateUtils.getDate()); //haBo.setExamineResult(1);//审核通过 haBo.setZgTermOrder(1);//已整改,且不包含无法整改 if(userIds!=null){ //rectifyWrapper.in(CheckRectify::getCreateBy,userIds); haBo.setUserIds(userIds.stream().toArray(Long[]::new)); } Long yzgHazard = checkHazardService.hiddenDangerRectifyCount(haBo);*/ LambdaQueryWrapper rectifyWrapper2 = new LambdaQueryWrapper<>(); rectifyWrapper2.notIn(CheckRectify::getRectifyResult, 4).isNotNull(CheckRectify::getRectifyResult); if(userIds!=null){ rectifyWrapper2.in(CheckRectify::getCreateBy,userIds); } if (!hazardVoList.isEmpty()) { Long[] hazardIds = hazardVoList.stream().map(CheckHazardVo::getId).toArray(Long[]::new); rectifyWrapper2.in(CheckRectify::getCheckHazardId, hazardIds); } rectifyWrapper2.apply("date_format(create_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(create_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')").groupBy(CheckRectify::getCheckHazardId); Integer yzgHazard = checkRectifyService.list(rectifyWrapper2).size(); //检查通过 补充时间条件 LambdaQueryWrapper manWrapper = new LambdaQueryWrapper<>(); manWrapper.eq(CheckManage::getCheckResult, 1); manWrapper.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); if (userIds != null) { manWrapper.in(CheckManage::getCreateBy, userIds); //haBo.setUserIds(userIds.stream().toArray(Long[]::new)); } Integer tgTotal = checkManageService.list(manWrapper).size(); //检查不通过 补充时间条件 LambdaQueryWrapper manWrapper2 = new LambdaQueryWrapper<>(); manWrapper2.eq(CheckManage::getCheckResult, 0); manWrapper2.apply("date_format(check_time,'%Y-%m-%d')>=DATE_FORMAT('" + now.with(TemporalAdjusters.firstDayOfMonth()) + "','%Y-%m-%d')") .apply("date_format(check_time,'%Y-%m-%d')<=DATE_FORMAT('" + DateUtils.getDate() + "','%Y-%m-%d')"); if (userIds != null) { manWrapper2.in(CheckManage::getCreateBy, userIds); //haBo.setUserIds(userIds.stream().toArray(Long[]::new)); } Integer bhTotal = checkManageService.list(manWrapper2).size(); //合格率 qualifyRate = WorkSchoolController.myPercent(tgTotal, (tgTotal + bhTotal), "##.##%"); //本月整改率 :已整改数(不含暂无法整改)÷检查隐患数 rectificationRate = WorkSchoolController.myPercent(Convert.toInt(yzgHazard), hazardTotal, "##.##%"); CheckHazardBo checkHazardBo = new CheckHazardBo(); checkHazardBo.setCheckTimeOrder(1);//按照复核时间查询 checkHazardBo.setBeginTime(now.with(TemporalAdjusters.firstDayOfMonth()).toString()); checkHazardBo.setEndTime(DateUtils.getDate()); //复核未通过 checkHazardBo.setExamineResult(0); if (userIds != null) { //manWrapper2.in(CheckManage::getCreateBy,userIds); checkHazardBo.setUserIds(userIds.stream().toArray(Long[]::new)); } Long wtgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //复核通过 checkHazardBo.setExamineResult(1); Long tgCheck = checkHazardService.hiddenDangerRectifyCount(checkHazardBo); //本月复核通过率 passRate = WorkSchoolController.myPercent(Convert.toInt(tgCheck), Convert.toInt((tgCheck + wtgCheck)), "##.#%"); } map.put("checkTotal", checkTotal); map.put("hazardTotal", hazardTotal); map.put("rectifyTotal", rectifyTotal); map.put("qualifyRate", qualifyRate); map.put("rectificationRate", rectificationRate); map.put("passRate", passRate); map.put("userType", flg); return ResultData.success(map); } /*********************************数据大屏*********************************************/ /*** * 获取最新一条进行中的计划 * @return */ private Long getPantId() { Long planId = null; //进行中的计划 QueryWrapper planWrapper = new QueryWrapper<>(); planWrapper.lambda().eq(CheckPlan::getCheckStatus, 2); List list = checkPlanService.list(planWrapper); if (list != null && !list.isEmpty()) { //根据所有正在进行中的计划获取最新一条进行中的计划信息 Long[] planIds = list.stream().map(a -> a.getId()).toArray(Long[]::new); QueryWrapper manageWper = new QueryWrapper<>(); manageWper.lambda().in(CheckManage::getCheckPlanId, planIds).orderByDesc(CheckManage::getCreateTime).last(" limit 1"); List mgList = checkManageService.list(manageWper); if (mgList != null && !mgList.isEmpty()) { planId = mgList.get(0).getCheckPlanId(); } } return planId; } /**** * 大屏数据统计,获取最新一条开始中的计划 * @param * @return */ @ApiOperation("大屏数据统计,获取最新一条开始中的计划") @GetMapping(value = "/bigViewCount") public ResultData bigViewCount() { Map map = new HashMap<>(); //隐患数总 Integer yhTotal = 0; //本次已整改 Integer yzgTotal = 0; //遗留数 Integer ylTotal = 0; //日期 String dateTime = ""; //标题 String title = ""; //获取最新一条进行中的计划 Long planId = getPantId(); if (planId != null) { QueryWrapper planWrapper = new QueryWrapper<>(); planWrapper.lambda().eq(CheckPlan::getId, planId); List list = checkPlanService.list(planWrapper); if (list != null && !list.isEmpty()) { CheckPlan plan = list.get(0); Long pantId = plan.getId(); dateTime = plan.getCreateTime().getYear() + "年" + plan.getCreateTime().getMonthValue() + "月" + plan.getCreateTime().getDayOfMonth() + "日"; title = plan.getTitle(); //该计划下的隐患总数 Page page = new Page().setSize(-1); CheckHazardBo bo = new CheckHazardBo(); bo.setPlanId(pantId); Page hazardList = checkHazardService.hiddenDataStatisticsList(page, bo); yhTotal = hazardList.getRecords().size(); //已整改数 if (yhTotal > 0) { for (CheckHazardVo vo : hazardList.getRecords()) { if (vo.getRectifyStatus().equals(1)) { yzgTotal++; } } //该计划下的遗留总数(未整改的) bo.setRectifyStatus(2); Page notStartedList = checkHazardService.hiddenDataStatisticsList(page, bo); ylTotal = notStartedList.getRecords().size(); } } } map.put("ylTotal", ylTotal); map.put("yzgTotal", yzgTotal); map.put("yhTotal", yhTotal); map.put("dateTime", dateTime); map.put("title", title); map.put("planId", String.valueOf(planId)); return ResultData.success(map); } /*** * 大屏数据统计,获取最新一条开始中的计划下的实验室隐患信息 * @return */ @ApiOperation("大屏数据统计,获取最新一条开始中的计划") @GetMapping(value = "/bigViewList") public TableDataInfo bigViewList(CheckManageBo bo) { List listVo = new ArrayList<>(); //获取最新一条进行中的计划 Long planId = getPantId(); if (planId != null) { //查询计划信息 QueryWrapper planQueryWrapper = new QueryWrapper<>(); planQueryWrapper.lambda().eq(CheckPlan::getId, planId); List checkPlanList = checkPlanService.list(planQueryWrapper); CheckPlan plan = checkPlanList.get(0); //查询该计划下 检查中和已完成的数据 PageHelper.startPage(bo.getPageNum(), bo.getPageSize()); QueryWrapper manageWrapper = new QueryWrapper<>(); manageWrapper.lambda().eq(CheckManage::getCheckPlanId, plan.getId()).notIn(CheckManage::getManageStatus, 0); List manageList = checkManageService.list(manageWrapper); for (CheckManage m : manageList) { QueryWrapper hazardWrapper = new QueryWrapper<>(); //查询该条计划的隐患已整改数量(已完成,不包含暂无法整改) CheckManageVo mVo = new CheckManageVo(); BeanUtils.copyProperties(m, mVo); hazardWrapper.lambda().eq(CheckHazard::getCheckManageId, m.getId()).eq(CheckHazard::getRectifyStatus, 1); List haList = checkHazardService.list(hazardWrapper); //已整改数量 mVo.setAmount(haList.size()); listVo.add(mVo); } } return getDataTable(listVo); } /**** * 大屏遗留问题列表 * @param bo * @return */ @ApiOperation("大屏遗留问题列表") @GetMapping(value = "/remainList") public TableDataInfo bigViewRemainHazardList(CheckHazardBo bo) { List list = new ArrayList<>(); if (StringUtils.isNull(bo.getPlanId())) { return getDataTable(list); } PageHelper.startPage(bo.getPageNum(), bo.getPageSize()); //未整改 bo.setRectifyStatus(2); list = checkHazardService.hazardList(bo); return getDataTable(list); } /**** * 大屏本次检查问题 * @param bo * @return */ @ApiOperation("大屏本次检查问题") @GetMapping(value = "/rectificationList") public TableDataInfo bigViewRectificationHazardList(CheckHazardBo bo) { List list = new ArrayList<>(); if (StringUtils.isNull(bo.getPlanId())) { return getDataTable(list); } PageHelper.startPage(bo.getPageNum(), bo.getPageSize()); list = checkHazardService.hazardList(bo); return getDataTable(list); } /*** * 数据大屏 安全隐患统计-按指标分组 * @param bo * @return */ @DataPermission() @ApiOperation("安全隐患统计-按指标分组") @GetMapping(value = "/groupHazard") public TableDataInfo groupHazard(CheckHazardBo bo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ bo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } PageHelper.startPage(bo.getPageNum(), bo.getPageSize()); return getDataTable(checkHazardService.groupByHazard(bo)); } /*** * 安全隐患统计-按实验室分组 * @param bo * @return */ @DataPermission() @ApiOperation("安全隐患统计-按实验室分组") @GetMapping(value = "/groupSub") public TableDataInfo groupSub(CheckHazardBo bo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ bo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } return getDataTable(checkHazardService.groupBySub(bo)); } @ApiOperation("安全隐患指标列表") @GetMapping(value = "/optionList") public ResultData optionList() { QueryWrapper mgWrapper = new QueryWrapper<>(); mgWrapper.lambda().eq(CheckOption::getLevel, 1).eq(CheckOption::getIsDeleted, 0); Page page = new Page().setSize(-1); return ResultData.success(checkOptionService.page(page, mgWrapper)); } /*** * 数据大屏 安全隐患统计 检查项、实验室分组列表 * @return */ @DataPermission() @ApiOperation("安全隐患指标、实验室列表") @GetMapping(value = "/hazardSubList") public ResultData hazardSubList(CheckHazardBo bo) { List users = DataPermissionAspect.threadLocal.get(); if(users!=null && !users.isEmpty()){ bo.setUserIds(users.stream().toArray(Long[]::new)); DataPermissionAspect.threadLocal.remove(); } Page page = new Page<>(bo.getPageNum(), bo.getPageSize()); return ResultData.success(checkHazardService.groupBySubAndOption(page, bo)); } }