From 8e815945eb16c042bd60848d8b5db60796cce1fa Mon Sep 17 00:00:00 2001 From: Yangwl <1726150332@qq.com> Date: Mon, 27 Nov 2023 14:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0SAP=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E5=92=8C@Bean=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=85=88=E5=90=8E=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/op/sap/controller/SapController.java | 22 +++++ .../com/op/sap/service/SapOrderService.java | 5 + .../sap/service/impl/SapOrderServiceImpl.java | 93 +++++++++++++++++++ .../java/com/op/sap/util/SAPConnUtils.java | 2 + 4 files changed, 122 insertions(+) diff --git a/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java b/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java index cb9f6cea..393bb74e 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/controller/SapController.java @@ -62,6 +62,17 @@ public class SapController extends BaseController { return sapOrderService.shopOrderSync(sapProOrder); } + /** + * SAP订单修改接口 + * 传递母订单号和母订单数量 + */ + @PostMapping("/shopUpdateSync") + @Log(title = "修改SAP订单", businessType = BusinessType.SAP) + public R shopUpdateSync(@RequestBody SapShopOrderQuery sapProOrder){ + return sapOrderService.shopUpdateSync(sapProOrder); + } + + /** * 物料同步接口 * @param @@ -357,5 +368,16 @@ public class SapController extends BaseController { } + /** + * 采购订单接口 + */ + + @PostMapping("/sapPurchaseOrderSync") + @Log(title = "获取采购订单", businessType = BusinessType.SAP) + public R sapPurchaseOrderSync(@RequestBody SapPurchaseOrderQuery sapPurchaseOrderQuery){ + return sapOrderService.sapPurchaseOrderSync(sapPurchaseOrderQuery); + } + + } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java b/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java index adf895b1..fe4273ae 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/SapOrderService.java @@ -2,6 +2,7 @@ package com.op.sap.service; import com.op.common.core.domain.R; +import com.op.sap.domain.vo.SapPurchaseOrderQuery; import com.op.system.api.domain.sap.SapCreateOrder; import com.op.system.api.domain.sap.SapRFW; import com.op.system.api.domain.sap.SapShopOrderQuery; @@ -44,4 +45,8 @@ public interface SapOrderService { */ R sapRFWOrder(SapRFW sapRFW); + + R sapPurchaseOrderSync(SapPurchaseOrderQuery sapPurchaseOrderQuery); + + R shopUpdateSync(SapShopOrderQuery sapProOrder); } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapOrderServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapOrderServiceImpl.java index 561d8c53..96667412 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapOrderServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapOrderServiceImpl.java @@ -6,6 +6,7 @@ import com.op.common.core.utils.DateUtils; import com.op.common.core.utils.StringUtils; import com.op.common.core.utils.uuid.IdUtils; +import com.op.sap.domain.vo.SapPurchaseOrderQuery; import com.op.sap.service.SapOrderService; import com.op.sap.util.SAPConnUtils; @@ -296,6 +297,98 @@ public class SapOrderServiceImpl implements SapOrderService { return R.fail(e.getMessage()); } } + + @Override + public R sapPurchaseOrderSync(SapPurchaseOrderQuery sapPurchaseOrderQuery) { + try { + // 获取调用 RFC 函数对象 + //获取连接 + //JCoDestination dest = SAPConnUtils.connect(); + JCoRepository repository = dest.getRepository(); + JCoFunction func = repository.getFunction("ZMES_GET_PROCURE"); + JCoParameterList jCoParameterList= func.getTableParameterList(); + System.out.println(jCoParameterList); + if (func == null) { + throw new RuntimeException("Function does not exist in SAP"); + } + /** S_EBELN 采购订单号 + * S_EBELP 行项目 + * S_MATNR 物料号 + * S_PWERK 工厂 + */ + if (!StringUtils.isNull(sapPurchaseOrderQuery.getEbeln())){ + JCoTable S_EBELN = func.getTableParameterList().getTable("S_EBELN"); + S_EBELN.appendRow(); + S_EBELN.setValue(Constants.SIGN, "I"); + S_EBELN.setValue(Constants.OPTION, "EQ"); + S_EBELN.setValue(Constants.LOW, sapPurchaseOrderQuery.getEbeln()); + } + if (!StringUtils.isNull(sapPurchaseOrderQuery.getEbeln())){ + JCoTable S_EBELN = func.getTableParameterList().getTable("S_EBELP"); + S_EBELN.appendRow(); + S_EBELN.setValue(Constants.SIGN, "I"); + S_EBELN.setValue(Constants.OPTION, "EQ"); + S_EBELN.setValue(Constants.LOW, sapPurchaseOrderQuery.getEbeln()); + } + if (!StringUtils.isNull(sapPurchaseOrderQuery.getMatnr())){ + JCoTable S_MATNR = func.getTableParameterList().getTable("S_MATNR"); + S_MATNR.appendRow(); + S_MATNR.setValue(Constants.SIGN, "I"); + S_MATNR.setValue(Constants.OPTION, "EQ"); + S_MATNR.setValue(Constants.LOW, sapPurchaseOrderQuery.getMatnr()); + } + + if (!StringUtils.isNull(sapPurchaseOrderQuery.getPwerk())){ + JCoTable S_PWERK = func.getTableParameterList().getTable("S_PWERK"); + S_PWERK.appendRow(); + S_PWERK.setValue(Constants.SIGN, "I"); + S_PWERK.setValue(Constants.OPTION, "EQ"); + S_PWERK.setValue(Constants.LOW, sapPurchaseOrderQuery.getPwerk()); + } + func.execute(dest);//执行调用函数 + // 获取 内表 - LT_PROCURE + JCoTable maraTable = func.getTableParameterList().getTable("LT_PROCURE"); + JCoRecordMetaData metaData = maraTable.getRecordMetaData(); + System.out.println("###" + metaData.toString()); + return R.ok(); + }catch (Exception e){ + return R.fail(e.getMessage()); + } + + } + + @Override + public R shopUpdateSync(SapShopOrderQuery sapProOrder) { + try { + JCoRepository repository = dest.getRepository(); + JCoFunction func = repository.getFunction("ZPPR_MES_PRODORD_CHANGE"); + // 配置传入参数 + JCoParameterList jCoParameterList = func.getImportParameterList(); + System.out.println(jCoParameterList); + if (func == null) { + throw new RuntimeException("Function does not exist in SAP"); + } + if (StringUtils.isEmpty(sapProOrder.getAufnr())) + { + return R.fail("订单号为空!"); + } + if (StringUtils.isEmpty(sapProOrder.getQuantity())) + { + return R.fail("数量为空!"); + } + + jCoParameterList.setValue("P_AUFNR",sapProOrder.getAufnr()); + jCoParameterList.setValue("P_QUANTITY",sapProOrder.getQuantity()); + func.execute(dest);//执行调用函数 + JCoParameterList J= func.getExportParameterList(); + System.out.println(J); + String MESSAGE= func.getExportParameterList().getString("MESSAGE"); + System.out.println(MESSAGE); + return R.ok(MESSAGE); + }catch (Exception e){ + return R.fail(e.getMessage()); + } + } } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/util/SAPConnUtils.java b/op-modules/op-sap/src/main/java/com/op/sap/util/SAPConnUtils.java index d187ff82..7266fb09 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/util/SAPConnUtils.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/util/SAPConnUtils.java @@ -7,6 +7,7 @@ import com.sap.conn.jco.JCoException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.DependsOn; import org.springframework.stereotype.Component; @Component @@ -16,6 +17,7 @@ public class SAPConnUtils { private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL"; @Bean + @DependsOn("CreateABAP") public JCoDestination connect() { JCoDestination destination = null; try {