|
|
@@ -1,9 +1,11 @@
|
|
|
package com.xunmei.core.edu.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
@@ -239,16 +241,13 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int updateCoreEduTrainingPlan(CoreEduTrainingPlanEditDto request) {
|
|
|
-
|
|
|
- if (ObjectUtil.isAllEmpty(request.getExecOrgType(), request.getPlanExecOrgIdList())) {
|
|
|
- throw new RuntimeException("培训机构类型和执行机构不能同时为空!");
|
|
|
- }
|
|
|
-
|
|
|
final CoreEduTrainingPlan plan = getById(request.getId());
|
|
|
- //如果是下发的计划,执行频次不应低于省联社下发时设定的次数
|
|
|
- if (ObjectUtil.equal(plan.getStandard(), 0) && request.getExecTimes() < plan.getExecTimes()) {
|
|
|
- throw new RuntimeException("执行次数不应低于基准次数!");
|
|
|
+ //此处判断能否修改,如果可以 需要删除任务,且还需要判断是否需要生成任务
|
|
|
+ Boolean can = checkCanUpdate(request, plan);
|
|
|
+ if (!can) {
|
|
|
+ throw new RuntimeException("当前任务已生成且存在已执行情况,无法修改培训机构类型,具体培训机构,培训角色,培训周期等信息!");
|
|
|
}
|
|
|
+ //可以修改计划
|
|
|
BeanUtils.copyProperties(request, plan);
|
|
|
plan.setUpdateTime(DateUtils.getNowDate());
|
|
|
plan.setFileList(ObjectUtil.isNotEmpty(request.getFileList()) ? JSON.toJSONString(request.getFileList()) : null);
|
|
|
@@ -258,8 +257,8 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
batchSavePlanToRole(request.getPlanRoleId(), plan.getId());
|
|
|
batchSavePlanToExecOrg(request.getPlanExecOrgIdList(), plan.getId());
|
|
|
final int i = coreEduTrainingPlanMapper.updateById(plan);
|
|
|
- if (ObjectUtil.equal(plan.getStandard(), 0) && ObjectUtil.equal(plan.getIssue(), 0)) {
|
|
|
- //说明是行方自己创建的计划,修改后需要重新下发
|
|
|
+ if (ObjectUtil.equal(plan.getStandard(), 0)) {
|
|
|
+ //自建计划
|
|
|
Integer exit = coreEduTrainingTaskMapper.checkHasTask(request.getId());
|
|
|
Integer hasDone = coreEduTrainingTaskMapper.checkHasTaskIsDone(Collections.singletonList(request.getId()));
|
|
|
if (ObjectUtil.equal(exit, 1) && ObjectUtil.isNull(hasDone)) {
|
|
|
@@ -273,6 +272,53 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
return i;
|
|
|
}
|
|
|
|
|
|
+ private Boolean checkCanUpdate(CoreEduTrainingPlanEditDto request, CoreEduTrainingPlan plan) {
|
|
|
+ if (ObjectUtil.isAllEmpty(request.getExecOrgType(), request.getPlanExecOrgIdList())) {
|
|
|
+ throw new RuntimeException("培训机构类型和执行机构不能同时为空!");
|
|
|
+ }
|
|
|
+ //如果是下发的计划,执行频次不应低于省联社下发时设定的次数
|
|
|
+ if (ObjectUtil.equal(plan.getStandard(), 0) && request.getExecTimes() < plan.getExecTimes()) {
|
|
|
+ throw new RuntimeException("执行次数不应低于基准次数!");
|
|
|
+ }
|
|
|
+ final Long planId = plan.getId();
|
|
|
+ //判断计划是否有任务已经执行过
|
|
|
+ final Integer done = coreEduTrainingTaskMapper.checkHasTaskIsDone(Arrays.asList(planId));
|
|
|
+ boolean flag = true;
|
|
|
+ //计划周期
|
|
|
+ if (ObjectUtil.notEqual(request.getPlanCycle(), plan.getPlanCycle())) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ //执行机构类型
|
|
|
+ if (ObjectUtil.notEqual(request.getExecOrgType(), plan.getExecOrgType())) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ //执行角色
|
|
|
+ List<Long> roleIdLit = coreEduTrainingPlanToRoleMapper.selectRoleIdByPlanId(planId);
|
|
|
+ List<Long> planRoleId = request.getPlanRoleId();
|
|
|
+ if (ObjectUtil.isEmpty(planRoleId)) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ for (Long roleId : roleIdLit) {
|
|
|
+ if (!planRoleId.contains(roleId)) {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //执行机构
|
|
|
+ List<Long> execOrgIdList = coreEduTrainingPlanToExecOrgMapper.selectOrgIdByPlanId(planId);
|
|
|
+ final List<Long> planExecOrgIdList = request.getPlanExecOrgIdList();
|
|
|
+ if (execOrgIdList.size() != planExecOrgIdList.size()) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ for (Long orgId : execOrgIdList) {
|
|
|
+ if (!planExecOrgIdList.contains(orgId)) {
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null == done || flag;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public CoreEduTrainingPlanDataVo getCoreEduTrainingPlanDataVo(Long id) {
|
|
|
final CoreEduTrainingPlanDataVo dataVo = coreEduTrainingPlanMapper.getDetailPlanData(id);
|
|
|
@@ -379,7 +425,6 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
// 下发 按钮显示逻辑:仅省联社安全保卫管理人员进入且由省联社管理安全保卫人员创建的计划才显示
|
|
|
//todo 判断当前人的角色信息
|
|
|
|
|
|
-
|
|
|
//获取执行角色
|
|
|
LambdaQueryWrapper<CoreEduTrainingPlanToRole> ros = new LambdaQueryWrapper<>();
|
|
|
ros.eq(CoreEduTrainingPlanToRole::getPlanId, plan.getId());
|
|
|
@@ -417,6 +462,13 @@ public class CoreEduTrainingPlanServiceImpl extends ServiceImpl<CoreEduTrainingP
|
|
|
if (list.size() > 0) {
|
|
|
this.saveBatch(list);
|
|
|
}
|
|
|
+ for (CoreEduTrainingPlan trainingPlan : list) {
|
|
|
+ //如果不是省联社或者办事处,状态启用,并且是无周期或者立即生效
|
|
|
+ if ((ObjectUtil.equal(0, plan.getPlanStatus()) && (ObjectUtil.equal(0, plan.getPlanCycle()) || ObjectUtil.equal(1, plan.getBuildTaskNow())))) {
|
|
|
+ CoreEduTrainingPlanDataVo detailPlanData = this.getCoreEduTrainingPlanDataVo(trainingPlan.getId());
|
|
|
+ coreEduTrainingTaskService.createTaskForNow(detailPlanData, plan.getStartDate(), plan.getEndDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
if (insertPlanRoleList.size() > 0) {
|
|
|
coreEduTrainingPlanToRoleService.saveBatch(insertPlanRoleList);
|
|
|
}
|