修改和SAP连接的方式,使用工厂类,避免重复连接SAP系统。

highway
Yangwl 12 months ago
parent e1e5b8f1fc
commit da12afa045

@ -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());
}
}

@ -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) {

@ -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");
// 配置传入参数

@ -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<List<SapMaterialPreparation>> 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) {

@ -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<List<SapProOrder>> 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) {

@ -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) {

@ -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) {

@ -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;
}
}

Loading…
Cancel
Save