|
|
@ -1,19 +1,26 @@ |
|
|
package com.ccsens.common.service; |
|
|
package com.ccsens.common.service; |
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
import cn.hutool.core.util.BooleanUtil; |
|
|
import cn.hutool.core.util.BooleanUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import com.ccsens.common.bean.dto.TaskDto; |
|
|
import com.ccsens.common.bean.dto.TaskDto; |
|
|
import com.ccsens.common.bean.po.ProTaskDetail; |
|
|
import com.ccsens.common.bean.message.TaskMessageWithStatus; |
|
|
|
|
|
import com.ccsens.common.bean.po.ProTaskStatusRecord; |
|
|
import com.ccsens.common.bean.po.ProTaskSub; |
|
|
import com.ccsens.common.bean.po.ProTaskSub; |
|
|
import com.ccsens.common.bean.vo.TaskVo; |
|
|
import com.ccsens.common.bean.vo.TaskVo; |
|
|
import com.ccsens.common.persist.dao.*; |
|
|
import com.ccsens.common.persist.dao.*; |
|
|
|
|
|
import com.ccsens.common.persist.mapper.ProTaskStatusRecordMapper; |
|
|
import com.ccsens.common.persist.mapper.ProTaskSubMapper; |
|
|
import com.ccsens.common.persist.mapper.ProTaskSubMapper; |
|
|
import com.ccsens.common.util.CommonCodeError; |
|
|
import com.ccsens.common.util.CommonCodeError; |
|
|
import com.ccsens.common.util.Constant; |
|
|
import com.ccsens.common.util.Constant; |
|
|
|
|
|
import com.ccsens.util.JacksonUtil; |
|
|
|
|
|
import com.ccsens.util.bean.message.common.InMessage; |
|
|
|
|
|
import com.ccsens.util.bean.message.common.MessageConstant; |
|
|
|
|
|
import com.ccsens.util.config.RabbitMQConfig; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import com.ccsens.util.exception.BaseException; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.val; |
|
|
import org.springframework.amqp.core.AmqpTemplate; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -45,9 +52,16 @@ public class TaskService implements ITaskService{ |
|
|
private ProTaskSubMapper taskSubMapper; |
|
|
private ProTaskSubMapper taskSubMapper; |
|
|
@Resource |
|
|
@Resource |
|
|
private ProTaskPluginDao taskPluginDao; |
|
|
private ProTaskPluginDao taskPluginDao; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private ProTaskStatusRecordMapper taskStatusRecordMapper; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private AmqpTemplate rabbitTemplate; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 判断当前用户的角色是否被设置不可见(是否有权限查看任务) |
|
|
* 判断当前用户的角色是否被设置不可见(是否有权限查看任务) |
|
|
|
|
|
* |
|
|
* @param roleId 查看的角色id |
|
|
* @param roleId 查看的角色id |
|
|
* @param userId 用户id |
|
|
* @param userId 用户id |
|
|
* @return 是否可见(true可见, false不可见) |
|
|
* @return 是否可见(true可见, false不可见) |
|
|
@ -86,6 +100,7 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 查询任务的插件相关信息 |
|
|
* 查询任务的插件相关信息 |
|
|
|
|
|
* |
|
|
* @param taskList 任务列表 |
|
|
* @param taskList 任务列表 |
|
|
*/ |
|
|
*/ |
|
|
public void queryPluginForTask(List<TaskVo.QueryTask> taskList) { |
|
|
public void queryPluginForTask(List<TaskVo.QueryTask> taskList) { |
|
|
@ -116,6 +131,7 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据插件的最大行列创建面板 |
|
|
* 根据插件的最大行列创建面板 |
|
|
|
|
|
* |
|
|
* @param taskDetailId 任务详情id |
|
|
* @param taskDetailId 任务详情id |
|
|
* @param plugins 插件列表 |
|
|
* @param plugins 插件列表 |
|
|
* @param queryTask 任务 |
|
|
* @param queryTask 任务 |
|
|
@ -136,6 +152,7 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建面板 |
|
|
* 创建面板 |
|
|
|
|
|
* |
|
|
* @param plugins 插件列表 |
|
|
* @param plugins 插件列表 |
|
|
* @param row 行 |
|
|
* @param row 行 |
|
|
* @param col 列 |
|
|
* @param col 列 |
|
|
@ -152,6 +169,7 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 向空面板里插入插件详情 |
|
|
* 向空面板里插入插件详情 |
|
|
|
|
|
* |
|
|
* @param taskPluginInfoList 插件详情列表 |
|
|
* @param taskPluginInfoList 插件详情列表 |
|
|
* @param plugins 插件列表 |
|
|
* @param plugins 插件列表 |
|
|
* @param queryTask 任务 |
|
|
* @param queryTask 任务 |
|
|
@ -218,9 +236,7 @@ public class TaskService implements ITaskService{ |
|
|
List<TaskVo.QueryTask> replenishTask = taskDetailDao.continueQueryTask(param.getRoleId(), param.getTimeUnit(), param.getTimeNode(), param.getQueryType(), query, timeFormat); |
|
|
List<TaskVo.QueryTask> replenishTask = taskDetailDao.continueQueryTask(param.getRoleId(), param.getTimeUnit(), param.getTimeNode(), param.getQueryType(), query, timeFormat); |
|
|
Map<String, List<TaskVo.QueryTask>> taskMap = replenishTask.stream().collect(Collectors.groupingBy(task -> new SimpleDateFormat("yyyy-MM-dd").format(new Date(task.getPlanStart())))); |
|
|
Map<String, List<TaskVo.QueryTask>> taskMap = replenishTask.stream().collect(Collectors.groupingBy(task -> new SimpleDateFormat("yyyy-MM-dd").format(new Date(task.getPlanStart())))); |
|
|
List<String> mapOfKey = new ArrayList<>(); |
|
|
List<String> mapOfKey = new ArrayList<>(); |
|
|
taskMap.forEach((key,val)->{ |
|
|
taskMap.forEach((key, val) -> mapOfKey.add(key)); |
|
|
mapOfKey.add(key); |
|
|
|
|
|
}); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(mapOfKey)) { |
|
|
if (CollectionUtil.isNotEmpty(mapOfKey)) { |
|
|
if (0 == param.getQueryType()) { |
|
|
if (0 == param.getQueryType()) { |
|
|
String max = Collections.max(mapOfKey); |
|
|
String max = Collections.max(mapOfKey); |
|
|
@ -242,11 +258,12 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 修改任务状态 |
|
|
* 修改任务状态 |
|
|
|
|
|
* |
|
|
* @param param 任务分解id和任务状态 |
|
|
* @param param 任务分解id和任务状态 |
|
|
* @param userId 用户id |
|
|
* @param userId 用户id |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public void updateTaskType(TaskDto.UpdateTaskType param, Long userId) { |
|
|
public void updateTaskType(TaskDto.UpdateTaskType param, Long userId) throws Exception { |
|
|
//验证任务是否存在
|
|
|
//验证任务是否存在
|
|
|
ProTaskSub proTaskSub = taskSubMapper.selectByPrimaryKey(param.getId()); |
|
|
ProTaskSub proTaskSub = taskSubMapper.selectByPrimaryKey(param.getId()); |
|
|
if (ObjectUtil.isNull(proTaskSub)) { |
|
|
if (ObjectUtil.isNull(proTaskSub)) { |
|
|
@ -261,13 +278,149 @@ public class TaskService implements ITaskService{ |
|
|
Integer pm = roleDao.isPmByUserId(userId, projectId); |
|
|
Integer pm = roleDao.isPmByUserId(userId, projectId); |
|
|
//验证是否是任务负责人
|
|
|
//验证是否是任务负责人
|
|
|
Integer executor = roleDao.isExecutorByUserId(userId, proTaskSub.getTaskDetailId()); |
|
|
Integer executor = roleDao.isExecutorByUserId(userId, proTaskSub.getTaskDetailId()); |
|
|
|
|
|
//只有负责人或者是项目经理才能操作任务的状态
|
|
|
if (pm < 2 && executor == 0) { |
|
|
if (pm < 2 && executor == 0) { |
|
|
throw new BaseException(CommonCodeError.NOT_TASK); |
|
|
throw new BaseException(CommonCodeError.NOT_PERMISSION); |
|
|
} |
|
|
} |
|
|
//根据状态修改信息
|
|
|
//获取当前时间
|
|
|
//开始 添加操作记录 修改任务的状态为进行中,实际开始时间为当前时间,实际时长清空
|
|
|
Long now = System.currentTimeMillis(); |
|
|
//暂停 判断任务是否是进行中, 修改任务的状态为暂停,计算实际时长 添加操作记录
|
|
|
//添加记录
|
|
|
//继续 判断任务是否是暂停中 修改任务状态进行中,添加操作记录
|
|
|
saveTaskStatusRecord(param, userId, now); |
|
|
//完成 判断任务的交付物信息 修改任务的状态为完成,计算任务的实际时长 记录操作记录
|
|
|
switch (param.getType()) { |
|
|
|
|
|
case Constant.TaskOperationType.START: |
|
|
|
|
|
//开始 修改任务的状态为进行中,实际开始时间为当前时间,实际时长清空
|
|
|
|
|
|
proTaskSub.setTaskStatus(Constant.TaskType.PROCESSING); |
|
|
|
|
|
proTaskSub.setRealStartTime(now); |
|
|
|
|
|
proTaskSub.setRealDuration(0L); |
|
|
|
|
|
proTaskSub.setRealEndTime(0L); |
|
|
|
|
|
taskSubMapper.updateByPrimaryKeySelective(proTaskSub); |
|
|
|
|
|
break; |
|
|
|
|
|
case Constant.TaskOperationType.PAUSE: |
|
|
|
|
|
//暂停 判断任务是否是进行中,
|
|
|
|
|
|
if (proTaskSub.getTaskStatus() != Constant.TaskType.PROCESSING) { |
|
|
|
|
|
throw new BaseException(CommonCodeError.OPERATION_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
//修改任务的状态为暂停,计算实际时长
|
|
|
|
|
|
proTaskSub.setTaskStatus(Constant.TaskType.PAUSE); |
|
|
|
|
|
//计算当前任务实际时长
|
|
|
|
|
|
Long duration = calculateDuration(param.getId()); |
|
|
|
|
|
proTaskSub.setRealDuration(duration); |
|
|
|
|
|
taskSubMapper.updateByPrimaryKeySelective(proTaskSub); |
|
|
|
|
|
break; |
|
|
|
|
|
case Constant.TaskOperationType.TASK_CONTINUE: |
|
|
|
|
|
//继续 判断任务是否是暂停中
|
|
|
|
|
|
if (proTaskSub.getTaskStatus() != Constant.TaskType.PAUSE) { |
|
|
|
|
|
throw new BaseException(CommonCodeError.OPERATION_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
//修改任务状态为进行中
|
|
|
|
|
|
proTaskSub.setTaskStatus(Constant.TaskType.PROCESSING); |
|
|
|
|
|
taskSubMapper.updateByPrimaryKeySelective(proTaskSub); |
|
|
|
|
|
break; |
|
|
|
|
|
case Constant.TaskOperationType.COMPLETE: |
|
|
|
|
|
//TODO 验证交付物
|
|
|
|
|
|
//修改任务状态
|
|
|
|
|
|
proTaskSub.setTaskStatus(Constant.TaskType.COMPLETED); |
|
|
|
|
|
proTaskSub.setRealEndTime(now); |
|
|
|
|
|
//计算当前任务实际时长
|
|
|
|
|
|
Long d = calculateDuration(param.getId()); |
|
|
|
|
|
proTaskSub.setRealDuration(d); |
|
|
|
|
|
taskSubMapper.updateByPrimaryKeySelective(proTaskSub); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new BaseException(CommonCodeError.OPERATION_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//发送消息
|
|
|
|
|
|
sendToTaskStatus(userId,proTaskSub,param.getType(),now); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**发送任务状态修改的消息*/ |
|
|
|
|
|
private void sendToTaskStatus(Long userId, ProTaskSub proTaskSub,byte operationType,Long now) throws Exception { |
|
|
|
|
|
//查找任务所有的负责人下的所有的成员
|
|
|
|
|
|
List<String> userIdList = roleDao.queryExecutorUserIdBySubTaskId(proTaskSub.getId()); |
|
|
|
|
|
Set<String> userIdSet = new HashSet<>(userIdList); |
|
|
|
|
|
|
|
|
|
|
|
TaskMessageWithStatus taskMessageWithStatus = |
|
|
|
|
|
new TaskMessageWithStatus(proTaskSub.getId(),proTaskSub.getTaskDetailId(),operationType,proTaskSub.getTaskStatus(),userId,now); |
|
|
|
|
|
|
|
|
|
|
|
//封装成inMessage
|
|
|
|
|
|
InMessage inMessage = new InMessage(); |
|
|
|
|
|
inMessage.setToDomain(MessageConstant.DomainType.User); |
|
|
|
|
|
inMessage.setTos(userIdSet); |
|
|
|
|
|
inMessage.setData(JacksonUtil.beanToJson(taskMessageWithStatus)); |
|
|
|
|
|
log.info("发送消息--任务状态改变--:{}",inMessage); |
|
|
|
|
|
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME, |
|
|
|
|
|
JacksonUtil.beanToJson(inMessage)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 计算实际时长 |
|
|
|
|
|
*/ |
|
|
|
|
|
private Long calculateDuration(Long subTaskId) { |
|
|
|
|
|
long time = 0L; |
|
|
|
|
|
long duration = 0L; |
|
|
|
|
|
byte type = 0; |
|
|
|
|
|
List<ProTaskStatusRecord> taskStatusRecords = taskDetailDao.calculateDuration(subTaskId); |
|
|
|
|
|
if (CollectionUtil.isNotEmpty(taskStatusRecords)) { |
|
|
|
|
|
for (ProTaskStatusRecord taskStatusRecord : taskStatusRecords) { |
|
|
|
|
|
if(taskStatusRecord.getTaskStatus() == Constant.TaskOperationType.START){ |
|
|
|
|
|
//时长为零
|
|
|
|
|
|
duration = 0L; |
|
|
|
|
|
//记录开始时间和状态
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(taskStatusRecord.getTaskStatus() == Constant.TaskOperationType.PAUSE){ |
|
|
|
|
|
//上一个阶段到这一个阶段的时间 加上以保存的时长
|
|
|
|
|
|
duration += taskStatusRecord.getUpdateStatusTime() - time; |
|
|
|
|
|
//记录暂停的时间 和状态
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(taskStatusRecord.getTaskStatus() == Constant.TaskOperationType.TASK_CONTINUE){ |
|
|
|
|
|
//时长暂时不动
|
|
|
|
|
|
//记录一下暂停的时间
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(taskStatusRecord.getTaskStatus() == Constant.TaskOperationType.COMPLETE){ |
|
|
|
|
|
if(type == Constant.TaskOperationType.START){ |
|
|
|
|
|
//如果是开始 用当前时间减去上一个阶段的时间 等于时长
|
|
|
|
|
|
duration = taskStatusRecord.getUpdateStatusTime() - time; |
|
|
|
|
|
//记录一下时间和类型
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(type == Constant.TaskOperationType.PAUSE){ |
|
|
|
|
|
//如果是暂停 直接用之前的时长
|
|
|
|
|
|
//记录一下时间和类型
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(type == Constant.TaskOperationType.TASK_CONTINUE){ |
|
|
|
|
|
//如果是继续 用当前时间减去继续的时间,加上之前的时长
|
|
|
|
|
|
duration += taskStatusRecord.getUpdateStatusTime() - time; |
|
|
|
|
|
//记录一下时间和类型
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
}else if(type == Constant.TaskOperationType.COMPLETE){ |
|
|
|
|
|
//如果是停止,直接返回时长
|
|
|
|
|
|
//记录一下时间和类型
|
|
|
|
|
|
time = taskStatusRecord.getUpdateStatusTime(); |
|
|
|
|
|
type = taskStatusRecord.getTaskStatus(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
log.info("查询当前任务的时长-{}",duration); |
|
|
|
|
|
return duration; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 修改任务状态时添加修改记录 |
|
|
|
|
|
*/ |
|
|
|
|
|
public void saveTaskStatusRecord(TaskDto.UpdateTaskType param, Long userId, Long now) { |
|
|
|
|
|
ProTaskStatusRecord taskStatusRecord = new ProTaskStatusRecord(); |
|
|
|
|
|
taskStatusRecord.setId(snowflake.nextId()); |
|
|
|
|
|
taskStatusRecord.setTaskStatus(param.getType()); |
|
|
|
|
|
taskStatusRecord.setTaskSubId(param.getId()); |
|
|
|
|
|
taskStatusRecord.setUserId(userId); |
|
|
|
|
|
taskStatusRecord.setUpdateStatusTime(now); |
|
|
|
|
|
taskStatusRecordMapper.insertSelective(taskStatusRecord); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|