feat(ic): 实现 调拨和其它出入库单 同步到 MES 系统

- 修改 HttpPostOtherSysImpl 类,使用 callMes 方法替代 callLE
- 在 SignBP 中添加同步规则
- 更新相关文件以支持新功能
This commit is contained in:
maolei 2025-05-15 15:24:32 +08:00
parent 624200a970
commit 9f5e7703ea
8 changed files with 475 additions and 9 deletions

View File

@ -0,0 +1,37 @@
package nc.bs.ic.m4a.sign;
import nc.bs.ic.general.rule.after.UpdateSCOnhandRule;
import nc.bs.ic.general.rule.before.InOutAuditDateCheck;
import nc.bs.ic.general.sign.ISignBP;
import nc.bs.ic.general.sign.ISignRuleProvider;
import nc.bs.ic.general.sign.SignBPTemplate;
import nc.bs.ic.m4a.base.BPPlugInPoint;
import nc.bs.ic.m4a.sign.rule.AfterSignRuleForLiabilityProcess;
import nc.bs.ic.m4a.sign.rule.AfterSignRuleSyncMesProcess;
import nc.bs.scmpub.rule.VOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.ic.m4a.entity.GeneralInVO;
public class SignBP implements ISignBP<GeneralInVO>, ISignRuleProvider<GeneralInVO> {
public void addAfterRule(GeneralInVO[] vos, AroundProcesser<GeneralInVO> processor) {
processor.addAfterRule(new UpdateSCOnhandRule(false, true));
processor.addAfterRule(new AfterSignRuleSyncMesProcess());
processor.addAfterRule(new AfterSignRuleForLiabilityProcess());
processor.addBeforeRule(new AfterSignRuleSyncMesProcess());
}
public void addBeforeRule(GeneralInVO[] vos, AroundProcesser<GeneralInVO> processor) {
processor.addBeforeRule(new VOSagaFrozenValidateRule(true));
processor.addBeforeRule(new InOutAuditDateCheck());
}
public GeneralInVO[] sign(GeneralInVO[] bills) {
SignBPTemplate<GeneralInVO> insertBP = new SignBPTemplate(BPPlugInPoint.SignAction, this);
GeneralInVO[] resultVOs = (GeneralInVO[]) insertBP.sign(bills);
return resultVOs;
}
}

View File

