|
|
@@ -12,9 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.ErrorMsgConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
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.*;
|
|
|
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;
|
|
|
@@ -26,10 +24,7 @@ import com.xunmei.common.core.exception.SystemException;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
-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.mapper.*;
|
|
|
import com.xunmei.core.edu.service.ICoreEduTrainingPlanService;
|
|
|
import com.xunmei.core.edu.service.ICoreEduTrainingPlanToExecOrgService;
|
|
|
import com.xunmei.core.edu.service.ICoreEduTrainingPlanToRoleService;
|
|
|
@@ -75,12 +70,14 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
@Autowired
|
|
|
private CoreEduTrainingTaskMapper coreEduTrainingTaskMapper;
|
|
|
@Autowired
|
|
|
+ private CoreEduTrainingTaskToRoleMapper coreEduTrainingTaskToRoleMapper;
|
|
|
+ @Autowired
|
|
|
private RemoteOrgService orgService;
|
|
|
@Autowired
|
|
|
private RemoteRoleService remoteRoleService;
|
|
|
|
|
|
@Override
|
|
|
- public TableDataInfo selectPage(CoreEduTrainingPlanPageDto request) {
|
|
|
+ public TableDataInfo selectPage(CoreEduTrainingPlanPageDto request) throws InterruptedException {
|
|
|
|
|
|
//下穿
|
|
|
if (request.getCheckSub()) {
|
|
|
@@ -245,31 +242,65 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
plan.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
coreEduTrainingPlanToRoleMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
coreEduTrainingPlanToExecOrgMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
- batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
|
|
|
- batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
|
|
|
+ List<CoreEduTrainingPlanToRole> trainingPlanToRoleList = batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
|
|
|
+ List<CoreEduTrainingPlanToExecOrg> trainingPlanToExecOrgList = batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
|
|
|
final int i = coreEduTrainingPlanMapper.updateById(plan);
|
|
|
+ if (plan.getStandard() == 1) {
|
|
|
+ //如果标准计划可以修改,那么需要删除所有计划与任务,重新创建计划任务
|
|
|
+ updateStandardPlan(plan, trainingPlanToRoleList, trainingPlanToExecOrgList);
|
|
|
+ } else {
|
|
|
+ //普通计划
|
|
|
+ updateCommonPlan(plan);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateStandardPlan(CoreEduTrainingPlan plan, List<CoreEduTrainingPlanToRole> trainingPlanToRoleList, List<CoreEduTrainingPlanToExecOrg> trainingPlanToExecOrgList) {
|
|
|
+ Long planId = plan.getId();
|
|
|
+ //删除原有数据, 然后重新生成计划,任务
|
|
|
+ List<Long> planIdList = coreEduTrainingPlanMapper.selectIdByParentId(planId);
|
|
|
+ coreEduTrainingPlanMapper.deleteBatchIds(planIdList);
|
|
|
+ coreEduTrainingPlanToExecOrgMapper.delete(new LambdaQueryWrapper<CoreEduTrainingPlanToExecOrg>().in(CoreEduTrainingPlanToExecOrg::getPlanId, planIdList));
|
|
|
+ coreEduTrainingPlanToRoleMapper.delete(new LambdaQueryWrapper<CoreEduTrainingPlanToRole>().in(CoreEduTrainingPlanToRole::getPlanId, planIdList));
|
|
|
+ List<CoreEduTrainingTask> taskIdList = coreEduTrainingTaskMapper.selectList(new LambdaQueryWrapper<CoreEduTrainingTask>().in(CoreEduTrainingTask::getPlanId, planIdList).select(CoreEduTrainingTask::getId));
|
|
|
+ List<Long> collect = taskIdList.stream().map(CoreEduTrainingTask::getId).collect(Collectors.toList());
|
|
|
+ coreEduTrainingTaskMapper.deleteBatchIds(collect);
|
|
|
+ coreEduTrainingTaskToRoleMapper.delete(new LambdaQueryWrapper<CoreEduTrainingTaskToRole>().in(CoreEduTrainingTaskToRole::getEduTrainingTaskId, collect));
|
|
|
+ List<CoreEduTrainingPlan> planList = buildPlanData(plan, trainingPlanToRoleList);
|
|
|
+
|
|
|
+ for (CoreEduTrainingPlan trainingPlan : planList) {
|
|
|
+ CoreEduTrainingPlanDataVo dataVo = getCoreEduTrainingPlanDataVo(trainingPlan.getId());
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //说明有任务并且都没执行过,需要重新生成任务
|
|
|
+ coreEduTrainingTaskService.createTaskForNow(dataVo, plan.getStartDate(), plan.getEndDate());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateCommonPlan(CoreEduTrainingPlan plan) {
|
|
|
/*
|
|
|
- 判断能否修改: 如果上面返回了true; 说明两种情况
|
|
|
+ 判断能否修改: 如果上面返回了true; 说明两种情况
|
|
|
1:计划生成了任务,但是未执行: 此时需要删除所有任务,修改计划数据后重新创建任务
|
|
|
2:计划生成了任务且执行了,但是没有修改到关键信息,此时则不能删除任务,只允许修改计划信息
|
|
|
+
|
|
|
*/
|
|
|
final Integer done = coreEduTrainingTaskMapper.checkHasTaskIsDone(Arrays.asList(plan.getId()));
|
|
|
if (ObjectUtil.equal(1, done)) {
|
|
|
//此为情况二, 计划生成了任务且执行 不能删除任务,只允许修改计划信息,所以直接返回
|
|
|
//TODO 考虑是否同步修改已生成的任务的名称
|
|
|
- return i;
|
|
|
+ return;
|
|
|
}
|
|
|
- // final Integer hasTask = coreEduTrainingTaskMapper.checkHasTask(plan.getId());
|
|
|
//此为情况一,计划没有生成任务或者生成了任务但未执行
|
|
|
- final CoreEduTrainingPlanDataVo dataVo = getCoreEduTrainingPlanDataVo(request.getId());
|
|
|
+ final CoreEduTrainingPlanDataVo dataVo = getCoreEduTrainingPlanDataVo(plan.getId());
|
|
|
if (ObjectUtil.equal(1, plan.getBuildTaskNow()) && ObjectUtil.equal(0, plan.getPlanStatus())) {
|
|
|
- coreEduTrainingTaskMapper.deleteByMap(MapUtil.of("plan_id", request.getId()));
|
|
|
+ coreEduTrainingTaskMapper.deleteByMap(MapUtil.of("plan_id", plan.getId()));
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
//说明有任务并且都没执行过,需要重新生成任务
|
|
|
coreEduTrainingTaskService.createTaskForNow(dataVo, plan.getStartDate(), plan.getEndDate());
|
|
|
});
|
|
|
}
|
|
|
- return i;
|
|
|
}
|
|
|
|
|
|
private Boolean checkCanUpdate(CoreEduTrainingPlanEditDto request, CoreEduTrainingPlan plan) {
|
|
|
@@ -281,9 +312,14 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
throw new RuntimeException("执行次数不应低于基准次数!");
|
|
|
}
|
|
|
final Long planId = plan.getId();
|
|
|
+ boolean flag = true;
|
|
|
//判断计划是否有任务已经执行过
|
|
|
final Integer done = coreEduTrainingTaskMapper.checkHasTaskIsDone(Arrays.asList(planId));
|
|
|
- boolean flag = true;
|
|
|
+ //判断标准计划能否修改:存在下发的计划生成了任务且任务存在已执行
|
|
|
+ Integer standardPlanHasDone = coreEduTrainingTaskMapper.checkHasTaskIsDoneByPlanParentId(planId);
|
|
|
+ if (standardPlanHasDone != null) {
|
|
|
+ throw new RuntimeException("该计划下存在任务已执行的情况,无法修改!");
|
|
|
+ }
|
|
|
//计划周期
|
|
|
if (ObjectUtil.notEqual(request.getPlanCycle(), plan.getPlanCycle())) {
|
|
|
flag = false;
|
|
|
@@ -326,10 +362,10 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
return dataVo;
|
|
|
}
|
|
|
|
|
|
- public void batchSavePlanToRole(List<Long> roleIdList, Long planId) {
|
|
|
+ public List<CoreEduTrainingPlanToRole> batchSavePlanToRole(List<Long> roleIdList, Long planId) {
|
|
|
roleIdList.removeIf(Objects::isNull);
|
|
|
if (ObjectUtil.isEmpty(roleIdList)) {
|
|
|
- return;
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
List<CoreEduTrainingPlanToRole> planRoleList = new ArrayList<>();
|
|
|
for (Long roleId : roleIdList) {
|
|
|
@@ -341,12 +377,13 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
if (CollectionUtil.isNotEmpty(planRoleList)) {
|
|
|
coreEduTrainingPlanToRoleService.saveBatch(planRoleList);
|
|
|
}
|
|
|
+ return planRoleList;
|
|
|
}
|
|
|
|
|
|
- public void batchSavePlanToExecOrg(List<Long> orgIdList, Long planId) {
|
|
|
+ public List<CoreEduTrainingPlanToExecOrg> batchSavePlanToExecOrg(List<Long> orgIdList, Long planId) {
|
|
|
// orgIdList.removeIf(Objects::isNull);
|
|
|
if (ObjectUtil.isEmpty(orgIdList)) {
|
|
|
- return;
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
List<CoreEduTrainingPlanToExecOrg> planOrgList = new ArrayList<CoreEduTrainingPlanToExecOrg>();
|
|
|
for (Long orgId : orgIdList) {
|
|
|
@@ -355,7 +392,11 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
org.setPlanId(planId);
|
|
|
planOrgList.add(org);
|
|
|
}
|
|
|
- coreEduTrainingPlanToExecOrgService.saveBatch(planOrgList);
|
|
|
+ if (ObjectUtil.isNotEmpty(planOrgList)) {
|
|
|
+ coreEduTrainingPlanToExecOrgService.saveBatch(planOrgList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return planOrgList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -395,7 +436,7 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
return coreEduTrainingPlanMapper.selectPlanRole(orgId);
|
|
|
}
|
|
|
|
|
|
- public List<SysOrg> getPlanPublishOrgList(CoreEduTrainingPlan plan,List<Long> orgIdList) {
|
|
|
+ public List<SysOrg> getPlanPublishOrgList(CoreEduTrainingPlan plan, List<Long> orgIdList) {
|
|
|
List<SysOrg> orgList;
|
|
|
//优先判断是否存在具体的执行机构,如果存在则直接返回,否则根据机构类型进行查询
|
|
|
// QueryWrapper<CoreEduTrainingPlanToExecOrg> eos = new QueryWrapper<>();
|
|
|
@@ -410,18 +451,17 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
return orgList;
|
|
|
}
|
|
|
|
|
|
- private List<SysOrg> getPlanExecOrg(CoreEduTrainingPlan plan)
|
|
|
- {
|
|
|
+ private List<SysOrg> getPlanExecOrg(CoreEduTrainingPlan plan) {
|
|
|
QueryWrapper<CoreEduTrainingPlanToExecOrg> eos = new QueryWrapper<>();
|
|
|
eos.lambda().eq(CoreEduTrainingPlanToExecOrg::getPlanId, plan.getId());
|
|
|
final List<CoreEduTrainingPlanToExecOrg> coreEduTrainingPlanToExecOrgs = coreEduTrainingPlanToExecOrgMapper.selectList(eos);
|
|
|
- if(ObjectUtil.isNotEmpty(coreEduTrainingPlanToExecOrgs)){
|
|
|
+ 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 null;
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -436,56 +476,77 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
}
|
|
|
// 下发 按钮显示逻辑:仅省联社安全保卫管理人员进入且由省联社管理安全保卫人员创建的计划才显示
|
|
|
//todo 判断当前人的角色信息
|
|
|
+ List<CoreEduTrainingPlan> list = buildPlanData(plan, new ArrayList<>());
|
|
|
+
|
|
|
+ plan.setIssue(1);
|
|
|
+ this.updateById(plan);
|
|
|
+ //事务提交后执行
|
|
|
+ TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
|
|
+ @Override
|
|
|
+ public void afterCommit() {
|
|
|
+ for (CoreEduTrainingPlan trainingPlan : list) {
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
|
|
|
+ if ((ObjectUtil.equal(0, plan.getPlanStatus()) && (ObjectUtil.equal(0, plan.getPlanCycle()) || ObjectUtil.equal(1, plan.getBuildTaskNow())))) {
|
|
|
+ CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(trainingPlan.getId());
|
|
|
+ coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- //获取执行角色
|
|
|
- LambdaQueryWrapper<CoreEduTrainingPlanToRole> ros = new LambdaQueryWrapper<>();
|
|
|
- ros.eq(CoreEduTrainingPlanToRole::getPlanId, plan.getId());
|
|
|
- List<CoreEduTrainingPlanToRole> planRoleList = coreEduTrainingPlanToRoleMapper.selectList(ros);
|
|
|
+ }
|
|
|
|
|
|
+ private List<CoreEduTrainingPlan> buildPlanData(CoreEduTrainingPlan plan, List<CoreEduTrainingPlanToRole> planRoleList) {
|
|
|
+ if (ObjectUtil.isEmpty(planRoleList)) {
|
|
|
+ //获取执行角色
|
|
|
+ LambdaQueryWrapper<CoreEduTrainingPlanToRole> ros = new LambdaQueryWrapper<>();
|
|
|
+ ros.eq(CoreEduTrainingPlanToRole::getPlanId, plan.getId());
|
|
|
+ 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<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)){
|
|
|
+ List<SysOrg> publishOrgList = this.getPlanPublishOrgList(plan, orgIds);
|
|
|
+ if (ObjectUtil.isEmpty(publishOrgList)) {
|
|
|
throw new RuntimeException("未能查询到行社数据!");
|
|
|
}
|
|
|
|
|
|
- List<CoreEduTrainingPlanToExecOrg> planToExecOrgs=new ArrayList<>();
|
|
|
+ List<CoreEduTrainingPlanToExecOrg> planToExecOrgs = new ArrayList<>();
|
|
|
List<CoreEduTrainingPlan> list = new ArrayList<>();
|
|
|
for (SysOrg sysOrg : publishOrgList) {
|
|
|
CoreEduTrainingPlan coreEduTrainingPlan = new CoreEduTrainingPlan();
|
|
|
BeanUtils.copyProperties(plan, coreEduTrainingPlan);
|
|
|
coreEduTrainingPlan.setId(IdWorker.getId());
|
|
|
-// coreEduTrainingPlan.setBuildTaskNow(plan.getBuildTaskNow());
|
|
|
coreEduTrainingPlan.setBelongOrgId(sysOrg.getId());
|
|
|
coreEduTrainingPlan.setBelongOrgName(sysOrg.getName());
|
|
|
coreEduTrainingPlan.setBelongOrgPath(sysOrg.getPath());
|
|
|
coreEduTrainingPlan.setStandard(0);
|
|
|
coreEduTrainingPlan.setIssue(0);
|
|
|
- coreEduTrainingPlan.setParentId(planId);
|
|
|
+ coreEduTrainingPlan.setParentId(plan.getId());
|
|
|
coreEduTrainingPlan.setCreateTime(new Date());
|
|
|
coreEduTrainingPlan.setUpdateTime(new Date());
|
|
|
list.add(coreEduTrainingPlan);
|
|
|
|
|
|
- if(ObjectUtil.isNotEmpty(planExecOrgList)){
|
|
|
- planExecOrgList.stream().filter(x->x.getPath().contains(sysOrg.getPath())).forEach(y->{
|
|
|
- CoreEduTrainingPlanToExecOrg temp=new CoreEduTrainingPlanToExecOrg();
|
|
|
- temp.setPlanId(coreEduTrainingPlan.getId());
|
|
|
- temp.setOrgId(y.getId());
|
|
|
- planToExecOrgs.add(temp);
|
|
|
- });
|
|
|
+ if (ObjectUtil.isNotEmpty(planExecOrgList)) {
|
|
|
+ planExecOrgList.stream().filter(x -> x.getPath().contains(sysOrg.getPath())).forEach(y -> {
|
|
|
+ CoreEduTrainingPlanToExecOrg temp = new CoreEduTrainingPlanToExecOrg();
|
|
|
+ temp.setPlanId(coreEduTrainingPlan.getId());
|
|
|
+ temp.setOrgId(y.getId());
|
|
|
+ planToExecOrgs.add(temp);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
if (planToExecOrgs.size() > 0) {
|
|
|
coreEduTrainingPlanToExecOrgService.saveBatch(planToExecOrgs);
|
|
|
}
|
|
|
-
|
|
|
List<CoreEduTrainingPlanToRole> insertPlanRoleList = new ArrayList<>();
|
|
|
for (CoreEduTrainingPlan coreEduTrainingPlan : list) {
|
|
|
//保存执行角色
|
|
|
@@ -499,28 +560,11 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
if (list.size() > 0) {
|
|
|
this.saveBatch(list);
|
|
|
}
|
|
|
-
|
|
|
if (insertPlanRoleList.size() > 0) {
|
|
|
coreEduTrainingPlanToRoleService.saveBatch(insertPlanRoleList);
|
|
|
}
|
|
|
- plan.setIssue(1);
|
|
|
- this.updateById(plan);
|
|
|
- //事务提交后执行
|
|
|
- TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
|
|
- @Override
|
|
|
- public void afterCommit() {
|
|
|
- for (CoreEduTrainingPlan trainingPlan : list) {
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
- //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
|
|
|
- if ((ObjectUtil.equal(0, plan.getPlanStatus()) && (ObjectUtil.equal(0, plan.getPlanCycle()) || ObjectUtil.equal(1, plan.getBuildTaskNow())))) {
|
|
|
- CoreEduTrainingPlanDataVo detailPlanData = getCoreEduTrainingPlanDataVo(trainingPlan.getId());
|
|
|
- coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
@Override
|