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 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("文件已提交撤销或失效申请,暂不能修订;流程未结束(含退回)时保持占用");} }