|
@@ -1,976 +0,0 @@
|
|
|
-package com.management.platform.controller;
|
|
|
-
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.github.pagehelper.IPage;
|
|
|
-import com.management.platform.entity.*;
|
|
|
-import com.management.platform.entity.vo.SysRichFunction;
|
|
|
-import com.management.platform.mapper.*;
|
|
|
-import com.management.platform.service.*;
|
|
|
-import com.management.platform.util.HttpRespMsg;
|
|
|
-import com.management.platform.util.MessageUtils;
|
|
|
-import org.assertj.core.util.Lists;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.time.Duration;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 前端控制器
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author Seyason
|
|
|
- * @since 2021-04-19
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("/task")
|
|
|
-public class TaskController {
|
|
|
- @Resource
|
|
|
- private HttpServletRequest request;
|
|
|
- @Resource
|
|
|
- private TaskService taskService;
|
|
|
- @Resource
|
|
|
- private ReportMapper reportMapper;
|
|
|
- @Resource
|
|
|
- private StagesService stagesService;
|
|
|
- @Resource
|
|
|
- private ProjectService projectService;
|
|
|
- @Resource
|
|
|
- private UserMapper userMapper;
|
|
|
- @Resource
|
|
|
- private TaskLogService taskLogService;
|
|
|
- @Resource
|
|
|
- private TaskCommentService taskCommentService;
|
|
|
- @Resource
|
|
|
- private InformationService informationService;
|
|
|
- @Resource
|
|
|
- private TaskProgressService taskProgressService;
|
|
|
- @Resource
|
|
|
- private SysFunctionMapper sysFunctionMapper;
|
|
|
- @Resource
|
|
|
- private TprogressPaticipatorsService tprogressPaticipatorsService;
|
|
|
- @Resource
|
|
|
- private TaskCommentMapper taskCommentMapper;
|
|
|
- @Resource
|
|
|
- private TaskMapper taskMapper;
|
|
|
- @Resource
|
|
|
- private TaskExecutorMapper taskExecutorMapper;
|
|
|
- @Resource
|
|
|
- private ParticipationMapper participationMapper;
|
|
|
- @Resource
|
|
|
- private TaskExecutorService taskExecutorService;
|
|
|
-// @Resource
|
|
|
-// private CompanyDingdingService companyDingdingService;
|
|
|
- @Resource
|
|
|
- private WxCorpInfoService wxCorpInfoService;
|
|
|
- @Resource
|
|
|
- private ProjectSeparateMapper projectSeparateMapper;
|
|
|
- @Resource
|
|
|
- private GroupParticipatorMapper groupParticipatorMapper;
|
|
|
- @Resource
|
|
|
- private DepartmentService departmentService;
|
|
|
- @Resource
|
|
|
- private TaskGroupService taskGroupService;
|
|
|
- @Resource
|
|
|
- private TaskAddCtrlMapper taskAddCtrlMapper;
|
|
|
- @Resource
|
|
|
- private TaskRestartMapper taskRestartMapper;
|
|
|
- @Resource
|
|
|
- private TaskPersonLiableMapper taskPersonLiableMapper;
|
|
|
-
|
|
|
- @RequestMapping("/save")
|
|
|
- @Transactional
|
|
|
- public HttpRespMsg save(Task task) throws Exception {
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- String executorListStr = task.getExecutorListStr();
|
|
|
-
|
|
|
- //当前用户
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
-
|
|
|
- //新建的任务,需要设置创建人,创建时间
|
|
|
- if (task.getId() == null) {
|
|
|
- task.setCreateDate(LocalDate.now());
|
|
|
- task.setCreaterId(userId);
|
|
|
- task.setCreaterName(user.getName());
|
|
|
- task.setCreatorColor(user.getColor());
|
|
|
- task.setCompanyId(user.getCompanyId());
|
|
|
- }
|
|
|
- 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());
|
|
|
- });
|
|
|
- executorList.stream().forEach(ex->{
|
|
|
- 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().filter(f->f.getPlanHours() != null).mapToInt(TaskExecutor::getPlanHours).sum());
|
|
|
- //检查执行人是否在当前分组的参与人当中
|
|
|
- List<GroupParticipator> groupParticipatorList = groupParticipatorMapper.selectList(new QueryWrapper<GroupParticipator>().eq("group_id", task.getGroupId()));
|
|
|
- List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().eq("project_id", task.getProjectId()));
|
|
|
- for (TaskExecutor executor : executorList) {
|
|
|
- if(!StringUtils.isEmpty(executor.getExecutorId())){
|
|
|
- boolean b = groupParticipatorList.stream().anyMatch(gp -> gp.getUserId() != null && gp.getUserId().equals(executor.getExecutorId()));
|
|
|
- if(!b){
|
|
|
- GroupParticipator g=new GroupParticipator();
|
|
|
- g.setGroupId(task.getGroupId());
|
|
|
- g.setUserId(executor.getExecutorId());
|
|
|
- groupParticipatorMapper.insert(g);
|
|
|
- }
|
|
|
- boolean b1 = participationList.stream().anyMatch(pl -> pl.getUserId() != null && pl.getUserId().equals(executor.getExecutorId()));
|
|
|
- if(!b1){
|
|
|
- Participation participation=new Participation();
|
|
|
- participation.setUserId(executor.getExecutorId());
|
|
|
- participation.setProjectId(task.getProjectId());
|
|
|
- participationMapper.insert(participation);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //有父任务,需要设置名称
|
|
|
- if (task.getParentTid() != null && task.getParentTname() == null) {
|
|
|
- task.setParentTname(taskService.getById(task.getParentTid()).getName());
|
|
|
- }
|
|
|
- boolean isNew = false;
|
|
|
- boolean needRecalculateProgress = false;
|
|
|
- List<String> msgRecepientList = new ArrayList<>();
|
|
|
- List<Task> needReOrderList = new ArrayList<>();
|
|
|
- //新建的任务需要计算排序
|
|
|
- if (task.getId() == null) {
|
|
|
- isNew = true;
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<Task>();
|
|
|
- queryWrapper.eq("stages_id", task.getStagesId()).eq("task_status", 0).orderByDesc("seq").last("limit 1");
|
|
|
- List<Task> taskList = taskService.list(queryWrapper);
|
|
|
- if (taskList.size() == 0) {
|
|
|
- task.setSeq(1);
|
|
|
- } else {
|
|
|
- task.setSeq(taskList.get(0).getSeq() + 1);
|
|
|
- }
|
|
|
- //比当前创建的这条task的seq大于或者等于的,都要往后排一位
|
|
|
- queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("stages_id", task.getStagesId()).ge("seq", task.getSeq());
|
|
|
- List<Task> oldTaskList = taskMapper.selectList(queryWrapper);
|
|
|
- for (Task t : oldTaskList) {
|
|
|
- Task newT = new Task();
|
|
|
- newT.setId(t.getId());
|
|
|
- newT.setSeq(t.getSeq() + 1);
|
|
|
- needReOrderList.add(newT);
|
|
|
- }
|
|
|
- if (task.getExecutorId() != null) {
|
|
|
- msgRecepientList = task.getExecutorList().stream().filter(exe->!StringUtils.isEmpty(exe.getExecutorId())).map(TaskExecutor::getExecutorId).collect(Collectors.toList());
|
|
|
- }
|
|
|
- if (task.getTaskType() == 1) {
|
|
|
- needRecalculateProgress = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- //更新的情况,需要对比是否修改了任务标题,更新子任务的parentTname
|
|
|
- Task oldTask = taskService.getById(task.getId());
|
|
|
- if (!oldTask.getName().equals(task.getName())) {
|
|
|
- Task sample = new Task();
|
|
|
- sample.setParentTname(task.getName());
|
|
|
- taskService.update(sample, new QueryWrapper<Task>().eq("parent_tid", task.getId()));
|
|
|
- }
|
|
|
- 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.getId()!=null&&newT.getId().equals(old.getId())))
|
|
|
- .map(TaskExecutor::getId).collect(Collectors.toList());
|
|
|
- if (ids.size() > 0) {
|
|
|
- taskExecutorService.removeByIds(ids);
|
|
|
- }
|
|
|
- if (task.getExecutorList().size() > 0) {
|
|
|
- task.getExecutorList().forEach(exe->exe.setTaskId(task.getId()));
|
|
|
- taskExecutorService.saveOrUpdateBatch(task.getExecutorList());
|
|
|
- //新增的执行人
|
|
|
- msgRecepientList = task.getExecutorList().stream().filter(newT->!StringUtils.isEmpty(newT.getExecutorId()) && !oldExeList.stream().anyMatch(old->newT.getExecutorId().equals(old.getExecutorId())))
|
|
|
- .map(TaskExecutor::getExecutorId).collect(Collectors.toList());
|
|
|
- }
|
|
|
- if(task.getStartDate()==null){
|
|
|
- taskMapper.updateStartDate(task.getId());
|
|
|
- }
|
|
|
- if(task.getEndDate()==null){
|
|
|
- taskMapper.updateEndDate(task.getId());
|
|
|
- }
|
|
|
- if(task.getFinishDate()==null){
|
|
|
- taskMapper.updateFinishDate(task.getId());
|
|
|
- }
|
|
|
- if ((oldTask.getTaskType() == 1 && task.getTaskType() != 1) || (oldTask.getTaskType() != 1 && task.getTaskType() == 1)) {
|
|
|
- needRecalculateProgress = true;
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println(task.getStartDate());
|
|
|
- System.out.println(task.getEndDate());
|
|
|
- System.out.println(task.getFinishDate());
|
|
|
- taskService.saveOrUpdate(task);
|
|
|
- if (task.getExecutorId() == null) {
|
|
|
- //清空执行人
|
|
|
- if (!isNew) {
|
|
|
- taskMapper.removeTaskExecutor(task.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- if (isNew) {
|
|
|
- //保存任务执行人
|
|
|
- task.getExecutorList().forEach(exe->exe.setTaskId(task.getId()));
|
|
|
- taskExecutorService.saveBatch(task.getExecutorList());
|
|
|
- //重新调整其他任务的手动排序
|
|
|
- if (needReOrderList.size() > 0) {
|
|
|
- taskService.updateBatchById(needReOrderList);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- TaskComment comment = new TaskComment();
|
|
|
- comment.setTaskId(task.getId());
|
|
|
- comment.setUserId(user.getId());
|
|
|
- comment.setUserName(user.getName());
|
|
|
- comment.setType(isNew?1:2);
|
|
|
- //comment.setContent(user.getName()+(isNew?"创建":"编辑")+"了任务");
|
|
|
- comment.setContent(user.getName()+(isNew?MessageUtils.message("entry.create"):MessageUtils.message("entry.editedTask"))+MessageUtils.message("entry.task"));
|
|
|
- taskCommentMapper.insert(comment);
|
|
|
-
|
|
|
- //需要重新计算项目进度
|
|
|
- if (needRecalculateProgress) {
|
|
|
- updateProjectProgress(task.getProjectId());
|
|
|
- }
|
|
|
- if (msgRecepientList.size() > 0) {
|
|
|
- //发消息通知执行人, 带项目id
|
|
|
- msgRecepientList.forEach(msgRecepient->{
|
|
|
- informationService.save(new Information().setType(1).setContent(String.valueOf(task.getProjectId())).setUserId(msgRecepient));
|
|
|
- });
|
|
|
- List<User> recpUserList = userMapper.selectList(new QueryWrapper<User>().in("id", msgRecepientList));
|
|
|
- if (recpUserList.size() > 0) {
|
|
|
- if (recpUserList.get(0).getDingdingUserid() != null) {
|
|
|
- //钉钉用户
|
|
|
-// CompanyDingding dingding = companyDingdingService.getOne(new QueryWrapper<CompanyDingding>().eq("company_id", user.getCompanyId()));
|
|
|
-// LocalDate endDate = task.getEndDate();
|
|
|
-// String endStr = "";
|
|
|
-// if (endDate != null) {
|
|
|
-// endStr = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(endDate);
|
|
|
-// }
|
|
|
-// companyDingdingService.sendNewTaskMsg(dingding, recpUserList.stream().map(User::getDingdingUserid).collect(Collectors.joining(",")),
|
|
|
-// task.getName(), endStr);
|
|
|
- } else if (recpUserList.get(0).getCorpwxUserid() != null) {
|
|
|
- //企业微信用户
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
- String corpUid = recpUserList.stream().map(User::getCorpwxUserid).distinct().collect(Collectors.joining("|"));
|
|
|
- JSONObject json=new JSONObject();
|
|
|
- JSONArray dataJson=new JSONArray();
|
|
|
- JSONObject jsonObj=new JSONObject();
|
|
|
- jsonObj.put("key", "任务内容");
|
|
|
- jsonObj.put("value",task.getName());
|
|
|
- dataJson.add(jsonObj);
|
|
|
- json.put("template_id","tty9TkCAAAovv416zsWtn0e06CJ635HA");
|
|
|
- json.put("url", "https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww4e237fd6abb635af&redirect_uri=http://worktime.ttkuaiban.com/api/corpWXAuth&response_type=code&scope=snsapi_base&state=task#wechat_redirect");
|
|
|
- json.put("content_item",dataJson);
|
|
|
- //todo:发送消息提醒任务
|
|
|
- wxCorpInfoService.sendWXCorpTemplateMsg(wxCorpInfo, corpUid, json);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- private void updateProjectProgress(Integer projectId) {
|
|
|
- //只有里程碑才更新项目进度, 非已撤销状态的
|
|
|
- List<Task> all = taskMapper.simpleList(new QueryWrapper<Task>().eq("project_id", projectId).ne("task_status", 2).eq("task_type",1),null,null);
|
|
|
- Project project = new Project();
|
|
|
- project.setId(projectId);
|
|
|
- if (all.size() > 0) {
|
|
|
- long running = all.stream().filter(a -> a.getTaskStatus() == 1).count();
|
|
|
- int progress = ((int) running) * 100 / all.size();
|
|
|
- project.setProgress(progress);
|
|
|
- } else {
|
|
|
- project.setProgress(0);
|
|
|
- }
|
|
|
- projectService.updateById(project);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/finish")
|
|
|
- public HttpRespMsg finish(Task task,String personLiableIds,String reason) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- String token = request.getHeader("TOKEN");
|
|
|
- User user = userMapper.selectById(token);
|
|
|
- //进行完成操作时需要检查子任务是否全部完成
|
|
|
- if (task.getTaskStatus() == 0) {
|
|
|
- QueryWrapper<Task> subQuery = new QueryWrapper<Task>();
|
|
|
- subQuery.eq("parent_tid", task.getId()).eq("task_status", 0);
|
|
|
- int count = taskService.count(subQuery);
|
|
|
- if (count > 0) {
|
|
|
- //msg.setError("请先完成全部子任务");
|
|
|
- msg.setError(MessageUtils.message("Stages.SubTasksError"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
- }
|
|
|
- boolean isFinishTask = false;
|
|
|
- if (task.getTaskStatus() == 0) {
|
|
|
- task.setTaskStatus(1);
|
|
|
- isFinishTask = true;
|
|
|
- //计算排序,需要移动到最后
|
|
|
- Task old = taskService.getById(task.getId());
|
|
|
- if (old.getFinishDate() == null) {
|
|
|
- //仅对没有完成日期的任务设置完成日期
|
|
|
- task.setFinishDate(LocalDate.now());
|
|
|
- }
|
|
|
-
|
|
|
- if (task.getParentTid() == null) {
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("stages_id", old.getStagesId()).isNull("parent_tid").orderByDesc("seq").last("limit 1");
|
|
|
- List<Task> afterList = taskService.list(queryWrapper);
|
|
|
- if (afterList.size() > 0) {
|
|
|
- //取第一个,也就是正序排序的最后一个
|
|
|
- Task lastItem = afterList.get(0);
|
|
|
- if (!lastItem.getId().equals(old.getId())) {
|
|
|
- task.setSeq(lastItem.getSeq() + 1);//当前操作的任务不是最后一个的情况下,需要把它排到最后,+1
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- TaskComment taskComment=new TaskComment();
|
|
|
- taskComment.setUserName(user.getName());
|
|
|
- taskComment.setContent(user.getName()+ df.format(LocalDateTime.now())+MessageUtils.message("entry.completeTask"));
|
|
|
- taskComment.setTaskId(task.getId());
|
|
|
- taskComment.setUserId(user.getId());
|
|
|
- taskComment.setCreateTime(LocalDateTime.now());
|
|
|
- taskComment.setType(3);
|
|
|
- taskCommentMapper.insert(taskComment);
|
|
|
- } else if (task.getTaskStatus() == 1) {
|
|
|
- task.setTaskStatus(0);
|
|
|
- TaskComment taskComment=new TaskComment();
|
|
|
- taskComment.setUserName(user.getName());
|
|
|
- taskComment.setContent(user.getName()+ df.format(LocalDateTime.now())+MessageUtils.message("entry.restartTask"));
|
|
|
- taskComment.setTaskId(task.getId());
|
|
|
- taskComment.setUserId(user.getId());
|
|
|
- taskComment.setCreateTime(LocalDateTime.now());
|
|
|
- taskComment.setType(4);
|
|
|
- taskCommentMapper.insert(taskComment);
|
|
|
- TaskRestart taskRestart=new TaskRestart();
|
|
|
- taskRestart.setOperatorId(user.getId());
|
|
|
- taskRestart.setRestartDate(LocalDateTime.now());
|
|
|
- taskRestart.setTaskId(task.getId());
|
|
|
- taskRestart.setRestartReason(reason);
|
|
|
- taskRestart.setTaskCommentId(taskComment.getId());
|
|
|
- taskRestartMapper.insert(taskRestart);
|
|
|
- if(personLiableIds!=null&&!personLiableIds.equals("")){
|
|
|
- String[] split = personLiableIds.split(",");
|
|
|
- List<String> list = Arrays.asList(split);
|
|
|
- for (String s : list) {
|
|
|
- TaskPersonLiable taskPersonLiable=new TaskPersonLiable();
|
|
|
- taskPersonLiable.setPersonLiableId(s);
|
|
|
- taskPersonLiable.setTaskId(task.getId());
|
|
|
- taskPersonLiable.setTaskRestartId(taskRestart.getId());
|
|
|
- taskPersonLiable.setTaskCommentId(taskComment.getId());
|
|
|
- taskPersonLiableMapper.insert(taskPersonLiable);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- //msg.setError("状态不对,无法操作");
|
|
|
- msg.setError(MessageUtils.message("other.stateError"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- taskService.updateById(task);
|
|
|
- ArrayList<Integer> finishedTaskIds = Lists.list(task.getId());
|
|
|
- if (isFinishTask) {
|
|
|
- List<Task> finishedMileStoneList = taskMapper.selectList(new QueryWrapper<Task>().select("id, name, project_id, finish_date").in("id", finishedTaskIds).eq("task_type", 1));
|
|
|
- taskService.notifyMileStoneFinish(user.getCompanyId(), finishedMileStoneList);
|
|
|
- }
|
|
|
-
|
|
|
- //如果是里程碑,需要更新项目完成度
|
|
|
- task = taskMapper.selectById(task.getId());
|
|
|
- if (task.getTaskType() == 1) {
|
|
|
- Integer projectId = task.getProjectId();
|
|
|
- updateProjectProgress(projectId);
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping("/changeOrder")
|
|
|
- public HttpRespMsg changeOrder(Integer id, Integer oldIndex, Integer newIndex, Integer oldStagesId, Integer newStagesId) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- Task curItem = new Task();
|
|
|
- curItem.setId(id);
|
|
|
- if (!oldStagesId.equals(newStagesId)) {
|
|
|
- //获取移动到的目标位置上一个数据的seq,计算当前任务的新seq
|
|
|
- //跨stage移动,旧的stage上移除,切换stages后,旧的任务列表自动会重新排序,不需要再操作
|
|
|
- curItem.setStagesId(newStagesId);
|
|
|
- curItem.setStagesName(stagesService.getById(newStagesId).getStagesName());
|
|
|
- }
|
|
|
-
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<Task>();
|
|
|
- int startSeq = 0;
|
|
|
- if (newIndex > 0) {
|
|
|
- int beforeItemIndex = 0;
|
|
|
- if (oldStagesId.equals(newStagesId)) {
|
|
|
- beforeItemIndex = newIndex > oldIndex?newIndex:newIndex-1;
|
|
|
- } else {
|
|
|
- //跨stages移动,相当于从下往上移动
|
|
|
- beforeItemIndex = newIndex-1;
|
|
|
- }
|
|
|
- queryWrapper.eq("stages_id", newStagesId).isNull("parent_tid").orderByAsc("seq").last("limit " +beforeItemIndex+", 1");
|
|
|
- List<Task> taskList = taskService.list(queryWrapper);
|
|
|
- if (taskList.size() > 0) {
|
|
|
- Task beforeItem = taskList.get(0);
|
|
|
- startSeq = beforeItem.getSeq() + 1;
|
|
|
- } else {
|
|
|
- startSeq = 1;
|
|
|
- }
|
|
|
- } else {
|
|
|
- //移动到了第一个位置
|
|
|
- startSeq = 1;
|
|
|
- }
|
|
|
-
|
|
|
- curItem.setSeq(startSeq);
|
|
|
- //在新位置下面的包括原来占据新位置的,全部调整,从startSeq开始递增
|
|
|
- queryWrapper = new QueryWrapper<Task>();
|
|
|
- queryWrapper.eq("stages_id", newStagesId).isNull("parent_tid").ge("seq", startSeq).orderByAsc("seq");
|
|
|
- List<Task> taskList = taskService.list(queryWrapper);
|
|
|
- if (taskList.size() > 0) {
|
|
|
- List<Task> batchList = new ArrayList<>();
|
|
|
- for (Task t:taskList) {
|
|
|
- Task item = new Task();
|
|
|
- item.setId(t.getId());
|
|
|
- startSeq++;
|
|
|
- item.setSeq(startSeq);
|
|
|
- batchList.add(item);
|
|
|
- }
|
|
|
- taskService.updateBatchById(batchList);
|
|
|
- }
|
|
|
-
|
|
|
- taskService.updateById(curItem);
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping("/list")
|
|
|
- public HttpRespMsg list(Task task, Integer viewId, String order, boolean isDesc,Integer pageIndex,Integer pageSize) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- Integer size=pageSize;
|
|
|
- Integer start=(pageIndex-1)*pageSize;
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- Project project = projectService.getById(task.getProjectId());
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("project_id", task.getProjectId());
|
|
|
- List<Stages> stagesList = stagesService.list(new QueryWrapper<Stages>().eq("project_id", task.getProjectId()));
|
|
|
- if (isDesc) {
|
|
|
- queryWrapper.orderByDesc(order);
|
|
|
- } else {
|
|
|
- queryWrapper.orderByAsc(order);
|
|
|
- }
|
|
|
-
|
|
|
- //按视图查看
|
|
|
- if (viewId == 1) {
|
|
|
- //全部任务
|
|
|
- } else if (viewId == 2) {
|
|
|
- //进行中的任务
|
|
|
- queryWrapper.eq("task_status", 0);
|
|
|
- } else if (viewId == 3) {
|
|
|
- //已完成的任务
|
|
|
- queryWrapper.eq("task_status", 1);
|
|
|
- } else if (viewId == 4) {
|
|
|
- //待安排的任务
|
|
|
- queryWrapper.isNull("executor_id");
|
|
|
- } else if (viewId == 5) {
|
|
|
- //我创建的任务
|
|
|
- queryWrapper.eq("creater_id", userId);
|
|
|
- } else if (viewId == 6) {
|
|
|
- //我执行的任务
|
|
|
- queryWrapper.like("executor_id", userId);
|
|
|
- } else if (viewId == 7) {
|
|
|
- //今天的任务
|
|
|
- queryWrapper.eq("end_date", LocalDate.now());
|
|
|
- } else if (viewId == 8) {
|
|
|
- //已超期的任务,未完成的任务
|
|
|
- queryWrapper.lt("end_date", LocalDate.now()).eq("task_status", 0);
|
|
|
- }
|
|
|
- List<Task> list = taskService.simpleList(queryWrapper,start,size);
|
|
|
- int total = taskMapper.selectCount(queryWrapper);
|
|
|
- //没有权限只能看到自己创建的,负责的和待分配的任务
|
|
|
- List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部任务");
|
|
|
- if (functionList.size() == 0 && !userId.equals(project.getInchargerId())) {
|
|
|
- list = list.stream().filter(t->t.getExecutorId() == null || t.getExecutorId().contains(userId) || userId.equals(t.getCreaterId())).collect(Collectors.toList());
|
|
|
- }
|
|
|
- //设置列表名称
|
|
|
- list.forEach(item->{
|
|
|
- Optional<Stages> first = stagesList.stream().filter(s -> s.getId().equals(item.getStagesId())).findFirst();
|
|
|
- if (first.isPresent()) {
|
|
|
- item.setStagesName(first.get().getStagesName());
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- Map map=new HashMap();
|
|
|
- map.put("records",list);
|
|
|
- map.put("total",total);
|
|
|
- msg.data = map;
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getTaskOnlyList")
|
|
|
- public HttpRespMsg getTaskOnlyList(Integer projectId) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
|
|
|
- //只看任务类型的
|
|
|
- queryWrapper.eq("project_id", projectId).eq("task_type", 0);
|
|
|
- queryWrapper.orderByDesc("id");
|
|
|
- List<Task> list = taskService.nameList(queryWrapper);
|
|
|
- Project project = projectService.getById(projectId);
|
|
|
-
|
|
|
- //没有权限只能看到自己创建的,负责的和待分配的任务
|
|
|
- List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全部任务");
|
|
|
- if (functionList.size() == 0 && !userId.equals(project.getInchargerId())) {
|
|
|
- list = list.stream().filter(t->t.getExecutorId() == null || t.getExecutorId().contains(userId) || t.getCreaterId().equals(userId)).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- msg.data = list;
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加关联的任务
|
|
|
- * @param milestoneId
|
|
|
- * @param taskIds
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/addMileStoneTask")
|
|
|
- public HttpRespMsg addMileStoneTask(Integer milestoneId, String taskIds) {
|
|
|
- return taskService.addMileStoneTask(milestoneId, taskIds);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除关联的任务
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/removeMileStoneTask")
|
|
|
- public HttpRespMsg removeMileStoneTask(Integer id) {
|
|
|
- return taskService.removeMileStoneTask(id);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取关联的任务列表
|
|
|
- * @param milestoneId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/getMilestoneTaskList")
|
|
|
- public HttpRespMsg getMilestoneTaskList(Integer milestoneId) {
|
|
|
- return taskService.getMilestoneTaskList(milestoneId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 认领任务
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/addAsMyTask")
|
|
|
- public HttpRespMsg addAsMyTask(Integer id) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- Task task = new Task();
|
|
|
- //检查是否已经被认领
|
|
|
- Task t = taskService.getById(id);
|
|
|
- if (t.getExecutorId() != null) {
|
|
|
- if (t.getExecutorId().contains(userId)) {
|
|
|
- //msg.setError("您已认领过该任务,请勿重复操作");
|
|
|
- msg.setError(MessageUtils.message("Stages.repeatedCollection"));
|
|
|
- } else {
|
|
|
- //msg.setError("该任务已被其他人认领");
|
|
|
- msg.setError(MessageUtils.message("Stages.receiveError"));
|
|
|
- }
|
|
|
- } else {
|
|
|
- task.setId(id);
|
|
|
- task.setExecutorId(userId);
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- task.setExecutorName(user.getName());
|
|
|
- task.setExecutorColor(user.getColor());
|
|
|
- taskService.updateById(task);
|
|
|
- //加入执行人表
|
|
|
- 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 {
|
|
|
- //不存在,新增一条
|
|
|
- List<TaskExecutor> executors = TaskExecutor.fromTask(task);
|
|
|
- taskExecutorService.saveBatch(executors);
|
|
|
- }
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取任务详情
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/getTask")
|
|
|
- public HttpRespMsg getTask(Integer id) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- Task t = taskService.getById(id);
|
|
|
- if (t == null) {
|
|
|
- //msg.setError("该任务已不存在");
|
|
|
- msg.setError(MessageUtils.message("Stages.noExist"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
- //查询直接子任务
|
|
|
- QueryWrapper<Task> subQuery = new QueryWrapper<Task>().eq("parent_tid", id).orderByAsc("end_date");
|
|
|
- t.setSubTaskList(taskService.list(subQuery));
|
|
|
-
|
|
|
- //查询最新的一条任务进展
|
|
|
- List<TaskProgress> list = taskProgressService.list(new QueryWrapper<TaskProgress>().eq("task_id", id).orderByDesc("id").last("limit 1"));
|
|
|
- if (list.size() > 0) {
|
|
|
- t.setProgress(list.get(0));
|
|
|
- //设置创建人姓名
|
|
|
- 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())));
|
|
|
- //查询项目负责人id以及所属任务分组负责人id
|
|
|
- Project project = projectService.getOne(new QueryWrapper<Project>().eq("id", t.getProjectId()));
|
|
|
- TaskGroup group = taskGroupService.getOne(new QueryWrapper<TaskGroup>().eq("id", t.getGroupId()));
|
|
|
- t.setProjectInchargerId(project.getInchargerId()==null?"":project.getInchargerId());
|
|
|
- t.setGroupInchargerId(group.getInchargerId()==null?"":group.getInchargerId());
|
|
|
- //判断当前用户是否有权限创建任务: 有权限的包括管理全部项目,项目创建人,项目PM, 分组负责人,分组参与人
|
|
|
- List<SysRichFunction> manageAllProjects = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "管理全部项目");
|
|
|
- boolean canAddTask = false;
|
|
|
- Integer companyId = user.getCompanyId();
|
|
|
- TaskAddCtrl taskAddCtrl = taskAddCtrlMapper.selectById(companyId);
|
|
|
- if (taskAddCtrl == null) {
|
|
|
- //没有的话,默认生成一个
|
|
|
- taskAddCtrl = new TaskAddCtrl();
|
|
|
- taskAddCtrl.setCompanyId(companyId);
|
|
|
- taskAddCtrl.setCtrlType(1);//0-普通项目参与人不可添加任务,1-项目参与人可添加,2-仅分组参与人可添加
|
|
|
- taskAddCtrlMapper.insert(taskAddCtrl);
|
|
|
- }
|
|
|
- if (manageAllProjects.size() > 0 || userId.equals(project.getCreatorId()) || userId.equals(project.getInchargerId())) {
|
|
|
- canAddTask = true;
|
|
|
- }
|
|
|
- if (!canAddTask) {
|
|
|
- //进一步判断是否是分组的负责人,参与人
|
|
|
- if (userId.equals(group.getInchargerId())) {
|
|
|
- canAddTask = true;
|
|
|
- }
|
|
|
- if (!canAddTask) {
|
|
|
- Integer ctrlType = taskAddCtrl.getCtrlType();
|
|
|
- if (ctrlType == 1) {
|
|
|
- canAddTask = true;
|
|
|
- } else if (ctrlType == 2) {
|
|
|
- //分组参与人可以创建任务
|
|
|
- int count = groupParticipatorMapper.selectCount(new QueryWrapper<GroupParticipator>().eq("user_id", userId).eq("group_id", group.getId()));
|
|
|
- if (count > 0) {
|
|
|
- canAddTask = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- t.setCanAddTask(canAddTask);
|
|
|
- msg.data = t;
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getSubTask")
|
|
|
- public HttpRespMsg getSubTask(Integer id) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
-
|
|
|
- //查询直接子任务
|
|
|
- QueryWrapper<Task> subQuery = new QueryWrapper<Task>().eq("parent_tid", id).orderByAsc("end_date");
|
|
|
- msg.data = taskService.list(subQuery);
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getRecentTask")
|
|
|
- public HttpRespMsg getRecentTask(Integer projectId,
|
|
|
- @RequestParam(required = false, defaultValue = "0") Integer isSubstitude) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- if (isSubstitude == 0) {
|
|
|
- msg.data = taskMapper.recentSimpleList(projectId, userId);
|
|
|
- } else {
|
|
|
- //代填的情况,获取的是项目中的所有任务
|
|
|
- msg.data = taskMapper.recentSimpleList(projectId, null);
|
|
|
- }
|
|
|
-
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping("/getMileStoneList")
|
|
|
- public HttpRespMsg getMileStoneList(Integer projectId) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
-
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<Task>().eq("project_id", projectId).eq("task_type", 1);
|
|
|
- queryWrapper.orderByAsc("end_date is null").orderByAsc("end_date");
|
|
|
- msg.data = taskService.list(queryWrapper);
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @RequestMapping("/getExecutorPanel")
|
|
|
- public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
|
- return taskService.getExecutorPanel(projectId);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getExecutorPlanHour")
|
|
|
- public HttpRespMsg getExecutorPlanHour(Integer projectId){
|
|
|
- return taskService.getExecutorPlanHour(projectId);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getStagesPanel")
|
|
|
- public HttpRespMsg getStagesPanel(Integer projectId) {
|
|
|
- return taskService.getStagesPanel(projectId);
|
|
|
- }
|
|
|
- @RequestMapping("/getTopCostTask")
|
|
|
- public HttpRespMsg getTopCostTask(Integer projectId) {
|
|
|
- return taskService.getTopCostTask(projectId);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/delete")
|
|
|
- public HttpRespMsg delete(Integer id) {
|
|
|
- Task task = taskService.getById(id);
|
|
|
- if (task == null) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- //msg.setError("该任务不存在,请刷新查看");
|
|
|
- msg.setError(MessageUtils.message("Stages.noExistAndRefresh"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- if (task.getParentTid() == null) {
|
|
|
- //删除的是第一级任务,需要调整顺序
|
|
|
- List<Task> afterList = taskService.list(new QueryWrapper<Task>().eq("stages_id", task.getStagesId()).isNull("parent_tid").gt("seq", task.getSeq()));
|
|
|
- if (afterList.size() > 0) {
|
|
|
- List<Task> finalList = new ArrayList<>();
|
|
|
- afterList.forEach(a->{
|
|
|
- Task t = new Task();
|
|
|
- t.setId(a.getId());
|
|
|
- t.setSeq(a.getSeq() -1);
|
|
|
- finalList.add(t);
|
|
|
- });
|
|
|
- taskService.updateBatchById(finalList);
|
|
|
- }
|
|
|
- }
|
|
|
- long cnt = reportMapper.selectCount(new QueryWrapper<Report>().eq("task_id", id));
|
|
|
- if (cnt > 0) {
|
|
|
- reportMapper.deleteReportTask(id);
|
|
|
- }
|
|
|
- taskService.removeById(id);
|
|
|
- //删除任务日志
|
|
|
- taskLogService.remove(new QueryWrapper<TaskLog>().eq("task_id", id));
|
|
|
- //删除留言
|
|
|
- taskCommentService.remove(new QueryWrapper<TaskComment>().eq("task_id", id));
|
|
|
- deleteSubTask(task);
|
|
|
-
|
|
|
-
|
|
|
- //删除里程碑,需要重新计算项目进度
|
|
|
- if (task.getTaskType() == 1) {
|
|
|
- updateProjectProgress(task.getProjectId());
|
|
|
- }
|
|
|
- return new HttpRespMsg();
|
|
|
- }
|
|
|
-
|
|
|
- private void deleteSubTask(Task task) {
|
|
|
- List<Task> subTasks = taskService.list(new QueryWrapper<Task>().eq("parent_tid", task.getId()));
|
|
|
- if (subTasks.size() > 0) {
|
|
|
- taskService.remove(new QueryWrapper<Task>().eq("parent_tid", task.getId()));
|
|
|
- List<Integer> collect = subTasks.stream().map(Task::getId).collect(Collectors.toList());
|
|
|
- //删除任务日志
|
|
|
- taskLogService.remove(new QueryWrapper<TaskLog>().in("task_id", collect));
|
|
|
- //删除留言
|
|
|
- taskCommentService.remove(new QueryWrapper<TaskComment>().in("task_id", collect));
|
|
|
- subTasks.forEach(s->{
|
|
|
- deleteSubTask(s);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/getTaskTimeCompare")
|
|
|
- public HttpRespMsg getTaskTimeCompare(Integer projectId) {
|
|
|
- return taskService.getTaskTimeCompare(projectId);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/exportTaskTimeCompare")
|
|
|
- public HttpRespMsg exportTaskTimeCompare(Integer projectId) {
|
|
|
- return taskService.exportTaskTimeCompare(projectId);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("exportTask")
|
|
|
- public HttpRespMsg exportTask(Integer projectId, Integer taskType) {
|
|
|
- return taskService.exportTask(projectId, taskType);
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/importTask")
|
|
|
- public HttpRespMsg importUser(Integer projectId, Integer groupId, @RequestParam MultipartFile file) {
|
|
|
- return taskService.importTask(projectId, groupId, file, request);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * task/listByPage获取待办任务列表
|
|
|
- * @param status 0-进行中,1-已完成
|
|
|
- * @param viewId 1-我执行的任务, 2-我创建的任务
|
|
|
- * @param pageIndex
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping("/listByPage")
|
|
|
- public HttpRespMsg listByPage(Integer status, Integer viewId, Integer pageIndex, Integer pageSize,Integer type,Integer dateType,String startDate,String endDate,Integer deptId) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- String userId = request.getHeader("Token");
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- Integer companyId = user.getCompanyId();
|
|
|
- QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
|
|
|
-
|
|
|
- //任务状态
|
|
|
- queryWrapper.eq("task_status", status).eq("task.company_id", companyId);
|
|
|
- if (viewId == 1) {
|
|
|
- //我执行的任务
|
|
|
- queryWrapper.like("executor_id", userId);
|
|
|
- } else if (viewId == 2) {
|
|
|
- //我创建的任务
|
|
|
- queryWrapper.eq("creater_id", userId);
|
|
|
- }
|
|
|
- if(type!=null){
|
|
|
- queryWrapper.eq("task_type",type);
|
|
|
- }
|
|
|
- if(dateType!=null){
|
|
|
- switch (dateType){
|
|
|
- case 0:
|
|
|
- queryWrapper.ge("start_date",startDate).le("start_date",endDate);
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- queryWrapper.ge("task.end_date",startDate).le("task.end_date",endDate);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-// else if (viewId == 3) {
|
|
|
-// //今天的任务
|
|
|
-// queryWrapper.eq("end_date", LocalDate.now());
|
|
|
-// } else if (viewId == 4) {
|
|
|
-// //已超期的任务,未完成的任务
|
|
|
-// queryWrapper.lt("end_date", LocalDate.now()).eq("task_status", 0);
|
|
|
-// }
|
|
|
- List<Integer> branchDepartment=null;
|
|
|
- if(deptId!=null){
|
|
|
- List<Department> departmentList=departmentService.list(new QueryWrapper<Department>().eq("company_id",companyId));
|
|
|
- branchDepartment= getBranchDepartment(deptId, departmentList);
|
|
|
- }
|
|
|
- List<Task> list = taskMapper.getTaskWithProjectName(queryWrapper, (pageIndex-1)*pageSize, pageSize,companyId,branchDepartment);
|
|
|
- List<Integer> collect = list.stream().map(l -> l.getId()).distinct().collect(Collectors.toList());
|
|
|
- collect.add(-1);
|
|
|
- List<TaskExecutor> taskExecutorList = taskExecutorMapper.selectList(new QueryWrapper<TaskExecutor>().in("task_id", collect));
|
|
|
- list.forEach(l->{
|
|
|
- List<TaskExecutor> executorList = taskExecutorList.stream().filter(tl -> tl.getTaskId().equals(l.getId())&&tl.getExecutorId()!=null).collect(Collectors.toList());
|
|
|
- l.setExecutorList(executorList);
|
|
|
- });
|
|
|
- int total = taskMapper.selectCount(queryWrapper);
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("records", list);
|
|
|
- map.put("total", total);
|
|
|
- msg.data = map;
|
|
|
- return msg;
|
|
|
- }
|
|
|
- private List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
|
|
|
- List<Integer> list = new ArrayList<>();
|
|
|
- list.add(departmentId);
|
|
|
- //搜到子部门进行添加
|
|
|
- for (Department department : departmentList) {
|
|
|
- if (departmentId.equals(department.getSuperiorId())) {
|
|
|
- list.addAll(getBranchDepartment(department.getDepartmentId(), departmentList));
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
- @RequestMapping("/getGroupNameList")
|
|
|
- public HttpRespMsg getGroupNameList(HttpServletRequest request){
|
|
|
- HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
- List<Project> projectList = projectService.list(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
- List<Integer> collect = projectList.stream().map(Project::getId).distinct().collect(Collectors.toList());
|
|
|
- List<ProjectSeparate> projectSeparateList = projectSeparateMapper.selectList(new QueryWrapper<ProjectSeparate>().in("id", collect));
|
|
|
- List<String> nameList = projectSeparateList.stream().map(ProjectSeparate::getProjectCategorySub).distinct().collect(Collectors.toList());
|
|
|
- httpRespMsg.data=nameList;
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
-
|
|
|
- @RequestMapping("/operateMeeting")
|
|
|
- public HttpRespMsg operateMeeting(HttpServletRequest request,Integer taskId,String startTime,String endTime) throws Exception {
|
|
|
- HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- User user = userMapper.selectById(request.getHeader("token"));
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoService.list(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId())).get(0);
|
|
|
- Task task = taskMapper.selectById(taskId);
|
|
|
- DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- LocalDateTime start = LocalDateTime.parse(startTime, df);
|
|
|
- if(start.isBefore(LocalDateTime.now())){
|
|
|
- httpRespMsg.setError("开始时间必须大于当前时间");
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
- LocalDateTime end = LocalDateTime.parse(endTime, df);
|
|
|
- if(end.isBefore(start)){
|
|
|
- httpRespMsg.setError("结束时间必须大于开始时间");
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
- Duration between = Duration.between(start, end);
|
|
|
- List<TaskExecutor> taskExecutorList = taskExecutorMapper.selectList(new QueryWrapper<TaskExecutor>().eq("task_id", task.getId()));
|
|
|
- if(taskExecutorList.size()>0){
|
|
|
- List<String> list = taskExecutorList.stream().map(TaskExecutor::getExecutorId).distinct().collect(Collectors.toList());
|
|
|
- String userIds = userMapper.selectList(new QueryWrapper<User>().in("id", list)).stream().map(User::getCorpwxUserid).distinct().collect(Collectors.joining("|"));
|
|
|
- String meetingResp;
|
|
|
- if(!StringUtils.isEmpty(task.getMeetingId())){
|
|
|
- meetingResp = wxCorpInfoService.operateMeeting(userIds, "工时管家任务", task.getName(), startTime, between.getSeconds(),wxCorpInfo, "update", task.getMeetingId());
|
|
|
- }else {
|
|
|
- meetingResp = wxCorpInfoService.operateMeeting(userIds,"工时管家任务",task.getName(),startTime,between.getSeconds(),wxCorpInfo,"create",null);
|
|
|
- if(!meetingResp.contains("invalid")){
|
|
|
- task.setMeetingId(meetingResp);
|
|
|
- taskMapper.updateById(task);
|
|
|
- }
|
|
|
- }
|
|
|
- httpRespMsg.data=meetingResp;
|
|
|
- }else httpRespMsg.setError("该任务无执行人");
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
- @RequestMapping("/getMeeting")
|
|
|
- public HttpRespMsg getMeeting(Integer taskId) throws Exception {
|
|
|
- HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- User user = userMapper.selectById(request.getHeader("token"));
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoService.list(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId())).get(0);
|
|
|
- Task task = taskMapper.selectById(taskId);
|
|
|
- String meetingInfo = wxCorpInfoService.operateMeeting(null, null, null, null, 300, wxCorpInfo, "get_info", task.getMeetingId());
|
|
|
- httpRespMsg.data=meetingInfo;
|
|
|
- return httpRespMsg;
|
|
|
- }
|
|
|
-}
|
|
|
-
|