|
@@ -7,12 +7,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.TaskCommentMapper;
|
|
|
+import com.management.platform.mapper.TaskExecutorMapper;
|
|
|
import com.management.platform.mapper.TaskMapper;
|
|
|
import com.management.platform.mapper.UserMapper;
|
|
|
import com.management.platform.service.*;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import org.opencv.features2d.SimpleBlobDetector;
|
|
|
import org.springframework.format.annotation.DateTimeFormat;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.WebDataBinder;
|
|
|
import org.springframework.web.bind.annotation.InitBinder;
|
|
@@ -57,8 +59,6 @@ public class TaskController {
|
|
|
@Resource
|
|
|
private ProjectService projectService;
|
|
|
@Resource
|
|
|
- private UserRecentTaskService userRecentTaskService;
|
|
|
- @Resource
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
|
private TaskLogService taskLogService;
|
|
@@ -74,10 +74,17 @@ public class TaskController {
|
|
|
private TaskCommentMapper taskCommentMapper;
|
|
|
@Resource
|
|
|
private TaskMapper taskMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskExecutorMapper taskExecutorMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskExecutorService taskExecutorService;
|
|
|
|
|
|
@RequestMapping("/save")
|
|
|
+ @Transactional
|
|
|
public HttpRespMsg save(Task task) {
|
|
|
String userId = request.getHeader("Token");
|
|
|
+ String executorListStr = task.getExecutorListStr();
|
|
|
+
|
|
|
//当前用户
|
|
|
User user = userMapper.selectById(userId);
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -91,19 +98,31 @@ public class TaskController {
|
|
|
task.setCompanyId(user.getCompanyId());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (!StringUtils.isEmpty(task.getExecutorId())) {
|
|
|
- User executor = userMapper.selectById(task.getExecutorId());
|
|
|
-
|
|
|
- task.setExecutorName(executor.getName());
|
|
|
- task.setExecutorColor(executor.getColor());
|
|
|
+ if (!StringUtils.isEmpty(executorListStr)) {
|
|
|
+ List<User> allUsers = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<TaskExecutor> executorList = JSONArray.parseArray(executorListStr, TaskExecutor.class);
|
|
|
+ task.setExecutorList(executorList);
|
|
|
+ executorList.stream().filter(ex->!StringUtils.isEmpty(ex.getExecutorId())).forEach(ex->{
|
|
|
+ User exeUser = allUsers.stream().filter(al->al.getId().equals(ex.getExecutorId())).findFirst().get();
|
|
|
+ ex.setExecutorName(exeUser.getName());
|
|
|
+ ex.setExecutorColor(exeUser.getColor());
|
|
|
+ ex.setProjectId(task.getProjectId());
|
|
|
+ });
|
|
|
+ String ids = executorList.stream().filter(f->!StringUtils.isEmpty(f.getExecutorId())).map(TaskExecutor::getExecutorId).collect(Collectors.joining(","));
|
|
|
+ task.setExecutorId(StringUtils.isEmpty(ids)?null:ids);
|
|
|
+ String names = executorList.stream().filter(f->!StringUtils.isEmpty(f.getExecutorId())).map(TaskExecutor::getExecutorName).collect(Collectors.joining(","));
|
|
|
+ task.setExecutorName(StringUtils.isEmpty(names)?null:names);
|
|
|
+ String colors = executorList.stream().filter(f->!StringUtils.isEmpty(f.getExecutorId())).map(TaskExecutor::getExecutorColor).collect(Collectors.joining(","));
|
|
|
+ task.setExecutorColor(StringUtils.isEmpty(colors)?null:colors);
|
|
|
+ //总时长
|
|
|
+ task.setPlanHours(executorList.stream().mapToInt(TaskExecutor::getPlanHours).sum());
|
|
|
}
|
|
|
//有父任务,需要设置名称
|
|
|
if (task.getParentTid() != null && task.getParentTname() == null) {
|
|
|
task.setParentTname(taskService.getById(task.getParentTid()).getName());
|
|
|
}
|
|
|
boolean isNew = false;
|
|
|
- String msgRecepient = null;
|
|
|
+ List<String> msgRecepientList = new ArrayList<>();
|
|
|
//新建的任务需要计算排序
|
|
|
if (task.getId() == null) {
|
|
|
isNew = true;
|
|
@@ -116,9 +135,8 @@ public class TaskController {
|
|
|
task.setSeq(taskList.get(0).getSeq() + 1);
|
|
|
}
|
|
|
if (task.getExecutorId() != null) {
|
|
|
- msgRecepient = task.getExecutorId();
|
|
|
+ msgRecepientList = task.getExecutorList().stream().filter(exe->exe.getExecutorId() != null).map(TaskExecutor::getExecutorId).collect(Collectors.toList());
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
//更新的情况,需要对比是否修改了任务标题,更新子任务的parentTname
|
|
|
Task oldTask = taskService.getById(task.getId());
|
|
@@ -126,17 +144,28 @@ public class TaskController {
|
|
|
Task sample = new Task();
|
|
|
sample.setParentTname(task.getName());
|
|
|
taskService.update(sample, new QueryWrapper<Task>().eq("parent_tid", task.getId()));
|
|
|
-
|
|
|
- UserRecentTask userRecentTask = new UserRecentTask();
|
|
|
- userRecentTask.setTaskName(task.getName());
|
|
|
- userRecentTaskService.update(userRecentTask, new QueryWrapper<UserRecentTask>().eq("task_id", task.getId()));
|
|
|
}
|
|
|
- if (task.getExecutorId() != null && !task.getExecutorId().equals(oldTask.getExecutorId())) {
|
|
|
- //执行人发生变化
|
|
|
- msgRecepient = task.getExecutorId();
|
|
|
+ List<TaskExecutor> oldExeList = taskExecutorMapper.selectList(new QueryWrapper<TaskExecutor>().eq("task_id", task.getId()));
|
|
|
+ //计算需要移除的执行人
|
|
|
+ List<Integer> ids = oldExeList.stream().filter(old->!task.getExecutorList().stream().anyMatch(newT->newT.getExecutorId().equals(old.getExecutorId())))
|
|
|
+ .map(TaskExecutor::getId).collect(Collectors.toList());
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ taskExecutorService.removeByIds(ids);
|
|
|
}
|
|
|
+
|
|
|
+ task.getExecutorList().forEach(exe->exe.setTaskId(task.getId()));
|
|
|
+ taskExecutorService.saveOrUpdateBatch(task.getExecutorList());
|
|
|
+
|
|
|
+ //新增的执行人
|
|
|
+ msgRecepientList = task.getExecutorList().stream().filter(newT->newT.getExecutorId() != null && !oldExeList.stream().anyMatch(old->newT.getExecutorId().equals(old.getExecutorId())))
|
|
|
+ .map(TaskExecutor::getExecutorId).collect(Collectors.toList());
|
|
|
}
|
|
|
taskService.saveOrUpdate(task);
|
|
|
+ if (isNew) {
|
|
|
+ //保存任务执行人
|
|
|
+ task.getExecutorList().forEach(exe->exe.setTaskId(task.getId()));
|
|
|
+ taskExecutorService.saveBatch(task.getExecutorList());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
TaskComment comment = new TaskComment();
|
|
@@ -147,18 +176,15 @@ public class TaskController {
|
|
|
comment.setContent(user.getName()+(isNew?"创建":"编辑")+"了任务");
|
|
|
taskCommentMapper.insert(comment);
|
|
|
|
|
|
- //更新执行人近期任务
|
|
|
- if (!StringUtils.isEmpty(task.getExecutorId())) {
|
|
|
- saveOrUpdateRecentTask(task, task.getExecutorId());
|
|
|
- }
|
|
|
-
|
|
|
//新增任务,需要重新计算项目进度
|
|
|
if (isNew) {
|
|
|
updateProjectProgress(task.getProjectId());
|
|
|
}
|
|
|
- if (msgRecepient != null) {
|
|
|
- //发消息通知执行人, 待项目id
|
|
|
- informationService.save(new Information().setType(1).setContent(String.valueOf(task.getProjectId())).setUserId(msgRecepient));
|
|
|
+ if (msgRecepientList.size() > 0) {
|
|
|
+ //发消息通知执行人, 带项目id
|
|
|
+ msgRecepientList.forEach(msgRecepient->{
|
|
|
+ informationService.save(new Information().setType(1).setContent(String.valueOf(task.getProjectId())).setUserId(msgRecepient));
|
|
|
+ });
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
@@ -166,7 +192,7 @@ public class TaskController {
|
|
|
private void updateProjectProgress(Integer projectId) {
|
|
|
//更新项目完成度
|
|
|
//只有第一级任务才更新项目进度, 非已撤销状态的
|
|
|
- List<Task> all = taskService.list(new QueryWrapper<Task>().eq("project_id", projectId).isNull("parent_tid").ne("task_status", 2));
|
|
|
+ List<Task> all = taskMapper.simpleList(new QueryWrapper<Task>().eq("project_id", projectId).isNull("parent_tid").ne("task_status", 2));
|
|
|
|
|
|
if (all.size() > 0) {
|
|
|
long running = all.stream().filter(a -> a.getTaskStatus() == 1).count();
|
|
@@ -326,7 +352,7 @@ public class TaskController {
|
|
|
queryWrapper.eq("creater_id", userId);
|
|
|
} else if (viewId == 6) {
|
|
|
//我执行的任务
|
|
|
- queryWrapper.eq("executor_id", userId);
|
|
|
+ queryWrapper.like("executor_id", userId);
|
|
|
} else if (viewId == 7) {
|
|
|
//今天的任务
|
|
|
queryWrapper.eq("end_date", LocalDate.now());
|
|
@@ -338,7 +364,7 @@ public class TaskController {
|
|
|
|
|
|
//普通员工,并且非项目经理,只能看到自己创建的,负责的和待分配的任务
|
|
|
if (user.getRole() == 0 && !userId.equals(project.getInchargerId())) {
|
|
|
- list = list.stream().filter(t->t.getExecutorId() == null || t.getExecutorId().equals(userId) || t.getCreaterId().equals(userId)).collect(Collectors.toList());
|
|
|
+ list = list.stream().filter(t->t.getExecutorId() == null || t.getExecutorId().contains(userId) || t.getCreaterId().equals(userId)).collect(Collectors.toList());
|
|
|
}
|
|
|
//设置列表名称
|
|
|
list.forEach(item->{
|
|
@@ -368,7 +394,7 @@ public class TaskController {
|
|
|
//检查是否已经被认领
|
|
|
Task t = taskService.getById(id);
|
|
|
if (t.getExecutorId() != null) {
|
|
|
- if (t.getExecutorId().equals(userId)) {
|
|
|
+ if (t.getExecutorId().contains(userId)) {
|
|
|
msg.setError("您已认领过该任务,请勿重复操作");
|
|
|
} else {
|
|
|
msg.setError("该任务已被其他人认领");
|
|
@@ -380,29 +406,19 @@ public class TaskController {
|
|
|
task.setExecutorName(user.getName());
|
|
|
task.setExecutorColor(user.getColor());
|
|
|
taskService.updateById(task);
|
|
|
-
|
|
|
- //更新用户近期任务
|
|
|
- saveOrUpdateRecentTask(task, userId);
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- private void saveOrUpdateRecentTask(Task task, String userId) {
|
|
|
- //更新用户近期任务
|
|
|
- List<UserRecentTask> recentTaskList = userRecentTaskService.list(new QueryWrapper<UserRecentTask>().eq("task_id", task.getId()).eq("user_id", userId));
|
|
|
- UserRecentTask recentTask = null;
|
|
|
- if (recentTaskList.size() > 0) {
|
|
|
- recentTask = recentTaskList.get(0);
|
|
|
- if (recentTask != null) {
|
|
|
- userRecentTaskService.removeById(recentTask.getId());
|
|
|
+ //加入执行人表
|
|
|
+ List<TaskExecutor> executorList = taskExecutorMapper.selectList(new QueryWrapper<TaskExecutor>().eq("task_id", id));
|
|
|
+ if (executorList.size() > 0) {
|
|
|
+ TaskExecutor oldExe = executorList.get(0);
|
|
|
+ TaskExecutor.fromTask(task, oldExe);
|
|
|
+ taskExecutorMapper.updateById(oldExe);
|
|
|
+ } else {
|
|
|
+ //不存在,新增一条
|
|
|
+ TaskExecutor executor = TaskExecutor.fromTask(t);
|
|
|
+ taskExecutorMapper.insert(executor);
|
|
|
}
|
|
|
}
|
|
|
- recentTask = new UserRecentTask();
|
|
|
- recentTask.setTaskId(task.getId());
|
|
|
- recentTask.setTaskName(task.getName());
|
|
|
- recentTask.setProjectId(task.getProjectId());
|
|
|
- recentTask.setUserId(userId);
|
|
|
- userRecentTaskService.save(recentTask);
|
|
|
+ return msg;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -414,8 +430,11 @@ public class TaskController {
|
|
|
public HttpRespMsg getTask(Integer id) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
String userId = request.getHeader("Token");
|
|
|
- Task task = new Task();
|
|
|
Task t = taskService.getById(id);
|
|
|
+ if (t == null) {
|
|
|
+ msg.setError("该任务已不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
//查询直接子任务
|
|
|
QueryWrapper<Task> subQuery = new QueryWrapper<Task>().eq("parent_tid", id);
|
|
|
t.setSubTaskList(taskService.list(subQuery));
|
|
@@ -428,6 +447,8 @@ public class TaskController {
|
|
|
String name = userMapper.selectById(list.get(0).getCreatorId()).getName();
|
|
|
list.get(0).setCreatorName(name);
|
|
|
}
|
|
|
+ //查询任务的执行人
|
|
|
+ t.setExecutorList(taskExecutorMapper.selectList(new QueryWrapper<TaskExecutor>().eq("task_id", t.getId())));
|
|
|
msg.data = t;
|
|
|
return msg;
|
|
|
}
|
|
@@ -507,8 +528,6 @@ public class TaskController {
|
|
|
taskLogService.remove(new QueryWrapper<TaskLog>().eq("task_id", id));
|
|
|
//删除留言
|
|
|
taskCommentService.remove(new QueryWrapper<TaskComment>().eq("task_id", id));
|
|
|
- //删除近期任务
|
|
|
- userRecentTaskService.remove(new QueryWrapper<UserRecentTask>().eq("task_id", id));
|
|
|
deleteSubTask(task);
|
|
|
|
|
|
//删除根任务,需要重新计算项目进度
|
|
@@ -527,8 +546,6 @@ public class TaskController {
|
|
|
taskLogService.remove(new QueryWrapper<TaskLog>().in("task_id", collect));
|
|
|
//删除留言
|
|
|
taskCommentService.remove(new QueryWrapper<TaskComment>().in("task_id", collect));
|
|
|
- //删除近期任务
|
|
|
- userRecentTaskService.remove(new QueryWrapper<UserRecentTask>().in("task_id", collect));
|
|
|
subTasks.forEach(s->{
|
|
|
deleteSubTask(s);
|
|
|
});
|
|
@@ -574,7 +591,7 @@ public class TaskController {
|
|
|
queryWrapper.eq("task_status", status);
|
|
|
if (viewId == 1) {
|
|
|
//我执行的任务
|
|
|
- queryWrapper.eq("executor_id", userId);
|
|
|
+ queryWrapper.like("executor_id", userId);
|
|
|
} else if (viewId == 2) {
|
|
|
//我创建的任务
|
|
|
queryWrapper.eq("creater_id", userId);
|