刘光辉
117 分钟以前 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
package jnpf.fileStorage.dms;
 
import jnpf.base.ActionResult;
import jnpf.base.ActionResultCode;
import jnpf.dms.DmsResourceApi;
import jnpf.dmsEntity.storage.form.DmsWorkflowFileActivateForm;
import jnpf.dmsEntity.storage.vo.DmsFileUploadVO;
import jnpf.dmsEntity.storage.vo.DmsWorkflowFileActivationVO;
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 DmsWorkflowFileActivateService {
    private static final String SERVICE_ID = "jnpf-file";
 
    private final WorkFlowApi workFlowApi;
    private final DmsResourceApi dmsResourceApi;
 
    public DmsWorkflowFileActivationVO activate(DmsWorkflowFileActivateForm form) {
        String flowId = form.getSourceId().trim();
        String taskId = form.getTaskId().trim();
        TaskEntity task = requireApprovedTask(flowId, taskId);
        ActionResult<DmsFileUploadVO> response = dmsResourceApi.activateWorkflowFile(SERVICE_ID, form);
        if (response == null || !ActionResultCode.SUCCESS.getCode().equals(response.getCode())
                || response.getData() == null) {
            String message = response == null ? null : response.getMsg();
            throw new DataException(message == null || message.trim().isEmpty()
                    ? "DMS文件生效失败或响应数据不完整" : message);
        }
 
        DmsFileUploadVO file = response.getData();
        file.setSourceId(flowId);
        DmsWorkflowFileActivationVO result = new DmsWorkflowFileActivationVO();
        result.setFile(file);
        result.setTaskId(taskId);
        result.setFlowState(task.getStatus());
        result.setFlowStatus(TaskStatusEnum.PASSED.getMessage());
        result.setCompleted(Boolean.TRUE);
        result.setWenjianZhongxinWenjianId(file.getDocumentId());
        result.setWenjianZhongxinBanbenId(file.getFileVersionId());
        return result;
    }
 
    private TaskEntity 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("流程任务尚未审核通过,不能生效文件");
        }
        return task;
    }
}