package jnpf.dmsService; import jnpf.dmsEntity.storage.expiry.DmsFileExpiryResource; import jnpf.dmsMapper.DmsFileExpiryProjectionMapper; 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; @Service @RequiredArgsConstructor public class DmsFileValidityProjection { private final DmsFileExpiryProjectionMapper resources; @Transactional(propagation = Propagation.MANDATORY) public void apply(String tenantId, UUID versionId, Date effectiveTo, String actor) { List matches = resources.lockResources(tenantId, versionId); if (matches.size() > 1) throw new DataException("延期版本映射了多个当前业务资源"); if (matches.isEmpty()) return; DmsFileExpiryResource resource = matches.get(0); if (!"effective".equals(resource.getBizStatus()) || !versionId.toString().equals(resource.getCenterVersionId()) || !versionId.toString().equals(resource.getVersionCenterId())) { throw new DataException("业务资源已停用或当前版本映射不一致,不能延期"); } if (resources.extendValidity(tenantId, resource, effectiveTo, actor) != 1) { throw new DataException("延期业务资源已变化,请重试"); } } }