刘光辉
12 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package jnpf.dmsController;
 
import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jnpf.base.ActionResult;
import jnpf.base.Pagination;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.dmsEntity.wenjianbianhao.form.DmsFlowEventForm;
import jnpf.dmsEntity.wenjianbianhao.form.DmsWenjianBianhaoPreviewForm;
import jnpf.dmsEntity.wenjianbianhao.vo.DmsWenjianBianhaoOptionVO;
import jnpf.dmsEntity.wenjianbianhao.vo.DmsWenjianBianhaoPreviewVO;
import jnpf.dmsEntity.wenjianbianhao.vo.DmsWenjianBianhaoRuleVO;
import jnpf.dmsService.DmsWenjianBianhaoApplicationService;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import jnpf.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
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;
 
@Tag(name = "DMS文件编号申请接口")
@RestController
@SaCheckLogin
@RequiredArgsConstructor
@RequestMapping("/biz/wenjian/bianhao")
public class DmsWenjianBianhaoController {
 
    private final DmsWenjianBianhaoApplicationService service;
    private final WorkFlowApi workFlowApi;
 
    @Operation(summary = "可申请的文件编号规则")
    @GetMapping("/guize/enabled")
    public ActionResult<PageListVO<DmsWenjianBianhaoRuleVO>> enabledRules(
            Pagination pagination,
            @RequestParam(name = "guize_id", required = false) String guizeId,
            @RequestParam(name = "search_val", required = false) String searchValue)
            throws DataException {
        List<DmsWenjianBianhaoRuleVO> list = service.enabledRules(
                pagination, guizeId, searchValue);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    @Operation(summary = "预览文件编号,不占用流水号")
    @PostMapping("/preview")
    public ActionResult<DmsWenjianBianhaoPreviewVO> preview(
            @Valid @RequestBody DmsWenjianBianhaoPreviewForm form) throws DataException {
        return ActionResult.success(service.preview(form.getGuizeId()));
    }
 
    @Operation(summary = "可关联的使用中文件编号")
    @GetMapping("/using")
    public ActionResult<PageListVO<DmsWenjianBianhaoOptionVO>> usingNumbers(
            Pagination pagination,
            @RequestParam(name = "bianhao_id", required = false) String bianhaoId,
            @RequestParam(name = "search_val", required = false) String searchValue)
            throws DataException {
        List<DmsWenjianBianhaoOptionVO> list = service.usingNumbers(
                pagination, bianhaoId, searchValue);
        PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(list, paginationVO);
    }
 
    @Operation(summary = "同步文件编号申请流程事件")
    @PostMapping("/shenqing/flow-event")
    public ActionResult<String> syncApplicationFlowEvent(
            @Valid @RequestBody DmsFlowEventForm form) throws DataException {
        service.syncApplicationFlow(form.getFlowId(), form.getTaskId(),
                requireWorkflowState(form.getTaskId()), form.getEventType());
        return ActionResult.success("文件编号申请流程状态同步成功", "文件编号申请流程状态同步成功");
    }
 
    @Operation(summary = "同步文件名称变更流程事件")
    @PostMapping("/mingcheng-biangeng/flow-event")
    public ActionResult<String> syncNameChangeFlowEvent(
            @Valid @RequestBody DmsFlowEventForm form) throws DataException {
        service.syncNameChangeFlow(form.getFlowId(), form.getTaskId(),
                requireWorkflowState(form.getTaskId()), form.getEventType());
        return ActionResult.success("文件名称变更流程状态同步成功", "文件名称变更流程状态同步成功");
    }
 
    private Integer requireWorkflowState(String taskId) throws DataException {
        TaskEntity task = workFlowApi.getInfoSubmit(taskId.trim());
        if (task == null || task.getId() == null) {
            throw new DataException("未找到流程任务:" + taskId);
        }
        if (!taskId.trim().equals(task.getId())) {
            throw new DataException("流程任务与传入任务ID不匹配");
        }
        if (task.getStatus() == null) {
            throw new DataException("流程任务状态为空:" + taskId);
        }
        return task.getStatus();
    }
}