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;
|
}
|
}
|