@ -0,0 +1,182 @@
package nc.bs.ic.m4a.sign.rule;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.uif.pub.IUifService;
import nc.vo.bd.material.MaterialVersionVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.ic.m4a.entity.GeneralInBodyVO;
import nc.vo.ic.m4a.entity.GeneralInHeadVO;
import nc.vo.ic.m4a.entity.GeneralInVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.pubift.commen.impl.utils.HttpPostOtherSysImpl;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.util.Objects;
public class AfterSignRuleSyncMesProcess implements IRule<GeneralInVO> {
public static final IHttpPostOtherSys LOOKUP = new HttpPostOtherSysImpl();
private static final String LOG_INFO_NAME = "OALOG";
private static final Log obmlog = Log.getInstance(LOG_INFO_NAME);
private static final IUifService IUIFSERVICE = NCLocator.getInstance().lookup(IUifService.class);
public void process(GeneralInVO[] vos) {
if (vos != null && vos.length != 0) {
try {
for (GeneralInVO vo : vos) {
syncOtherSystem(vo);
}
} catch (BusinessException ex) {
ExceptionUtils.wrappException(ex);
}
}
}
private void syncOtherSystem(GeneralInVO generalInVO) throws BusinessException {
GeneralInHeadVO head = generalInVO.getHead();
obmlog.debug("触发同步其它入库单(M4A), 单据号:" + head.getVbillcode() + ", 出库类型编码:" + head.getVtrantypecode() + "开始拼接数据");
// 调拨入库
if ("4A-02".equals(head.getVtrantypecode())) {
// 表体body信息拼接
JSONArray details = new JSONArray();
// 填充details
for (GeneralInBodyVO body : generalInVO.getBodys()) {
JSONObject temp = new JSONObject();
temp.put("orderNo", head.getVbillcode());
temp.put("sequenceNum", body.getCrowno());
temp.put("type", "DBCK");
MaterialVersionVO materialVersionVO = (MaterialVersionVO) IUIFSERVICE.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialvid());
if (Objects.isNull(materialVersionVO)) {
throw new BusinessException("物料信息不存在, 主键:" + body.getCmaterialvid());
}
temp.put("materialId", materialVersionVO.getCode());
temp.put("outQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null);
temp.put("actOutQty", body.getNnum() != null ? body.getNnum().doubleValue() : null);
temp.put("assistActOutQry", ""); // Per example for similar field
temp.put("productNum", null);
temp.put("outStorageId", body.getClocationid()); // 拨入库位 (destination location)
temp.put("outBatchNum", body.getVbatchcode()); // 批号 (received batch)
temp.put("customId", null);
temp.put("supplierId", null);
temp.put("manufactureDate", null);
temp.put("color", null);
temp.put("packLen", null);
temp.put("packSize", null);
temp.put("remark", body.getVnotebody());
details.add(temp);
}
JSONObject info = new JSONObject();
info.put("details", details);
// 从head中取数
info.put("orderNo", head.getVbillcode());
info.put("type", "DBCK");
info.put("genType", null);
info.put("outDate", head.getDbilldate() != null ? head.getDbilldate().toString() : null);
StordocVO outWarehouse = (StordocVO) IUIFSERVICE.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid());
if (Objects.isNull(outWarehouse)) {
throw new BusinessException("拨出仓库信息不存在, 主键:" + head.getCwarehouseid());
}
info.put("outStoreId", outWarehouse.getCode());
StordocVO inWarehouse = (StordocVO) IUIFSERVICE.queryByPrimaryKey(StordocVO.class, head.getCotherwhid());
if (Objects.isNull(inWarehouse)) {
throw new BusinessException("拨入仓库信息不存在, 主键:" + head.getCotherwhid());
}
info.put("inStoreId", inWarehouse.getCode());
info.put("workerNo", null);
info.put("worker", null);
info.put("storeKeeper", head.getCwhsmanagerid());
info.put("returned", "N");
info.put("mark", "N");
info.put("remark", head.getVnote());
info.put("oldOrderNo", null);
// 拼接数据,先创建一个jsonObject
JSONObject requestData = new JSONObject();
requestData.put("operation_type", "I"); // 固定给I 操作
requestData.put("info", info);
obmlog.debug("调拨入库requestData:" + requestData.toJSONString());
IHttpPostOtherSys httpService = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
httpService.sendToExternalSystem("test", requestData);
obmlog.debug("调拨入库单 " + head.getVbillcode() + " 同步成功");
}
// 其它入库
else if ("4A-01".equals(head.getVtrantypecode())) {
obmlog.debug("开始处理其它入库单(4A-01): " + head.getVbillcode());
// 表体body信息拼接
JSONArray details = new JSONArray();
// 填充details
for (GeneralInBodyVO body : generalInVO.getBodys()) {
JSONObject temp = new JSONObject();
temp.put("orderNo", head.getVbillcode());
temp.put("sequenceNum", body.getCrowno());
temp.put("type", "QTRK");
MaterialVersionVO materialVersionVO = (MaterialVersionVO) IUIFSERVICE.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialvid());
if (Objects.isNull(materialVersionVO)) {
throw new BusinessException("物料信息不存在, 主键:" + body.getCmaterialvid());
}
temp.put("materialId", materialVersionVO.getCode());
temp.put("recQty", body.getNshouldnum() != null ? body.getNshouldnum().doubleValue() : null);
temp.put("actQty", body.getNnum() != null ? body.getNnum().doubleValue() : null);
temp.put("assistActQry", "");
temp.put("productNum", null);
temp.put("storageId", body.getClocationid());
temp.put("batchNum", body.getVbatchcode());
temp.put("customId", null);
temp.put("supplierId", null);
temp.put("manufactureDate", null);
temp.put("color", null);
temp.put("packLen", null);
temp.put("packSize", null);
temp.put("remark", body.getVnotebody());
details.add(temp);
}
JSONObject info = new JSONObject();
info.put("details", details);
// 从head中取数
info.put("orderNo", head.getVbillcode());
info.put("type", "QTRK");
info.put("actureDate", head.getDmakedate() != null ? head.getDmakedate().toString() : null);
StordocVO warehouse = (StordocVO) IUIFSERVICE.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid());
if (Objects.isNull(warehouse)) {
throw new BusinessException("仓库信息不存在, 主键:" + head.getCwarehouseid());
}
info.put("storeId", warehouse.getCode());
info.put("workerNo", null);
info.put("worker", null);
info.put("storeKeeper", head.getCwhsmanagerid());
info.put("returned", "N");
info.put("mark", "N");
info.put("remark", head.getVnote());
// 拼接数据,先创建一个jsonObject
JSONObject requestData = new JSONObject();
requestData.put("operation_type", "I"); // 固定给I 操作
requestData.put("info", info);
obmlog.debug("其它入库(4A-01) requestData:" + requestData.toJSONString());
IHttpPostOtherSys httpService = LOOKUP;
httpService.sendToExternalSystem("test", requestData);
obmlog.debug("其它入库单(4A-01) " + head.getVbillcode() + " 同步成功");
}
}
}

