:feat: 合同变更合规推送增加同步状态回写闭环,仅原合同已推送合规的变更单参与推送

This commit is contained in:
刘泉佳
2026-10-28 14:16:17 +08:00
parent a7204cec20
commit 632e0e5971
4 changed files with 40 additions and 10 deletions
@@ -33,6 +33,7 @@ import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.transport.constant.HcsSyncConstant;
import org.springblade.transport.pojo.entity.ContractChange;
import org.springblade.transport.pojo.vo.ContractChangeVO;
import org.springblade.transport.service.IContractChangeService;
@@ -110,17 +111,12 @@ public class ContractChangeController extends BladeController {
hcsImmediatePushSupport.pushContractAndWait(contractId);
String syncFailure = HcsImmediatePushSupport.pollSyncFailure();
if (syncFailure != null) {
ContractChange contractChange = contractChangeService.getById(id);
if (contractChange != null) {
contractChange.setSyncStatus("failed");
contractChangeService.updateById(contractChange);
}
contractChangeService.writeBackSyncStatus(contractId, HcsSyncConstant.HCS_STATUS_FAILED);
return R.data(Boolean.FALSE, "审批通过,但合规推送失败:" + syncFailure);
}
ContractChange contractChange = contractChangeService.getById(id);
if (contractChange != null) {
contractChange.setSyncStatus("synced");
contractChangeService.updateById(contractChange);
// 即时推送未开启时(开关关闭不触发推送)不标记已推送,待推送状态由定时扫描任务推送后闭环
if (hcsImmediatePushSupport.isImmediateEnabled()) {
contractChangeService.writeBackSyncStatus(contractId, HcsSyncConstant.HCS_STATUS_SYNCED);
}
return R.success("审批通过");
}
@@ -72,4 +72,13 @@ public interface IContractChangeService extends BaseService<ContractChange> {
*/
boolean markSyncStatus(String ids, String syncStatus);
/**
* 按原合同回写最近一条待同步变更单的同步状态(审批即时推送/定时任务推送后调用)
*
* @param contractId 原合同ID
* @param syncStatus 同步状态(synced/failed)
* @return 是否回写成功(无待同步变更单时返回 false)
*/
boolean writeBackSyncStatus(Long contractId, String syncStatus);
}
@@ -190,7 +190,11 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
String processor = TransportBusinessSupport.trimToNull(AuthUtil.getUserName());
contractChange.setCurrentProcessor(processor == null ? "系统" : processor);
contractChange.setApprovedTime(LocalDateTime.now());
contractChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
// 仅原合同已推送合规(有合规单据ID标识 hcs_fd_id)的变更单参与合规推送(C103-11),存量未推送合同不置同步状态
ContractManage contractManage = contractManageService.getById(contractChange.getContractId());
if (contractManage != null && Func.isNotBlank(contractManage.getHcsFdId())) {
contractChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
}
updateById(contractChange);
contractManageService.applyChangeFromRecord(contractChange);
return contractChange.getContractId();
@@ -253,6 +257,20 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
return true;
}
@Override
public boolean writeBackSyncStatus(Long contractId, String syncStatus) {
if (contractId == null) {
return false;
}
// 仅回写该合同最近一条审批通过且未同步/失败的变更单,历史已闭环单据不翻动
return update(Wrappers.<ContractChange>lambdaUpdate()
.eq(ContractChange::getContractId, contractId)
.eq(ContractChange::getApprovalStatus, STATUS_APPROVED)
.in(ContractChange::getSyncStatus, List.of(HcsSyncConstant.HCS_STATUS_UNSYNCED, HcsSyncConstant.HCS_STATUS_FAILED))
.set(ContractChange::getSyncStatus, syncStatus)
.last("order by approved_time desc limit 1"));
}
private LambdaQueryWrapper<ContractChange> buildQuery(ContractChangeVO contractChange) {
TransportBusinessSupport.validateAllDept(contractChange.getAllDept(), "合同变更");
LambdaQueryWrapper<ContractChange> queryWrapper = Wrappers.<ContractChange>lambdaQuery().eq(ContractChange::getIsDeleted, 0);
@@ -153,6 +153,13 @@ public class HcsImmediatePushSupport {
this.pushWithLock(HcsSyncConstant.BIZ_TYPE_CONTRACT, id, () -> this.pushContractNow(id));
}
/**
* 即时推送开关(thirdParty.hcs.push.immediate-enabled)状态,供 Controller 判断审批响应是否实际等待过推送结果
*/
public boolean isImmediateEnabled() {
return hcsProperties.getPush().isImmediateEnabled();
}
/**
* 项目立项"通过"按钮路径:在审批事务提交返回后由 Controller 同步调用,失败原因留在当前线程供其取走
*