From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master

---
 jnpf-flowable/jnpf-flowable-controller/src/main/java/jnpf/flowable/controller/TaskController.java |  348 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 348 insertions(+), 0 deletions(-)

diff --git a/jnpf-flowable/jnpf-flowable-controller/src/main/java/jnpf/flowable/controller/TaskController.java b/jnpf-flowable/jnpf-flowable-controller/src/main/java/jnpf/flowable/controller/TaskController.java
new file mode 100644
index 0000000..e46f7d8
--- /dev/null
+++ b/jnpf-flowable/jnpf-flowable-controller/src/main/java/jnpf/flowable/controller/TaskController.java
@@ -0,0 +1,348 @@
+package jnpf.flowable.controller;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.google.common.collect.ImmutableMap;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jnpf.base.ActionResult;
+import jnpf.base.Pagination;
+import jnpf.base.UserInfo;
+import jnpf.base.controller.SuperController;
+import jnpf.base.vo.PageListVO;
+import jnpf.base.vo.PaginationVO;
+import jnpf.config.ConfigValueUtil;
+import jnpf.constant.MsgCode;
+import jnpf.database.util.TenantDataSourceUtil;
+import jnpf.exception.WorkFlowException;
+import jnpf.flowable.entity.EventLogEntity;
+import jnpf.flowable.entity.TaskEntity;
+import jnpf.flowable.enums.EventEnum;
+import jnpf.flowable.enums.TaskStatusEnum;
+import jnpf.flowable.model.candidates.CandidateUserVo;
+import jnpf.flowable.model.outside.OutsideModel;
+import jnpf.flowable.model.task.*;
+import jnpf.flowable.model.template.BeforeInfoVo;
+import jnpf.flowable.model.trigger.TriggerInfoModel;
+import jnpf.flowable.model.util.FlowNature;
+import jnpf.flowable.service.EventLogService;
+import jnpf.flowable.service.TaskService;
+import jnpf.flowable.service.TriggerTaskService;
+import jnpf.flowable.util.*;
+import jnpf.permission.entity.UserEntity;
+import jnpf.util.*;
+import jnpf.util.context.RequestContext;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * 娴佺▼浠诲姟
+ *
+ * @author JNPF@YinMai Info. Co., Ltd
+ * @version 5.0.x
+ * @since 2024/4/17 15:13
+ */
+@Tag(name = "娴佺▼浠诲姟", description = "TaskController")
+@RestController
+@RequestMapping("/task")
+@RequiredArgsConstructor
+public class TaskController extends SuperController<TaskService, TaskEntity> {
+
+
+    private final FlowUtil flowUtil;
+
+    private final ServiceUtil serviceUtil;
+
+    private final OutsideUtil outsideUtil;
+
+    private final OperatorUtil operatorUtil;
+
+    private final ConfigValueUtil configValueUtil;
+
+
+    private final TaskService taskService;
+
+    private final EventLogService eventLogService;
+
+    private final TriggerTaskService triggerTaskService;
+
+    /**
+     * 璇︽儏
+     *
+     * @param id 浠诲姟id
+     * @param fo 鍙傛暟绫�
+     */
+    @Operation(summary = "璇︽儏")
+    @GetMapping("/{id}")
+    public ActionResult<Object> getInfo(@PathVariable("id") String id, FlowModel fo) throws WorkFlowException {
+        String fileNameAll = DesUtil.aesOrDecode(id, false, true);
+        int i1 = fileNameAll.indexOf(",");
+        int i2 = fileNameAll.lastIndexOf(",");
+        id = fileNameAll.substring(i1 + 1, i2);
+        if (!Objects.equals(id, UserProvider.getLoginUserId())) {
+            throw new WorkFlowException(MsgCode.FA021.getMsg());
+        }
+        String taskId = fileNameAll.substring(0, i1);
+        if (ObjectUtil.equals(fo.getType(), 2)) {
+            TriggerInfoModel triggerInfo = triggerTaskService.getInfo(taskId);
+            return ActionResult.success(triggerInfo);
+        }
+        return ActionResult.success(taskService.getInfo(taskId, fo));
+    }
+
+    /**
+     * 鏆傚瓨鎴栨彁浜�
+     *
+     * @param fo 鍙傛暟绫�
+     */
+    @Operation(summary = "鏆傚瓨鎴栨彁浜�")
+    @PostMapping
+    public ActionResult<AuditModel> saveOrSubmit(@RequestBody FlowModel fo) throws WorkFlowException {
+        taskService.batchSaveOrSubmit(fo);
+        operatorUtil.handleOperator();
+        if (ObjectUtil.equals(TaskStatusEnum.RUNNING.getCode(), fo.getStatus())) {
+            operatorUtil.handleTaskStatusThenEvent(fo, EventEnum.INIT.getStatus());
+        }
+        TaskEntity taskEntity = fo.getTaskEntity();
+        if (taskEntity.getRejectDataId() == null) {
+            operatorUtil.autoAudit(fo);
+            operatorUtil.launchTrigger(fo);
+            operatorUtil.handleOperator();
+            operatorUtil.handleTaskStatusThenEvent();
+        } else {
+            operatorUtil.handleTaskStatus();
+        }
+        String msg = TaskStatusEnum.TO_BE_SUBMIT.getCode().equals(fo.getStatus()) ? MsgCode.SU002.get() : MsgCode.SU006.get();
+        TaskEntity task = taskService.getById(taskEntity.getId());
+        taskEntity = task == null ? taskEntity : task;
+        AuditModel model = operatorUtil.getAuditModel(taskEntity.getId(), fo, null);
+        return ActionResult.success(msg, model);
+    }
+
+    /**
+     * 鏆傚瓨鎴栨彁浜わ紝宸叉殏瀛樼殑鍐嶆鏆傚瓨鎴栨彁浜�
+     *
+     * @param id 浠诲姟涓婚敭
+     * @param fo 鍙傛暟
+     */
+    @Operation(summary = "鏆傚瓨鎴栨彁浜�(鎴戝彂璧风殑)")
+    @PutMapping("/{id}")
+    public ActionResult<Object> saveOrSubmit(@PathVariable("id") String id, @RequestBody FlowModel fo) throws WorkFlowException {
+        Map<String, Object> data = fo.getFormData();
+        String flowTaskID = Objects.nonNull(data.get(FlowFormConstant.FLOWTASKID)) ? data.get(FlowFormConstant.FLOWTASKID).toString() : id;
+        fo.setId(flowTaskID);
+        TaskEntity taskEntity = taskService.getById(flowTaskID);
+        if (taskEntity != null) {
+            flowUtil.isSuspend(taskEntity);
+            flowUtil.isCancel(taskEntity);
+        }
+        taskService.batchSaveOrSubmit(fo);
+        operatorUtil.handleOperator();
+        if (ObjectUtil.equals(TaskStatusEnum.RUNNING.getCode(), fo.getStatus())) {
+            operatorUtil.handleTaskStatusThenEvent(fo, EventEnum.INIT.getStatus());
+        }
+        taskEntity = fo.getTaskEntity();
+        if (taskEntity.getRejectDataId() == null) {
+            operatorUtil.autoAudit(fo);
+            operatorUtil.launchTrigger(fo);
+            operatorUtil.handleOperator();
+            operatorUtil.handleTaskStatusThenEvent();
+        } else {
+            operatorUtil.handleTaskStatus();
+        }
+        TaskEntity task = taskService.getById(taskEntity.getId());
+        taskEntity = task == null ? taskEntity : task;
+        String msg = TaskStatusEnum.TO_BE_SUBMIT.getCode().equals(fo.getStatus()) ? MsgCode.SU002.get() : MsgCode.SU006.get();
+        AuditModel model = operatorUtil.getAuditModel(taskEntity.getId(), fo, null);
+        return ActionResult.success(msg, model);
+    }
+
+    /**
+     * 鍒犻櫎
+     *
+     * @param id 涓婚敭
+     */
+    @Operation(summary = "鍒犻櫎")
+    @DeleteMapping("/{id}")
+    public ActionResult<String> delete(@PathVariable("id") String id) throws WorkFlowException {
+        taskService.delete(id);
+        return ActionResult.success(MsgCode.SU003.get());
+    }
+
+    /**
+     * 鎴戝彂璧风殑 鍒楄〃
+     *
+     * @param pagination 鍒嗛〉鍙傛暟
+     */
+    @Operation(summary = "鎴戝彂璧风殑")
+    @GetMapping
+    public ActionResult<PageListVO<TaskVo>> list(TaskPagination pagination) {
+        pagination.setSystemId(serviceUtil.getSystemCodeById(RequestContext.getAppCode()));
+        List<TaskVo> list = taskService.getList(pagination);
+        List<TaskVo> voList = new ArrayList<>();
+        List<UserEntity> userList = serviceUtil.getUserName(list.stream().map(TaskVo::getCreatorUser).collect(Collectors.toList()));
+        for (TaskVo vo : list) {
+            UserEntity userEntity = userList.stream().filter(t -> t.getId().equals(vo.getCreatorUser())).findFirst().orElse(null);
+            vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : "");
+            voList.add(vo);
+        }
+        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
+        return ActionResult.page(voList, paginationVO);
+    }
+
+    /**
+     * 鍙戣捣鎾ゅ洖
+     *
+     * @param id 浠诲姟涓婚敭
+     */
+    @Operation(summary = "鍙戣捣鎾ゅ洖")
+    @PutMapping("/Recall/{id}")
+    public ActionResult<String> recall(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws WorkFlowException {
+        taskService.recall(id, flowModel);
+        operatorUtil.handleTaskStatusThenEvent(flowModel, EventEnum.FLOW_RECALL.getStatus());
+        return ActionResult.success(MsgCode.WF008.get());
+    }
+
+    /**
+     * 鍌姙
+     *
+     * @param id 浠诲姟涓婚敭
+     */
+    @Operation(summary = "鍌姙")
+    @PostMapping("/Press/{id}")
+    public ActionResult<String> press(@PathVariable("id") String id) throws WorkFlowException {
+        if (taskService.press(id)) {
+            return ActionResult.success(MsgCode.WF022.get());
+        }
+        return ActionResult.fail(MsgCode.WF023.get());
+    }
+
+    /**
+     * 鎾ら攢
+     *
+     * @param id 浠诲姟涓婚敭
+     */
+    @Operation(summary = "鎾ら攢")
+    @PutMapping("/Revoke/{id}")
+    public ActionResult<String> revoke(@PathVariable("id") String id, @RequestBody FlowModel flowModel) throws WorkFlowException {
+        taskService.revoke(id, flowModel);
+        return ActionResult.success(MsgCode.SU006.get());
+    }
+
+    /**
+     * 鑾峰彇娴佺▼鎵�鍏宠仈鐨勭敤鎴蜂俊鎭�
+     *
+     * @param id         浠诲姟涓婚敭
+     * @param pagination 鍒嗛〉鍙傛暟
+     */
+    @Operation(summary = "鑾峰彇娴佺▼鎵�鍏宠仈鐨勭敤鎴蜂俊鎭�")
+    @GetMapping("/TaskUserList/{id}")
+    public ActionResult<PageListVO<CandidateUserVo>> getTaskUserList(@PathVariable("id") String id, Pagination pagination) {
+        TaskUserListModel model = taskService.getTaskUserList(id);
+        String admin = serviceUtil.getAdmin();
+        List<String> allUserIdList = model.getAllUserIdList();
+        allUserIdList.remove(admin);
+        List<CandidateUserVo> userList = operatorUtil.getUserModel(allUserIdList, pagination);
+        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
+        return ActionResult.page(userList, paginationVO);
+    }
+
+    /**
+     * 瀛愭祦绋嬭鎯�
+     *
+     * @param flowModel 鍙傛暟
+     */
+    @Operation(summary = "瀛愭祦绋嬭鎯�")
+    @GetMapping("/SubFlowInfo")
+    public ActionResult<Object> subFlowInfo(FlowModel flowModel) throws WorkFlowException {
+        List<BeforeInfoVo> list = taskService.subFlowInfo(flowModel);
+        return ActionResult.success(list);
+    }
+
+    /**
+     * 鏌ョ湅鍙戣捣琛ㄥ崟
+     *
+     * @param taskId 浠诲姟涓婚敭
+     */
+    @Operation(summary = "鏌ョ湅鍙戣捣琛ㄥ崟")
+    @GetMapping("/ViewStartForm/{taskId}")
+    public ActionResult<Object> getStartForm(@PathVariable("taskId") String taskId) throws WorkFlowException {
+        ViewFormModel model = taskService.getStartForm(taskId);
+        return ActionResult.success(model);
+    }
+
+    /**
+     * 澶栭儴閲嶈瘯
+     */
+    @Operation(summary = "澶栭儴閲嶈瘯")
+    @GetMapping("/Hooks/Retry/{id}")
+    public ActionResult<Object> outsideRetry(@PathVariable("id") String id) throws WorkFlowException {
+        boolean retryResult = outsideUtil.retry(id);
+        return ActionResult.success(MsgCode.SU005.get(), retryResult);
+    }
+
+    /**
+     * 澶栭儴瀹℃壒
+     */
+    @Operation(summary = "澶栭儴瀹℃壒")
+    @PostMapping("/Hooks")
+    @NoDataSourceBind
+    public ActionResult<Object> outside(@RequestParam(value = "tenantId", required = false) String tenantId, @RequestBody Map<String, Object> body) throws WorkFlowException {
+        if (configValueUtil.isMultiTenancy() && StringUtil.isNotEmpty(tenantId)) {
+            // 鍒ゆ柇鏄笉鏄粠澶栭潰鐩存帴璇锋眰
+
+            //鍒囨崲鎴愮鎴峰簱
+            try {
+                TenantDataSourceUtil.switchTenant(tenantId);
+            } catch (Exception e) {
+                return ActionResult.fail(MsgCode.LOG105.get());
+            }
+
+        }
+        OutsideModel outsideModel = JsonUtil.getJsonToBean(body, OutsideModel.class);
+        String eventId = outsideModel.getEventId();
+        EventLogEntity eventLog = StringUtil.isNotEmpty(eventId) ? eventLogService.getById(eventId) : null;
+        if (eventLog == null) {
+            throw new WorkFlowException(MsgCode.FA001.get());
+        }
+        TaskEntity taskEntity = taskService.getInfo(eventLog.getTaskId());
+        FlowModel flowModel = new FlowModel();
+        flowModel.setFormData(outsideModel.getFormData());
+        flowModel.setId(eventId);
+        flowModel.setTaskId(eventLog.getTaskId());
+        try {
+            if (FlowNature.SYSTEM_CODE.equals(eventLog.getCreatorUserId())){
+                eventLog.setCreatorUserId(serviceUtil.getAdmin());
+            }
+            String token = AuthUtil.loginTempUser(eventLog.getCreatorUserId(), tenantId);
+            UserInfo userInfo = UserProvider.getUser(token);
+            UserProvider.setLoginUser(userInfo);
+            UserProvider.setLocalLoginUser(userInfo);
+            flowModel.setUserInfo(userInfo);
+            outsideUtil.outsideAudit(flowModel, eventLog);
+        } catch (Exception e) {
+            operatorUtil.compensate(taskEntity);
+            throw e;
+        }
+        operatorUtil.handleOperator();
+        operatorUtil.handleTaskStatusThenEvent();
+        if (taskEntity.getRejectDataId() == null) {
+            operatorUtil.autoAudit(flowModel);
+            operatorUtil.launchTrigger(flowModel);
+            operatorUtil.handleOperator();
+            operatorUtil.handleTaskStatusThenEvent();
+        }
+        return ActionResult.success(MsgCode.WF066.get());
+    }
+
+
+    @GetMapping("/test")
+    public Map<String,String> test() {
+        return ImmutableMap.of("handleId", "03d159a3-0f88-424c-a24f-02f63855fe4f,9624fa22-ac3a-4184-af0b-b2c720df9d60,3977de33-668c-4585-b09b-239aacfb4ebe");
+    }
+}

--
Gitblit v1.8.0