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;
|
}
|
}
|