From 9ca0dc6e7833715b875cc9b6b91d5c497b2bae8b Mon Sep 17 00:00:00 2001 From: zf <1603559716@qq.com> Date: 星期三, 30 八月 2023 09:05:45 +0800 Subject: [PATCH] Merge branch 'master' of https://sinanoaq.cn:8888/r/hazardInvestigationSystem into zf --- src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java | 309 +++++++++++++++++++++++++-------------------------- 1 files changed, 153 insertions(+), 156 deletions(-) diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java index d6664fa..1a8b085 100644 --- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gk.hotwork.Domain.*; +import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO; import com.gk.hotwork.Domain.Do.SafetySelfInspectionItemQualifiedCountDO; import com.gk.hotwork.Domain.Exception.BusinessException; import com.gk.hotwork.Domain.Utils.BeanUtils; @@ -53,9 +54,11 @@ private InspectionExpertService expertService; @Autowired private InspectionHiddenDangerService dangerService; + @Autowired + private AttachmentInfoService attachmentInfoService; /** - * @Description: 分页 + * @Description: 自查分页 */ @Override public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { @@ -72,24 +75,22 @@ filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } - filter.put("flag",0); + filter.put("flag",(byte)2); IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); List<SafetySelfInspection> records = res.getRecords(); if (CollectionUtils.isNotEmpty(records)){ DecimalFormat df = new DecimalFormat("0.00%"); records = records.stream().map((safetySelfInspection) -> { - if (safetySelfInspection.getStatus() == 2) { - Long id = safetySelfInspection.getId(); - SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id); - safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem()); - if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) { - BigDecimal rate = new BigDecimal(countDO.getQualifiedItem()) - .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP); - String qualifiedRate = df.format(rate); - safetySelfInspection.setQualifiedRate(qualifiedRate); - safetySelfInspection.setItemSum(countDO.getItemSum()); - } + Long id = safetySelfInspection.getId(); + SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id); + safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem()); + if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) { + BigDecimal rate = new BigDecimal(countDO.getQualifiedItem()) + .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP); + String qualifiedRate = df.format(rate); + safetySelfInspection.setQualifiedRate(qualifiedRate); + safetySelfInspection.setItemSum(countDO.getItemSum()); } return safetySelfInspection; }).collect(Collectors.toList()); @@ -99,7 +100,7 @@ } /** - * @Description: 分页 + * @Description: 监管检查分页 */ @Override public IPage<SafetySelfInspection> selectSupervisePage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { @@ -116,59 +117,13 @@ filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } - filter.put("flag",1); + filter.put("flag",(byte)1); IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); List<SafetySelfInspection> records = res.getRecords(); if (CollectionUtils.isNotEmpty(records)){ DecimalFormat df = new DecimalFormat("0.00%"); records = records.stream().map((safetySelfInspection) -> { - if (safetySelfInspection.getStatus() == 2) { - Long id = safetySelfInspection.getId(); - SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id); - safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem()); - if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) { - BigDecimal rate = new BigDecimal(countDO.getQualifiedItem()) - .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP); - String qualifiedRate = df.format(rate); - safetySelfInspection.setQualifiedRate(qualifiedRate); - safetySelfInspection.setItemSum(countDO.getItemSum()); - } - } - return safetySelfInspection; - }).collect(Collectors.toList()); - res.setRecords(records); - } - return res; - } - /* @Override - public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { - Integer type = user.getType(); - //普通用户 - if (type.equals(3)) { - Long companyid = user.getCompanyid(); - filter.put("companyid",companyid); - } - //监管用户 - if (type.equals(2)) { - Long companyid = user.getCompanyid(); - //获取企业信息 - CompanyInfo companyInfo = companyService.getById(companyid); - filter.put("province",companyInfo.getProvince()); - filter.put("city",companyInfo.getCity()); - filter.put("area",companyInfo.getArea()); - } - - IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); - List<SafetySelfInspection> records = res.getRecords(); - if (CollectionUtils.isNotEmpty(records)){ - DecimalFormat df = new DecimalFormat("0.00%"); - records = records.stream().map((safetySelfInspection) -> { - //总分 - Integer totalScore = 0; - //扣分 - Integer delScore =0; - Long id = safetySelfInspection.getId(); SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id); safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem()); @@ -179,81 +134,13 @@ safetySelfInspection.setQualifiedRate(qualifiedRate); safetySelfInspection.setItemSum(countDO.getItemSum()); } - //计算总分以及得分 - //获取要素 - List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id); - //获取检查项 - List<SafetySelfInspectionItem> safetySelfInspectionItemList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId2(id); - //循环要素 - for(SafetyInspectionElementA elementA : inspectionElementAList){ - //获取该要素的树 - List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA()); - //二级要素 - if (CollectionUtils.isNotEmpty(elementTree)) { - List<ElementTree> elementBList = elementTree.get(0).getChildren(); - for(ElementTree stree : elementBList){ - //三级要素为空 - if(CollectionUtils.isEmpty(stree.getChildren())){ - //总分累计 - totalScore += stree.getPoint(); - //无三级要素过滤出二级要素检查内容 - List<SafetySelfInspectionItem> sItemList = safetySelfInspectionItemList - .stream() - .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue())) - .collect(Collectors.toList()); - //判断是否有否决项 - List<SafetySelfInspectionItem> rejectList = sItemList - .stream() - .filter(item -> item.getSafetyInspectionItemResult().equals(0)) - .collect(Collectors.toList()); - - if(rejectList.size() > 0){ - delScore += stree.getPoint(); - }else { - //计算出不合格扣分 - delScore += unqualifiedItemDelScore(sItemList); - } - - } else { - List<ElementTree> elementCList = stree.getChildren(); - for(ElementTree ttree : elementCList){ - //计算总分 - totalScore += ttree.getPoint(); - //过滤该三级要素检查项目 - List<SafetySelfInspectionItem> tItemList = safetySelfInspectionItemList - .stream() - .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue())) - .collect(Collectors.toList()); - //判断是否有被否决 - List<SafetySelfInspectionItem> rejectList = tItemList - .stream() - .filter(item -> item.getSafetyInspectionItemResult().equals(0)) - .collect(Collectors.toList()); - if(rejectList.size() > 0){ - delScore += ttree.getPoint(); - }else { - //计算出不合格扣分 - totalScore += unqualifiedItemDelScore(tItemList); - } - } - - } - } - - } - - - } - //得分 - Integer score = totalScore - delScore; - safetySelfInspection.setTotalScore(totalScore.toString()); - safetySelfInspection.setScore(score.toString()); return safetySelfInspection; }).collect(Collectors.toList()); res.setRecords(records); } return res; - }*/ + } + //累计过出不合格扣分 private Integer unqualifiedItemDelScore(List<SafetySelfInspectionItem> itemList){ int delScore = 0; @@ -287,7 +174,7 @@ Date date = new Date(); String username = user.getRealname(); param.setValidFlag(Boolean.TRUE); - param.setFlag((byte) 0); + param.setFlag((byte) 2); param.setUpdateBy(username); param.setCreateBy(username); param.setUpdateTime(date); @@ -324,6 +211,7 @@ * @param param * @param user */ + @Transactional @Override public void addSupervise(SafetySelfInspection param, UserInfo user) { requiredSuperviseVerification(param); @@ -459,6 +347,7 @@ /** * @Description: 删除 */ + @Transactional @Override public void delOne(Long id, UserInfo user) { selectVerification(id); @@ -523,25 +412,30 @@ BeanUtils.copyProperties(safetySelfInspection,safetySelfInspectionRespDTO); //获取所有检查项 List<SafetySelfInspectionItem> itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified); - //获取关联要素 - List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id); + //获取要素树 + List<ElementTree> elementTreeList = elementManagementService.getMenuType1Tree(); + //获取附件 + List<AttachmentInfo> byBusinessId = attachmentInfoService.findByBusinessId(id); + safetySelfInspectionRespDTO.setAttachmentList(byBusinessId); List<SafetySelfInspectionElementRespDTO> arespDTOList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(inspectionElementAList)) { - for (SafetyInspectionElementA elementA : inspectionElementAList) { - //获取该要素的树 - List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA()); - if (CollectionUtils.isNotEmpty(elementTree)) { - //一级要素 - ElementTree otree = elementTree.get(0); + if (CollectionUtils.isNotEmpty(elementTreeList)) { + for (ElementTree elementA : elementTreeList) { + + List<SafetySelfInspectionItem> selectElementList = itemList + .stream() + .filter(item -> item.getElementA() != null && + item.getElementA().equals(elementA.getValue())) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(selectElementList)) { SafetySelfInspectionElementRespDTO elementARespDTO = new SafetySelfInspectionElementRespDTO(); - elementARespDTO.setElementId(otree.getValue()); - elementARespDTO.setElementName(otree.getLabel()); - elementARespDTO.setType(otree.getType()); + elementARespDTO.setElementId(elementA.getValue()); + elementARespDTO.setElementName(elementA.getLabel()); + elementARespDTO.setType(elementA.getType()); List<SafetySelfInspectionElementRespDTO> brespDTOList = new ArrayList<>(); //二级要素 - List<ElementTree> elementBList = otree.getChildren(); + List<ElementTree> elementBList = elementA.getChildren(); if(CollectionUtils.isNotEmpty(elementBList)){ for (ElementTree stree : elementBList) { SafetySelfInspectionElementRespDTO elementBRespDTO = new SafetySelfInspectionElementRespDTO(); @@ -560,7 +454,9 @@ //无三级要素过滤出二级要素检查内容 List<SafetySelfInspectionItem> sItemList = itemList .stream() - .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue())) + .filter(item -> item.getElementC() == null + && item.getElementB() != null + && item.getElementB().equals(stree.getValue())) .collect(Collectors.toList()); //填充检查项 elementBRespDTO.setItemList(assemblyDeduction(sItemList)); @@ -671,6 +567,7 @@ SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id); List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId()); List<InspectionHiddenDanger> inspectionHiddenDangerList = dangerService.getBySafetySelfInspectionItemId(id); + List<AttachmentInfo> byBusinessId = attachmentInfoService.findByBusinessId(id); if (CollectionUtils.isNotEmpty(selfDeductionList)){ safetySelfInspectionItem.setSelfDeductionList(selfDeductionList); @@ -691,10 +588,25 @@ safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>()); } } + for (InspectionHiddenDanger inspectionHiddenDanger : inspectionHiddenDangerList) { + if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){ + List<Long> attachmentIds = new ArrayList<>(); + String[] split = inspectionHiddenDanger.getUrl().split(","); + for (String s : split) { + attachmentIds.add(Long.valueOf(s)); + } + + List<AttachmentInfo> dangerAttachList = attachmentInfoService.findByIds(attachmentIds); + inspectionHiddenDanger.setAttachmentList(dangerAttachList); + } + + } + safetySelfInspectionItem.setAttachmentList(byBusinessId); safetySelfInspectionItem.setDangerList(inspectionHiddenDangerList); return safetySelfInspectionItem; } + @Transactional @Override public void modItemInfo(SafetySelfInspectionItem param, UserInfo user) { @@ -706,11 +618,22 @@ param.setUpdateTime(date); param.setUpdateBy(username); safetySelfInspectionItemMapper.updateById(param); + //附件 + List<AttachmentInfo> attachmentInfoList = new ArrayList<>(); + if(CollectionUtils.isNotEmpty(param.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : param.getAttachmentList()) { + attachmentInfo.setBusinessId(param.getId()); + attachmentInfoList.add(attachmentInfo); + } + } + if (param.getSafetyInspectionItemResult()==0 || param.getSafetyInspectionItemResult() == 2){ //否决 合格--删除扣分记录 safetySelfInspectionItemDeductionMapper.delBySafetySelfInspectionItemId(param.getId(),username,date); //删除隐患 - dangerService.delByInspectionItemId(param.getSafetyInspectionItemId(),user); + dangerService.delByInspectionItemId(param.getId(),user); + //删除附件 + attachmentInfoService.deleteByBusinessId(param.getId()); }else{ //扣分 List<SafetySelfInspectionItemDeduction> list = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(param.getId()); @@ -748,23 +671,53 @@ dangerService.delByIds(idList); } for (InspectionHiddenDanger inspectionHiddenDanger : param.getDangerList()) { + StringBuffer stringBuffer = new StringBuffer(); + //附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + stringBuffer.append(attachmentInfo.getId().toString()).append(","); + } + stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length()-1); + } + if(inspectionHiddenDanger.getId() == null){ inspectionHiddenDanger.setCreateBy(user.getRealname()); inspectionHiddenDanger.setCreateTime(new Date()); inspectionHiddenDanger.setUpdateBy(user.getRealname()); inspectionHiddenDanger.setUpdateTime(new Date()); - inspectionHiddenDanger.setStatus((byte)0); + inspectionHiddenDanger.setStatus((byte)-1); inspectionHiddenDanger.setValidFlag(true); inspectionHiddenDanger.setSelfInspectionId(param.getSafetySelfInspectionId()); inspectionHiddenDanger.setSelfInspectionItemId(param.getId()); + inspectionHiddenDanger.setUrl(stringBuffer.toString()); dangerService.save(inspectionHiddenDanger); + //附件 + if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + attachmentInfo.setBusinessId(inspectionHiddenDanger.getId()); + attachmentInfoList.add(attachmentInfo); + } + } }else { inspectionHiddenDanger.setUpdateBy(user.getRealname()); inspectionHiddenDanger.setUpdateTime(new Date()); + inspectionHiddenDanger.setUrl(stringBuffer.toString()); dangerService.updateById(inspectionHiddenDanger); + //附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + attachmentInfo.setBusinessId(inspectionHiddenDanger.getId()); + attachmentInfoList.add(attachmentInfo); + } + } } } } + + } + //附件信息更新 + if(CollectionUtils.isNotEmpty(attachmentInfoList)){ + attachmentInfoService.updateBusinessIdBatch(attachmentInfoList); } } @@ -778,6 +731,7 @@ safetySelfInspection.setStatus(2); safetySelfInspection.setUpdateTime(date); safetySelfInspection.setUpdateBy(username); + safetySelfInspection.setInspectionEndTime(new Date()); safetySelfInspectionMapper.updateById(safetySelfInspection); } @@ -788,6 +742,55 @@ item.setUpdateTime(new Date()); }); safetySelfInspectionItemMapper.updateBatch(itemList); + } + + @Override + public void addCheckAttachment(List<AttachmentInfo> attachmentList, UserInfo user) { + requiredAttachmentVerification(attachmentList); + for (AttachmentInfo attachmentInfo : attachmentList) { + attachmentInfo.setUpdateTime(new Date()); + attachmentInfo.setUpdateUid(user.getId()); + attachmentInfo.setUpdateUname(user.getRealname()); + } + attachmentInfoService.updateBusinessIdBatch(attachmentList); + } + + @Override + public Date selectLastTimeByCompanyId(Long companyId,Date startTime,Date endTime) { + SafetySelfInspection inspection = safetySelfInspectionMapper.selectOne(new LambdaQueryWrapper<SafetySelfInspection>() + .eq(SafetySelfInspection::getValidFlag,1) + .eq(SafetySelfInspection::getFlag, 2) + .eq(SafetySelfInspection::getCheckedCompanyId, companyId) + .ge(startTime != null,SafetySelfInspection::getInspectionTime,startTime) + .le(endTime != null,SafetySelfInspection::getInspectionTime,endTime) + .orderByDesc(SafetySelfInspection::getInspectionTime) + .last("limit 1")); + if(inspection != null){ + return inspection.getInspectionTime(); + } + return null; + + } + + @Override + public CompanyStatisticInspectionDO companyStatisticInspection(Map<String, Object> params) { + + return safetySelfInspectionMapper.companyStatisticInspection(params); + } + + private void requiredAttachmentVerification(List<AttachmentInfo> attachmentList) { + if(CollectionUtils.isEmpty(attachmentList)){ + throw new BusinessException("附件信息为空"); + } + for (AttachmentInfo attachmentInfo : attachmentList) { + if(attachmentInfo.getId() == null){ + throw new BusinessException("附件主键信息不能为空"); + } + if(attachmentInfo.getBusinessId() == null){ + throw new BusinessException("附件信息关联业务id不能为空"); + } + } + } /** @@ -845,13 +848,7 @@ if (param.getCheckedCompanyId() == null){ throw new BusinessException("请选择被检查公司"); } - if(CollectionUtils.isEmpty(param.getElementAList())){ - throw new BusinessException("请选择A检查要素"); - } - for(SafetyInspectionElementA elementA : param.getElementAList()){ - if(elementA.getElementA() == null){ - throw new BusinessException("请选择A检查要素"); - } - } } + + } -- Gitblit v1.9.2