| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489 |
- 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- bo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckManageVo> page = new Page<>(bo.getPageNum(), bo.getPageSize());
- return ResultData.success(getSubList(page, bo));
- }
- private Page<CheckManageVo> getSubList(Page page, CheckManageBo bo) {
- Page<CheckManageVo> 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<String, Object>> linkedHashMap = (List<LinkedHashMap<String, Object>>) 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<LinkedHashMap<String, Object>> linkedHazardRdMap = (List<LinkedHashMap<String, Object>>) 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<Long> 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<String, Object> getSubListTop(CheckManageBo bo) {
- Map<String, Object> map = new HashMap<>();
- //安全分级
- Map<Long, Integer> classmap = new HashMap<>();
- //安全分类
- Map<Long, Integer> classTypemap = new HashMap<>();
- //安全分级
- List<CheckManageVo> classListVo = new ArrayList<>();
- //安全分类
- List<CheckManageVo> classTypeListVo = new ArrayList<>();
- //总数
- Integer sumTotal = 0;
- //存在危险源的实验室数量
- Integer hazardSubjectTotal = 0;
- //危险源总数
- Integer hazardTotal = 0;
- //特种设备总数
- Integer specialTotal = 0;
- Page<CheckManageVo> page = new Page().setSize(-1);
- Page<CheckManageVo> 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<String, Object>> linkedHashMap = (List<LinkedHashMap<String, Object>>) 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<String, Object>> linkedHashMap = (List<LinkedHashMap<String, Object>>) 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<String, Object>> linkedHashMap = (List<LinkedHashMap<String, Object>>) 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<SubjectExcel> excelList = new ArrayList<>();
- Page<CheckManageVo> page = new Page().setSize(-1);
- bo.setSubListIds(bo.getIds());
- Page<CheckManageVo> 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<String, Object> map = getSubListTop(bo);
- //安全等级
- List<CheckManageVo> classListVoList = (List<CheckManageVo>) map.get("classListVo");
- if (classListVoList != null && !classListVoList.isEmpty()) {
- for (CheckManageVo vo : classListVoList) {
- audjList += vo.getLevelName() + ":" + vo.getAmount() + " ";
- }
- }
- //安全分类
- List<CheckManageVo> classTypeList = (List<CheckManageVo>) 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<SubjectExcel> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckHazardBo> page = new Page<>(hazardBo.getPageNum(), hazardBo.getPageSize());
- //排序标识
- hazardBo.setAppFlag(1);
- Page<CheckHazardVo> 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<Long> 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<String, Object> getHazardListTop(CheckHazardBo hazardBo) {
- Map<String, Object> 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<CheckHazardBo> page = new Page().setSize(-1);
- Page<CheckHazardVo> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckHazardBo> page = new Page().setSize(-1);
- List<HazardExcel> excelList = new ArrayList<>();
- Page<CheckHazardVo> 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<String, Object> 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<HazardExcel> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckHazardBo> page = new Page<>(hazardBo.getPageNum(), hazardBo.getPageSize());
- Page<CheckHazardVo> 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<Long> 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<String, Object> getHazardContentTop(CheckHazardBo hazardBo) {
- Map<String, Object> map = new HashMap<>();
- //总数
- Integer sumTotal = 0;
- //已整改
- Integer sumYzg = 0;
- //未整改
- Integer sumWzg = 0;
- //整改率
- String rate = "0%";
- Page<CheckHazardBo> page = new Page().setSize(-1);
- Page<CheckHazardVo> 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<CheckHazardVo> getCountList(Page page, CheckHazardBo bo) {
- Page<CheckHazardVo> list = checkHazardService.hiddenDataContentList(page, bo);
- if (list.getRecords() != null && list.getRecords().size() > 0) {
- //查询检查内容危险源总数
- QueryWrapper<CheckHazard> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- //查询检查内容危险源总数
- QueryWrapper<CheckHazard> 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<CheckHazardBo> page = new Page().setSize(-1);
- List<ContentExcel> excelList = new ArrayList<>();
- Page<CheckHazardVo> 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<String, Object> 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<ContentExcel> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckHazardVo> 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<Long> 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<String, Object> getItemsListTop(CheckHazardBo hazardBo) {
- Map<String, Object> 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<CheckHazardVo> 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<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- hazardBo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- List<ItemsExcel> excelList = new ArrayList<>();
- Page<CheckHazardVo> 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<String, Object> 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<ItemsExcel> 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<String, Object>> linkedHashMap = (List<LinkedHashMap<String, Object>>) 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<CheckStaffUser> userQueryWrapper = new QueryWrapper<>();
- //是否实验室检查人员
- userQueryWrapper.lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId()).eq(CheckStaffUser::getStaffType, 1);
- if (checkStaffUserService.list(userQueryWrapper).size() > 0) {
- return 2;
- }
- QueryWrapper<CheckMember> memberQueryWrapper = new QueryWrapper<>();
- //是否检查组成员
- memberQueryWrapper.lambda().eq(CheckMember::getUserId, sysUser.getUserId());
- if (checkMemberService.list(memberQueryWrapper).size() > 0) {
- return 2;
- }
- //是否实验室整改人员
- QueryWrapper<CheckStaffUser> 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<String, Object> map = new HashMap<>();
- LocalDate now = LocalDate.now();
- //获取当前登录用户
- LoginModel sysUser = tokenService.getLoginUser();
- if (StringUtils.isNull(flg)) {
- return ResultData.success(map);
- }
- if (3 == flg) {
- //本月已整改=已整改的次数(不含暂无法整改)
- LambdaQueryWrapper<CheckRectify> 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<CheckStaffUser> staffUserWrapper = new QueryWrapper<>();
- staffUserWrapper.select("sub_id subId ,count(1) sumCount").groupBy("sub_id").lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId());
- List<Map<String, Object>> 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<CheckHazardVo> hazardVoList = checkHazardService.seletHazardList(bo);
- hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0);
- //已整改数(已整改的次数(不含暂无法整改))
- LambdaQueryWrapper<CheckRectify> 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<CheckManage> 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<CheckStaffUser> staffUserWrapper = new QueryWrapper<>();
- staffUserWrapper.select("sub_id subId ,count(1) sumCount").groupBy("sub_id").lambda().eq(CheckStaffUser::getUserId, sysUser.getUserId());
- List<Map<String, Object>> 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<CheckHazardVo> hazardVoList = checkHazardService.seletHazardList(bo);
- hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0);
- //已整改数(已整改的次数(不含暂无法整改))
- LambdaQueryWrapper<CheckRectify> 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<CheckRectify> 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<CheckManage> 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<CheckManage> 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<Long> userIds = null;
- if (11 == flg) {
- //如果是院级查询本部门子集集合
- ResultData<List<SysDept>> listResultData = remoteDeptService.getDeptListBySubset(loginModel.getDeptId());
- if (listResultData.getCode().equals(HttpStatus.SUCCESS)) {
- List<SysDept> deptList = listResultData.getData();
- if (!deptList.isEmpty()) {
- List<Long> deptIds = deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList());
- deptIds.add(loginModel.getDeptId());
- //查询部门下的用户集合
- ResultData<List<Long>> userDeptIDS = remoteUserService.getSysCustomRoleUserIds(deptIds);
- if (userDeptIDS.getCode().equals(HttpStatus.SUCCESS) && !userDeptIDS.getData().isEmpty()) {
- userIds = userDeptIDS.getData();
- }
- }
- }
- }
- //本月已检查数 sec_check_manage=2 的数据
- LambdaQueryWrapper<CheckManage> 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<CheckHazardVo> hazardVoList = checkHazardService.seletHazardList(bo);
- hazardTotal = Integer.valueOf(!hazardVoList.isEmpty() ? hazardVoList.size() : 0);
- //本月已整改(已整改的次数(不含暂无法整改))
- LambdaQueryWrapper<CheckRectify> 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<CheckRectify> 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<CheckManage> 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<CheckManage> 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<CheckPlan> planWrapper = new QueryWrapper<>();
- planWrapper.lambda().eq(CheckPlan::getCheckStatus, 2);
- List<CheckPlan> list = checkPlanService.list(planWrapper);
- if (list != null && !list.isEmpty()) {
- //根据所有正在进行中的计划获取最新一条进行中的计划信息
- Long[] planIds = list.stream().map(a -> a.getId()).toArray(Long[]::new);
- QueryWrapper<CheckManage> manageWper = new QueryWrapper<>();
- manageWper.lambda().in(CheckManage::getCheckPlanId, planIds).orderByDesc(CheckManage::getCreateTime).last(" limit 1");
- List<CheckManage> 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<String, Object> map = new HashMap<>();
- //隐患数总
- Integer yhTotal = 0;
- //本次已整改
- Integer yzgTotal = 0;
- //遗留数
- Integer ylTotal = 0;
- //日期
- String dateTime = "";
- //标题
- String title = "";
- //获取最新一条进行中的计划
- Long planId = getPantId();
- if (planId != null) {
- QueryWrapper<CheckPlan> planWrapper = new QueryWrapper<>();
- planWrapper.lambda().eq(CheckPlan::getId, planId);
- List<CheckPlan> 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<CheckHazardBo> page = new Page().setSize(-1);
- CheckHazardBo bo = new CheckHazardBo();
- bo.setPlanId(pantId);
- Page<CheckHazardVo> 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<CheckHazardVo> 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<CheckManageVo> listVo = new ArrayList<>();
- //获取最新一条进行中的计划
- Long planId = getPantId();
- if (planId != null) {
- //查询计划信息
- QueryWrapper<CheckPlan> planQueryWrapper = new QueryWrapper<>();
- planQueryWrapper.lambda().eq(CheckPlan::getId, planId);
- List<CheckPlan> checkPlanList = checkPlanService.list(planQueryWrapper);
- CheckPlan plan = checkPlanList.get(0);
- //查询该计划下 检查中和已完成的数据
- PageHelper.startPage(bo.getPageNum(), bo.getPageSize());
- QueryWrapper<CheckManage> manageWrapper = new QueryWrapper<>();
- manageWrapper.lambda().eq(CheckManage::getCheckPlanId, plan.getId()).notIn(CheckManage::getManageStatus, 0);
- List<CheckManage> manageList = checkManageService.list(manageWrapper);
- for (CheckManage m : manageList) {
- QueryWrapper<CheckHazard> hazardWrapper = new QueryWrapper<>();
- //查询该条计划的隐患已整改数量(已完成,不包含暂无法整改)
- CheckManageVo mVo = new CheckManageVo();
- BeanUtils.copyProperties(m, mVo);
- hazardWrapper.lambda().eq(CheckHazard::getCheckManageId, m.getId()).eq(CheckHazard::getRectifyStatus, 1);
- List<CheckHazard> 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<CheckHazardVo> 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<CheckHazardVo> 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<Long> 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<Long> 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<CheckOption> mgWrapper = new QueryWrapper<>();
- mgWrapper.lambda().eq(CheckOption::getLevel, 1).eq(CheckOption::getIsDeleted, 0);
- Page<CheckOption> page = new Page().setSize(-1);
- return ResultData.success(checkOptionService.page(page, mgWrapper));
- }
- /***
- * 数据大屏 安全隐患统计 检查项、实验室分组列表
- * @return
- */
- @DataPermission()
- @ApiOperation("安全隐患指标、实验室列表")
- @GetMapping(value = "/hazardSubList")
- public ResultData hazardSubList(CheckHazardBo bo) {
- List<Long> users = DataPermissionAspect.threadLocal.get();
- if(users!=null && !users.isEmpty()){
- bo.setUserIds(users.stream().toArray(Long[]::new));
- DataPermissionAspect.threadLocal.remove();
- }
- Page<CheckHazardBo> page = new Page<>(bo.getPageNum(), bo.getPageSize());
- return ResultData.success(checkHazardService.groupBySubAndOption(page, bo));
- }
- }
|