package com.gk.hotwork.Service.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; 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; import com.gk.hotwork.Domain.Utils.StringUtils; import com.gk.hotwork.Domain.Vo.UserVo; import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionElementRespDTO; import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionRespDTO; import com.gk.hotwork.Mapper.*; import com.gk.hotwork.Service.*; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Service("SafetySelfInspectionService") @Transactional public class SafetySelfInspectionImpl extends ServiceImpl implements SafetySelfInspectionService { @Autowired private SafetySelfInspectionMapper safetySelfInspectionMapper; @Autowired private SafetySelfInspectionItemMapper safetySelfInspectionItemMapper; @Autowired private SafetySelfInspectionItemDeductionMapper safetySelfInspectionItemDeductionMapper; @Autowired private SafetyInspectionItemDeductionMapper safetyInspectionItemDeductionMapper; @Autowired private CompanyService companyService; @Autowired private ElementManagementService elementManagementService; @Autowired private SafetyInspectionElementAService safetyInspectionElementAService; @Autowired private UserService userService; @Autowired private InspectionExpertGroupService expertGroupService; @Autowired private InspectionExpertService expertService; @Autowired private InspectionHiddenDangerService dangerService; @Autowired private AttachmentInfoService attachmentInfoService; /** * @Description: 自查分页 */ @Override public IPage selectPage(Page page, Map filter, UserInfo user) { Integer type = user.getType(); //企业用户 if (type.equals(3)) { Long companyid = user.getCompanyid(); filter.put("checkedCompanyId",companyid); } //监管用户 if (type.equals(2)) { //获取企业信息 filter.put("province",user.getProvince()); filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } filter.put("flag",(byte)2); IPage res = safetySelfInspectionMapper.selectPages(page, filter); List records = res.getRecords(); if (CollectionUtils.isNotEmpty(records)){ DecimalFormat df = new DecimalFormat("0.00%"); records = records.stream().map((safetySelfInspection) -> { 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; } /** * @Description: 监管检查分页 */ @Override public IPage selectSupervisePage(Page page, Map filter, UserInfo user) { Integer type = user.getType(); //普通用户 if (type.equals(3)) { Long companyid = user.getCompanyid(); filter.put("checkedCompanyId",companyid); } //监管用户 if (type.equals(2)) { //获取企业信息 filter.put("province",user.getProvince()); filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } filter.put("flag",(byte)1); IPage res = safetySelfInspectionMapper.selectPages(page, filter); List records = res.getRecords(); if (CollectionUtils.isNotEmpty(records)){ DecimalFormat df = new DecimalFormat("0.00%"); records = records.stream().map((safetySelfInspection) -> { 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; } //累计过出不合格扣分 private Integer unqualifiedItemDelScore(List itemList){ int delScore = 0; //过滤出不合格 List unqualifiedItemList = itemList .stream() .filter(item -> item.getSafetyInspectionItemResult().equals(1)) .collect(Collectors.toList()); for (SafetySelfInspectionItem unqualifiedItem : unqualifiedItemList){ List itemDeductionList = safetySelfInspectionItemDeductionMapper .selectList(new LambdaQueryWrapper() .eq(SafetySelfInspectionItemDeduction::getSafetySelfInspectionItemId, unqualifiedItem.getId()) .eq(SafetySelfInspectionItemDeduction::getValidFlag,1)); for (SafetySelfInspectionItemDeduction itemDeduction : itemDeductionList) { delScore += itemDeduction.getPoint(); } } return delScore; } /** * @Description: 新增 */ @Override @Transactional public void addOne(SafetySelfInspection param, UserInfo user) { requiredVerification(param); Date date = new Date(); String username = user.getRealname(); param.setValidFlag(Boolean.TRUE); param.setFlag((byte) 2); param.setUpdateBy(username); param.setCreateBy(username); param.setUpdateTime(date); param.setCreateTime(date); param.setCheckUnit(user.getCompany()); this.save(param); if (CollectionUtils.isNotEmpty(param.getItemList())) { for (SafetySelfInspectionItem safetySelfInspectionItem : param.getItemList()) { //默认合格 safetySelfInspectionItem.setSafetyInspectionItemResult(2); safetySelfInspectionItem.setValidFlag(Boolean.TRUE); safetySelfInspectionItem.setUpdateBy(username); safetySelfInspectionItem.setCreateBy(username); safetySelfInspectionItem.setUpdateTime(date); safetySelfInspectionItem.setCreateTime(date); safetySelfInspectionItem.setSafetySelfInspectionId(param.getId()); safetySelfInspectionItemMapper.insert(safetySelfInspectionItem); } } if(CollectionUtils.isNotEmpty(param.getElementAList())){ for (SafetyInspectionElementA inspectionElementA : param.getElementAList()) { SafetyInspectionElementA safetyInspectionElementA = new SafetyInspectionElementA(); safetyInspectionElementA.setSafetyInspectionId(param.getId()); safetyInspectionElementA.setElementA(inspectionElementA.getElementA()); safetyInspectionElementAService.save(safetyInspectionElementA); } } } /** * 监管检查-新增 * @param param * @param user */ @Transactional @Override public void addSupervise(SafetySelfInspection param, UserInfo user) { requiredSuperviseVerification(param); Date date = new Date(); String username = user.getRealname(); param.setValidFlag(Boolean.TRUE); param.setFlag((byte) 1); param.setInspector(user.getId()); param.setUpdateBy(username); param.setCreateBy(username); param.setUpdateTime(date); param.setCreateTime(date); param.setCheckUnit(user.getCompany()); this.save(param); //生成专家组记录 InspectionExpertGroup inspectionExpertGroup = new InspectionExpertGroup(); inspectionExpertGroup.setInspectionName(param.getInspectionName()); inspectionExpertGroup.setInspectionTime(param.getInspectionTime()); inspectionExpertGroup.setCheckedCompanyId(param.getCheckedCompanyId()); inspectionExpertGroup.setCheckedCompanyName(param.getCheckedCompanyName()); inspectionExpertGroup.setCheckUnit(user.getCompany()); inspectionExpertGroup.setSelfInspectionId(param.getId()); inspectionExpertGroup.setValidFlag(true); inspectionExpertGroup.setCreateTime(new Date()); List collect = param.getExpertList().stream().filter(inspectionExpert -> inspectionExpert.getIsLeader() == true).collect(Collectors.toList()); if (collect.size() > 0) { UserVo userVo = userService.selectUserVoById(collect.get(0).getExpertId()); inspectionExpertGroup.setExpertLeader(userVo.getRealname()); } expertGroupService.save(inspectionExpertGroup); if (CollectionUtils.isNotEmpty(param.getItemList())) { for (SafetySelfInspectionItem safetySelfInspectionItem : param.getItemList()) { //默认合格 safetySelfInspectionItem.setSafetyInspectionItemResult(2); safetySelfInspectionItem.setValidFlag(Boolean.TRUE); safetySelfInspectionItem.setUpdateBy(username); safetySelfInspectionItem.setCreateBy(username); safetySelfInspectionItem.setUpdateTime(date); safetySelfInspectionItem.setCreateTime(date); safetySelfInspectionItem.setSafetySelfInspectionId(param.getId()); safetySelfInspectionItemMapper.insert(safetySelfInspectionItem); } } if(CollectionUtils.isNotEmpty(param.getElementAList())){ for (SafetyInspectionElementA inspectionElementA : param.getElementAList()) { SafetyInspectionElementA safetyInspectionElementA = new SafetyInspectionElementA(); safetyInspectionElementA.setSafetyInspectionId(param.getId()); safetyInspectionElementA.setElementA(inspectionElementA.getElementA()); safetyInspectionElementAService.save(safetyInspectionElementA); } } if(CollectionUtils.isNotEmpty(param.getExpertList())){ for (InspectionExpert inspectionExpert : param.getExpertList()) { UserVo userVo = userService.selectUserVoById(inspectionExpert.getExpertId()); inspectionExpert.setCompanyName(userVo.getCompany()); inspectionExpert.setIdcard(userVo.getIdcard()); inspectionExpert.setName(userVo.getRealname()); inspectionExpert.setPhone(userVo.getUsername()); inspectionExpert.setType(userVo.getType()); inspectionExpert.setProfessionalLevel(user.getProfessionalLevel()); inspectionExpert.setSpecialityName(userVo.getSpecialityName()); inspectionExpert.setSelfInspectionId(param.getId()); inspectionExpert.setExpertGropId(inspectionExpertGroup.getId()); expertService.save(inspectionExpert); } } } /** * @Description: 修改 */ @Override public void modOne(SafetySelfInspection param, UserInfo user) { selectVerification(param.getId()); requiredVerification(param); //更新主表 Date date = new Date(); String username = user.getRealname(); param.setUpdateTime(date); param.setUpdateBy(username); this.updateById(param); //更新检查项表 //1.新增新的元素 //2.删除旧的不存在的元素 List oldFileList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId(param.getId()); List newFileList = param.getItemList(); List oldIdList = new ArrayList<>(); List newIdList = new ArrayList<>(); for (SafetySelfInspectionItem oldSafetySelfInspectionItem :oldFileList ){ oldIdList.add(oldSafetySelfInspectionItem.getId()); } for (SafetySelfInspectionItem newSafetySelfInspectionItem :newFileList ){ if (newSafetySelfInspectionItem.getId()==null){ //1.添加新增的元素 newSafetySelfInspectionItem.setValidFlag(Boolean.TRUE); newSafetySelfInspectionItem.setUpdateBy(username); newSafetySelfInspectionItem.setCreateBy(username); newSafetySelfInspectionItem.setUpdateTime(date); newSafetySelfInspectionItem.setCreateTime(date); newSafetySelfInspectionItem.setSafetySelfInspectionId(param.getId()); safetySelfInspectionItemMapper.insert(newSafetySelfInspectionItem); }else{ newIdList.add(newSafetySelfInspectionItem.getId()); } } //2.删除不存在的元素 List diffList = getDif(oldIdList,newIdList); if (CollectionUtils.isNotEmpty(diffList)){ for (Long id : diffList){ safetySelfInspectionItemMapper.deleteById(id,username,date); } } } public List getDif(List oldIdList , List newIdList ){ ArrayList dif = new ArrayList<>(); //查找出oldIdList表中不包含newIdList的元素 for (Long id : oldIdList) { if (!(newIdList.contains(id))) { dif.add(id); } } return dif; } /** * @Description: 删除 */ @Transactional @Override public void delOne(Long id, UserInfo user) { selectVerification(id); SafetySelfInspection delOne = new SafetySelfInspection(); delOne.setId(id); delOne.setUpdateTime(new Date()); delOne.setUpdateBy(user.getRealname()); delOne.setValidFlag(Boolean.FALSE); this.updateById(delOne); InspectionExpertGroup expertGroup = expertGroupService.getBySelfInspectionId(id); if(expertGroup != null){ expertGroup.setValidFlag(false); expertGroupService.updateById(expertGroup); } } /* @Override public SafetySelfInspection infoOne(Long id,String unqualified, UserInfo user) { SafetySelfInspection safetySelfInspection=selectVerification(id); //组装检查项 List itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified); if(CollectionUtils.isNotEmpty(itemList)){ //组装扣分项 for (SafetySelfInspectionItem safetySelfInspectionItem : itemList){ if (safetySelfInspectionItem.getSafetyInspectionItemResult()==null){ //根据检查项id获取原始扣分项 List safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId()); if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){ List oldSafetySelfInspectionItemDeductionList=new ArrayList<>(); for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){ SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction(); safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId()); safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName()); safetySelfInspectionItemDeduction.setPoint(0); oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction); } safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList); }else{ safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>()); } }else if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(1)){ //根据自查清单记录的检查项id获取其扣分项 List selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId()); if (CollectionUtils.isNotEmpty(selfDeductionList)){ safetySelfInspectionItem.setSelfDeductionList(selfDeductionList); } } } safetySelfInspection.setItemList(itemList); }else{ safetySelfInspection.setItemList(new ArrayList<>()); } return safetySelfInspection; }*/ @Override public SafetySelfInspectionRespDTO infoOne(Long id, String unqualified, UserInfo user) { SafetySelfInspection safetySelfInspection = selectVerification(id); SafetySelfInspectionRespDTO safetySelfInspectionRespDTO = new SafetySelfInspectionRespDTO(); BeanUtils.copyProperties(safetySelfInspection,safetySelfInspectionRespDTO); //获取所有检查项 List itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified); //获取要素树 List elementTreeList = elementManagementService.getMenuType1Tree(); //获取附件 List byBusinessId = attachmentInfoService.findByBusinessId(id); safetySelfInspectionRespDTO.setAttachmentList(byBusinessId); List arespDTOList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(elementTreeList)) { for (ElementTree elementA : elementTreeList) { List 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(elementA.getValue()); elementARespDTO.setElementName(elementA.getLabel()); elementARespDTO.setType(elementA.getType()); List brespDTOList = new ArrayList<>(); //二级要素 List elementBList = elementA.getChildren(); if(CollectionUtils.isNotEmpty(elementBList)){ for (ElementTree stree : elementBList) { SafetySelfInspectionElementRespDTO elementBRespDTO = new SafetySelfInspectionElementRespDTO(); elementBRespDTO.setElementId(stree.getValue()); elementBRespDTO.setElementName(stree.getLabel()); elementBRespDTO.setType(stree.getType()); elementBRespDTO.setPid(stree.getPid()); List cRespDTOList = new ArrayList<>(); //三级要素 List elementCList = stree.getChildren(); if(CollectionUtils.isEmpty(elementCList)){ //扣分 int delScore = 0; int totalScore = stree.getPoint(); //无三级要素过滤出二级要素检查内容 List sItemList = itemList .stream() .filter(item -> item.getElementC() == null && item.getElementB() != null && item.getElementB().equals(stree.getValue())) .collect(Collectors.toList()); //填充检查项 elementBRespDTO.setItemList(assemblyDeduction(sItemList)); //判断是否有否决项 List rejectList = sItemList .stream() .filter(item -> item.getSafetyInspectionItemResult().equals(0)) .collect(Collectors.toList()); if(rejectList.size() > 0){ delScore = stree.getPoint(); }else { //计算出不合格扣分 delScore += unqualifiedItemDelScore(sItemList); } //总分 elementBRespDTO.setTotalScore(stree.getPoint()); //得分 elementBRespDTO.setScore(totalScore-delScore); }else { for(ElementTree ttree : elementCList){ SafetySelfInspectionElementRespDTO elementCRespDTO = new SafetySelfInspectionElementRespDTO(); elementCRespDTO.setElementId(ttree.getValue()); elementCRespDTO.setElementName(ttree.getLabel()); elementCRespDTO.setType(ttree.getType()); elementCRespDTO.setPid(ttree.getPid()); //扣分 int delScore = 0; int totalScore = ttree.getPoint(); //过滤该三级要素检查项目 List tItemList = itemList .stream() .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue())) .collect(Collectors.toList()); //填充检查项 elementCRespDTO.setItemList(assemblyDeduction(tItemList)); //判断是否有被否决 List rejectList = tItemList .stream() .filter(item -> item.getSafetyInspectionItemResult().equals(0)) .collect(Collectors.toList()); if(rejectList.size() > 0){ delScore = ttree.getPoint(); }else { //计算出不合格扣分 delScore = unqualifiedItemDelScore(tItemList); } //总分 elementCRespDTO.setTotalScore(ttree.getPoint()); //得分 elementCRespDTO.setScore(totalScore-delScore); cRespDTOList.add(elementCRespDTO); } } elementBRespDTO.setChildren(cRespDTOList); brespDTOList.add(elementBRespDTO); } } elementARespDTO.setChildren(brespDTOList); arespDTOList.add(elementARespDTO); } } } safetySelfInspectionRespDTO.setElementList(arespDTOList); return safetySelfInspectionRespDTO; } //组装扣分项 private List assemblyDeduction( List itemList){ for (SafetySelfInspectionItem safetySelfInspectionItem : itemList){ if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(2)){ //根据检查项id获取原始扣分项 List safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId()); if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){ List oldSafetySelfInspectionItemDeductionList=new ArrayList<>(); for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){ SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction(); safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId()); safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName()); safetySelfInspectionItemDeduction.setPoint(0); oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction); } safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList); }else{ safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>()); } }else if (safetySelfInspectionItem.getSafetyInspectionItemResult().equals(1)){ //根据自查清单记录的检查项id获取其扣分项 List selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId()); if (CollectionUtils.isNotEmpty(selfDeductionList)){ safetySelfInspectionItem.setSelfDeductionList(selfDeductionList); } } } return itemList; } @Override public SafetySelfInspectionItem itemInfoOne(Long id, UserInfo user){ SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id); List selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId()); List inspectionHiddenDangerList = dangerService.getBySafetySelfInspectionItemId(id); List byBusinessId = attachmentInfoService.findByBusinessId(id); if (CollectionUtils.isNotEmpty(selfDeductionList)){ safetySelfInspectionItem.setSelfDeductionList(selfDeductionList); }else{ //根据自查清单检查项里的检查项表去找原有的扣分项 List safetyInspectionItemDeductionList = safetyInspectionItemDeductionMapper.getBySafetyInspectionItemId(safetySelfInspectionItem.getSafetyInspectionItemId()); if (CollectionUtils.isNotEmpty(safetyInspectionItemDeductionList)){ List oldSafetySelfInspectionItemDeductionList=new ArrayList<>(); for (SafetyInspectionItemDeduction safetyInspectionItemDeduction : safetyInspectionItemDeductionList){ SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction = new SafetySelfInspectionItemDeduction(); safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetyInspectionItemDeduction.getId()); safetySelfInspectionItemDeduction.setName(safetyInspectionItemDeduction.getName()); safetySelfInspectionItemDeduction.setPoint(0); oldSafetySelfInspectionItemDeductionList.add(safetySelfInspectionItemDeduction); } safetySelfInspectionItem.setSelfDeductionList(oldSafetySelfInspectionItemDeductionList); }else{ safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>()); } } for (InspectionHiddenDanger inspectionHiddenDanger : inspectionHiddenDangerList) { if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){ List attachmentIds = new ArrayList<>(); String[] split = inspectionHiddenDanger.getUrl().split(","); for (String s : split) { attachmentIds.add(Long.valueOf(s)); } List dangerAttachList = attachmentInfoService.findByIds(attachmentIds); inspectionHiddenDanger.setAttachmentList(dangerAttachList); } } safetySelfInspectionItem.setAttachmentList(byBusinessId); safetySelfInspectionItem.setDangerList(inspectionHiddenDangerList); return safetySelfInspectionItem; } @Transactional @Override public void modItemInfo(SafetySelfInspectionItem param, UserInfo user) { if (param.getSafetyInspectionItemResult()==0 && StringUtils.isBlank(param.getSafetyInspectionItemResultDesc())){ throw new BusinessException("否决说明必填!"); } Date date = new Date(); String username = user.getRealname(); param.setUpdateTime(date); param.setUpdateBy(username); safetySelfInspectionItemMapper.updateById(param); //附件 List 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.getId(),user); //删除附件 attachmentInfoService.deleteByBusinessId(param.getId()); }else{ //扣分 List list = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(param.getId()); if (CollectionUtils.isEmpty(list)){ //新增扣分记录 for (SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction : param.getSelfDeductionList()){ safetySelfInspectionItemDeduction.setValidFlag(Boolean.TRUE); safetySelfInspectionItemDeduction.setUpdateBy(username); safetySelfInspectionItemDeduction.setCreateBy(username); safetySelfInspectionItemDeduction.setUpdateTime(date); safetySelfInspectionItemDeduction.setCreateTime(date); safetySelfInspectionItemDeduction.setSafetySelfInspectionItemId(param.getId()); safetySelfInspectionItemDeduction.setSafetyInspectionItemDeductionId(safetySelfInspectionItemDeduction.getSafetyInspectionItemDeductionId()); safetySelfInspectionItemDeductionMapper.insert(safetySelfInspectionItemDeduction); } }else{ //更新扣分记录 for (SafetySelfInspectionItemDeduction safetySelfInspectionItemDeduction : param.getSelfDeductionList()){ safetySelfInspectionItemDeduction.setUpdateBy(username); safetySelfInspectionItemDeduction.setUpdateTime(date); safetySelfInspectionItemDeductionMapper.updateById(safetySelfInspectionItemDeduction); } } //隐患 if(CollectionUtils.isNotEmpty(param.getDangerList())){ List oldDangerList = dangerService.getBySafetySelfInspectionItemId(param.getId()); //过滤出要删除数据 List deleteOldDangerList = oldDangerList.stream().parallel().filter(a -> param.getDangerList().stream().noneMatch(b -> a.getId().equals(b.getId()))) .collect(Collectors.toList()); //删除 if (CollectionUtils.isNotEmpty(deleteOldDangerList)) { List idList = deleteOldDangerList.stream().map(InspectionHiddenDanger::getId).collect(Collectors.toList()); 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)-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); } } @Override public void finish(Long id, UserInfo user) { SafetySelfInspection safetySelfInspection=selectVerification(id); Date date = new Date(); String username = user.getRealname(); safetySelfInspection.setStatus(2); safetySelfInspection.setUpdateTime(date); safetySelfInspection.setUpdateBy(username); safetySelfInspection.setInspectionEndTime(new Date()); safetySelfInspectionMapper.updateById(safetySelfInspection); } @Override public void addItemExpert(List itemList, UserInfo user) { itemList.forEach(item -> { item.setUpdateBy(user.getRealname()); item.setUpdateTime(new Date()); }); safetySelfInspectionItemMapper.updateBatch(itemList); } @Override public void addCheckAttachment(List 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() .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 params) { return safetySelfInspectionMapper.companyStatisticInspection(params); } private void requiredAttachmentVerification(List 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不能为空"); } } } /** * 查询验证 * 验证对象存在 */ public SafetySelfInspection selectVerification(Long id) { if (id == null) throw new BusinessException("id传参不能为空"); SafetySelfInspection SafetySelfInspection = this.getById(id); if (SafetySelfInspection == null) throw new BusinessException("找不到对应实体"); return SafetySelfInspection; } /** * 操作验证 * 验证必填项 */ public void requiredVerification(SafetySelfInspection param) { if (StringUtils.isBlank(param.getInspectionName())) throw new BusinessException("请填写自查清单名称"); if (param.getInspectionTime() == null) throw new BusinessException("请选择自查时间"); if (param.getInspector() == null) throw new BusinessException("请选择自查人员"); if (CollectionUtils.isEmpty(param.getItemList())) { throw new BusinessException("请选择检查项"); } 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检查要素"); } } } public void requiredSuperviseVerification(SafetySelfInspection param) { if (StringUtils.isBlank(param.getInspectionName())) throw new BusinessException("请填写排查清单名称"); if (param.getInspectionTime() == null) throw new BusinessException("请选择排查时间"); if (CollectionUtils.isEmpty(param.getExpertList())) throw new BusinessException("请选择检查专家"); for(InspectionExpert inspectionExpert : param.getExpertList()){ if(inspectionExpert.getExpertId() == null){ throw new BusinessException("请选择检查专家"); } if(StringUtils.isBlank(inspectionExpert.getName())){ throw new BusinessException("请选择检查专家名字"); } if(inspectionExpert.getIsLeader() == null){ throw new BusinessException("请选择组长或者组员"); } } if (CollectionUtils.isEmpty(param.getItemList())) { throw new BusinessException("请选择检查项"); } if (param.getCheckedCompanyId() == null){ throw new BusinessException("请选择被检查公司"); } } }