刘光辉
119 分钟以前 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package jnpf.dmsService.center;
 
import jnpf.audit.sdk.annotation.AuditLog;
import jnpf.dmsEntity.center.DmsCenterDisableCommand;
import jnpf.dmsEntity.center.DmsInvalidationTarget;
import jnpf.dmsEntity.storage.approval.DmsDisableRequest;
import jnpf.dmsMapper.DmsInvalidationMapper;
import jnpf.dmsMapper.DmsRevocationMapper;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.UUID;
 
/** Center transitions participate in the approved item's local transaction. */
@Service
@RequiredArgsConstructor
public class DmsCenterDisableService {
    private final DmsInvalidationMapper mapper;
    private final DmsRevocationMapper revocations;
 
    /** The caller still completes the approved item and releases its own receipts in the same transaction.
     * Elapsed validity is sufficient even while the lowest-priority expiry task is waiting for that receipt.
     * This check never rewrites the existing invalidation reason, validity interval or directory members.
     */
    @Transactional(propagation = Propagation.MANDATORY)
    public boolean alreadyIneffective(DmsCenterDisableCommand command, DmsDisableRequest row, Date at) {
        List<UUID> documents = mapper.lockDocuments(command);
        if (documents.isEmpty() || documents.size() > 1000)
            throw new DataException("执行目录不存在或成员超过1000个");
        if (mapper.hasPendingVersions(command))
            throw new DataException("目录存在待批准、待生效或未完成业务回写的版本,暂不结束任务");
        Boolean ineffective = mapper.alreadyIneffective(row, at);
        if (ineffective == null)
            throw new DataException("执行目标已换版、缺失或资源与中心状态不一致,不能认定任务成功");
        return ineffective;
    }
 
    @Transactional(propagation = Propagation.MANDATORY)
    @AuditLog(action = "DMS_INVALIDATE_CENTER", bizCodeExpr = "#command.requestId")
    public List<DmsInvalidationTarget> invalidate(DmsCenterDisableCommand command, Date at) {
        if (!"yishixiao".equals(command.getReason())) throw new DataException("该入口只执行已批准的文件失效");
        List<UUID> documents = mapper.lockDocuments(command);
        if (documents.isEmpty() || documents.size() > 1000 || !mapper.validDirectory(command))
            throw new DataException("失效专属目录不存在、已停用、归属已变化或成员超过1000个");
        if (mapper.hasPendingVersions(command))
            throw new DataException("目录存在待批准、待生效或未完成业务回写的版本,暂不执行失效");
        List<DmsInvalidationTarget> targets = mapper.currentTargets(command);
        if (targets.size() > 1000 || targets.stream().noneMatch(t -> command.getMainDocumentId().equals(t.getDocumentId())
                && command.getExpectedMainVersionId().equals(t.getFileVersionId())))
            throw new DataException("失效主文件已不是申请登记的现行有效版本");
        for (DmsInvalidationTarget target : targets) {
            if (target.getEffectiveFrom() == null || !at.after(target.getEffectiveFrom())
                    || mapper.invalidateVersion(command, target, at) != 1)
                throw new DataException("失效版本或有效时间已变化,请重试");
        }
        if (mapper.markDocuments(command, at) != documents.size())
            throw new DataException("失效目录成员已变化,请重试");
        return targets;
    }
 
    @Transactional(propagation = Propagation.MANDATORY)
    @AuditLog(action = "DMS_REVOKE_CENTER", bizCodeExpr = "#command.requestId")
    public List<DmsInvalidationTarget> revoke(DmsCenterDisableCommand command, Date at) {
        if (!"yichexiao".equals(command.getReason())) throw new DataException("该入口只执行已批准的文件撤销");
        List<UUID> documents = revocations.lockDocuments(command);
        if (documents.isEmpty() || documents.size() > 1000 || !revocations.validDirectory(command))
            throw new DataException("撤销专属目录不存在、已停用、归属已变化或成员超过1000个");
        if (revocations.hasPendingVersions(command))
            throw new DataException("目录存在待批准、待生效或未完成业务回写的版本,暂不执行撤销");
        List<DmsInvalidationTarget> targets = revocations.currentTargets(command);
        if (targets.size() > 1000 || targets.stream().noneMatch(t -> command.getMainDocumentId().equals(t.getDocumentId())
                && command.getExpectedMainVersionId().equals(t.getFileVersionId())))
            throw new DataException("撤销主文件已不是申请登记的最新版本,或已被其他操作停用");
        for (DmsInvalidationTarget target : targets) {
            if (target.getEffectiveFrom() == null || !at.after(target.getEffectiveFrom())
                    || revocations.revokeVersion(command, target, at) != 1)
                throw new DataException("撤销版本或有效时间已变化,请重试");
        }
        if (revocations.markDocuments(command, at) != documents.size())
            throw new DataException("撤销目录成员已变化,请重试");
        return targets;
    }
}