刘光辉
4 小时以前 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
package jnpf.dmsService;
 
import jnpf.flowable.entity.TaskEntity;
import jnpf.dmsMapper.DmsDisableApplicationMapper;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.UUID;
import java.util.List;
import java.util.Set;
import java.util.Objects;
import jnpf.flowable.WorkFlowApi;
import jnpf.dmsEntity.storage.approval.DmsDisableOccupancy;
import org.springframework.beans.factory.annotation.Value;
 
@Service
@RequiredArgsConstructor
public class DmsDisableApplicationGuard {
    private final DmsDisableApplicationMapper mapper;
    private final WorkFlowApi workflow;
    @Value("${dms.disable-occupancy.enabled:false}") private boolean occupancyEnabled;
    public void requireFileEditable(String tenantId,String fileId) {
        int count = occupancyEnabled ? mapper.pendingForFile(tenantId,fileId) : legacyPending(mapper.legacyApplicationsForFile(tenantId,fileId));
        if (count>0) throw occupied();
    }
    public void requireDocumentEditable(String tenantId,UUID documentId) {
        int count = occupancyEnabled ? mapper.pendingForDocument(tenantId,documentId) : legacyPending(mapper.legacyApplicationsForDocument(tenantId,documentId));
        if (count>0) throw occupied();
    }
    private int legacyPending(List<DmsDisableOccupancy> applications) {
        for (DmsDisableOccupancy application : applications) {
            if (application.getTaskId() == null || application.getFlowId() == null) return 1;
            TaskEntity task = workflow.getInfoSubmit(application.getTaskId());
            // Incomplete or unavailable workflow evidence must not release a file.
            if (task == null || !Objects.equals(application.getTaskId(), task.getId())
                    || (!Objects.equals(application.getFlowId(), task.getFlowId())
                        && !Objects.equals(application.getFlowId(), task.getTemplateId()))
                    || task.getStatus() == null || !Set.of(3,4,7,9).contains(task.getStatus())
                    || task.getEndTime() == null) return 1;
        }
        return 0;
    }
    private DataException occupied() {return new DataException("文件已提交撤销或失效申请,暂不能修订;流程未结束(含退回)时保持占用");}
}