From 06d9000c40a43c67089807db74b5094a445d4956 Mon Sep 17 00:00:00 2001 From: zhengyf Date: Wed, 7 Aug 2024 14:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BD=E7=9F=A5=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8E=A8=E9=80=81u8c=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=88pk/cod?= =?UTF-8?q?e=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/lets/constant/OverallConstant.java | 93 ++++++++++++ .../lets/constant/ProfilesActiveConstant.java | 26 ++++ .../plugin/lets/util/PushDataByU8cUtil.java | 137 ++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/OverallConstant.java create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ProfilesActiveConstant.java create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/PushDataByU8cUtil.java diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/OverallConstant.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/OverallConstant.java new file mode 100644 index 00000000..f2bea2e7 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/OverallConstant.java @@ -0,0 +1,93 @@ +package com.hzya.frame.plugin.lets.constant; + +import java.util.HashMap; +import java.util.Map; + +/** + * lets全局静态参数配置 + * + */ +public class OverallConstant { + + private static final Map devOverAll = new HashMap<>(); + + private static final Map testOverAll = new HashMap<>(); + + private static final Map prodOverAll = new HashMap<>(); + + private static final Map prodOverPublic = new HashMap<>(); + + static { + //dev + loadDev(); + //prod + loadProd(); + //公共部分 + loadPublic(); + } + + private static void loadPublic() { + + //存货分类 + prodOverPublic.put("bdinvclSave", "/u8cloud/api/uapbd/bdinvcl/save");//存货分类新增 + prodOverPublic.put("bdinvclUpdate", "/u8cloud/api/uapbd/bdinvcl/update");//存货分类修改 + prodOverPublic.put("bdinvclDelete", "/u8cloud/api/uapbd/bdinvcl/delete");//存货分类删除 + //存货基本档案 + /** + * * 存货基本档案新增 /u8cloud/api/uapbd/invbasdoc/insert + * * 存货基本档案修改 /u8cloud/api/uapbd/invbasdoc/update + * * 存货基本档案封存 /u8cloud/api/uapbd/invbasdoc/seal + * * 存货基本档案取消封存 /u8cloud/api/uapbd/invbasdoc/unseal + */ + prodOverPublic.put("bdinvclSave", "/u8cloud/api/uapbd/bdinvcl/save");//存货分类新增 + + + + } + + private static void loadDev() { + + devOverAll.put("u8cApiUsercodePK", "admin"); + devOverAll.put("u8cApiPasswordPK", "21232f297a57a5a743894a0e4a801fc3"); + devOverAll.put("u8cApiTrantypePK", "pk"); + devOverAll.put("u8cApiSystemPK", "lz"); + devOverAll.put("u8cApiServiceNamePK", "http://39.170.109.90:9099");//测试U8C + devOverAll.put("u8cApiNeedStackTracePK", "Y"); + devOverAll.put("u8cApiZdrPK", "0001A210000000000GVS");//单据制单人---测试环境:郑一凡 + + devOverAll.put("u8cApiUsercodeCode", "admin1"); + devOverAll.put("u8cApiPasswordCode", "e00cf25ad42683b3df678c61f42c6bda"); + devOverAll.put("u8cApiTrantypeCode", "code"); + devOverAll.put("u8cApiSystemCode", "lz1"); + devOverAll.put("u8cApiServiceNameCode", "http://39.170.109.90:9099");//测试U8C + devOverAll.put("u8cApiNeedStackTraceCode", "Y"); + devOverAll.put("u8cApiZdrCode", "15932295350");//单据制单人---测试环境:郑一凡 + + } + + private static void loadProd() { + + + } + + /** + * 根据key获取全局变量值 + * + * @param key key值 + * @return 返回String + */ + public static String getOverAllValue(String key) { + String value = null; + if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals("dev")) { + value = devOverAll.get(key); + } else if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals("test")) { + value = testOverAll.get(key); + } else if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals("prod")) { + value = prodOverAll.get(key); + } + if (value == null) { + value = prodOverPublic.get(key); + } + return value; + } +} \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ProfilesActiveConstant.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ProfilesActiveConstant.java new file mode 100644 index 00000000..62f90ae2 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/constant/ProfilesActiveConstant.java @@ -0,0 +1,26 @@ +package com.hzya.frame.plugin.lets.constant; + +/** + * lets项目公共参数 + * + */ +public class ProfilesActiveConstant { + + public static final String LETS_PROFILES_ACTIVE = "dev"; + + public static final String LOG_STATUS_Y = "Y"; + + public static final String LOG_STATUS_N = "N"; + + public static final String LOG_STATUS_Y_H = "'Y','H'"; + + public static final String TYPE_DATE = "date"; + + public static final String TYPE_VBILLCODE = "vbillcode"; + + public static final String TYPE_DETAIL_ERROR = "details_error"; + + public static final String TYPE_TIME_FRAME = "time_frame"; + + public static final String TYPE_OTHER = "other"; +} \ No newline at end of file diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/PushDataByU8cUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/PushDataByU8cUtil.java new file mode 100644 index 00000000..b5488581 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/PushDataByU8cUtil.java @@ -0,0 +1,137 @@ +package com.hzya.frame.plugin.lets.util; + +import cn.hutool.core.lang.Assert; + +import com.hzya.frame.plugin.lets.constant.OverallConstant; +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.springframework.stereotype.Component; + +/** + * U8C推送工具类 + */ +@Component +public class PushDataByU8cUtil { + /** + * 发起post请求,传递json类型 + * + * @param url 地址 + * @param data 请求参数 + * @return 返回消息 + */ + public String pushU8CByPK(String url, String data) throws Exception { + Assert.notNull(url, "请求地址不能为空"); + Assert.notNull(data, "请求参数不能为空(需要JSON格式)"); + + // 创建HttpClientBuilder + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + // HttpClient + CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); + + try { + // 设置连接超时和读取超时 + RequestConfig requestConfig = RequestConfig.custom() + .setConnectTimeout(300000) // 连接超时时间为60秒 + .setSocketTimeout(300000) // 读取超时时间为60秒 + .build(); + + HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiServiceNamePK") + url); + post.setHeader("Content-Type", "application/json;charset=UTF-8"); + post.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodePK")); + post.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordPK")); + post.setHeader("trantype", OverallConstant.getOverAllValue("u8cApiTrantypePK")); + post.setHeader("system", OverallConstant.getOverAllValue("u8cApiSystemPK")); + post.setHeader("needStackTrace", OverallConstant.getOverAllValue("u8cApiNeedStackTracePK")); + post.setConfig(requestConfig); + //post.setHeader("charset", "utf-8"); + + ByteArrayEntity entity = new ByteArrayEntity(data.getBytes("UTF-8")); + entity.setContentType("application/json"); + post.setEntity(entity); + + HttpResponse response = closeableHttpClient.execute(post); + // 处理返回结果乱码问题 + if (response != null && response.getEntity() != null) { + String resultStr = EntityUtils.toString(response.getEntity(), "UTF-8"); + return resultStr; + } + } catch (Exception e) { + e.printStackTrace(); + Assert.state(false, "拉取/推送失败(pushU8CByPK),失败原因:{} 请求地址:{}", e.getMessage(), url); + } finally { + try { + if (closeableHttpClient != null) { + closeableHttpClient.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * 发起post请求,传递json类型 + * + * u8c code模式。 + * + * @param url 地址 + * @param data 请求参数 + * @return 返回消息 + */ + public String pushU8CByCode(String url, String data) throws Exception { + Assert.notNull(url, "请求地址不能为空"); + Assert.notNull(data, "请求参数不能为空(需要JSON格式)"); + + // 创建HttpClientBuilder + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + // HttpClient + CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); + + try { + // 设置连接超时和读取超时 + RequestConfig requestConfig = RequestConfig.custom() + .setConnectTimeout(300000) // 连接超时时间为60秒 + .setSocketTimeout(300000) // 读取超时时间为60秒 + .build(); + + HttpPost post = new HttpPost(OverallConstant.getOverAllValue("u8cApiServiceNameCode") + url); + post.setHeader("Content-Type", "application/json;charset=UTF-8"); + post.setHeader("usercode", OverallConstant.getOverAllValue("u8cApiUsercodeCode")); + post.setHeader("password", OverallConstant.getOverAllValue("u8cApiPasswordCode")); + post.setHeader("trantype", OverallConstant.getOverAllValue("u8cApiTrantypeCode")); + post.setHeader("system", OverallConstant.getOverAllValue("u8cApiSystemCode")); + post.setHeader("needStackTrace", OverallConstant.getOverAllValue("u8cApiNeedStackTraceCode")); + post.setConfig(requestConfig); + //post.setHeader("charset", "utf-8"); + + ByteArrayEntity entity = new ByteArrayEntity(data.getBytes("UTF-8")); + entity.setContentType("application/json"); + post.setEntity(entity); + + HttpResponse response = closeableHttpClient.execute(post); + // 处理返回结果乱码问题 + if (response != null && response.getEntity() != null) { + String resultStr = EntityUtils.toString(response.getEntity(), "UTF-8"); + return resultStr; + } + } catch (Exception e) { + e.printStackTrace(); + Assert.state(false, "拉取/推送失败(pushU8CByCode),失败原因:{} 请求地址:{}", e.getMessage(), url); + } finally { + try { + if (closeableHttpClient != null) { + closeableHttpClient.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +}