package com.qqflow.engine.domain.flow.controller; import com.qqflow.engine.common.PageResult; import com.qqflow.engine.common.Result; import com.qqflow.engine.common.exception.BusinessException; import com.qqflow.engine.common.util.SecurityUtils; import com.qqflow.engine.config.security.LoginUser; import com.qqflow.engine.domain.flow.dto.ApprovalRecordDTO; import com.qqflow.engine.domain.flow.dto.ApprovalTaskDTO; import com.qqflow.engine.domain.flow.dto.ApproveTaskDTO; import com.qqflow.engine.domain.flow.dto.BatchTaskDTO; import com.qqflow.engine.domain.flow.dto.NextNodeDTO; import com.qqflow.engine.domain.flow.dto.TransferTaskDTO; import com.qqflow.engine.domain.flow.service.ApprovalTaskService; import com.qqflow.engine.domain.system.dto.UserDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/flow/task") @RequiredArgsConstructor @Tag(name = "审批任务管理") public class ApprovalTaskController { private final ApprovalTaskService approvalTaskService; @GetMapping("/todo") @Operation(summary = "我的待办列表") public Result> todoList( @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) String processName, @RequestParam(required = false) String formFilters) { Long assigneeId = SecurityUtils.getUserId(); String assigneeType = requireLoginUser().getUserType(); return Result.ok(this.approvalTaskService.todoList(assigneeId, assigneeType, processName, formFilters, pageNum, pageSize)); } @GetMapping("/handled") @Operation(summary = "我的已办列表") public Result> handledList( @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) String processName) { Long assigneeId = SecurityUtils.getUserId(); String assigneeType = requireLoginUser().getUserType(); return Result.ok(this.approvalTaskService.handledList(assigneeId, assigneeType, processName, pageNum, pageSize)); } @GetMapping("/{taskId}/next-nodes") @Operation(summary = "获取当前任务的下游节点列表(条件节点选分支用)") public Result> nextNodes(@PathVariable Long taskId) { return Result.ok(this.approvalTaskService.getNextNodes(taskId)); } @PostMapping("/{taskId}/approve") @Operation(summary = "审批通过") public Result approve(@PathVariable Long taskId, @RequestBody @Valid ApproveTaskDTO dto) { dto.setTaskId(taskId); this.approvalTaskService.approve(dto); return Result.ok(); } @PostMapping("/{taskId}/reject") @Operation(summary = "审批拒绝") public Result reject(@PathVariable Long taskId, @RequestBody @Valid ApproveTaskDTO dto) { dto.setTaskId(taskId); this.approvalTaskService.reject(dto); return Result.ok(); } @PostMapping("/batch-approve") @Operation(summary = "批量审批通过") public Result batchApprove(@RequestBody @Valid BatchTaskDTO dto) { this.approvalTaskService.batchApprove(dto); return Result.ok(); } @PostMapping("/batch-reject") @Operation(summary = "批量审批拒绝") public Result batchReject(@RequestBody @Valid BatchTaskDTO dto) { this.approvalTaskService.batchReject(dto); return Result.ok(); } @PostMapping("/{taskId}/return") @Operation(summary = "审批回退") public Result returnTask(@PathVariable Long taskId, @RequestBody @Valid ApproveTaskDTO dto) { dto.setTaskId(taskId); this.approvalTaskService.returnTask(dto); return Result.ok(); } @PostMapping("/{taskId}/transfer") @Operation(summary = "任务转办") public Result transfer(@PathVariable Long taskId, @RequestBody @Valid TransferTaskDTO dto) { dto.setTaskId(taskId); this.approvalTaskService.transfer(dto); return Result.ok(); } @PostMapping("/{taskId}/add-sign") @Operation(summary = "任务加签") public Result addSign(@PathVariable Long taskId, @RequestParam Long assigneeId) { this.approvalTaskService.addSign(taskId, assigneeId); return Result.ok(); } @GetMapping("/history/{instanceId}") @Operation(summary = "审批历史记录") public Result> history(@PathVariable Long instanceId) { return Result.ok(this.approvalTaskService.history(instanceId)); } @GetMapping("/todo-count") @Operation(summary = "我的待办任务数") public Result todoCount() { Long assigneeId = SecurityUtils.getUserId(); String assigneeType = requireLoginUser().getUserType(); return Result.ok(this.approvalTaskService.todoCount(assigneeId, assigneeType)); } @GetMapping("/cc") @Operation(summary = "我的抄送列表") public Result> ccList( @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @RequestParam(required = false) String processName) { Long assigneeId = SecurityUtils.getUserId(); String assigneeType = requireLoginUser().getUserType(); return Result.ok(this.approvalTaskService.ccList(assigneeId, assigneeType, processName, pageNum, pageSize)); } @PostMapping("/cc/{taskId}/read") @Operation(summary = "标记抄送已读") public Result readCc(@PathVariable Long taskId) { this.approvalTaskService.readCc(taskId); return Result.ok(); } @GetMapping("/{taskId}/transferable-users") @Operation(summary = "获取可转办/加签的用户列表") public Result> transferableUsers(@PathVariable Long taskId) { return Result.ok(this.approvalTaskService.getTransferableUsers(taskId)); } private LoginUser requireLoginUser() { LoginUser loginUser = SecurityUtils.getLoginUser(); if (loginUser == null) { throw new BusinessException("未登录"); } return loginUser; } }