From da12afa045bd29ae2b7057398a14b9a3ead7bde3 Mon Sep 17 00:00:00 2001 From: Yangwl <1726150332@qq.com> Date: Fri, 24 Nov 2023 15:19:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=92=8CSAP=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=9A=84=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=B7=A5=E5=8E=82=E7=B1=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=BF=9E=E6=8E=A5SAP=E7=B3=BB=E7=BB=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/op/sap/config/DestinationManager.java | 1 - .../sap/service/impl/SapBomServiceImpl.java | 7 ++++++- .../op/sap/service/impl/SapItemSyncImpl.java | 9 +++++++-- .../SapMaterialPreparationServiceImpl.java | 7 ++++++- .../sap/service/impl/SapOrderServiceImpl.java | 13 +++++++++---- .../service/impl/SapRouterServiceImpl.java | 7 ++++++- .../impl/SapWorkCenterServiceImpl.java | 10 +++++++--- .../java/com/op/sap/util/SAPConnUtils.java | 19 ++++++++++++++----- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/op-modules/op-sap/src/main/java/com/op/sap/config/DestinationManager.java b/op-modules/op-sap/src/main/java/com/op/sap/config/DestinationManager.java index 64c2614c..a3b98f66 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/config/DestinationManager.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/config/DestinationManager.java @@ -67,7 +67,6 @@ public class DestinationManager { properties.store(fos, "for test only!"); } catch (Exception e) { // TODO: handle exception -// System.out.println("Create Data file fault,error msg:" + e.toString()); throw new RuntimeException("无法创建目标文件" + cfg.getName()); } } diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java index 79bff835..08a1e329 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapBomServiceImpl.java @@ -23,12 +23,14 @@ import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; +@Component @Service public class SapBomServiceImpl implements SapBomService { private static final String END_DATE="99991231"; @@ -41,13 +43,16 @@ public class SapBomServiceImpl implements SapBomService { @Autowired private SqlSessionFactory sqlSessionFactory; + @Autowired + private JCoDestination dest; + @Override public R bomSync(SapBomQuery sapBomQuery) { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + //JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_BOM"); if (func == null) { diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java index cad097c4..a0c06733 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapItemSyncImpl.java @@ -20,6 +20,7 @@ import com.sap.conn.jco.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import javax.validation.Validator; @@ -28,6 +29,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +@Component @Service public class SapItemSyncImpl implements SapItemSyncService { @@ -41,13 +43,16 @@ public class SapItemSyncImpl implements SapItemSyncService { @Autowired protected Validator validator; + @Autowired + private JCoDestination dest; + private static final Logger log = LoggerFactory.getLogger(SapItemSyncImpl.class); @Override public R itemSync(SapItemQuery sapItemQuery) { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZMMR_MES_MAT_GET"); @@ -200,7 +205,7 @@ public class SapItemSyncImpl implements SapItemSyncService { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_GOODSMVT_CREATE"); // 配置传入参数 diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapMaterialPreparationServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapMaterialPreparationServiceImpl.java index b0b1d752..4c4a80db 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapMaterialPreparationServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapMaterialPreparationServiceImpl.java @@ -9,17 +9,22 @@ import com.op.sap.util.SAPConnUtils; import com.op.system.api.domain.sap.SapMaterialPreparation; import com.sap.conn.jco.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +@Component @Service public class SapMaterialPreparationServiceImpl implements SapMaterialPreparationService { @Autowired SapMaterialPreparationMapper sapMaterialPreparationMapper; + @Autowired + private JCoDestination dest; + @Override public R> MaterialPreparation(String shopOrder) { // 连接 @@ -27,7 +32,7 @@ public class SapMaterialPreparationServiceImpl implements SapMaterialPreparation try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_MATERIAL_PREPARATION"); if (func == null) { 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 3c9803ba..561d8c53 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 @@ -15,6 +15,8 @@ import com.op.system.api.domain.sap.SapShopOrderQuery; import com.op.system.api.model.SapProOrder; import com.sap.conn.jco.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -23,10 +25,13 @@ import java.util.List; import java.util.Map; +@Component @Service public class SapOrderServiceImpl implements SapOrderService { private static final String END_DATE="99991231"; + @Autowired + private JCoDestination dest; @Override public R> shopOrderSync(SapShopOrderQuery sapShopOrderQuery) { @@ -34,7 +39,7 @@ public class SapOrderServiceImpl implements SapOrderService { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + //JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_PRO_TO"); if (func == null) { @@ -147,7 +152,7 @@ public class SapOrderServiceImpl implements SapOrderService { String L_MSG=null; try { //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_PRODORD_CREATE"); if (func == null) { @@ -200,7 +205,7 @@ public class SapOrderServiceImpl implements SapOrderService { String L_MSG=null; try { //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_PRODORD_CLOSE"); if (func == null) { @@ -232,7 +237,7 @@ public class SapOrderServiceImpl implements SapOrderService { String MESSAGE=null; try { //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_PRODORDCONF_CREATE_TT"); if (func == null) { diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapRouterServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapRouterServiceImpl.java index f2559511..494e865f 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapRouterServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapRouterServiceImpl.java @@ -14,6 +14,7 @@ import com.op.sap.util.SAPConnUtils; import com.op.system.api.domain.sap.*; import com.sap.conn.jco.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import javax.validation.Validator; import java.rmi.ServerException; @@ -23,6 +24,7 @@ import java.util.List; import java.util.TreeSet; import java.util.stream.Collectors; +@Component @Service public class SapRouterServiceImpl implements SapRouterService { private static final String END_DATE="99991231"; @@ -41,6 +43,9 @@ public class SapRouterServiceImpl implements SapRouterService { @Autowired protected Validator validator; + @Autowired + private JCoDestination dest; + @Override public R sapRouterSync(SapRouterQuery sapRouterQuery) { int successNum = 0; @@ -50,7 +55,7 @@ public class SapRouterServiceImpl implements SapRouterService { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZPPR_MES_ROUTING"); if (func == null) { diff --git a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java index 69784f2a..c4e07dcd 100644 --- a/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java +++ b/op-modules/op-sap/src/main/java/com/op/sap/service/impl/SapWorkCenterServiceImpl.java @@ -14,6 +14,7 @@ import com.op.system.api.domain.sap.SapSupplier; import com.op.system.api.domain.sap.SapWorkCenter; import com.sap.conn.jco.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -22,19 +23,22 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +@Component @Service public class SapWorkCenterServiceImpl implements SapWorkCenterService { private static final String END_DATE="99991231"; @Autowired private SapBomMapper sapBomMapper; + @Autowired + private JCoDestination dest; @Override public R sapWorkCenterSync(SapWorkCenterQuery sapWorkCenterQuery) { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZMES_GET_ARBPL"); if (func == null) { @@ -111,7 +115,7 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZMES_GET_LFB1"); if (func == null) { @@ -188,7 +192,7 @@ public class SapWorkCenterServiceImpl implements SapWorkCenterService { try { // 获取调用 RFC 函数对象 //获取连接 - JCoDestination dest = SAPConnUtils.connect(); + // JCoDestination dest = SAPConnUtils.connect(); JCoRepository repository = dest.getRepository(); JCoFunction func = repository.getFunction("ZMES_GET_KNA1"); if (func == null) { 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 2d704d44..d187ff82 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 @@ -4,20 +4,29 @@ package com.op.sap.util; import com.sap.conn.jco.JCoDestination; import com.sap.conn.jco.JCoDestinationManager; import com.sap.conn.jco.JCoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +@Component public class SAPConnUtils { + + protected Logger logger = LoggerFactory.getLogger(getClass()); private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL"; - public static JCoDestination connect() { + + @Bean + public JCoDestination connect() { JCoDestination destination = null; try { destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED); -// System.out.println(destination.getAttributes()); + if (destination!=null){ + logger.info("连接SAP成功"); + } } catch (JCoException e) { - // TODO: handle exception + logger.info("连接SAP失败,错误: " + e.toString()); throw new RuntimeException("连接SAP失败,错误: " + e.toString()); -// System.out.println("连接SAP失败,错误: " + e.toString()); } return destination; } - }