diff --git a/javascript/xuanran.wang/longgong/NewProductTest.js b/javascript/xuanran.wang/longgong/NewProductTest.js index b0f6285..ca63af7 100644 --- a/javascript/xuanran.wang/longgong/NewProductTest.js +++ b/javascript/xuanran.wang/longgong/NewProductTest.js @@ -8,8 +8,8 @@ const threeMonthIndex = 1; const submitWaitNode = WfForm.convertFieldNameToId("sftjddjd"); // 下次超时提醒日期 const timeoutRemindDateFiled = WfForm.convertFieldNameToId("cstxrq"); -// 跟踪天数 -const trackingDays = WfForm.getFieldValue(trackTimeField) <= 1 ? 15 : 30; +// 跟踪天数 <= 1 ? 15 : 30; +const trackingDaysField = WfForm.convertFieldNameToId("gzts") // 跟踪触发行数 const trackingLineField = WfForm.convertFieldNameToId("gzcfxs"); $(() => { @@ -44,6 +44,7 @@ function getNodeNum(){ let currentDate = getCurrentDate(); let dayDiff = getDaysDiff(firstSaleDate, currentDate); console.log('当前天数与首台销售日期相差天数 : ', dayDiff) + let trackingDays = WfForm.getFieldValue(trackingDaysField); return Math.floor(dayDiff / trackingDays) + 1; } @@ -52,6 +53,7 @@ function initTimeoutDate(){ let firstSaleDate = WfForm.getFieldValue(firstSaleDateField); const nodeNum = getNodeNum(); console.log('到达节点次数 ', nodeNum); + let trackingDays = WfForm.getFieldValue(trackingDaysField); console.log('跟踪天数 ', trackingDays); let computeTimeoutDate = addDays(firstSaleDate, nodeNum * trackingDays); console.log('计算下次超时日期 ', computeTimeoutDate); diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java index 076bda2..668d3c6 100644 --- a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/controller/OtherSystemToOAController.java @@ -45,12 +45,12 @@ public class OtherSystemToOAController { // 获取重定向地址和secret Map redirectUrlAndCorpsecret = service.getRedirectUrlAndCorpsecret(appId); String redirectUrl = Util.null2DefaultStr(redirectUrlAndCorpsecret.get("REDIRECTURL"),""); - log.info("successSendRedirectUrl : " + redirectUrl); if(StringUtils.isBlank(redirectUrl)){ throw new CustomerException("redirectUrl is null! " + JSONObject.toJSONString(redirectUrlAndCorpsecret)); } int userId = service.getUserFromOtherSys(code, redirectUrlAndCorpsecret); - SessionUtil.createSession(userId + "", request, response); + SessionUtil.createSession(String.valueOf(userId), request, response); + log.info("successSendRedirectUrl : " + redirectUrl); response.sendRedirect(redirectUrl); }catch (Exception e){ log.error("sso error : " + e.getMessage()); diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java index f3c4884..c38b1b6 100644 --- a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/mapper/OtherSystemToOAMapper.java @@ -1,8 +1,11 @@ package com.api.xuanran.wang.sh_bigdata.sso.mapper; +import aiyh.utils.Util; import aiyh.utils.annotation.recordset.ParamMapper; import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; +import aiyh.utils.annotation.recordset.SqlString; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; import java.util.Map; @@ -21,8 +24,8 @@ public interface OtherSystemToOAMapper { * @param outKey 外键id * @return oa ID **/ - @Select("select id from hrmresource where outkey = #{outKey}") - int selectUserIdByOutKey(@ParamMapper("outKey") String outKey); + @Select(custom = true) + int selectUserIdByOutKey(@SqlString String sql, @ParamMapper("outKey") String outKey); /** *

根据appId 查跳转的地址

