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

View File

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

View File

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

View File

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

View File

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