|
|
@@ -1,33 +1,31 @@
|
|
|
package com.xunmei.core.drill.service.impl;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.xunmei.common.core.constant.ErrorMsgConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
-import com.xunmei.common.core.domain.drill.domain.CoreDrillPlanToExecOrg;
|
|
|
-import com.xunmei.common.core.domain.drill.domain.CoreDrillPlanToRole;
|
|
|
+import com.xunmei.common.core.domain.IdName;
|
|
|
+import com.xunmei.common.core.domain.drill.domain.*;
|
|
|
+import com.xunmei.common.core.domain.drill.dto.CoreDrillPlanInsertDto;
|
|
|
import com.xunmei.common.core.domain.drill.dto.CoreDrillPlanPageDto;
|
|
|
import com.xunmei.common.core.domain.drill.dto.CoreDrillPlanUpdateDto;
|
|
|
+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.CoreEduTrainingPlanToExecOrg;
|
|
|
-import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlanToRole;
|
|
|
-import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanEditDto;
|
|
|
-import com.xunmei.common.core.domain.edu.dto.CoreEduTrainingPlanPageDto;
|
|
|
-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.utils.DateUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
-import com.xunmei.core.drill.mapper.CoreDrillPlanToExecOrgMapper;
|
|
|
-import com.xunmei.core.drill.mapper.CoreDrillPlanToRoleMapper;
|
|
|
+import com.xunmei.core.drill.mapper.*;
|
|
|
import com.xunmei.core.drill.service.ICoreDrillPlanToExecOrgService;
|
|
|
import com.xunmei.core.drill.service.ICoreDrillPlanToRoleService;
|
|
|
+import com.xunmei.core.drill.service.ICoreDrillTaskService;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.function.RemoteCallHandlerExecutor;
|
|
|
@@ -35,17 +33,18 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
-import com.xunmei.core.drill.mapper.CoreDrillPlanMapper;
|
|
|
-import com.xunmei.common.core.domain.drill.domain.CoreDrillPlan;
|
|
|
import com.xunmei.core.drill.service.ICoreDrillPlanService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
|
|
+import org.springframework.transaction.support.TransactionSynchronizationManager;
|
|
|
|
|
|
/**
|
|
|
* 预案演练计划Service业务层处理
|
|
|
@@ -66,6 +65,14 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
@Autowired
|
|
|
private CoreDrillPlanToExecOrgMapper coreDrillPlanToExecOrgMapper;
|
|
|
@Autowired
|
|
|
+ private ICoreDrillTaskService coreDrillTaskService;
|
|
|
+ @Autowired
|
|
|
+ private CoreDrillTaskMapper coreDrillTaskMapper;
|
|
|
+ @Autowired
|
|
|
+ private CoreDrillTaskToRoleMapper coreDrillTaskToRoleMapper;
|
|
|
+ @Autowired
|
|
|
+ private CoreDrillTaskToUserMapper coreDrillTaskToUserMapper;
|
|
|
+ @Autowired
|
|
|
private RemoteOrgService orgService;
|
|
|
|
|
|
@Override
|
|
|
@@ -101,6 +108,10 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
}
|
|
|
child.setPlanRoleNameList(roleNameList);
|
|
|
}
|
|
|
+ if (record.getStandard() == 1) {
|
|
|
+ final Integer done = coreDrillTaskMapper.checkHasTaskIsDoneByPlanParentId(record.getId());
|
|
|
+ record.setDone(done);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,8 +121,18 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
* @return 预案演练计划
|
|
|
*/
|
|
|
@Override
|
|
|
- public CoreDrillPlan selectCoreDrillPlanById(Long id) {
|
|
|
- return coreDrillPlanMapper.selectById(id);
|
|
|
+ public CoreDrillPlanDetailVo selectCoreDrillPlanById(Long id) {
|
|
|
+ final CoreDrillPlan plan = coreDrillPlanMapper.selectById(id);
|
|
|
+ CoreDrillPlanDetailVo vo = new CoreDrillPlanDetailVo();
|
|
|
+ BeanUtils.copyProperties(plan, vo);
|
|
|
+ vo.setFileList(ObjectUtil.isNotEmpty(plan.getFileList()) ? JSON.parseArray(plan.getFileList(), String.class) : null);
|
|
|
+ final List<CoreDrillPlanToExecOrg> execOrgList = coreDrillPlanToExecOrgMapper.selectByMap(MapUtil.of("plan_id", id));
|
|
|
+ final List<Long> execOrgIdList = execOrgList.stream().map(CoreDrillPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ vo.setPlanExecOrgIdList(ObjectUtil.isEmpty(execOrgIdList) ? null : execOrgIdList);
|
|
|
+ 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);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -128,22 +149,77 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
/**
|
|
|
* 新增预案演练计划
|
|
|
*
|
|
|
- * @param coreDrillPlan 预案演练计划
|
|
|
+ * @param request 预案演练计划
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertCoreDrillPlan(CoreDrillPlan coreDrillPlan) {
|
|
|
- coreDrillPlan.setCreateTime(DateUtils.getNowDate());
|
|
|
- return coreDrillPlanMapper.insert(coreDrillPlan);
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int insertCoreDrillPlan(CoreDrillPlanInsertDto request) {
|
|
|
+ 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("当计划为无周期的时候,请填入开始时间和结束时间!");
|
|
|
+ }
|
|
|
+ Long count = coreDrillPlanMapper.selectCount(new LambdaQueryWrapper<CoreDrillPlan>()
|
|
|
+ .eq(CoreDrillPlan::getPlanName, request.getPlanName())
|
|
|
+ .eq(CoreDrillPlan::getDeleted, 0));
|
|
|
+ if (null != count && count > 0) {
|
|
|
+ throw new RuntimeException("计划名称已存在!");
|
|
|
+ }
|
|
|
+ CoreDrillPlan plan = new CoreDrillPlan();
|
|
|
+ BeanUtils.copyProperties(request, plan);
|
|
|
+ plan.setId(IdWorker.getId());
|
|
|
+ plan.setCreateTime(new Date());
|
|
|
+ plan.setUpdateTime(new Date());
|
|
|
+ plan.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ plan.setUpdateBy(SecurityUtils.getUserId().toString());
|
|
|
+ plan.setBuildTaskNow(Boolean.TRUE.equals(request.getBuildTaskNow()) ? 1 : 0);
|
|
|
+ final Long orgId = SecurityUtils.getLoginUser().getSysUser().getOrgId();
|
|
|
+ SysOrg r = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgById(orgId, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ SysOrg org = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.getSysOrgByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ plan.setCreateOrgId(orgId);
|
|
|
+ plan.setCreateOrgName(r.getName());
|
|
|
+ plan.setCreateOrgPath(r.getPath());
|
|
|
+ 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());
|
|
|
+ //省联社或者办事处创建的计划才存在下发
|
|
|
+ if (checkOrgType(org.getType())) {
|
|
|
+ plan.setStandard(1);
|
|
|
+ plan.setIssue(0);
|
|
|
+ }
|
|
|
+ plan.setBeIssue(0);
|
|
|
+ int insert = coreDrillPlanMapper.insert(plan);
|
|
|
+
|
|
|
+ //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
|
|
|
+ if ((!checkOrgType(org.getType())) && ObjectUtil.equal(0, plan.getPlanStatus()) && (ObjectUtil.equal(0, plan.getPlanCycle()) || ObjectUtil.equal(1, plan.getBuildTaskNow()))) {
|
|
|
+ final CoreDrillPlanDataVo detailPlanData = this.getCoreDrillPlanDataVo(plan.getId());
|
|
|
+ coreDrillTaskService.createTaskForNow(detailPlanData, plan.getPlanStartDate(), plan.getPlanEndDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ return insert;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean checkOrgType(Integer orgType) {
|
|
|
+ if (ObjectUtil.isEmpty(orgType)) {
|
|
|
+ throw new RuntimeException("当前用户所在机构类型无法确认!");
|
|
|
+ }
|
|
|
+ //如果是省联社或者办事处则返回1,其他机构类型返回0
|
|
|
+ return ObjectUtil.equal(orgType, 1) || ObjectUtil.equal(orgType, 2);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改预案演练计划
|
|
|
*
|
|
|
- * @param coreDrillPlan 预案演练计划
|
|
|
+ * @param request 预案演练计划
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public int updateCoreDrillPlan(CoreDrillPlanUpdateDto request) {
|
|
|
final CoreDrillPlan plan = getById(request.getId());
|
|
|
//此处判断能否修改,如果可以 需要删除任务,且还需要判断是否需要生成任务
|
|
|
@@ -158,21 +234,76 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
plan.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
coreDrillPlanToRoleMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
coreDrillPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
- List<CoreDrillPlanToRole> trainingPlanToRoleList = batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
|
|
|
- List<CoreDrillPlanToExecOrg> trainingPlanToExecOrgList = batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
|
|
|
+ List<CoreDrillPlanToRole> coreDrillPlanToRoleList = batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
|
|
|
+ List<CoreDrillPlanToExecOrg> drillPlanToExecOrgList = batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
|
|
|
final int i = coreDrillPlanMapper.updateById(plan);
|
|
|
if (plan.getStandard() == 1) {
|
|
|
//如果标准计划可以修改,那么需要删除所有计划与任务,重新创建计划任务
|
|
|
- // updateStandardPlan(plan, trainingPlanToRoleList, trainingPlanToExecOrgList);
|
|
|
+ updateStandardPlan(plan, coreDrillPlanToRoleList);
|
|
|
} else {
|
|
|
//普通计划
|
|
|
- // updateCommonPlan(plan);
|
|
|
+ updateCommonPlan(plan);
|
|
|
}
|
|
|
|
|
|
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
+ private void updateStandardPlan(CoreDrillPlan plan, List<CoreDrillPlanToRole> drillPlanToRoleList) {
|
|
|
+ //没下发的就不管
|
|
|
+ if (0 == plan.getIssue()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long planId = plan.getId();
|
|
|
+ //删除原有数据, 然后重新生成计划,任务
|
|
|
+ List<Long> planIdList = coreDrillPlanMapper.selectIdByParentId(planId);
|
|
|
+ if (ObjectUtil.isNotEmpty(planIdList)) {
|
|
|
+ coreDrillPlanMapper.deleteBatchIds(planIdList);
|
|
|
+ coreDrillPlanToExecOrgMapper.delete(new LambdaQueryWrapper<CoreDrillPlanToExecOrg>().in(CoreDrillPlanToExecOrg::getPlanId, planIdList));
|
|
|
+ coreDrillPlanToRoleMapper.delete(new LambdaQueryWrapper<CoreDrillPlanToRole>().in(CoreDrillPlanToRole::getPlanId, planIdList));
|
|
|
+ }
|
|
|
+ List<CoreDrillTask> taskIdList = coreDrillTaskMapper.selectList(new LambdaQueryWrapper<CoreDrillTask>().in(CoreDrillTask::getPlanId, planIdList).select(CoreDrillTask::getId));
|
|
|
+ List<Long> collect = taskIdList.stream().map(CoreDrillTask::getId).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(collect)) {
|
|
|
+ coreDrillTaskMapper.deleteBatchIds(collect);
|
|
|
+ coreDrillTaskToRoleMapper.delete(new LambdaQueryWrapper<CoreDrillTaskToRole>().in(CoreDrillTaskToRole::getDrillTaskId, collect));
|
|
|
+
|
|
|
+ }
|
|
|
+ List<CoreDrillPlan> planList = buildPlanData(plan, drillPlanToRoleList);
|
|
|
+
|
|
|
+ for (CoreDrillPlan drillPlan : planList) {
|
|
|
+ final CoreDrillPlanDataVo dataVo = getCoreDrillPlanDataVo(drillPlan.getId());
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //说明有任务并且都没执行过,需要重新生成任务
|
|
|
+ coreDrillTaskService.createTaskForNow(dataVo, plan.getPlanStartDate(), plan.getPlanEndDate());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateCommonPlan(CoreDrillPlan plan) {
|
|
|
+ /*
|
|
|
+ 判断能否修改: 如果上面返回了true; 说明两种情况
|
|
|
+ 1:计划生成了任务,但是未执行: 此时需要删除所有任务,修改计划数据后重新创建任务
|
|
|
+ 2:计划生成了任务且执行了,但是没有修改到关键信息,此时则不能删除任务,只允许修改计划信息
|
|
|
+
|
|
|
+ */
|
|
|
+ final Integer done = coreDrillTaskMapper.checkHasTaskIsDone(Arrays.asList(plan.getId()));
|
|
|
+ if (ObjectUtil.equal(1, done)) {
|
|
|
+ //此为情况二, 计划生成了任务且执行 不能删除任务,只允许修改计划信息,所以直接返回
|
|
|
+ //TODO 考虑是否同步修改已生成的任务的名称
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //此为情况一,计划没有生成任务或者生成了任务但未执行
|
|
|
+ final CoreDrillPlanDataVo dataVo = getCoreDrillPlanDataVo(plan.getId());
|
|
|
+ if (ObjectUtil.equal(1, plan.getBuildTaskNow()) && ObjectUtil.equal(0, plan.getPlanStatus())) {
|
|
|
+ coreDrillTaskMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //说明有任务并且都没执行过,需要重新生成任务
|
|
|
+ coreDrillTaskService.createTaskForNow(dataVo, plan.getPlanStartDate(), plan.getPlanEndDate());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private Boolean checkCanUpdate(CoreDrillPlanUpdateDto request, CoreDrillPlan plan) {
|
|
|
if (ObjectUtil.isAllEmpty(request.getExecOrgType(), request.getPlanExecOrgIdList())) {
|
|
|
throw new RuntimeException("培训机构类型和执行机构不能同时为空!");
|
|
|
@@ -185,11 +316,9 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
boolean flag = true;
|
|
|
//判断计划是否有任务已经执行过
|
|
|
// TODO
|
|
|
- //final Integer done = coreEduTrainingTaskMapper.checkHasTaskIsDone(Arrays.asList(planId));
|
|
|
- final Integer done = 1;
|
|
|
+ final Integer done = coreDrillTaskMapper.checkHasTaskIsDone(Arrays.asList(planId));
|
|
|
//判断标准计划能否修改:存在下发的计划生成了任务且任务存在已执行
|
|
|
- Integer standardPlanHasDone = 1;
|
|
|
- //Integer standardPlanHasDone = coreEduTrainingTaskMapper.checkHasTaskIsDoneByPlanParentId(planId);
|
|
|
+ Integer standardPlanHasDone = coreDrillTaskMapper.checkHasTaskIsDoneByPlanParentId(planId);
|
|
|
if (standardPlanHasDone != null) {
|
|
|
throw new RuntimeException("该计划下存在任务已执行的情况,无法修改!");
|
|
|
}
|
|
|
@@ -261,12 +390,52 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
/**
|
|
|
* 批量删除预案演练计划
|
|
|
*
|
|
|
- * @param ids 需要删除的预案演练计划主键
|
|
|
+ * @param id 需要删除的预案演练计划主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteCoreDrillPlanByIds(Long[] ids) {
|
|
|
- return coreDrillPlanMapper.deleteBatchIds(Arrays.asList((ids)));
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int deleteCoreDrillPlanByIds(Long id) {
|
|
|
+ Integer count = coreDrillTaskMapper.checkHasTaskIsDone(Collections.singletonList(id));
|
|
|
+ if (count != null && count > 0) {
|
|
|
+ throw new RuntimeException("已有任务完成,无法删除");
|
|
|
+ }
|
|
|
+ final Integer done = coreDrillTaskMapper.checkHasTaskIsDoneByPlanParentId(id);
|
|
|
+ if (done != null && done > 0) {
|
|
|
+ throw new RuntimeException("已有任务完成,无法删除");
|
|
|
+ }
|
|
|
+ final CoreDrillPlan plan = getById(id);
|
|
|
+ if (plan.getStandard() == 0) {
|
|
|
+ //自建计划
|
|
|
+ final List<CoreDrillTask> drillTaskList = coreDrillTaskMapper.selectList(new LambdaQueryWrapper<CoreDrillTask>()
|
|
|
+ .eq(CoreDrillTask::getPlanId, id)
|
|
|
+ .select(CoreDrillTask::getId));
|
|
|
+ final List<Long> taskIdList = drillTaskList.stream().map(CoreDrillTask::getId).collect(Collectors.toList());
|
|
|
+ //删除任务相关
|
|
|
+ if (ObjectUtil.isNotEmpty(taskIdList)) {
|
|
|
+ coreDrillTaskMapper.deleteBatchIds(taskIdList);
|
|
|
+ coreDrillTaskToRoleMapper.delete(new LambdaQueryWrapper<CoreDrillTaskToRole>().in(CoreDrillTaskToRole::getDrillTaskId, taskIdList));
|
|
|
+ }
|
|
|
+ //删除计划
|
|
|
+ return coreDrillPlanMapper.deleteBatchIds(Collections.singletonList((id)));
|
|
|
+ } else {
|
|
|
+ //标准计划
|
|
|
+ List<Long> planIdList = coreDrillPlanMapper.selectIdByParentId(id);
|
|
|
+ if (ObjectUtil.isNotEmpty(planIdList)) {
|
|
|
+ //删除任务相关
|
|
|
+ final List<CoreDrillTask> drillTaskList = coreDrillTaskMapper.selectList(new LambdaQueryWrapper<CoreDrillTask>()
|
|
|
+ .in(CoreDrillTask::getPlanId, planIdList)
|
|
|
+ .select(CoreDrillTask::getId));
|
|
|
+ final List<Long> taskIdList = drillTaskList.stream().map(CoreDrillTask::getId).collect(Collectors.toList());
|
|
|
+ if (ObjectUtil.isNotEmpty(taskIdList)) {
|
|
|
+ coreDrillTaskMapper.deleteBatchIds(taskIdList);
|
|
|
+ coreDrillTaskToRoleMapper.delete(new LambdaQueryWrapper<CoreDrillTaskToRole>().in(CoreDrillTaskToRole::getDrillTaskId, taskIdList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除计划
|
|
|
+ planIdList.add(id);
|
|
|
+ return coreDrillPlanMapper.deleteBatchIds(planIdList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -279,4 +448,181 @@ public class CoreDrillPlanServiceImpl extends ServiceImpl<CoreDrillPlanMapper, C
|
|
|
public int deleteCoreDrillPlanById(Long id) {
|
|
|
return coreDrillPlanMapper.deleteById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CoreDrillPlanRoleVo> listPlanRole(Long orgId) {
|
|
|
+ if (orgId == null) {
|
|
|
+ SysOrg r = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectTopOrg(SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ orgId = r.getId();
|
|
|
+ }
|
|
|
+ return coreDrillPlanMapper.selectPlanRole(orgId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void publishPlan(Long planId) {
|
|
|
+ final CoreDrillPlan plan = coreDrillPlanMapper.selectById(planId);
|
|
|
+ if (plan == null) {
|
|
|
+ throw new SystemException("计划不存在!");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equal(plan.getIssue(), 1)) {
|
|
|
+ throw new SystemException("计划已完成发布!");
|
|
|
+ }
|
|
|
+ // 下发 按钮显示逻辑:仅省联社安全保卫管理人员进入且由省联社管理安全保卫人员创建的计划才显示
|
|
|
+ //todo 判断当前人的角色信息
|
|
|
+ List<CoreDrillPlan> list = buildPlanData(plan, new ArrayList<>());
|
|
|
+
|
|
|
+ plan.setIssue(1);
|
|
|
+ this.updateById(plan);
|
|
|
+ //事务提交后执行
|
|
|
+ TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
|
|
+ @Override
|
|
|
+ public void afterCommit() {
|
|
|
+ for (CoreDrillPlan drillPlan : list) {
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
|
|
|
+ if ((ObjectUtil.equal(0, plan.getPlanStatus()) && (ObjectUtil.equal(0, plan.getPlanCycle()) || ObjectUtil.equal(1, plan.getBuildTaskNow())))) {
|
|
|
+ final CoreDrillPlanDataVo detailPlanData = getCoreDrillPlanDataVo(drillPlan.getId());
|
|
|
+ coreDrillTaskService.createTaskForNow(detailPlanData, plan.getPlanStartDate(), plan.getPlanEndDate());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CoreDrillPlanDataVo getCoreDrillPlanDataVo(Long id) {
|
|
|
+ final CoreDrillPlanDataVo dataVo = coreDrillPlanMapper.getDetailPlanData(id);
|
|
|
+ dataVo.setFileList(ObjectUtil.isNotEmpty(dataVo.getFile()) ? JSON.parseArray(dataVo.getFile(), String.class) : null);
|
|
|
+ return dataVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<IdName<String, String>> planList(Long orgId) {
|
|
|
+ SysOrg org = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectOrgById(orgId, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ final Integer orgType = org.getType();
|
|
|
+ switch (orgType) {
|
|
|
+ case 1:
|
|
|
+ //省联社
|
|
|
+ final List<CoreDrillPlan> sLsPlanList = getPlanList(orgId, 1, 1);
|
|
|
+ return sLsPlanList.stream().map(x -> new IdName<>(x.getId().toString(), x.getPlanName())).collect(Collectors.toList());
|
|
|
+ case 2:
|
|
|
+ //办事处
|
|
|
+ SysOrg topOrg = RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectTopOrg(SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+ final List<CoreDrillPlan> lsPlanList = getPlanList(topOrg.getId(), 1, 1);
|
|
|
+ final List<CoreDrillPlan> bscPlanList = getPlanList(orgId, 1, 1);
|
|
|
+ return Stream.of(lsPlanList, bscPlanList).flatMap(Collection::stream).map(x -> new IdName<>(x.getId().toString(), x.getPlanName())).collect(Collectors.toList());
|
|
|
+ case 3:
|
|
|
+ //行社
|
|
|
+ final List<CoreDrillPlan> hsPlanList = getPlanList(orgId, 0, 0);
|
|
|
+ return hsPlanList.stream().map(x -> new IdName<>(x.getId().toString(), x.getPlanName())).collect(Collectors.toList());
|
|
|
+ default:
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CoreDrillPlan> getPlanList(Long orgId, Integer standard, Integer issue) {
|
|
|
+ return coreDrillPlanMapper.selectList(new LambdaQueryWrapper<CoreDrillPlan>()
|
|
|
+ .eq(CoreDrillPlan::getBelongOrgId, orgId)
|
|
|
+ .eq(CoreDrillPlan::getStandard, standard)
|
|
|
+ .eq(CoreDrillPlan::getIssue, issue)
|
|
|
+ .eq(CoreDrillPlan::getDeleted, 0)
|
|
|
+ .eq(CoreDrillPlan::getPlanStatus, 0)
|
|
|
+ .select(CoreDrillPlan::getId, CoreDrillPlan::getPlanName)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CoreDrillPlan> buildPlanData(CoreDrillPlan plan, List<CoreDrillPlanToRole> planRoleList) {
|
|
|
+ if (ObjectUtil.isEmpty(planRoleList)) {
|
|
|
+ //获取执行角色
|
|
|
+ LambdaQueryWrapper<CoreDrillPlanToRole> ros = new LambdaQueryWrapper<>();
|
|
|
+ ros.eq(CoreDrillPlanToRole::getPlanId, plan.getId());
|
|
|
+ planRoleList = coreDrillPlanToRoleMapper.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("未能查询到行社数据!");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CoreDrillPlanToExecOrg> planToExecOrgs = new ArrayList<>();
|
|
|
+ List<CoreDrillPlan> list = new ArrayList<>();
|
|
|
+ for (SysOrg sysOrg : publishOrgList) {
|
|
|
+ CoreDrillPlan drillPlan = new CoreDrillPlan();
|
|
|
+ BeanUtils.copyProperties(plan, drillPlan);
|
|
|
+ drillPlan.setId(IdWorker.getId());
|
|
|
+ drillPlan.setBelongOrgId(sysOrg.getId());
|
|
|
+ drillPlan.setBelongOrgName(sysOrg.getName());
|
|
|
+ drillPlan.setBelongOrgPath(sysOrg.getPath());
|
|
|
+ drillPlan.setStandard(0);
|
|
|
+ drillPlan.setIssue(0);
|
|
|
+ drillPlan.setParentId(plan.getId());
|
|
|
+ drillPlan.setCreateTime(new Date());
|
|
|
+ drillPlan.setUpdateTime(new Date());
|
|
|
+ list.add(drillPlan);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(planExecOrgList)) {
|
|
|
+ planExecOrgList.stream().filter(x -> x.getPath().contains(sysOrg.getPath())).forEach(y -> {
|
|
|
+ CoreDrillPlanToExecOrg temp = new CoreDrillPlanToExecOrg();
|
|
|
+ temp.setPlanId(drillPlan.getId());
|
|
|
+ temp.setOrgId(y.getId());
|
|
|
+ planToExecOrgs.add(temp);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (planToExecOrgs.size() > 0) {
|
|
|
+ coreDrillPlanToExecOrgService.saveBatch(planToExecOrgs);
|
|
|
+ }
|
|
|
+ List<CoreDrillPlanToRole> insertPlanRoleList = new ArrayList<>();
|
|
|
+ for (CoreDrillPlan drillPlan : list) {
|
|
|
+ //保存执行角色
|
|
|
+ for (CoreDrillPlanToRole planRole : planRoleList) {
|
|
|
+ CoreDrillPlanToRole role = new CoreDrillPlanToRole();
|
|
|
+ role.setPlanId(drillPlan.getId());
|
|
|
+ role.setRoleId(planRole.getRoleId());
|
|
|
+ insertPlanRoleList.add(role);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (list.size() > 0) {
|
|
|
+ this.saveBatch(list);
|
|
|
+ }
|
|
|
+ if (insertPlanRoleList.size() > 0) {
|
|
|
+ coreDrillPlanToRoleService.saveBatch(insertPlanRoleList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SysOrg> getPlanExecOrg(CoreDrillPlan plan) {
|
|
|
+ QueryWrapper<CoreDrillPlanToExecOrg> eos = new QueryWrapper<>();
|
|
|
+ eos.lambda().eq(CoreDrillPlanToExecOrg::getPlanId, plan.getId());
|
|
|
+ final List<CoreDrillPlanToExecOrg> coreDrillPlanToExecOrgList = coreDrillPlanToExecOrgMapper.selectList(eos);
|
|
|
+ if (ObjectUtil.isNotEmpty(coreDrillPlanToExecOrgList)) {
|
|
|
+
|
|
|
+ final List<Long> list = coreDrillPlanToExecOrgList.stream().map(CoreDrillPlanToExecOrg::getOrgId).collect(Collectors.toList());
|
|
|
+ return RemoteCallHandlerExecutor.executeRemoteCall(() -> orgService.selectByOrgIdList(list, SecurityConstants.INNER), ErrorMsgConstants.QUERY_ORG_DATA_ERROR);
|
|
|
+
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SysOrg> getPlanPublishOrgList(CoreDrillPlan plan, List<Long> orgIdList) {
|
|
|
+ List<SysOrg> orgList;
|
|
|
+ //优先判断是否存在具体的执行机构,如果存在则直接返回,否则根据机构类型进行查询
|
|
|
+ if (ObjectUtil.isNotEmpty(orgIdList)) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|