|  | @@ -3,6 +3,8 @@ package com.xunmei.core.edu.service.impl;
 | 
	
		
			
				|  |  |  import cn.hutool.core.collection.CollectionUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.map.MapUtil;
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  | +import cn.hutool.json.JSONUtil;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson2.JSON;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 | 
	
	
		
			
				|  | @@ -21,7 +23,9 @@ import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanDetailVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanPageVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanRoleVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.exception.SystemException;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.util.BeanHelper;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.utils.DateUtils;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.vo.IdNameVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.web.page.TableDataInfo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.security.utils.SecurityUtils;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.mapper.CoreEduTrainingPlanMapper;
 | 
	
	
		
			
				|  | @@ -32,7 +36,9 @@ import com.xunmei.core.edu.service.ICoreEduTrainingPlanService;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.service.ICoreEduTrainingPlanToExecOrgService;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.service.ICoreEduTrainingPlanToRoleService;
 | 
	
		
			
				|  |  |  import com.xunmei.core.edu.service.ICoreEduTrainingTaskService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.Eto.RoleConditionEto;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.RemoteOrgService;
 | 
	
		
			
				|  |  | +import com.xunmei.system.api.RemoteRoleService;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.domain.SysOrg;
 | 
	
		
			
				|  |  |  import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
	
		
			
				|  | @@ -43,10 +49,7 @@ import org.springframework.transaction.annotation.Propagation;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.util.Assert;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import java.util.ArrayList;
 | 
	
		
			
				|  |  | -import java.util.Arrays;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -74,6 +77,8 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |      private CoreEduTrainingTaskMapper coreEduTrainingTaskMapper;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private RemoteOrgService orgService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private RemoteRoleService remoteRoleService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public TableDataInfo selectPage(CoreEduTrainingPlanPageDto request) {
 | 
	
	
		
			
				|  | @@ -86,17 +91,12 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          //获取数据
 | 
	
		
			
				|  |  |          Page<CoreEduTrainingPlanPageVo> page = coreEduTrainingPlanMapper.selectPageData(request.getPage(), request);
 | 
	
		
			
				|  |  |          SysOrg sysOrg = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectTopOrg(SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | -        for (CoreEduTrainingPlanPageVo record : page.getRecords()) {
 | 
	
		
			
				|  |  | -            record.setNo(page.getRecords().indexOf(record) + 1);
 | 
	
		
			
				|  |  | -            if (ObjectUtil.equal(record.getCreateOrgId(), sysOrg.getId())) {
 | 
	
		
			
				|  |  | -                record.setCreateByTopOrg(1);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            String roleNameList = coreEduTrainingPlanToRoleMapper.selectRoleNameByPlanId(record.getId()).stream().map(CoreEduTrainingPlanRoleVo::getRoleName).collect(Collectors.joining(","));
 | 
	
		
			
				|  |  | -            record.setPlanRoleNameList(roleNameList);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        List<CoreEduTrainingPlanPageVo> records = page.getRecords();
 | 
	
		
			
				|  |  | +        for (CoreEduTrainingPlanPageVo record : records) {
 | 
	
		
			
				|  |  | +            dealData(record, records, sysOrg.getId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //抓换为TableDataInfo适配前端
 | 
	
		
			
				|  |  | -        TableDataInfo tableDataInfo = new TableDataInfo();
 | 
	
		
			
				|  |  | +        TableDataInfo<CoreEduTrainingPlanPageVo> tableDataInfo = new TableDataInfo();
 | 
	
		
			
				|  |  |          tableDataInfo.setMsg("操作成功");
 | 
	
		
			
				|  |  |          tableDataInfo.setCode(200);
 | 
	
		
			
				|  |  |          tableDataInfo.setTotal(page.getTotal());
 | 
	
	
		
			
				|  | @@ -106,6 +106,32 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void dealData(CoreEduTrainingPlanPageVo record, List<CoreEduTrainingPlanPageVo> records, Long orgId) {
 | 
	
		
			
				|  |  | +        record.setNo(records.indexOf(record) + 1);
 | 
	
		
			
				|  |  | +        if (ObjectUtil.equal(record.getCreateOrgId(), orgId)) {
 | 
	
		
			
				|  |  | +            record.setCreateByTopOrg(1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        String roleNameList = coreEduTrainingPlanToRoleMapper.selectRoleNameByPlanId(record.getId()).stream().map(CoreEduTrainingPlanRoleVo::getRoleName).collect(Collectors.joining(","));
 | 
	
		
			
				|  |  | +        record.setPlanRoleNameList(roleNameList);
 | 
	
		
			
				|  |  | +        List<CoreEduTrainingPlan> planList = coreEduTrainingPlanMapper.selectList(new LambdaQueryWrapper<CoreEduTrainingPlan>().eq(CoreEduTrainingPlan::getParentId, record.getId()));
 | 
	
		
			
				|  |  | +        List<CoreEduTrainingPlanPageVo> children = BeanHelper.copyProperties(planList, CoreEduTrainingPlanPageVo.class);
 | 
	
		
			
				|  |  | +        final List<Long> collect = children.stream().map(CoreEduTrainingPlanPageVo::getUpdateBy).map(Long::valueOf).distinct().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        final List<IdNameVo> idNameVos = RemoteCallHandlerExecutor.executeRemoteCall(() -> remoteRoleService.getNames(new RoleConditionEto(collect)), ErrorMsgConstants.QUERY_ROLE_DATA_ERROR);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //将idNameVos使用steam转为map
 | 
	
		
			
				|  |  | +        final Map<Long, String> idNameMap = idNameVos.stream().collect(Collectors.toMap(IdNameVo::getId, IdNameVo::getName));
 | 
	
		
			
				|  |  | +        record.setChildren(children);
 | 
	
		
			
				|  |  | +        record.setHasChildren(ObjectUtil.isNotEmpty(children));
 | 
	
		
			
				|  |  | +        for (CoreEduTrainingPlanPageVo child : children) {
 | 
	
		
			
				|  |  | +            if (ObjectUtil.equal(child.getCreateOrgId(), orgId)) {
 | 
	
		
			
				|  |  | +                child.setCreateByTopOrg(1);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            final String name = idNameMap.get(Long.valueOf(child.getUpdateBy()));
 | 
	
		
			
				|  |  | +            child.setUpdateBy(name);
 | 
	
		
			
				|  |  | +            child.setPlanRoleNameList(roleNameList);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 查询教育培训计划
 | 
	
	
		
			
				|  | @@ -118,6 +144,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          final CoreEduTrainingPlan plan = coreEduTrainingPlanMapper.selectById(id);
 | 
	
		
			
				|  |  |          CoreEduTrainingPlanDetailVo vo = new CoreEduTrainingPlanDetailVo();
 | 
	
		
			
				|  |  |          BeanUtils.copyProperties(plan, vo);
 | 
	
		
			
				|  |  | +        vo.setFileList(ObjectUtil.isNotEmpty(plan.getFileList()) ? JSON.parseArray(plan.getFileList(), String.class) : null);
 | 
	
		
			
				|  |  |          final List<CoreEduTrainingPlanToExecOrg> execOrgList = coreEduTrainingPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", id));
 | 
	
		
			
				|  |  |          final List<Long> execOrgIdList = execOrgList.stream().map(CoreEduTrainingPlanToExecOrg::getOrgId).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          vo.setPlanExecOrgIdList(ObjectUtil.isEmpty(execOrgIdList) ? null : execOrgIdList);
 | 
	
	
		
			
				|  | @@ -150,6 +177,9 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          if (ObjectUtil.isAllEmpty(request.getExecOrgType(), request.getPlanExecOrgIdList())) {
 | 
	
		
			
				|  |  |              throw new RuntimeException("培训机构类型和执行机构不能同时为空!");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        if (ObjectUtil.equal(request.getPlanCycle(), 0) && ObjectUtil.hasEmpty(request.getStartDate(), request.getEndDate())) {
 | 
	
		
			
				|  |  | +            throw new RuntimeException("当计划为无周期的时候,请填入开始时间和结束时间!");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          CoreEduTrainingPlan plan = new CoreEduTrainingPlan();
 | 
	
		
			
				|  |  |          BeanUtils.copyProperties(request, plan);
 | 
	
		
			
				|  |  |          plan.setId(IdWorker.getId());
 | 
	
	
		
			
				|  | @@ -167,6 +197,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          plan.setBelongOrgId(orgId);
 | 
	
		
			
				|  |  |          plan.setBelongOrgName(r.getName());
 | 
	
		
			
				|  |  |          plan.setBelongOrgPath(r.getPath());
 | 
	
		
			
				|  |  | +        plan.setFileList(ObjectUtil.isNotEmpty(request.getFileList()) ? JSON.toJSONString(request.getFileList()) : null);
 | 
	
		
			
				|  |  |          batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
 | 
	
		
			
				|  |  |          batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
 | 
	
		
			
				|  |  |          //省联社或者办事处创建的计划才存在下发
 | 
	
	
		
			
				|  | @@ -301,12 +332,10 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
 | 
	
		
			
				|  |  |          List<CoreEduTrainingPlanToExecOrg> execOrg = coreEduTrainingPlanToExecOrgMapper.selectList(eos);
 | 
	
		
			
				|  |  |          if (ObjectUtil.isNotEmpty(execOrg)) {
 | 
	
		
			
				|  |  |              final List<Long> list = execOrg.stream().map(CoreEduTrainingPlanToExecOrg::getOrgId).collect(Collectors.toList());
 | 
	
		
			
				|  |  | -            orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgByIdList(list, SecurityConstants.INNER), "未能查找到具体的培训机构,请联系管理员!");
 | 
	
		
			
				|  |  | +            orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgByIdList(list, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  |              return orgList;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        Assert.notNull(execOrgType, "未能查找到具体的培训机构,请联系管理员!");
 | 
	
		
			
				|  |  |          orgList = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectByOrgType(execOrgType, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
 | 
	
		
			
				|  |  | -        Assert.notEmpty(orgList, "无法根据培训机构类型找到具体机构,请修改计划内容!");
 | 
	
		
			
				|  |  |          return orgList;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |