刘光辉
118 分钟以前 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.expiry;
 
import jnpf.dmsEntity.storage.expiry.DmsFileExpiryItem;
import jnpf.dmsEntity.storage.form.DmsFileLifecycleUpdateForm;
import jnpf.dmsMapper.DmsFileExpiryMapper;
import jnpf.dmsService.DmsFileLifecycleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
@Service
@RequiredArgsConstructor
public class DmsFileExpiryExecutor {
    private final DmsFileExpiryMapper mapper;
    private final DmsFileLifecycleService lifecycle;
    private final jnpf.dmsService.DmsBusinessLifecycleGuard businessOccupancy;
 
    @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
    public boolean process(DmsFileExpiryItem candidate) {
        if (!businessOccupancy.tryEnterExpiry(candidate.getTenantId(), candidate.getFileVersionId())) return false;
        if (mapper.tryLockDocument(candidate.getTenantId(), candidate.getDocumentId()) == null) return false;
        DmsFileExpiryItem current = mapper.dueState(candidate.getTenantId(), candidate.getFileVersionId());
        if (current == null) return false; // Extended or superseded since discovery.
        DmsFileLifecycleUpdateForm form = new DmsFileLifecycleUpdateForm();
        form.setTenantId(current.getTenantId());
        form.setFileVersionId(current.getFileVersionId());
        form.setLifecycleStatus("EXPIRED");
        form.setEffectiveFrom(current.getEffectiveFrom());
        form.setEffectiveTo(current.getEffectiveTo());
        lifecycle.updateExpired(form, "dms-expiry-job");
        return true;
    }
}