|  | @@ -11,14 +11,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.constant.CacheConstants;
 | 
	
		
			
				|  |  |  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.IdName;
 | 
	
		
			
				|  |  | -import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlan;
 | 
	
		
			
				|  |  | -import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlanToExecOrg;
 | 
	
		
			
				|  |  | -import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlanToRole;
 | 
	
		
			
				|  |  | -import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingTask;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.edu.domain.*;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanEditDto;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanInsertDto;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanPageDto;
 | 
	
	
		
			
				|  | @@ -31,9 +29,11 @@ import com.xunmei.common.core.enums.drill.DrillPlanCycleEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.edu.EduTrainingDoStatus;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.edu.EduTrainingPlanCycleEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.edu.EduTrainingPlanStatus;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.util.BeanHelper;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.AssertUtil;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.DateUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.web.page.TableDataInfo;
 | 
	
		
			
				|  |  | +import com.xunmei.common.redis.utils.RedisUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.common.security.utils.SecurityUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.mapper.*;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.service.ICoreEduTrainingPlanService;
 | 
	
	
		
			
				|  | @@ -44,6 +44,7 @@ import com.xunmei.core.thread.ThreadPoolConfig;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.vo.SysOrgVO;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.ObjectUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
	
		
			
				|  | @@ -85,7 +86,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private CoreEduTrainingTaskMapper coreEduTrainingTaskMapper;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private CoreEduTrainingTaskToRoleMapper coreEduTrainingTaskToRoleMapper;
 | 
	
		
			
				|  |  | +    private CoreEduTrainingPlanToOrgTypeMapper coreEduTrainingPlanToOrgTypeMapper;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private RemoteOrgService orgService;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -221,14 +222,14 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          return coreEduTrainingPlanMapper.insert(plan);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public Boolean checkCanBuildTaskNow( CoreEduTrainingPlan plan) {
 | 
	
		
			
				|  |  | +    public Boolean checkCanBuildTaskNow(CoreEduTrainingPlan plan) {
 | 
	
		
			
				|  |  |          //使用中,如果不是使用中状态不能立即生成任务
 | 
	
		
			
				|  |  |          boolean statusFlag = ObjectUtil.equal(EduTrainingPlanStatus.USING.getCode(), plan.getPlanStatus());
 | 
	
		
			
				|  |  |          //无周期?有周期的不能立即生成任务
 | 
	
		
			
				|  |  |          boolean cycleFlag = ObjectUtil.equal(EduTrainingPlanCycleEnum.NONE.getCode(), plan.getPlanCycle());
 | 
	
		
			
				|  |  |          //是否需要立即生效 不是则不能立即生成任务
 | 
	
		
			
				|  |  |          boolean buildFlag = ObjectUtil.equal(1, plan.getBuildTaskNow());
 | 
	
		
			
				|  |  | -        return  statusFlag && (cycleFlag || buildFlag);
 | 
	
		
			
				|  |  | +        return statusFlag && (cycleFlag || buildFlag);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -314,7 +315,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |              public void afterCommit() {
 | 
	
		
			
				|  |  |                  CompletableFuture.runAsync(() -> {
 | 
	
		
			
				|  |  |                      //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
 | 
	
		
			
				|  |  | -                    if (checkCanBuildTaskNow( plan)) {
 | 
	
		
			
				|  |  | +                    if (checkCanBuildTaskNow(plan)) {
 | 
	
		
			
				|  |  |                          CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(plan.getId());
 | 
	
		
			
				|  |  |                          coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
 | 
	
		
			
				|  |  |                      }
 | 
	
	
		
			
				|  | @@ -375,7 +376,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |                      for (CoreEduTrainingPlan trainingPlan : finalPlanList) {
 | 
	
		
			
				|  |  |                          CompletableFuture.runAsync(() -> {
 | 
	
		
			
				|  |  |                              //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
 | 
	
		
			
				|  |  | -                            if (checkCanBuildTaskNow( plan)) {
 | 
	
		
			
				|  |  | +                            if (checkCanBuildTaskNow(plan)) {
 | 
	
		
			
				|  |  |                                  CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(trainingPlan.getId());
 | 
	
		
			
				|  |  |                                  coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
 | 
	
		
			
				|  |  |                              }
 | 
	
	
		
			
				|  | @@ -580,32 +581,25 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          return coreEduTrainingPlanMapper.selectPlanRole(orgId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public List<SysOrg> getPlanPublishOrgList(CoreEduTrainingPlan plan, List<Long> orgIdList) {
 | 
	
		
			
				|  |  | -        List<SysOrg> orgList;
 | 
	
		
			
				|  |  | -        //优先判断是否存在具体的执行机构,如果存在则直接返回,否则根据机构类型进行查询
 | 
	
		
			
				|  |  | -//        QueryWrapper<CoreEduTrainingPlanToExecOrg> eos = new QueryWrapper<>();
 | 
	
		
			
				|  |  | -//        eos.lambda().eq(CoreEduTrainingPlanToExecOrg::getPlanId, plan.getId());
 | 
	
		
			
				|  |  | -//        List<CoreEduTrainingPlanToExecOrg> execOrg = coreEduTrainingPlanToExecOrgMapper.selectList(eos);
 | 
	
		
			
				|  |  | -        if (ObjectUtil.isNotEmpty(orgIdList)) {
 | 
	
		
			
				|  |  | -//            final List<Long> list = planExecOrgList.stream().map(CoreEduTrainingPlanToExecOrg::getOrgId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectParentHs(orgIdList, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | -            return orgList;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectChildHs(plan.getCreateOrgId(), SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | -        return orgList;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private List<SysOrg> getPlanExecOrg(CoreEduTrainingPlan plan) {
 | 
	
		
			
				|  |  | +    private List<SysOrgVO> getPlanExecOrg(CoreEduTrainingPlan plan) {
 | 
	
		
			
				|  |  | +        List<SysOrgVO> all = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
 | 
	
		
			
				|  |  |          QueryWrapper<CoreEduTrainingPlanToExecOrg> eos = new QueryWrapper<>();
 | 
	
		
			
				|  |  |          eos.lambda().eq(CoreEduTrainingPlanToExecOrg::getPlanId, plan.getId());
 | 
	
		
			
				|  |  |          final List<CoreEduTrainingPlanToExecOrg> coreEduTrainingPlanToExecOrgs = coreEduTrainingPlanToExecOrgMapper.selectList(eos);
 | 
	
		
			
				|  |  |          if (ObjectUtil.isNotEmpty(coreEduTrainingPlanToExecOrgs)) {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |              final List<Long> list = coreEduTrainingPlanToExecOrgs.stream().map(CoreEduTrainingPlanToExecOrg::getOrgId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            return RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectByOrgIdList(list, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +            return all.stream().filter(org -> list.contains(org.getId())).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +           /* List<CoreEduTrainingPlanToOrgType> toOrgTypeList = coreEduTrainingPlanToOrgTypeMapper.selectList(new LambdaQueryWrapper<CoreEduTrainingPlanToOrgType>()
 | 
	
		
			
				|  |  | +                    .eq(CoreEduTrainingPlanToOrgType::getPlanId, plan.getId()));
 | 
	
		
			
				|  |  | +            List<Integer> collect = toOrgTypeList.stream().map(CoreEduTrainingPlanToOrgType::getOrgType).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            return all.stream().filter(org -> collect.contains(org.getType())).collect(Collectors.toList());*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return all.stream().filter(org->ObjectUtil.isNotNull(org.getType())).filter(org -> org.getType().equals(plan.getExecOrgType())).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return new ArrayList<>();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -642,7 +636,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |                  for (CoreEduTrainingPlan trainingPlan : finalPlanList) {
 | 
	
		
			
				|  |  |                      CompletableFuture.runAsync(() -> {
 | 
	
		
			
				|  |  |                          //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
 | 
	
		
			
				|  |  | -                        if (checkCanBuildTaskNow( plan)) {
 | 
	
		
			
				|  |  | +                        if (checkCanBuildTaskNow(plan)) {
 | 
	
		
			
				|  |  |                              CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(trainingPlan.getId());
 | 
	
		
			
				|  |  |                              coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
 | 
	
		
			
				|  |  |                          }
 | 
	
	
		
			
				|  | @@ -653,6 +647,22 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public List<SysOrgVO> getPlanPublishOrgList(List<SysOrgVO> list) {
 | 
	
		
			
				|  |  | +        //省联社/办事处/行社
 | 
	
		
			
				|  |  | +        List<SysOrgVO> collect = list.stream().filter(org -> checkOrgType(org.getType())).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        //行社以下的机构
 | 
	
		
			
				|  |  | +        List<SysOrgVO> collect1 = list.stream().filter(org -> !checkOrgType(org.getType())).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (ObjectUtil.isNotEmpty(collect1)) {
 | 
	
		
			
				|  |  | +            List<Long> orgIdList = collect1.stream().map(SysOrgVO::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            List<SysOrg> orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectParentHs(orgIdList, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | +            List<SysOrgVO> sysOrgVOS = BeanHelper.copyProperties(orgList, SysOrgVO.class);
 | 
	
		
			
				|  |  | +            return Stream.of(sysOrgVOS, collect).flatMap(Collection::stream).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return collect;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private List<CoreEduTrainingPlan> buildPlanData(CoreEduTrainingPlan plan, List<CoreEduTrainingPlanToRole> planRoleList, Boolean isPublish) {
 | 
	
		
			
				|  |  |          /*if (ObjectUtil.isEmpty(planRoleList)) {
 | 
	
		
			
				|  |  |              //获取执行角色
 | 
	
	
		
			
				|  | @@ -661,25 +671,11 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |              planRoleList = coreEduTrainingPlanToRoleMapper.selectList(ros);
 | 
	
		
			
				|  |  |          }*/
 | 
	
		
			
				|  |  |          //获取计划具体执行机构
 | 
	
		
			
				|  |  | -        final List<SysOrg> planExecOrgList = this.getPlanExecOrg(plan);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<Long> orgIds = null;
 | 
	
		
			
				|  |  | -        if (ObjectUtil.isNotEmpty(planExecOrgList)) {
 | 
	
		
			
				|  |  | -            orgIds = planExecOrgList.stream().map(SysOrg::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        //获取所有行社机构
 | 
	
		
			
				|  |  | -        List<SysOrg> publishOrgList = this.getPlanPublishOrgList(plan, orgIds);
 | 
	
		
			
				|  |  | -        if (ObjectUtil.isEmpty(publishOrgList)) {
 | 
	
		
			
				|  |  | -            throw new RuntimeException("未能查询到行社数据!");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (publishOrgList.get(0).getId().equals(plan.getBelongOrgId())) {
 | 
	
		
			
				|  |  | -            plan.setParentId(plan.getId());
 | 
	
		
			
				|  |  | -            return ListUtil.list(true, plan);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        final List<SysOrgVO> planExecOrgList = this.getPlanExecOrg(plan);
 | 
	
		
			
				|  |  | +        List<SysOrgVO> planPublishOrgList = getPlanPublishOrgList(planExecOrgList);
 | 
	
		
			
				|  |  |          List<CoreEduTrainingPlanToExecOrg> planToExecOrgs = new ArrayList<>();
 | 
	
		
			
				|  |  |          List<CoreEduTrainingPlan> list = new ArrayList<>();
 | 
	
		
			
				|  |  | -        for (SysOrg sysOrg : publishOrgList) {
 | 
	
		
			
				|  |  | +        for (SysOrgVO sysOrg : planPublishOrgList) {
 | 
	
		
			
				|  |  |              CoreEduTrainingPlan coreEduTrainingPlan = new CoreEduTrainingPlan();
 | 
	
		
			
				|  |  |              BeanUtils.copyProperties(plan, coreEduTrainingPlan);
 | 
	
		
			
				|  |  |              coreEduTrainingPlan.setId(IdWorker.getId());
 |