刘光辉
3 小时以前 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
package jnpf.fileStorage.dms;
 
import jnpf.base.ActionResult;
import jnpf.base.ActionResultCode;
import jnpf.dms.DmsResourceApi;
import jnpf.dmsEntity.print.form.DmsWorkflowPrintAuthorizeForm;
import jnpf.dmsEntity.print.vo.DmsWorkflowPrintAuthorizationVO;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import jnpf.flowable.enums.TaskStatusEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
 
@Service
@RequiredArgsConstructor
public class DmsWorkflowPrintAuthorizeService {
    private static final String SERVICE_ID = "jnpf-file";
 
    private final WorkFlowApi workFlowApi;
    private final DmsResourceApi dmsResourceApi;
 
    public DmsWorkflowPrintAuthorizationVO authorize(
            DmsWorkflowPrintAuthorizeForm form, String auditBizSign) {
        String flowId = form.getSourceId().trim();
        String taskId = form.getTaskId().trim();
        requireApprovedTask(flowId, taskId);
        ActionResult<DmsWorkflowPrintAuthorizationVO> response =
                dmsResourceApi.authorizeWorkflowPrint(SERVICE_ID, auditBizSign, form);
        if (response == null || !ActionResultCode.SUCCESS.getCode().equals(response.getCode())
                || response.getData() == null || !Boolean.TRUE.equals(response.getData().getCompleted())) {
            String message = response == null ? null : response.getMsg();
            throw new DataException(message == null || message.trim().isEmpty()
                    ? "DMS打印授权失败或响应数据不完整" : message);
        }
        return response.getData();
    }
 
    private void requireApprovedTask(String flowId, String taskId) {
        TaskEntity task = workFlowApi.getInfoSubmit(taskId);
        if (task == null || !taskId.equals(task.getId())) {
            throw new DataException("未找到与taskId匹配的流程任务");
        }
        if (!flowId.equals(task.getFlowId()) && !flowId.equals(task.getTemplateId())) {
            throw new DataException("流程任务不属于指定flowID");
        }
        if (!TaskStatusEnum.PASSED.getCode().equals(task.getStatus())) {
            throw new DataException("流程任务尚未审核通过,不能授予打印权限");
        }
    }
}