| 
					
				 | 
			
			
				@@ -11,6 +11,7 @@ import cn.hutool.core.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.hutool.core.util.ObjectUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.excel.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.toolkit.IdWorker; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.constant.ErrorMsgConstants; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.constant.SecurityConstants; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -20,16 +21,19 @@ import com.xunmei.common.core.enums.CycleCommonEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.enums.OrgTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.enums.PlanStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.enums.RegisterBookType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.xunmei.common.core.exception.ServiceException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.exception.SystemException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.utils.DateHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.core.utils.DateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.common.security.utils.SecurityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.registerbook.service.ICoreRegisterBookPdfService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.xunmei.core.resumption.domain.AppPlan; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.resumption.dto.DistributeDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.resumption.dto.DistributeStatusDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.resumption.mapper.AppPlanMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.resumption.vo.appPlan.ResumptionPlanPageVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.safetyCheck.domain.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.xunmei.core.safetyCheck.enums.SafetyPlanCycle; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.safetyCheck.job.SafetyCheckJobBusiness; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.safetyCheck.mapper.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.xunmei.core.safetyCheck.service.ICoreSafecheckPlanService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -146,17 +150,16 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void distributeToOrg(DistributeDto dto, Boolean immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CoreSafecheckPlan oldPlan = baseMapper.selectById(dto.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        throwIfNoCycleOverdue(oldPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Long parentId = IdWorker.getId(oldPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<Object> hsPlans = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Date effectiveTime = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            effectiveTime = DateUtil.offset(DateUtil.beginOfDay(DateUtils.getStartAndEnd(now, oldPlan.getPlanCycle()).getEndTime()), DateField.DAY_OF_YEAR, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        CoreSafecheckPlan byId = baseMapper.selectById(dto.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<CoreSafecheckPlan> hsPlans = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date effectiveTime = getEffectiveTime(oldPlan, immediateEffect); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (DistributeStatusDto d : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 dto.getOrgAndStatus()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            CoreSafecheckPlan plan = baseMapper.selectOne(new LambdaQueryWrapper<CoreSafecheckPlan>().eq(CoreSafecheckPlan::getPlanOfOrgId, d.getOrgId()).eq(CoreSafecheckPlan::getParentId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CoreSafecheckPlan plan = baseMapper.selectOne(new LambdaQueryWrapper<CoreSafecheckPlan>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getPlanOfOrgId, d.getOrgId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getParentId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //如果子计划已存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (plan != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //从停用状态下发,才会有已存在的子计划; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -169,10 +172,8 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     plan.setPublishTime(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     plan.setEffectiveTime(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                plan.setPlanStatus(d.getStatus() > 0 ? 1 : 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 plan.setDistributePlanStatus(d.getStatus().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 plan.setDistributeStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                plan.setPlanCreateOrgId(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (!immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     //停用状态下发,逻辑删除旧的计划,并生成一份副本 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     baseMapper.updateById(plan); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -180,32 +181,34 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     Long hsPlanId = IdWorker.getId(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     copyChildPlan(plan.getId(), hsPlanId, parentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                        AppPlan newPlan = baseMapper.selectById(hsPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     baseMapper.updateById(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                baseMapper.updateById(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 CoreSafecheckPlan coreSafecheckPlan = new CoreSafecheckPlan(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 BeanUtils.copyProperties(oldPlan, coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    hsPlans.add(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    hsPlans.add(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coreSafecheckPlan.setSolidId(IdWorker.getId(coreSafecheckPlan)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Long childPlanId = IdWorker.getId(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coreSafecheckPlan.setId(childPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coreSafecheckPlan.setSolidId(childPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setParentSolidId(oldPlan.getSolidId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setDistributeStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setPlanOfOrgId(d.getOrgId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coreSafecheckPlan.setPlanStatus(d.getStatus() > 0 ? 1 : 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                coreSafecheckPlan.setPlanStatus(d.getStatus() > 0 ? 1 : 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setDistributePlanStatus(d.getStatus().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (ObjectUtil.equal(d.getStatus(), 1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlan.setPublishTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlan.setEffectiveTime(effectiveTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    coreSafecheckPlan.setPublishTime(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    coreSafecheckPlan.setEffectiveTime(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //下发所属机构类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setPlanOfOrgType(orgService.selectSysOrgById(coreSafecheckPlan.getPlanOfOrgId(), SecurityConstants.INNER).getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coreSafecheckPlan.setId(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            if (coreSafecheckPlan.getPlanCycle()==6){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                coreSafecheckPlan.setStartDate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -214,28 +217,29 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setParentId(dto.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 baseMapper.insert(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<CoreSafecheckPlanToRole> roleList = coreSafecheckPlanToRoleMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToRole>().eq(CoreSafecheckPlanToRole::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<CoreSafecheckPlanToRole> roleList = coreSafecheckPlanToRoleMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToRole>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(CoreSafecheckPlanToRole::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //再处理角色关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (roleList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlanToRoleMapper.deleteCoreSafecheckPlanToRoleByPlanId(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (CoreSafecheckPlanToRole r : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             roleList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         coreSafecheckPlanToRoleMapper.insert(new CoreSafecheckPlanToRole(coreSafecheckPlan.getId(), r.getRoleId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //再处理检查机构关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<CoreSafecheckPlanToExecOrg> execOrgList = coreSafecheckPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToExecOrg>().eq(CoreSafecheckPlanToExecOrg::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<CoreSafecheckPlanToExecOrg> execOrgList = coreSafecheckPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToExecOrg>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(CoreSafecheckPlanToExecOrg::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (execOrgList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlanToExecOrgMapper.deleteCoreSafecheckPlanToExecOrgByPlanId(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (CoreSafecheckPlanToExecOrg org : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             execOrgList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         coreSafecheckPlanToExecOrgMapper.insert(new CoreSafecheckPlanToExecOrg(coreSafecheckPlan.getId(), org.getOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //再处理受检机构关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<CoreSafecheckPlanToCheckOrg> checkOrgList = coreSafecheckPlanToCheckOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg>().eq(CoreSafecheckPlanToCheckOrg::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<CoreSafecheckPlanToCheckOrg> checkOrgList = coreSafecheckPlanToCheckOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(CoreSafecheckPlanToCheckOrg::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (checkOrgList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlanToCheckOrgMapper.deleteCoreSafecheckPlanToCheckOrgByPlanId(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (CoreSafecheckPlanToCheckOrg org : 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -245,10 +249,12 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //再处理受检机构类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<CoreSafecheckPlanToCheckOrgType> checkOrgTypes = coreSafecheckPlanToCheckOrgTypeMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrgType>().eq(CoreSafecheckPlanToCheckOrgType::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<CoreSafecheckPlanToCheckOrgType> checkOrgTypes = coreSafecheckPlanToCheckOrgTypeMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrgType>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(CoreSafecheckPlanToCheckOrgType::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (checkOrgTypes != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     //删除当前计划的受检机构类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    coreSafecheckPlanToCheckOrgTypeMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrgType>().eq(CoreSafecheckPlanToCheckOrgType::getPlanId, coreSafecheckPlan.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    coreSafecheckPlanToCheckOrgTypeMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrgType>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .eq(CoreSafecheckPlanToCheckOrgType::getPlanId, coreSafecheckPlan.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (CoreSafecheckPlanToCheckOrgType type : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             checkOrgTypes) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         coreSafecheckPlanToCheckOrgTypeMapper.insert(new CoreSafecheckPlanToCheckOrgType(coreSafecheckPlan.getId(), type.getTypeId())); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -257,15 +263,16 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //再处理检查要点关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //查询父计划的所有检查要点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<CoreSafecheckPlanToPoint> rpList = coreSafecheckPlanToPointMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, dto.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, byId.getPlanOfOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<CoreSafecheckPlanToPoint> rpList = coreSafecheckPlanToPointMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .eq(CoreSafecheckPlanToPoint::getPlanId, dto.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (rpList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     //删除父计划创建的检查要点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    coreSafecheckPlanToPointMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, coreSafecheckPlan.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, byId.getPlanOfOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    coreSafecheckPlanToPointMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            .eq(CoreSafecheckPlanToPoint::getPlanId, coreSafecheckPlan.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     for (CoreSafecheckPlanToPoint s : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             rpList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         //插入父计划的所有检查要点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         coreSafecheckPlanToPointMapper.insert(new CoreSafecheckPlanToPoint(coreSafecheckPlan.getId(), s.getPointId(), s.isPointScan(), s.isRequired(), s.getOfOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -275,32 +282,60 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         coreSafecheckPlan.setId(dto.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         coreSafecheckPlan.setDistribute("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         coreSafecheckPlan.setPlanStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        coreSafecheckPlan.setPublishTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        coreSafecheckPlan.setEffectiveTime(effectiveTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        baseMapper.updateById(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        coreSafecheckPlan.setBuildTaskNow(coreSafecheckPlanMapper.selectById(dto.getId()).isBuildTaskNow()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (ObjectUtil.equal(oldPlan.getPlanStatus(), PlanStatus.DELETED.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //停用时下发且立即生效,逻辑删除旧计划并生成新计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            copySelfPlan(oldPlan.getId(), parentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.deleteById(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            copySelfPlan(oldPlan.getId(), parentId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            safetyCheckJobBusiness.rebuildCurrentCycleTask(hsPlans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            safetyCheckJobBusiness.createTaskByPlans(hsPlans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        coreSafecheckPlanMapper.updateById(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 获取生效日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param plan 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param immediateEffect 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Date getEffectiveTime(CoreSafecheckPlan plan, Boolean immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.equal(plan.getPlanCycle(), SafetyPlanCycle.NONE.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return DateUtil.beginOfDay(plan.getEndDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date effectiveTime = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            effectiveTime = DateUtil.offset( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    DateUtil.beginOfDay( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            DateUtils.getStartAndEnd(new Date(), SafetyPlanCycle.toCommon(plan.getPlanCycle())).getEndTime()), DateField.DAY_OF_YEAR, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return effectiveTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 单个任务下发 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param immediateEffect 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public int distributeHS(Long id, Boolean immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public int distributeSingle(Long id, Boolean immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CoreSafecheckPlan plan = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        plan.setPlanStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer planStatus = plan.getPlanStatus(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        throwIfNoCycleOverdue(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        plan.setPlanStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //设置计划状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         plan.setPlanStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Date effectiveTime = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (!immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            effectiveTime = DateUtil.offset(DateUtil.beginOfDay(DateUtils.getStartAndEnd(now, plan.getPlanCycle()).getEndTime()), DateField.DAY_OF_YEAR, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date effectiveTime = getEffectiveTime(plan, immediateEffect); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         plan.setPublishTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         plan.setEffectiveTime(effectiveTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //如果是行社撤回需要修改下发状态 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -310,10 +345,9 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             plan.setDistribute("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<CoreSafecheckPlan> newlist = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (immediateEffect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            List<Object> newlist = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (ObjectUtil.equal(planStatus, PlanStatus.DRAFT.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //草稿状态下发,立即生效则生成任务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 newlist.add(plan); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -328,66 +362,65 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 CoreSafecheckPlan newPlan = baseMapper.selectById(newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 newlist.add(newPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            safetyCheckJobBusiness.rebuildCurrentCycleTask(newlist); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.updateById(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        baseMapper.updateById(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.isNotEmpty(newlist)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            safetyCheckJobBusiness.createTaskByPlans(newlist); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 无周期,超过结束日期则报错 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param plan 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void throwIfNoCycleOverdue(CoreSafecheckPlan plan) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date date = DateUtil.beginOfDay(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.equal(plan.getPlanCycle(), SafetyPlanCycle.NONE.getCode()) && date.after(plan.getEndDate())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ServiceException("已超过无周期任务的结束时间"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void cheHui(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CoreSafecheckPlan plan = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //修改所有子计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<CoreSafecheckPlan> appPlans = baseMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlan>().eq(CoreSafecheckPlan::getParentId, id)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<Long> planIds = appPlans.stream().map(CoreSafecheckPlan::getId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        planIds.add(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //拿到父计划和所属子计划是否存在已完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Long hasEdit = coreSafetyTaskMapper.selectCount(new LambdaQueryWrapper<CoreSafetyTask>().in(CoreSafetyTask::getPlanId, planIds).in(CoreSafetyTask::getStatus, 3, 4)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        for (CoreSafecheckPlan ap : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                appPlans) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//修改计划状态为停用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ap.setPlanStatus(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            baseMapper.updateById(ap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            CycleCommonEnum code = CycleCommonEnum.getEnum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            DateRange dateRange = new DateRange(ap.getStartDate(), ap.getEndDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (plan.getPlanCycle() != 6) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                code = CycleCommonEnum.getEnum(Math.toIntExact(plan.getPlanCycle()) + 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                dateRange = DateUtils.getStartAndEnd(new Date(), code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //如果不存在已完成撤回需要删除本周期所有任务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (plan.getPlanCycle() == 6) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, ap.getId()).between(CoreSafetyTask::getYmdDate, dateRange.getStartTime(), dateRange.getEndTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (hasEdit == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, ap.getId()).in(CoreSafetyTask::getStatus, 1, 2).between(CoreSafetyTask::getYmdDate, dateRange.getStartTime(), dateRange.getEndTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //设置下发状态为未下发 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        plan.setDistribute("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        plan.setPlanStatus(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        baseMapper.updateById(plan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        CycleCommonEnum code = CycleCommonEnum.getEnum(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        DateRange dateRange = new DateRange(plan.getStartDate(), plan.getEndDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (plan.getPlanCycle() != 6) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            code = CycleCommonEnum.getEnum(Math.toIntExact(plan.getPlanCycle()) + 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            dateRange = DateUtils.getStartAndEnd(new Date(), code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (plan.getPlanCycle() == 6) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, plan.getId()).between(CoreSafetyTask::getYmdDate, dateRange.getStartTime(), dateRange.getEndTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.equal(plan.getTaskHasCompleted(), 1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //有已完成时,计划及子计划状态变为停用,不删除任务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LambdaUpdateWrapper<CoreSafecheckPlan> updateWrapper = new LambdaUpdateWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            updateWrapper.set(CoreSafecheckPlan::getPlanStatus, 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(CoreSafecheckPlan::getWithdrawTime, now) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getParentId, id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            baseMapper.update(null, updateWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            updateWrapper = new LambdaUpdateWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            updateWrapper.set(CoreSafecheckPlan::getPlanStatus, 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(CoreSafecheckPlan::getDistribute, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(CoreSafecheckPlan::getWithdrawTime, now) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getId, id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            baseMapper.update(null, updateWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (hasEdit == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, plan.getId()).in(CoreSafetyTask::getStatus, 1, 2).between(CoreSafetyTask::getYmdDate, dateRange.getStartTime(), dateRange.getEndTime())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //无已完成时,删除子计划,计划本身变为草稿 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LambdaUpdateWrapper<CoreSafecheckPlan> updateWrapper = new LambdaUpdateWrapper<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            updateWrapper.set(CoreSafecheckPlan::getPlanStatus, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(CoreSafecheckPlan::getDistribute, 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .set(CoreSafecheckPlan::getWithdrawTime, now) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getId, id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            baseMapper.update(null, updateWrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<CoreSafecheckPlan> childrenPlan = baseMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlan>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(CoreSafecheckPlan::getParentId, id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .select(CoreSafecheckPlan::getSolidId, CoreSafecheckPlan::getId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            delete(childrenPlan.stream().map(CoreSafecheckPlan::getId).collect(Collectors.toList())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<Long> childrenPlanIds = childrenPlan.stream().map(CoreSafecheckPlan::getSolidId).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            childrenPlanIds.add(plan.getSolidId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            deleteAllTaskByPlanId(childrenPlanIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -476,8 +509,12 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new RuntimeException("未选择检查项!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer planStatus = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (coreSafecheckPlan.getId() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            coreSafecheckPlan.setSolidId(IdWorker.getId(coreSafecheckPlan)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Long id = IdWorker.getId(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            coreSafecheckPlan.setId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            coreSafecheckPlan.setSolidId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             coreSafecheckPlan.setParentSolidId(-1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //先处理检查计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             coreSafecheckPlan.setPlanOfOrgId(coreSafecheckPlan.getPlanCreateOrgId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -500,10 +537,14 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             coreSafecheckPlanMapper.insert(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             returnId = coreSafecheckPlan.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CoreSafecheckPlan oldPlan = baseMapper.get(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            planStatus = oldPlan.getPlanStatus(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //先克隆旧的数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(needCopyOnEdit(coreSafecheckPlan)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Long newPlanId=IdWorker.getId(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                copySelfPlan(coreSafecheckPlan.getId(),newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (needCopyOnEdit(oldPlan)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                baseMapper.deleteById(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Long newPlanId = IdWorker.getId(coreSafecheckPlan); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                copySelfPlan(coreSafecheckPlan.getId(), newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlan.setId(newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -550,7 +591,6 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             for (SafetyCheckRulePointVo s : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     coreSafecheckPlan.getRulePointList()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 coreSafecheckPlanToPointMapper.insert(new CoreSafecheckPlanToPoint(coreSafecheckPlan.getId(), s.getId(), s.isPointScan(), s.isRequired(), s.getOfOrgId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //再处理受检机构类型 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -563,9 +603,9 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (needRebuildOnEdit(coreSafecheckPlan)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (needRebuildOnEdit(coreSafecheckPlan, planStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             CoreSafecheckPlan plan = baseMapper.selectById(coreSafecheckPlan.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            safetyCheckJobBusiness.rebuildCurrentCycleTask(Arrays.asList(plan)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            safetyCheckJobBusiness.createTaskByPlans(Arrays.asList(plan)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return returnId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -573,7 +613,7 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(rollbackFor = RuntimeException.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void childrenPlan(Long oldPlanId,Long newPlanId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void childrenPlan(Long oldPlanId, Long newPlanId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //处理子计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //拿到所有子计划 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<CoreSafecheckPlan> children = baseMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlan>() 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -583,21 +623,21 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //        Long hasEdit = coreSafetyTaskMapper.selectCount(new LambdaQueryWrapper<CoreSafetyTask>().in(CoreSafetyTask::getPlanId, planIds).in(CoreSafetyTask::getStatus, 3, 4)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CoreSafecheckPlan coreSafecheckPlan = baseMapper.selectById(newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<Object> needRebuildPlans = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<CoreSafecheckPlan> needRebuildPlans = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (CoreSafecheckPlan p : 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 children) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             CoreSafecheckPlan child = p; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (needCopyOnEdit(coreSafecheckPlan)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //使用中状态且立即生效,复制副本 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Long newChildPlanId = IdWorker.getId(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                copyChildPlan(p.getId(),newChildPlanId,newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                copyChildPlan(p.getId(), newChildPlanId, newPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 baseMapper.updateById(p); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 baseMapper.deleteById(p.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 child = baseMapper.selectById(newChildPlanId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (needRebuildOnEdit(p)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (needRebuildOnEdit(p, p.getPlanStatus())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 needRebuildPlans.add(child); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             p.setUpdateTime(DateUtils.getNowDate()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -677,8 +717,8 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if(CollectionUtil.isNotEmpty(needRebuildPlans)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            safetyCheckJobBusiness.rebuildCurrentCycleTask(needRebuildPlans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (CollectionUtil.isNotEmpty(needRebuildPlans)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            safetyCheckJobBusiness.createTaskByPlans(needRebuildPlans); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -743,8 +783,8 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param plan 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private Boolean needRebuildOnEdit(CoreSafecheckPlan plan) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.USING.getCode()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Boolean needRebuildOnEdit(CoreSafecheckPlan plan, Integer planStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.equal(planStatus, PlanStatus.USING.getCode()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 && (ObjectUtil.equal(plan.getPlanOfOrgType(), OrgTypeEnum.HANG_SHE.getCode()) || ObjectUtil.equal(plan.getExecOrgType(), OrgTypeEnum.BAN_SHI_CHU.getCode()) || ObjectUtil.equal(plan.getExecOrgType(), OrgTypeEnum.SHEGN_LIAN_SHE.getCode())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 && (ObjectUtil.isNull(plan.getTaskHasCompleted()) || ObjectUtil.equal(plan.getPlanStatus(), 0)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 && !new Date().before(plan.getEffectiveTime())) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -997,4 +1037,33 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return StringUtil.EMPTY_STRING; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 更新计划及父计划的任务是否有已完成标志。 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param planId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param state 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void updatePlanCompletedState(Long planId, Integer state) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.notEqual(state, 1) && ObjectUtil.notEqual(state, 0) && ObjectUtil.isNotNull(state)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ServiceException("state参数值无效"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CoreSafecheckPlan plan = baseMapper.selectById(planId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.isNull(plan)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ServiceException("计划不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        LambdaUpdateWrapper<CoreSafecheckPlan> wrapper = new LambdaUpdateWrapper(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        wrapper.eq(CoreSafecheckPlan::getId, planId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .set(CoreSafecheckPlan::getTaskHasCompleted, state); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        baseMapper.update(null, wrapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (ObjectUtil.isNotNull(plan.getParentId()) && plan.getParentId() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            baseMapper.updateParentPlanCompletedState(plan.getParentId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |