|
|
@@ -12,12 +12,16 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
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.google.common.collect.Sets;
|
|
|
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.*;
|
|
|
+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.dto.CoreEduTrainingPlanEditDto;
|
|
|
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanInsertDto;
|
|
|
import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanPageDto;
|
|
|
@@ -27,10 +31,12 @@ import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanPageVo;
|
|
|
import com.xunmei.common.core.domain.edu.vo.CoreEduTrainingPlanRoleVo;
|
|
|
import com.xunmei.common.core.enums.OrgTypeEnum;
|
|
|
import com.xunmei.common.core.enums.drill.DrillPlanCycleEnum;
|
|
|
+import com.xunmei.common.core.enums.drill.DrillPlanStatus;
|
|
|
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.exception.ServiceException;
|
|
|
+import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
import com.xunmei.common.core.util.BeanHelper;
|
|
|
import com.xunmei.common.core.utils.AssertUtil;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
@@ -39,13 +45,15 @@ import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.core.compense.dto.CompensateDto;
|
|
|
import com.xunmei.core.compense.interfaces.CompensateService;
|
|
|
-import com.xunmei.core.edu.mapper.*;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingPlanMapper;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingPlanToExecOrgMapper;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingPlanToRoleMapper;
|
|
|
+import com.xunmei.core.edu.mapper.CoreEduTrainingTaskMapper;
|
|
|
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.core.registerbook.service.ICoreRegisterBookPdfService;
|
|
|
-import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.enums.BusinessPlanType;
|
|
|
@@ -69,6 +77,8 @@ import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import static java.util.stream.Collectors.toList;
|
|
|
+
|
|
|
/**
|
|
|
* 教育培训计划Service业务层处理
|
|
|
*
|
|
|
@@ -963,10 +973,145 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
@Override
|
|
|
public void compensate(CompensateDto compensateDto) {
|
|
|
|
|
|
+ CoreEduTrainingPlan eduTrainingPlan = getById(compensateDto.getPlanId());
|
|
|
+
|
|
|
+ if (ObjectUtil.isNull(eduTrainingPlan)) {
|
|
|
+ throw new ServiceException("计划不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(eduTrainingPlan.getPlanStatus(), DrillPlanStatus.USING.getCode())) {
|
|
|
+ throw new ServiceException("计划尚未下发或已停用");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.equal(eduTrainingPlan.getDeleted(), 1)) {
|
|
|
+ throw new ServiceException("计划状态异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysOrgVO> orgCacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+ //推断计划
|
|
|
+ deducePlanAndBuildTask(eduTrainingPlan, compensateDto.getOrgIdList(), orgCacheList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Set<OrgTypeEnum> INVALID_ORG_TYPES = Sets.newHashSet(OrgTypeEnum.SHEGN_LIAN_SHE, OrgTypeEnum.BAN_SHI_CHU, OrgTypeEnum.DIQU_HANG_SHE);
|
|
|
+ private void deducePlanAndBuildTask(CoreEduTrainingPlan trainingPlan, List<Long> orgIdList, List<SysOrgVO> orgCacheList) {
|
|
|
+ List<SysOrgVO> orgList = orgCacheList.stream().filter(org -> orgIdList.contains(org.getId())).collect(toList());
|
|
|
+ if (orgList.isEmpty()) {
|
|
|
+ throw new ServiceException("未查询到orgIdList中指定的机构信息");
|
|
|
+ }
|
|
|
+ List<Long> idList = orgList.stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ List<Integer> typeList = orgList.stream().map(SysOrgVO::getType).distinct().collect(toList());
|
|
|
+ if (typeList.size() > 1) {
|
|
|
+ throw new ServiceException("orgIdList中指定的机构信息存在多种机构类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgTypeEnum orgTypeEnum = OrgTypeEnum.getOrgTypeEnum(typeList.get(0));
|
|
|
+
|
|
|
+ // 省联社创建的计划
|
|
|
+ if (checkIsParentPlan(trainingPlan.getId())) {
|
|
|
+ List<CoreEduTrainingPlan> allHsPlanList = getHsPlanList(trainingPlan);
|
|
|
+ if (ObjectUtil.isEmpty(allHsPlanList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = getHsOrg(orgCacheList, orgList, orgTypeEnum);
|
|
|
+ List<Long> hsPlanIdList = allHsPlanList.stream().map(CoreEduTrainingPlan::getId).collect(toList());
|
|
|
+ List<Long> hsOrgIdList = ((List<SysOrgVO>) map.get("list")).stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ if (ObjectUtil.hasEmpty(hsPlanIdList, hsOrgIdList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<CoreEduTrainingPlan> reallyPlanIdList = findReallyPlanIdList(hsPlanIdList, hsOrgIdList);
|
|
|
+ boolean underHsOrgType = (boolean) map.get("underHsOrgType");
|
|
|
+ for (CoreEduTrainingPlan plan : reallyPlanIdList) {
|
|
|
+ create(plan, underHsOrgType ? idList : null, threadPoolTaskExecutor);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 行社自建计划
|
|
|
+ if (INVALID_ORG_TYPES.contains(orgTypeEnum)) {
|
|
|
+ throw new ServiceException("orgIdList中传递机构信息错误!与计划信息不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OrgTypeEnum.HANG_SHE.equals(orgTypeEnum)) {
|
|
|
+ create(trainingPlan, null, threadPoolTaskExecutor);
|
|
|
+ } else {
|
|
|
+ //其实这里如果真是传入了行社以下的机构,那么大概率这里的reallyPlanIdList 计划id也只会有一个元素
|
|
|
+ create(trainingPlan, idList, threadPoolTaskExecutor);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ private void create(CoreEduTrainingPlan plan, List<Long> idList, ThreadPoolTaskExecutor executor) {
|
|
|
+ Long planId = plan.getId();
|
|
|
+ Date planStartDate = plan.getStartDate();
|
|
|
+ Date planEndDate = plan.getEndDate();
|
|
|
+
|
|
|
+ executor.execute(() -> {
|
|
|
+ CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(planId);
|
|
|
+ coreEduTrainingTaskService.createTaskForNow(detailPlanData, planStartDate, planEndDate, idList);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CoreEduTrainingPlan> findReallyPlanIdList(List<Long> planIdList, List<Long> orgIdList) {
|
|
|
|
|
|
+ LambdaQueryWrapper<CoreEduTrainingPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(CoreEduTrainingPlan::getId, planIdList);
|
|
|
+ wrapper.in(CoreEduTrainingPlan::getBelongOrgId, orgIdList);
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkIsParentPlan(Long planId) {
|
|
|
+ //演练与培训的 行社下发的计划 id=parentId
|
|
|
+ LambdaQueryWrapper<CoreEduTrainingPlan> countWrapper = new LambdaQueryWrapper<>();
|
|
|
+ countWrapper.eq(CoreEduTrainingPlan::getParentId, planId);
|
|
|
+ countWrapper.ne(CoreEduTrainingPlan::getId, planId);
|
|
|
+ Long l = baseMapper.selectCount(countWrapper);
|
|
|
+ return ObjectUtil.isNotNull(l) && l.compareTo(0L) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<CoreEduTrainingPlan> getHsPlanList(CoreEduTrainingPlan drillPlan) {
|
|
|
+ LambdaQueryWrapper<CoreEduTrainingPlan> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CoreEduTrainingPlan::getPlanStatus, DrillPlanStatus.USING.getCode());
|
|
|
+ wrapper.eq(CoreEduTrainingPlan::getDeleted, 0);
|
|
|
+ wrapper.eq(CoreEduTrainingPlan::getParentId, drillPlan.getId());
|
|
|
+ return baseMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getHsOrg(List<SysOrgVO> orgCacheList, List<SysOrgVO> needBuildTaskOrgList, OrgTypeEnum needBuildTaskOrgTypeEnum) {
|
|
|
+ List<SysOrgVO> list = new ArrayList<>();
|
|
|
+ boolean underHsOrgType = false;
|
|
|
+ switch (needBuildTaskOrgTypeEnum) {
|
|
|
+ //如果是省联社/办事处/地区行社 那么找到下级的行社
|
|
|
+ case SHEGN_LIAN_SHE:
|
|
|
+ case BAN_SHI_CHU:
|
|
|
+ case DIQU_HANG_SHE:
|
|
|
+ for (SysOrgVO sysOrgVO : needBuildTaskOrgList) {
|
|
|
+ String path = sysOrgVO.getPath();
|
|
|
+ List<SysOrgVO> collect = orgCacheList
|
|
|
+ .stream()
|
|
|
+ .filter(org -> ObjectUtil.isAllNotEmpty(org.getPath(), org.getType()))
|
|
|
+ .filter(org -> org.getPath().contains(path))
|
|
|
+ .filter(org -> org.getType().equals(OrgTypeEnum.HANG_SHE.getCode()))
|
|
|
+ .collect(toList());
|
|
|
+ list.addAll(collect);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case HANG_SHE: //如果传进来的就是行社 那么直接返回
|
|
|
+ list = needBuildTaskOrgList;
|
|
|
+ break;
|
|
|
+ default: //如果是行社以下机构类型,那么找到上级的行社机构返回
|
|
|
+ List<Long> ids = needBuildTaskOrgList.stream().map(SysOrgVO::getId).collect(toList());
|
|
|
+ List<SysOrg> sysOrgs = orgService.selectParentHs(ids, SecurityConstants.INNER);
|
|
|
+ list = BeanHelper.copyProperties(sysOrgs, SysOrgVO.class);
|
|
|
+ underHsOrgType = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("list", list);
|
|
|
+ map.put("underHsOrgType", underHsOrgType);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
@Override
|
|
|
public void run(Runnable runnable, ThreadPoolTaskExecutor threadPoolTaskExecutor) {
|
|
|
-
|
|
|
+ CompletableFuture.runAsync(runnable, threadPoolTaskExecutor);
|
|
|
}
|
|
|
}
|