提交erp逻辑修改、修改合同校验修改

This commit is contained in:
guojunyun
2025-10-21 16:23:24 +08:00
parent 6fc5682374
commit a4b997ec49
3 changed files with 52 additions and 10 deletions

View File

@@ -145,7 +145,7 @@ public class ContractController implements BusinessControllerMarker {
@PostMapping("/submit/erp") @PostMapping("/submit/erp")
@Operation(summary = "提交ERP") @Operation(summary = "提交ERP")
@PreAuthorize("@ss.hasPermission('base:contract:erp')") @PreAuthorize("@ss.hasPermission('base:contract:erp')")
public CommonResult<Boolean> submitErp(@RequestBody List<Long> ids) { public CommonResult<List<String>> submitErp(@RequestBody List<Long> ids) {
return success(contractService.submitErp(ids)); return success(contractService.submitErp(ids));
} }

View File

@@ -105,7 +105,7 @@ public interface ContractService {
* @param ids 合同ID集合 * @param ids 合同ID集合
* @return * @return
*/ */
Boolean submitErp(List<Long> ids); List<String> submitErp(List<Long> ids);
/** /**
* 删除合同 * 删除合同

View File

@@ -730,6 +730,29 @@ public class ContractServiceImpl implements ContractService {
// 请求更新的合同信息 // 请求更新的合同信息
ContractMainDO newContractMainDO = BeanUtils.toBean(reqVO, ContractMainDO.class); ContractMainDO newContractMainDO = BeanUtils.toBean(reqVO, ContractMainDO.class);
// 校验ERP的公司
if (StringUtils.isNotEmpty(reqVO.getPurchaseCompanyNumber())
|| StringUtils.isNotEmpty(reqVO.getSalesCompanyNumber())) {
if (StringUtils.isNotEmpty(reqVO.getPurchaseCompanyNumber())) {
ErpCompanyDO erpCompany = erpCompanyService.getErpCompanyByNumber(reqVO.getPurchaseCompanyNumber());
if (erpCompany == null) {
throw exception(CONTRACT_ERP_COMPANY_PLEASE_BIND, ApiConstants.PURCHASE);
} else {
newContractMainDO.setErpPurchaseCompanyNumber(erpCompany.getNumber());
newContractMainDO.setErpPurchaseCompanyName(erpCompany.getName());
}
}
if (StringUtils.isNotEmpty(reqVO.getSalesCompanyNumber())) {
ErpCompanyDO erpCompany = erpCompanyService.getErpCompanyByNumber(reqVO.getSalesCompanyNumber());
if (erpCompany == null) {
throw exception(CONTRACT_ERP_COMPANY_PLEASE_BIND, ApiConstants.SALES);
} else {
newContractMainDO.setErpSalesCompanyNumber(erpCompany.getNumber());
newContractMainDO.setErpSalesCompanyName(erpCompany.getName());
}
}
}
// 删除关联信息 // 删除关联信息
// 查询合同明细 // 查询合同明细
List<ContractDetailDO> detailDOS = contractDetailMapper List<ContractDetailDO> detailDOS = contractDetailMapper
@@ -1289,7 +1312,9 @@ public class ContractServiceImpl implements ContractService {
} }
@Override @Override
public Boolean submitErp(List<Long> ids) { public List<String> submitErp(List<Long> ids) {
List<String> results = new ArrayList<>();
// 遍历合同ID集合 // 遍历合同ID集合
ids.forEach(id -> { ids.forEach(id -> {
@@ -1312,23 +1337,40 @@ public class ContractServiceImpl implements ContractService {
ErpContractSaveReqVO erpContractVO = getErpContract(contractMainDO); ErpContractSaveReqVO erpContractVO = getErpContract(contractMainDO);
// 调用ERP模块 // 调用ERP模块
Map<Boolean, String> erpResult = sendToErp(erpContractVO); JSONObject erpResult = sendToErp(erpContractVO);
log.info("合同提交ERP结果{}", erpResult); log.info("合同提交ERP结果{}", erpResult);
String result = id
+"-"+erpResult.getBool("success")
+(erpResult.getBool("success") ? "" : "-" + erpResult.getStr("errMsg"));
results.add(result);
// 更新合同状态
if (erpResult.getBool("success")) {
contractMainDO.setStatus(DictEnum.BSE_CTRT_STS_IN_PROGRESS.getCode());
contractMainDO.setErpStatus(DictEnum.ERP_REQ_STS_FIND.getCode());
contractMainMapper.updateById(contractMainDO);
} else { } else {
throw exception(CONTRACT_NOT_EXISTS); contractMainDO.setStatus(DictEnum.BSE_CTRT_STS_PUSH_ERROR.getCode());
contractMainDO.setErpStatus(DictEnum.ERP_REQ_STS_RLBK.getCode());
// contractMainDO.setCause(erpResult.getStr("errMsg"));
contractMainMapper.updateById(contractMainDO);
}
} else {
results.add(id+"-"+"false"+"-"+CONTRACT_NOT_EXISTS);
} }
}); });
return true; return results;
} }
private Map<Boolean, String> sendToErp(ErpContractSaveReqVO erpContractVO) { private JSONObject sendToErp(ErpContractSaveReqVO erpContractVO) {
Map<Boolean, String> erpResult = new HashMap<>(); JSONObject erpResult = new JSONObject();
try { try {
String result = erpContractService.submitErp(erpContractVO); String result = erpContractService.submitErp(erpContractVO);
erpResult.put(true, result); erpResult.putOnce("success", true);
} catch (Exception e) { } catch (Exception e) {
erpResult.put(false, e.getMessage()); erpResult.putOnce("success", false);
erpResult.putOnce("errMsg", e.getMessage());
} }
return erpResult; return erpResult;