package jnpf.dmsService;
|
|
import jnpf.dmsEntity.storage.form.DmsApprovedRegistrationCallback;
|
import jnpf.dmsEntity.storage.approval.DmsApprovedBatch;
|
import jnpf.dmsEntity.wenjianbianhao.form.DmsFlowEventForm;
|
import jnpf.dmsMapper.DmsApprovedBatchMapper;
|
import jnpf.dmsPermission.DmsCurrentIdentity;
|
import jnpf.dmsService.impl.DmsWenjianBanbenServiceImpl;
|
import jnpf.exception.DataException;
|
import jnpf.flowable.WorkFlowApi;
|
import jnpf.flowable.entity.TaskEntity;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
/** Orchestration deliberately has no encompassing transaction. Approval, activation and projection are separate facts. */
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
public class DmsApprovedFlowService {
|
private final WorkFlowApi workflow;
|
private final DmsCurrentIdentity identity;
|
private final DmsApprovedFileAcceptanceService acceptance;
|
private final DmsApprovedFileRetryService retry;
|
private final DmsWenjianBanbenServiceImpl business;
|
private final DmsApprovedBatchMapper receipts;
|
private final DmsTemplateNotificationService notifications;
|
|
public void sync(DmsFlowEventForm form, String type) {
|
String taskId = form.getTaskId().trim(), flowId = form.getFlowId().trim();
|
TaskEntity task = workflow.getInfoSubmit(taskId);
|
if (task == null || !taskId.equals(task.getId()) || task.getStatus() == null
|
|| (!flowId.equals(task.getFlowId()) && !flowId.equals(task.getTemplateId())))
|
throw new DataException("未找到匹配的工作流任务");
|
if (!Integer.valueOf(2).equals(task.getStatus())) {
|
if ("xinzeng_shenhe".equals(type)) business.syncNewAuditFlow(flowId, taskId, task.getStatus(), form.getEventType());
|
else business.syncRevisionAuditFlow(flowId, taskId, task.getStatus(), form.getEventType());
|
return;
|
}
|
jnpf.base.UserInfo user = identity.requireUser();
|
if (task.getEndTime() == null) throw new DataException("批准任务缺少结束时间");
|
// Commit approval facts and both progress tables before entering the file service.
|
DmsApprovedBatch queued = acceptance.enqueue(identity.tenantId(user), flowId, taskId, type,
|
user.getUserId(), task.getEndTime());
|
if ("xiuding_shenhe".equals(type)) notifications.approved(queued.getTenantId(), taskId);
|
retry.process(queued);
|
}
|
|
/** Called through the existing trusted registration callback, outside the acceptance transaction. */
|
public DmsApprovedBatch completeRegistration(DmsApprovedRegistrationCallback form, String serviceId) {
|
DmsApprovedBatch accepted = acceptance.accept(form, serviceId);
|
activateAndApply(accepted);
|
DmsApprovedBatch result = receipts.find(accepted.getTenantId(), accepted.getTaskId(), accepted.getAuditType());
|
if (result == null) throw new DataException("登记确认后未找到批次回执");
|
result.setItems(receipts.items(result.getTenantId(), result.getId()));
|
return result;
|
}
|
|
public void activateAndApply(DmsApprovedBatch receipt) {
|
retry.advance(receipt);
|
}
|
}
|