* @author xuanran.wang diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java index 7f736c4..69e69ec 100644 --- a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/OtherSystemToOAService.java @@ -21,7 +21,7 @@ public interface OtherSystemToOAService { * @param cusSuccess 自定义接口成功/失败标识 * @return 接口响应字段 **/ - int getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret); + Object getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret); /** *

根据第三方系统人员code匹配oa人员id

* @author xuanran.wang diff --git a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java index 3e1581a..c07bd3c 100644 --- a/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java +++ b/src/main/java/com/api/xuanran/wang/sh_bigdata/sso/service/impl/OtherSystemToOAServiceImpl.java @@ -28,12 +28,13 @@ public class OtherSystemToOAServiceImpl implements OtherSystemToOAService { .successField("code") .successValue(0) .errorMsg("msg") - .dataKey("data.id") + .dataKey("data." + Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("ssoInterfaceCompareField"), "id")) .build(); private final OtherSystemToOAMapper otherSystemToOAMapper = Util.getMapper(OtherSystemToOAMapper.class); private final Logger log = Util.getLogger(); + @Override - public int getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret) { + public Object getUserIdByCode(String url, Map params, Map headers, CusSuccess cusSuccess, Map redirectUrlSecret) { String secret = Util.null2DefaultStr(redirectUrlSecret.get("SECRET"), ""); log.info("secret : " + secret); if(StringUtils.isBlank(secret)){ @@ -48,7 +49,7 @@ public class OtherSystemToOAServiceImpl implements OtherSystemToOAService { params.put("code", code); // 获取第三方系统id String getUserInfoByCodeUrl = ShBigDataUtil.getPropertiesValByKey("getUserInfoByCodeUrl"); - int codeId; + Object codeId; try { codeId = getUserIdByCode(getUserInfoByCodeUrl, params, new HashMap<>(), cusSuccess, redirectUrlSecret); }catch (Exception e){ @@ -61,10 +62,12 @@ public class OtherSystemToOAServiceImpl implements OtherSystemToOAService { throw new CustomerException(e.getMessage()); } } - if(codeId < 0){ + String oaOutKey = Util.null2DefaultStr(codeId, ""); + if(StringUtils.isBlank(oaOutKey)){ throw new CustomerException(Util.logStr("code : {}, not found in {} .", code, getUserInfoByCodeUrl)); } - int id = otherSystemToOAMapper.selectUserIdByOutKey(codeId + ""); + String sql = "select id from hrmresource where " + Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("ssoOaCompareField"),"outkey") + " = #{outKey}"; + int id = otherSystemToOAMapper.selectUserIdByOutKey(sql, oaOutKey); if(id < 0){ throw new CustomerException(Util.logStr("code : {} not found in OA!", id)); } diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java index df1d46e..94b1c6a 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -680,6 +680,12 @@ public class DealWithMapping extends ToolUtil { } } } + // 自定义sql用{mainTable}代替当前表名 解决极兔ncc问题 + if(StringUtils.isNotBlank(mainTable)){ + valueContext = valueContext.replace("{mainTable}", mainTable); + }else { + logger.error("mainTable is null!"); + } String requestId = Util.null2String(mainMap.get("requestid")); tempValue = "'" + tempValue + "'"; value = this.getValueByChangeRule(valueContext, tempValue, requestId, detailId); @@ -1028,6 +1034,12 @@ public class DealWithMapping extends ToolUtil { tempValue = Util.null2String(tempRs.getString(fieldName)); } } + // 自定义sql用{mainTable}代替当前表名 解决极兔ncc问题 + if(StringUtils.isNotBlank(mainTable)){ + valueContext = valueContext.replace("{mainTable}", mainTable); + }else { + logger.error("mainTable is null!"); + } tempValue = "'" + tempValue + "'"; value = this.getValueByChangeRule(valueContext, tempValue, requestId, detailId); } diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java index 46cc313..63443f3 100644 --- a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/action/WorkflowToSap.java @@ -1,17 +1,14 @@ package weaver.xuanran.wang.eighty_five_degreec.sap.action; -import aiyh.utils.ThreadPoolConfig; import aiyh.utils.action.SafeCusBaseAction; -import aiyh.utils.annotation.ActionDesc; -import aiyh.utils.annotation.PrintParamMark; -import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.annotation.*; +import aiyh.utils.excention.CustomerException; import weaver.hrm.User; import weaver.soa.workflow.request.RequestInfo; import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; import weaver.xuanran.wang.eighty_five_degreec.sap.service.WorkflowToSapService; import weaver.xuanran.wang.eighty_five_degreec.sap.service.impl.WorkflowToSapServiceImpl; -import java.util.concurrent.ExecutorService; /** *

将流程数据推送到sap中

@@ -23,31 +20,53 @@ import java.util.concurrent.ExecutorService; public class WorkflowToSap extends SafeCusBaseAction { private final WorkflowToSapService service = new WorkflowToSapServiceImpl(); - private final ExecutorService pool = ThreadPoolConfig.createThreadPoolInstance(); @PrintParamMark @RequiredMark("配置表唯一标识") + @ActionDefaultTestValue(value = "****") private String uniqueCode; @PrintParamMark @RequiredMark("日志表模块id") + @ActionDefaultTestValue(value = "11") private String modelId; + @PrintParamMark + @RequiredMark("成功失败/标识字段") + @ActionDefaultTestValue(value = "soap-env:Envelope.soap-env:Body.n0:ZFI_OA_DOC_POSTINGResponse.ES_OA_OUTPUT.TYPE") + private String successField; + @PrintParamMark + @RequiredMark("成功时候的值") + @ActionDefaultTestValue(value = "T") + private String successVal; + @PrintParamMark + @RequiredMark("消息提示字段") + @ActionDefaultTestValue(value = "soap-env:Envelope.soap-env:Body.n0:ZFI_OA_DOC_POSTINGResponse.ES_OA_OUTPUT.MESSAGE") + private String messageField; @Override public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + String xml = ""; + String response = ""; + String url = ""; + String error = ""; + boolean success = true; try { MainRequestConfig config = service.getRequestConfig(uniqueCode, billTable); - String xml = service.convertXml(config, requestId, billTable); - String response = service.sendToSap(); - pool.execute(()->{ - try { - service.logToOA(modelId, config.getRequestUrl(), requestId, xml, response); - }catch (Exception e){ - log.error("日志数据写入建模失败! " + e.getMessage()); - } - }); + url = config.getRequestUrl(); + xml = service.convertXml(config, requestId, billTable); + response = service.sendToSap(config.getRequestUrl(), xml); + service.parseResponse(response, successField, successVal, messageField); }catch (Exception e){ log.error("流程数据推送SAP error : " + e.getMessage()); + error = e.getMessage(); + success = false; + } + try { + service.logToOA(modelId, url, requestId, xml, response, error); + }catch (Exception e){ + log.error("日志数据写入建模失败! " + e.getMessage()); + } + if(!success){ + throw new CustomerException("WorkflowToSap Action execute error : " + error); } - } } diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java index 5509ef1..ea5798f 100644 --- a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/entity/eneity/DetailRequestConfig.java @@ -11,6 +11,9 @@ import lombok.Data; */ @Data public class DetailRequestConfig { + @SqlDbFieldAnn("nodeType") + @SqlOracleDbFieldAnn("NODETYPE") + private String nodeType; @SqlDbFieldAnn("paramName") @SqlOracleDbFieldAnn("PARAMNAME") private String paramName; diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java index 0498b63..7e1a14b 100644 --- a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/WorkflowToSapService.java @@ -11,6 +11,7 @@ import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConf public interface WorkflowToSapService { MainRequestConfig getRequestConfig(String uniqueCode, String tableName); String convertXml(MainRequestConfig config, String requestId, String tableName); - String sendToSap(); - void logToOA(String modelId, String url, String requestId, String requestXml, String response); + String sendToSap(String url, String xml); + String parseResponse(String response, String responseField, String successField, String messageField); + void logToOA(String modelId, String url, String requestId, String requestXml, String response, String error); } diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java index b0aa755..607f0dc 100644 --- a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/service/impl/WorkflowToSapServiceImpl.java @@ -1,6 +1,11 @@ package weaver.xuanran.wang.eighty_five_degreec.sap.service.impl; import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.log4j.Logger; +import org.json.JSONObject; +import org.json.XML; +import weaver.xuanran.wang.common.util.CusData2OA; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; import weaver.xuanran.wang.eighty_five_degreec.sap.service.WorkflowToSapService; @@ -8,6 +13,7 @@ import weaver.xuanran.wang.eighty_five_degreec.sap.util.ReadConfigUtil; import java.util.Collections; import java.util.HashMap; +import java.util.Map; /** @@ -18,7 +24,7 @@ import java.util.HashMap; */ public class WorkflowToSapServiceImpl implements WorkflowToSapService { private final ReadConfigUtil configUtil = new ReadConfigUtil(); - + private final Logger log = Util.getLogger(); @Override public MainRequestConfig getRequestConfig(String uniqueCode, String tableName) { return configUtil.getConfigByUniqueCode(uniqueCode, tableName); @@ -30,20 +36,40 @@ public class WorkflowToSapServiceImpl implements WorkflowToSapService { } @Override - public String sendToSap() { - // TODO sap接口调用方式暂时搞不了 - return ""; + public String sendToSap(String url, String xml) { + return configUtil.callSap(url, xml); + } + + @Override + public String parseResponse(String response, String successField, String successVal, String messageField) { + String responseVal; + JSONObject xmlResponseObj; + try { + xmlResponseObj = XML.toJSONObject(response); + }catch (Exception e){ + throw new CustomerException("xml to jsonObj error : " + e.getMessage()); + } + Map responseMap = com.alibaba.fastjson.JSONObject.parseObject(xmlResponseObj.toString(), Map.class); + responseVal = configUtil.parseMap(responseMap, successField); + if(!successVal.equals(responseVal)){ + throw new CustomerException("successVal not equals responseVal! current responseVal is : " + + responseVal + ", the successVal is " + successVal + ", responseMsg is " + configUtil.parseMap(responseMap, messageField)); + } + return responseVal; } @Override public void logToOA(String modelId, String url, String requestId, - String requestXml, String response) { + String requestXml, String response, String error) { HashMap params = new HashMap<>(); - params.put("requestUrlAndFunName", url); + params.put("requestUrl", url); params.put("reqId", requestId); params.put("requestXml", requestXml); params.put("responseCode",""); - params.put("erpResponse", response); - CusInfoToOAUtil.getDataId(Util.getIntValue(modelId, -1), params, "select id from #{tableName} where reqId = ?", Collections.singletonList(requestId)); + params.put("sapResponse", response); + params.put("error", error); + log.info("写入日志参数 : " + com.alibaba.fastjson.JSONObject.toJSONString(params)); + CusData2OA.writeToModel(modelId, "select id from #{tableName} where reqId = " + requestId, params); } + } diff --git a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java index d805dd1..bfe44cc 100644 --- a/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java +++ b/src/main/java/weaver/xuanran/wang/eighty_five_degreec/sap/util/ReadConfigUtil.java @@ -1,5 +1,6 @@ package weaver.xuanran.wang.eighty_five_degreec.sap.util; +import aiyh.utils.excention.CustomerException; import com.google.common.base.Strings; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -12,11 +13,10 @@ import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.DetailRequestCo import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; import weaver.zwl.common.ToolUtil; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStreamReader; +import java.io.*; import java.lang.reflect.Field; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.text.ParseException; @@ -55,7 +55,7 @@ public class ReadConfigUtil extends ToolUtil { } int mainId = Util.getIntValue(res.getId()); // 配置明细表 - sql = "select paramName,paramType,parentName,getValueType,workflowField,valueContext,fv.tableName," + + sql = "select nodeType,paramName,paramType,parentName,getValueType,workflowField,valueContext,fv.tableName," + " fv.id fieldId,fv.fieldname,fv.indexdesc " + " from uf_memsic_createXml_dt1 config " + " left join workflow_field_table_view fv on config.workflowField = fv.id " + @@ -88,7 +88,7 @@ public class ReadConfigUtil extends ToolUtil { * @return 返回类对象 **/ public static T getInstance(RecordSet queryRs, Class clazz) { - T res = null; + T res; try { res = clazz.newInstance(); Field[] fields = clazz.getDeclaredFields(); @@ -443,15 +443,35 @@ public class ReadConfigUtil extends ToolUtil { // 明细 String[] detailIdArr = detailIndex.split(","); StringBuilder detailSb = new StringBuilder(); + for (String detailId : detailIdArr) { + String nodeName; + List nodeList = requestConfigList.stream() + .filter(item -> "0".equals(item.getNodeType())).collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(nodeList)){ + nodeName = nodeList.get(0).getParamName(); + } else { + nodeName = ""; + } List detailCollect = requestConfigList.stream() - .filter(item -> "detailRecord".equals(item.getParentName()) - ).collect(Collectors.toList()); + .filter(item -> { + if(StringUtils.isNotBlank(nodeName)){ + return nodeName.equals(item.getParentName()); + }else { + return "detailRecord".equals(item.getParentName()); + } + }).collect(Collectors.toList()); String detailSql = "select * from " + tableName + "_dt" + detailId + " where mainid = ?"; if (detailRs.executeQuery(detailSql, mainId)) { int count = 1; while (detailRs.next()) { + if(StringUtils.isNotBlank(nodeName)){ + detailSb.append("<").append(nodeName).append(">\n"); + } appendXml(detailSb, detailCollect, mainRs, detailRs, count++); + if(StringUtils.isNotBlank(nodeName)){ + detailSb.append("\n"); + } } } } @@ -474,7 +494,7 @@ public class ReadConfigUtil extends ToolUtil { .append(paramName) .append(">") .append(getParamValue(requestConfig, mainRs, detailRs,count)) - .append("<") + .append("") .append("\n"); @@ -544,22 +564,80 @@ public class ReadConfigUtil extends ToolUtil { * @return 响应数据 */ public String parseMap(Map responseMap, String responseField){ - String[] strArr = responseField.split("\\."); - int i = 0; - while (i < strArr.length - 1){ - Object o = responseMap.get(strArr[i]); - if(o instanceof Map){ - responseMap = (Map) o; - }else if(o instanceof List){ - List> list = (List>) o; - if(CollectionUtils.isEmpty(list)){ - return ""; - } - responseMap = list.get(0); - } - i++; - } - return Util.null2String(responseMap.get(strArr[strArr.length - 1])); + try { + String[] strArr = responseField.split("\\."); + int i = 0; + while (i < strArr.length - 1){ + Object o = responseMap.get(strArr[i]); + if(o instanceof Map){ + responseMap = (Map) o; + }else if(o instanceof List){ + List> list = (List>) o; + if(CollectionUtils.isEmpty(list)){ + return ""; + } + responseMap = list.get(0); + } + i++; + } + return Util.null2String(responseMap.get(strArr[strArr.length - 1])); + }catch (Exception e){ + throw new CustomerException("parseMap error : " + e.getMessage()); + } } + /** + *

调用sap接口

+ * @author xuanran.wang + * @dateTime 2023/5/15 14:05 + * @param url 接口地址 + * @param xml 报文xml + * @return 接口响应 + **/ + public String callSap(String url, String xml){ + OutputStreamWriter writer = null; + BufferedReader reader = null; + try { + String userName = aiyh.utils.Util.null2DefaultStr(getSystemParamValue("sapUserName"),""); + String password = aiyh.utils.Util.null2DefaultStr(getSystemParamValue("sapPassword"),""); + log.info("callSap userName : [ " + userName + " ], password : [ " + password + " ]"); + String authString = userName + ":" + password; + byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); + String authStringEnc = new String(authEncBytes); + URL serviceUrl = new URL(url); + HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); + connection.setRequestProperty("Authorization", "Basic " + authStringEnc); + connection.setDoOutput(true); + writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8); + writer.write(xml); + writer.close(); + reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); + String line; + StringBuilder responseBuilder = new StringBuilder(); + while ((line = reader.readLine()) != null) { + responseBuilder.append(line); + } + reader.close(); + String response = responseBuilder.toString(); + if(StringUtils.isBlank(response)){ + throw new CustomerException("sap response is empty!"); + } + return response; + }catch (Exception e){ + throw new CustomerException("callSap error : " + e.getMessage()); + }finally { + try { + if(writer != null){ + writer.close(); + } + if(reader != null){ + reader.close(); + } + }catch (Exception e){ + log.error("关流异常 : " + e.getMessage()); + } + } + } } diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java index bcf46c6..13de9f8 100644 --- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java @@ -35,6 +35,8 @@ public class ShBigDataUtil { WHILTE_LIST.add("loginErrorSendRedirectUrl"); WHILTE_LIST.add("getUserIdDebug"); WHILTE_LIST.add("getUserIdDebugOutKey"); + WHILTE_LIST.add("ssoInterfaceCompareField"); + WHILTE_LIST.add("ssoOaCompareField"); } /** diff --git a/src/test/java/xuanran/wang/NormalTest.java b/src/test/java/xuanran/wang/NormalTest.java new file mode 100644 index 0000000..0fc4fb5 --- /dev/null +++ b/src/test/java/xuanran/wang/NormalTest.java @@ -0,0 +1,21 @@ +package xuanran.wang; + +import aiyh.utils.GenerateFileUtil; +import basetest.BaseTest; +import org.junit.Test; +import weaver.xuanran.wang.eighty_five_degreec.sap.action.WorkflowToSap; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/5/19 16:48 + */ +public class NormalTest extends BaseTest { + + + @Test + public void testWord(){ + GenerateFileUtil.createActionDocument(WorkflowToSap.class); + } +} diff --git a/src/test/java/xuanran/wang/big_data/BigDataTest.java b/src/test/java/xuanran/wang/big_data/BigDataTest.java index fb032cb..1639bc9 100644 --- a/src/test/java/xuanran/wang/big_data/BigDataTest.java +++ b/src/test/java/xuanran/wang/big_data/BigDataTest.java @@ -3,6 +3,7 @@ package xuanran.wang.big_data; import aiyh.utils.Util; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.sh_bigdata.sso.mapper.OtherSystemToOAMapper; import com.icbc.api.internal.apache.http.impl.cookie.S; import com.weaver.esb.server.cache.ResourceComInfo; import emo.macro.ob.OB; @@ -13,6 +14,7 @@ import weaver.email.EmailWorkRunnable; import weaver.general.TimeUtil; import weaver.xuanran.wang.common.util.CusInfoToOAUtil; import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.OrganizationHrmSyncFromOtherSys; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OrgHrmAsyncConfigMain; import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; @@ -32,369 +34,366 @@ import java.util.stream.Collectors; * @date 2023/4/10 10:49 */ public class BigDataTest extends BaseTest { - private final OrgHrmAsyncServiceImpl orgHrmAsyncService = new OrgHrmAsyncServiceImpl(); - private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); - private final List departmentWhiteList; - private final List subCompanyWhiteList; - private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); - - { - departmentWhiteList = orgHrmAsyncMapper.selectCusDepart(); - subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany(); - } - - @Test - public void testA() throws IOException { -// List rootDepList = departmentInfo -// .stream() -// .filter(item -> 1 == item.getHasChild()) -// .sorted(Comparator.comparing(OtherSysDepartment::getId)) -// .collect(Collectors.toList()); -// for (OtherSysDepartment department : rootDepList) { -// setChildList(department, departmentInfo); +// private final OrgHrmAsyncServiceImpl orgHrmAsyncService = new OrgHrmAsyncServiceImpl(); +// private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); +// private final List departmentWhiteList; +// private final List subCompanyWhiteList; +// private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); +// +// { +// departmentWhiteList = orgHrmAsyncMapper.selectCusDepart(); +// subCompanyWhiteList = orgHrmAsyncMapper.selectCusSubCompany(); +// } +// +// @Test +// public void testA() throws IOException { +//// List rootDepList = departmentInfo +//// .stream() +//// .filter(item -> 1 == item.getHasChild()) +//// .sorted(Comparator.comparing(OtherSysDepartment::getId)) +//// .collect(Collectors.toList()); +//// for (OtherSysDepartment department : rootDepList) { +//// setChildList(department, departmentInfo); +//// } +//// List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); +//// List convert = Util.listToTree(departmentInfo, +//// OtherSysDepartment::getId, OtherSysDepartment::getParentid, +//// OtherSysDepartment::getChildList, OtherSysDepartment::setChildList, +//// parentid -> parentid == -1); +//// System.out.println("convert => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); +//// List hrmSubCompany = new ArrayList<>(); +//// List hrmDepartment = new ArrayList<>(); +//// int maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3); +//// System.out.println(countNodes(convert.get(0))); +//// parseSubCompanyAndDepartment(convert, 0,maxLevel, hrmSubCompany, hrmDepartment); +//// parseSubCompanyAndDepartment(convert, hrmSubCompany); +//// System.out.println("hrmSubCompany => " + hrmSubCompany.size()); +//// System.out.println("convertLevel => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); +//// System.out.println("hrmSubCompany => " + JSONObject.toJSONString(hrmSubCompany)); +//// System.out.println("hrmDepartment => " + JSONObject.toJSONString(hrmDepartment)); +//// orgHrmAsyncService.asyncDepartment(); +// Map res = JSONObject.parseObject("{\n" + +// "\t\t\"code\":0,\n" + +// "\t\t\"msg\":\"ok\",\n" + +// "\t\t\"data\":{\n" + +// "\t\t\t\"UserId\":\"13800000000\",\n" + +// "\t\t\t\"errcode\":0,\n" + +// "\t\t\t\"errmsg\":\"ok\",\n" + +// "\t\t\t\"id\":109,\n" + +// "\t\t\t\"userid\":\"13800000000\",\n" + +// "\t\t\t\"name\":\"祝芳\",\n" + +// "\t\t\t\"mobile\":\"13800000000\",\n" + +// "\t\t\t\"gender\":1,\n" + +// "\t\t\t\"department\":[\n" + +// "\t\t\t\t539\n" + +// "\t\t\t],\n" + +// "\t\t\t\"order\":[\n" + +// "\t\t\t\t6\n" + +// "\t\t\t]\n" + +// "\t\t}\n" + +// "\t}", Map.class); +// System.out.println(getRes(res)); +// } +// +// public String getRes(Map res){ +// return (String) parseRes(res, cusSuccess); +// } +// +// private final CusSuccess cusSuccess = CusSuccess.builder() +// .successField("code") +// .successValue(0) +// .errorMsg("msg") +// .dataKey("data.id") +// .build(); +// +// public T parseRes(Map response, CusSuccess cusSuccess){ +// String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); +// int len = split.length; +// if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){ +// return (T)response; // } -// List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); -// List convert = Util.listToTree(departmentInfo, -// OtherSysDepartment::getId, OtherSysDepartment::getParentid, -// OtherSysDepartment::getChildList, OtherSysDepartment::setChildList, -// parentid -> parentid == -1); -// System.out.println("convert => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); -// List hrmSubCompany = new ArrayList<>(); -// List hrmDepartment = new ArrayList<>(); -// int maxLevel = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("maxLevel"), 3); -// System.out.println(countNodes(convert.get(0))); -// parseSubCompanyAndDepartment(convert, 0,maxLevel, hrmSubCompany, hrmDepartment); -// parseSubCompanyAndDepartment(convert, hrmSubCompany); -// System.out.println("hrmSubCompany => " + hrmSubCompany.size()); -// System.out.println("convertLevel => " + JSONObject.toJSONString(convert, SerializerFeature.DisableCircularReferenceDetect)); -// System.out.println("hrmSubCompany => " + JSONObject.toJSONString(hrmSubCompany)); -// System.out.println("hrmDepartment => " + JSONObject.toJSONString(hrmDepartment)); -// orgHrmAsyncService.asyncDepartment(); - Map res = JSONObject.parseObject("{\n" + - "\t\t\"code\":0,\n" + - "\t\t\"msg\":\"ok\",\n" + - "\t\t\"data\":{\n" + - "\t\t\t\"UserId\":\"13800000000\",\n" + - "\t\t\t\"errcode\":0,\n" + - "\t\t\t\"errmsg\":\"ok\",\n" + - "\t\t\t\"id\":109,\n" + - "\t\t\t\"userid\":\"13800000000\",\n" + - "\t\t\t\"name\":\"祝芳\",\n" + - "\t\t\t\"mobile\":\"13800000000\",\n" + - "\t\t\t\"gender\":1,\n" + - "\t\t\t\"department\":[\n" + - "\t\t\t\t539\n" + - "\t\t\t],\n" + - "\t\t\t\"order\":[\n" + - "\t\t\t\t6\n" + - "\t\t\t]\n" + - "\t\t}\n" + - "\t}", Map.class); - System.out.println(getRes(res)); - } - - public String getRes(Map res){ - return (String) parseRes(res, cusSuccess); - } - - private final CusSuccess cusSuccess = CusSuccess.builder() - .successField("code") - .successValue(0) - .errorMsg("msg") - .dataKey("data.id") - .build(); - - public T parseRes(Map response, CusSuccess cusSuccess){ - String[] split = Util.null2DefaultStr(cusSuccess.getDataKey(),"").split("\\."); - int len = split.length; - if(len == 0 || StringUtils.isBlank(cusSuccess.getDataKey())){ - return (T)response; - } - for (int i = 0; i < len - 1; i++) { - response = (Map) response.get(split[i]); - } - return (T) response.get(split[len - 1]); - } - - @Test - public void testMap(){ - List> list = orgHrmAsyncApiService.getDepartmentInfoMap(); - // 将列表转换为以id为键的Map - List> tree = convertListToTree(list); - List> department = new ArrayList<>(); - List> subCompany = new ArrayList<>(); - orgHrmAsyncService.parseSubCompanyAndDepartmentMap(tree, 0, 3, department, subCompany); - System.out.println(JSONObject.toJSONString(department)); - System.out.println(JSONObject.toJSONString(subCompany)); - } - - @Test - public void testMapper(){ -// System.setProperty("_isDebug", "false"); -// System.out.println("分部执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(0))); -// System.out.println("部门执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(1))); -// List orgHrmAsyncConfigMains = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(2); -// System.out.println(JSONObject.toJSONString(orgHrmAsyncConfigMains)); - ArrayList ids = new ArrayList<>(); - for (int i = 0; i < 100; i++) { - ids.add("'" + UUID.randomUUID().toString().replace("-","") + "'"); - } - String updateDelStatus = "update cus_fielddata set field0 = 1 where " + - weaver.general.Util.getSubINClause(StringUtils.join(ids,","),"field2","not in"); - System.out.println(updateDelStatus); - } - - @Test - public void testAsync(){ - System.out.println(TimeUtil.getCurrentTimeString()); - OrganizationHrmSyncFromOtherSys async = new OrganizationHrmSyncFromOtherSys(); - async.SynTimingToOASubCompany(); - async.SynTimingToOADepartment(); - HashMap synResult = async.getSynResult(); - System.out.println("res => \n" + JSONObject.toJSONString(synResult)); - System.out.println(TimeUtil.getCurrentTimeString()); - } - - @Test - public void testExtra(){ - orgHrmAsyncService.asyncHrm(); - } - - public List> convertListToTree(List> list){ - Map> map = new HashMap<>(); - for (Map item : list) { - map.put((Integer) item.get("id"), item); - } - - // 构建树形结构 - List> tree = new ArrayList<>(); - for (Map item : list) { - int parentId = (Integer) item.get("parentid"); - if (parentId == -1) { - // 添加根节点 - tree.add(item); - } else { - // 添加子节点 - Map parent = map.get(parentId); - if (parent != null) { - List> childList = (List>) parent.get("childList"); - if (childList == null) { - childList = new ArrayList<>(); - parent.put("childList", childList); - } - childList.add(item); - } - } - } - return tree; - } - public int countNodes(OtherSysDepartment node) { - int count = 1; // 当前节点也算一条数据 - List childList = node.getChildList(); - if (CollectionUtils.isNotEmpty(childList)) { - for (OtherSysDepartment otherSysDepartment : childList) { - count += countNodes(otherSysDepartment); - } - } - return count; - } - - public int countNodes(Map node) { - int count = 1; // 当前节点也算一条数据 - List> childList = (List>) node.get("childList"); - if (CollectionUtils.isNotEmpty(childList)) { - for (Map map : childList) { - count += countNodes(map); - } - } - return count; - } - - - /** - *

解析部门or分部

- * @author xuanran.wang - * @dateTime 2023/4/10 12:13 - * @param list 树形集合 - * @param hrmDepartment 部门 - **/ - public void parseSubCompanyAndDepartment(List list, List hrmDepartment){ - for (OtherSysDepartment department : list) { - List childList = department.getChildList(); - if(CollectionUtils.isNotEmpty(childList)){ - parseSubCompanyAndDepartment(childList,hrmDepartment); - department.setChildList(null); - } - hrmDepartment.add(department); - } - } - - - /** - *

解析部门or分部

- * @author xuanran.wang - * @dateTime 2023/4/10 12:13 - * @param list 树形集合 - * @param n 层级 - * @param hrmSubCompany 分部 - * @param hrmDepartment 部门 - **/ - public void parseSubCompanyAndDepartment(List list, int n, int maxLevel,List hrmSubCompany, List hrmDepartment){ - n++; - for (OtherSysDepartment department : list) { - department.setLevel(n); - List childList = department.getChildList(); - String departmentId = department.getId() + ""; - if(CollectionUtils.isNotEmpty(childList)){ - List collect = department.getChildList().stream().map(item -> Util.null2DefaultStr(item.getId(), "")).collect(Collectors.toList()); - if(departmentWhiteList.contains(departmentId)){ - departmentWhiteList.addAll(collect); - }else if(subCompanyWhiteList.contains(departmentId)){ - subCompanyWhiteList.addAll(collect); - } - parseSubCompanyAndDepartment(childList, n, maxLevel, hrmSubCompany, hrmDepartment); - department.setChildList(null); - } - if(n > maxLevel || departmentWhiteList.contains(departmentId)){ - hrmDepartment.add(department); - }else { - hrmSubCompany.add(department); - } - - } - } - - @Test - public void testParseObj(){ - String json = "{\n" + - " \"code\":0,\n" + - " \"msg\":\"ok\",\n" + - " \"data\":\n" + - " {\n" + - " \"errcode\": 0,\n" + - " \"errmsg\": \"ok\",\n" + - " \"id\": \"1\",\n" + - " \"userid\": \"superAdmin\",\n" + - " \"name\": \"超级管理员\",\n" + - " \"mobile\":\"12345678911\",\n" + - " \"email\":\"123@321.com\",\n" + - " \"gender\":0,\n" + - " \"position\":\"position\",\n" + - " \"avatarImg\":\"avatarImg\",\n" + - " \"workPhone\":\"workPhone\",\n" + - " \"fixedTelephone\":\"fixedTelephone\",\n" + - " \"extName\":\"extName\",\n" + - " \"userType\":0,\n" + - " \"department\": [\n" + - " 1\n" + - " ],\n" + - " \"order\": [\n" + - " 0\n" + - " ],\n" + - " \"rank\":\"rank\"\n" + - " }\n" + - "}"; - Map response = JSONObject.parseObject(json, Map.class); - String obj = Util.null2DefaultStr(getObj("data.id", response),""); - System.out.println("obj => " + obj); - } - - public T getObj(String dataKey, Map response){ - String[] split = Util.null2DefaultStr(dataKey,"").split("\\."); - int len = split.length; - if(len == 0 || StringUtils.isBlank(dataKey)){ - return (T)response; - } - for (int i = 0; i < len - 1; i++) { - response = (Map) response.get(split[i]); - } - return (T) response.get(split[len - 1]); - } - - @Test - public void testMsg(){ - String html = "\n" + - "\n" + - "\n" + - "\tInvestment Calculator\n" + - "\t\n" + - "\n" + - "\n" + - "\t\n" + - "\t\t\n" + - "\t\t\t\n" + - "\t\t\n" + - "\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\n" + - "\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\t\n" + - "\t\t\n" + - "\t\t\n" + - " \t
投资试算(场外基金)
ABCDEFGHIJKLM
Cell A1Cell B1Cell C1Cell D1Cell E1Cell F1Cell G1Cell H1Cell I1Cell J1Cell K1Cell L1Cell M1
\n" + - " \n" + - "\n"; - EmailWorkRunnable.threadModeReminder("3055088966@qq.com,xuanran.wang@weaver.com.cn", "test11", html); - - } +// for (int i = 0; i < len - 1; i++) { +// response = (Map) response.get(split[i]); +// } +// return (T) response.get(split[len - 1]); +// } +// +// @Test +// public void testMap(){ +// List> list = orgHrmAsyncApiService.getDepartmentInfoMap(); +// // 将列表转换为以id为键的Map +// List> tree = convertListToTree(list); +// List> department = new ArrayList<>(); +// List> subCompany = new ArrayList<>(); +// orgHrmAsyncService.parseSubCompanyAndDepartmentMap(tree, 0, 3, department, subCompany); +// System.out.println(JSONObject.toJSONString(department)); +// System.out.println(JSONObject.toJSONString(subCompany)); +// } +// +// @Test +// public void testMapper(){ +//// System.setProperty("_isDebug", "false"); +//// System.out.println("分部执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(0))); +//// System.out.println("部门执行结果 => " + JSONObject.toJSONString(orgHrmAsyncService.asyncOrgDep(1))); +//// List orgHrmAsyncConfigMains = orgHrmAsyncMapper.selectSubCompanyAsyncConfig(2); +//// System.out.println(JSONObject.toJSONString(orgHrmAsyncConfigMains)); +// ArrayList ids = new ArrayList<>(); +// for (int i = 0; i < 100; i++) { +// ids.add("'" + UUID.randomUUID().toString().replace("-","") + "'"); +// } +// String updateDelStatus = "update cus_fielddata set field0 = 1 where " + +// weaver.general.Util.getSubINClause(StringUtils.join(ids,","),"field2","not in"); +// System.out.println(updateDelStatus); +// } +// +// @Test +// public void testAsync(){ +// System.out.println(TimeUtil.getCurrentTimeString()); +// OrganizationHrmSyncFromOtherSys async = new OrganizationHrmSyncFromOtherSys(); +// async.SynTimingToOASubCompany(); +// async.SynTimingToOADepartment(); +// HashMap synResult = async.getSynResult(); +// System.out.println("res => \n" + JSONObject.toJSONString(synResult)); +// System.out.println(TimeUtil.getCurrentTimeString()); +// } +// +// @Test +// public void testExtra(){ +// orgHrmAsyncService.asyncHrm(); +// } +// +// public List> convertListToTree(List> list){ +// Map> map = new HashMap<>(); +// for (Map item : list) { +// map.put((Integer) item.get("id"), item); +// } +// +// // 构建树形结构 +// List> tree = new ArrayList<>(); +// for (Map item : list) { +// int parentId = (Integer) item.get("parentid"); +// if (parentId == -1) { +// // 添加根节点 +// tree.add(item); +// } else { +// // 添加子节点 +// Map parent = map.get(parentId); +// if (parent != null) { +// List> childList = (List>) parent.get("childList"); +// if (childList == null) { +// childList = new ArrayList<>(); +// parent.put("childList", childList); +// } +// childList.add(item); +// } +// } +// } +// return tree; +// } +// public int countNodes(OtherSysDepartment node) { +// int count = 1; // 当前节点也算一条数据 +// List childList = node.getChildList(); +// if (CollectionUtils.isNotEmpty(childList)) { +// for (OtherSysDepartment otherSysDepartment : childList) { +// count += countNodes(otherSysDepartment); +// } +// } +// return count; +// } +// +// public int countNodes(Map node) { +// int count = 1; // 当前节点也算一条数据 +// List> childList = (List>) node.get("childList"); +// if (CollectionUtils.isNotEmpty(childList)) { +// for (Map map : childList) { +// count += countNodes(map); +// } +// } +// return count; +// } +// +// +// /** +// *

