|
|
@ -1,19 +1,26 @@ |
|
|
|
package com.ccsens.common.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.BooleanUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
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.vo.TaskVo; |
|
|
|
import com.ccsens.common.persist.dao.*; |
|
|
|
import com.ccsens.common.persist.mapper.ProTaskStatusRecordMapper; |
|
|
|
import com.ccsens.common.persist.mapper.ProTaskSubMapper; |
|
|
|
import com.ccsens.common.util.CommonCodeError; |
|
|
|
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 lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.val; |
|
|
|
import org.springframework.amqp.core.AmqpTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -28,8 +35,8 @@ import java.util.stream.Collectors; |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) |
|
|
|
public class TaskService implements ITaskService{ |
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|
|
|
public class TaskService implements ITaskService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ProRoleRepulsionDao roleRepulsionDao; |
|
|
@ -45,39 +52,46 @@ public class TaskService implements ITaskService{ |
|
|
|
private ProTaskSubMapper taskSubMapper; |
|
|
|
@Resource |
|
|
|
private ProTaskPluginDao taskPluginDao; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private ProTaskStatusRecordMapper taskStatusRecordMapper; |
|
|
|
@Resource |
|
|
|
private AmqpTemplate rabbitTemplate; |
|
|
|
|
|
|
|
/** |
|
|
|
* 判断当前用户的角色是否被设置不可见(是否有权限查看任务) |
|
|
|
* @param roleId 查看的角色id |
|
|
|
* @param userId 用户id |
|
|
|
* @return 是否可见(true可见,false不可见) |
|
|
|
* |
|
|
|
* @param roleId 查看的角色id |
|
|
|
* @param userId 用户id |
|
|
|
* @return 是否可见(true可见, false不可见) |
|
|
|
*/ |
|
|
|
public Boolean queryRoleIsLook(Long roleId,Long userId){ |
|
|
|
public Boolean queryRoleIsLook(Long roleId, Long userId) { |
|
|
|
byte visitor = 0; |
|
|
|
Long projectId = roleDao.findRoleOfProjectId(roleId); |
|
|
|
if (ObjectUtil.isNull(projectId)){ |
|
|
|
if (ObjectUtil.isNull(projectId)) { |
|
|
|
throw new BaseException(CommonCodeError.ROLE_ERROR); |
|
|
|
} |
|
|
|
Long memberId = memberDao.findUserOfMemberId(projectId,userId); |
|
|
|
Long memberId = memberDao.findUserOfMemberId(projectId, userId); |
|
|
|
//不是项目成员则为游客
|
|
|
|
if (ObjectUtil.isNull(memberId)){ |
|
|
|
if (ObjectUtil.isNull(memberId)) { |
|
|
|
visitor = 1; |
|
|
|
} |
|
|
|
//查看角色互斥表是否有对所属角色不可见
|
|
|
|
List<Long> repulsionRoleIds = roleRepulsionDao.findRepulsionByRoleId(roleId); |
|
|
|
List<Long> repulsionRoleIds = roleRepulsionDao.findRepulsionByRoleId(roleId); |
|
|
|
//如果为游客
|
|
|
|
if (1 == visitor) { |
|
|
|
return !CollectionUtil.isNotEmpty(repulsionRoleIds); |
|
|
|
} |
|
|
|
//查找成员所属的所有角色
|
|
|
|
List<Long> roleIds = roleMemberDao.findMemberOfRoleIds(memberId); |
|
|
|
if (CollectionUtil.isEmpty(roleIds)){ |
|
|
|
if (CollectionUtil.isNotEmpty(repulsionRoleIds)){ |
|
|
|
if (CollectionUtil.isEmpty(roleIds)) { |
|
|
|
if (CollectionUtil.isNotEmpty(repulsionRoleIds)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
//排斥角色包含所有所属角色则不可见
|
|
|
|
if (CollectionUtil.isNotEmpty(repulsionRoleIds) && CollectionUtil.isNotEmpty(roleIds)){ |
|
|
|
if (CollectionUtil.isNotEmpty(repulsionRoleIds) && CollectionUtil.isNotEmpty(roleIds)) { |
|
|
|
boolean isLook = repulsionRoleIds.containsAll(roleIds); |
|
|
|
return !isLook; |
|
|
|
} |
|
|
@ -86,29 +100,30 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询任务的插件相关信息 |
|
|
|
* @param taskList 任务列表 |
|
|
|
* |
|
|
|
* @param taskList 任务列表 |
|
|
|
*/ |
|
|
|
public void queryPluginForTask(List<TaskVo.QueryTask> taskList){ |
|
|
|
if (CollectionUtil.isNotEmpty(taskList)){ |
|
|
|
public void queryPluginForTask(List<TaskVo.QueryTask> taskList) { |
|
|
|
if (CollectionUtil.isNotEmpty(taskList)) { |
|
|
|
for (TaskVo.QueryTask queryTask : taskList) { |
|
|
|
List<List<TaskVo.TaskPluginInfo>> plugins = new ArrayList<>(); |
|
|
|
//如果任务面板信息不为空,则根据任务面板的行/列创建二维数组
|
|
|
|
if (ObjectUtil.isNotNull(queryTask.getPanel())){ |
|
|
|
if (ObjectUtil.isNotNull(queryTask.getPanel())) { |
|
|
|
int panelRow = queryTask.getPanel().getRow(); |
|
|
|
int panelCol = queryTask.getPanel().getCol(); |
|
|
|
if (0 != panelRow && 0 != panelCol){ |
|
|
|
if (0 != panelRow && 0 != panelCol) { |
|
|
|
//创建任务面板的二维数组
|
|
|
|
createSecondPanel(plugins,panelRow,panelCol); |
|
|
|
createSecondPanel(plugins, panelRow, panelCol); |
|
|
|
//将插件放入二维数组对应的位置中
|
|
|
|
List<TaskVo.TaskPluginInfo> taskPluginInfoList = taskPluginDao.queryTaskOfPlugin(queryTask.getDetailId()); |
|
|
|
putDateInList(taskPluginInfoList,plugins,queryTask); |
|
|
|
}else{ |
|
|
|
putDateInList(taskPluginInfoList, plugins, queryTask); |
|
|
|
} else { |
|
|
|
//根据插件最大的行和列创建二维数组
|
|
|
|
createPanelByPlugin(queryTask.getDetailId(),plugins,queryTask); |
|
|
|
createPanelByPlugin(queryTask.getDetailId(), plugins, queryTask); |
|
|
|
} |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
//根据插件最大的行和列创建二维数组
|
|
|
|
createPanelByPlugin(queryTask.getDetailId(),plugins,queryTask); |
|
|
|
createPanelByPlugin(queryTask.getDetailId(), plugins, queryTask); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -116,31 +131,33 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据插件的最大行列创建面板 |
|
|
|
* |
|
|
|
* @param taskDetailId 任务详情id |
|
|
|
* @param plugins 插件列表 |
|
|
|
* @param queryTask 任务 |
|
|
|
* @param plugins 插件列表 |
|
|
|
* @param queryTask 任务 |
|
|
|
*/ |
|
|
|
public void createPanelByPlugin(Long taskDetailId,List<List<TaskVo.TaskPluginInfo>> plugins,TaskVo.QueryTask queryTask){ |
|
|
|
public void createPanelByPlugin(Long taskDetailId, List<List<TaskVo.TaskPluginInfo>> plugins, TaskVo.QueryTask queryTask) { |
|
|
|
List<TaskVo.TaskPluginInfo> taskPluginInfoList = taskPluginDao.queryTaskOfPlugin(taskDetailId); |
|
|
|
if (CollectionUtil.isNotEmpty(taskPluginInfoList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(taskPluginInfoList)) { |
|
|
|
List<Integer> col = taskPluginInfoList.stream().map(TaskVo.TaskPluginInfo::getCol).collect(Collectors.toList()); |
|
|
|
List<Integer> row = taskPluginInfoList.stream().map(TaskVo.TaskPluginInfo::getRow).collect(Collectors.toList()); |
|
|
|
Integer newCol = Collections.max(col); |
|
|
|
Integer newRow = Collections.max(row); |
|
|
|
//创建任务面板的二维数组
|
|
|
|
createSecondPanel(plugins,newRow,newCol); |
|
|
|
createSecondPanel(plugins, newRow, newCol); |
|
|
|
//将插件放入二维数组对应的位置中
|
|
|
|
putDateInList(taskPluginInfoList,plugins,queryTask); |
|
|
|
putDateInList(taskPluginInfoList, plugins, queryTask); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建面板 |
|
|
|
* |
|
|
|
* @param plugins 插件列表 |
|
|
|
* @param row 行 |
|
|
|
* @param col 列 |
|
|
|
* @param row 行 |
|
|
|
* @param col 列 |
|
|
|
*/ |
|
|
|
public void createSecondPanel(List<List<TaskVo.TaskPluginInfo>> plugins,int row,int col){ |
|
|
|
public void createSecondPanel(List<List<TaskVo.TaskPluginInfo>> plugins, int row, int col) { |
|
|
|
for (int i = 0; i < row; i++) { |
|
|
|
List<TaskVo.TaskPluginInfo> pluginInfoList = new ArrayList<>(); |
|
|
|
for (int j = 0; j < col; j++) { |
|
|
@ -152,11 +169,12 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 向空面板里插入插件详情 |
|
|
|
* |
|
|
|
* @param taskPluginInfoList 插件详情列表 |
|
|
|
* @param plugins 插件列表 |
|
|
|
* @param queryTask 任务 |
|
|
|
* @param plugins 插件列表 |
|
|
|
* @param queryTask 任务 |
|
|
|
*/ |
|
|
|
public void putDateInList(List<TaskVo.TaskPluginInfo> taskPluginInfoList,List<List<TaskVo.TaskPluginInfo>> plugins,TaskVo.QueryTask queryTask){ |
|
|
|
public void putDateInList(List<TaskVo.TaskPluginInfo> taskPluginInfoList, List<List<TaskVo.TaskPluginInfo>> plugins, TaskVo.QueryTask queryTask) { |
|
|
|
for (TaskVo.TaskPluginInfo taskPlugin : taskPluginInfoList) { |
|
|
|
int pluginCol = taskPlugin.getCol(); |
|
|
|
int pluginRow = taskPlugin.getRow(); |
|
|
@ -171,8 +189,8 @@ public class TaskService implements ITaskService{ |
|
|
|
@Override |
|
|
|
public List<TaskVo.QueryTask> queryPermanentGlobalTask(TaskDto.QueryPermanentGlobalTask param, Long userId) { |
|
|
|
//查找当前角色是否有查看权限
|
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(),userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)){ |
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(), userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)) { |
|
|
|
throw new BaseException(CommonCodeError.NOT_PERMISSION); |
|
|
|
} |
|
|
|
List<TaskVo.QueryTask> permanentGlobalTask = taskDetailDao.queryPermanentGlobalTask(param.getRoleId()); |
|
|
@ -185,11 +203,11 @@ public class TaskService implements ITaskService{ |
|
|
|
@Override |
|
|
|
public List<TaskVo.QueryTask> queryGlobalTask(TaskDto.QueryGlobalTask param, Long userId) { |
|
|
|
//查找当前角色是否有查看权限
|
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(),userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)){ |
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(), userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)) { |
|
|
|
throw new BaseException(CommonCodeError.NOT_PERMISSION); |
|
|
|
} |
|
|
|
List<TaskVo.QueryTask> globalTask = taskDetailDao.queryGlobalTask(param.getRoleId(),param.getTimeNode(),param.getTimeUnit()); |
|
|
|
List<TaskVo.QueryTask> globalTask = taskDetailDao.queryGlobalTask(param.getRoleId(), param.getTimeNode(), param.getTimeUnit()); |
|
|
|
queryPluginForTask(globalTask); |
|
|
|
return globalTask; |
|
|
|
} |
|
|
@ -201,32 +219,30 @@ public class TaskService implements ITaskService{ |
|
|
|
String query = ""; |
|
|
|
String timeFormat = Constant.timeFormat.get(param.getTimeUnit()); |
|
|
|
String unit = Constant.timeUnit.get(param.getTimeUnit()); |
|
|
|
if (0 == param.getQueryType()){ |
|
|
|
query = "interval -"+param.getQueryNum()+" "+unit; |
|
|
|
}else{ |
|
|
|
query +="interval "+(param.getQueryNum()-1)+" "+unit; |
|
|
|
if (0 == param.getQueryType()) { |
|
|
|
query = "interval -" + param.getQueryNum() + " " + unit; |
|
|
|
} else { |
|
|
|
query += "interval " + (param.getQueryNum() - 1) + " " + unit; |
|
|
|
} |
|
|
|
//查找当前角色是否有查看权限
|
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(),userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)){ |
|
|
|
Boolean isLook = queryRoleIsLook(param.getRoleId(), userId); |
|
|
|
if (BooleanUtil.isFalse(isLook)) { |
|
|
|
throw new BaseException(CommonCodeError.NOT_PERMISSION); |
|
|
|
} |
|
|
|
//TODO 季度未实现
|
|
|
|
List<TaskVo.QueryTask> regularTask = taskDetailDao.queryRegularTask(param.getRoleId(),param.getTimeUnit(),param.getTimeNode(),param.getQueryType(),query,timeFormat); |
|
|
|
List<TaskVo.QueryTask> regularTask = taskDetailDao.queryRegularTask(param.getRoleId(), param.getTimeUnit(), param.getTimeNode(), param.getQueryType(), query, timeFormat); |
|
|
|
//如果该时段没有任务向上或向下补充
|
|
|
|
if (CollectionUtil.isEmpty(regularTask)) { |
|
|
|
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())))); |
|
|
|
List<String> mapOfKey = new ArrayList<>(); |
|
|
|
taskMap.forEach((key,val)->{ |
|
|
|
mapOfKey.add(key); |
|
|
|
}); |
|
|
|
if (CollectionUtil.isNotEmpty(mapOfKey)){ |
|
|
|
if (0 == param.getQueryType()){ |
|
|
|
taskMap.forEach((key, val) -> mapOfKey.add(key)); |
|
|
|
if (CollectionUtil.isNotEmpty(mapOfKey)) { |
|
|
|
if (0 == param.getQueryType()) { |
|
|
|
String max = Collections.max(mapOfKey); |
|
|
|
queryPluginForTask(taskMap.get(max)); |
|
|
|
return taskMap.get(max); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
String min = Collections.min(mapOfKey); |
|
|
|
queryPluginForTask(taskMap.get(min)); |
|
|
|
return taskMap.get(min); |
|
|
@ -242,32 +258,169 @@ public class TaskService implements ITaskService{ |
|
|
|
|
|
|
|
/** |
|
|
|
* 修改任务状态 |
|
|
|
* @param param 任务分解id和任务状态 |
|
|
|
* |
|
|
|
* @param param 任务分解id和任务状态 |
|
|
|
* @param userId 用户id |
|
|
|
*/ |
|
|
|
@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()); |
|
|
|
if(ObjectUtil.isNull(proTaskSub)){ |
|
|
|
if (ObjectUtil.isNull(proTaskSub)) { |
|
|
|
throw new BaseException(CommonCodeError.NOT_TASK); |
|
|
|
} |
|
|
|
//根据任务查找项目id
|
|
|
|
Long projectId = taskDetailDao.projectIdByTaskDetailId(proTaskSub.getTaskDetailId()); |
|
|
|
if(ObjectUtil.isNull(projectId)){ |
|
|
|
if (ObjectUtil.isNull(projectId)) { |
|
|
|
throw new BaseException(CommonCodeError.NOT_TASK); |
|
|
|
} |
|
|
|
//验证当前成员的权限(是该任务的负责人,或是项目经理,可以修改)
|
|
|
|
Integer pm = roleDao.isPmByUserId(userId,projectId); |
|
|
|
Integer pm = roleDao.isPmByUserId(userId, projectId); |
|
|
|
//验证是否是任务负责人
|
|
|
|
Integer executor = roleDao.isExecutorByUserId(userId,proTaskSub.getTaskDetailId()); |
|
|
|
if(pm < 2 && executor == 0){ |
|
|
|
throw new BaseException(CommonCodeError.NOT_TASK); |
|
|
|
Integer executor = roleDao.isExecutorByUserId(userId, proTaskSub.getTaskDetailId()); |
|
|
|
//只有负责人或者是项目经理才能操作任务的状态
|
|
|
|
if (pm < 2 && executor == 0) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|