SAP-RFC 函数封装

This commit is contained in:
xd 2024-04-30 14:25:02 +08:00
parent 71910079e6
commit a940b1d832
13 changed files with 454 additions and 14 deletions

View File

@ -0,0 +1,11 @@
#for tests only !
#Tue Apr 30 14:23:52 CST 2024
jco.destination.pool_capacity=10
jco.client.lang=ZH
jco.client.ashost=172.19.0.125
jco.client.saprouter=
jco.client.user=RFC
jco.client.sysnr=00
jco.destination.peak_limit=10
jco.client.passwd=dZ7%0^^S.BC9=76d+x^RaptI:lSr7*7(n*?L**;[-c`$qn-b
jco.client.client=800

View File

@ -16,7 +16,6 @@
</description>
<dependencies>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -98,6 +97,15 @@
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<!-- sapjco3 -->
<dependency>
<groupId>com.sap.conn.jco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.1.2</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/sapjco3.jar</systemPath>
</dependency>
</dependencies>
<build>
@ -108,6 +116,7 @@
<version>2.5.15</version>
<configuration>
<fork>true</fork> <!-- 如果没有该配置devtools不会生效 -->
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>

View File

@ -0,0 +1,117 @@
package com.ruoyi.web.controller.common;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.file.MinioUtil;
import com.ruoyi.customer.domain.Customer;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.materialType.domain.CMaterialType;
import com.ruoyi.web.utils.SapFunction.RfcResult;
import com.ruoyi.web.utils.SapFunction.SapRfcUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* SAP-Rfc Controller
*
* @author ruoyi
*/
@RestController
@RequestMapping("/rfc/rfc")
public class SapRfcController
{
private static final Logger log = LoggerFactory.getLogger(SapRfcController.class);
@Autowired
private RedisCache redisCache;
/**
* 获取SAP 国家数据
* @param customer
* @return
*/
@PreAuthorize("@ss.hasPermi('customer:customer:list')")
@GetMapping("/getCountrys")
public AjaxResult countrys(Customer customer)
{
AjaxResult ajax = AjaxResult.success();
List<RfcResult> resCache = redisCache.getCacheObject(getSapCacheKey("country"));
if(CollectionUtils.isEmpty(resCache)){
resCache = SapRfcUtils.getCountrys(null);
redisCache.setCacheObject(getSapCacheKey("country"),resCache);
}
log.info("获取国家数据条数 - {}", resCache.size());
ajax.put("countrysDicts", resCache);
return ajax;
}
/**
* 获取SAP 行业代码数据
* @param customer
* @return
*/
@PreAuthorize("@ss.hasPermi('customer:customer:list')")
@GetMapping("/getIndustryCode")
public AjaxResult industryCode(Customer customer)
{
AjaxResult ajax = AjaxResult.success();
List<RfcResult> resCache = redisCache.getCacheObject(getSapCacheKey("industryCode"));
if(CollectionUtils.isEmpty(resCache)){
resCache = SapRfcUtils.getIndustryCode(null);
redisCache.setCacheObject(getSapCacheKey("industryCode"),resCache);
}
log.info("获取行业代码数据条数 - {}", resCache.size());
ajax.put("industryCodeDicts", resCache);
return ajax;
}
/**
* 获取SAP 语言数据
* @param customer
* @return
*/
@PreAuthorize("@ss.hasPermi('customer:customer:list')")
@GetMapping("/getLanguage")
public AjaxResult language(Customer customer)
{
AjaxResult ajax = AjaxResult.success();
List<RfcResult> resCache = redisCache.getCacheObject(getSapCacheKey("language"));
if(CollectionUtils.isEmpty(resCache)){
resCache = SapRfcUtils.getLanguage(null);
redisCache.setCacheObject(getSapCacheKey("language"),resCache);
}
log.info("获取语言数据条数 - {}", resCache.size());
ajax.put("languageDicts", resCache);
return ajax;
}
private String getSapCacheKey(String type)
{
return CacheConstants.SAP_COMMON + type;
}
}

View File

@ -44,6 +44,8 @@ public class CacheController
caches.add(new SysCache(CacheConstants.PWD_ERR_CNT_KEY, "密码错误次数"));
caches.add(new SysCache(CacheConstants.STORAGE_LOCATION, "车间库位"));
caches.add(new SysCache(CacheConstants.SYS_JOB_KEY, "定时任务"));
caches.add(new SysCache(CacheConstants.SAP_COMMON, "SAP公共数据"));
}
@PreAuthorize("@ss.hasPermi('monitor:cache:list')")

View File

@ -0,0 +1,83 @@
package com.ruoyi.web.utils.SapFunction;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
public class ConnectToSAP {
private static final String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
private static JCoDestination destination = null;
/**
* 初始化SAP连接
*/
private static void initProperties() {
Properties connectProperties = new Properties();
// SAP服务器
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "172.19.0.125");
// SAP系统编号
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "00");
// SAP集团
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "800");
// SAP用户名
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "RFC");
// SAP密码
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "654321");
// SAP登录语言
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
// 最大连接数
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "10");
// 最大连接线程
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
// SAP ROUTER
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, "");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
/**
* 创建SAP接口属性文件
*
* @param name
* ABAP管道名称
* @param suffix
* 属性文件后缀
* @param properties
* 属性文件内容
*/
private static void createDataFile(String name, String suffix, Properties properties) {
File cfg = new File(name + "." + suffix);
if (cfg.exists()) {
cfg.deleteOnExit();
}
try {
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
} catch (Exception e) {
System.out.println("Create Data file fault, error msg: " + e.toString());
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
/*
* * 获取SAP连接
*
* @return SAP连接对象
*/
public static JCoDestination connect() {
try {
initProperties();
if(null == destination)
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
} catch (JCoException e) {
System.out.println("Connect SAP fault, error msg: " + e.toString());
}
return destination;
}
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.web.utils.SapFunction;
public class RfcResult {
private String value;
private String label;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -0,0 +1,108 @@
package com.ruoyi.web.utils.SapFunction;
import com.ruoyi.common.utils.StringUtils;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoTable;
import java.util.ArrayList;
import java.util.List;
public class SapRfcUtils {
/**
* 获取SAP国家数据
* @param param 不传查询全部
* @return
*/
public static List<RfcResult> getCountrys(String param){
JCoFunction function = null;
RfcResult rfcResult = null;
List<RfcResult> countrys = new ArrayList<>();
JCoDestination destination = ConnectToSAP.connect();
try {
function = destination.getRepository().getFunctionTemplate("ZRFC_BASIC_DATA").getFunction();
if (function == null)
throw new RuntimeException("RFC_SYSTEM_INFO not found in SAP.");
JCoParameterList input = function.getImportParameterList();
input.setValue("FALG20", StringUtils.isNotNull(param)?param:"X");//输入参数
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("T_T005T");
for(int i = 0; i<table.getNumRows(); i++){
table.setRow(i);
rfcResult = new RfcResult();
rfcResult.setValue(table.getString("LAND1"));
rfcResult.setLabel(table.getString("LANDX"));
countrys.add(rfcResult);
}
}catch (Exception e) {
e.printStackTrace();
}
return countrys;
}
/**
* 获取SAP行业代码数据
* @param param 不传查询全部
* @return
*/
public static List<RfcResult> getIndustryCode(String param){
JCoFunction function = null;
RfcResult rfcResult = null;
List<RfcResult> countrys = new ArrayList<>();
JCoDestination destination = ConnectToSAP.connect();
try {
function = destination.getRepository().getFunctionTemplate("ZRFC_BASIC_DATA").getFunction();
if (function == null)
throw new RuntimeException("RFC_SYSTEM_INFO not found in SAP.");
JCoParameterList input = function.getImportParameterList();
input.setValue("FLAG59", StringUtils.isNotNull(param)?param:"X");//输入参数
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("T_TBRC");
for(int i = 0; i<table.getNumRows(); i++){
table.setRow(i);
rfcResult = new RfcResult();
rfcResult.setValue(table.getString("BRACO"));
rfcResult.setLabel(table.getString("VTEXT"));
countrys.add(rfcResult);
}
}catch (Exception e) {
e.printStackTrace();
}
return countrys;
}
/**
* 获取SAP语言数据
* @param param 不传查询全部
* @return
*/
public static List<RfcResult> getLanguage(String param){
JCoFunction function = null;
RfcResult rfcResult = null;
List<RfcResult> countrys = new ArrayList<>();
JCoDestination destination = ConnectToSAP.connect();
try {
function = destination.getRepository().getFunctionTemplate("ZRFC_BASIC_DATA").getFunction();
if (function == null)
throw new RuntimeException("RFC_SYSTEM_INFO not found in SAP.");
JCoParameterList input = function.getImportParameterList();
input.setValue("FLAG27", StringUtils.isNotNull(param)?param:"X");//输入参数
function.execute(destination);
JCoTable table = function.getTableParameterList().getTable("T_T002T");
for(int i = 0; i<table.getNumRows(); i++){
table.setRow(i);
rfcResult = new RfcResult();
rfcResult.setValue(table.getString("SPRSL"));
rfcResult.setLabel(table.getString("SPTXT"));
countrys.add(rfcResult);
}
}catch (Exception e) {
e.printStackTrace();
}
return countrys;
}
}

View File

@ -1,12 +1,26 @@
# 远程下单提交时间范围
order.commitDateBeginAm: 08:00:00
order.commitDateEndAm: 12:00:00
order.commitDateBeginPm: 12:00:00
order.commitDateEndPm: 20:00:00
# sapWebservice
sapWebservice.host: poprd
sapWebservice.user: PO_USER
sapWebservice.psw: QAZ54321
# 企查查
qichacha.key: 824936f8e78c4f4788978da38b26d488
qichacha.secretKey: 8B9EB102FD17E0CF2EDEC0FB507DEC1E
qichacha.serviceName: https://api.qichacha.com/FuzzySearch/GetList
# SAP-RFC函数
sapRfc.ashost: 172.19.0.125 #服务器
sapRfc.sysnr: 00 #系统编号
sapRfc.client: 800 #集团
sapRfc.user: RFC #用户名
sapRfc.passwd: 654321 #密码
sapRfc.lang: ZH #登录语言
sapRfc.pool_capacity: 10 #最大连接数
sapRfc.peak_limit: 10 #最大连接线程
sapRfc.saprouter: #路由

Binary file not shown.

Binary file not shown.

View File

@ -51,4 +51,9 @@ public class CacheConstants
* 定时任务 redis key
*/
public static final String SYS_JOB_KEY = "sys_job:";
/**
* SAP-公共数据 redis key
*/
public static final String SAP_COMMON = "sap_common:";
}

View File

@ -0,0 +1,27 @@
import request from '@/utils/request'
// 查询SAP 国家数据
export function getCountrys(query) {
return request({
url: '/rfc/rfc/getCountrys',
method: 'get',
params: query
})
}
// 查询SAP 行业代码数据
export function getIndustryCode(query) {
return request({
url: '/rfc/rfc/getIndustryCode',
method: 'get',
params: query
})
}
// 查询SAP 语言数据
export function getLanguage(query) {
return request({
url: '/rfc/rfc/getLanguage',
method: 'get',
params: query
})
}

View File

@ -237,11 +237,11 @@
<el-form-item label="国家" prop="cusCountry">
<el-select v-model="form.cusCountry" placeholder="请选择国家" style="width: 100%;" :disabled="isDis">
<el-option
v-for="dict in dict.type.cus_country"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
v-for="item in countrysDicts"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
@ -249,11 +249,11 @@
<el-form-item label="语言" prop="cusLanguage">
<el-select v-model="form.cusLanguage" placeholder="请选择语言" style="width: 100%;" :disabled="isDis">
<el-option
v-for="dict in dict.type.cus_language"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
v-for="item in languageDicts"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
@ -390,9 +390,11 @@
<script>
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer, commitCustomer, qccListCustomer } from "@/api/customer/customer";
import { checkPermi, checkRole } from "@/utils/permission"; //
import { getCountrys,getIndustryCode,getLanguage } from "@/api/common/sapRfc";// sap-rfc
export default {
name: "Customer",
dicts: ['cus_country', 'cus_payment_terms', 'cus_group', 'cus_approval_status', 'cus_language', 'cus_type', 'common_state'],
dicts: ['cus_payment_terms', 'cus_group', 'cus_approval_status', 'cus_language', 'cus_type', 'common_state'],
data() {
return {
//
@ -487,8 +489,14 @@ export default {
qccMultiple: true,
queryQccParams:{
Name: null
}
},
/*****************************企查查查询模块*************************************/
/*****************************SAP-RFC查询模块*************************************/
countrysDicts: [], //
industryCodeDicts: [], //
languageDicts: [], //
/*****************************SAP-RFC查询模块*************************************/
};
},
created() {
@ -565,6 +573,13 @@ export default {
this.form.cusCountry = 'CN';
this.form.cusLanguage = 'ZH';
this.form.cusType = '0';
//SAP
this.getCountrys();
//SAP
this.getIndustryCode();
//SAP
this.getLanguage();
},
/** 修改按钮操作 */
handleUpdate(row) {
@ -577,6 +592,13 @@ export default {
this.bankList = response.data.bankList;
this.open = true;
this.title = "修改客户信息";
//SAP
this.getCountrys();
//SAP
this.getIndustryCode();
//SAP
this.getLanguage();
});
},
/** 保存按钮 */
@ -714,8 +736,28 @@ export default {
this.qccCustomerList = [];
//this.qccTotal = 0;
this.resetForm("queryQccForm");
}
},
/*****************************企查查查询模块*************************************/
/*****************************SAP-RFC查询模块*************************************/
//SAP
getCountrys(){
getCountrys(this.queryParams).then(response => {
this.countrysDicts = response.countrysDicts;
});
},
//SAP
getIndustryCode(){
getIndustryCode(this.queryParams).then(response => {
this.industryCodeDicts = response.industryCodeDicts;
});
},
//SAP
getLanguage(){
getLanguage(this.queryParams).then(response => {
this.languageDicts = response.languageDicts;
});
},
/*****************************SAP-RFC查询模块*************************************/
},
/* computed: {
//