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