REQ-3581: 修复印章状态同步问题

This commit is contained in:
yanglin 2025-02-20 11:19:09 +08:00
parent e781720838
commit 41d77b2a8e
5 changed files with 15 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package cn.axzo.nanopart.ess.server.dao;
import cn.axzo.nanopart.ess.api.domain.contract.Approver;
import cn.axzo.nanopart.ess.api.domain.contract.EssApproveDetail;
import cn.axzo.nanopart.ess.api.enums.EssContractState;
import cn.axzo.nanopart.ess.server.entity.EssContract;
@ -42,11 +43,13 @@ public class EssContractDao extends ServiceImpl<EssContractMapper, EssContract>
public void setEssContractCreated(Long id,
String flowId,
List<String> essFileIds) {
List<String> essFileIds,
List<Approver> approvers) {
lambdaUpdate()
.eq(EssContract::getId, id)
.set(EssContract::getEssFieldIds, JSON.toJSONString(essFileIds))
.set(EssContract::getEssContractId, flowId)
.set(EssContract::getApprovers, JSON.toJSONString(approvers))
.update();
}
@ -62,7 +65,7 @@ public class EssContractDao extends ServiceImpl<EssContractMapper, EssContract>
.update();
}
public void setOssFileKey(EssContract contract, String fileKey) {
public void setOssKey(EssContract contract, String fileKey) {
lambdaUpdate()
.eq(EssContract::getId, contract.getId())
.set(EssContract::getOssFileKey, fileKey)

View File

@ -62,7 +62,8 @@ public class ContractManager {
for (int i = 0; i < contract.approverSize(); i++)
contract.getApprover(i).setEssRecipientId(essRecipientIds.get(i));
essContractDao.setEssContractCreated(
contract.getId(), essResponse.getFlowId(), essFileIds);
contract.getId(), essResponse.getFlowId(),
essFileIds, contract.getApprovers());
contract = essContractDao.getOrThrow(essResponse.getFlowId());
essBroadcaster.fireContractStateChanged(contract);
CreateContractByFileResponse response = new CreateContractByFileResponse();

View File

@ -33,7 +33,6 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.function.Function;
import java.util.function.Supplier;
import static cn.axzo.nanopart.ess.server.utils.BizAssertions.fail;
@ -155,8 +154,7 @@ public class EssService {
&& StringUtils.isNotBlank(contract.getOssFileKey())) {
return ossService.getOssUrl(contract.getOssFileKey());
}
maybeUploadContractToOss(contract.getEssContractId(),
() -> getContractPDFUrlFromEss(contract));
maybeUploadContractToOss(contract);
return getContractPDFUrlFromEss(contract);
}
@ -165,15 +163,16 @@ public class EssService {
return essClient.getContractPDFUrl(creator, contract.getEssContractId());
}
public void maybeUploadContractToOss(String essContractId, Supplier<String> essPdfUrl) {
public void maybeUploadContractToOss(EssContract contract) {
essSupport.asyncExec(() -> {
EssContract effectiveContract = essContractDao.findOrNull(essContractId);
EssContract effectiveContract = essContractDao.findOrNull(contract.getEssContractId());
if (!effectiveContract.isFinalState()
|| StringUtils.isNotBlank(effectiveContract.getOssFileKey()))
return;
String pdfUrl = getContractPDFUrlFromEss(effectiveContract);
String fileName = String.format("%s.pdf", effectiveContract.getContractName());
String fileKey = ossService.uploadToOss(essPdfUrl.get(), fileName);
essContractDao.setOssFileKey(effectiveContract, fileKey);
String fileKey = ossService.uploadToOss(pdfUrl, fileName);
essContractDao.setOssKey(effectiveContract, fileKey);
});
}

View File

@ -164,9 +164,7 @@ class CallbackController implements EssCallbackApi, InitializingBean {
}
if (contract != null) {
contractManager.updateContractState(contract, state, approveDetails);
EssContract finalContract = contract;
essService.maybeUploadContractToOss(contract.getEssContractId(),
() -> essService.getContractPDFUrlFromEss(finalContract));
essService.maybeUploadContractToOss(contract);
}
return changes.getFlowId();
});

View File

@ -41,7 +41,7 @@ public class EssSupport {
private final ExecutorService executor = new ThreadPoolExecutor(1, 5,
0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(1024),
new ArrayBlockingQueue<>(200),
new NamedThreadFactory(EssSupport.class.getName(), false),
new CallerRunsPolicy());