刘光辉
3 小时以前 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
package jnpf.dmsService.pdf;
 
import jnpf.dmsEntity.storage.pdf.DmsPdfGenerationTask;
import jnpf.dmsEntity.storage.vo.DmsPersistentPdfGenerateVO;
import jnpf.dmsMapper.DmsPdfGenerationTaskMapper;
import jnpf.exception.DataException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
@RequiredArgsConstructor
public class DmsPdfGenerationCompletion {
    private final DmsPdfGenerationTaskMapper mapper;
 
    @Transactional(rollbackFor = Exception.class)
    public void succeed(DmsPdfGenerationTask task, String token, DmsPersistentPdfGenerateVO pdf) {
        if (pdf == null || pdf.getObjectKey() == null || pdf.getSizeBytes() == null
                || pdf.getChecksumSha256() == null || pdf.getSourceChecksumSha256() == null) {
            throw new DataException("持久化 PDF 返回结果不完整");
        }
        if (mapper.writePdf(task.getTenantId(), task.getFileVersionId(),
                task.getSourceChecksumSha256(), pdf) != 1) {
            throw new DataException("源文件已变化,拒绝写入过期 PDF");
        }
        if (mapper.succeed(task.getTenantId(), task.getFileVersionId(), token) != 1) {
            throw new DataException("持久化 PDF 任务租约已失效");
        }
    }
}