解析部门or分部

+// * @author xuanran.wang +// * @dateTime 2023/4/10 12:13 +// * @param list 树形集合 +// * @param hrmDepartment 部门 +// **/ +// public void parseSubCompanyAndDepartment(List list, List hrmDepartment){ +// for (OtherSysDepartment department : list) { +// List childList = department.getChildList(); +// if(CollectionUtils.isNotEmpty(childList)){ +// parseSubCompanyAndDepartment(childList,hrmDepartment); +// department.setChildList(null); +// } +// hrmDepartment.add(department); +// } +// } +// +// +// /** +// *

解析部门or分部

+// * @author xuanran.wang +// * @dateTime 2023/4/10 12:13 +// * @param list 树形集合 +// * @param n 层级 +// * @param hrmSubCompany 分部 +// * @param hrmDepartment 部门 +// **/ +// public void parseSubCompanyAndDepartment(List list, int n, int maxLevel,List hrmSubCompany, List hrmDepartment){ +// n++; +// for (OtherSysDepartment department : list) { +// department.setLevel(n); +// List childList = department.getChildList(); +// String departmentId = department.getId() + ""; +// if(CollectionUtils.isNotEmpty(childList)){ +// List collect = department.getChildList().stream().map(item -> Util.null2DefaultStr(item.getId(), "")).collect(Collectors.toList()); +// if(departmentWhiteList.contains(departmentId)){ +// departmentWhiteList.addAll(collect); +// }else if(subCompanyWhiteList.contains(departmentId)){ +// subCompanyWhiteList.addAll(collect); +// } +// parseSubCompanyAndDepartment(childList, n, maxLevel, hrmSubCompany, hrmDepartment); +// department.setChildList(null); +// } +// if(n > maxLevel || departmentWhiteList.contains(departmentId)){ +// hrmDepartment.add(department); +// }else { +// hrmSubCompany.add(department); +// } +// +// } +// } +// +// @Test +// public void testParseObj(){ +// String json = "{\n" + +// " \"code\":0,\n" + +// " \"msg\":\"ok\",\n" + +// " \"data\":\n" + +// " {\n" + +// " \"errcode\": 0,\n" + +// " \"errmsg\": \"ok\",\n" + +// " \"id\": \"1\",\n" + +// " \"userid\": \"superAdmin\",\n" + +// " \"name\": \"超级管理员\",\n" + +// " \"mobile\":\"12345678911\",\n" + +// " \"email\":\"123@321.com\",\n" + +// " \"gender\":0,\n" + +// " \"position\":\"position\",\n" + +// " \"avatarImg\":\"avatarImg\",\n" + +// " \"workPhone\":\"workPhone\",\n" + +// " \"fixedTelephone\":\"fixedTelephone\",\n" + +// " \"extName\":\"extName\",\n" + +// " \"userType\":0,\n" + +// " \"department\": [\n" + +// " 1\n" + +// " ],\n" + +// " \"order\": [\n" + +// " 0\n" + +// " ],\n" + +// " \"rank\":\"rank\"\n" + +// " }\n" + +// "}"; +// Map response = JSONObject.parseObject(json, Map.class); +// String obj = Util.null2DefaultStr(getObj("data.id", response),""); +// System.out.println("obj => " + obj); +// } +// +// public T getObj(String dataKey, Map response){ +// String[] split = Util.null2DefaultStr(dataKey,"").split("\\."); +// int len = split.length; +// if(len == 0 || StringUtils.isBlank(dataKey)){ +// return (T)response; +// } +// for (int i = 0; i < len - 1; i++) { +// response = (Map) response.get(split[i]); +// } +// return (T) response.get(split[len - 1]); +// } +// +// @Test +// public void testMsg(){ +// String html = "\n" + +// "\n" + +// "\n" + +// "\tInvestment Calculator\n" + +// "\t\n" + +// "\n" + +// "\n" + +// "\t\n" + +// "\t\t\n" + +// "\t\t\t\n" + +// "\t\t\n" + +// "\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\n" + +// "\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\t\n" + +// "\t\t\n" + +// "\t\t\n" + +// " \t
投资试算(场外基金)
ABCDEFGHIJKLM
Cell A1Cell B1Cell C1Cell D1Cell E1Cell F1Cell G1Cell H1Cell I1Cell J1Cell K1Cell L1Cell M1
\n" + +// " \n" + +// "\n"; +// EmailWorkRunnable.threadModeReminder("3055088966@qq.com,xuanran.wang@weaver.com.cn", "test11", html); +// +// } + private final OtherSystemToOAMapper otherSystemToOAMapper = Util.getMapper(OtherSystemToOAMapper.class); @Test public void testG(){ -// String sql =" select case '$t{test1}' when '03' then '场外基金' when '04' then '基金赎回' else '测试下' end"; -// HashMap param = new HashMap<>(); -// param.put("test1","04"); -// String s = orgHrmAsyncMapper.selectCustomerSql(sql, param); -// System.out.println("s => " + s); - HashMap map = new HashMap<>(); - map.put("tiem", new Date()); - System.out.println("map => " + JSONObject.toJSONString(map)); + String oaOutKey = "111"; + String sql = "select id from hrmresource where " + Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("ssoOaCompareField"),"outkey") + " = #{outKey}"; + int id = otherSystemToOAMapper.selectUserIdByOutKey(sql, oaOutKey); + log.info("id => " + id); } } diff --git a/src/test/java/xuanran/wang/cssc/FileTest.java b/src/test/java/xuanran/wang/cssc/FileTest.java index 4d558da..9fce4db 100644 --- a/src/test/java/xuanran/wang/cssc/FileTest.java +++ b/src/test/java/xuanran/wang/cssc/FileTest.java @@ -1,6 +1,7 @@ package xuanran.wang.cssc; import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.util.HttpUtils; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; import org.apache.commons.codec.digest.DigestUtils; @@ -201,4 +202,9 @@ public class FileTest extends BaseTest { } } + @Test + public void testB(){ + HttpUtils httpUtils = new HttpUtils(); + } + } diff --git a/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java b/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java index da47043..6461041 100644 --- a/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java +++ b/src/test/java/xuanran/wang/eighty_five_degreec/SAPTest.java @@ -1,12 +1,24 @@ package xuanran.wang.eighty_five_degreec; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; import aiyh.utils.tool.cn.hutool.core.lang.UUID; import basetest.BaseTest; +import com.alibaba.excel.util.CollectionUtils; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.XML; import org.junit.Test; +import weaver.general.GCONST; +import weaver.general.Util; import weaver.xuanran.wang.common.util.CusData2OA; import weaver.xuanran.wang.eighty_five_degreec.sap.entity.eneity.MainRequestConfig; +import weaver.xuanran.wang.eighty_five_degreec.sap.service.WorkflowToSapService; +import weaver.xuanran.wang.eighty_five_degreec.sap.service.impl.WorkflowToSapServiceImpl; import weaver.xuanran.wang.eighty_five_degreec.sap.util.ReadConfigUtil; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -20,15 +32,116 @@ import java.util.Map; */ public class SAPTest extends BaseTest { + private final WorkflowToSapService service = new WorkflowToSapServiceImpl(); + @Test public void testXml(){ - ReadConfigUtil configUtil = new ReadConfigUtil(); String uniqueCode = "test1"; - String tableName = "formtable_main_161"; + String billTable = "formtable_main_161"; String requestId = "419420"; - MainRequestConfig config = configUtil.getConfigByUniqueCode(uniqueCode, tableName); - String xml = configUtil.getXml(config, requestId, tableName); - System.out.println("xml => \n " + xml); + + String response = ""; + String url = ""; + String error = ""; + String xml = ""; + boolean success = true; + String modelId = "119"; + String successField = "soap-env:Envelope.soap-env:Body.n0:ZFI_OA_DOC_POSTINGResponse.ES_OA_OUTPUT.TYPE"; + String successVal = "N"; + String messageField = "soap-env:Envelope.soap-env:Body.n0:ZFI_OA_DOC_POSTINGResponse.ES_OA_OUTPUT.MESSAGE"; + + try { + MainRequestConfig config = service.getRequestConfig(uniqueCode, billTable); + url = config.getRequestUrl(); + xml = service.convertXml(config, requestId, billTable); +// response = service.sendToSap(config.getRequestUrl(), xml); + response = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " clbx000003\n" + + " \n" + + " 1200\n" + + " 2023-05-01\n" + + " t?·???????é??è????¨\n" + + " E\n" + + " 1000 上不存在成本中心 1200180001/2023/05/01 。\n" + + " 2023-05-15\n" + + " 13:46:11\n" + + " \n" + + " \n" + + " \n" + + " clbx000002\n" + + " 1\n" + + " item1\n" + + " CN07010001\n" + + " \n" + + " \n" + + " 123.23\n" + + " CNY\n" + + " H\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " clbx000003\n" + + " 2\n" + + " item2\n" + + " \n" + + " 90010601\n" + + " 1200180001\n" + + " 100.23\n" + + " CNY\n" + + " S\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " clbx000003\n" + + " 3\n" + + " item3\n" + + " \n" + + " 90010602\n" + + " 1200180001\n" + + " 23.0\n" + + " CNY\n" + + " S\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + response = service.parseResponse(response, successField, successVal, messageField); + }catch (Exception e){ + log.error("流程数据推送SAP error : " + e.getMessage()); + error = e.getMessage(); + success = false; + } + try { + service.logToOA(modelId, url, requestId, xml, response, error); + }catch (Exception e){ + log.error("日志数据写入建模失败! " + e.getMessage()); + } + if(!success){ + throw new CustomerException("WorkflowToSap Action execute error : " + error); + } } @Test @@ -49,4 +162,149 @@ public class SAPTest extends BaseTest { List strings = CusData2OA.batchWriteToModel(modelId, sql, list); System.out.println("data => " + strings); } + + @Test + public void testResponse() throws JSONException { + String response = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " clbx000003\n" + + " \n" + + " 1200\n" + + " 2023-05-01\n" + + " t?·???????é??è????¨\n" + + " E\n" + + " 1000 上不存在成本中心 1200180001/2023/05/01 。\n" + + " 2023-05-15\n" + + " 13:46:11\n" + + " \n" + + " \n" + + " \n" + + " clbx000002\n" + + " 1\n" + + " item1\n" + + " CN07010001\n" + + " \n" + + " \n" + + " 123.23\n" + + " CNY\n" + + " H\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " clbx000003\n" + + " 2\n" + + " item2\n" + + " \n" + + " 90010601\n" + + " 1200180001\n" + + " 100.23\n" + + " CNY\n" + + " S\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " clbx000003\n" + + " 3\n" + + " item3\n" + + " \n" + + " 90010602\n" + + " 1200180001\n" + + " 23.0\n" + + " CNY\n" + + " S\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " string..............\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + JSONObject xmlResponseObj = XML.toJSONObject(response); + log.info("接口响应 : \n" + xmlResponseObj); + Map responseMap = com.alibaba.fastjson.JSONObject.parseObject(xmlResponseObj.toString(), Map.class); + System.out.println("responseMap : " + com.alibaba.fastjson.JSONObject.toJSONString(responseMap)); +// code = Util.null2String(parseMap(responseMap, RESPONSE_CODE)); +// if(!successCode.equals(code)){ +// throw new RuntimeException("推送erp接口失败! " + Util.null2String(readConfigUtil.parseMap(responseMap, RESPONSE_DESCRIPTION))); +// } + } + + /** + *

