|  | @@ -8,6 +8,7 @@ import cn.hutool.core.util.ObjectUtil;
 | 
	
		
			
				|  |  |  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.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;
 | 
	
	
		
			
				|  | @@ -25,10 +26,13 @@ import com.xunmei.common.core.domain.drill.vo.CoreDrillPlanDataVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.drill.vo.CoreDrillPlanDetailVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.drill.vo.CoreDrillPlanPageVo;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.domain.drill.vo.CoreDrillPlanRoleVo;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlan;
 | 
	
		
			
				|  |  | +import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingTask;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.OrgTypeEnum;
 | 
	
		
			
				|  |  |  import com.xunmei.common.core.enums.drill.DrillDoStatus;
 | 
	
		
			
				|  |  |  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.SystemException;
 | 
	
	
		
			
				|  | @@ -50,6 +54,7 @@ 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.apache.ibatis.annotations.Param;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Qualifier;
 | 
	
	
		
			
				|  | @@ -160,6 +165,9 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |          /*final List<CoreDrillPlanToRole> planToRoles = coreDrillPlanToRoleMapper.selectByMap(MapUtil.of("plan_id", id));
 | 
	
		
			
				|  |  |          final List<Long> execRoleIdList = planToRoles.stream().map(CoreDrillPlanToRole::getRoleId).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          vo.setPlanRoleId(ObjectUtil.isEmpty(execRoleIdList) ? null : execRoleIdList);*/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Integer done = coreDrillTaskMapper.checkHasTaskIsDoneByPlanIdOrParentId(plan.getId());
 | 
	
		
			
				|  |  | +        vo.setDone(done);
 | 
	
		
			
				|  |  |          return vo;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -545,19 +553,21 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public void deleteCoreDrillPlanByIds(Long id) {
 | 
	
		
			
				|  |  | -        CoreDrillPlan plan = getById(id);
 | 
	
		
			
				|  |  | -        if (EduTrainingPlanStatus.DRAFT.getCode() == plan.getPlanStatus()) {
 | 
	
		
			
				|  |  | -            removeById(id);
 | 
	
		
			
				|  |  | -            coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(Arrays.asList(id), null, null);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        final Integer done = coreDrillTaskMapper.checkHasTaskIsDoneByPlanParentId(id);
 | 
	
		
			
				|  |  | -        if (done != null && done > 0) {
 | 
	
		
			
				|  |  | -            throw new RuntimeException("计划有已完成或者已逾期的任务,不能被删除");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  |          List<Long> list = baseMapper.selectIdByParentId(id);
 | 
	
		
			
				|  |  | +        Integer isExecute = coreDrillTaskMapper.selectCount(new LambdaQueryWrapper<CoreDrillTask>()
 | 
	
		
			
				|  |  | +                        .in(CoreDrillTask::getPlanId, list)
 | 
	
		
			
				|  |  | +                        .eq(CoreDrillTask::getStatus, DrillDoStatus.DONE.getCode()))
 | 
	
		
			
				|  |  | +                .intValue();
 | 
	
		
			
				|  |  |          list.add(id);
 | 
	
		
			
				|  |  | -        coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, null, null);
 | 
	
		
			
				|  |  | -        removeByIds(list);
 | 
	
		
			
				|  |  | +        if (ObjectUtil.notEqual(isExecute, 1)) {
 | 
	
		
			
				|  |  | +            // 计划下没有已完成:删除所有任务,计划数据做物理删除。
 | 
	
		
			
				|  |  | +            coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, null, null);
 | 
	
		
			
				|  |  | +            coreDrillPlanMapper.delByIds(list);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //计划下有已完成:删除本轮次及以后的所有任务,计划本身做逻辑删除。
 | 
	
		
			
				|  |  | +            coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, new Date(), null);
 | 
	
		
			
				|  |  | +            removeByIds(list);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -583,7 +593,7 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public void publishPlan(Long planId) {
 | 
	
		
			
				|  |  | +    public void publishPlan(Long planId, Integer status) {
 | 
	
		
			
				|  |  |          final CoreDrillPlan plan = coreDrillPlanMapper.selectById(planId);
 | 
	
		
			
				|  |  |          if (plan == null) {
 | 
	
		
			
				|  |  |              throw new SystemException("计划不存在!");
 | 
	
	
		
			
				|  | @@ -594,11 +604,9 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |          List<CoreDrillPlan> planList = lambdaQuery()
 | 
	
		
			
				|  |  |                  .eq(CoreDrillPlan::getParentId, planId)
 | 
	
		
			
				|  |  |                  .select(CoreDrillPlan::getId).list();
 | 
	
		
			
				|  |  | -        boolean isPublishAgain = false;
 | 
	
		
			
				|  |  |          if (planList.isEmpty()) {
 | 
	
		
			
				|  |  |              planList = buildPlanData(plan, new ArrayList<>(), true);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  | -            isPublishAgain = true;
 | 
	
		
			
				|  |  |              planList.forEach(plan1 -> plan1.setPlanStatus(EduTrainingPlanStatus.USING.getCode()));
 | 
	
		
			
				|  |  |              List<Long> collect = planList.stream().map(CoreDrillPlan::getId).collect(Collectors.toList());
 | 
	
		
			
				|  |  |              coreDrillPlanMapper.updatePlanStatusByIdList(collect, EduTrainingPlanStatus.USING.getCode());
 | 
	
	
		
			
				|  | @@ -607,8 +615,10 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |          plan.setPlanStatus(DrillPlanStatus.USING.getCode());
 | 
	
		
			
				|  |  |          plan.setIssue(1);
 | 
	
		
			
				|  |  |          this.updateById(plan);
 | 
	
		
			
				|  |  | -        if (isPublishAgain) {
 | 
	
		
			
				|  |  | -            //说明是计划是二次下发,下个周期生效,此处临时set为0,不保存入库,
 | 
	
		
			
				|  |  | +        if (ObjectUtil.equal(status, 1)) {
 | 
	
		
			
				|  |  | +            //status=1:立即生效  status=0:下周期生效
 | 
	
		
			
				|  |  | +            plan.setBuildTaskNow(1);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  |              plan.setBuildTaskNow(0);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //事务提交后执行
 | 
	
	
		
			
				|  | @@ -644,22 +654,31 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public int revocationPlan(Long planId) {
 | 
	
		
			
				|  |  | -        CoreDrillPlan plan = getById(planId);
 | 
	
		
			
				|  |  | -        plan.setIssue(0);
 | 
	
		
			
				|  |  | -        plan.setPlanStatus(EduTrainingPlanStatus.DELETED.getCode());
 | 
	
		
			
				|  |  |          List<Long> list = coreDrillPlanMapper.selectIdByParentId(planId);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        //无周期计划撤回,不管任务状态,删除所有任务,撤回后计划停用
 | 
	
		
			
				|  |  | -        //有周期计划撤回,如果没有任务已完成,删除所有任务,撤回后计划停用
 | 
	
		
			
				|  |  |          Integer isExecute = coreDrillTaskMapper.selectCount(new LambdaQueryWrapper<CoreDrillTask>()
 | 
	
		
			
				|  |  |                          .in(CoreDrillTask::getPlanId, list)
 | 
	
		
			
				|  |  |                          .eq(CoreDrillTask::getStatus, DrillDoStatus.DONE.getCode()))
 | 
	
		
			
				|  |  |                  .intValue();
 | 
	
		
			
				|  |  | -        if (ObjectUtil.equal(isExecute, 0) || EduTrainingPlanCycleEnum.NONE.getCode().equals(plan.getPlanCycle())) {
 | 
	
		
			
				|  |  | +        //计划下没有已完成:删除所有任务数据和子计划,计划状态回到草稿状态。
 | 
	
		
			
				|  |  | +        if (ObjectUtil.notEqual(isExecute, 1)/* || EduTrainingPlanCycleEnum.NONE.getCode().equals(plan.getPlanCycle())*/) {
 | 
	
		
			
				|  |  | +            // 删除所有任务数据
 | 
	
		
			
				|  |  |              coreDrillTaskService.delByStartTimeAndEndTimeAndPlanIdList(list, null, null);
 | 
	
		
			
				|  |  | +            //删除所有子计划
 | 
	
		
			
				|  |  | +            coreDrillPlanMapper.delByIds(list);
 | 
	
		
			
				|  |  | +            //计划状态回到草稿状态
 | 
	
		
			
				|  |  | +            update(new LambdaUpdateWrapper<CoreDrillPlan>()
 | 
	
		
			
				|  |  | +                    .eq(CoreDrillPlan::getId, planId)
 | 
	
		
			
				|  |  | +                    .set(CoreDrillPlan::getIssue, 0)
 | 
	
		
			
				|  |  | +                    .set(CoreDrillPlan::getPlanStatus, DrillPlanStatus.DRAFT.getCode()));
 | 
	
		
			
				|  |  | +            return 1;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            //计划下有已完成:不删任务,计划状态回到停用。
 | 
	
		
			
				|  |  | +            coreDrillPlanMapper.updatePlanStatusByIdOrParentId(planId, EduTrainingPlanStatus.DELETED.getCode());
 | 
	
		
			
				|  |  | +            CoreDrillPlan plan = getById(planId);
 | 
	
		
			
				|  |  | +            plan.setIssue(0);
 | 
	
		
			
				|  |  | +            return coreDrillPlanMapper.updateById(plan);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        coreDrillPlanMapper.updatePlanStatusByIdOrParentId(planId, EduTrainingPlanStatus.DELETED.getCode());
 | 
	
		
			
				|  |  | -        return coreDrillPlanMapper.updateById(plan);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -715,7 +734,7 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
 | 
	
		
			
				|  |  |          final SysOrgVO planCreateOrg = all.stream().filter(org -> org.getId().equals(plan.getCreateOrgId())).findFirst().get();
 | 
	
		
			
				|  |  |          final long count = all.stream()
 | 
	
		
			
				|  |  |                  .filter(org -> ObjectUtil.isNotEmpty(org.getPath()))
 | 
	
		
			
				|  |  | -                .filter(org -> ObjectUtil.notEqual(org.getId(),plan.getCreateOrgId()))
 | 
	
		
			
				|  |  | +                .filter(org -> ObjectUtil.notEqual(org.getId(), plan.getCreateOrgId()))
 | 
	
		
			
				|  |  |                  .filter(org -> org.getPath().startsWith(planCreateOrg.getPath()))
 | 
	
		
			
				|  |  |                  .filter(org -> OrgTypeEnum.HANG_SHE.getCode().equals(org.getType()))
 | 
	
		
			
				|  |  |                  .count();
 |