|  | @@ -592,6 +592,7 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |      public int distribute(Long id, Boolean immediateEffect) throws ParseException {
 | 
	
		
			
				|  |  |          //查询
 | 
	
		
			
				|  |  |          TMonitoringRetrievalPlan publishPlan = tMonitoringRetrievalPlanMapper.selectById(id);
 | 
	
		
			
				|  |  | +        Integer oldPlanStatus=publishPlan.getPlanStatus();
 | 
	
		
			
				|  |  |          publishPlan.setImmediately(immediateEffect);
 | 
	
		
			
				|  |  |          publishPlan.setIsDistribute("1");
 | 
	
		
			
				|  |  |          publishPlan.setPlanStatus(1);
 | 
	
	
		
			
				|  | @@ -614,7 +615,7 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          final CompletableFuture<List<TMonitoringRetrievalPlan>> planListFuture = CompletableFuture.supplyAsync(() -> {
 | 
	
		
			
				|  |  | -            return getNeedCreateTaskPlans(loginUserOrg, publishPlan);
 | 
	
		
			
				|  |  | +            return getNeedCreateTaskPlans(loginUserOrg, publishPlan,oldPlanStatus);
 | 
	
		
			
				|  |  |          }, threadPoolTaskExecutor);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          planListFuture.thenAcceptAsync((result) -> {
 | 
	
	
		
			
				|  | @@ -631,7 +632,7 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |          return i;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private List<TMonitoringRetrievalPlan> getNeedCreateTaskPlans(SysOrg loginUserOrg, TMonitoringRetrievalPlan publishPlan) {
 | 
	
		
			
				|  |  | +    private List<TMonitoringRetrievalPlan> getNeedCreateTaskPlans(SysOrg loginUserOrg, TMonitoringRetrievalPlan publishPlan,Integer oldPlanStatus) {
 | 
	
		
			
				|  |  |          List<TMonitoringRetrievalPlan> tempPlans = new ArrayList<>();
 | 
	
		
			
				|  |  |          SysOrg publishPlanOrg = remoteOrgService.selectSysOrgById(publishPlan.getOrgId(), SecurityConstants.INNER);
 | 
	
		
			
				|  |  |          //如果登录当前是省联社 办事处
 | 
	
	
		
			
				|  | @@ -639,84 +640,77 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              QueryWrapper queryWrapper = new QueryWrapper();
 | 
	
		
			
				|  |  |              queryWrapper.eq(PARENT_ID, publishPlan.getId());
 | 
	
		
			
				|  |  | +            queryWrapper.eq("is_deleted", 0);
 | 
	
		
			
				|  |  |              // 获取当前计划已存在的子计划
 | 
	
		
			
				|  |  |              List<TMonitoringRetrievalPlan> existSubPlanlist = tMonitoringRetrievalPlanMapper.selectList(queryWrapper);
 | 
	
		
			
				|  |  |              //如果已存在子计划
 | 
	
		
			
				|  |  |              if (CollectionUtils.isNotEmpty(existSubPlanlist)) {
 | 
	
		
			
				|  |  | -                for (TMonitoringRetrievalPlan tm : existSubPlanlist) {
 | 
	
		
			
				|  |  | -                    tm.setPlanStatus(1);
 | 
	
		
			
				|  |  | -                    tm.setIsDistribute("1");
 | 
	
		
			
				|  |  | -                    baseMapper.updateById(tm);
 | 
	
		
			
				|  |  | -                    setPlanStartEndTime(publishPlan, tm);
 | 
	
		
			
				|  |  | -                    tempPlans.add(tm);
 | 
	
		
			
				|  |  | -//                    if (publishPlan.getOrgType().equals("3")) {
 | 
	
		
			
				|  |  | -//                        setPlanStartEndTime(publishPlan,tm);
 | 
	
		
			
				|  |  | -//                        tempPlans.add(tm);
 | 
	
		
			
				|  |  | -//                    }
 | 
	
		
			
				|  |  | -//                    else
 | 
	
		
			
				|  |  | -//                    {
 | 
	
		
			
				|  |  | -//                        SysOrg sysOrg = new SysOrg();
 | 
	
		
			
				|  |  | -//                        sysOrg.setPath(tm.getOrgPath());
 | 
	
		
			
				|  |  | -//                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
 | 
	
		
			
				|  |  | -//                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | -//                        List<SysOrg> sysOrgs=getExecOrgList(null,Integer.valueOf(publishPlan.getOrgType()),tm.getOrgPath());
 | 
	
		
			
				|  |  | -//                        for (SysOrg s : sysOrgs) {
 | 
	
		
			
				|  |  | -//                            TMonitoringRetrievalPlan plan = createTempPlan(publishPlan,publishPlan.getId(),s);
 | 
	
		
			
				|  |  | -//                            tempPlans.add(plan);
 | 
	
		
			
				|  |  | -//                        }
 | 
	
		
			
				|  |  | -//                    }
 | 
	
		
			
				|  |  | +                // 停用状态再次下发,肯定存在已完成任务,之前的子计划不会删除, 但是又有可能修改了具体执行机构 此时需要处理 历史子计划
 | 
	
		
			
				|  |  | +                if(ObjectUtil.equal(oldPlanStatus,2))
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    tempPlans.addAll(dealSubPlanWithHistorySubPlan(existSubPlanlist,publishPlan,publishPlanOrg));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                else {
 | 
	
		
			
				|  |  | +                    for (TMonitoringRetrievalPlan tm : existSubPlanlist) {
 | 
	
		
			
				|  |  | +                        tm.setPlanStatus(1);
 | 
	
		
			
				|  |  | +                        tm.setIsDistribute("1");
 | 
	
		
			
				|  |  | +                        baseMapper.updateById(tm);
 | 
	
		
			
				|  |  | +                        setPlanStartEndTime(publishPlan, tm);
 | 
	
		
			
				|  |  | +                        tempPlans.add(tm);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  // 计划机构类型 是 省联社或者办事处及行社以下的机构类型 才创建子计划
 | 
	
		
			
				|  |  |                  if (!checkOrgType(Integer.parseInt(publishPlan.getOrgType()))) {
 | 
	
		
			
				|  |  | -                    // 查询当前计划的具体执行机构
 | 
	
		
			
				|  |  | -                    List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", publishPlan.getId()));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    List<Long> planExecOrgIds = planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -                    // 根据机构类型和具体调阅机构 获取需创建子计划的机构
 | 
	
		
			
				|  |  | -                    List<SysOrg> subPlanOrglist = getPlanOrgListByOrgTypeAndExecOrgs(planExecOrgIds, Integer.parseInt(publishPlan.getOrgType()), publishPlanOrg.getPath());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    List<SysOrg> execOrglist = new ArrayList<>();
 | 
	
		
			
				|  |  | -                    if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | -                        execOrglist = RemoteCallHandlerExecutor.executeRemoteCall(() ->
 | 
	
		
			
				|  |  | -                                        remoteOrgService.selectOrgByIdList(planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList()), SecurityConstants.INNER),
 | 
	
		
			
				|  |  | -                                ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    List<TMonitoringRetrievalPlan> needAddSubPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | -                    List<TMonitoringRetrievalPlanToExecOrg> needAddSubPlanExecOrgList = new ArrayList<>();
 | 
	
		
			
				|  |  | -                    for (SysOrg subPlanOrg : subPlanOrglist) {
 | 
	
		
			
				|  |  | -                        TMonitoringRetrievalPlan tMonitoringRetrievalPlan1 = new TMonitoringRetrievalPlan();
 | 
	
		
			
				|  |  | -                        BeanUtils.copyProperties(publishPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setId(IdWorker.getId());
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setOrgId(subPlanOrg.getId());
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setOrganization(subPlanOrg.getShortName());
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setOrgPath(subPlanOrg.getPath());
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setParentId(publishPlan.getId());
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setIsDistribute("1");
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setCreateType(1);
 | 
	
		
			
				|  |  | -//                        SysOrg sysOrg = remoteOrgService.selectSysOrgById(publishPlan.getOrgId(), SecurityConstants.INNER);
 | 
	
		
			
				|  |  | -                        tMonitoringRetrievalPlan1.setOrgName(publishPlanOrg.getShortName());
 | 
	
		
			
				|  |  | -//                        insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                        needAddSubPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                        if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | -                            execOrglist.stream().filter(x -> x.getPath().contains(subPlanOrg.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | -                                TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | -                                tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | -                                tempExecOrg.setPlanId(tMonitoringRetrievalPlan1.getId());
 | 
	
		
			
				|  |  | -                                needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | -                            });
 | 
	
		
			
				|  |  | -                        }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    //保存子计划和子计划具体执行机构
 | 
	
		
			
				|  |  | -                    if (ObjectUtil.isNotEmpty(needAddSubPlans)) {
 | 
	
		
			
				|  |  | -                        this.saveBatch(needAddSubPlans);
 | 
	
		
			
				|  |  | -                        itMonitoringRetrievalPlanToExecOrgService.saveBatch(needAddSubPlanExecOrgList);
 | 
	
		
			
				|  |  | -                        needAddSubPlans.stream().forEach(plan -> {
 | 
	
		
			
				|  |  | -                            setPlanStartEndTime(plan, plan);
 | 
	
		
			
				|  |  | -                        });
 | 
	
		
			
				|  |  | -                        tempPlans.addAll(needAddSubPlans);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +                    tempPlans.addAll(buildSubPlans(publishPlan,publishPlanOrg));
 | 
	
		
			
				|  |  | +//                    // 查询当前计划的具体执行机构
 | 
	
		
			
				|  |  | +//                    List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", publishPlan.getId()));
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                    List<Long> planExecOrgIds = planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +//                    // 根据机构类型和具体调阅机构 获取需创建子计划的机构
 | 
	
		
			
				|  |  | +//                    List<SysOrg> subPlanOrglist = getPlanOrgListByOrgTypeAndExecOrgs(planExecOrgIds, Integer.parseInt(publishPlan.getOrgType()), publishPlanOrg.getPath());
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                    List<SysOrg> execOrglist = new ArrayList<>();
 | 
	
		
			
				|  |  | +//                    if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +//                        execOrglist = RemoteCallHandlerExecutor.executeRemoteCall(() ->
 | 
	
		
			
				|  |  | +//                                        remoteOrgService.selectOrgByIdList(planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList()), SecurityConstants.INNER),
 | 
	
		
			
				|  |  | +//                                ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//
 | 
	
		
			
				|  |  | +//                    List<TMonitoringRetrievalPlan> needAddSubPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +//                    List<TMonitoringRetrievalPlanToExecOrg> needAddSubPlanExecOrgList = new ArrayList<>();
 | 
	
		
			
				|  |  | +//                    for (SysOrg subPlanOrg : subPlanOrglist) {
 | 
	
		
			
				|  |  | +//                        TMonitoringRetrievalPlan tMonitoringRetrievalPlan1 = new TMonitoringRetrievalPlan();
 | 
	
		
			
				|  |  | +//                        BeanUtils.copyProperties(publishPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setId(IdWorker.getId());
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setOrgId(subPlanOrg.getId());
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setOrganization(subPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setOrgPath(subPlanOrg.getPath());
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setParentId(publishPlan.getId());
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setIsDistribute("1");
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setCreateType(1);
 | 
	
		
			
				|  |  | +////                        SysOrg sysOrg = remoteOrgService.selectSysOrgById(publishPlan.getOrgId(), SecurityConstants.INNER);
 | 
	
		
			
				|  |  | +//                        tMonitoringRetrievalPlan1.setOrgName(publishPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +////                        insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +//                        needAddSubPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +//                        if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +//                            execOrglist.stream().filter(x -> x.getPath().contains(subPlanOrg.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | +//                                TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | +//                                tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | +//                                tempExecOrg.setPlanId(tMonitoringRetrievalPlan1.getId());
 | 
	
		
			
				|  |  | +//                                needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | +//                            });
 | 
	
		
			
				|  |  | +//                        }
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  | +//                    //保存子计划和子计划具体执行机构
 | 
	
		
			
				|  |  | +//                    if (ObjectUtil.isNotEmpty(needAddSubPlans)) {
 | 
	
		
			
				|  |  | +//                        this.saveBatch(needAddSubPlans);
 | 
	
		
			
				|  |  | +//                        itMonitoringRetrievalPlanToExecOrgService.saveBatch(needAddSubPlanExecOrgList);
 | 
	
		
			
				|  |  | +//                        needAddSubPlans.stream().forEach(plan -> {
 | 
	
		
			
				|  |  | +//                            setPlanStartEndTime(plan, plan);
 | 
	
		
			
				|  |  | +//                        });
 | 
	
		
			
				|  |  | +//                        tempPlans.addAll(needAddSubPlans);
 | 
	
		
			
				|  |  | +//                    }
 | 
	
		
			
				|  |  |                  } else {
 | 
	
		
			
				|  |  |                      publishPlan.setCreateType(1);
 | 
	
		
			
				|  |  |                      publishPlan.setUpdateBy(SecurityUtils.getUsername());
 | 
	
	
		
			
				|  | @@ -725,100 +719,169 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |                      setPlanStartEndTime(publishPlan, publishPlan);
 | 
	
		
			
				|  |  |                      tempPlans.add(publishPlan);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -//                if (publishPlan.getOrgType().equals("3")) {
 | 
	
		
			
				|  |  | -//                    publishPlan.setCreateType(1);
 | 
	
		
			
				|  |  | -//                    publishPlan.setUpdateBy(SecurityUtils.getUsername());
 | 
	
		
			
				|  |  | -//                    publishPlan.setUpdateTime(DateUtils.getNowDate());
 | 
	
		
			
				|  |  | -//                    baseMapper.updateById(publishPlan);
 | 
	
		
			
				|  |  | -//                    setPlanStartEndTime(publishPlan,publishPlan);
 | 
	
		
			
				|  |  | -//                    tempPlans.add(publishPlan);
 | 
	
		
			
				|  |  | -//                }
 | 
	
		
			
				|  |  | -//                else
 | 
	
		
			
				|  |  | -//                {
 | 
	
		
			
				|  |  | -//                        SysOrg sysOrg = new SysOrg();
 | 
	
		
			
				|  |  | -//                        sysOrg.setPath(l.getPath());
 | 
	
		
			
				|  |  | -//                        sysOrg.setType(Integer.valueOf(tMonitoringRetrievalPlan.getOrgType()));
 | 
	
		
			
				|  |  | -//                        List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | -//                    List<SysOrg> sysOrgs=getExecOrgList(planExecOrgIds,Integer.valueOf(publishPlan.getOrgType()),l.getPath());
 | 
	
		
			
				|  |  | -//                    for (SysOrg s : sysOrgs) {
 | 
	
		
			
				|  |  | -//                        TMonitoringRetrievalPlan plan = createTempPlan(publishPlan,tMonitoringRetrievalPlan1.getId(),s);
 | 
	
		
			
				|  |  | -//                        tempPlans.add(plan);
 | 
	
		
			
				|  |  | -//                    }
 | 
	
		
			
				|  |  | -//                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        else // 行社计划,没有子计划,直接生成任务
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  |              publishPlan.setCreateType(1);
 | 
	
		
			
				|  |  |              publishPlan.setIsDistribute("1");
 | 
	
		
			
				|  |  |              baseMapper.updateById(publishPlan);
 | 
	
		
			
				|  |  |              setPlanStartEndTime(publishPlan, publishPlan);
 | 
	
		
			
				|  |  |              tempPlans.add(publishPlan);
 | 
	
		
			
				|  |  | -//            SysOrg sysOrg = new SysOrg();
 | 
	
		
			
				|  |  | -//            sysOrg.setPath(loginUserOrg.getPath());
 | 
	
		
			
				|  |  | -//            sysOrg.setType(Integer.valueOf(publishPlan.getOrgType()));
 | 
	
		
			
				|  |  | -//            List<SysOrg> sysOrgs = remoteOrgService.listByParentIdAndType(sysOrg, SecurityConstants.INNER);
 | 
	
		
			
				|  |  | -//            for (SysOrg s : sysOrgs) {
 | 
	
		
			
				|  |  | -//                TMonitoringRetrievalPlan plan = createTempPlan(publishPlan,publishPlan.getId(),s);
 | 
	
		
			
				|  |  | -//                tempPlans.add(plan);
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return tempPlans;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private List<TMonitoringRetrievalPlan> buildSubPlans(TMonitoringRetrievalPlan parentPlan, List<Long> parentPlanExecOrgIds, SysOrg parentPlanOrg) {
 | 
	
		
			
				|  |  | -        List<TMonitoringRetrievalPlan> subPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 停用状态再次下发,肯定存在已完成任务,之前的子计划不会删除, 但是又有可能修改了具体执行机构 此时需要处理 历史子计划
 | 
	
		
			
				|  |  | +     * @param existSubPlanlist
 | 
	
		
			
				|  |  | +     * @param publishPlan
 | 
	
		
			
				|  |  | +     * @param publishPlanOrg
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private List<TMonitoringRetrievalPlan> dealSubPlanWithHistorySubPlan(List<TMonitoringRetrievalPlan> existSubPlanlist, TMonitoringRetrievalPlan publishPlan,SysOrg publishPlanOrg) {
 | 
	
		
			
				|  |  | +        List<TMonitoringRetrievalPlan> tempPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if(ObjectUtil.isNotEmpty(existSubPlanlist))
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            // 查询当前计划的具体执行机构
 | 
	
		
			
				|  |  | +            List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", publishPlan.getId()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<Long> planExecOrgIds = planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            // 根据机构类型和具体调阅机构 获取需创建子计划的机构
 | 
	
		
			
				|  |  | +            List<SysOrg> subPlanOrglist = getPlanOrgListByOrgTypeAndExecOrgs(planExecOrgIds, Integer.parseInt(publishPlan.getOrgType()), publishPlanOrg.getPath());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<SysOrg> execOrglist = new ArrayList<>();
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +                execOrglist = RemoteCallHandlerExecutor.executeRemoteCall(() ->
 | 
	
		
			
				|  |  | +                                remoteOrgService.selectOrgByIdList(planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList()), SecurityConstants.INNER),
 | 
	
		
			
				|  |  | +                        ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<TMonitoringRetrievalPlan> needSaveSubPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +            List<TMonitoringRetrievalPlanToExecOrg> needAddSubPlanExecOrgList = new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 找出历史子计划 在新的需要创建计划列表中不存在的删除掉
 | 
	
		
			
				|  |  | +            List<TMonitoringRetrievalPlan> needDeletedHistorySubPlan = existSubPlanlist.stream().filter(x -> !subPlanOrglist.stream().anyMatch(y -> ObjectUtil.equal(y.getId(), x.getOrgId()))).collect(toList());
 | 
	
		
			
				|  |  | +            if(ObjectUtil.isNotEmpty(needDeletedHistorySubPlan))
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                needDeletedHistorySubPlan.forEach(x->x.setIsDeleted(1L));
 | 
	
		
			
				|  |  | +                this.saveOrUpdateBatch(needDeletedHistorySubPlan);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            for (SysOrg subPlanOrg : subPlanOrglist) {
 | 
	
		
			
				|  |  | +                Optional<TMonitoringRetrievalPlan> historySubPlanOpt = existSubPlanlist.stream().filter(x -> x.getOrgId().equals(subPlanOrg.getId())).findFirst();
 | 
	
		
			
				|  |  | +                // 该机构下存在历史子计划
 | 
	
		
			
				|  |  | +                if(historySubPlanOpt.isPresent())
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    TMonitoringRetrievalPlan historySubPlan=historySubPlanOpt.get();
 | 
	
		
			
				|  |  | +                    historySubPlan.setIsDistribute("1");
 | 
	
		
			
				|  |  | +                    historySubPlan.setCreateType(1);
 | 
	
		
			
				|  |  | +                    historySubPlan.setPlanStatus(1);
 | 
	
		
			
				|  |  | +                    needSaveSubPlans.add(historySubPlan);
 | 
	
		
			
				|  |  | +                    // 删除历史计划的具体执行机构
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", historySubPlan.getId()));
 | 
	
		
			
				|  |  | +                    // 新增新的具体执行机构
 | 
	
		
			
				|  |  | +                    if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +                        execOrglist.stream().filter(x -> x.getPath().contains(subPlanOrg.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | +                            TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | +                            tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | +                            tempExecOrg.setPlanId(historySubPlan.getId());
 | 
	
		
			
				|  |  | +                            needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | +                        });
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                else {
 | 
	
		
			
				|  |  | +                    TMonitoringRetrievalPlan tMonitoringRetrievalPlan1 = new TMonitoringRetrievalPlan();
 | 
	
		
			
				|  |  | +                    BeanUtils.copyProperties(publishPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setId(IdWorker.getId());
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setOrgId(subPlanOrg.getId());
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setOrganization(subPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setOrgPath(subPlanOrg.getPath());
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setParentId(publishPlan.getId());
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setIsDistribute("1");
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setCreateType(1);
 | 
	
		
			
				|  |  | +                    tMonitoringRetrievalPlan1.setOrgName(publishPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +                    needSaveSubPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +                    if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +                        execOrglist.stream().filter(x -> x.getPath().contains(subPlanOrg.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | +                            TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | +                            tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | +                            tempExecOrg.setPlanId(tMonitoringRetrievalPlan1.getId());
 | 
	
		
			
				|  |  | +                            needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | +                        });
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //保存子计划和子计划具体执行机构
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotEmpty(needSaveSubPlans)) {
 | 
	
		
			
				|  |  | +                this.saveOrUpdateBatch(needSaveSubPlans);
 | 
	
		
			
				|  |  | +                itMonitoringRetrievalPlanToExecOrgService.saveBatch(needAddSubPlanExecOrgList);
 | 
	
		
			
				|  |  | +                needSaveSubPlans.stream().forEach(plan -> {
 | 
	
		
			
				|  |  | +                    setPlanStartEndTime(plan, plan);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                tempPlans.addAll(needSaveSubPlans);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        else // 不存在历史子计划,直接全新创建
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +          return buildSubPlans(publishPlan,publishPlanOrg);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return  tempPlans;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private List<TMonitoringRetrievalPlan> buildSubPlans(TMonitoringRetrievalPlan publishPlan,SysOrg publishPlanOrg) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<TMonitoringRetrievalPlan> tempPlans = new ArrayList<>();
 | 
	
		
			
				|  |  | +        // 查询当前计划的具体执行机构
 | 
	
		
			
				|  |  | +        List<TMonitoringRetrievalPlanToExecOrg> planExecOrgList = tMonitoringRetrievalPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", publishPlan.getId()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<Long> planExecOrgIds = planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          // 根据机构类型和具体调阅机构 获取需创建子计划的机构
 | 
	
		
			
				|  |  | -        List<SysOrg> hsOrglist = getPlanOrgListByOrgTypeAndExecOrgs(parentPlanExecOrgIds, 3, parentPlanOrg.getPath());
 | 
	
		
			
				|  |  | +        List<SysOrg> subPlanOrglist = getPlanOrgListByOrgTypeAndExecOrgs(planExecOrgIds, Integer.parseInt(publishPlan.getOrgType()), publishPlanOrg.getPath());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<SysOrg> execOrglist = new ArrayList<>();
 | 
	
		
			
				|  |  | -        if (ObjectUtil.isNotEmpty(parentPlanExecOrgIds)) {
 | 
	
		
			
				|  |  | +        if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  |              execOrglist = RemoteCallHandlerExecutor.executeRemoteCall(() ->
 | 
	
		
			
				|  |  | -                            remoteOrgService.selectOrgByIdList(parentPlanExecOrgIds, SecurityConstants.INNER),
 | 
	
		
			
				|  |  | +                            remoteOrgService.selectOrgByIdList(planExecOrgList.stream().map(x -> x.getOrgId()).collect(Collectors.toList()), SecurityConstants.INNER),
 | 
	
		
			
				|  |  |                      ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<TMonitoringRetrievalPlan> needAddSubPlans = new ArrayList<>();
 | 
	
		
			
				|  |  |          List<TMonitoringRetrievalPlanToExecOrg> needAddSubPlanExecOrgList = new ArrayList<>();
 | 
	
		
			
				|  |  | -        for (SysOrg l : hsOrglist) {
 | 
	
		
			
				|  |  | +        for (SysOrg subPlanOrg : subPlanOrglist) {
 | 
	
		
			
				|  |  |              TMonitoringRetrievalPlan tMonitoringRetrievalPlan1 = new TMonitoringRetrievalPlan();
 | 
	
		
			
				|  |  | -            BeanUtils.copyProperties(parentPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -            //创建机构是顶级的
 | 
	
		
			
				|  |  | -            tMonitoringRetrievalPlan1.setOrgId(l.getId());
 | 
	
		
			
				|  |  | -            tMonitoringRetrievalPlan1.setOrganization(l.getShortName());
 | 
	
		
			
				|  |  | -            tMonitoringRetrievalPlan1.setOrgPath(l.getPath());
 | 
	
		
			
				|  |  | -            tMonitoringRetrievalPlan1.setParentId(parentPlan.getId());
 | 
	
		
			
				|  |  | +            BeanUtils.copyProperties(publishPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setId(IdWorker.getId());
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setOrgId(subPlanOrg.getId());
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setOrganization(subPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setOrgPath(subPlanOrg.getPath());
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setParentId(publishPlan.getId());
 | 
	
		
			
				|  |  |              tMonitoringRetrievalPlan1.setIsDistribute("1");
 | 
	
		
			
				|  |  |              tMonitoringRetrievalPlan1.setCreateType(1);
 | 
	
		
			
				|  |  | -            if (!parentPlan.getOrgType().equals("3")) {
 | 
	
		
			
				|  |  |  //                        SysOrg sysOrg = remoteOrgService.selectSysOrgById(publishPlan.getOrgId(), SecurityConstants.INNER);
 | 
	
		
			
				|  |  | -                tMonitoringRetrievalPlan1.setOrgName(parentPlanOrg.getShortName());
 | 
	
		
			
				|  |  | +            tMonitoringRetrievalPlan1.setOrgName(publishPlanOrg.getShortName());
 | 
	
		
			
				|  |  |  //                        insertTMonitoringRetrievalPlan(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                needAddSubPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                if (ObjectUtil.isNotEmpty(parentPlanExecOrgIds)) {
 | 
	
		
			
				|  |  | -                    execOrglist.stream().filter(x -> x.getPath().contains(l.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | -                        TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | -                        tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | -                        tempExecOrg.setPlanId(tMonitoringRetrievalPlan1.getId());
 | 
	
		
			
				|  |  | -                        needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | -                    });
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            if (parentPlan.getOrgType().equals("3")) {
 | 
	
		
			
				|  |  | -                parentPlan.setCreateType(1);
 | 
	
		
			
				|  |  | -                parentPlan.setUpdateBy(SecurityUtils.getUsername());
 | 
	
		
			
				|  |  | -                parentPlan.setUpdateTime(DateUtils.getNowDate());
 | 
	
		
			
				|  |  | -                baseMapper.updateById(parentPlan);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                setPlanStartEndTime(parentPlan, tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -                subPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                List<SysOrg> sysOrgs = getExecOrgList(parentPlanExecOrgIds, Integer.valueOf(parentPlan.getOrgType()), l.getPath());
 | 
	
		
			
				|  |  | -                for (SysOrg s : sysOrgs) {
 | 
	
		
			
				|  |  | -                    TMonitoringRetrievalPlan plan = createTempPlan(parentPlan, tMonitoringRetrievalPlan1.getId(), s);
 | 
	
		
			
				|  |  | -                    subPlans.add(plan);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +            needAddSubPlans.add(tMonitoringRetrievalPlan1);
 | 
	
		
			
				|  |  | +            if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | +                execOrglist.stream().filter(x -> x.getPath().contains(subPlanOrg.getPath())).forEach(x -> {
 | 
	
		
			
				|  |  | +                    TMonitoringRetrievalPlanToExecOrg tempExecOrg = new TMonitoringRetrievalPlanToExecOrg();
 | 
	
		
			
				|  |  | +                    tempExecOrg.setOrgId(x.getId());
 | 
	
		
			
				|  |  | +                    tempExecOrg.setPlanId(tMonitoringRetrievalPlan1.getId());
 | 
	
		
			
				|  |  | +                    needAddSubPlanExecOrgList.add(tempExecOrg);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return subPlans;
 | 
	
		
			
				|  |  | +        //保存子计划和子计划具体执行机构
 | 
	
		
			
				|  |  | +        if (ObjectUtil.isNotEmpty(needAddSubPlans)) {
 | 
	
		
			
				|  |  | +            this.saveBatch(needAddSubPlans);
 | 
	
		
			
				|  |  | +            itMonitoringRetrievalPlanToExecOrgService.saveBatch(needAddSubPlanExecOrgList);
 | 
	
		
			
				|  |  | +            needAddSubPlans.stream().forEach(plan -> {
 | 
	
		
			
				|  |  | +                setPlanStartEndTime(plan, plan);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            tempPlans.addAll(needAddSubPlans);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +       return tempPlans;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private List<TMonitoringRetrievalPlanToExecOrg> buildPlanExecOrgs(List<TMonitoringRetrievalPlan> plans, List<SysOrg> execOrglist) {
 | 
	
	
		
			
				|  | @@ -1415,8 +1478,13 @@ public class TMonitoringRetrievalPlanServiceImpl extends ServiceImpl<TMonitoring
 | 
	
		
			
				|  |  |                      return result;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            // 停用状态 肯定存在已完成的任务, 只能修改任务名称
 | 
	
		
			
				|  |  | +            // 停用状态 肯定存在已完成的任务, 只能修改任务名称 和具体机构
 | 
	
		
			
				|  |  |              else if (oldPlan.getPlanStatus() == 2) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // 保存具体机构
 | 
	
		
			
				|  |  | +                tMonitoringRetrievalPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", oldPlan.getId()));
 | 
	
		
			
				|  |  | +                batchSavePlanToExecOrg(tMonitoringRetrievalPlanDto.getPlanExecOrgIdList(), oldPlan.getId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  tMonitoringRetrievalPlanMapper.updateById(oldPlan);
 | 
	
		
			
				|  |  |                  QueryWrapper queryWrapper = new QueryWrapper();
 | 
	
		
			
				|  |  |                  queryWrapper.eq(PARENT_ID, oldPlan.getId());
 |