|  | @@ -2,6 +2,7 @@ package com.xunmei.core.resumption.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import cn.hutool.core.date.DateTime;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.constant.SecurityConstants;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.R;
 | 
	
	
		
			
				|  | @@ -13,6 +14,7 @@ import com.xunmei.core.resumption.domain.AppPlan;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.dto.DistributeDto;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.dto.plan.CoreResumptionPlanPageDto;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.service.AppPlanService;
 | 
	
		
			
				|  |  | +import com.xunmei.core.resumption.task.RebuildResumptionTaskBusiness;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.task.ResumptionTaskBusiness;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.vo.appPlan.AppPlanVo;
 | 
	
		
			
				|  |  |  import com.xunmei.core.resumption.vo.appPlan.RuleItemVo;
 | 
	
	
		
			
				|  | @@ -23,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.Collections;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  import java.util.Map;
 | 
	
		
			
				|  |  |  import java.util.TimeZone;
 | 
	
	
		
			
				|  | @@ -44,6 +47,8 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |      private RemoteOrgService remoteOrgService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      ResumptionTaskBusiness taskBusiness;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    RebuildResumptionTaskBusiness rebuildResumptionTaskBusiness;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 计划分页查询
 | 
	
	
		
			
				|  | @@ -62,6 +67,7 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 下发
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  |       * @param dto
 | 
	
		
			
				|  |  |       * @return
 | 
	
		
			
				|  |  |       */
 | 
	
	
		
			
				|  | @@ -72,30 +78,34 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |              appPlanService.distributeToOrg(dto);
 | 
	
		
			
				|  |  |              AppPlan plan = appPlanService.getById(dto.getId());
 | 
	
		
			
				|  |  |              //如果选择了计划立即生效
 | 
	
		
			
				|  |  | -            if (plan.getBuildTaskNow()==1) {
 | 
	
		
			
				|  |  | -                DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | -                datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | -                Integer plancycle = plan.getPlanCycle();
 | 
	
		
			
				|  |  | -                if (plancycle != null) {
 | 
	
		
			
				|  |  | -                    if (plancycle == 2) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (plancycle == 3) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (plancycle == 4) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (plancycle == 5) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (plancycle == 6) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    if (plancycle == 7) {
 | 
	
		
			
				|  |  | -                        taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            if (plan.getBuildTaskNow() == 1) {
 | 
	
		
			
				|  |  | +                List<AppPlan> list = appPlanService.list(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()).eq(AppPlan::getDeleted, 0));
 | 
	
		
			
				|  |  | +                list.add(plan);
 | 
	
		
			
				|  |  | +                rebuildResumptionTaskBusiness.rebuildCurrentCycleTask(Collections.singletonList(list));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +//                DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | +//                datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | +//                Integer plancycle = plan.getPlanCycle();
 | 
	
		
			
				|  |  | +//                if (plancycle != null) {
 | 
	
		
			
				|  |  | +//                    if (plancycle == 2) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    if (plancycle == 3) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    if (plancycle == 4) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    if (plancycle == 5) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    if (plancycle == 6) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    if (plancycle == 7) {
 | 
	
		
			
				|  |  | +//                        taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return AjaxResult.success();
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
	
		
			
				|  | @@ -146,42 +156,42 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |      public AjaxResult edit(@RequestBody AppPlanVo info) {
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              appPlanService.saveOrUpdatePlan(info);
 | 
	
		
			
				|  |  | +            AppPlan plan = null;
 | 
	
		
			
				|  |  | +            plan = appPlanService.getById(info.getId());
 | 
	
		
			
				|  |  |              Long planOfOrgType = null;
 | 
	
		
			
				|  |  | -            if (info.getId()==null){
 | 
	
		
			
				|  |  | -                Long orgId = info.getPlanCreateOrgId();
 | 
	
		
			
				|  |  | -                planOfOrgType = Long.valueOf(remoteOrgService.selectSysOrgById(orgId, SecurityConstants.INNER).getType());
 | 
	
		
			
				|  |  | -            }else {
 | 
	
		
			
				|  |  | -                AppPlan plan = appPlanService.getById(info.getId());
 | 
	
		
			
				|  |  | -                planOfOrgType = plan.getPlanOfOrgType();
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +            planOfOrgType = plan.getPlanOfOrgType();
 | 
	
		
			
				|  |  |              //判断是否是编辑并且计划所属任务不存在已完成或者逾期,需要删除所有任务重新生成
 | 
	
		
			
				|  |  | -            boolean isEditAll = info.getHasEdit() == null&&info.getId()!=null;
 | 
	
		
			
				|  |  | +            boolean isEditAll = info.getHasEdit() == null && info.getId() != null;
 | 
	
		
			
				|  |  |              //如果计划所属机构类型为行社并且勾选立即执行,新增的时候立即生成任务
 | 
	
		
			
				|  |  | -            if ((info.getId()==null&&planOfOrgType==3&&info.getBuildTaskNow()==1)||isEditAll){
 | 
	
		
			
				|  |  | -                    DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | -                    datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | -                    //当有周期存在时保持原有接口不变(doTask),否则按照新的接口创建
 | 
	
		
			
				|  |  | -                    Integer plancycle = info.getPlanCycle();
 | 
	
		
			
				|  |  | -                    if (plancycle != null) {
 | 
	
		
			
				|  |  | -                        if (plancycle == 2) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if (plancycle == 3) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if (plancycle == 4) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if (plancycle == 5) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if (plancycle == 6) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                        if (plancycle == 7) {
 | 
	
		
			
				|  |  | -                            taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +            if ((info.getId() == null && planOfOrgType == 3 && info.getBuildTaskNow() == 1) || isEditAll) {
 | 
	
		
			
				|  |  | +//                    DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | +//                    datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | +//                    //当有周期存在时保持原有接口不变(doTask),否则按照新的接口创建
 | 
	
		
			
				|  |  | +//                    Integer plancycle = info.getPlanCycle();
 | 
	
		
			
				|  |  | +//                    if (plancycle != null) {
 | 
	
		
			
				|  |  | +//                        if (plancycle == 2) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        if (plancycle == 3) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        if (plancycle == 4) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        if (plancycle == 5) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        if (plancycle == 6) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                        if (plancycle == 7) {
 | 
	
		
			
				|  |  | +//                            taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +                //如果编辑
 | 
	
		
			
				|  |  | +                List<AppPlan> list = appPlanService.list(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()).eq(AppPlan::getDeleted, 0));
 | 
	
		
			
				|  |  | +                list.add(plan);
 | 
	
		
			
				|  |  | +                rebuildResumptionTaskBusiness.rebuildCurrentCycleTask(Collections.singletonList(list));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -245,6 +255,7 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |  //        }
 | 
	
		
			
				|  |  |          return AjaxResult.success();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @ApiOperation(value = "撤回后下发")
 | 
	
		
			
				|  |  |      @GetMapping(value = "/distributeCheHui/{id}")
 | 
	
		
			
				|  |  |  //    @RequiresPermissions("core:plan:findById")
 | 
	
	
		
			
				|  | @@ -252,31 +263,35 @@ public class ApiPlanController {
 | 
	
		
			
				|  |  |          int i = appPlanService.distributeCheHui(id);
 | 
	
		
			
				|  |  |          AppPlan plan = appPlanService.getById(id);
 | 
	
		
			
				|  |  |          //撤回后的下发如果存在子计划并且勾选立即执行也需要生成任务
 | 
	
		
			
				|  |  | -        if(plan.getBuildTaskNow()==1){
 | 
	
		
			
				|  |  | -            DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | -            datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | -            //当有周期存在时保持原有接口不变(doTask),否则按照新的接口创建
 | 
	
		
			
				|  |  | -            Integer plancycle = plan.getPlanCycle();
 | 
	
		
			
				|  |  | -            if (plancycle != null) {
 | 
	
		
			
				|  |  | -                if (plancycle == 2) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (plancycle == 3) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (plancycle == 4) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (plancycle == 5) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (plancycle == 6) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                if (plancycle == 7) {
 | 
	
		
			
				|  |  | -                    taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        if (plan.getBuildTaskNow() == 1) {
 | 
	
		
			
				|  |  | +//            DateTime datetime = new DateTime();
 | 
	
		
			
				|  |  | +//            datetime.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
 | 
	
		
			
				|  |  | +//            //当有周期存在时保持原有接口不变(doTask),否则按照新的接口创建
 | 
	
		
			
				|  |  | +//            Integer plancycle = plan.getPlanCycle();
 | 
	
		
			
				|  |  | +//            if (plancycle != null) {
 | 
	
		
			
				|  |  | +//                if (plancycle == 2) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncDay(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                if (plancycle == 3) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncWeek(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                if (plancycle == 4) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncMonth(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                if (plancycle == 5) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncQuarter(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                if (plancycle == 6) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncHalfYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//                if (plancycle == 7) {
 | 
	
		
			
				|  |  | +//                    taskBusiness.syncYear(datetime, plancycle);
 | 
	
		
			
				|  |  | +//                }
 | 
	
		
			
				|  |  | +//            }
 | 
	
		
			
				|  |  | +            List<AppPlan> list = appPlanService.list(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()).eq(AppPlan::getDeleted, 0));
 | 
	
		
			
				|  |  | +            list.add(plan);
 | 
	
		
			
				|  |  | +            rebuildResumptionTaskBusiness.rebuildCurrentCycleTask(Collections.singletonList(list));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return AjaxResult.success(i);
 | 
	
		
			
				|  |  |      }
 |