|  | @@ -32,6 +32,8 @@ import org.springframework.scheduling.annotation.Async;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import javax.validation.constraints.NotEmpty;
 | 
	
		
			
				|  |  | +import javax.validation.constraints.NotNull;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -61,52 +63,37 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 一个入口,生成多种组合
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param execOrgIds 执行机构类型
 | 
	
		
			
				|  |  | +     * @param planIds    计划类型
 | 
	
		
			
				|  |  | +     * @param date       要生成的周期中的某个日期
 | 
	
		
			
				|  |  | +     * @param cycle
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle) {
 | 
	
		
			
				|  |  | -        List<AppPlan> AppPlanList = queryPlans(getHangsheOrgIds(), cycle, null);
 | 
	
		
			
				|  |  | -        return createTaskByPlan(AppPlanList);
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    /*
 | 
	
		
			
				|  |  | -     * 按计划重新生成。为保持通用,参数使用object.只支持同属一个父计划的子计划
 | 
	
		
			
				|  |  | -     * */
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    @Transactional
 | 
	
		
			
				|  |  | -    public void rebuildCurrentCycleTask(List<Object> plans) {
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isEmpty(plans)) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<AppPlan> appPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | -        for (Object plan : plans) {
 | 
	
		
			
				|  |  | -            if (plan.getClass() == AppPlan.class) {
 | 
	
		
			
				|  |  | -                appPlans.add((AppPlan) plan);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isEmpty(appPlans)) {
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | +    public int buildTask(List<Long> execOrgIds, List<Long> planIds, @NotNull Date date, @NotNull CycleCommonEnum cycle) {
 | 
	
		
			
				|  |  | +        List<Long> hsOrgIds = null;
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(execOrgIds)) {
 | 
	
		
			
				|  |  | +            hsOrgIds = getHangsheOrgIds();
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            hsOrgIds = remoteOrgService.selectParentHs(execOrgIds, SecurityConstants.INNER).stream()
 | 
	
		
			
				|  |  | +                    .map(SysOrg::getId)
 | 
	
		
			
				|  |  | +                    .collect(Collectors.toList());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        AppPlan plan = appPlans.get(0);
 | 
	
		
			
				|  |  | -        CycleCommonEnum cycle = CycleCommonEnum.getEnum(plan.getPlanCycle());
 | 
	
		
			
				|  |  | -        DateRange range = DateUtils.getStartAndEnd(new Date(), cycle);
 | 
	
		
			
				|  |  | +        List<AppPlan> appPlanList = queryPlans(hsOrgIds, cycle, null, planIds);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<Resumption> resumptionList = queryTask(range.getStartTime(), cycle, null, appPlans.stream().map(AppPlan::getId).collect(Collectors.toList()));
 | 
	
		
			
				|  |  | -        List<Long> deleteIds = resumptionList.stream()
 | 
	
		
			
				|  |  | -                .filter(r -> (ObjectUtil.equal(r.getStatus(), 1) || ObjectUtil.equal(r.getStatus(), 2)))
 | 
	
		
			
				|  |  | -                .map(Resumption::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isNotEmpty(deleteIds)) {
 | 
	
		
			
				|  |  | -            baseMapper.deleteBatchIds(deleteIds);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        createTaskByPlan(appPlans);
 | 
	
		
			
				|  |  | +        return buildTask(execOrgIds, appPlanList, date);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    private int createTaskByPlan(List<AppPlan> appPlanList) {
 | 
	
		
			
				|  |  | +    public int buildTask(List<Long> execOrgIds, @NotEmpty List<AppPlan> plans, @NotNull Date date) {
 | 
	
		
			
				|  |  |          List<Resumption> resumptions = new ArrayList<>();
 | 
	
		
			
				|  |  | -        for (AppPlan appPlan : appPlanList) {
 | 
	
		
			
				|  |  | +        for (AppPlan appPlan : plans) {
 | 
	
		
			
				|  |  | +            if(ObjectUtil.notEqual(appPlan.getPlanStatus(),1)){
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //获取履职计划中对应的检查要点
 | 
	
		
			
				|  |  |              List<AppRulePointTaskVo> pointList = appRulePointService.findPointByPlan(appPlan.getId());
 | 
	
		
			
				|  |  |              if (pointList.size() <= 0) {//没有检查项不生成履职任务
 | 
	
	
		
			
				|  | @@ -114,21 +101,23 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |                  continue;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            List<Long> orgIdList = getPlanOrgIds(appPlan);
 | 
	
		
			
				|  |  | -            if (CollectionUtils.isEmpty(orgIdList)) {//没有检查项不生成履职任务
 | 
	
		
			
				|  |  | -                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
 | 
	
		
			
				|  |  | -                continue;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  |              //获取履职角色
 | 
	
		
			
				|  |  |              List<Long> roleIds = appPlanService.findRoleByPlan(appPlan.getId());
 | 
	
		
			
				|  |  |              if (CollectionUtils.isEmpty(roleIds)) {//没有检查项不生成履职任务
 | 
	
		
			
				|  |  |                  log.info("error:该计划ID:{}没有履职角色", appPlan.getId());
 | 
	
		
			
				|  |  |                  continue;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<Long> orgIds = getPlanOrgIds(appPlan, execOrgIds);
 | 
	
		
			
				|  |  | +            if (CollectionUtils.isEmpty(orgIds)) {
 | 
	
		
			
				|  |  | +                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              CycleCommonEnum cycleCommonEnum = CycleCommonEnum.getEnum(appPlan.getPlanCycle());
 | 
	
		
			
				|  |  | -            DateRange range = DateUtils.getStartAndEnd(new Date(), cycleCommonEnum);
 | 
	
		
			
				|  |  | -            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIdList);
 | 
	
		
			
				|  |  | -            for (Long orgId : orgIdList) {
 | 
	
		
			
				|  |  | +            DateRange range = DateUtils.getStartAndEnd(date, cycleCommonEnum);
 | 
	
		
			
				|  |  | +            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIds);
 | 
	
		
			
				|  |  | +            for (Long orgId : orgIds) {
 | 
	
		
			
				|  |  |                  if (!workTimes.containsKey(orgId) || ObjectUtil.isNull(workTimes.get(orgId)) || ObjectUtil.notEqual(workTimes.get(orgId).getIsEnable(), 1L)) {
 | 
	
		
			
				|  |  |                      continue;
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -154,6 +143,108 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +//    @Override
 | 
	
		
			
				|  |  | +//    @Transactional
 | 
	
		
			
				|  |  | +//    public int buildTaskByCycle(DateTime dateTime, CycleCommonEnum cycle) {
 | 
	
		
			
				|  |  | +//        List<AppPlan> AppPlanList = queryPlans(getHangsheOrgIds(), cycle, null, null);
 | 
	
		
			
				|  |  | +//        return createTaskByPlan(AppPlanList);
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /*
 | 
	
		
			
				|  |  | +     * 按计划重新生成。为保持通用,参数使用object.只支持同属一个父计划的子计划
 | 
	
		
			
				|  |  | +     * */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional
 | 
	
		
			
				|  |  | +    public void rebuildCurrentCycleTask(List<Object> plans) {
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(plans)) {
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<Long> hsOrgIds = getHangsheOrgIds();
 | 
	
		
			
				|  |  | +        List<AppPlan> appPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (Object plan : plans) {
 | 
	
		
			
				|  |  | +            if (plan.getClass() != AppPlan.class) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            AppPlan p = (AppPlan) plan;
 | 
	
		
			
				|  |  | +            if (!hsOrgIds.contains(p.getPlanOfOrgId())) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            appPlans.add(p);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(appPlans)) {
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        AppPlan plan = appPlans.get(0);
 | 
	
		
			
				|  |  | +        Date workDate = new Date();
 | 
	
		
			
				|  |  | +        CycleCommonEnum cycle = CycleCommonEnum.getEnum(plan.getPlanCycle());
 | 
	
		
			
				|  |  | +        DateRange range = DateUtils.getStartAndEnd(workDate, cycle);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Resumption> resumptionList = queryTask(range.getStartTime(), cycle, null, appPlans.stream().map(AppPlan::getId).collect(Collectors.toList()));
 | 
	
		
			
				|  |  | +        List<Long> deleteIds = resumptionList.stream()
 | 
	
		
			
				|  |  | +                .filter(r -> (ObjectUtil.equal(r.getStatus(), 1) || ObjectUtil.equal(r.getStatus(), 2)))
 | 
	
		
			
				|  |  | +                .map(Resumption::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(deleteIds)) {
 | 
	
		
			
				|  |  | +            baseMapper.deleteBatchIds(deleteIds);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        buildTask(null, appPlans, workDate);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//    private int createTaskByPlan(List<AppPlan> appPlanList) {
 | 
	
		
			
				|  |  | +//        List<Resumption> resumptions = new ArrayList<>();
 | 
	
		
			
				|  |  | +//        for (AppPlan appPlan : appPlanList) {
 | 
	
		
			
				|  |  | +//            //获取履职计划中对应的检查要点
 | 
	
		
			
				|  |  | +//            List<AppRulePointTaskVo> pointList = appRulePointService.findPointByPlan(appPlan.getId());
 | 
	
		
			
				|  |  | +//            if (pointList.size() <= 0) {//没有检查项不生成履职任务
 | 
	
		
			
				|  |  | +//                log.info("error:该计划ID:" + appPlan.getId() + "没有检查项");
 | 
	
		
			
				|  |  | +//                continue;
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//            List<Long> orgIdList = getPlanOrgIds(appPlan, null);
 | 
	
		
			
				|  |  | +//            if (CollectionUtils.isEmpty(orgIdList)) {//没有检查项不生成履职任务
 | 
	
		
			
				|  |  | +//                log.info("error:该计划ID:{}没有执行机构", appPlan.getId());
 | 
	
		
			
				|  |  | +//                continue;
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +//            //获取履职角色
 | 
	
		
			
				|  |  | +//            List<Long> roleIds = appPlanService.findRoleByPlan(appPlan.getId());
 | 
	
		
			
				|  |  | +//            if (CollectionUtils.isEmpty(roleIds)) {//没有检查项不生成履职任务
 | 
	
		
			
				|  |  | +//                log.info("error:该计划ID:{}没有履职角色", appPlan.getId());
 | 
	
		
			
				|  |  | +//                continue;
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +//            CycleCommonEnum cycleCommonEnum = CycleCommonEnum.getEnum(appPlan.getPlanCycle());
 | 
	
		
			
				|  |  | +//            DateRange range = DateUtils.getStartAndEnd(new Date(), cycleCommonEnum);
 | 
	
		
			
				|  |  | +//            Map<Long, SysWorkTime> workTimes = orgSingleWorkTimeMap(new Date(), cycleCommonEnum, orgIdList);
 | 
	
		
			
				|  |  | +//            for (Long orgId : orgIdList) {
 | 
	
		
			
				|  |  | +//                if (!workTimes.containsKey(orgId) || ObjectUtil.isNull(workTimes.get(orgId)) || ObjectUtil.notEqual(workTimes.get(orgId).getIsEnable(), 1L)) {
 | 
	
		
			
				|  |  | +//                    continue;
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                SysWorkTime workTime = workTimes.get(orgId);
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                List<Resumption> tasks;
 | 
	
		
			
				|  |  | +//                if (ObjectUtil.equal(CycleCommonEnum.DAILY.getCode(), appPlan.getPlanCycle())) {
 | 
	
		
			
				|  |  | +//                    tasks = buildResumptions(appPlan, orgId, workTime);
 | 
	
		
			
				|  |  | +//                } else {
 | 
	
		
			
				|  |  | +//                    tasks = buildResumptions(appPlan, orgId, range.getStartTime(), range.getEndTime(), 0L);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                if (CollectionUtils.isNotEmpty(tasks)) {
 | 
	
		
			
				|  |  | +//                    resumptions.addAll(tasks);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +//        }
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//        if (this.saveBatch(resumptions)) {
 | 
	
		
			
				|  |  | +//            return resumptions.size();
 | 
	
		
			
				|  |  | +//        } else {
 | 
	
		
			
				|  |  | +//            return 0;
 | 
	
		
			
				|  |  | +//        }
 | 
	
		
			
				|  |  | +//    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public void rebuildDayTask(List<Long> orgIds, SysWorkTime workTime) {
 | 
	
		
			
				|  |  |          rebuildTask(orgIds, workTime.getYmdDate(), workTime.getYmdDate(), CycleCommonEnum.DAILY, workTime);
 | 
	
	
		
			
				|  | @@ -224,7 +315,7 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |              List<Long> hsOrgIds = remoteOrgService.selectParentHs(ListUtil.toList(orgId), SecurityConstants.INNER)
 | 
	
		
			
				|  |  |                      .stream().map(SysOrg::getId)
 | 
	
		
			
				|  |  |                      .collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            List<AppPlan> listPlans = queryPlans(hsOrgIds, cycle, ListUtil.toList(org.getType()));
 | 
	
		
			
				|  |  | +            List<AppPlan> listPlans = queryPlans(hsOrgIds, cycle, ListUtil.toList(org.getType()), null);
 | 
	
		
			
				|  |  |              if (CollectionUtils.isEmpty(listPlans)) {
 | 
	
		
			
				|  |  |                  continue;
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -355,7 +446,7 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |       * @param cycle
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private List<AppPlan> queryPlans(List<Long> planOfOrgId, CycleCommonEnum cycle, List<Integer> execOrgTypes) {
 | 
	
		
			
				|  |  | +    private List<AppPlan> queryPlans(List<Long> planOfOrgId, CycleCommonEnum cycle, List<Integer> execOrgTypes, List<Long> planIds) {
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(planOfOrgId)) {
 | 
	
		
			
				|  |  |              return new ArrayList<>();
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -367,6 +458,9 @@ public class ResumptionTaskBusiness extends TaskCreatingServiceImplBase<Resumpti
 | 
	
		
			
				|  |  |          if (CollectionUtils.isNotEmpty(execOrgTypes)) {
 | 
	
		
			
				|  |  |              qw.lambda().in(AppPlan::getExecOrgType, execOrgTypes);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(planIds)) {
 | 
	
		
			
				|  |  | +            qw.lambda().in(AppPlan::getId, planIds);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          List<AppPlan> listPlans = appPlanMapper.selectList(qw);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return listPlans;
 |