|  | @@ -1,32 +1,44 @@
 | 
	
		
			
				|  |  |  package com.xunmei.core.safetyCheck.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.io.File;
 | 
	
		
			
				|  |  | +import java.text.MessageFormat;
 | 
	
		
			
				|  |  | +import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import cn.hutool.core.collection.CollectionUtil;
 | 
	
		
			
				|  |  | -import cn.hutool.core.date.DateTime;
 | 
	
		
			
				|  |  | +import cn.hutool.core.date.DateUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.ErrorMsgConstants;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.DateRange;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.registerbook.domain.CoreRegisterBookPdf;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.CycleCommonEnum;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.enums.RegisterBookType;
 | 
	
		
			
				|  |  |  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.resumption.domain.AppPlan;
 | 
	
		
			
				|  |  | -import com.xunmei.core.resumption.domain.AppPlanToPoint;
 | 
	
		
			
				|  |  | -import com.xunmei.core.resumption.domain.AppPlanToRole;
 | 
	
		
			
				|  |  | -import com.xunmei.core.resumption.domain.Resumption;
 | 
	
		
			
				|  |  | +import com.xunmei.core.registerbook.service.ICoreRegisterBookPdfService;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.dto.DistributeDto;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.dto.DistributeStatusDto;
 | 
	
		
			
				|  |  | -import com.xunmei.core.resumption.vo.appPlan.ResumptionPlanPageVo;
 | 
	
		
			
				|  |  | +import com.xunmei.core.resumption.mapper.AppPlanMapper;
 | 
	
		
			
				|  |  | +import com.xunmei.core.resumption.vo.appPlan.RuleItemVo;
 | 
	
		
			
				|  |  |  import com.xunmei.core.safetyCheck.domain.*;
 | 
	
		
			
				|  |  |  import com.xunmei.core.safetyCheck.job.SafetyCheckJobBusiness;
 | 
	
		
			
				|  |  |  import com.xunmei.core.safetyCheck.mapper.*;
 | 
	
		
			
				|  |  |  import com.xunmei.core.safetyCheck.service.ICoreSafecheckPlanService;
 | 
	
		
			
				|  |  | -import com.xunmei.core.safetyCheck.vo.ruleItem.SafetyCheckRulePointSelectVo;
 | 
	
		
			
				|  |  | +import com.xunmei.core.safetyCheck.vo.regsiter.AppTaskRegisterPointVo;
 | 
	
		
			
				|  |  | +import com.xunmei.core.safetyCheck.vo.regsiter.TaskRegisterVo;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.RemoteFileService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.CheckDataVo;
 | 
	
		
			
				|  |  | +import com.xunmei.core.safetyCheck.vo.PointDto;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.domain.SafeCheckTaskRegisterBookVo;
 | 
	
		
			
				|  |  |  import com.xunmei.core.safetyCheck.vo.ruleItem.SafetyCheckRulePointVo;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 | 
	
		
			
				|  |  | +import io.netty.util.internal.StringUtil;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.scheduling.annotation.Async;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -37,6 +49,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.web.page.TableDataInfo;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Propagation;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 常规安全检查计划Service业务层处理
 | 
	
	
		
			
				|  | @@ -62,7 +76,12 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
 | 
	
		
			
				|  |  |      private SafetyCheckJobBusiness safetyCheckJobBusiness;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private CoreSafetyTaskMapper coreSafetyTaskMapper;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ICoreRegisterBookPdfService registerBookPdfService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private AppPlanMapper appPlanMapper;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private RemoteFileService fileService;
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public TableDataInfo<CoreSafecheckPlan> selectPage(CoreSafecheckPlan coreSafecheckPlan) {
 | 
	
		
			
				|  |  |          //未删除
 | 
	
	
		
			
				|  | @@ -205,9 +224,9 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
 | 
	
		
			
				|  |  |              baseMapper.updateById(ap);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              CycleCommonEnum code = CycleCommonEnum.getEnum(0);
 | 
	
		
			
				|  |  | -            DateRange dateRange = new DateRange(ap.getStartDate(),ap.getEndDate());
 | 
	
		
			
				|  |  | -            if(plan.getPlanCycle()!=6L){
 | 
	
		
			
				|  |  | -                code=CycleCommonEnum.getEnum( Math.toIntExact(plan.getPlanCycle())+2);
 | 
	
		
			
				|  |  | +            DateRange dateRange = new DateRange(ap.getStartDate(), ap.getEndDate());
 | 
	
		
			
				|  |  | +            if (plan.getPlanCycle() != 6L) {
 | 
	
		
			
				|  |  | +                code = CycleCommonEnum.getEnum(Math.toIntExact(plan.getPlanCycle()) + 2);
 | 
	
		
			
				|  |  |                  dateRange = DateUtils.getStartAndEnd(new Date(), code);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //撤回需要删除本周期所有任务
 | 
	
	
		
			
				|  | @@ -224,9 +243,9 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
 | 
	
		
			
				|  |  |          baseMapper.updateById(plan);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          CycleCommonEnum code = CycleCommonEnum.getEnum(0);
 | 
	
		
			
				|  |  | -        DateRange dateRange = new DateRange(plan.getStartDate(),plan.getEndDate());
 | 
	
		
			
				|  |  | -        if(plan.getPlanCycle()!=6L){
 | 
	
		
			
				|  |  | -            code=CycleCommonEnum.getEnum( Math.toIntExact(plan.getPlanCycle())+2);
 | 
	
		
			
				|  |  | +        DateRange dateRange = new DateRange(plan.getStartDate(), plan.getEndDate());
 | 
	
		
			
				|  |  | +        if (plan.getPlanCycle() != 6L) {
 | 
	
		
			
				|  |  | +            code = CycleCommonEnum.getEnum(Math.toIntExact(plan.getPlanCycle()) + 2);
 | 
	
		
			
				|  |  |              dateRange = DateUtils.getStartAndEnd(new Date(), code);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (plan.getPlanCycle() == 6L) {
 | 
	
	
		
			
				|  | @@ -381,99 +400,98 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          return returnId;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Async
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void childrenPlan(Long id) {
 | 
	
		
			
				|  |  | -            //处理子计划
 | 
	
		
			
				|  |  | -            //拿到所有子计划
 | 
	
		
			
				|  |  | -            List<CoreSafecheckPlan> children = baseMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlan>().eq(CoreSafecheckPlan::getParentId, id));
 | 
	
		
			
				|  |  | -            CoreSafecheckPlan coreSafecheckPlan = baseMapper.selectById(id);
 | 
	
		
			
				|  |  | -            for (CoreSafecheckPlan p :
 | 
	
		
			
				|  |  | -                    children) {
 | 
	
		
			
				|  |  | -                p.setUpdateTime(DateUtils.getNowDate());
 | 
	
		
			
				|  |  | -                p.setModifiedBy(SecurityUtils.getUserId());
 | 
	
		
			
				|  |  | -                p.setPlanName(coreSafecheckPlan.getPlanName());
 | 
	
		
			
				|  |  | -                p.setBuildTaskNow(coreSafecheckPlan.isBuildTaskNow());
 | 
	
		
			
				|  |  | -                p.setCheckOrgType(coreSafecheckPlan.getCheckOrgType());
 | 
	
		
			
				|  |  | -                p.setCheckType(coreSafecheckPlan.getCheckType());
 | 
	
		
			
				|  |  | -                p.setCount(p.getCount()>coreSafecheckPlan.getCount()?p.getCount():coreSafecheckPlan.getCount());
 | 
	
		
			
				|  |  | -                p.setDescription(coreSafecheckPlan.getDescription());
 | 
	
		
			
				|  |  | -                p.setExecOrgType(coreSafecheckPlan.getExecOrgType());
 | 
	
		
			
				|  |  | -                p.setPlanCycle(coreSafecheckPlan.getPlanCycle());
 | 
	
		
			
				|  |  | +        //处理子计划
 | 
	
		
			
				|  |  | +        //拿到所有子计划
 | 
	
		
			
				|  |  | +        List<CoreSafecheckPlan> children = baseMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlan>().eq(CoreSafecheckPlan::getParentId, id));
 | 
	
		
			
				|  |  | +        CoreSafecheckPlan coreSafecheckPlan = baseMapper.selectById(id);
 | 
	
		
			
				|  |  | +        for (CoreSafecheckPlan p :
 | 
	
		
			
				|  |  | +                children) {
 | 
	
		
			
				|  |  | +            p.setUpdateTime(DateUtils.getNowDate());
 | 
	
		
			
				|  |  | +            p.setModifiedBy(SecurityUtils.getUserId());
 | 
	
		
			
				|  |  | +            p.setPlanName(coreSafecheckPlan.getPlanName());
 | 
	
		
			
				|  |  | +            p.setBuildTaskNow(coreSafecheckPlan.isBuildTaskNow());
 | 
	
		
			
				|  |  | +            p.setCheckOrgType(coreSafecheckPlan.getCheckOrgType());
 | 
	
		
			
				|  |  | +            p.setCheckType(coreSafecheckPlan.getCheckType());
 | 
	
		
			
				|  |  | +            p.setCount(p.getCount() > coreSafecheckPlan.getCount() ? p.getCount() : coreSafecheckPlan.getCount());
 | 
	
		
			
				|  |  | +            p.setDescription(coreSafecheckPlan.getDescription());
 | 
	
		
			
				|  |  | +            p.setExecOrgType(coreSafecheckPlan.getExecOrgType());
 | 
	
		
			
				|  |  | +            p.setPlanCycle(coreSafecheckPlan.getPlanCycle());
 | 
	
		
			
				|  |  |  //                p.setPlanStatus(coreSafecheckPlan.getPlanStatus());
 | 
	
		
			
				|  |  | -                p.setSourceType(coreSafecheckPlan.getSourceType());
 | 
	
		
			
				|  |  | -                baseMapper.updateById(p);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            p.setSourceType(coreSafecheckPlan.getSourceType());
 | 
	
		
			
				|  |  | +            baseMapper.updateById(p);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                //拿到父计划的所有角色映射
 | 
	
		
			
				|  |  | -                List<CoreSafecheckPlanToRole> roleList = coreSafecheckPlanToRoleMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToRole>().eq(CoreSafecheckPlanToRole::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | -                //再处理角色关系
 | 
	
		
			
				|  |  | -                if (roleList != null) {
 | 
	
		
			
				|  |  | -                    //删除子计划原角色映射
 | 
	
		
			
				|  |  | -                    coreSafecheckPlanToRoleMapper.deleteCoreSafecheckPlanToRoleByPlanId(p.getId());
 | 
	
		
			
				|  |  | -                    for (CoreSafecheckPlanToRole r :
 | 
	
		
			
				|  |  | -                            roleList) {
 | 
	
		
			
				|  |  | -                        //添加来自父计划的角色映射
 | 
	
		
			
				|  |  | -                        coreSafecheckPlanToRoleMapper.insert(new CoreSafecheckPlanToRole(p.getId(), r.getRoleId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                //再处理检查机构关系
 | 
	
		
			
				|  |  | -                List<CoreSafecheckPlanToExecOrg> execOrgList = coreSafecheckPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToExecOrg>().eq(CoreSafecheckPlanToExecOrg::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | -                if (execOrgList != null) {
 | 
	
		
			
				|  |  | -                    coreSafecheckPlanToExecOrgMapper.deleteCoreSafecheckPlanToExecOrgByPlanId(p.getId());
 | 
	
		
			
				|  |  | -                    for (CoreSafecheckPlanToExecOrg org :
 | 
	
		
			
				|  |  | -                            execOrgList) {
 | 
	
		
			
				|  |  | -                        coreSafecheckPlanToExecOrgMapper.insert(new CoreSafecheckPlanToExecOrg(p.getId(), org.getOrgId()));
 | 
	
		
			
				|  |  | +            //拿到父计划的所有角色映射
 | 
	
		
			
				|  |  | +            List<CoreSafecheckPlanToRole> roleList = coreSafecheckPlanToRoleMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToRole>().eq(CoreSafecheckPlanToRole::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | +            //再处理角色关系
 | 
	
		
			
				|  |  | +            if (roleList != null) {
 | 
	
		
			
				|  |  | +                //删除子计划原角色映射
 | 
	
		
			
				|  |  | +                coreSafecheckPlanToRoleMapper.deleteCoreSafecheckPlanToRoleByPlanId(p.getId());
 | 
	
		
			
				|  |  | +                for (CoreSafecheckPlanToRole r :
 | 
	
		
			
				|  |  | +                        roleList) {
 | 
	
		
			
				|  |  | +                    //添加来自父计划的角色映射
 | 
	
		
			
				|  |  | +                    coreSafecheckPlanToRoleMapper.insert(new CoreSafecheckPlanToRole(p.getId(), r.getRoleId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                //再处理受检机构关系
 | 
	
		
			
				|  |  | -                List<CoreSafecheckPlanToCheckOrg> checkOrgList = coreSafecheckPlanToCheckOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg>().eq(CoreSafecheckPlanToCheckOrg::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | -                if (checkOrgList != null) {
 | 
	
		
			
				|  |  | -                    coreSafecheckPlanToCheckOrgMapper.deleteCoreSafecheckPlanToCheckOrgByPlanId(p.getId());
 | 
	
		
			
				|  |  | -                    for (CoreSafecheckPlanToCheckOrg org :
 | 
	
		
			
				|  |  | -                            checkOrgList) {
 | 
	
		
			
				|  |  | -                        coreSafecheckPlanToCheckOrgMapper.insert(new CoreSafecheckPlanToCheckOrg(p.getId(), org.getOrgId()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //再处理检查机构关系
 | 
	
		
			
				|  |  | +            List<CoreSafecheckPlanToExecOrg> execOrgList = coreSafecheckPlanToExecOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToExecOrg>().eq(CoreSafecheckPlanToExecOrg::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | +            if (execOrgList != null) {
 | 
	
		
			
				|  |  | +                coreSafecheckPlanToExecOrgMapper.deleteCoreSafecheckPlanToExecOrgByPlanId(p.getId());
 | 
	
		
			
				|  |  | +                for (CoreSafecheckPlanToExecOrg org :
 | 
	
		
			
				|  |  | +                        execOrgList) {
 | 
	
		
			
				|  |  | +                    coreSafecheckPlanToExecOrgMapper.insert(new CoreSafecheckPlanToExecOrg(p.getId(), org.getOrgId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                //再处理子计划检查要点关系
 | 
	
		
			
				|  |  | -                //查询计划id为当前父计划的id,所属机构id为当前父计划所属机构id的数据
 | 
	
		
			
				|  |  | -                List<CoreSafecheckPlanToPoint> rpList = coreSafecheckPlanToPointMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, coreSafecheckPlan.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, coreSafecheckPlan.getPlanOfOrgId()));
 | 
	
		
			
				|  |  | -                if (rpList != null) {
 | 
	
		
			
				|  |  | -                    coreSafecheckPlanToPointMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, p.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, coreSafecheckPlan.getPlanOfOrgId()));
 | 
	
		
			
				|  |  | -                    for (CoreSafecheckPlanToPoint s :
 | 
	
		
			
				|  |  | -                            rpList) {
 | 
	
		
			
				|  |  | -                        coreSafecheckPlanToPointMapper.insert(new CoreSafecheckPlanToPoint(p.getId(), s.getPointId(), s.isPointScan(), s.isRequired(), s.getOfOrgId()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //再处理受检机构关系
 | 
	
		
			
				|  |  | +            List<CoreSafecheckPlanToCheckOrg> checkOrgList = coreSafecheckPlanToCheckOrgMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToCheckOrg>().eq(CoreSafecheckPlanToCheckOrg::getPlanId, coreSafecheckPlan.getId()));
 | 
	
		
			
				|  |  | +            if (checkOrgList != null) {
 | 
	
		
			
				|  |  | +                coreSafecheckPlanToCheckOrgMapper.deleteCoreSafecheckPlanToCheckOrgByPlanId(p.getId());
 | 
	
		
			
				|  |  | +                for (CoreSafecheckPlanToCheckOrg org :
 | 
	
		
			
				|  |  | +                        checkOrgList) {
 | 
	
		
			
				|  |  | +                    coreSafecheckPlanToCheckOrgMapper.insert(new CoreSafecheckPlanToCheckOrg(p.getId(), org.getOrgId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                //如果计划是编辑全部,代表不存在已完成或者逾期的任务,需要删除重新生成
 | 
	
		
			
				|  |  | -                if (coreSafecheckPlan.getHasEdit() == null&& coreSafecheckPlan.isBuildTaskNow()&&coreSafecheckPlan.getPlanStatus()==1) {
 | 
	
		
			
				|  |  | -                    coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, p.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  | -                } else {
 | 
	
		
			
				|  |  | -                    //否则代表编辑名称,需要同步未进行的任务名称
 | 
	
		
			
				|  |  | -                    CoreSafetyTask temp = new CoreSafetyTask();
 | 
	
		
			
				|  |  | -                    temp.setTitle(coreSafecheckPlan.getPlanName());
 | 
	
		
			
				|  |  | -                    coreSafetyTaskMapper.update(temp, new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, p.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //再处理子计划检查要点关系
 | 
	
		
			
				|  |  | +            //查询计划id为当前父计划的id,所属机构id为当前父计划所属机构id的数据
 | 
	
		
			
				|  |  | +            List<CoreSafecheckPlanToPoint> rpList = coreSafecheckPlanToPointMapper.selectList(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, coreSafecheckPlan.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, coreSafecheckPlan.getPlanOfOrgId()));
 | 
	
		
			
				|  |  | +            if (rpList != null) {
 | 
	
		
			
				|  |  | +                coreSafecheckPlanToPointMapper.delete(new LambdaQueryWrapper<CoreSafecheckPlanToPoint>().eq(CoreSafecheckPlanToPoint::getPlanId, p.getId()).eq(CoreSafecheckPlanToPoint::getOfOrgId, coreSafecheckPlan.getPlanOfOrgId()));
 | 
	
		
			
				|  |  | +                for (CoreSafecheckPlanToPoint s :
 | 
	
		
			
				|  |  | +                        rpList) {
 | 
	
		
			
				|  |  | +                    coreSafecheckPlanToPointMapper.insert(new CoreSafecheckPlanToPoint(p.getId(), s.getPointId(), s.isPointScan(), s.isRequired(), s.getOfOrgId()));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //如果计划是编辑全部,代表不存在已完成或者逾期的任务,需要删除重新生成
 | 
	
		
			
				|  |  | -            if (coreSafecheckPlan.getHasEdit() == null&& coreSafecheckPlan.isBuildTaskNow()&&coreSafecheckPlan.getPlanStatus()==1) {
 | 
	
		
			
				|  |  | -                coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, coreSafecheckPlan.getId()).in(CoreSafetyTask::getStatus,1,2));
 | 
	
		
			
				|  |  | +            if (coreSafecheckPlan.getHasEdit() == null && coreSafecheckPlan.isBuildTaskNow() && coreSafecheckPlan.getPlanStatus() == 1) {
 | 
	
		
			
				|  |  | +                coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, p.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  //否则代表编辑名称,需要同步未进行的任务名称
 | 
	
		
			
				|  |  |                  CoreSafetyTask temp = new CoreSafetyTask();
 | 
	
		
			
				|  |  |                  temp.setTitle(coreSafecheckPlan.getPlanName());
 | 
	
		
			
				|  |  | -                coreSafetyTaskMapper.update(temp, new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, coreSafecheckPlan.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  | +                coreSafetyTaskMapper.update(temp, new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, p.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //如果计划是编辑全部,代表不存在已完成或者逾期的任务,需要删除重新生成
 | 
	
		
			
				|  |  | +        if (coreSafecheckPlan.getHasEdit() == null && coreSafecheckPlan.isBuildTaskNow() && coreSafecheckPlan.getPlanStatus() == 1) {
 | 
	
		
			
				|  |  | +            coreSafetyTaskMapper.delete(new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, coreSafecheckPlan.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //否则代表编辑名称,需要同步未进行的任务名称
 | 
	
		
			
				|  |  | +            CoreSafetyTask temp = new CoreSafetyTask();
 | 
	
		
			
				|  |  | +            temp.setTitle(coreSafecheckPlan.getPlanName());
 | 
	
		
			
				|  |  | +            coreSafetyTaskMapper.update(temp, new LambdaQueryWrapper<CoreSafetyTask>().eq(CoreSafetyTask::getPlanId, coreSafecheckPlan.getId()).in(CoreSafetyTask::getStatus, 1, 2));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -550,4 +568,143 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
 | 
	
		
			
				|  |  |      public int deleteCoreSafecheckPlanById(Long id) {
 | 
	
		
			
				|  |  |          return coreSafecheckPlanMapper.deleteById(id);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Async
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void buildPdf(Long taskId) {
 | 
	
		
			
				|  |  | +        CoreSafetyTask coreSafetyTask = coreSafetyTaskMapper.selectById(taskId);
 | 
	
		
			
				|  |  | +        createSafetyCheckRegisterBookPdf(coreSafetyTask);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
 | 
	
		
			
				|  |  | +    public String createSafetyCheckRegisterBookPdf(CoreSafetyTask appSafetyCheckTask) {
 | 
	
		
			
				|  |  | +        SafeCheckTaskRegisterBookVo registerBookVo = buildSafetyCheckRegisterBookData(appSafetyCheckTask);
 | 
	
		
			
				|  |  | +        String url = this.createSafeCheckPdfNow(registerBookVo);
 | 
	
		
			
				|  |  | +        CoreRegisterBookPdf registerBookPdf = new CoreRegisterBookPdf();
 | 
	
		
			
				|  |  | +        registerBookPdf.setId(appSafetyCheckTask.getId());
 | 
	
		
			
				|  |  | +        registerBookPdf.setRegisterBookType(RegisterBookType.SAFE_CHECK_REPORT.getNum());
 | 
	
		
			
				|  |  | +        registerBookPdf.setDate(new Date());
 | 
	
		
			
				|  |  | +        SysOrg org = orgService.selectSysOrgById(registerBookVo.getOrgId(), SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        registerBookPdf.setOrgId(org.getId());
 | 
	
		
			
				|  |  | +        registerBookPdf.setOrgPath(org.getPath());
 | 
	
		
			
				|  |  | +        registerBookPdf.setFileUrl(url);
 | 
	
		
			
				|  |  | +        registerBookPdf.setFileName(StringUtils.substringAfterLast(url, "\\"));
 | 
	
		
			
				|  |  | +        registerBookPdf.setOrgName(registerBookVo.getOrgName());
 | 
	
		
			
				|  |  | +        registerBookPdfService.save(registerBookPdf);
 | 
	
		
			
				|  |  | +        CoreSafetyTask tem = new CoreSafetyTask();
 | 
	
		
			
				|  |  | +        tem.setId(appSafetyCheckTask.getId());
 | 
	
		
			
				|  |  | +        tem.setPdfUrl(url);
 | 
	
		
			
				|  |  | +        coreSafetyTaskMapper.updateById(tem);
 | 
	
		
			
				|  |  | +        return url;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public String createSafeCheckPdfNow(SafeCheckTaskRegisterBookVo data) {
 | 
	
		
			
				|  |  | +        return buildSafeCheckPdfData(data);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static String getCacheDir() {
 | 
	
		
			
				|  |  | +        String resource = "cache";
 | 
	
		
			
				|  |  | +        File file = new File(resource);
 | 
	
		
			
				|  |  | +        if (!file.exists()) {
 | 
	
		
			
				|  |  | +            file.mkdirs();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return resource;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String generateFilePath(String fileName) {
 | 
	
		
			
				|  |  | +        final String resource = getCacheDir();
 | 
	
		
			
				|  |  | +        return resource + File.separator + fileName;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String buildSafeCheckPdfData(SafeCheckTaskRegisterBookVo data) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String fileOrgName = registerBookPdfService.getFileOrgName(data.getOrgId());
 | 
	
		
			
				|  |  | +        String fileName = fileOrgName + "_" + RegisterBookType.SAFE_CHECK_REPORT.getText()+ "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss") + ".pdf";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        data.setDest(fileName);
 | 
	
		
			
				|  |  | +        //新方式生成pdf
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //返回相对地址
 | 
	
		
			
				|  |  | +            return fileService.generateSafeCheckPdf(data).getData();
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            throw new RuntimeException(e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String getParentName(Long parentId, String name) {
 | 
	
		
			
				|  |  | +        SysOrg org = orgService.selectSysOrgById(parentId, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +        if (org != null && org.getParentId() == -1) {
 | 
	
		
			
				|  |  | +            return ObjectUtil.isEmpty(name) ? org.getName() : name;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (org != null) {
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotNull(name)) {
 | 
	
		
			
				|  |  | +                name = this.getParentName(org.getParentId(), org.getName() + "/" + name);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNull(name)) {
 | 
	
		
			
				|  |  | +                name = this.getParentName(org.getParentId(), org.getName());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            String string = name.subSequence(0, name.length() - 1).toString();
 | 
	
		
			
				|  |  | +            name = StringUtils.substringAfter(string, "/");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return name;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public SafeCheckTaskRegisterBookVo buildSafetyCheckRegisterBookData(CoreSafetyTask appSafetyCheckTask) {
 | 
	
		
			
				|  |  | +        SafeCheckTaskRegisterBookVo registerBookVo = new SafeCheckTaskRegisterBookVo();
 | 
	
		
			
				|  |  | +        registerBookVo.setTaskTitle(appSafetyCheckTask.getTitle() + getRegisterBookCycleText(Math.toIntExact(appSafetyCheckTask.getCheckCycle()), appSafetyCheckTask.getSubmitTime()));
 | 
	
		
			
				|  |  | +        final SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
 | 
	
		
			
				|  |  | +        String dateStr = format.format(appSafetyCheckTask.getSubmitTime());
 | 
	
		
			
				|  |  | +        registerBookVo.setDateStr(dateStr);
 | 
	
		
			
				|  |  | +        registerBookVo.setCheckOrgId(appSafetyCheckTask.getCheckOrgId());
 | 
	
		
			
				|  |  | +        registerBookVo.setCheckOrgName(appSafetyCheckTask.getCheckOrgName());
 | 
	
		
			
				|  |  | +        registerBookVo.setOrgId(appSafetyCheckTask.getOrgId());
 | 
	
		
			
				|  |  | +        registerBookVo.setOrgName(appSafetyCheckTask.getOrgName());
 | 
	
		
			
				|  |  | +        String checkUserInfo = appSafetyCheckTask.getSubmitBy();
 | 
	
		
			
				|  |  | +        registerBookVo.setCheckUserInfo(checkUserInfo);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<CheckDataVo> pointCheckDataList = new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<AppTaskRegisterPointVo> appTaskRegisterPointVos = coreSafetyTaskMapper.selectPointByTask(appSafetyCheckTask.getId());
 | 
	
		
			
				|  |  | +        for (AppTaskRegisterPointVo vo :
 | 
	
		
			
				|  |  | +                appTaskRegisterPointVos) {
 | 
	
		
			
				|  |  | +            CheckDataVo v = new CheckDataVo();
 | 
	
		
			
				|  |  | +            v.setItemName(vo.getItemName());
 | 
	
		
			
				|  |  | +            v.setPointName(vo.getPointName());
 | 
	
		
			
				|  |  | +            v.setResRemark(vo.getRemark());
 | 
	
		
			
				|  |  | +            pointCheckDataList.add(v);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        registerBookVo.setCheckDatas(pointCheckDataList);
 | 
	
		
			
				|  |  | +        return registerBookVo;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private String getRegisterBookCycleText(int cycle, Date checkDate) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String cycleText = StringUtil.EMPTY_STRING;
 | 
	
		
			
				|  |  | +        DateHelper dh = new DateHelper(checkDate);
 | 
	
		
			
				|  |  | +        switch (cycle) {
 | 
	
		
			
				|  |  | +            case 2:// 每月
 | 
	
		
			
				|  |  | +                SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
 | 
	
		
			
				|  |  | +                cycleText = sdf.format(checkDate);
 | 
	
		
			
				|  |  | +                return MessageFormat.format("({0})", cycleText);
 | 
	
		
			
				|  |  | +            case 3:// 每季
 | 
	
		
			
				|  |  | +                cycleText = dh.getYear() + "年第" + dh.getQuarter() + "季度";
 | 
	
		
			
				|  |  | +                return MessageFormat.format("({0})", cycleText);
 | 
	
		
			
				|  |  | +            case 4:// 每半年
 | 
	
		
			
				|  |  | +                cycleText = dh.getYear() + "年" + (dh.getHalfyear() == 1 ? "上半年" : "下半年");
 | 
	
		
			
				|  |  | +                return MessageFormat.format("({0})", cycleText);
 | 
	
		
			
				|  |  | +            case 5:// 每年
 | 
	
		
			
				|  |  | +            case 6:// 无周期
 | 
	
		
			
				|  |  | +            case 1:// 每周
 | 
	
		
			
				|  |  | +            case 0:// 每日
 | 
	
		
			
				|  |  | +            default:
 | 
	
		
			
				|  |  | +                return StringUtil.EMPTY_STRING;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |