|
|
|
@ -2,8 +2,10 @@ package com.ccsens.tall.service; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.ccsens.tall.bean.dto.TaskDto; |
|
|
|
import com.ccsens.tall.bean.po.*; |
|
|
|
import com.ccsens.tall.bean.vo.ProjectVo; |
|
|
|
import com.ccsens.tall.bean.vo.TaskVo; |
|
|
|
@ -12,7 +14,11 @@ import com.ccsens.tall.util.TaskUtil; |
|
|
|
import com.ccsens.util.CodeEnum; |
|
|
|
import com.ccsens.util.DateUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.cron.CronConstant; |
|
|
|
import com.ccsens.util.cron.NatureToDate; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import com.sun.org.apache.bcel.internal.classfile.Code; |
|
|
|
import io.swagger.annotations.ApiModelProperty; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Repository; |
|
|
|
@ -20,6 +26,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.sql.Struct; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
@ -55,6 +62,8 @@ public class ProTaskDetailService implements IProTaskDetailService { |
|
|
|
private SysProjectDao sysProjectDao; |
|
|
|
@Autowired |
|
|
|
private TaskPluginDao taskPluginDao; |
|
|
|
@Autowired |
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveTaskDetail(ProTaskDetail taskDetail) { |
|
|
|
@ -760,8 +769,8 @@ public class ProTaskDetailService implements IProTaskDetailService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<TaskVo.TaskDetailByKey> getTaskDetailByKey(Long currentUserId, Long projectId, String key) { |
|
|
|
List<TaskVo.TaskDetailByKey> taskDetailByKeyList = taskDetailDao.selectTaskByKey(currentUserId, projectId, key); |
|
|
|
return taskDetailByKeyList; |
|
|
|
// List<TaskVo.TaskDetailByKey> taskDetailByKeyList = taskDetailDao.selectTaskByKey(currentUserId, projectId, key);
|
|
|
|
return taskDetailDao.selectTaskByKey(currentUserId, projectId, key); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -769,8 +778,7 @@ public class ProTaskDetailService implements IProTaskDetailService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public TaskVo.NormalTask selectTaskByParentId(Long parentId, Long startTime, Long endTime) { |
|
|
|
TaskVo.NormalTask normalTask = taskDetailDao.selectTaskByParentIdAndTime(parentId, startTime, endTime); |
|
|
|
return normalTask; |
|
|
|
return taskDetailDao.selectTaskByParentIdAndTime(parentId, startTime, endTime); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -878,4 +886,141 @@ public class ProTaskDetailService implements IProTaskDetailService { |
|
|
|
taskDetailDao.selectTaskByDetailId(taskId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改任务信息 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public TaskVo.NormalTask updateTaskInfo(Long currentUserId, TaskDto.UpdateTaskInfo updateTaskInfo) throws Exception { |
|
|
|
TaskVo.NormalTask normalTask = null; |
|
|
|
|
|
|
|
ProTaskDetail taskDetail = null; |
|
|
|
ProTaskSubTime taskSubTime = taskSubTimeDao.selectByPrimaryKey(updateTaskInfo.getId()); |
|
|
|
if(ObjectUtil.isNotNull(taskSubTime)){ |
|
|
|
taskDetail = taskDetailDao.selectByPrimaryKey(taskSubTime.getTaskDetailId()); |
|
|
|
}else { |
|
|
|
taskDetail = taskDetailDao.selectByPrimaryKey(updateTaskInfo.getId()); |
|
|
|
} |
|
|
|
if(ObjectUtil.isNotNull(taskDetail)) { |
|
|
|
SysProject project = sysProjectDao.selectByPrimaryKey(taskDetail.getProjectId()); |
|
|
|
if(ObjectUtil.isNotNull(project)) { |
|
|
|
int power = proRoleService.selectPowerByRoleName(currentUserId, project.getId()); |
|
|
|
if (power > 1) { |
|
|
|
//任务名
|
|
|
|
if(StrUtil.isNotEmpty(updateTaskInfo.getName())){ |
|
|
|
taskDetail.setName(updateTaskInfo.getName()); |
|
|
|
} |
|
|
|
//详情
|
|
|
|
if(StrUtil.isNotEmpty(updateTaskInfo.getDescription())){ |
|
|
|
taskDetail.setDescription(updateTaskInfo.getDescription()); |
|
|
|
} |
|
|
|
//负责人
|
|
|
|
if(ObjectUtil.isNotNull(updateTaskInfo.getExecutorRole())){ |
|
|
|
taskDetail.setExecutorRole(updateTaskInfo.getExecutorRole()); |
|
|
|
} |
|
|
|
//奖惩金额
|
|
|
|
if(ObjectUtil.isNotNull(updateTaskInfo.getMoney())){ |
|
|
|
taskDetail.setMoney(updateTaskInfo.getMoney()); |
|
|
|
} |
|
|
|
//切换模式
|
|
|
|
if(ObjectUtil.isNotNull(updateTaskInfo.getDelay())){ |
|
|
|
taskDetail.setDelay((byte) updateTaskInfo.getDelay()); |
|
|
|
} |
|
|
|
//延迟切换时间
|
|
|
|
if(ObjectUtil.isNotNull(updateTaskInfo.getDelayTime()) && |
|
|
|
(taskDetail.getDelay() == WebConstant.TASK_DELAY.DelayManual.value)){ |
|
|
|
taskDetail.setDelayTime(updateTaskInfo.getDelayTime()); |
|
|
|
} |
|
|
|
//时间
|
|
|
|
boolean isUpdateTime = false; |
|
|
|
//一级任务没有时间,不能修改
|
|
|
|
if(taskDetail.getLevel() != 1 && taskDetail.getLevel() != 0) { |
|
|
|
if (ObjectUtil.isNotNull(updateTaskInfo.getBeginTime())) { |
|
|
|
taskDetail.setBeginTime(updateTaskInfo.getBeginTime()); |
|
|
|
isUpdateTime = true; |
|
|
|
} |
|
|
|
if (ObjectUtil.isNotNull(updateTaskInfo.getEndTime())) { |
|
|
|
taskDetail.setEndTime(updateTaskInfo.getEndTime()); |
|
|
|
isUpdateTime = true; |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(updateTaskInfo.getCycle())) { |
|
|
|
taskDetail.setCycle(updateTaskInfo.getCycle()); |
|
|
|
isUpdateTime = true; |
|
|
|
} |
|
|
|
|
|
|
|
//时间赋完值后,检查开始时间是否小于结束时间。(赋值前判断太麻烦)
|
|
|
|
if (taskDetail.getBeginTime() >= taskDetail.getEndTime()){ |
|
|
|
throw new BaseException(CodeEnum.TIME_ERROR_BEGIN); |
|
|
|
} |
|
|
|
} |
|
|
|
//若时间相关被修改,删掉旧的subTime,根据新时间重新生成
|
|
|
|
if(isUpdateTime){ |
|
|
|
//删掉旧的subTime
|
|
|
|
ProTaskSubTimeExample subTimeExample = new ProTaskSubTimeExample(); |
|
|
|
subTimeExample.createCriteria().andTaskDetailIdEqualTo(taskDetail.getId()); |
|
|
|
taskSubTimeDao.deleteByExample(subTimeExample); |
|
|
|
//重新生成subTime
|
|
|
|
partTaskSubTime(taskDetail); |
|
|
|
} |
|
|
|
//修改数据
|
|
|
|
taskDetailDao.updateByPrimaryKeySelective(taskDetail); |
|
|
|
//返回的任务详细信息
|
|
|
|
normalTask = getTaskInfoByTaskId(currentUserId,project.getId(),updateTaskInfo.getId()); |
|
|
|
} |
|
|
|
}else { |
|
|
|
throw new BaseException(CodeEnum.NOT_POWER); |
|
|
|
} |
|
|
|
}else { |
|
|
|
throw new BaseException(CodeEnum.NOT_TASK); |
|
|
|
} |
|
|
|
return normalTask; |
|
|
|
} |
|
|
|
// private void changeTime(ProTaskDetail taskDetail,Long beginTime,Long endTime,SysProject project){
|
|
|
|
// if(beginTime >= project.getBeginTime() || endTime <= project.getEndTime()){
|
|
|
|
// throw new BaseException(CodeEnum.TIME_ERROR_PROJECT);
|
|
|
|
// }
|
|
|
|
// if(taskDetail.getLevel() == 2){
|
|
|
|
// ProTaskDetailExample detailExample = new ProTaskDetailExample();
|
|
|
|
// detailExample.createCriteria().andParentIdEqualTo(taskDetail.getId());
|
|
|
|
// List<ProTaskDetail> detailList = taskDetailDao.selectByExample(detailExample);
|
|
|
|
// if(CollectionUtil.isNotEmpty(detailList)){
|
|
|
|
//
|
|
|
|
// }else {
|
|
|
|
// if (ObjectUtil.isNotNull(beginTime)) {
|
|
|
|
// taskDetail.setBeginTime(beginTime);
|
|
|
|
// }
|
|
|
|
// if (ObjectUtil.isNotNull(endTime)) {
|
|
|
|
// taskDetail.setEndTime(endTime);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }else if(taskDetail.getLevel() == 3){
|
|
|
|
//
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
private void partTaskSubTime(ProTaskDetail taskDetail){ |
|
|
|
//cycle为空或者组任务,只加一条数据
|
|
|
|
if (StrUtil.isEmpty(taskDetail.getCycle()) || taskDetail.getHasGroup() == 1) { |
|
|
|
ProTaskSubTime proTaskSubTime = new ProTaskSubTime(); |
|
|
|
proTaskSubTime.setId(snowflake.nextId()); |
|
|
|
proTaskSubTime.setEndTime(taskDetail.getEndTime()); |
|
|
|
proTaskSubTime.setBeginTime(taskDetail.getBeginTime()); |
|
|
|
proTaskSubTime.setTaskDetailId(taskDetail.getId()); |
|
|
|
taskSubTimeDao.insertSelective(proTaskSubTime); |
|
|
|
} else { |
|
|
|
Date startDate = new Date(taskDetail.getBeginTime()); |
|
|
|
Date endDate = new Date(taskDetail.getEndTime()); |
|
|
|
List<CronConstant.TaskDate> taskDateList = |
|
|
|
NatureToDate.generateDates(taskDetail.getCycle(), startDate, endDate); |
|
|
|
if (CollectionUtil.isEmpty(taskDateList)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
for (CronConstant.TaskDate taskDate : taskDateList) { |
|
|
|
ProTaskSubTime proTaskSubTime = new ProTaskSubTime(); |
|
|
|
proTaskSubTime.setId(snowflake.nextId()); |
|
|
|
proTaskSubTime.setBeginTime(taskDate.getStartDate().getTime()); |
|
|
|
proTaskSubTime.setEndTime(taskDate.getEndDate().getTime()); |
|
|
|
proTaskSubTime.setTaskDetailId(taskDetail.getId()); |
|
|
|
taskSubTimeDao.insertSelective(proTaskSubTime); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|