刘光辉
4 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package jnpf.controller;
 
import cn.dev33.satoken.same.SaSameUtil;
import jnpf.exception.DataException;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jnpf.base.ActionResult;
import jnpf.dmsEntity.storage.form.DmsApprovedRegistrationForm;
import jnpf.dmsEntity.storage.approval.DmsApprovedBatch;
import jnpf.dmsEntity.download.form.DmsWorkflowDownloadAuthorizeForm;
import jnpf.dmsEntity.download.vo.DmsWorkflowDownloadAuthorizationVO;
import jnpf.dmsEntity.print.form.DmsWorkflowPrintAuthorizeForm;
import jnpf.dmsEntity.print.vo.DmsWorkflowPrintAuthorizationVO;
import jnpf.dmsEntity.storage.form.DmsWorkflowFileActivateForm;
import jnpf.dmsEntity.storage.vo.DmsFileUploadVO;
import jnpf.dmsEntity.storage.vo.DmsWorkflowFileActivationVO;
import jnpf.fileStorage.dms.DmsFileStorageService;
import jnpf.fileStorage.dms.DmsWorkflowFileCreateService;
import jnpf.fileStorage.dms.DmsWorkflowFileActivateService;
import jnpf.fileStorage.dms.DmsWorkflowDownloadAuthorizeService;
import jnpf.fileStorage.dms.DmsWorkflowPrintAuthorizeService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.format.annotation.DateTimeFormat;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.util.MultiValueMap;
 
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
 
@RestController
@RequestMapping("/Dms")
@RequiredArgsConstructor
public class DmsFileUploadController {
    private final DmsFileStorageService fileStorageService;
    private final DmsWorkflowFileCreateService workflowFileCreateService;
    private final DmsWorkflowFileActivateService workflowFileActivateService;
    private final DmsWorkflowDownloadAuthorizeService workflowDownloadAuthorizeService;
    private final DmsWorkflowPrintAuthorizeService workflowPrintAuthorizeService;
 
    @PostMapping(value = "/Uploader", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ActionResult<DmsFileUploadVO> upload(@RequestParam("folderId") UUID folderId,
                                                @RequestHeader(value = "X-Audit-Biz-Sign", required = false)
                                                String auditBizSign,
                                                @RequestParam("sourceId") String sourceId,
                                                @RequestParam("documentNo") String documentNo,
                                                @RequestParam("documentName") String documentName,
                                                @RequestParam("documentType") String documentType,
                                                @RequestParam("responsibleDeptId") String responsibleDeptId,
                                                @RequestParam("versionLabel") String versionLabel,
                                                @RequestParam("preparedBy") String preparedBy,
                                                @RequestParam("preparedOn")
                                                @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
                                                LocalDate preparedOn,
                                                @RequestParam MultiValueMap<String, String> requestParameters,
                                                @RequestPart("file") MultipartFile file) {
        return ActionResult.success(fileStorageService.upload(folderId, sourceId, documentNo,
                documentName, documentType, responsibleDeptId, versionLabel, preparedBy,
                preparedOn, auditSignParameters(requestParameters), auditBizSign, file));
    }
 
    @Operation(summary = "审批通过后整批登记并确认新增或修订文件,按日期生效")
    @PostMapping(value = "/workflowFileRegister", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ActionResult<DmsApprovedBatch> workflowFileRegister(
            @RequestHeader("X-DMS-Service-Id") String serviceId,
            @RequestHeader(value = "X-Audit-Biz-Sign", required = false) String auditBizSign,
            @RequestBody @Valid DmsApprovedRegistrationForm form) {
        SaSameUtil.checkCurrentRequestToken();
        if (!"jnpf-dms".equals(serviceId)) throw new DataException("仅允许 DMS 推送批准文件登记批次");
        return ActionResult.success(workflowFileCreateService.process(form, auditBizSign));
    }
 
    @Operation(summary = "审批通过后生效已登记的工作流DMS文件")
    @PostMapping(value = "/workflowFileActivate", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ActionResult<DmsWorkflowFileActivationVO> workflowFileActivate(
            @RequestBody @Valid DmsWorkflowFileActivateForm form) {
        return ActionResult.success(workflowFileActivateService.activate(form));
    }
 
    @Operation(summary = "审批通过后为文件下载申请人授予一次下载权限")
    @PostMapping(value = "/workflowFileDownloadAuthorize", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ActionResult<DmsWorkflowDownloadAuthorizationVO> workflowFileDownloadAuthorize(
            @RequestHeader(value = "X-Audit-Biz-Sign", required = false) String auditBizSign,
            @RequestBody @Valid DmsWorkflowDownloadAuthorizeForm form) {
        return ActionResult.success(workflowDownloadAuthorizeService.authorize(form, auditBizSign));
    }
 
    @Operation(summary = "审批通过后为文件打印申请人授予永久打印权限")
    @PostMapping(value = "/workflowFilePrintAuthorize", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ActionResult<DmsWorkflowPrintAuthorizationVO> workflowFilePrintAuthorize(
            @RequestHeader(value = "X-Audit-Biz-Sign", required = false) String auditBizSign,
            @RequestBody @Valid DmsWorkflowPrintAuthorizeForm form) {
        return ActionResult.success(workflowPrintAuthorizeService.authorize(form, auditBizSign));
    }
 
    @PostMapping(value = "/Revisions", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ActionResult<DmsFileUploadVO> revise(
            @RequestParam("documentId") UUID documentId,
            @RequestHeader(value = "X-Audit-Biz-Sign", required = false) String auditBizSign,
            @RequestParam("baseFileVersionId") UUID baseFileVersionId,
            @RequestParam("sourceId") String sourceId,
            @RequestParam("versionLabel") String versionLabel,
            @RequestParam("preparedBy") String preparedBy,
            @RequestParam("preparedOn")
            @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate preparedOn,
            @RequestParam("revisionReason") String revisionReason,
            @RequestParam MultiValueMap<String, String> requestParameters,
            @RequestPart("file") MultipartFile file) {
        return ActionResult.success(fileStorageService.revise(documentId, baseFileVersionId,
                sourceId, versionLabel, preparedBy, preparedOn, revisionReason,
                auditSignParameters(requestParameters), auditBizSign, file));
    }
 
    private Map<String, Object> auditSignParameters(MultiValueMap<String, String> parameters) {
        Map<String, Object> signs = new LinkedHashMap<>();
        if (parameters == null) {
            return signs;
        }
        for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
            if (entry.getKey() == null
                    || !entry.getKey().toLowerCase(Locale.ROOT).endsWith("_sign")) {
                continue;
            }
            List<String> values = entry.getValue() == null
                    ? new ArrayList<>() : new ArrayList<>(entry.getValue());
            signs.put(entry.getKey(), values.size() == 1 ? values.get(0) : values);
        }
        return signs;
    }
}