刘光辉
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
52
53
54
55
56
57
58
59
60
61
62
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);
    }
}