|
|
@@ -0,0 +1,193 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.mocha.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.mocha.vo.TaskStatisticsVO;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springblade.mocha.entity.Task;
|
|
|
+import org.springblade.mocha.vo.TaskVO;
|
|
|
+import org.springblade.mocha.service.ITaskService;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 任务 控制器
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2023-09-28
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/task")
|
|
|
+@Api(value = " 任务", tags = " 任务接口")
|
|
|
+public class TaskController extends BladeController {
|
|
|
+
|
|
|
+ private final ITaskService taskService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ */
|
|
|
+ @GetMapping("/detail")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "详情", notes = "传入task")
|
|
|
+ public R<Task> detail(Task task) {
|
|
|
+ Task detail = taskService.getOne(Condition.getQueryWrapper(task));
|
|
|
+ return R.data(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页 任务
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入task")
|
|
|
+ public R list(Task task, Query query) {
|
|
|
+
|
|
|
+ TaskStatisticsVO taskStatisticsVO = taskService.statistics(AuthUtil.getTenantId());
|
|
|
+
|
|
|
+// QueryWrapper<Task> qw = Condition.getQueryWrapper(task).orderByDesc("create_time", "responsible_user_name");
|
|
|
+ QueryWrapper<Task> qw = new QueryWrapper<>();
|
|
|
+ String tsInfo = task.getTsInfo();
|
|
|
+ if (tsInfo != null && !tsInfo.isEmpty()) {
|
|
|
+ qw.like("ts_info", tsInfo);
|
|
|
+ }
|
|
|
+ Long responsibleUserId = task.getResponsibleUserId();
|
|
|
+ if (responsibleUserId != null) {
|
|
|
+ qw.eq("responsible_user_id", responsibleUserId);
|
|
|
+ }
|
|
|
+ Long postId = task.getPostId();
|
|
|
+ if (postId != null) {
|
|
|
+ qw.eq("post_id", postId);
|
|
|
+ }
|
|
|
+ Integer type = task.getType();
|
|
|
+ if (type != null) {
|
|
|
+ qw.eq("type", type);
|
|
|
+ }
|
|
|
+ List<String> date = task.getCreateTimeSelect();
|
|
|
+ if (date != null) {
|
|
|
+ qw.ge("create_time", date.get(0))
|
|
|
+ .le("create_time", date.get(1));
|
|
|
+ }
|
|
|
+ qw.eq("is_deleted", 0);
|
|
|
+ if (AuthUtil.getUserName() != "admin") {
|
|
|
+ qw.and(qwa -> qwa.like("cc_id", AuthUtil.getUserId())
|
|
|
+ .or().eq("create_user", AuthUtil.getUserId())
|
|
|
+ .or().eq("responsible_user_id", AuthUtil.getUserId()));
|
|
|
+ }
|
|
|
+ qw.orderByDesc("create_time", "responsible_user_name");
|
|
|
+
|
|
|
+ IPage<Task> pages = taskService.page(Condition.getPage(query), qw);
|
|
|
+ for (Task record : pages.getRecords()) {
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ if (record.getType() != 4 && nowTime.isAfter(record.getCompletionTime())) {
|
|
|
+ record.setIsDateExceeded("已超时");
|
|
|
+ } else if (record.getType() == 4 && record.getAccomplishTime().isAfter(record.getCompletionTime())) {
|
|
|
+ record.setIsDateExceeded("已超时");
|
|
|
+ } else {
|
|
|
+ record.setIsDateExceeded("未超时");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("pages", pages);
|
|
|
+ map.put("statistics", taskStatisticsVO);
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义分页 任务
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入task")
|
|
|
+ public R<IPage<TaskVO>> page(TaskVO task, Query query) {
|
|
|
+ IPage<TaskVO> pages = taskService.selectTaskPage(Condition.getPage(query), task);
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增 任务
|
|
|
+ */
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "新增", notes = "传入task")
|
|
|
+ public R save(@Valid @RequestBody Task task) {
|
|
|
+ task.setCreateTime(LocalDateTime.now());
|
|
|
+ return R.status(taskService.save(task));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改 任务
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "修改", notes = "传入task")
|
|
|
+ public R update(@Valid @RequestBody Task task) {
|
|
|
+ task.setUpdateTime(LocalDateTime.now());
|
|
|
+ return R.status(taskService.updateById(task));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改 任务
|
|
|
+ */
|
|
|
+ @PostMapping("/submit")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "新增或修改", notes = "传入task")
|
|
|
+ public R submit(@Valid @RequestBody Task task) {
|
|
|
+ return R.status(taskService.saveOrUpdate(task));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除 任务
|
|
|
+ */
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "删除", notes = "传入ids")
|
|
|
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
|
|
+// return R.status(taskService.removeByIds(Func.toLongList(ids)));
|
|
|
+ List<Long> idList = Func.toLongList(ids);
|
|
|
+ return R.status(taskService.deleteByIds(idList));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询人员完成任务情况
|
|
|
+ */
|
|
|
+ @GetMapping("/completion")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "查询人员完成任务情况", notes = "传入task")
|
|
|
+ public R completion(TaskVO task) {
|
|
|
+ List<TaskStatisticsVO> taskVOList = taskService.completion(task);
|
|
|
+ return R.data(taskVOList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|