View File

@ -11,7 +11,6 @@ import nc.vo.ic.m4c.entity.SaleOutHeadVO;
import nc.vo.ic.m4c.entity.SaleOutVO; import nc.vo.ic.m4c.entity.SaleOutVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDate;
import nccloud.pubift.commen.impl.utils.HttpPostOtherSysImpl;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -42,7 +41,7 @@ public class AfterSigningSynchronizeRule implements IRule<SaleOutVO> {
// 构建要发送的数据 // 构建要发送的数据
JSONObject syncData = buildSyncData(hvo, bvos); JSONObject syncData = buildSyncData(hvo, bvos);
// 发送数据到金思维系统使用HttpPostOtherSysImpl处理网络请求 // 发送数据到金思维系统使用HttpPostOtherSysImpl处理网络请求
String mesResponse = httpPostOtherSys.callLE(SALE_OUT_URL, syncData); String mesResponse = httpPostOtherSys.callMes(SALE_OUT_URL, syncData);
obmlog.debug("AfterSigningSynchronizeRule-金思维系统响应: " + mesResponse); obmlog.debug("AfterSigningSynchronizeRule-金思维系统响应: " + mesResponse);
// 解析响应处理结果 // 解析响应处理结果
processResponse(hvo.getVbillcode(), mesResponse); processResponse(hvo.getVbillcode(), mesResponse);

View File

@ -0,0 +1,39 @@
package nc.bs.ic.m4i.sign;
import nc.bs.ic.general.rule.after.UpdateSCOnhandRule;
import nc.bs.ic.general.rule.before.InOutAuditDateCheck;
import nc.bs.ic.general.sign.ISignBP;
import nc.bs.ic.general.sign.ISignRuleProvider;
import nc.bs.ic.general.sign.SignBPTemplate;
import nc.bs.ic.m4i.base.BPPlugInPoint;
import nc.bs.ic.m4i.sign.rule.AfterSignRuleForFinanceProcess;
import nc.bs.ic.m4i.sign.rule.AfterSignRuleForLiabilityProcess;
import nc.bs.ic.m4i.sign.rule.AfterSignRuleForMatterApp;
import nc.bs.ic.m4i.sign.rule.AfterSignRuleSyncMesProcess;
import nc.bs.scmpub.rule.VOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.ic.m4i.entity.GeneralOutVO;
public class SignBP implements ISignBP<GeneralOutVO>, ISignRuleProvider<GeneralOutVO> {
public void addAfterRule(GeneralOutVO[] vos, AroundProcesser<GeneralOutVO> processor) {
processor.addAfterRule(new UpdateSCOnhandRule(false, false));
processor.addAfterRule(new AfterSignRuleForFinanceProcess());
processor.addAfterRule(new AfterSignRuleForLiabilityProcess());
processor.addAfterRule(new AfterSignRuleForMatterApp());
processor.addBeforeRule(new AfterSignRuleSyncMesProcess());
}
public void addBeforeRule(GeneralOutVO[] vos, AroundProcesser<GeneralOutVO> processor) {
processor.addBeforeRule(new VOSagaFrozenValidateRule(true));
processor.addBeforeRule(new InOutAuditDateCheck());
}
public GeneralOutVO[] sign(GeneralOutVO[] bills) {
SignBPTemplate<GeneralOutVO> insertBP = new SignBPTemplate(BPPlugInPoint.SignAction, this);
GeneralOutVO[] resultVOs = (GeneralOutVO[]) insertBP.sign(bills);
return resultVOs;
}
}

View File

@ -0,0 +1,176 @@
package nc.bs.ic.m4i.sign.rule;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.uif.pub.IUifService;
import nc.vo.bd.material.MaterialVersionVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.ic.m4i.entity.GeneralOutBodyVO;
import nc.vo.ic.m4i.entity.GeneralOutHeadVO;
import nc.vo.ic.m4i.entity.GeneralOutVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.util.Objects;
public class AfterSignRuleSyncMesProcess implements IRule<GeneralOutVO> {
private static String logginfo = "OALOG";
private static Log obmlog = Log.getInstance(logginfo);
private IUifService iUifService = NCLocator.getInstance().lookup(IUifService.class);
public void process(GeneralOutVO[] vos) {
if (vos != null && vos.length != 0) {
try {
for (GeneralOutVO vo : vos) {
syncOtherSystem(vo);
}
} catch (BusinessException ex) {
ExceptionUtils.wrappException(ex);
}
}
}
private void syncOtherSystem(GeneralOutVO generalOutVO) throws BusinessException {
obmlog.debug("触发同步其它出库单,出库类型编码:" + generalOutVO.getHead().getVtrantypecode() + "开始拼接数据");
// if (!generalOutVO.getHead().getPk_org().equals("0001A110000000000677")) {
// obmlog.debug("仅同步山东泰开电缆有限公司,当前组织:" + generalOutVO.getHead().getPk_org());
// return; // 仅操作山东泰开电缆有限公司
// }
// 其它出库
if (generalOutVO.getHead().getVtrantypecode().equals("4I-01")) {
// 表体body信息拼接
JSONArray details = new JSONArray();
GeneralOutHeadVO head = generalOutVO.getHead();
// 填充details
for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数
JSONObject temp = new JSONObject();
temp.put("orderNo", head.getVbillcode());
temp.put("sequenceNum", body.getCrowno());
temp.put("type", "QTCK");
MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid());
if (Objects.isNull(materialVersionVO)) {
throw new BusinessException("搜索物料信息不存在");
}
temp.put("materialId", materialVersionVO.getCode());
temp.put("issuedQty", body.getNshouldnum().doubleValue());
temp.put("actQty", body.getNnum().doubleValue());
temp.put("assistActQry", "");
temp.put("productNum", null);
temp.put("storageId", body.getClocationid());
temp.put("batchNum", body.getVbatchcode());
temp.put("customId", null);
temp.put("supplierId", null);
temp.put("manufactureDate", null);
temp.put("remark", body.getVnotebody());
details.add(temp);
}
JSONObject info = new JSONObject();
info.put("details", details);
// 从head中取数
info.put("orderNo", head.getVbillcode());
info.put("type", "QTCK");
info.put("actureDate", head.getDmakedate().toString());
StordocVO warehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid());
if (Objects.isNull(warehouse)) {
throw new BusinessException("仓库信息不存在,主键:" + head.getCwarehouseid());
}
info.put("storeId", warehouse.getCode());
info.put("workerNo", null);
info.put("worker", null);
info.put("storeKeeper", head.getCwhsmanagerid());
info.put("returned", "N");
info.put("mark", "N");
info.put("remark", head.getVnote());
// 拼接数据,先创建一个jsonObject
JSONObject requestData = new JSONObject();
requestData.put("operation_type", "I");// 固定给I 操作
requestData.put("info", info);
obmlog.debug("其它出库requestData:" + requestData.toJSONString());
}
// 调拨出库/转库单
if (generalOutVO.getHead().getVtrantypecode().equals("4I-02")) {
// 表体body信息拼接
JSONArray details = new JSONArray();
GeneralOutHeadVO head = generalOutVO.getHead();
// 填充details
for (GeneralOutBodyVO body : generalOutVO.getBodys()) {// body中取数
JSONObject temp = new JSONObject();
temp.put("orderNo", head.getVbillcode());
temp.put("sequenceNum", body.getCrowno());
temp.put("type", "DBCK");
temp.put("genType", null);
MaterialVersionVO materialVersionVO = (MaterialVersionVO) iUifService.queryByPrimaryKey(MaterialVersionVO.class, body.getCmaterialoid());
if (Objects.isNull(materialVersionVO)) {
throw new BusinessException("搜索物料信息不存在");
}
temp.put("materialId", materialVersionVO.getCode());
temp.put("issuedQty", body.getNshouldnum().doubleValue());
temp.put("actQty", body.getNnum().doubleValue());
temp.put("outQty", body.getNnum().doubleValue());
temp.put("assistActQry", "");
temp.put("productNum", null);
temp.put("outStorageId", body.getClocationid());
temp.put("outBatchNum", body.getVbatchcode());
temp.put("customId", null);
temp.put("supplierId", null);
temp.put("manufactureDate", null);
temp.put("color", null);
temp.put("packLen", null);
temp.put("packSize", null);
temp.put("remark", body.getVnotebody());
details.add(temp);
}
JSONObject info = new JSONObject();
info.put("details", details);
// 从head中取数
info.put("orderNo", head.getVbillcode());
info.put("type", "DBCK");
info.put("genType", null);
info.put("outDate", head.getDbilldate().toString());
StordocVO outWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCwarehouseid());
if (Objects.isNull(outWarehouse)) {
throw new BusinessException("出库仓库信息不存在,主键:" + head.getCwarehouseid());
}
info.put("outStoreId", outWarehouse.getCode());
StordocVO inWarehouse = (StordocVO) iUifService.queryByPrimaryKey(StordocVO.class, head.getCotherwhid());
if (Objects.isNull(inWarehouse)) {
throw new BusinessException("入库仓库信息不存在,主键:" + head.getCotherwhid());
}
info.put("inStoreId", inWarehouse.getCode());
info.put("workerNo", null);
info.put("worker", null);
info.put("storeKeeper", head.getCwhsmanagerid());
info.put("returned", "N");
info.put("mark", "N");
info.put("remark", head.getVnote());
// 拼接数据,先创建一个jsonObject
JSONObject requestData = new JSONObject();
requestData.put("operation_type", "I");// 固定给I 操作
requestData.put("info", info);
obmlog.debug("其它出库requestData:" + requestData.toJSONString());
IHttpPostOtherSys httpService = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
httpService.sendToExternalSystem("test", requestData);
}
}
}