解析响应数据

+ * @param responseMap 响应map + * @param responseField 需要从map中获取指定字段的标识 Response.Execution + * @return 响应数据 + */ + public String parseMap(Map responseMap, String responseField){ + String[] strArr = responseField.split("\\."); + int i = 0; + while (i < strArr.length - 1){ + Object o = responseMap.get(strArr[i]); + if(o instanceof Map){ + responseMap = (Map) o; + }else if(o instanceof List){ + List> list = (List>) o; + if(CollectionUtils.isEmpty(list)){ + return ""; + } + responseMap = list.get(0); + } + i++; + } + return Util.null2String(responseMap.get(strArr[strArr.length - 1])); + } + + + @Test + public void testB(){ + String path = "sap.sap.xml"; + System.out.println(parseConfigPath(path)); + } + + /** + *

解析请求xml模板位置

+ * wxr.memsic.test.xml = /wxr/memsic/test.xml + * @param configFilePath 模板文件路径 + * @return 解析后的文件路径 + */ + public String parseConfigPath(String configFilePath){ + StringBuilder filePath = new StringBuilder(GCONST.getSysFilePath()); + int beginIndex = configFilePath.indexOf("."); + int endIndex = configFilePath.lastIndexOf("."); + if(beginIndex == endIndex){ + filePath.append(configFilePath); + }else { + String[] pathArr = configFilePath.split("\\."); + for (int i = 0; i < pathArr.length - 2; i++) { + if(i != 0){ + filePath.append(File.separator); + } + filePath.append(pathArr[i]); + } + filePath.append(File.separator) + .append(pathArr[pathArr.length - 2]) + .append(".") + .append(pathArr[pathArr.length - 1]); + } + return filePath.toString(); + } } diff --git a/src/test/java/xuanran/wang/http_test/annotations/CusJsonMappingConfig.java b/src/test/java/xuanran/wang/http_test/annotations/CusJsonMappingConfig.java new file mode 100644 index 0000000..802d261 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/CusJsonMappingConfig.java @@ -0,0 +1,19 @@ +package xuanran.wang.http_test.annotations; + + +import java.lang.annotation.*; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/5/25 14:42 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +@Documented +public @interface CusJsonMappingConfig { + String configCode() default ""; + String tableName() default ""; + +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java b/src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java index 172c5af..b2f8379 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java +++ b/src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java @@ -15,5 +15,5 @@ import java.lang.annotation.*; @Target({ElementType.METHOD, ElementType.TYPE}) @Documented public @interface CusReqAfterHandleRegister { - Class afterHandle(); + Class[] afterHandle(); } diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPost.java b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPost.java index 57f6806..2926c4a 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPost.java +++ b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPost.java @@ -23,4 +23,6 @@ public @interface CusRequestPost { @AliasFor(annotation = CusRequestType.class, attribute = "requestType") int requestType() default CusRequestClientConstant.POST; + + String configCode() default ""; } diff --git a/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java b/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java index 67c06e9..b629ff7 100644 --- a/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java +++ b/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java @@ -7,7 +7,9 @@ import lombok.Setter; import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; import xuanran.wang.http_test.handle.CusRequestAfterHandle; +import java.lang.reflect.Type; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -31,8 +33,8 @@ public class CusRequestEntity{ private boolean async = false; private String host = ""; private int port; - private Class returnType; - private CusRequestAfterHandle cusRequestAfter; + private Type returnType; + private List cusRequestAfter; private CusResponseSuccessHandle responseSuccessHandle; private Map responseMap; } diff --git a/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java b/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java index 4bcafaa..4b46176 100644 --- a/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java +++ b/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java @@ -7,6 +7,7 @@ import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.CollectionUtils; import org.apache.log4j.Logger; import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister; import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; @@ -85,16 +86,17 @@ public class CusHandleCenter{ } public Object requestAfterHandle(Method method, CusRequestEntity cusRequest, ResponeVo responseVo){ - if(cusRequest.getCusRequestAfter() == null){ - CusReqAfterHandleRegister cusReqAfterHandleRegister = method.getDeclaredAnnotation(CusReqAfterHandleRegister.class); - if(cusReqAfterHandleRegister != null){ - RequestUtil.setCusRequestAfter(cusReqAfterHandleRegister, cusRequest); - } + CusReqAfterHandleRegister cusReqAfterHandleRegister = method.getDeclaredAnnotation(CusReqAfterHandleRegister.class); + if(cusReqAfterHandleRegister != null){ + RequestUtil.setCusRequestAfter(cusReqAfterHandleRegister, cusRequest); + }else { + List tempList = new ArrayList<>(); + tempList.add(new CusDefaultRequestAfterHandle()); + cusRequest.setCusRequestAfter(tempList); } -// Type genericReturnType = method.getGenericReturnType(); - cusRequest.setReturnType(method.getReturnType()); + cusRequest.setReturnType(method.getGenericReturnType()); CusResponseSuccessHandle cusResponseSuccessHandle = method.getDeclaredAnnotation(CusResponseSuccessHandle.class); - if(cusResponseSuccessHandle != null && cusRequest.getResponseSuccessHandle() == null){ + if(cusResponseSuccessHandle != null && cusRequest.getResponseSuccessHandle() != null){ cusRequest.setResponseSuccessHandle(cusResponseSuccessHandle); } return requestAfterHandle(cusRequest, responseVo); @@ -113,11 +115,19 @@ public class CusHandleCenter{ responseVo.getEntityString())); throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // } - CusRequestAfterHandle handle = cusRequest.getCusRequestAfter() == null ? new CusDefaultRequestAfterHandle() : cusRequest.getCusRequestAfter(); - cusRequest.setCusRequestAfter(handle); + cusRequest.setResponseMap(responseVo.getResponseMap()); + List cusRequestAfter = cusRequest.getCusRequestAfter(); + Object res = null; log.info(Util.logStr("cusRequest: {}", JSONObject.toJSONString(cusRequest))); - Object res = handle.parseResponse(cusRequest, responseVo); - handle.service(cusRequest, responseVo); + for (CusRequestAfterHandle handle : cusRequestAfter) { + if(RequestUtil.isMethodOverridden(handle.getClass(), CusDefaultRequestAfterHandle.class, "parseResponse")){ + res = handle.parseResponse(cusRequest, responseVo); + }else { + CusDefaultRequestAfterHandle defaultRequestAfterHandle = new CusDefaultRequestAfterHandle(); + res = defaultRequestAfterHandle.parseResponse(cusRequest, responseVo); + } + handle.service(cusRequest, responseVo); + } return res; } diff --git a/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java b/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java index 06901f6..3dbb11b 100644 --- a/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java @@ -25,11 +25,10 @@ public abstract class CusRequestHandle { realRequestUrl.append(url); }else { realRequestUrl.append(host); - if(!host.endsWith(":")){ - realRequestUrl.append(":"); + if(port > 0 && !host.endsWith(":")){ + realRequestUrl.append(":").append(port); } - realRequestUrl.append(port); - if(!url.endsWith("/")){ + if(!host.endsWith("/") && !url.startsWith("/")){ realRequestUrl.append("/"); } realRequestUrl.append(url); diff --git a/src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java b/src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java index 7baeadb..03c5a04 100644 --- a/src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java @@ -72,10 +72,14 @@ public class RequestHeaderHandle implements CusRequestBeforeHandle { Parameter parameter = parameters[i]; CusRequestHeader requestHeader = parameter.getAnnotation(CusRequestHeader.class); if(requestHeader != null){ - String val = Util.null2DefaultStr(args[i], "").trim(); - String key = requestHeader.value().trim(); - if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){ - headers.put(key, val); + if(Map.class.isAssignableFrom(parameter.getType())){ + headers.putAll((Map) args[i]); + }else { + String val = Util.null2DefaultStr(args[i], "").trim(); + String key = requestHeader.value().trim(); + if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){ + headers.put(key, val); + } } } } diff --git a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java index 500e3c0..833fff6 100644 --- a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java @@ -10,6 +10,7 @@ import xuanran.wang.http_test.constant.CusRequestClientConstant; import xuanran.wang.http_test.entity.CusRequestEntity; import xuanran.wang.http_test.handle.CusRequestAfterHandle; +import java.lang.reflect.Type; import java.util.Map; /** @@ -22,12 +23,11 @@ public class CusDefaultRequestAfterHandle implements CusRequestAfterHandle { @Override public Object parseResponse(CusRequestEntity cusRequest, ResponeVo responseVo) { - Class returnType = cusRequest.getReturnType(); - if(ResponeVo.class.isAssignableFrom(returnType)) { + Type returnType = cusRequest.getReturnType(); + if(ResponeVo.class.isAssignableFrom(returnType.getClass())) { return responseVo; } String json = responseVo.getEntityString(); - cusRequest.setResponseMap(responseVo.getResponseMap()); CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle(); if(responseSuccessHandle != null){ String successCondition = responseSuccessHandle.successCondition(); diff --git a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java index d5c9edb..43e5032 100644 --- a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java @@ -8,6 +8,8 @@ import xuanran.wang.http_test.entity.CusRequestEntity; import xuanran.wang.http_test.handle.CusRequestBeforeHandle; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; /** *

方法路径拼接处理

@@ -23,7 +25,6 @@ public class CusUrlHandle implements CusRequestBeforeHandle { throw new CustomerException("method not found CusRequestUrl!"); } cusRequest.setUrl(requestUrl.url()); - Class returnType = method.getReturnType(); - cusRequest.setReturnType(returnType); + cusRequest.setReturnType(method.getGenericReturnType()); } } diff --git a/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java b/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java index 169237b..f380e26 100644 --- a/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java +++ b/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java @@ -17,6 +17,8 @@ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; /** @@ -29,12 +31,13 @@ public class RequestUtil implements InvocationHandler { private CusRequestAddress cusRequestAddress = null; private final Logger log = Util.getLogger(); private final CusHandleCenter handleCenter = new CusHandleCenter(); - private final CusRequestEntity cusRequest = new CusRequestEntity(); + private CusRequestEntity cusRequest; public T getRequestClient(Class clazz){ Annotation annotation = clazz.getDeclaredAnnotation(CusRequestClient.class); if(annotation == null){ throw new CustomerException(Util.logStr(clazz.getName() + " not found CusRequestClient annotation!")); } + cusRequest = new CusRequestEntity(); // 请求后处理 CusReqAfterHandleRegister cusReqAfterHandleRegister = clazz.getDeclaredAnnotation(CusReqAfterHandleRegister.class); if(cusReqAfterHandleRegister != null){ @@ -62,7 +65,6 @@ public class RequestUtil implements InvocationHandler { cusRequest.setPort(port); } handleCenter.requestBeforeHandle(cusRequest, method, args); - log.info("requestHandle : \n" + JSONObject.toJSONString(cusRequest)); ResponeVo responeVo = handleCenter.requestHandle(cusRequest, method); return handleCenter.requestAfterHandle(method, cusRequest, responeVo); } @@ -70,16 +72,33 @@ public class RequestUtil implements InvocationHandler { public static void setCusRequestAfter(CusReqAfterHandleRegister cusReqAfterHandleRegister, CusRequestEntity cusRequest){ if(cusReqAfterHandleRegister != null){ - Class clazz = cusReqAfterHandleRegister.afterHandle(); - if (CusRequestAfterHandle.class.isAssignableFrom(clazz)) { - try { - Object cusRequestAfter = clazz.newInstance(); - cusRequest.setCusRequestAfter((CusRequestAfterHandle) cusRequestAfter); - }catch (Exception e){ - throw new CustomerException(Util.logStr("class : {}, newInstance error!", e.getMessage())); + Class[] clazz = cusReqAfterHandleRegister.afterHandle(); + List requestAfter = cusRequest.getCusRequestAfter(); + if(requestAfter == null){ + requestAfter = new ArrayList<>(); + } + cusRequest.setCusRequestAfter(requestAfter); + for (Class aClass : clazz) { + if (CusRequestAfterHandle.class.isAssignableFrom(aClass)) { + try { + CusRequestAfterHandle cusRequestAfter = (CusRequestAfterHandle) aClass.newInstance(); + requestAfter.add(cusRequestAfter); + }catch (Exception e){ + throw new CustomerException(Util.logStr("class : {}, newInstance error!", e.getMessage())); + } } } } } + public static boolean isMethodOverridden(Class subclass, Class superclass, String methodName) { + try { + Method method = subclass.getDeclaredMethod(methodName); + Method superMethod = superclass.getDeclaredMethod(methodName); + return !method.equals(superMethod); + } catch (NoSuchMethodException e) { + return false; + } + } + } diff --git a/src/test/java/xuanran/wang/http_test/service/EcTestService.java b/src/test/java/xuanran/wang/http_test/service/EcTestService.java new file mode 100644 index 0000000..855ed46 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/service/EcTestService.java @@ -0,0 +1,27 @@ +package xuanran.wang.http_test.service; + +import xuanran.wang.http_test.annotations.CusRequestClient; +import xuanran.wang.http_test.annotations.header.CusRequestHeader; +import xuanran.wang.http_test.annotations.request_type.CusRequestPost; + +import javax.ws.rs.core.MediaType; +import java.util.Map; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/5/24 14:53 + */ +@CusRequestClient(host = "https://ecology.yeyaguitu.cn") +public interface EcTestService { + + @CusRequestPost(url = "/api/ec/dev/auth/regist") + @CusRequestHeader(cusHeaders = {"appid:JYZ", "loginid:sysadmin","Content-type:"+ MediaType.APPLICATION_JSON}) + Map register(); + + @CusRequestPost(url = "/api/ec/dev/auth/regist") + @CusRequestHeader(cusHeaders = {"Content-type:"+ MediaType.APPLICATION_JSON}) + Map register(@CusRequestHeader("appid") String appId, + @CusRequestHeader Map headers); +} diff --git a/src/test/java/xuanran/wang/http_test/service/TestService.java b/src/test/java/xuanran/wang/http_test/service/TestService.java index e74ea59..30dc0c4 100644 --- a/src/test/java/xuanran/wang/http_test/service/TestService.java +++ b/src/test/java/xuanran/wang/http_test/service/TestService.java @@ -2,12 +2,15 @@ package xuanran.wang.http_test.service; import xuanran.wang.http_test.annotations.*; import xuanran.wang.http_test.annotations.body.CusRequestBody; +import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister; import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; import xuanran.wang.http_test.annotations.header.CusRequestHeader; import xuanran.wang.http_test.annotations.request_path.CusPathQuery; import xuanran.wang.http_test.annotations.request_type.CusRequestGet; import xuanran.wang.http_test.annotations.request_type.CusRequestPost; import xuanran.wang.http_test.constant.CusRequestClientConstant; +import xuanran.wang.http_test.test.Student; +import xuanran.wang.http_test.test.TestRequestAfterHandle; import java.util.List; import java.util.Map; @@ -19,7 +22,6 @@ import java.util.Map; * @date 2023/3/10 12:39 */ @CusRequestClient(host = "http://114.115.168.220", port = 8191) -//@CusReqAfterHandleRegister(afterHandle = TestRequestAfterHandle.class) public interface TestService { @CusRequestGet(url = "educate-plat/api/v1/class/getClassList") @@ -30,8 +32,9 @@ public interface TestService { errorMsg = "msg", data = "data" ) - Map getStu(Map path, - @CusRequestBody Map body, - @CusRequestHeader("hsjhdsad") String test, - @CusPathQuery("test") String test1); + @CusReqAfterHandleRegister(afterHandle = {TestRequestAfterHandle.class}) + List getStu(Map path, + @CusRequestBody Map body, + @CusRequestHeader("hsjhdsad") String test, + @CusPathQuery("test") String test1); } diff --git a/src/test/java/xuanran/wang/http_test/test/RequestTest.java b/src/test/java/xuanran/wang/http_test/test/RequestTest.java index 7b3dccf..29d2937 100644 --- a/src/test/java/xuanran/wang/http_test/test/RequestTest.java +++ b/src/test/java/xuanran/wang/http_test/test/RequestTest.java @@ -2,6 +2,7 @@ package xuanran.wang.http_test.test; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; import com.api.doc.migrate.util.FtpUtil; import com.jcraft.jsch.ChannelSftp; import org.junit.Test; @@ -9,6 +10,7 @@ import weaver.backup.utils.ZipUtil; import xuanran.wang.http_test.entity.CusHandleEntity; import xuanran.wang.http_test.handle.util.HandleUtil; import xuanran.wang.http_test.proxy.CusUtil; +import xuanran.wang.http_test.service.EcTestService; import xuanran.wang.http_test.service.TestService; import java.util.*; @@ -23,6 +25,7 @@ import java.util.stream.Collectors; public class RequestTest extends BaseTest { private TestService requestClient = CusUtil.getRequestClient(TestService.class); + private EcTestService ecTestService = CusUtil.getRequestClient(EcTestService.class); @Test public void test(){ HashMap map = new HashMap<>(); @@ -36,9 +39,11 @@ public class RequestTest extends BaseTest { path.put("e","5"); path.put("f","6"); - Map stu = requestClient.getStu(map, body, "a", "test1111"); - log.info("stu : \n" + JSONObject.toJSONString(stu)); - +// List stu = requestClient.getStu(map, body, "a", "test1111"); + List stu = requestClient.getStu(map, body, "a", "test1111"); + for (Student student : stu) { + System.out.println("stu => " + student); + } // String json = "{\"xuanran.wang.http_test.requestBeforeHandle.path_handle\":[{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle.CusPathParseHandle\",\"order\":0,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle\"},{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle.TestHandle\",\"order\":99,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.path_handle\"}],\"xuanran.wang.http_test.requestBeforeHandle.header_handle\":[{\"handleClass\":\"xuanran.wang.http_test.requestBeforeHandle.header_handle.RequestHeaderHandle\",\"order\":0,\"packageName\":\"xuanran.wang.http_test.requestBeforeHandle.header_handle\"}]}"; // System.out.println(JSONObject.parseObject(JSONObject.toJSONString(json), Map.class)); // String stu1 = requestClient.getStu(body); @@ -61,4 +66,16 @@ public class RequestTest extends BaseTest { } } + + @Test + public void testB(){ + Map register = ecTestService.register(); + System.out.printf("register : " + JSONObject.toJSONString(register)); + + HashMap header = new HashMap<>(); + header.put("loginid","123"); + header.put("dadsada","sasas"); + Map register1 = ecTestService.register("JYZ1", header); + System.out.printf("register1 : " + JSONObject.toJSONString(register1)); + } } diff --git a/src/test/java/xuanran/wang/http_test/test/Student.java b/src/test/java/xuanran/wang/http_test/test/Student.java new file mode 100644 index 0000000..ef0a148 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/test/Student.java @@ -0,0 +1,49 @@ +package xuanran.wang.http_test.test; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/5/23 11:40 + */ +public class Student { + private String teacherId; + private int belongYear; + private String classNo; + private String className; + private String id; + public void setTeacherId(String teacherId) { + this.teacherId = teacherId; + } + public String getTeacherId() { + return teacherId; + } + + public void setBelongYear(int belongYear) { + this.belongYear = belongYear; + } + public int getBelongYear() { + return belongYear; + } + + public void setClassNo(String classNo) { + this.classNo = classNo; + } + public String getClassNo() { + return classNo; + } + + public void setClassName(String className) { + this.className = className; + } + public String getClassName() { + return className; + } + + public void setId(String id) { + this.id = id; + } + public String getId() { + return id; + } +}