From 28c3c1e74aad3e421a315afce48053018bfd77a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= Date: Thu, 15 May 2025 11:00:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(ic):=20=E5=AE=9E=E7=8E=B0=E4=BA=86?= =?UTF-8?q?=E4=B8=8E=E5=85=B6=E4=BB=96=E7=B3=BB=E7=BB=9F=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?HTTP=20POST=E4=BA=A4=E4=BA=92=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增了HttpPostOtherSysImpl类,实现了IHttpPostOtherSys接口 - 实现了调用LE系统接口的功能,包括获取token和发送POST请求 - 代码中使用了Fastjson、StringUtils等工具库- 异常处理使用了ExceptionUtils进行业务异常包装 --- .../nc/bs/ic/HttpPostOtherSysImpl.java | 89 +++++++++++++++++++ ic/src/public/nc/IHttpPostOtherSys.java | 15 ++++ 2 files changed, 104 insertions(+) create mode 100644 ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java create mode 100644 ic/src/public/nc/IHttpPostOtherSys.java diff --git a/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java b/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java new file mode 100644 index 0000000..0f2fd70 --- /dev/null +++ b/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java @@ -0,0 +1,89 @@ +package nc.bs.ic; + +import com.alibaba.fastjson.JSONObject; +import nc.IHttpPostOtherSys; +import nc.hr.utils.PubEnv; +import nc.itf.scmpub.reference.uap.para.SysParaInitQuery; +import nc.pub.fa.common.util.StringUtils; +import nc.vo.pubapp.pattern.exception.ExceptionUtils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +public class HttpPostOtherSysImpl implements IHttpPostOtherSys { + + @Override + public String callLE(String url, JSONObject json) { + String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); +// String leip = "http://60.214.115.166:20003"; + String baseurl = leip + url; + String token = this.getLEToken(leip); + Map headers = new HashMap<>(); + headers.put("x-token", token); + String postResult = doPost(baseurl, headers, json); + JSONObject result = JSONObject.parseObject(postResult); + String code = result.getString("code"); + if (StringUtils.equals(code, "0")) { + return postResult; + } else { + String message = result.getString("message"); + ExceptionUtils.wrappBusinessException(message); + return message; + } + } + + private String getLEToken(String leip) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("username", "nc_le"); + jsonObject.put("password", "7qTx8aPxVQ3n3j3HaKxZvLepyCyNm6gk967V7qcmJZkfBbJFEQZqPdQJMgfQNWdQ"); + String result = doPost(leip + "/login", null, jsonObject); + JSONObject parsed = JSONObject.parseObject(result); + String token = parsed.getString("token"); + return token; + } + + private String doPost(String baseurl, Map map, JSONObject json) { + BufferedReader reader = null; + try { + URL url = new URL(baseurl);// + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(true); + connection.setRequestMethod("POST"); // ʽ + // ýݵĸʽ + connection.setRequestProperty("Content-Type", "application/json"); // ÷ݵĸʽ + if (map != null) { + for (String key : map.keySet()) { + connection.setRequestProperty(key, map.get(key)); + } + } + connection.connect(); + // һҪBufferedReader Ӧ ʹֽӦķǽղݵ + OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // UTF-8 + if (json != null) { + out.append(json.toString()); + } + out.flush(); + out.close(); + // ȡӦ + reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + String line; + String res = ""; + while ((line = reader.readLine()) != null) { + res += line; + } + reader.close(); + return res; + } catch (Exception e) { +// e.printStackTrace(); + throw new RuntimeException(e); + } + } +} diff --git a/ic/src/public/nc/IHttpPostOtherSys.java b/ic/src/public/nc/IHttpPostOtherSys.java new file mode 100644 index 0000000..0c51069 --- /dev/null +++ b/ic/src/public/nc/IHttpPostOtherSys.java @@ -0,0 +1,15 @@ +package nc; + +import com.alibaba.fastjson.JSONObject; + + +public interface IHttpPostOtherSys { + + /** + * xuwjl@yonyou.com 2025424 15:24:14 + * @param url LEĽӿڵַip + * @param json + */ + public String callLE(String url, JSONObject json); + +} From 5da447c7d39052588b7ab4fc7e3eb36b16b6a38d Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 15 May 2025 11:01:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=87=91=E6=85=A7=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9BIP=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=98=8E=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openapi/so/m30/SaleOrderResource.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java index 5f6292e..e8d1085 100644 --- a/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java +++ b/so/src/public/nccloud/openapi/so/m30/SaleOrderResource.java @@ -7,6 +7,7 @@ import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.NCLocator; import nc.itf.bd.defdoc.IDefdocService; import nc.itf.pim.project.prv.IProject; +import nc.jdbc.framework.SQLParameter; import nc.jdbc.framework.processor.ColumnListProcessor; import nc.jdbc.framework.processor.ColumnProcessor; import nc.jdbc.framework.processor.MapProcessor; @@ -21,6 +22,8 @@ import nccloud.api.rest.utils.NCCRestUtils; import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.api.so.m30.IAPISaleOrderMaitain; import nccloud.api.so.m30.IAPISaleOrderQuery; +import nccloud.baseapp.core.log.NCCForUAPLogger; +import nccloud.commons.lang.StringUtils; import nccloud.openapi.scmpub.pub.NCCPubRestResource; import nccloud.openapi.scmpub.pub.TransferCodeToPKTool; import nccloud.openapi.scmpub.pub.TransferMapToVOTool; @@ -483,4 +486,45 @@ public class SaleOrderResource extends NCCPubRestResource { return ResultMessageUtil.exceptionToJSON(e); } } + + /** + * ޸BIP۶ϸ + * + * @author mzr + * @date 2025/05/14 + */ + @POST + @Path("updateDef") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString updateDef(Map paramMap) { + String csaleorderbid = (String) paramMap.get("csaleorderbid"); + if (StringUtils.isEmpty(csaleorderbid)) { + return ResultMessageUtil.exceptionToJSON("Ϊ,", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + try { + StringBuilder sql = new StringBuilder("update so_saleorder_b set "); + SQLParameter parameter = new SQLParameter(); + for (Map.Entry entry : paramMap.entrySet()) { + if (!"csaleorderbid".equals(entry.getKey())) { + sql.append(entry.getKey()).append(" = ?, "); + parameter.addParam(entry.getValue()); + } + } + if (parameter.getCountParams() <= 0) { + return ResultMessageUtil.toJSON("Ϊ,", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + // ɾ", " + sql.delete(sql.length() - 2, sql.length()); + sql.append(" where csaleorderbid = ?"); + NCCForUAPLogger.debug("updateDef-sql:" + sql); + parameter.addParam(csaleorderbid); + BaseDAO baseDAO = new BaseDAO(); + int num = baseDAO.executeUpdate(sql.toString(), parameter); + return ResultMessageUtil.toJSON(num, "۶޸ijɹ"); + } catch (BusinessException e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + } From 0763417ca8a2f3fe5a1ef1a6e2c7dc7b397fd89c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=8E?= Date: Thu, 15 May 2025 12:17:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refactor(ic):=20=E9=87=8D=E6=9E=84=20HttpPo?= =?UTF-8?q?stOtherSysImpl=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了请求 MES 系统的方式 - 添加了获取 MES token 的方法- 优化了代码结构,增加了常量定义 - 新增了处理 cookie 的方法 --- .../nc/bs/ic/HttpPostOtherSysImpl.java | 116 ++++++++++++++---- 1 file changed, 94 insertions(+), 22 deletions(-) diff --git a/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java b/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java index 0f2fd70..b601a3a 100644 --- a/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java +++ b/ic/src/private/nc/bs/ic/HttpPostOtherSysImpl.java @@ -8,45 +8,46 @@ import nc.pub.fa.common.util.StringUtils; import nc.vo.pubapp.pattern.exception.ExceptionUtils; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; +import java.util.List; import java.util.Map; public class HttpPostOtherSysImpl implements IHttpPostOtherSys { + private static final String USER_ID = "BIP"; + private static final String PASSWORD = "BIP@2025bip"; + private static final String CLIENT_TYPE = "S"; + private static final String EP_ID = ""; + private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login"; + @Override public String callLE(String url, JSONObject json) { - String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); -// String leip = "http://60.214.115.166:20003"; - String baseurl = leip + url; - String token = this.getLEToken(leip); +// String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP"); + String mesip = "http://192.168.29.32"; + String baseurl = mesip + url; + String cookie = this.getMESToken(mesip); Map headers = new HashMap<>(); - headers.put("x-token", token); - String postResult = doPost(baseurl, headers, json); - JSONObject result = JSONObject.parseObject(postResult); - String code = result.getString("code"); - if (StringUtils.equals(code, "0")) { - return postResult; - } else { - String message = result.getString("message"); - ExceptionUtils.wrappBusinessException(message); - return message; - } + headers.put("Set-Cookie", cookie); + return doPost(baseurl, headers, json); } - private String getLEToken(String leip) { + private String getMESToken(String leip) { JSONObject jsonObject = new JSONObject(); - jsonObject.put("username", "nc_le"); - jsonObject.put("password", "7qTx8aPxVQ3n3j3HaKxZvLepyCyNm6gk967V7qcmJZkfBbJFEQZqPdQJMgfQNWdQ"); - String result = doPost(leip + "/login", null, jsonObject); - JSONObject parsed = JSONObject.parseObject(result); - String token = parsed.getString("token"); - return token; + jsonObject.put("userId", USER_ID); + jsonObject.put("password", PASSWORD); + jsonObject.put("clientType", CLIENT_TYPE); + jsonObject.put("epId", EP_ID); + return postCookie(leip + LOGIN_URL, null, jsonObject); } + /** + * ҵpost + */ private String doPost(String baseurl, Map map, JSONObject json) { BufferedReader reader = null; try { @@ -86,4 +87,75 @@ public class HttpPostOtherSysImpl implements IHttpPostOtherSys { throw new RuntimeException(e); } } + + /** + * ȡcookiepost + */ + private String postCookie(String baseurl, Map map, JSONObject json) { + BufferedReader reader = null; + try { + URL url = new URL(baseurl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setUseCaches(false); + connection.setInstanceFollowRedirects(true); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + + if (map != null) { + for (String key : map.keySet()) { + connection.setRequestProperty(key, map.get(key)); + } + } + + connection.connect(); + + // д + OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); + if (json != null) { + out.append(json.toString()); + } + out.flush(); + out.close(); + + // ȡӦͷе Set-Cookie + Map> headers = connection.getHeaderFields(); + String setCookieHeader = null; + + for (Map.Entry> entry : headers.entrySet()) { + if ("Set-Cookie".equalsIgnoreCase(entry.getKey())) { + setCookieHeader = entry.getValue().get(0); // ȡһ Set-Cookie ͷ + break; + } + } + if (setCookieHeader != null) { + return extractAspxAuth(setCookieHeader); // ASPXAUTH ֵ + } else { + return null; + } + + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + // ȡ .ASPXAUTH ֵ + private String extractAspxAuth(String cookieHeader) { + String[] cookies = cookieHeader.split("; "); + for (String cookie : cookies) { + if (cookie.startsWith(".ASPXAUTH=")) { + return cookie.substring(".ASPXAUTH=".length()); + } + } + return null; + } }