View File

@ -1,5 +1,6 @@
package nc.bs.ic.m4r.approve.rule; package nc.bs.ic.m4r.approve.rule;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yonyou.cloud.utils.StringUtils; import com.yonyou.cloud.utils.StringUtils;
@ -7,12 +8,11 @@ import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Log; import nc.bs.logging.Log;
import nc.impl.pubapp.pattern.rule.IRule; import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.ic.m4r.entity.InvCountBillVO; import nc.vo.ic.m4r.entity.InvCountBillVO;
import nc.vo.ic.m4r.entity.InvCountHeaderVO;
import nc.vo.ic.m4r.entity.InvCountBodyVO; import nc.vo.ic.m4r.entity.InvCountBodyVO;
import nc.vo.ic.m4r.entity.InvCountHeaderVO;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble; import nc.vo.pub.lang.UFDouble;
import nccloud.pubift.commen.impl.utils.HttpPostOtherSysImpl;
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys; import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -46,7 +46,7 @@ public class AfterApprovingSynchronizeRule implements IRule<InvCountBillVO> {
JSONObject syncData = buildSyncData(hvo, bvos); JSONObject syncData = buildSyncData(hvo, bvos);
// 发送数据到金思维系统使用HttpPostOtherSysImpl处理网络请求 // 发送数据到金思维系统使用HttpPostOtherSysImpl处理网络请求
String mesResponse = httpPostOtherSys.callLE(INV_COUNT_URL, syncData); String mesResponse = httpPostOtherSys.callMes(INV_COUNT_URL, syncData);
obmlog.debug("AfterApprovingSynchronizeRule-金思维系统响应: " + mesResponse); obmlog.debug("AfterApprovingSynchronizeRule-金思维系统响应: " + mesResponse);
// 解析响应处理结果 // 解析响应处理结果

View File

@ -22,7 +22,7 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys {
private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login"; private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login";
@Override @Override
public String callLE(String url, JSONObject json) { public String callMes(String url, JSONObject json) {
// String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); // String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP");
String mesip = "http://192.168.29.32"; String mesip = "http://192.168.29.32";
String baseurl = mesip + url; String baseurl = mesip + url;

View File

@ -1,15 +1,48 @@
package nccloud.pubift.commen.itf.utils; package nccloud.pubift.commen.itf.utils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import nc.bs.framework.common.NCLocator;
import nc.vo.pub.BusinessException;
import java.util.Iterator;
import java.util.Map;
public interface IHttpPostOtherSys { public interface IHttpPostOtherSys {
/** /**
* xuwjl@yonyou.com 2025年4月24日 15:24:14 * @param apiPath MES的接口地址不包含ip
* @param url LE的接口地址不包含ip
* @param json Èë²Î * @param json Èë²Î
*/ */
public String callLE(String url, JSONObject json); public String callMes(String apiPath, JSONObject json);
/**
* 发送数据到外部系统
*/
default void sendToExternalSystem(String apiPaht, Map<String, Object> requestData) throws BusinessException {
try {
IHttpPostOtherSys httpService = NCLocator.getInstance().lookup(IHttpPostOtherSys.class);
JSONObject jsonRequest = new JSONObject(requestData);
String response = httpService.callMes(apiPaht, jsonRequest);
JSONObject jsonResponse = JSONObject.parseObject(response);
int code = jsonResponse.getIntValue("code");
if (code != 0) {
throw new Exception("自定义档案同步失败,错误码:" + code + ",消息:" + jsonResponse.getString("message"));
}
if (jsonResponse.containsKey("data") && !jsonResponse.getJSONObject("data").isEmpty()) {
JSONObject data = jsonResponse.getJSONObject("data");
StringBuilder errorMsg = new StringBuilder("自定义档案同步出现错误:");
Iterator<String> keys = data.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
errorMsg.append("\n编码 ").append(key).append(": ").append(data.get(key));
}
throw new Exception(errorMsg.toString());
}
} catch (Exception e) {
throw new BusinessException("调用外部接口失败:" + e.getMessage(), e);
}
}
} }