刘光辉
117 分钟以前 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
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<DmsFileExpiryResource> 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("延期业务资源已变化,请重试");
        }
    }
}