From 4615e23317d81587f18ff51014674b724767a6f6 Mon Sep 17 00:00:00 2001 From: "yushun.ding" <2437588377@qq.com> Date: Sat, 25 Mar 2023 00:26:00 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=A4=84=E7=90=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index cc5f158..62322df 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -3870,4 +3870,70 @@ public class Util extends weaver.general.Util { } return ip; } + + /** + * 多语言处理 + * + * @param oldName 老名字 + * @param newName 新名字 + * @param lanuage 要替换的语言 以 7 8 9 举例 + */ + public String moreLanugageHandler(String oldName, String newName, String lanuage) { + List languageIds = weaver.general.Util.getActiveLanguageIds();//获取系统支持的多语言 + String newMoreLanuage = ""; + //要按照当前系统支持的多语言id进行拼接处理 + if (oldName.startsWith("~`~`") && oldName.endsWith("`~`~")) { + // 获取当前系统存在的多语言id + // 思路:先按照系统存在的语言进行拼接,之后判断oldname包含那些语言进行过滤,将除了lanuage的其他语言都替换成之前的 + //多语言的中间处理 + String tempLanuage = joinLanuage(newName, languageIds); + //中间处理转成map + Map splitMultilangData = weaver.general.Util.splitMultilangData(tempLanuage); + Map lanuageMap = new HashMap<>(); + for (Object id : languageIds) { + String labelLanuage = "`~`" + id; + if (oldName.contains(labelLanuage)) { + //获取过滤的语言name + String formatLanuageName = weaver.general.Util.formatMultiLang(oldName, String.valueOf(id)); + if (!weaver.general.StringUtil.isEmpty(formatLanuageName)) { + lanuageMap.put(String.valueOf(id), formatLanuageName); + } + } + } + String s = lanuageMap.get(lanuage); + if (weaver.general.StringUtil.isEmpty(s)) { + for (Map.Entry entry : lanuageMap.entrySet()) { + splitMultilangData.put(entry.getKey(), entry.getValue()); + } + } else { + lanuageMap.remove(lanuage); + for (Map.Entry entry : lanuageMap.entrySet()) { + splitMultilangData.put(entry.getKey(), entry.getValue()); + } + } + newMoreLanuage = weaver.general.Util.stitchMultilangData(splitMultilangData); + } else { + //要根据系统支持的语言进行拼接 + newMoreLanuage = joinLanuage(newName, languageIds); + } + return newMoreLanuage; + } + + /** + * 多语言拼接 + * + * @param newName 新的名字 + * @param languageIds 系统支持的语言集合 + * @return 拼接后的字符串 + */ + public String joinLanuage(String newName, List languageIds) { + StringBuilder supportLanuage = new StringBuilder(); + supportLanuage.append("~`~`"); + languageIds.forEach(id -> { + supportLanuage.append(id).append(" ").append(newName).append("`~`"); + }); + supportLanuage.delete(supportLanuage.lastIndexOf("`~`"), supportLanuage.length()); + supportLanuage.append("`~`~"); + return supportLanuage.toString(); + } } From 3c49ade7b4abc220f9a7345b367126fd5b403c2a Mon Sep 17 00:00:00 2001 From: "yushun.ding" <2437588377@qq.com> Date: Sat, 25 Mar 2023 21:12:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B9=E6=B3=95=E8=A1=A5=E5=85=85static?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 62322df..12ad673 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -3878,8 +3878,8 @@ public class Util extends weaver.general.Util { * @param newName 新名字 * @param lanuage 要替换的语言 以 7 8 9 举例 */ - public String moreLanugageHandler(String oldName, String newName, String lanuage) { - List languageIds = weaver.general.Util.getActiveLanguageIds();//获取系统支持的多语言 + public static String moreLanugageHandler(String oldName, String newName, String lanuage) { + List languageIds = getActiveLanguageIds();//获取系统支持的多语言 String newMoreLanuage = ""; //要按照当前系统支持的多语言id进行拼接处理 if (oldName.startsWith("~`~`") && oldName.endsWith("`~`~")) { @@ -3888,13 +3888,13 @@ public class Util extends weaver.general.Util { //多语言的中间处理 String tempLanuage = joinLanuage(newName, languageIds); //中间处理转成map - Map splitMultilangData = weaver.general.Util.splitMultilangData(tempLanuage); + Map splitMultilangData = splitMultilangData(tempLanuage); Map lanuageMap = new HashMap<>(); for (Object id : languageIds) { String labelLanuage = "`~`" + id; if (oldName.contains(labelLanuage)) { //获取过滤的语言name - String formatLanuageName = weaver.general.Util.formatMultiLang(oldName, String.valueOf(id)); + String formatLanuageName = formatMultiLang(oldName, String.valueOf(id)); if (!weaver.general.StringUtil.isEmpty(formatLanuageName)) { lanuageMap.put(String.valueOf(id), formatLanuageName); } @@ -3911,7 +3911,7 @@ public class Util extends weaver.general.Util { splitMultilangData.put(entry.getKey(), entry.getValue()); } } - newMoreLanuage = weaver.general.Util.stitchMultilangData(splitMultilangData); + newMoreLanuage = stitchMultilangData(splitMultilangData); } else { //要根据系统支持的语言进行拼接 newMoreLanuage = joinLanuage(newName, languageIds); @@ -3926,7 +3926,7 @@ public class Util extends weaver.general.Util { * @param languageIds 系统支持的语言集合 * @return 拼接后的字符串 */ - public String joinLanuage(String newName, List languageIds) { + public static String joinLanuage(String newName, List languageIds) { StringBuilder supportLanuage = new StringBuilder(); supportLanuage.append("~`~`"); languageIds.forEach(id -> { From ee64140219bac1b2ce7115bfaa2d0a0b44694af8 Mon Sep 17 00:00:00 2001 From: "yushun.ding" <2437588377@qq.com> Date: Mon, 27 Mar 2023 13:03:45 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=87=91=E9=A2=9D=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=20+=20-=20*=20/=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/AmountHandler.java | 178 ++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/main/java/aiyh/utils/AmountHandler.java diff --git a/src/main/java/aiyh/utils/AmountHandler.java b/src/main/java/aiyh/utils/AmountHandler.java new file mode 100644 index 0000000..0ccdab0 --- /dev/null +++ b/src/main/java/aiyh/utils/AmountHandler.java @@ -0,0 +1,178 @@ +package aiyh.utils; + +/** + * @Author DYS + * @Date 2023/3/25 18:08 + * @description create at weaver + */ + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 金额类型. 支持自身的四则运算,并将this返回. + */ +public class AmountHandler implements Serializable { + + private BigDecimal value; + + /** + * 提供默认精度10 + */ + private int scale = 10; + + public AmountHandler() { + + } + + /** + * double类型构造函数 + * + * @param value + */ + public AmountHandler(double value) { + this.value = new BigDecimal(Double.toString(value)); + } + + /** + * String类型构造函数 + * + * @param value + */ + public AmountHandler(String value) { + this.value = new BigDecimal(value); + } + + /** + * 取得BigDecimal的值 + * + * @return + */ + public BigDecimal getValue() { + return this.value; + } + + /** + * 两个double类型的数值相加 + * + * @param v1 + * @param v2 + * @return + */ + public double add(double v1, double v2) { + AmountHandler a1 = new AmountHandler(v1); + AmountHandler a2 = new AmountHandler(v2); + return add(a1, a2); + } + + /** + * 两数相除 + * + * @param v1 + * @param v2 + * @return + */ + public double div(double v1, double v2) { + AmountHandler a1 = new AmountHandler(v1); + AmountHandler a2 = new AmountHandler(v2); + return this.divide(a1, a2); + } + + /** + * 相减 + * + * @param v1 + * @param v2 + * @return + */ + public double sub(double v1, double v2) { + AmountHandler a1 = new AmountHandler(v1); + AmountHandler a2 = new AmountHandler(v2); + return this.subtract(a1, a2); + } + + /** + * 相乘 + * + * @param v1 + * @param v2 + * @return + */ + public double mul(double v1, double v2) { + AmountHandler a1 = new AmountHandler(v1); + AmountHandler a2 = new AmountHandler(v2); + return this.multiply(a1, a2); + } + + /** + * 两个Amount类型的数据进行相加 + * + * @param v1 + * @param v2 + * @return + */ + public double add(AmountHandler v1, AmountHandler v2) { + return v1.getValue().add(v2.getValue()).doubleValue(); + } + + /** + * 两个Amount类型变量相除 + * + * @param v1 + * @param v2 + * @return + */ + public double divide(AmountHandler v1, AmountHandler v2) { + if (scale < 0) { + throw new IllegalArgumentException("精度指定错误,请指定一个>=0的精度"); + } + return v1.getValue().divide(v2.getValue(), scale, + BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 两数相乘 + * + * @param v1 + * @param v2 + * @return + */ + public double multiply(AmountHandler v1, AmountHandler v2) { + return v1.getValue().multiply(v2.getValue()).doubleValue(); + } + + /** + * 两数相减 + * + * @param v1 + * @param v2 + * @return + */ + public double subtract(AmountHandler v1, AmountHandler v2) { + return v1.getValue().subtract(v2.getValue()).doubleValue(); + } + + /** + * 返回value的浮点数值 + * + * @return + */ + public double doubleValue() { + return this.getValue().doubleValue(); + } + + /** + * 设置精度 + * + * @param scale + */ + public void setScale(int scale) { + this.scale = scale; + } + + public static void main(String[] args) { + AmountHandler AmountHandler = new AmountHandler(5000.23); + AmountHandler AmountHandler1 = new AmountHandler(2033.37); + System.out.println(new AmountHandler().add(AmountHandler, AmountHandler1)); + } +} From 9275631cd829a3ba2031c14d13867c958750dfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=A3=E7=84=B6?= Date: Tue, 4 Apr 2023 17:15:00 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=A7=A3=E5=86=B3double=E8=B6=85=E5=87=BA?= =?UTF-8?q?=E7=B2=BE=E5=BA=A6=E8=BD=AC=E6=88=90=E7=A7=91=E5=AD=A6=E8=AE=B0?= =?UTF-8?q?=E6=95=B0=E6=B3=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/service/DealWithMapping.java | 16 +++- ...viceImpl.java => UserServiceImplBack.java} | 2 + .../http_test/annotations/CusPathQuery.java | 16 ---- ...{CusRequest.java => CusRequestClient.java} | 2 +- .../http_test/annotations/GetPathValue.java | 15 ---- .../wang/http_test/annotations/PostBody.java | 15 ---- ...ant.java => CusRequestClientConstant.java} | 2 +- ...andle.java => CusRequestBeforeHandle.java} | 0 .../wang/http_test/handle/PostTypeHandle.java | 35 -------- .../http_test/handle/RequestHeaderHandle.java | 81 ------------------- ...rseHandle.java => CusPathParseHandle.java} | 4 +- 11 files changed, 21 insertions(+), 167 deletions(-) rename src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/{UserServiceImpl.java => UserServiceImplBack.java} (98%) delete mode 100644 src/test/java/xuanran/wang/http_test/annotations/CusPathQuery.java rename src/test/java/xuanran/wang/http_test/annotations/{CusRequest.java => CusRequestClient.java} (86%) delete mode 100644 src/test/java/xuanran/wang/http_test/annotations/GetPathValue.java delete mode 100644 src/test/java/xuanran/wang/http_test/annotations/PostBody.java rename src/test/java/xuanran/wang/http_test/constant/{RequestUtilConstant.java => CusRequestClientConstant.java} (89%) rename src/test/java/xuanran/wang/http_test/handle/{RequestBeforeHandle.java => CusRequestBeforeHandle.java} (100%) delete mode 100644 src/test/java/xuanran/wang/http_test/handle/PostTypeHandle.java delete mode 100644 src/test/java/xuanran/wang/http_test/handle/RequestHeaderHandle.java rename src/test/java/xuanran/wang/http_test/handle/path_handle/{CusFieldKeyParseHandle.java => CusPathParseHandle.java} (89%) 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 712fc01..1219d1e 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -21,6 +21,7 @@ import weaver.zwl.common.ToolUtil; import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.math.BigDecimal; import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -115,7 +116,20 @@ public class DealWithMapping extends ToolUtil { continue; } if ("DECIMAL".equalsIgnoreCase(type) || "NUMERIC".equalsIgnoreCase(type)) { - map.put(key, rs.getDouble(i)); + /** + * @author xuanran.wang + * @data 2023-04-04 + * @desc 解决double超出精度转成科学记数法的问题 + */ + String val = Util.null2String(rs.getString(i)); + BigDecimal decimal; + if(StringUtils.isBlank(val)){ + decimal = new BigDecimal("0"); + }else { + decimal = new BigDecimal(val); + } + map.put(key, decimal); +// map.put(key, rs.getDouble(i)); continue; } map.put(key, rs.getString(i)); diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java similarity index 98% rename from src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java rename to src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java index 01d336e..759e1e2 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java @@ -68,6 +68,7 @@ public class UserServiceImpl extends CusInfoActionService { // 通过外键获取部门信息数据为空 throw new CustomerException("The department information data obtained by foreign key is empty!"); } + logger.info(Util.logStr("depInfoByOutKey : {}", JSONObject.toJSONString(depInfoByOutKey))); nextHrmId = getNextHrmId(); List params = initHrmParam(nextHrmId, userInfo, depInfoByOutKey); String departmentId = Util.null2DefaultStr(depInfoByOutKey.get("departmentId"), ""); @@ -177,6 +178,7 @@ public class UserServiceImpl extends CusInfoActionService { // 通过外键获取部门信息数据为空 throw new CustomerException("The department information data obtained by foreign key is empty!"); } + logger.info(Util.logStr("depInfoByOutKey : {}", JSONObject.toJSONString(depInfoByOutKey))); // oa人员id String hrmId = consumerMapper.getHrmIdByOutKey(userInfoId); if(StringUtils.isBlank(hrmId)){ diff --git a/src/test/java/xuanran/wang/http_test/annotations/CusPathQuery.java b/src/test/java/xuanran/wang/http_test/annotations/CusPathQuery.java deleted file mode 100644 index 3d43003..0000000 --- a/src/test/java/xuanran/wang/http_test/annotations/CusPathQuery.java +++ /dev/null @@ -1,16 +0,0 @@ -package xuanran.wang.http_test.annotations; - -import java.lang.annotation.*; - -/** - *

请求路径参数替换

- * - * @author xuanran.wang - * @date 2023/3/10 17:00 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PARAMETER}) -@Documented -public @interface CusPathQuery { - String value(); -} diff --git a/src/test/java/xuanran/wang/http_test/annotations/CusRequest.java b/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java similarity index 86% rename from src/test/java/xuanran/wang/http_test/annotations/CusRequest.java rename to src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java index ef05213..c1ea590 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/CusRequest.java +++ b/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java @@ -11,5 +11,5 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented -public @interface CusRequest { +public @interface CusRequestClient { } diff --git a/src/test/java/xuanran/wang/http_test/annotations/GetPathValue.java b/src/test/java/xuanran/wang/http_test/annotations/GetPathValue.java deleted file mode 100644 index 65dd302..0000000 --- a/src/test/java/xuanran/wang/http_test/annotations/GetPathValue.java +++ /dev/null @@ -1,15 +0,0 @@ -package xuanran.wang.http_test.annotations; - -import java.lang.annotation.*; - -/** - *

路径参数 可以修饰map,字段 如果是字段那就会将

- * - * @author xuanran.wang - * @date 2023/3/10 13:06 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -@Documented -public @interface GetPathValue { -} diff --git a/src/test/java/xuanran/wang/http_test/annotations/PostBody.java b/src/test/java/xuanran/wang/http_test/annotations/PostBody.java deleted file mode 100644 index 2f704c8..0000000 --- a/src/test/java/xuanran/wang/http_test/annotations/PostBody.java +++ /dev/null @@ -1,15 +0,0 @@ -package xuanran.wang.http_test.annotations; - -import java.lang.annotation.*; - -/** - *

post请求体

- * - * @author xuanran.wang - * @date 2023/3/10 13:48 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -@Documented -public @interface PostBody { -} diff --git a/src/test/java/xuanran/wang/http_test/constant/RequestUtilConstant.java b/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java similarity index 89% rename from src/test/java/xuanran/wang/http_test/constant/RequestUtilConstant.java rename to src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java index d8f6c83..d368610 100644 --- a/src/test/java/xuanran/wang/http_test/constant/RequestUtilConstant.java +++ b/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java @@ -6,7 +6,7 @@ package xuanran.wang.http_test.constant; * @author xuanran.wang * @date 2023/3/10 14:01 */ -public class RequestUtilConstant { +public class CusRequestClientConstant { public static final int GET = 0; public static final int POST = 1; public static final int DELETE = 2; diff --git a/src/test/java/xuanran/wang/http_test/handle/RequestBeforeHandle.java b/src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java similarity index 100% rename from src/test/java/xuanran/wang/http_test/handle/RequestBeforeHandle.java rename to src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java diff --git a/src/test/java/xuanran/wang/http_test/handle/PostTypeHandle.java b/src/test/java/xuanran/wang/http_test/handle/PostTypeHandle.java deleted file mode 100644 index 7b75eeb..0000000 --- a/src/test/java/xuanran/wang/http_test/handle/PostTypeHandle.java +++ /dev/null @@ -1,35 +0,0 @@ -//package xuanran.wang.http_test.handle; -// -//import com.alibaba.fastjson.JSONObject; -//import xuanran.wang.http_test.annotations.PostBody; -// -//import java.lang.reflect.Method; -//import java.lang.reflect.Parameter; -//import java.util.HashMap; -//import java.util.Map; -// -///** -// *

post方法解析

-// * -// * @author xuanran.wang -// * @date 2023/3/10 13:54 -// */ -//public class PostTypeHandle implements RequestBeforeHandle { -// @Override -// public Map handle(String url, Method method, Object[] args) { -// Parameter[] parameters = method.getParameters(); -// for (int i = 0; i < parameters.length; i++) { -// PostBody postBody = parameters[i].getDeclaredAnnotation(PostBody.class); -// if(postBody != null){ -// Object arg = args[i]; -// if(arg instanceof Map){ -// return (Map) arg; -// }else if(arg instanceof String){ -// String json = JSONObject.toJSONString(arg); -// return JSONObject.parseObject(json, Map.class); -// } -// } -// } -// return new HashMap(); -// } -//} diff --git a/src/test/java/xuanran/wang/http_test/handle/RequestHeaderHandle.java b/src/test/java/xuanran/wang/http_test/handle/RequestHeaderHandle.java deleted file mode 100644 index 6d2d99b..0000000 --- a/src/test/java/xuanran/wang/http_test/handle/RequestHeaderHandle.java +++ /dev/null @@ -1,81 +0,0 @@ -//package xuanran.wang.http_test.handle; -// -//import aiyh.utils.Util; -//import aiyh.utils.excention.CustomerException; -//import org.apache.commons.collections.CollectionUtils; -//import org.apache.commons.collections.MapUtils; -//import org.apache.commons.lang3.StringUtils; -//import xuanran.wang.http_test.annotations.header.CusRequestHeader; -//import xuanran.wang.http_test.interfaces.CusCreateRequestHeader; -// -//import java.lang.reflect.Method; -//import java.lang.reflect.Parameter; -//import java.util.HashMap; -//import java.util.Map; -// -///** -// *

请求头处理

-// * -// * @author xuanran.wang -// * @date 2023/3/10 14:42 -// */ -//public class RequestHeaderHandle implements RequestBeforeHandle { -// @Override -// public Object handle(String url, Method method, Object[] args) { -// CusRequestHeader methodCusRequestHeader = method.getDeclaredAnnotation(CusRequestHeader.class); -// if(methodCusRequestHeader == null){ -// return new HashMap<>(); -// } -// // 数组形式 -// String[] headersArr = methodCusRequestHeader.cusHeaders(); -// HashMap headers = new HashMap<>(); -// if(headersArr != null){ -// for (String headerStr : headersArr) { -// String[] split = headerStr.split(":"); -// String key = Util.null2DefaultStr(split[0],"").trim(); -// String val = Util.null2DefaultStr(split[1],"").trim(); -// if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){ -// headers.put(key, val); -// } -// } -// } -// -// // java代码自定义 -// String path = Util.null2DefaultStr(methodCusRequestHeader.cusHeadersClassPath(),""); -// if(StringUtils.isNotBlank(path)){ -// Class clazz; -// try { -// clazz = Class.forName(path); -// } catch (ClassNotFoundException e) { -// throw new CustomerException(Util.logStr("自定义请求头java类文件没找到!: {}", path)); -// } -// if(!clazz.isAssignableFrom(CusCreateRequestHeader.class)){ -// throw new CustomerException(Util.logStr("当前类路径:[{}] ,未实现CusCreateRequestHeader接口!", path)); -// } -// CusCreateRequestHeader o; -// try { -// o = (CusCreateRequestHeader) clazz.newInstance(); -// }catch (InstantiationException | IllegalAccessException e) { -// throw new CustomerException(Util.logStr("实例化 [{}] 对象失败! error:{}", path, e.getMessage())); -// } -// Map cusCreateHeader = o.createHeader(); -// if(MapUtils.isNotEmpty(cusCreateHeader)){ -// headers.putAll(cusCreateHeader); -// } -// } -// // 参数中 -// Parameter[] parameters = method.getParameters(); -// for (int i = 0; i < parameters.length; i++) { -// 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); -// } -// } -// } -// return headers; -// } -//} diff --git a/src/test/java/xuanran/wang/http_test/handle/path_handle/CusFieldKeyParseHandle.java b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java similarity index 89% rename from src/test/java/xuanran/wang/http_test/handle/path_handle/CusFieldKeyParseHandle.java rename to src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java index 19ab94e..d9cf5b8 100644 --- a/src/test/java/xuanran/wang/http_test/handle/path_handle/CusFieldKeyParseHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java @@ -2,7 +2,7 @@ package xuanran.wang.http_test.handle.path_handle; import aiyh.utils.Util; import org.apache.commons.lang3.StringUtils; -import xuanran.wang.http_test.annotations.CusPathQuery; +import xuanran.wang.http_test.annotations.request_path.CusPathQuery; import xuanran.wang.http_test.entity.CusRequestEntity; import xuanran.wang.http_test.handle.RequestBeforeHandle; @@ -33,7 +33,7 @@ public class CusFieldKeyParseHandle implements RequestBeforeHandle { }else { Class clazz = parameter.getType(); if(clazz.isAssignableFrom(Map.class)){ - requestEntity.setPathParams((Map) arg); + requestEntity.getPathParams().putAll((Map) arg); } } } From 771778167605599fbbda0711350abcdd9c01495d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=A3=E7=84=B6?= Date: Sun, 9 Apr 2023 21:15:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?2023-04-09=20=E4=B8=8A=E6=B5=B7=E5=A4=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=AD=E5=BF=83=E7=BB=9F=E4=B8=80=E5=BE=85?= =?UTF-8?q?=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xuanran.wang/bme/js/BuildContractApply.js | 6 +- javascript/xuanran.wang/bme/js/Common.js | 24 +- javascript/xuanran.wang/bme/js/DiaoBo.js | 26 ++ javascript/xuanran.wang/bme/js/PayApply.js | 155 +++++++- .../bme/js/PurchaseContractApply.js | 6 +- .../xuanran.wang/bme/js/SaleContractApply.js | 9 +- javascript/xuanran.wang/shyl/MealOrder.js | 45 +++ pom.xml | 6 + .../BatchCreateWorkFlowController.java | 4 - .../controller/UserUpdateToMQController.java | 54 +++ .../wang/shyl/mapper/ProducerMapper.java | 26 +- .../xuanran/wang/shyl/service/CarService.java | 5 + .../shyl/service/UserUpdateToMQService.java | 57 +++ .../workflow/action/FileTypeFieldConvert.java | 70 ++++ .../bme/action/CheckConsumerNameAction.java | 49 +++ .../action/ContractApplyComDateAction.java | 17 +- .../wang/common/util/CusInfoToOAUtil.java | 24 +- .../xuanran/wang/immc/WorkFlowToVmsAndMQ.java | 64 +++ .../wang/immc/cusfieldvalue/CusListValue.java | 50 +++ .../wang/immc/entity/VmsResponseVoField.java | 23 ++ .../xuanran/wang/immc/mapper/ImMcMapper.java | 20 + .../service/WorkFlowToVmsAndMQService.java | 165 ++++++++ .../sh_bigdata/common/entity/CusSuccess.java | 26 ++ .../sh_bigdata/common/entity/CusToken.java | 25 ++ .../common/util/RequestMasterPlate.java | 74 ++++ .../common/util/SendTodoTaskUtil.java | 167 ++++++++ .../sh_bigdata/common/util/ShBigDataUtil.java | 120 ++++++ .../sh_bigdata/common/util/TokenUtil.java | 78 ++++ .../OrganizationHrmSyncFromOtherSys.java | 106 +++++ .../annotations/CusDbEntityMapping.java | 16 + .../entity/OtherSysDepartment.java | 53 +++ .../mapper/OrgHrmAsyncMapper.java | 25 ++ .../service/OrgHrmAsyncApiService.java | 32 ++ .../service/OrgHrmAsyncService.java | 31 ++ .../impl/OrgHrmAsyncApiServiceImpl.java | 49 +++ .../service/impl/OrgHrmAsyncServiceImpl.java | 163 ++++++++ .../task_async/SendTodoTaskImpl.java | 162 ++++++++ .../task_async/entity/CusDoneTask.java | 23 ++ .../task_async/entity/CusDoneTaskOA.java | 39 ++ .../task_async/entity/CusTodoTask.java | 29 ++ .../entity/CusTodoTaskToOADetail.java | 68 ++++ .../task_async/mapper/SendTodoTaskMapper.java | 30 ++ .../service/SendTodoTaskService.java | 16 + .../service/impl/SendTodoTaskServiceImpl.java | 152 ++++++++ .../wang/shyl_mq/entity/MQMessage.java | 10 +- .../wang/shyl_mq/mapper/ConsumerMapper.java | 6 +- .../wang/shyl_mq/service/ProducerService.java | 10 +- .../service/impl/PassWordServiceImpl.java | 16 +- .../shyl_mq/service/impl/UserServiceImpl.java | 124 ++++++ .../service/impl/UserServiceImplBack.java | 4 +- .../wang/shyl_mq/util/RocketConsumerUtil.java | 23 +- .../prop/prop2map/OACarTest.properties | 5 + .../prop/prop2map/ShBigdataConf.properties | 24 ++ .../WEB-INF/prop/prop2map/VmsKafka.properties | 5 + .../annotations/CusRequestClient.java | 9 + .../http_test/annotations/CusRequestUrl.java | 16 + .../annotations/body/CusRequestBody.java | 16 + .../annotations/handle/CusHandle.java | 16 + .../annotations/handle/CusPreLoadHandle.java | 23 ++ .../handle/CusReqAfterHandleRegister.java | 19 + .../handle/CusResponseSuccessHandle.java | 19 + .../request_path/CusPathQuery.java | 2 +- .../request_type/CusRequestDelete.java | 12 +- .../request_type/CusRequestGet.java | 14 +- .../request_type/CusRequestPost.java | 12 +- .../request_type/CusRequestPut.java | 12 +- .../request_type/CusRequestType.java | 16 + .../constant/CusRequestClientConstant.java | 59 ++- .../http_test/entity/CusHandleEntity.java | 16 + .../http_test/entity/CusRequestEntity.java | 21 +- .../http_test/entity/CusResponseSuccess.java | 21 + .../http_test/handle/CusHandleCenter.java | 129 +++++++ .../handle/CusRequestAfterHandle.java | 31 ++ .../handle/CusRequestBeforeHandle.java | 4 +- .../http_test/handle/CusRequestHandle.java | 42 ++ .../header_handle/RequestHeaderHandle.java | 84 ++++ .../path_handle/CusBodyParseHandle.java | 39 ++ .../path_handle/CusPathParseHandle.java | 14 +- .../handle/path_handle/TestHandle.java | 22 ++ .../CusDefaultRequestAfterHandle.java | 47 +++ .../request_handle/CusRequestGetHandle.java | 21 + .../request_handle/CusRequestPostHandle.java | 21 + .../handle/request_handle/CusUrlHandle.java | 29 ++ .../http_test/handle/util/HandleUtil.java | 179 +++++++++ .../wang/http_test/proxy/RequestUtil.java | 93 +++-- .../wang/http_test/service/TestService.java | 33 +- .../wang/http_test/test/RequestTest.java | 33 +- .../test/TestRequestAfterHandle.java | 20 + .../java/xuanran/wang/immc/Kafka/MQTest.java | 363 ++++++++++++++++++ src/test/java/xuanran/wang/mq/CusMQType.java | 17 + .../wang/mq/consumer/DefaultConsumer.java | 21 + .../xuanran/wang/mq/infaces/CusBaseMQ.java | 27 ++ .../xuanran/wang/mq/infaces/CusConsumer.java | 16 + .../xuanran/wang/mq/infaces/CusMQClient.java | 11 + .../xuanran/wang/mq/infaces/CusProducer.java | 16 + .../xuanran/wang/mq/infaces/aop/CusMQAop.java | 18 + .../mq/infaces/callback/CusMQCallBack.java | 35 ++ .../java/xuanran/wang/mq/mq/CusKafkaMQ.java | 86 +++++ .../java/xuanran/wang/mq/mq/CusMQFactory.java | 45 +++ .../java/xuanran/wang/mq/mq/CusRocketMQ.java | 146 +++++++ .../xuanran/wang/mq/mq/DefaultCusMQAop.java | 41 ++ .../java/xuanran/wang/mq/test/MQTest.java | 58 +++ .../java/xuanran/wang/mq/util/CusMQUtil.java | 53 +++ .../wang/shyl/dataasync/AsyncTest.java | 22 +- .../wang/shyl/dataasync/MapperTest.java | 40 +- 105 files changed, 4585 insertions(+), 190 deletions(-) create mode 100644 javascript/xuanran.wang/bme/js/DiaoBo.js create mode 100644 javascript/xuanran.wang/shyl/MealOrder.js create mode 100644 src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java create mode 100644 src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java create mode 100644 src/main/java/weaver/shyl/workflow/action/FileTypeFieldConvert.java create mode 100644 src/main/java/weaver/xuanran/wang/bme/action/CheckConsumerNameAction.java create mode 100644 src/main/java/weaver/xuanran/wang/immc/WorkFlowToVmsAndMQ.java create mode 100644 src/main/java/weaver/xuanran/wang/immc/cusfieldvalue/CusListValue.java create mode 100644 src/main/java/weaver/xuanran/wang/immc/entity/VmsResponseVoField.java create mode 100644 src/main/java/weaver/xuanran/wang/immc/mapper/ImMcMapper.java create mode 100644 src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusToken.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusDbEntityMapping.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/SendTodoTaskImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTaskOA.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTaskToOADetail.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/mapper/SendTodoTaskMapper.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/SendTodoTaskService.java create mode 100644 src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java create mode 100644 src/main/resources/WEB-INF/prop/prop2map/OACarTest.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties create mode 100644 src/main/resources/WEB-INF/prop/prop2map/VmsKafka.properties create mode 100644 src/test/java/xuanran/wang/http_test/annotations/CusRequestUrl.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/body/CusRequestBody.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/handle/CusHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/handle/CusPreLoadHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/handle/CusResponseSuccessHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestType.java create mode 100644 src/test/java/xuanran/wang/http_test/entity/CusHandleEntity.java create mode 100644 src/test/java/xuanran/wang/http_test/entity/CusResponseSuccess.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/CusRequestAfterHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/path_handle/CusBodyParseHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/path_handle/TestHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestGetHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestPostHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java create mode 100644 src/test/java/xuanran/wang/http_test/handle/util/HandleUtil.java create mode 100644 src/test/java/xuanran/wang/http_test/test/TestRequestAfterHandle.java create mode 100644 src/test/java/xuanran/wang/immc/Kafka/MQTest.java create mode 100644 src/test/java/xuanran/wang/mq/CusMQType.java create mode 100644 src/test/java/xuanran/wang/mq/consumer/DefaultConsumer.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/CusBaseMQ.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/CusConsumer.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/CusMQClient.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/CusProducer.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/aop/CusMQAop.java create mode 100644 src/test/java/xuanran/wang/mq/infaces/callback/CusMQCallBack.java create mode 100644 src/test/java/xuanran/wang/mq/mq/CusKafkaMQ.java create mode 100644 src/test/java/xuanran/wang/mq/mq/CusMQFactory.java create mode 100644 src/test/java/xuanran/wang/mq/mq/CusRocketMQ.java create mode 100644 src/test/java/xuanran/wang/mq/mq/DefaultCusMQAop.java create mode 100644 src/test/java/xuanran/wang/mq/test/MQTest.java create mode 100644 src/test/java/xuanran/wang/mq/util/CusMQUtil.java diff --git a/javascript/xuanran.wang/bme/js/BuildContractApply.js b/javascript/xuanran.wang/bme/js/BuildContractApply.js index c8df318..f328f1b 100644 --- a/javascript/xuanran.wang/bme/js/BuildContractApply.js +++ b/javascript/xuanran.wang/bme/js/BuildContractApply.js @@ -22,6 +22,7 @@ const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); // 需要计算的款项类型集合 const computeDatePayType = ['0']; const DETAIL_MAX_SIZE = 5; +const readOnlyArr = ['0']; // 款项类型预计对应日期取值 const paymentTypeGetValue = { 0: (index)=>{ @@ -36,7 +37,8 @@ jQuery().ready(function(){ 'detailComPayDateId': detail2ComPayDateId, 'dayId': detail2DayId, 'computeDatePayType': computeDatePayType, - 'paymentTypeGetValue': paymentTypeGetValue + 'paymentTypeGetValue': paymentTypeGetValue, + 'readOnlyArr': readOnlyArr } let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(","); @@ -49,7 +51,7 @@ jQuery().ready(function(){ addRowBack(2, configObj); - changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType) + changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, readOnlyArr) // 主表字段发生变化 mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj); diff --git a/javascript/xuanran.wang/bme/js/Common.js b/javascript/xuanran.wang/bme/js/Common.js index 5c432b3..583099e 100644 --- a/javascript/xuanran.wang/bme/js/Common.js +++ b/javascript/xuanran.wang/bme/js/Common.js @@ -60,6 +60,7 @@ function submitCallback(detailTable, detail2PayProportionId){ sum += parseFloat(WfForm.getFieldValue(field));//遍历明细行字段 } } + console.log('sum => ', sum) sum === 100.00 ? callback() : WfForm.showMessage("明细付款比例总和不等于100,请修改后提交!"); }); } @@ -118,11 +119,18 @@ function changeDetailPayDate(obj){ let computeDatePayType = obj['computeDatePayType']; // 获取主表的字符值转换函数 let paymentTypeGetValue = obj['paymentTypeGetValue']; + // 只读 + let readOnlyArr = obj['readOnlyArr']; // 款项类型 let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`); + if(readOnlyArr.includes(paymentType)){ + WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY); + }else{ + // 如果款项类型不需要计算就把预计付款日期属性改成可编辑 + WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT); + } // 先进行赋值 if(computeDatePayType.includes(paymentType)){ - WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, READ_ONLY); // 存在字段联动延时处理 setTimeout(()=>{ if(paymentTypeGetValue){ @@ -142,16 +150,14 @@ function changeDetailPayDate(obj){ value: comDate }); } - }else { - // 如果对应日期为空就给预计付款赋空值 - WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{ - value: '' - }); } + // else { + // // 如果对应日期为空就给预计付款赋空值 + // WfForm.changeFieldValue(`${detailComPayDateId}_${index}`,{ + // value: '' + // }); + // } },100); - }else{ - // 如果款项类型不需要计算就把预计付款日期属性改成可编辑 - WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT); } } diff --git a/javascript/xuanran.wang/bme/js/DiaoBo.js b/javascript/xuanran.wang/bme/js/DiaoBo.js new file mode 100644 index 0000000..a742e50 --- /dev/null +++ b/javascript/xuanran.wang/bme/js/DiaoBo.js @@ -0,0 +1,26 @@ +const zrckField = WfForm.convertFieldNameToId('zrck'); +const zcckField = WfForm.convertFieldNameToId('zcck'); +// 主表存货编码 +const mainStockSetField = WfForm.convertFieldNameToId('chbmjh'); +// 明细1存货编码字段 +const deail1StockSetField = WfForm.convertFieldNameToId('chbm','detail_1'); +jQuery(document).ready(function(){ + WfForm.triggerFieldAllLinkage(zrckField); + WfForm.triggerFieldAllLinkage(zcckField); + initStockNo(); +}); +function initStockNo(){ + var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(","); + let arr = []; + for(var i=0; i{ + WfForm.triggerFieldAllLinkage(mainStockSetField); + },500); +} \ No newline at end of file diff --git a/javascript/xuanran.wang/bme/js/PayApply.js b/javascript/xuanran.wang/bme/js/PayApply.js index fbe6238..3923e3f 100644 --- a/javascript/xuanran.wang/bme/js/PayApply.js +++ b/javascript/xuanran.wang/bme/js/PayApply.js @@ -3,30 +3,157 @@ const yjfksj = WfForm.convertFieldNameToId('yjfksj'); // 主表比例 const bl = WfForm.convertFieldNameToId('bcfkbl'); // 明细要求付款日期 -const detail3Yqfkrq = WfForm.convertFieldNameToId('yqfkrq',"detail_3"); +const detail3Yqfkrq = WfForm.convertFieldNameToId('yqfkrq', "detail_3"); // 明细本次付款比例 -const detailBl = WfForm.convertFieldNameToId('bcfkbl',"detail_3"); +const detailBl = WfForm.convertFieldNameToId('bcfkbl', "detail_3"); +// 关联订单 +const relationOrder = WfForm.convertFieldNameToId("gldd"); +// 明细4施工合同字段 +const detail4SgField = WfForm.convertFieldNameToId("sght", "detail_4"); +// 明细4采购合同字段 +const detail4CgField = WfForm.convertFieldNameToId("cght", "detail_4"); +// 明细4发票字段 +const detail4FpField = WfForm.convertFieldNameToId("fpje", "detail_4"); +// 明细4合同发票金额和 +let detail4Map = new Map(); +// 明细3施工合同字段 +const detail3SgField = WfForm.convertFieldNameToId("sght", "detail_3"); +// 明细3采购合同字段 +const detail3CgField = WfForm.convertFieldNameToId("cght", "detail_3"); +// 明细3 含税金额 +const detail3TaxField = WfForm.convertFieldNameToId("ddhsje", "detail_3"); +// 明细3以收票金额 +const detail3YspField = WfForm.convertFieldNameToId("yspje", "detail_3"); WfForm.registerCheckEvent(WfForm.OPER_ADDROW + "3", function (callback) { callback(); + setTimeout(() => { + initDeatail3Date(); + }, 5) +}); +// 关联订单变化时将明细四的合同-金额map进行初始化 +WfForm.bindFieldChangeEvent(relationOrder, function (obj, id, value) { + setTimeout(() => { + initDetail4Map(); + changeDetail3SpMoney(); + }, 2000); +}); + + +WfForm.bindFieldChangeEvent(`${yjfksj},${bl}`, function (obj, id, value) { initDeatail3Date(); }); -WfForm.bindFieldChangeEvent(`${yjfksj},${bl}`, function(obj,id,value){ - initDeatail3Date(); -}); - -function initDeatail3Date(){ - let dateVal = WfForm.getFieldValue(yjfksj); - let blVal = WfForm.getFieldValue(bl); - console.log('dateVal ', dateVal); - console.log('blVal ', blVal); +// 计算明细三开票金额 +function changeDetail3SpMoney() { let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(","); for (let i = 0; i < detail3RowArr.length; i++) { let rowIndex = detail3RowArr[i]; if (rowIndex !== "") { - WfForm.changeFieldValue(`${detail3Yqfkrq}_${rowIndex}`,{value: dateVal}); - WfForm.changeFieldValue(`${detailBl}_${rowIndex}`,{value: blVal}); + let detail3SgFieldVal = WfForm.getFieldValue(`${detail3SgField}_${rowIndex}`); + let detail3CgFieldVal = WfForm.getFieldValue(`${detail3CgField}_${rowIndex}`); + let fpje = detail4Map.get(detail3SgFieldVal) ?? detail4Map.get(detail3CgFieldVal); + let mapVal = detail4Map.get(detail3SgFieldVal); + let key = detail3SgFieldVal; + if (!mapVal) { + key = detail3CgFieldVal; + } + console.log('key ', key); + if (fpje) { + console.log('fpje => ', fpje); +// 0.1 0.3 + let detail3TaxVal = WfForm.getFieldValue(`${detail3TaxField}_${rowIndex}`); + console.log('detail3TaxVal => ', detail3TaxVal); + let tempJe = fpje - detail3TaxVal; + console.log('tempJe => ', tempJe); + if (fpje > detail3TaxVal) { + WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: detail3TaxVal}); + } else if (tempJe <= 0 && fpje == 0) { + WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0}); + } else if (tempJe < 0) { + WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: fpje}); + tempJe = 0; + } + detail4Map.set(key, tempJe); + console.log('detail4Map ', detail4Map) + } else { + WfForm.changeFieldValue(`${detail3YspField}_${rowIndex}`, {value: 0}); + } } } -} \ No newline at end of file +} + + +function initDeatail3Date() { + let dateVal = WfForm.getFieldValue(yjfksj); + let blVal = WfForm.getFieldValue(bl); + let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(","); + for (let i = 0; i < detail3RowArr.length; i++) { + let rowIndex = detail3RowArr[i]; + if (rowIndex !== "") { + WfForm.changeFieldValue(`${detail3Yqfkrq}_${rowIndex}`, {value: dateVal}); + WfForm.changeFieldValue(`${detailBl}_${rowIndex}`, {value: blVal}); + } + } +} + +function initDetail4Map() { + let detail4RowArr = WfForm.getDetailAllRowIndexStr('detail_4').split(","); + console.log('detail4RowArr ', detail4RowArr); + for (let i = 0; i < detail4RowArr.length; i++) { + let rowIndex = detail4RowArr[i]; + if (rowIndex !== "") { + let detail4SgFieldVal = WfForm.getFieldValue(`${detail4SgField}_${rowIndex}`); + let detail4CgFieldVal = WfForm.getFieldValue(`${detail4CgField}_${rowIndex}`); + let detail4FpFieldVal = WfForm.getFieldValue(`${detail4FpField}_${rowIndex}`); + let key = -1; + console.log('detail4SgFieldVal ', detail4SgFieldVal); + console.log('detail4CgFieldVal ', detail4CgFieldVal); + console.log('detail4FpFieldVal ', detail4FpFieldVal); + if (!detail4FpFieldVal) { + continue; + } + key = detail4CgFieldVal ?? detail4SgFieldVal; + console.log('key ', key); + let tempVal = parseFloat(detail4Map.get(key) ?? 0); + tempVal += parseFloat(detail4FpFieldVal); + detail4Map.set(key, tempVal); + } + } + console.log('detail4Map ', detail4Map) +} + +const detail3ApplyMoneyField = WfForm.convertFieldNameToId("bcfkje", "detail_3"); +const detail3CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_3"); +const detail3Bl = WfForm.convertFieldNameToId('bcfkbl', "detail_3"); +let detailBlMap = new Map(); +const detail1Bl = WfForm.convertFieldNameToId('fkbl', "detail_1"); +const detail1CgId = WfForm.convertFieldNameToId("cgddzbid", "detail_1"); +WfForm.bindDetailFieldChangeEvent(detail3ApplyMoneyField, (id, rowIndex, value) => { + let detail3RowArr = WfForm.getDetailAllRowIndexStr('detail_3').split(","); + detailBlMap = new Map(); + for (let i = 0; i < detail3RowArr.length; i++) { + let rowIndex = detail3RowArr[i]; + if (rowIndex !== "") { + let bl = parseFloat(WfForm.getFieldValue(`${detail3Bl}_${rowIndex}`)); + let cg = WfForm.getFieldValue(`${detail3CgId}_${rowIndex}`); + let mapVal = parseFloat(detailBlMap.get(cg) ?? 0) + bl; + detailBlMap.set(cg, mapVal); + } + } + console.log('detailBlMap ', detailBlMap) + let detail1RowArr = WfForm.getDetailAllRowIndexStr('detail_1').split(","); + for (let i = 0; i < detail1RowArr.length; i++) { + let rowIndex = detail1RowArr[i]; + if (rowIndex !== "") { + let cg = WfForm.getFieldValue(`${detail1CgId}_${rowIndex}`); + let val = detailBlMap.get(cg) === '' ? 0 : detailBlMap.get(cg); + WfForm.changeFieldValue(`${detail1Bl}_${rowIndex}`, {value: val}) + } + } +}); + + + + + diff --git a/javascript/xuanran.wang/bme/js/PurchaseContractApply.js b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js index 705e114..1e2722f 100644 --- a/javascript/xuanran.wang/bme/js/PurchaseContractApply.js +++ b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js @@ -23,6 +23,7 @@ const detailComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); // 对应日期 const detailTempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); // 需要计算的款项类型集合 +const readOnlyArr = ['0']; const computeDatePayType = ['0','2','4']; // 款项类型预计对应日期取值 const paymentTypeGetValue = { @@ -49,12 +50,13 @@ function init(){ 'detailComPayDateId': detailComPayDateId, 'dayId': detailDayId, 'computeDatePayType': computeDatePayType, - 'paymentTypeGetValue': paymentTypeGetValue + 'paymentTypeGetValue': paymentTypeGetValue, + 'readOnlyArr': readOnlyArr } addRowBack(3, obj); - changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, computeDatePayType) + changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, readOnlyArr) // 主表字段发生变化 mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj); // 明细的款项类型字段变化绑定 diff --git a/javascript/xuanran.wang/bme/js/SaleContractApply.js b/javascript/xuanran.wang/bme/js/SaleContractApply.js index eff8107..6fb1ba7 100644 --- a/javascript/xuanran.wang/bme/js/SaleContractApply.js +++ b/javascript/xuanran.wang/bme/js/SaleContractApply.js @@ -11,7 +11,7 @@ const mainWorkFlowEndId = WfForm.convertFieldNameToId("fhdgdrq"); // 主表实际验收 const mainActualCheckId = WfForm.convertFieldNameToId("sjysrq"); // 明细2付款比例字段 -const detail2PayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable); +const detail2PayProportionId = WfForm.convertFieldNameToId("skbl",detailTable); // 明细2款项类型 const detail2PaymentTypeId = WfForm.convertFieldNameToId("kxlx",detailTable); // 明细2前后字段 @@ -24,6 +24,8 @@ const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); // 需要计算的款项类型集合 const computeDatePayType = ['2', '4', '5']; +// 只读 明细款项类型 +const readOnlyArr = []; // 款项类型预计对应日期取值 const paymentTypeGetValue = { 2: (index)=>{ @@ -50,10 +52,11 @@ function init(){ 'detailComPayDateId': detail2ComPayDateId, 'dayId': detail2DayId, 'computeDatePayType': computeDatePayType, - 'paymentTypeGetValue': paymentTypeGetValue + 'paymentTypeGetValue': paymentTypeGetValue, + 'readOnlyArr': readOnlyArr } addRowBack(2, obj); - changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType) + changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, readOnlyArr); // 主表字段发生变化 mainFieldChangeDetailCom(mainProjectId, detailTable, obj); // 明细的款项类型字段变化绑定 diff --git a/javascript/xuanran.wang/shyl/MealOrder.js b/javascript/xuanran.wang/shyl/MealOrder.js new file mode 100644 index 0000000..aca382b --- /dev/null +++ b/javascript/xuanran.wang/shyl/MealOrder.js @@ -0,0 +1,45 @@ +const enable = 0; +// 班级浏览按钮表单字段id +const classFieldId = WfForm.convertFieldNameToId("bjmc"); +// 明细1学员id +const detail1StuId = WfForm.convertFieldNameToId("studentId","detail_1");; +// 明细1学员编号 +const detail1StuNo = WfForm.convertFieldNameToId("studentNo","detail_1");; +// 明细1学员姓名 +const detail1StuName = WfForm.convertFieldNameToId("studentName","detail_1");; +// 明细1班级id +const detail1ClassId = WfForm.convertFieldNameToId("classId","detail_1"); +// 主表学员汇总字段 +const stuAllField = WfForm.convertFieldNameToId("mxxybhhzfz"); +WfForm.bindFieldChangeEvent(classFieldId, function(obj,id,value){ + let classId = WfForm.getBrowserShowName(classFieldId); + WfForm.delDetailRow("detail_1", "all"); + $.get('/api/wxr/students/getStudentsByClassId',{id:classId},(res)=>{ + let obj = JSON.parse(res); + if(obj.code != 200){ + WfForm.showMessage(obj.msg); + return; + } + console.log('obj ', obj); + let objData = obj.data; + let responseObj = JSON.parse(objData); + if(!responseObj || !responseObj.data){ + WfForm.showMessage(responseObj.msg); + return; + } + objData = responseObj.data; + WfForm.changeFieldValue(stuAllField, {value: ''}); + let stuArr = []; + objData.forEach((item)=>{ + let detailObj = {}; + detailObj[detail1StuId] = { value: item.id }; + detailObj[detail1StuNo] = { value: item.studentNo }; + detailObj[detail1StuName] = { value: item.studentName }; + detailObj[detail1ClassId] = { value: item.classId }; + // console.log('detailObj ', detailObj) + WfForm.addDetailRow("detail_1",detailObj); + stuArr.push(item.studentNo); + }) + WfForm.changeFieldValue(stuAllField, {value: stuArr.join(',')}); + }) +}); \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5b8411e..7267c9b 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,12 @@ 4.4.0 + + org.apache.kafka + kafka-clients + 2.3.1 + + cn.afterturn easypoi-base diff --git a/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java b/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java index 3c0791d..94abd03 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java +++ b/src/main/java/com/api/xuanran/wang/shyl/controller/BatchCreateWorkFlowController.java @@ -6,8 +6,6 @@ import aiyh.utils.excention.CustomerException; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.api.xuanran.wang.shyl.service.BatchCreateWorkflowService; -import com.api.xuanran.wang.shyl.service.MeetingService; -import com.api.xuanran.wang.shyl.vo.CreateWfVO; import com.engine.common.util.ServiceUtil; import com.engine.workflow.publicApi.WorkflowRequestOperatePA; import com.engine.workflow.publicApi.impl.WorkflowRequestOperatePAImpl; @@ -16,7 +14,6 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.hrm.User; -import weaver.xuanran.wang.common.mapper.CommonMapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -26,7 +23,6 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import java.util.List; /** *

上海团校-批量创建流程接口

diff --git a/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java b/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java new file mode 100644 index 0000000..a0b5f89 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/shyl/controller/UserUpdateToMQController.java @@ -0,0 +1,54 @@ +package com.api.xuanran.wang.shyl.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.api.xuanran.wang.shyl.service.UserUpdateToMQService; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +/** + *

用户信息更新将数据发送到队列中

+ * + * @author xuanran.wang + * @date 2023/3/20 17:15 + */ +@Path("/wxr/user_mq") +public class UserUpdateToMQController { + private final Logger log = Util.getLogger(); + private final UserUpdateToMQService userUpdateToMQService = new UserUpdateToMQService(); + /** + *

用户信息更新

+ * @author xuanran.wang + * @dateTime 2023/3/1 15:24 + **/ + @Path("/update") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String updateUserInfoToMQ(@Context HttpServletRequest request, + @Context HttpServletResponse response){ + try { + String id = Util.null2DefaultStr(request.getParameter("id"),""); + String onlyMark = Util.null2DefaultStr(request.getParameter("onlyMark"),""); + String configName = Util.null2DefaultStr(request.getParameter("configName"),""); + String debug = Util.null2DefaultStr(request.getParameter("debug"),""); + if(StringUtils.isBlank(id) || StringUtils.isBlank(onlyMark) || StringUtils.isBlank(configName)){ + throw new CustomerException("update user to mq id or onlyMark or configName can not null!"); + } + userUpdateToMQService.toMQ(id, onlyMark, configName, debug); + return ApiResult.success(null); + }catch (Exception e){ + log.error(Util.logStr("MeetingController error ! {}", e.getMessage())); + return ApiResult.error(500,"会议取消接口发生异常! 异常信息 :[ " + e.getMessage() + " ]"); + } + + } +} diff --git a/src/main/java/com/api/xuanran/wang/shyl/mapper/ProducerMapper.java b/src/main/java/com/api/xuanran/wang/shyl/mapper/ProducerMapper.java index 3b7da0c..7d0715b 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/mapper/ProducerMapper.java +++ b/src/main/java/com/api/xuanran/wang/shyl/mapper/ProducerMapper.java @@ -5,7 +5,7 @@ import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; import com.api.xuanran.wang.shyl.entity.ProducerCarInfo; -import java.util.HashMap; +import java.util.Map; /** *

生产者mapper

@@ -15,6 +15,13 @@ import java.util.HashMap; */ @SqlMapper public interface ProducerMapper { + /** + *

通过车辆ID查信息

+ * @author xuanran.wang + * @dateTime 2023/3/20 17:26 + * @param id 车辆id + * @return 车辆实体 + **/ @Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " + "b.telephone userPhone, carNo plateList, remark " + "from carinfo a " + @@ -23,6 +30,13 @@ public interface ProducerMapper { "where a.id = #{id}") ProducerCarInfo queryCarInfo(@ParamMapper("id") String id); + /** + *

通过车排号查信息

+ * @author xuanran.wang + * @dateTime 2023/3/20 17:27 + * @param carNo 车牌号 + * @return 车辆实体 + **/ @Select("select a.id carCode, Deposit status,b.outkey driver, b.lastname userName, " + "b.telephone userPhone, carNo plateList, remark " + "from carinfo a " + @@ -30,4 +44,14 @@ public interface ProducerMapper { "on a.driver = b.id " + "where a.carNo = #{carNo}") ProducerCarInfo queryCarNo(@ParamMapper("carNo") String carNo); + + /** + *

根据人员ID查询信息

+ * @author xuanran.wang + * @dateTime 2023/3/20 17:27 + * @param id 人员ID + * @return 人员信息 + **/ + @Select("select * from hrmresource where id = #{id}") + Map queryUserInfo(@ParamMapper("id") String id); } diff --git a/src/main/java/com/api/xuanran/wang/shyl/service/CarService.java b/src/main/java/com/api/xuanran/wang/shyl/service/CarService.java index c4205ec..fd73005 100644 --- a/src/main/java/com/api/xuanran/wang/shyl/service/CarService.java +++ b/src/main/java/com/api/xuanran/wang/shyl/service/CarService.java @@ -81,6 +81,10 @@ public class CarService { carNo = Util.null2DefaultStr(request.getParameter("carNo"),""); info = producerMapper.queryCarNo(carNo); } + + //add by taojw +// String plateList = info.getPlateList(); + // 如果能找到就说明是更新或者新增 if("del".equals(operation)){ //删除状态下 info = new ProducerCarInfo(); @@ -88,6 +92,7 @@ public class CarService { info.setStatus("1"); info.setRemark(""); info.setDriver(""); + //edit by taojw info.setPlateList(""); info.setUserName(""); info.setUserPhone(""); diff --git a/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java b/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java new file mode 100644 index 0000000..c19c2dc --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/shyl/service/UserUpdateToMQService.java @@ -0,0 +1,57 @@ +package com.api.xuanran.wang.shyl.service; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import com.api.xuanran.wang.shyl.mapper.ProducerMapper; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.xuanran.wang.shyl_mq.util.RocketConsumerUtil; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + *

用户信息更新将数据发送到队列业务方法

+ * + * @author xuanran.wang + * @date 2023/3/20 17:18 + */ +public class UserUpdateToMQService { + + private final Logger logger = Util.getLogger(); + + private final DealWithMapping dealWithMapping = new DealWithMapping(); + + private final ProducerMapper producerMapper = Util.getMapper(ProducerMapper.class); + + private static final String HRM_TABLE = "hrmresource"; + + + public void toMQ(String id, + String onlyMark, + String configName, + String debug){ + Map userMap = producerMapper.queryUserInfo(id); + if(MapUtils.isEmpty(userMap)){ + logger.error(Util.logStr("userId: {}, userInfo is empty!")); + return; + } + RequestMappingConfig config = dealWithMapping.treeDealWithUniqueCode(onlyMark); + dealWithMapping.setMainTable(HRM_TABLE); + Map param = dealWithMapping.getRequestParam(userMap, config); + if(MapUtils.isEmpty(param)){ + logger.error(Util.logStr("userId:{}, 生成json为空!",id)); + return; + } + if(StringUtils.isNotBlank(debug)){ + logger.info("update user json : \n" + JSONObject.toJSONString(param)); + return; + } + RocketConsumerUtil.producerSendMsg(configName, JSONObject.toJSONString(param), id); + } +} diff --git a/src/main/java/weaver/shyl/workflow/action/FileTypeFieldConvert.java b/src/main/java/weaver/shyl/workflow/action/FileTypeFieldConvert.java new file mode 100644 index 0000000..5e3a293 --- /dev/null +++ b/src/main/java/weaver/shyl/workflow/action/FileTypeFieldConvert.java @@ -0,0 +1,70 @@ +package weaver.shyl.workflow.action; + +import aiyh.utils.Util; +import aiyh.utils.entity.DocImageInfo; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.file.ImageFileManager; +import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.Base64; +import java.util.Map; +/** + *

团校-流程中字段图片附件转成base64

+ * + * @author xuanran.wang + * @date 2023/3/27 22:41 + */ +public class FileTypeFieldConvert implements CusInterfaceGetValue { + + private final Logger log = Util.getLogger(); + + /** + * 获取参数值 + * + * @param mainMap 主表数据 + * @param detailMap 明细表数据 + * @param currentValue 当前字段值 + * @param pathParam 路径参数 + * @return 最终返回参数 + */ + @Override + public Object execute(Map mainMap, Map detailMap, String currentValue, Map pathParam) { + try { + log.info("原文件图片ID:[" + currentValue + "]"); + log.info("pathParam : " + JSONObject.toJSONString(pathParam)); + int tempId = Util.getIntValue(currentValue, -1); + if(!"".equals(currentValue) && tempId > 0 && !currentValue.contains(",")) { + String imageFileId = Util.null2DefaultStr(pathParam.get("imageFileId"),""); + InputStream inputStream; + if (StringUtils.isBlank(imageFileId)) { + DocImageInfo docImageInfo = Util.selectImageInfoByDocId(currentValue); + inputStream = ImageFileManager.getInputStreamById(docImageInfo.getImageFileId()); + }else { + int fileId = Util.getIntValue(currentValue, -1); + if(fileId < 0){ + throw new CustomerException("image file id < 0"); + } + inputStream = ImageFileManager.getInputStreamById(fileId); + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + byte[] bytes = outputStream.toByteArray(); + return Base64.getEncoder().encodeToString(bytes); + } + } catch (Exception e) { + log.error("convert file to base64 fail!" + e.getMessage() + "\n" + Util.getErrString(e)); + throw new CustomerException("convert file to base64 fail!"); + } + return null; + } +} + diff --git a/src/main/java/weaver/xuanran/wang/bme/action/CheckConsumerNameAction.java b/src/main/java/weaver/xuanran/wang/bme/action/CheckConsumerNameAction.java new file mode 100644 index 0000000..9adc14c --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/bme/action/CheckConsumerNameAction.java @@ -0,0 +1,49 @@ +package weaver.xuanran.wang.bme.action; + +import aiyh.utils.Util; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.RequestInfo; +import weaver.workflow.request.RequestManager; + +/** + *

校验客户名称

+ * + * @author xuanran.wang + * @date 2023/4/6 09:51 + */ +public class CheckConsumerNameAction implements Action { + private final Logger log = Util.getLogger(); + private String wfConsumerField; + private String modelConsumerField; + private String modelName; + + @Override + public String execute(RequestInfo request) { + String requestId = request.getRequestid(); + String tableName = request.getRequestManager().getBillTableName(); + RecordSet rs = new RecordSet(); + + wfConsumerField = Util.null2DefaultStr(wfConsumerField, "khmc"); + modelConsumerField = Util.null2DefaultStr(modelConsumerField, "khmc"); + modelName = Util.null2DefaultStr(modelName, "uf_kh"); + + RequestManager requestManager = request.getRequestManager(); + rs.executeQuery("select * from " + tableName + " where requestid = ?", requestId); + rs.next(); + String wfConsumer = rs.getString(wfConsumerField); + log.info("wfConsumer : [ " + wfConsumer + " ]"); + if(StringUtils.isNotBlank(wfConsumer)){ + String sql = "select id from " + modelName + " where " + modelConsumerField + " = ?"; + log.info("sql : " + sql + " ,参数: " + wfConsumer); + if (rs.executeQuery(sql, wfConsumer) && rs.next()) { + requestManager.setMessageid(System.currentTimeMillis() + ""); + requestManager.setMessagecontent("当前客户名称: " + wfConsumer + " ,在客户表中已经存在请修改后提交!"); + return Action.FAILURE_AND_CONTINUE; + } + } + return Action.SUCCESS; + } +} diff --git a/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java b/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java index 55478d3..a58c672 100644 --- a/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java +++ b/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java @@ -68,6 +68,7 @@ public class ContractApplyComDateAction implements Action { *

明细前后字段

**/ @RequiredMark + @PrintParamMark private String beforeBackField; /** @@ -124,6 +125,7 @@ public class ContractApplyComDateAction implements Action { log.error(Util.logStr("checkDate:{}, project:{}", checkDate, project)); throw new CustomerException("实际验收日期或项目字段字段为空!"); } + // select a.id,a.requestid from formtable_main_58 a right join uf_cgdd b on a.htbh = b.lcbh where b.id = String selectSql = "select id,requestid from " + buildContractTable + " where " + buildContractProjectField + " = ?"; if(StringUtils.isNotBlank(relationSql)){ selectSql = relationSql; @@ -159,16 +161,15 @@ public class ContractApplyComDateAction implements Action { params.add(param); log.info(Util.logStr("关联流程requestId: {}, 流程明细前后字段: {}, 天数: {}, 计算后的日期: {}",tempRequestId, beforeBack, day, computeDate)); } - } - if(CollectionUtils.isNotEmpty(params)){ - if(!rs.executeBatchSql(updateSql,params)){ - log.error(Util.logStr("更新sql : {}, 参数 : {}", updateSql, params)); - throw new CustomerException("更新合同sql错误!"); + if(CollectionUtils.isNotEmpty(params)){ + if(!rs.executeBatchSql(updateSql,params)){ + log.error(Util.logStr("更新sql : {}, 参数 : {}", updateSql, params)); + throw new CustomerException("更新合同sql错误!"); + } + }else { + log.error(Util.logStr("明细表: {}不存在数据!", detailContractTable)); } - }else { - log.error(Util.logStr("明细表: {}不存在数据!", detailContractTable)); } - }else{ log.error(Util.logStr("查询关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId)); } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java index 0496f10..53df958 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java @@ -150,13 +150,15 @@ public class CusInfoToOAUtil { * @dateTime 2023/2/9 11:51 * @param modelId 模块id * @param list 插入参数集合 - * @param whereSql 更新条件 + * @param whereSql 更新条件sql * @return 建模数据id **/ public static List executeBatchByEntity(int modelId, List list, String whereSql){ String tableName = checkModelId(modelId); List> params = new ArrayList<>(); List> whereParams = new ArrayList<>(); + StringBuilder whereSqlSb; + LinkedHashSet whereFields = new LinkedHashSet<>(); for (Object o : list) { if(Objects.isNull(o)){ continue; @@ -165,7 +167,14 @@ public class CusInfoToOAUtil { Field[] fields = clazz.getDeclaredFields(); LinkedHashMap linkedHashMap = new LinkedHashMap<>(); ArrayList whereParam = new ArrayList<>(); - for (Field field : fields) { + List fieldArr = Arrays.stream(fields).collect(Collectors.toList()); + Class superclass = clazz.getSuperclass(); + // 找出父类所有的字段 + while (superclass != null){ + fieldArr.addAll(Arrays.stream(superclass.getDeclaredFields()).collect(Collectors.toList())); + superclass = superclass.getSuperclass(); + } + for (Field field : fieldArr) { field.setAccessible(true); String fieldName = field.getName(); Object fieldValue; @@ -194,14 +203,25 @@ public class CusInfoToOAUtil { if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){ continue; } + if(StringUtils.isBlank(whereSql)){ + whereFields.add(fieldName + " = ?"); + } whereParam.add(fieldValue.toString()); } params.add(linkedHashMap); whereParams.add(whereParam); } + if(!whereFields.isEmpty()){ + whereSqlSb = new StringBuilder("select id from #{tableName} where "); + for (String field : whereFields) { + whereSqlSb.append(field).append(" and "); + } + whereSql = whereSqlSb.substring(0, whereSqlSb.length() - 4); + } return executeBatch(modelId, tableName, params, whereSql, whereParams, true, new ArrayList<>()); } + /** *

将自定义信息写入建模

* @author xuanran.wang diff --git a/src/main/java/weaver/xuanran/wang/immc/WorkFlowToVmsAndMQ.java b/src/main/java/weaver/xuanran/wang/immc/WorkFlowToVmsAndMQ.java new file mode 100644 index 0000000..0246fb8 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/immc/WorkFlowToVmsAndMQ.java @@ -0,0 +1,64 @@ +package weaver.xuanran.wang.immc; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.ActionOptionalParam; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.immc.entity.VmsResponseVoField; +import weaver.xuanran.wang.immc.service.WorkFlowToVmsAndMQService; + +/** + *

智己 将流程数据推送到接口/kafka队列中

+ * + * @author xuanran.wang + * @date 2023/3/30 11:21 + */ +@ActionDesc(value = "智己 将流程数据推送到接口/kafka队列中", author = "xuanran.wang") +public class WorkFlowToVmsAndMQ extends SafeCusBaseAction { + + private final WorkFlowToVmsAndMQService workFlowToVmsAndMQService = new WorkFlowToVmsAndMQService(); + /** + *

+ * OA-uat + * 用户密码 + * oa_uat_user/los0cp6aiV1iO1e2 + * Topic + * oa_service_immc_topic_uat + * 接入点 + * 10.184.42.41:9094,10.184.42.42:9094,10.184.42.40:9094 + *

+ **/ + @PrintParamMark + @ActionOptionalParam(value = "", desc = "kafka配置文件名称") + private String kafkaConfig; + + @PrintParamMark + @RequiredMark("建模配置文件唯一标识") + private String onlyMark; + + @PrintParamMark + @ActionOptionalParam(value = "code", desc = "接口成功标识字段") + private String successField; + @PrintParamMark + @ActionOptionalParam(value = "200", desc = "接口成功标识默认200") + private String successVal; + @PrintParamMark + @ActionOptionalParam(value = "message", desc = "报错返回信息字段") + private String msg; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + log.info("-------------- " + requestId + " begin --------------"); + VmsResponseVoField vmsResponseVoField = VmsResponseVoField + .builder() + .successField(Util.null2DefaultStr(successField, "code")) + .successVal(Util.null2DefaultStr(successVal, "200")) + .message(Util.null2DefaultStr(msg, "message")) + .build(); + workFlowToVmsAndMQService.workFlowToVmsAndMQ(onlyMark, billTable, requestId, vmsResponseVoField, kafkaConfig); + } +} diff --git a/src/main/java/weaver/xuanran/wang/immc/cusfieldvalue/CusListValue.java b/src/main/java/weaver/xuanran/wang/immc/cusfieldvalue/CusListValue.java new file mode 100644 index 0000000..44faeeb --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/immc/cusfieldvalue/CusListValue.java @@ -0,0 +1,50 @@ +package weaver.xuanran.wang.immc.cusfieldvalue; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; +import weaver.xiao.commons.config.interfacies.CusInterfaceListValue; +import weaver.xuanran.wang.immc.mapper.ImMcMapper; + +import java.util.*; + +/** + *

附件集合

+ * + * @author xuanran.wang + * @date 2023/3/30 15:11 + */ +public class CusListValue implements CusInterfaceGetValue { + + private final Logger log = Util.getLogger(); + private final ImMcMapper mapper = Util.getMapper(ImMcMapper.class); + + @Override + public Object execute(Map mainMap, Map detailMap, String currentValue, Map pathParam) { + List list = new ArrayList<>(); + log.info("pathParam : \n" + JSONObject.toJSONString(pathParam)); + String attachmentField = Util.null2DefaultStr(pathParam.get("attachmentField"), ""); + String cusSql = Util.null2DefaultStr(pathParam.get("cusSql"), ""); + if(StringUtils.isNotBlank(cusSql)){ + String docIds = ""; + if (StringUtils.isNotBlank(attachmentField)) { + List attachment = new ArrayList<>(); + for (String item : attachmentField.split(",")) { + String filedValue = Util.null2DefaultStr(mainMap.get(item),""); + if(StringUtils.isNotBlank(Util.null2DefaultStr(mainMap.get(item),""))){ + attachment.add(filedValue); + } + } + docIds = StringUtils.join(attachment, ","); + } + cusSql = cusSql + .replace("{?docIds}", "( " + docIds + " )") + .replace("{?requestid}",Util.null2DefaultStr(mainMap.get("requestid"),"")); + List> attachmentInfo = mapper.getAttachmentInfo(cusSql); + list.addAll(attachmentInfo); + } + return list; + } +} diff --git a/src/main/java/weaver/xuanran/wang/immc/entity/VmsResponseVoField.java b/src/main/java/weaver/xuanran/wang/immc/entity/VmsResponseVoField.java new file mode 100644 index 0000000..7ccab43 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/immc/entity/VmsResponseVoField.java @@ -0,0 +1,23 @@ +package weaver.xuanran.wang.immc.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.kie.api.definition.rule.All; + +/** + *

vms响应对象

+ * + * @author xuanran.wang + * @date 2023/3/30 14:23 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class VmsResponseVoField { + private String successField; + private String successVal; + private String message; +} diff --git a/src/main/java/weaver/xuanran/wang/immc/mapper/ImMcMapper.java b/src/main/java/weaver/xuanran/wang/immc/mapper/ImMcMapper.java new file mode 100644 index 0000000..12b3bfc --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/immc/mapper/ImMcMapper.java @@ -0,0 +1,20 @@ +package weaver.xuanran.wang.immc.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import aiyh.utils.annotation.recordset.SqlString; + +import java.util.List; +import java.util.Map; + +/** + *

dao

+ * + * @author xuanran.wang + * @date 2023/3/30 15:27 + */ +@SqlMapper +public interface ImMcMapper { + @Select(custom = true) + List> getAttachmentInfo(@SqlString String sql); +} diff --git a/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java b/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java new file mode 100644 index 0000000..84d08ef --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/immc/service/WorkFlowToVmsAndMQService.java @@ -0,0 +1,165 @@ +package weaver.xuanran.wang.immc.service; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.xuanran.wang.common.util.CommonUtil; +import weaver.xuanran.wang.immc.entity.VmsResponseVoField; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.Map; + +/** + *

vms业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/1 10:58 + */ +public class WorkFlowToVmsAndMQService { + private static final int SUCCESS_CODE = 200; + private final DealWithMapping dealWithMapping = new DealWithMapping(); + private final Logger log = Util.getLogger(); // 获取日志对象 + private final HttpUtils httpUtils = new HttpUtils(); + // 表单字段 + private static final String MQ_SUCCESS = "mq_success"; + // 表单字段 + private static final String VMS_SUCCESS = "vms_success"; + private static final String SUCCESS = "0"; + { + httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 + } + + + /** + *

推送数据

+ * + * @param onlyMark 唯一编码 + * @param billTable 表名 + * @param requestId 请求id + * @param vmsResponseVoField vms成功标识 + * @param config kafka配置文件名称 + * @author xuanran.wang + * @dateTime 2022/12/5 17:05 + **/ + public void workFlowToVmsAndMQ(String onlyMark, String billTable, String requestId, VmsResponseVoField vmsResponseVoField, String config) { + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); // 将配置参数通过唯一标识查询处理成树形结构 + String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, billTable); + log.info(Util.logStr("查询主表数据sql : {}, requestId : {}", selectMainSql, requestId)); + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(selectMainSql, requestId); + recordSet.next(); + String url = requestMappingConfig.getRequestUrl(); + dealWithMapping.setMainTable(billTable); + Map param = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + String vmsSuccess = Util.null2DefaultStr(recordSet.getString(VMS_SUCCESS),""); + String mqSuccess = Util.null2DefaultStr(recordSet.getString(MQ_SUCCESS),""); + if(!SUCCESS.equals(vmsSuccess)){ + ResponeVo responeVo; + try { + responeVo = httpUtils.apiPost(url, param); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + parseResponseVo(responeVo, url, param, vmsResponseVoField); + updateWorkFlow(VMS_SUCCESS, billTable, requestId); + } + if(!SUCCESS.equals(mqSuccess) && StringUtils.isNotBlank(config)){ + sendToMQ(config, param); + updateWorkFlow(MQ_SUCCESS, billTable, requestId); + } + } + + /** + *

解析响应对象

+ * @author xuanran.wang + * @dateTime 2022/12/23 11:25 + * @param responseVo 响应对象 + * @param url 地址 + * @param requestParam 请求 + **/ + private void parseResponseVo(ResponeVo responseVo, String url, Map requestParam, VmsResponseVoField vmsResponseVoField){ + if (responseVo.getCode() != SUCCESS_CODE) { // 相应状态码 + log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", url, JSON.toJSON(requestParam), JSON.toJSONString(httpUtils.getGlobalCache().header), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + log.info(Util.logStr("vmsResponseVoField: {}", JSONObject.toJSONString(vmsResponseVoField))); + Map response = responseVo.getResponseMap(); // 根据相应结果转化为map集合 + String successCode = Util.null2DefaultStr(response.get(vmsResponseVoField.getSuccessField()), ""); + if (!vmsResponseVoField.getSuccessVal().equals(successCode)) { + throw new CustomerException(Util.logStr("接口响应码不为 : [{}],接口响应信息: {}", successCode, Util.null2DefaultStr(response.get(vmsResponseVoField.getMessage()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + } + + /** + *

将流程信息发送到kafka

+ * @author xuanran.wang + * @dateTime 2023/3/30 14:56 + * @param kafkaConfig kafka配置文件名称 + * @param message 消息对象 + **/ + public void sendToMQ(String kafkaConfig, Map message){ + KafkaProducer producer = null; + try { + Map configMap = Util.getProperties2Map(kafkaConfig); + if(MapUtils.isEmpty(configMap)){ + throw new CustomerException("please check /web-inf/prop2map has " + kafkaConfig + ".properties"); + } + log.info("kafkaConfig : " + JSONObject.toJSONString(configMap)); + String topic = Util.null2DefaultStr(configMap.get("topic"),""); + if(StringUtils.isBlank(topic)){ + throw new CustomerException("kafka properties topic can not null!"); + } + producer = new KafkaProducer<>(configMap); + // 发送消息到指定主题 + ProducerRecord record = new ProducerRecord<>(topic, JSONObject.toJSONString(message)); + try { + RecordMetadata recordMetadata = producer.send(record).get(); + log.info(Util.logStr("send mq recordMetadata: {}", JSONObject.toJSONString(recordMetadata))); + }catch (Exception e){ + throw new CustomerException(Util.logStr("producer send error: {}!", e.getMessage())); + } + }catch (Exception e){ + throw new CustomerException(Util.logStr("send to kafka error!: {}", e.getMessage())); + }finally { + // 关闭Kafka生产者实例 + if(producer != null){ + producer.close(); + } + } + } + + /** + *

更新流程sql

+ * @author xuanran.wang + * @dateTime 2023/3/30 19:18 + * @param field 主表字段 + * @param tableName 表名 + * @param requestId 请求id + **/ + public void updateWorkFlow(String field, String tableName, String requestId){ + String updateSQL = "update " + tableName + " set " + field + " = " + SUCCESS + " where requestid = ?"; + RecordSet recordSet = new RecordSet(); + if(!recordSet.executeUpdate(updateSQL, requestId)){ + log.error(Util.logStr("update field error! sql: {}, requestId: {}", updateSQL, requestId)); + throw new CustomerException("更新表单字段失败!"); + } + } +} + + diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java new file mode 100644 index 0000000..75622c5 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusSuccess.java @@ -0,0 +1,26 @@ +package weaver.xuanran.wang.sh_bigdata.common.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.function.Consumer; + +/** + *

自定义请求条件

+ * + * @author xuanran.wang + * @date 2023/4/6 19:34 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CusSuccess { + private String successField; + private int successValue; + private String errorMsg; + private String dataKey; + private Object response; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusToken.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusToken.java new file mode 100644 index 0000000..1c13a1d --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/entity/CusToken.java @@ -0,0 +1,25 @@ +package weaver.xuanran.wang.sh_bigdata.common.entity; + +import lombok.Data; + +/** + *

token实体类

+ * + * @author xuanran.wang + * @date 2023/4/7 23:29 + */ +@Data +public class CusToken { + /** + *

token

+ **/ + private String access_token; + /** + *

有效时间(s)

+ **/ + private long expires_in; + /** + *

过期时间戳

+ **/ + private long expiryTime; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java new file mode 100644 index 0000000..b638132 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java @@ -0,0 +1,74 @@ +package weaver.xuanran.wang.sh_bigdata.common.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; + +import java.io.IOException; +import java.util.Map; + +/** + *

请求模版方法

+ * + * @author xuanran.wang + * @date 2023/4/4 11:51 + */ +public class RequestMasterPlate{ + private final Logger log = Util.getLogger(); + private final HttpUtils httpUtils = new HttpUtils(); + private static final int HTTP_SUCCESS_CODE = 200; + + public T apiGet(String url, Map params, Map headers, CusSuccess cusSuccess){ + ResponeVo responeVo; + try { + responeVo = httpUtils.apiGet(url, params, headers); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + return parseResponse(url, responeVo, params, cusSuccess); + } + + public T apiPost(String url, Object o, Map headers, CusSuccess cusSuccess){ + ResponeVo responeVo; + try { + responeVo = httpUtils.apiPostObject(url, o, headers); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + return parseResponse(url, responeVo, o, cusSuccess); + } + + public T parseResponse(String url, ResponeVo responseVo, Object o, CusSuccess cusSuccess){ + if (responseVo.getCode() != HTTP_SUCCESS_CODE) { // 相应状态码 + log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", url, JSON.toJSON(o), JSON.toJSONString(httpUtils.getGlobalCache().header), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + Map response = responseVo.getResponseMap(); // 根据相应结果转化为map集合 + cusSuccess.setResponse(response); + int responseValue = Util.getIntValue(Util.null2DefaultStr(response.get(cusSuccess.getSuccessField()), ""),-1); + if (cusSuccess.getSuccessValue() != responseValue) { + throw new CustomerException(Util.logStr("接口响应码不为: [{}], 接口响应信息: {}", cusSuccess.getSuccessValue(), Util.null2DefaultStr(response.get(cusSuccess.getErrorMsg()), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + 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]); + } + + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java new file mode 100644 index 0000000..6810040 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/SendTodoTaskUtil.java @@ -0,0 +1,167 @@ +package weaver.xuanran.wang.sh_bigdata.common.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.workflow.request.todo.RequestStatusObj; +import weaver.xuanran.wang.common.mapper.CommonMapper; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTask; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTask; +import weaver.xuanran.wang.sh_bigdata.task_async.mapper.SendTodoTaskMapper; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/6 16:47 + */ +@Data +public class SendTodoTaskUtil { + private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class); + private final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + private String appId; + private String oaAddress; + private Logger log = Util.getLogger(); + + { + oaAddress = getOAAddress(); + } + + /** + *

将待办/已办集合进行去重

+ * @author xuanran.wang + * @dateTime 2023/4/6 17:01 + * @param list 待办/已办集合 + * @return 去重后的数据 + **/ + public List distantList(List list){ + if(CollectionUtils.isEmpty(list)){ + return new ArrayList<>(); + } + HashMap obj = new HashMap<>(); + for (RequestStatusObj statusObj : list) { + String str = statusObj.getRequestid() + "" + statusObj.getUser().getUID(); + if(obj.containsKey(str)){ + continue; + } + obj.put(str, statusObj); + } + return new ArrayList<>(obj.values()); + } + + /** + *

将oa任务对象转换成三方系统任务对象

+ * @author xuanran.wang + * @dateTime 2023/4/6 17:29 + * @param objs 任务对象 + * @return 三方系统任务接收对象 + **/ + public List getTodoTaskInfo(List objs){ + ArrayList res = new ArrayList<>(); + for (RequestStatusObj obj : objs) { + String taskId = getTaskId(0, obj); + CusTodoTask todoTask = new CusTodoTask(); + int requestId = obj.getRequestid(); + int userId = obj.getUser().getUID(); + todoTask.setTaskNum(taskId); + todoTask.setAppId(appId); + todoTask.setTaskName(obj.getRequestnamenew()); + todoTask.setTaskDesc(obj.getRequestnamenew()); + todoTask.setLinkUrl(oaAddress + "/spa/workflow/static4form/index.html?#/main/workflow/req?requestid="+requestId); + todoTask.setMobileLinkUrl(oaAddress + "/spa/workflow/static4mobileform/index.html?#/req?requestid="+requestId); + todoTask.setSender(getConvertHrm(0, obj, obj.getCreator().getUID() + "")); + todoTask.setReceiver(getConvertHrm(1, obj,userId + "")); + res.add(todoTask); + } + return res; + } + + /** + *

将oa任务对象转换成三方系统任务对象

+ * @author xuanran.wang + * @dateTime 2023/4/6 17:29 + * @param objs 任务对象 + * @return 三方系统任务接收对象 + **/ + public List getDoneTaskInfo(List objs){ + ArrayList res = new ArrayList<>(); + for (RequestStatusObj obj : objs) { + String taskId = getTaskId(1, obj); + List list = mapper.queryUnSendTodoTaskList(taskId); + for (String num : list) { + CusDoneTask doneTask = new CusDoneTask(); + doneTask.setTaskNum(num); + doneTask.setStatus(1); + doneTask.setAppId(appId); + res.add(doneTask); + } + } + return res; + } + + /** + *

获取任务id

+ * @author xuanran.wang + * @dateTime 2023/4/9 17:25 + * @param type 任务类型 0:待办 1:已办 + * @param obj 任务对象 + * @return 任务ID + **/ + public String getTaskId(int type, RequestStatusObj obj){ + String taskId = obj.getRequestid() + "" + obj.getUser().getUID(); + if(type == 0){ + taskId += (System.currentTimeMillis() / 1000); + } + return taskId; + } + + /** + *

获取转换后的人员id

+ * @author xuanran.wang + * @dateTime 2023/4/6 16:55 + * @param type 类型 0:发送人 1:接收人 + * @param obj 任务对象 + * @param hrmId 人力资源ID + * @return 转换后的人员id + **/ + public String getConvertHrm(int type, RequestStatusObj obj, String hrmId){ + String convertSql; + if(type == 0){ + convertSql = Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("hrmSenderConvertRuleSql"),""); + }else { + convertSql = Util.null2DefaultStr(ShBigDataUtil.getPropertiesValByKey("hrmReceiveConvertRuleSql"),""); + } + if(StringUtils.isNotBlank(convertSql) && StringUtils.isNotBlank(hrmId)){ + List ids = Arrays.stream(hrmId.split(",")).collect(Collectors.toList()); + int requestId = obj.getRequestid(); + convertSql = convertSql + .replace("{?.requestId}", requestId + "") + .replace("{?.nodeId}",obj.getNodeid() + ""); + return Util.null2DefaultStr(StringUtils.join(mapper.selectHrmConvertId(convertSql, ids), ","),hrmId + ""); + } + return hrmId + ""; + } + + /** + *

获取oa地址

+ * @author xuanran.wang + * @dateTime 2022/12/22 13:51 + * @return OA地址 + **/ + public String getOAAddress(){ + String address = mapper.queryOAAddress(); + if(StringUtils.isBlank(address)){ + throw new CustomerException("OAAddress can not null!"); + } + return address; + } + + +} 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 new file mode 100644 index 0000000..5688afc --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/ShBigDataUtil.java @@ -0,0 +1,120 @@ +package weaver.xuanran.wang.sh_bigdata.common.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping; + +import java.lang.reflect.Field; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

上海大数据中心工具方法

+ * + * @author xuanran.wang + * @date 2023/4/4 11:34 + */ +public class ShBigDataUtil { + + private static final String CONFIG_NAME = "ShBigdataConf"; + + private static final List WHILTE_LIST = new ArrayList<>(); + + static { + WHILTE_LIST.add("hrmSenderConvertRuleSql"); + WHILTE_LIST.add("hrmReceiveConvertRuleSql"); + } + + /** + *

获取token

+ * @author xuanran.wang + * @dateTime 2023/4/6 19:59 + * @return token + **/ + public static String getToken(){ + return TokenUtil.getToken(); + } + + /** + *

给post请求的url添加token

+ * @author xuanran.wang + * @dateTime 2023/4/6 20:11 + * @param url 路径 + * @return 添加完token的路径url + **/ + public static String addToken2Url(String url){ + return url + "?access_token=" + getToken(); + } + + /** + *

获取配置文件

+ * @author xuanran.wang + * @dateTime 2023/4/4 11:47 + * @return 配置文件map + **/ + public static Map getConfFromProperties(){ + Map configMap = Util.getProperties2Map(CONFIG_NAME); + if(MapUtils.isEmpty(configMap)){ + throw new CustomerException(Util.logStr("/web-inf/prop/prop2map/{}.properties can not empty!", CONFIG_NAME)); + } + return configMap; + } + + /** + *

从配置文件中获取指定key的value并进行校验

+ * @author xuanran.wang + * @dateTime 2023/4/6 10:45 + * @param key 指定的key + * @return value + **/ + public static String getPropertiesValByKey(String key){ + Map conf = getConfFromProperties(); + String value = Util.null2DefaultStr(conf.get(key), ""); + if(StringUtils.isBlank(value) && !WHILTE_LIST.contains(key)){ + throw new CustomerException(Util.logStr("/web-inf/prop/prop2map/{}.properties the key = {} can not empty!",CONFIG_NAME, key)); + } + return value; + } + + /** + *

解析注解并将实体类转换成map

+ * @author xuanran.wang + * @dateTime 2023/4/6 12:27 + * @param type 表类型 0: 分部, 1: 部门 + * @param o 对象 + * @return 参数 + **/ + public static LinkedHashMap parseCusDbEntityMapping(int type, Object o) throws IllegalAccessException { + Class clazz = o.getClass(); + LinkedHashMap params = new LinkedHashMap<>(); + Field[] fields = clazz.getDeclaredFields(); + Field[] superFields = clazz.getSuperclass().getDeclaredFields(); + List collect = Arrays.stream(fields).collect(Collectors.toList()); + if(superFields.length > 0){ + collect.addAll(Arrays.stream(superFields).collect(Collectors.toList())); + } + for (Field field : collect) { + CusDbEntityMapping cusDbEntityMapping = field.getDeclaredAnnotation(CusDbEntityMapping.class); + if(cusDbEntityMapping != null){ + String[] dbFields = cusDbEntityMapping.dbFiled(); + String dbField; + if(dbFields.length == 0 || type == -1){ + dbField = field.getName(); + }else { + int index = Math.min(dbFields.length, type); + dbField = dbFields[index - 1]; + } + field.setAccessible(true); + params.put(dbField, field.get(o)); + } + } + return params; + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java new file mode 100644 index 0000000..706bf4c --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java @@ -0,0 +1,78 @@ +package weaver.xuanran.wang.sh_bigdata.common.util; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.dubbo.common.serialize.fastjson.FastJsonObjectOutput; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusToken; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + *

token 工具类

+ * + * @author xuanran.wang + * @date 2023/4/7 23:27 + */ +public class TokenUtil { + private static final Logger log = Util.getLogger(); + private static volatile CusToken cusToken = null; + private static final CusSuccess tokenCusSuccess = CusSuccess.builder() + .successField("errcode") + .successValue(0) + .errorMsg("msg") + .dataKey("") + .build(); + private static final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + + /** + *

获取token

+ * @author xuanran.wang + * @dateTime 2023/4/6 19:59 + * @return token + **/ + public static String getToken() { + if(cusToken == null){ + synchronized (TokenUtil.class){ + if(cusToken == null){ + return getTokenByHTTP(); + } + } + } + long expiryTime = cusToken.getExpiryTime(); + if(new Date().getTime() >= expiryTime){ + synchronized (TokenUtil.class){ + expiryTime = cusToken.getExpiryTime(); + if(new Date().getTime() >= expiryTime){ + return getTokenByHTTP(); + } + } + } + return cusToken.getAccess_token(); + } + + /** + *

从接口获取token

+ * @author xuanran.wang + * @dateTime 2023/4/7 23:49 + * @return token + **/ + private static String getTokenByHTTP(){ + HashMap params = new HashMap<>(); + // 接口调用地址 + String tokenUrl = ShBigDataUtil.getPropertiesValByKey("tokenUrl"); + // 密钥 + String corpSecret = ShBigDataUtil.getPropertiesValByKey("corpSecret"); + params.put("corpsecret", corpSecret); + Map tokenMap = requestMasterPlate.apiGet(tokenUrl, params, new HashMap<>(), tokenCusSuccess); + cusToken = JSONObject.parseObject(JSONObject.toJSONString(tokenMap), CusToken.class); + long expiryBeforeTime = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("expiryBeforeTime"), 5); + // 默认少5分钟过期 + cusToken.setExpiryTime(new Date().getTime() + (cusToken.getExpires_in() * 1000) - (60 * expiryBeforeTime * 1000)); + log.info("http token => " + JSONObject.toJSONString(cusToken)); + return cusToken.getAccess_token(); + } +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java new file mode 100644 index 0000000..7e2b8d2 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/OrganizationHrmSyncFromOtherSys.java @@ -0,0 +1,106 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async; + +import weaver.hrm.resource.HrmSynDAO; +import weaver.interfaces.hrm.*; + +import java.util.HashMap; +import java.util.Map; + +/** + *

上海大数据中心人员/组织架构同步

+ * + * @author xuanran.wang + * @date 2023/4/4 10:21 + */ +public class OrganizationHrmSyncFromOtherSys implements HrmSynService { + private HashMap synResult; + + public OrganizationHrmSyncFromOtherSys(){ + this.removeSynResult(); + } + + @Override + public String SynTimingToOASubCompany() { + return null; + } + + @Override + public String SynTimingToOADepartment() { + return null; + } + + @Override + public String SynTimingToOAJobtitle() { + return null; + } + + @Override + public String SynTimingToOAHrmResource() { + return null; + } + + @Override + public void SynTimingFromOASubCompany(SubCompanyBean[] subCompanyBeans) { + } + + @Override + public void SynTimingFromOADepartment(DepartmentBean[] departmentBeans) { + + } + + @Override + public void SynTimingFromOAJobtitle(JobTitleBean[] jobTitleBeans) { + + } + + @Override + public void SynTimingFromOAHrmResource(UserBean[] userBeans) { + + } + + @Override + public void SynInstantSubCompany(SubCompanyBean subCompanyBean) { + + } + + @Override + public void SynInstantDepartment(DepartmentBean departmentBean) { + + } + + @Override + public void SynInstantJobtitle(JobTitleBean jobTitleBean) { + + } + + @Override + public void SynInstantHrmResource(UserBean userBean) { + + } + + @Override + public boolean SynSendMessage(String s, String s1, String s2, String s3, String s4) { + return false; + } + + @Override + public HashMap getSynResult() { + return this.synResult; + } + + @Override + public void removeSynResult() { + this.synResult = new HashMap<>(); + } + + private Map buildItemMap(String pkCode, String pk, String memo, String success, String error) { + //保存结果 + Map res = new HashMap<>(); + res.put(weaver.hrm.resource.HrmSynDAO.OUTPK, pkCode); + res.put(weaver.hrm.resource.HrmSynDAO.PK, pk); + res.put(weaver.hrm.resource.HrmSynDAO.Memo, memo); + res.put(weaver.hrm.resource.HrmSynDAO.Success, success); + res.put(HrmSynDAO.ErrorMessage, error); + return res; + } +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusDbEntityMapping.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusDbEntityMapping.java new file mode 100644 index 0000000..a377187 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/annotations/CusDbEntityMapping.java @@ -0,0 +1,16 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations; + +import java.lang.annotation.*; + +/** + *

自定义实体类与数据库映射

+ * + * @author xuanran.wang + * @date 2023/4/6 11:55 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +@Documented +public @interface CusDbEntityMapping { + String[] dbFiled() default {}; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java new file mode 100644 index 0000000..aacf42a --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/entity/OtherSysDepartment.java @@ -0,0 +1,53 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity; + +import aiyh.utils.annotation.recordset.SqlDbFieldAnn; +import lombok.Data; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.annotations.CusDbEntityMapping; + +import java.util.List; + + +/** + *

上海大数据中心人员/组织架构同步 部门实体类

+ * + * @author xuanran.wang + * @date 2023/4/4 11:03 + */ +@Data +public class OtherSysDepartment { + /** + *

创建的部门id

+ **/ + @CusDbEntityMapping(dbFiled ={"outkey"}) + private int id; + /** + *

部门名称

+ **/ + @CusDbEntityMapping(dbFiled = {"subcompanyname", "departmentname"}) + private String name; + /** + *

父部门id。根部门为1

+ **/ + @CusDbEntityMapping(dbFiled = {"supsubcomid", "supdepid"}) + private int parentid; + /** + *

+ * 在父部门中的次序值。order值大的排序靠前,order值相等的情况下,按照部门id排,id越小排序越靠前。有效的值范围是[0, 2^32) + *

+ **/ + @CusDbEntityMapping(dbFiled = {"showorder"}) + private int order; + /** + *

所属分部id

+ **/ + @CusDbEntityMapping(dbFiled = {"supsubcomid","supsubcomid1"}) + private int subCompanyId; + /** + *

+ * 是否有子部门,0:否,1:是 + *

+ **/ + private int hasChild; + + private List childList; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java new file mode 100644 index 0000000..769ae6f --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/mapper/OrgHrmAsyncMapper.java @@ -0,0 +1,25 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import aiyh.utils.annotation.recordset.SqlString; +import aiyh.utils.annotation.recordset.Update; +import io.swagger.models.auth.In; + +import java.util.Map; + +/** + *

组织架构同步 mapper

+ * + * @author xuanran.wang + * @date 2023/4/6 11:05 + */ +@SqlMapper +public interface OrgHrmAsyncMapper { + + @Select("select outkey, id from HrmSubCompany where outkey != '' and outkey is not null") + Map selectSubCompany(); + + @Update(custom = true) + boolean updateSubInfo(@SqlString String sql, Map params); +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java new file mode 100644 index 0000000..8d23e7c --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncApiService.java @@ -0,0 +1,32 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service; + +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; + +import java.util.List; + +/** + *

上海大数据中心人员/组织架构同步 接口调用

+ * + * @author xuanran.wang + * @date 2023/4/4 11:09 + */ +public interface OrgHrmAsyncApiService { + + + /** + *

获取用户信息

+ * @author xuanran.wang + * @dateTime 2023/4/4 11:13 + * @return 响应对象 + **/ + List getUserInfo(); + + /** + *

获取部门信息

+ * @author xuanran.wang + * @dateTime 2023/4/4 11:13 + * @return 响应对象 + **/ + List getDepartmentInfo(); + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java new file mode 100644 index 0000000..c7d1cf7 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/OrgHrmAsyncService.java @@ -0,0 +1,31 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service; + +import io.swagger.models.auth.In; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; + +import java.util.List; +import java.util.Map; + +/** + *

<上海大数据中心人员/组织架构同步 业务方法/h1> + * + * @author xuanran.wang + * @date 2023/4/4 11:07 + */ +public interface OrgHrmAsyncService { + + /** + *

获取分部表中 outKey 与 id对应到map集合

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:44 + * @return 分部表中 outKey 与 id对应到map集合 + **/ + Map initSubCompany(); + /** + *

部门数据同步

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:44 + **/ + List asyncDepartment(); + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java new file mode 100644 index 0000000..d4ba595 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncApiServiceImpl.java @@ -0,0 +1,49 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl; + +import com.alibaba.fastjson.JSONObject; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; +import weaver.xuanran.wang.sh_bigdata.common.util.RequestMasterPlate; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

+ * 上海大数据中心人员/组织架构同步 接口调用 具体业务方法 + *

+ * + * @author xuanran.wang + * @date 2023/4/4 11:24 + */ +public class OrgHrmAsyncApiServiceImpl implements OrgHrmAsyncApiService { + private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + @Override + public List getUserInfo() { + return null; + } + + @Override + public List getDepartmentInfo() { + String departmentInfoUrl = ShBigDataUtil.getPropertiesValByKey("departmentInfoUrl"); + HashMap params = new HashMap<>(); + params.put("access_token", ShBigDataUtil.getToken()); + CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(0) + .errorMsg("msg") + .dataKey("data.department") + .build(); + List> list = requestMasterPlate.apiGet(departmentInfoUrl, params, new HashMap<>(), cusSuccess); + List res = new ArrayList<>(); + for (Object o : list) { + res.add(JSONObject.parseObject(JSONObject.toJSONString(o), OtherSysDepartment.class)); + } + return res; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java new file mode 100644 index 0000000..b3500d8 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/org_hrm_async/service/impl/OrgHrmAsyncServiceImpl.java @@ -0,0 +1,163 @@ +package weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.collections.CollectionUtils; +import weaver.conn.RecordSet; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.matrix.MatrixUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.mapper.OrgHrmAsyncMapper; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncService; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + *

组织架构同步

+ * + * @author xuanran.wang + * @date 2023/4/6 10:10 + */ +public class OrgHrmAsyncServiceImpl implements OrgHrmAsyncService { + private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); + + private final OrgHrmAsyncMapper orgHrmAsyncMapper = Util.getMapper(OrgHrmAsyncMapper.class); + + private final SubCompanyComInfo sci = new SubCompanyComInfo(); + + @Override + public Map initSubCompany() { + return orgHrmAsyncMapper.selectSubCompany(); + } + + @Override + public List asyncDepartment() { + List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); + //TODO 分部(条件待确认) + List subList = departmentInfo + .stream() + .filter(item -> -1 == item.getParentid()) + .sorted(Comparator.comparing(OtherSysDepartment::getId)) + .collect(Collectors.toList()); + addHrmSubCompany(subList); + + // 过滤出父节点并根据id进行升序排序 + List rootDepList = departmentInfo + .stream() + .filter(item -> 0 == item.getHasChild() && -1 != item.getParentid()) + .sorted(Comparator.comparing(OtherSysDepartment::getId)) + .collect(Collectors.toList()); + + return null; + } + + /** + *

同步数据到分部

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + * @param departmentList 部门数据集合 + **/ + public void addHrmSubCompany(List departmentList){ + //新增的分部id + int subId; + char separator = weaver.general.Util.getSeparator(); + RecordSet rsSch = new RecordSet(); + // 分部数据 + Map subCompany = initSubCompany(); + for (OtherSysDepartment department : departmentList) { + subId = Util.getIntValue(Util.null2DefaultStr(subCompany.get(department.getId()),""),-1); + if(subId < 0){ + String para = department.getName() + separator + department.getName() + separator + "1" + separator + + department.getId()+ separator + "" + separator +department.getOrder(); + rsSch.executeProc("HrmSubCompany_Insert", para); + if (rsSch.next()) { + subId = rsSch.getInt(1); + } + } + updateTable("HrmSubCompany", subId, 0, department); + } + //清除全部分部缓存 + sci.removeCompanyCache(); + } + + /** + *

同步数据到分部

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:37 + * @param departmentList 部门数据集合 + **/ + public void addHrmDepartment(List departmentList){ + //新增的分部id + int id = 0; + char separator = weaver.general.Util.getSeparator(); + RecordSet rsSch = new RecordSet(); + for (OtherSysDepartment department : departmentList) { + String para = department.getName() + separator + department.getName() + separator + "1" + separator + + department.getParentid() + separator + "" + separator +department.getOrder(); + rsSch.executeProc("HrmSubCompany_Insert", para); + if (rsSch.next()) { + id = rsSch.getInt(1); + updateTable("HrmSubCompany", id, 0, department); + } + } + //清除全部分部缓存 + sci.removeCompanyCache(); + } + + /** + *

更新分部数据

+ * @author xuanran.wang + * @dateTime 2023/4/6 13:35 + * @param tableName 表名 + * @param id 数据id + * @param type 类型 + * @param o 对象 + **/ + public void updateTable(String tableName, int id, int type, Object o){ + StringBuilder sb = new StringBuilder("update "); + sb.append(tableName).append(" set "); + Map params; + try { + params = ShBigDataUtil.parseCusDbEntityMapping(type, o); + }catch (Exception e){ + throw new CustomerException("parseCusDbEntityMapping error!"); + } + for (Map.Entry entry : params.entrySet()) { + sb.append(entry.getKey()) + .append(" = #{") + .append(entry.getKey()) + .append("},"); + } + sb.deleteCharAt(sb.length() - 1); + sb.append(" where id = ").append(id); + boolean success = orgHrmAsyncMapper.updateSubInfo(sb.toString(), params); + if(!success){ + throw new CustomerException(Util.logStr("update {} sql error!", tableName)); + } + //同步分部数据到矩阵 + MatrixUtil.updateSubcompayData(String.valueOf(id)); + } + + public void setChildList(List departmentList){ + if(departmentList.size() == 0){ + return; + } + for (OtherSysDepartment department : departmentList) { + List childList = departmentList + .stream() + .filter(item -> department.getId() == item.getParentid()) + .collect(Collectors.toList()); + department.setChildList(childList); + if(CollectionUtils.isNotEmpty(childList)){ + setChildList(childList); + } + } + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/SendTodoTaskImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/SendTodoTaskImpl.java new file mode 100644 index 0000000..3b205dc --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/SendTodoTaskImpl.java @@ -0,0 +1,162 @@ +package weaver.xuanran.wang.sh_bigdata.task_async; + +import aiyh.utils.ThreadPoolConfig; +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.ofs.interfaces.SendRequestStatusDataInterfaces; +import weaver.workflow.request.todo.DataObj; +import weaver.workflow.request.todo.RequestStatusObj; +import weaver.xuanran.wang.sh_bigdata.common.util.SendTodoTaskUtil; +import weaver.xuanran.wang.sh_bigdata.task_async.service.impl.SendTodoTaskServiceImpl; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; + +/** + *

上海大数据中心统一待办推送

+ * + * @author xuanran.wang + * @date 2023/4/6 15:43 + */ +public class SendTodoTaskImpl implements SendRequestStatusDataInterfaces { + /** + * 后台设置id + */ + public String id; + /** + * 设置的系统编号 + */ + public String syscode; + /** + * 服务器URL + */ + public String serverurl; + /** + * 流程白名单 + */ + public ArrayList workflowwhitelist; + /** + * 人员白名单 + */ + public ArrayList userwhitelist; + + + public String getId() { + return id; + } + + public String getSyscode() { + return syscode; + } + + public String getServerurl() { + return serverurl; + } + + public ArrayList getWorkflowwhitelist() { + return workflowwhitelist; + } + + public ArrayList getUserwhitelist() { + return userwhitelist; + } + + + private final SendTodoTaskServiceImpl sendTodoTaskService = new SendTodoTaskServiceImpl(); + private final ExecutorService pool = ThreadPoolConfig.createThreadPoolInstance(); + private final SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil(); + private final Logger log = Util.getLogger(); + + @Override + public void SendRequestStatusData(ArrayList dataList) { + for (DataObj dataObj : dataList) { + List todoList = sendTodoTaskUtil.distantList(dataObj.getTododatas()); + List doneList = sendTodoTaskUtil.distantList(dataObj.getDonedatas()); + try { + pool.execute(() -> { + log.info("todoList => \n" + JSONObject.toJSONString(todoList)); + log.info("doneList => \n" + JSONObject.toJSONString(doneList)); + if (CollectionUtils.isNotEmpty(todoList)) { + sendTodoTaskService.sendTodo(todoList); + } + if (CollectionUtils.isNotEmpty(doneList)) { + sendTodoTaskService.sendDone(doneList); + } + }); + } catch (Exception e) { + log.error("SendTodoTaskImpl error! " + e.getMessage()); + } + } + } + + /** + * 格式化JSON格式输出 + * + * @param jsonStr + * @return 返回指定格式化的数据 + */ + public static String formatJson(String jsonStr) { + if (null == jsonStr || "".equals(jsonStr)) + return ""; + StringBuilder sb = new StringBuilder(); + char last = '\0'; + char current = '\0'; + int indent = 0; + boolean isInQuotationMarks = false; + for (int i = 0; i < jsonStr.length(); i++) { + last = current; + current = jsonStr.charAt(i); + switch (current) { + case '"': + if (last != '\\') { + isInQuotationMarks = !isInQuotationMarks; + } + sb.append(current); + break; + case '{': + case '[': + sb.append(current); + if (!isInQuotationMarks) { + sb.append('\n'); + indent++; + addIndentBlank(sb, indent); + } + break; + case '}': + case ']': + + if (!isInQuotationMarks) { + sb.append('\n'); + indent--; + addIndentBlank(sb, indent); + } + sb.append(current); + break; + case ',': + sb.append(current); + break; + default: + sb.append(current); + } + } + + return sb.toString(); + } + + /** + * 添加space(缩进) + * + * @param sb + * @param indent + */ + private static void addIndentBlank(StringBuilder sb, int indent) { + for (int i = 0; i < indent; i++) { + sb.append('\t'); + } + } + +} \ No newline at end of file diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java new file mode 100644 index 0000000..a69e3e9 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTask.java @@ -0,0 +1,23 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.entity; + +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; + +/** + *

已办实体

+ * + * @author xuanran.wang + * @date 2023/4/6 22:21 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CusDoneTask { + @SqlFieldMapping + private String taskNum; + private int status; + private String appId; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTaskOA.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTaskOA.java new file mode 100644 index 0000000..8b3da57 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusDoneTaskOA.java @@ -0,0 +1,39 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; + +/** + *

已办oa实体类

+ * + * @author xuanran.wang + * @date 2023/4/7 13:19 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CusDoneTaskOA extends CusDoneTask{ + @SqlFieldMapping + private String sourceTaskId; + @SqlFieldMapping + private String response; + @SqlFieldMapping + private String requestJson; + @SqlFieldMapping + private int success; + @SqlFieldMapping + private String requestUrl; + @SqlFieldMapping + private int taskType; + @SqlFieldMapping + private String sendTime; + /** + *

异常

+ **/ + @SqlFieldMapping + private String error; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java new file mode 100644 index 0000000..fe8a8a8 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTask.java @@ -0,0 +1,29 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; + +/** + *

待办实体

+ * + * @author xuanran.wang + * @date 2023/4/6 16:27 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CusTodoTask { + @SqlFieldMapping + protected String taskNum; + protected String appId; + @SqlFieldMapping + protected String taskName; + protected String taskDesc; + protected String linkUrl; + protected String mobileLinkUrl; + protected String receiver; + protected String sender; +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTaskToOADetail.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTaskToOADetail.java new file mode 100644 index 0000000..ab804ce --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/entity/CusTodoTaskToOADetail.java @@ -0,0 +1,68 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; + +/** + *

写入oa日志表的实体

+ * + * @author xuanran.wang + * @date 2023/4/6 20:18 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +public class CusTodoTaskToOADetail extends CusTodoTask{ + /** + *

任务类型

+ **/ + @SqlFieldMapping + private int taskType; + /** + *

请求路径

+ **/ + @SqlFieldMapping + private String requestUrl; + /** + *

接口响应

+ **/ + @SqlFieldMapping + private String response; + /** + *

任务源id

+ **/ + @SqlFieldMapping + @SqlUpdateWhereField + private String sourceTaskId; + /** + *

成功/失败

+ **/ + @SqlFieldMapping + private int success; + /** + *

已办发送状态

+ **/ + @SqlFieldMapping + private int status; + /** + *

待办json

+ **/ + @SqlFieldMapping + private String requestJson; + /** + *

发送时间

+ **/ + @SqlFieldMapping + private String sendTime; + /** + *

异常

+ **/ + @SqlFieldMapping + private String error; + public CusTodoTaskToOADetail() { + super(); + } +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/mapper/SendTodoTaskMapper.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/mapper/SendTodoTaskMapper.java new file mode 100644 index 0000000..360a26a --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/mapper/SendTodoTaskMapper.java @@ -0,0 +1,30 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.mapper; + +import aiyh.utils.annotation.recordset.*; + +import java.util.List; +import java.util.Map; + +/** + *

统一待办推送mapper

+ * + * @author xuanran.wang + * @date 2023/4/6 16:49 + */ +@SqlMapper +public interface SendTodoTaskMapper { + @Select("select hrmtransrule from ofs_sendinfo where syscode = #{sysCode}") + String querySendTodoUserConvert(@ParamMapper("sysCode") String sysCode); + @Select("select oaaddress from systemset") + String queryOAAddress(); + + @Select("select taskNum from uf_todo_task_log " + + "where sourceTaskId = #{sourceTaskId} and taskType = 0 and status = 0 and success = 0") + List queryUnSendTodoTaskList(@ParamMapper("sourceTaskId") String sourceTaskId); + + @Update("update uf_todo_task_log set status = 1 where taskNum in (${taskNums})") + boolean updateStatusByTaskNum(@ParamMapper("taskNums") List taskNums); + + @Select(custom = true) + List selectHrmConvertId(@SqlString String sql, @ParamMapper("ids") List ids); +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/SendTodoTaskService.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/SendTodoTaskService.java new file mode 100644 index 0000000..e90d8a7 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/SendTodoTaskService.java @@ -0,0 +1,16 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.service; + +import weaver.workflow.request.todo.RequestStatusObj; + +import java.util.List; + +/** + *

发送待办和已办

+ * + * @author xuanran.wang + * @date 2023/4/6 16:31 + */ +public interface SendTodoTaskService { + void sendTodo(List todoList); + void sendDone(List doneList); +} diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java new file mode 100644 index 0000000..748848b --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/task_async/service/impl/SendTodoTaskServiceImpl.java @@ -0,0 +1,152 @@ +package weaver.xuanran.wang.sh_bigdata.task_async.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.general.TimeUtil; +import weaver.workflow.request.todo.RequestStatusObj; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess; +import weaver.xuanran.wang.sh_bigdata.common.util.RequestMasterPlate; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTask; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTaskOA; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTask; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTaskToOADetail; +import weaver.xuanran.wang.sh_bigdata.task_async.mapper.SendTodoTaskMapper; +import weaver.xuanran.wang.sh_bigdata.task_async.service.SendTodoTaskService; +import weaver.xuanran.wang.sh_bigdata.common.util.SendTodoTaskUtil; + +import javax.ws.rs.core.MediaType; +import java.util.*; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/6 16:46 + */ +@Data +public class SendTodoTaskServiceImpl implements SendTodoTaskService { + private final Logger log = Util.getLogger(); + private String appId; + private final SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil(); + private String addTodoTaskUrl; + private String updateTodoTaskUrl; + private static final String MODEL_NAME = "uf_todo_task_log"; + private final HashMap header = new HashMap<>(); + private int modelId; + private final RequestMasterPlate requestMasterPlate = new RequestMasterPlate(); + private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class); + + + { + sendTodoTaskUtil.setAppId(ShBigDataUtil.getPropertiesValByKey("appId")); + modelId = Util.getIntValue(ShBigDataUtil.getPropertiesValByKey("modelId"),-1); + addTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("addTodoTaskUrl"); + updateTodoTaskUrl = ShBigDataUtil.getPropertiesValByKey("updateTodoTaskUrl"); + header.put("Content-Type", MediaType.APPLICATION_JSON); + } + + @Override + public void sendTodo(List todoList) { + try { + CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(200) + .errorMsg("msg") + .dataKey("") + .build(); + + List taskInfo = sendTodoTaskUtil.getTodoTaskInfo(todoList); + log.info("---------------- todoTaskInfo ---------------- \n" + JSONObject.toJSONString(taskInfo)); + Map response = null; + int success = 0; + String error = null; + try { + response = requestMasterPlate.apiPost(ShBigDataUtil.addToken2Url(addTodoTaskUrl), taskInfo, header, cusSuccess); + }catch (Exception e){ + log.error("Send Todo API Post Error! " + Util.getErrString(e)); + error = "Send Todo API Post Error! " + e.getMessage(); + success = 1; + } + ArrayList details = new ArrayList<>(); + for (CusTodoTask cusTodoTask : taskInfo) { + + CusTodoTaskToOADetail detail = new CusTodoTaskToOADetail(); + detail.setTaskNum(cusTodoTask.getTaskNum()); + detail.setRequestUrl(addTodoTaskUrl); + detail.setTaskName(cusTodoTask.getTaskName()); + detail.setTaskType(0); + detail.setStatus(0); + detail.setSuccess(success); + detail.setResponse(JSONObject.toJSONString(cusSuccess.getResponse() == null ? response : cusSuccess.getResponse())); + detail.setRequestJson(JSONObject.toJSONString(cusTodoTask)); + String sourceTaskId = detail.getTaskNum().substring(0, detail.getTaskNum().length() - 10); + detail.setSourceTaskId(sourceTaskId); + detail.setSendTime(TimeUtil.getCurrentTimeString()); + detail.setError(error); + details.add(detail); + } + CusInfoToOAUtil.executeBatchByEntity(modelId, details,""); + }catch (Exception e){ + log.error("send todo error! " + Util.getErrString(e)); + } + + + } + + @Override + public void sendDone(List doneList) { + try { + CusSuccess cusSuccess = CusSuccess.builder() + .successField("code") + .successValue(200) + .errorMsg("msg") + .dataKey("") + .build(); + + List doneTaskInfo = sendTodoTaskUtil.getDoneTaskInfo(doneList); + log.info("---------------- doneTaskInfo ---------------- \n" + JSONObject.toJSONString(doneTaskInfo)); + Map response = null; + ArrayList list = new ArrayList<>(); + ArrayList successTaskIds = new ArrayList<>(); + String error = ""; + for (CusDoneTask doneTask : doneTaskInfo) { + int success = 0; + try { + response = requestMasterPlate.apiPost(ShBigDataUtil.addToken2Url(updateTodoTaskUrl), doneTask, header, cusSuccess); + successTaskIds.add(doneTask.getTaskNum()); + }catch (Exception e){ + log.error("Send Todo API Post Error! " + Util.getErrString(e)); + error = "Send Todo API Post Error! " + Util.getErrString(e); + success = 1; + } + CusDoneTaskOA taskOA = new CusDoneTaskOA(); + taskOA.setTaskNum(doneTask.getTaskNum()); + taskOA.setTaskType(1); + String sourceTaskId = doneTask.getTaskNum().substring(0, doneTask.getTaskNum().length() - 10); + taskOA.setSourceTaskId(sourceTaskId); + taskOA.setResponse(JSONObject.toJSONString(cusSuccess.getResponse() == null ? response : cusSuccess.getResponse())); + taskOA.setRequestUrl(updateTodoTaskUrl); + taskOA.setRequestJson(JSONObject.toJSONString(doneTask)); + taskOA.setSuccess(success); + taskOA.setSendTime(TimeUtil.getCurrentTimeString()); + taskOA.setError(error); + list.add(taskOA); + } + CusInfoToOAUtil.executeBatchByEntity(modelId, list,""); + if(CollectionUtils.isNotEmpty(successTaskIds)){ + mapper.updateStatusByTaskNum(successTaskIds); + } + }catch (Exception e){ + log.error("send done error! " + Util.getErrString(e)); + } + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/entity/MQMessage.java b/src/main/java/weaver/xuanran/wang/shyl_mq/entity/MQMessage.java index ae01080..1972dd0 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/entity/MQMessage.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/entity/MQMessage.java @@ -24,7 +24,7 @@ public class MQMessage { * AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC: 密码修改队列 *

**/ - @SqlFieldMapping() + @SqlFieldMapping private String topic; /** *

消息内容操作类型

@@ -35,19 +35,19 @@ public class MQMessage { * PASSWORD_ACTION: 修改密码 *

**/ - @SqlFieldMapping() + @SqlFieldMapping private String actionType; /** *

消息发送时间

**/ - @SqlFieldMapping() + @SqlFieldMapping private String sendTime; /** *

消息业务内容,json 格式,分业务(用户、机构、密码修改)

**/ - @SqlFieldMapping() + @SqlFieldMapping private String content; - @SqlFieldMapping() + @SqlFieldMapping private String error; } diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java b/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java index 1d6bab2..e1ec671 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/mapper/ConsumerMapper.java @@ -100,7 +100,7 @@ public interface ConsumerMapper { * @param id id * @return true/false **/ - @Delete("delete from hrmresource where id = #{id}") + @Delete("update hrmresource set status = 7 where id = #{id}") boolean deleteHrmById(@ParamMapper("id") String id); /** @@ -115,4 +115,8 @@ public interface ConsumerMapper { @Select("select count(1) from uf_mqLog where messageId = #{messageId}") int getMainIdFromMQLogByMessageId(@ParamMapper("messageId") String messageId); + + @Update("update hrmresource set loginId = #{loginId} where id = #{id}") + boolean updateHrmLoginIdById(@ParamMapper("id") String id, + @ParamMapper("loginId") String loginId); } diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/ProducerService.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/ProducerService.java index 75c5bbc..e6ad383 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/ProducerService.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/ProducerService.java @@ -29,7 +29,7 @@ public class ProducerService { private final Logger logger = Util.getLogger(); private final DealWithMapping dealWithMapping = new DealWithMapping(); - private final ToolUtil toolUtil = new ToolUtil(); + private final HttpUtils httpUtils = new HttpUtils(); { @@ -54,7 +54,7 @@ public class ProducerService { ChangeRequestParam changeRequestParam){ RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark); String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, tableName); - logger.info("查询主表sql : " + selectMainSql); +// logger.info("查询主表sql : " + selectMainSql); RecordSet recordSet = new RecordSet(); recordSet.executeQuery(selectMainSql, requestId); Map requestParam = new HashMap<>(); @@ -69,10 +69,6 @@ public class ProducerService { if(!Objects.isNull(changeRequestParam)){ changeRequestParam.changeRequestParam(requestParam); } -// logger.info(Util.logStr("requestId : {}, msg:{}", requestId, JSONObject.toJSONString(requestParam))); - String sendMQ = Util.null2DefaultStr(toolUtil.getSystemParamValue("sendMQ"),""); - if("1".equals(sendMQ)){ - RocketConsumerUtil.producerSendMsg(configName,JSONObject.toJSONString(requestParam), requestId); - } + RocketConsumerUtil.producerSendMsg(configName, JSONObject.toJSONString(requestParam), requestId); } } diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java index b9cf11a..4a5198c 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/PassWordServiceImpl.java @@ -42,14 +42,14 @@ public class PassWordServiceImpl extends CusInfoActionService { String content = message.getContent(); ModifyPassWord passWord = JSONObject.parseObject(content, ModifyPassWord.class); logger.info(Util.logStr("cusPassWordAction messageId: {},UserInfo : {} ",message.getId(),JSONObject.toJSONString(passWord))); - String outKey = passWord.getId(); - String hrmId = consumerMapper.getHrmIdByOutKey(outKey); - if(StringUtils.isBlank(hrmId)){ - throw new CustomerException(Util.logStr("the userId is {} , no personnel information found in oa!", outKey)); - } - if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(passWord.getPassword()))) { - throw new CustomerException("update user password error!"); - } +// String outKey = passWord.getId(); +// String hrmId = consumerMapper.getHrmIdByOutKey(outKey); +// if(StringUtils.isBlank(hrmId)){ +// throw new CustomerException(Util.logStr("the userId is {} , no personnel information found in oa!", outKey)); +// } +// if (!consumerMapper.updatePasswordById(hrmId, Util.getEncrypt(passWord.getPassword()))) { +// throw new CustomerException("update user password error!"); +// } writeInOA(message.getId()); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } catch (Exception e) { diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..8a126d0 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImpl.java @@ -0,0 +1,124 @@ +package weaver.xuanran.wang.shyl_mq.service.impl; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.hrm.resource.ResourceComInfo; +import weaver.xuanran.wang.shyl_mq.entity.MQMessage; +import weaver.xuanran.wang.shyl_mq.entity.UserInfo; +import weaver.xuanran.wang.shyl_mq.service.CusInfoActionService; + + +/** + *

用户业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:04 + */ +public class UserServiceImpl extends CusInfoActionService { + private Logger logger = Util.getLogger("mq-consumer-user"); + + { + if(null == logger){ + logger = Util.getLogger("mq-consumer-user"); + } + } + + /** + *

用户新增

+ * @author xuanran.wang + * @dateTime 2023/1/3 13:37 + * @param message mq消息 + * @return 成功/重试 + **/ + @Override + public ConsumeConcurrentlyStatus cusCreateAction(MQMessage message) { + try { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + logger.info(Util.logStr("userCusCreateAction messageId: {}, UserInfo : {} ",message.getId(), JSONObject.toJSONString(userInfo))); + updateLoginId(userInfo); + writeInOA(message.getId()); + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + }catch (Exception e){ + throw new CustomerException(Util.logStr("hrmCreateAction error : {}", e.getMessage())); + } + } + + /** + *

用户删除

+ * @author xuanran.wang + * @dateTime 2023/1/3 13:38 + * @param message mq消息 + * @return 成功/重试 + **/ + @Override + public ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message) { + try { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + logger.info(Util.logStr("userCusDeleteAction messageId: {},UserInfo : {} ", message.getId(),JSONObject.toJSONString(userInfo))); + String id = Util.null2DefaultStr(userInfo.getId(),""); + if(StringUtils.isBlank(id)){ + throw new CustomerException("del user id not null!"); + } + if (!consumerMapper.deleteHrmById(id)) { + throw new CustomerException("del user sql execute error!"); + } + ResourceComInfo resourceComInfo = new ResourceComInfo(); + resourceComInfo.updateResourceInfoCache(id); + writeInOA(message.getId()); + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } catch (Exception e) { + throw new CustomerException(Util.logStr("hrmDeleteAction execute error : [{}]!", e.getMessage())); + } + } + + /** + *

用户更新

+ * @author xuanran.wang + * @dateTime 2023/1/3 13:39 + * @param message mq消息 + * @return 成功/重试 + **/ + @Override + public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) { + try { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + logger.info(Util.logStr("userCusUpdateAction messageId: {},UserInfo : {} ", message.getId(), JSONObject.toJSONString(userInfo))); + updateLoginId(userInfo); + writeInOA(message.getId()); + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + }catch (Exception e){ + throw new CustomerException(Util.logStr("userCusUpdateAction execute error : [{}]!", e.getMessage())); + } + } + /** + *

<更新登陆名/h1> + * @author xuanran.wang + * @dateTime 2023/3/28 13:07 + * @param userInfo 用户实体 + **/ + public void updateLoginId(UserInfo userInfo) throws Exception { + String id = Util.null2DefaultStr(userInfo.getId(),""); + String userName = Util.null2DefaultStr(userInfo.getUserName(),""); + if(StringUtils.isBlank(id) || StringUtils.isBlank(userName)){ + throw new CustomerException("create user id or userName can not null!"); + } + if (!consumerMapper.updateHrmLoginIdById(id, userName)) { + throw new CustomerException("update loginId sql execute error!"); + } + ResourceComInfo resourceComInfo = new ResourceComInfo(); + // 清空缓存 + resourceComInfo.updateResourceInfoCache(id); + } + + @Override + public ConsumeConcurrentlyStatus cusPassWordAction(MQMessage message) { + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java index 759e1e2..3f97c57 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/service/impl/UserServiceImplBack.java @@ -22,12 +22,12 @@ import java.util.List; import java.util.Map; /** - *

用户业务方法

+ *

用户业务方法-废弃

* * @Author xuanran.wang * @Date 2022/12/30 13:04 */ -public class UserServiceImpl extends CusInfoActionService { +public class UserServiceImplBack extends CusInfoActionService { private Logger logger = Util.getLogger("mq-consumer-user"); { diff --git a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java index a27c413..c6b564d 100644 --- a/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java +++ b/src/main/java/weaver/xuanran/wang/shyl_mq/util/RocketConsumerUtil.java @@ -1,4 +1,4 @@ -package weaver.xuanran.wang.shyl_mq.util;//package weaver.xuanran.wang.shyl.mq.util; +package weaver.xuanran.wang.shyl_mq.util; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; @@ -37,15 +37,21 @@ import java.util.*; */ public class RocketConsumerUtil { private static Logger log = Util.getLogger("mq-util"); + + private static Logger producerLog = Util.getLogger("mq-producer"); private static final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class); private static final ToolUtil tool = new ToolUtil(); private static final int ERROR_LOG_ID; + private static final ToolUtil toolUtil = new ToolUtil(); static { ERROR_LOG_ID = Util.getIntValue(tool.getSystemParamValue("mqErrorLogModelId"), -1); if(log == null){ log = Util.getLogger("mq-util"); } + if(producerLog == null){ + producerLog = Util.getLogger("mq-producer"); + } } /** @@ -83,7 +89,7 @@ public class RocketConsumerUtil { CusInfoActionService cusInfoActionService, String configName){ Map configMap = RocketMQFactory.CONFIG_MAPS.get(configName); int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES); - MessageExt messageExt = null; + MessageExt messageExt; String msgBody = ""; String mqMessageId = ""; MQMessage mqMessage = null; @@ -143,7 +149,7 @@ public class RocketConsumerUtil { mqMessage.setError(e.getMessage()); List ids = CusInfoToOAUtil.executeBatchByEntity(ERROR_LOG_ID, Collections.singletonList(mqMessage), ""); if(CollectionUtils.isEmpty(ids)){ - log.error("insert into mq_error_log failed!"); + log.error(Util.logStr("messageId : {}, insert into mq_error_log failed!", mqMessageId)); } } log.error(Util.logStr("MQ producer error already bigger maxReconsumeTimes! messageId : {}",mqMessageId)); @@ -164,6 +170,10 @@ public class RocketConsumerUtil { * @param requestId 请求id **/ public static void producerSendMsg(String configName, String msg, String requestId) { + String sendMQ = Util.null2DefaultStr(toolUtil.getSystemParamValue("sendMQ"),""); + if(!"1".equals(sendMQ)){ + return; + } // 先从本地缓存中获取生产者对象 DefaultMQProducer producer = RocketMQFactory.getMQProducer(configName); // 获取配置信息 @@ -171,9 +181,10 @@ public class RocketConsumerUtil { // 队列名 String topic = Util.null2DefaultStr(configMap.get("Topic"), ""); // tag - String tag = Util.null2DefaultStr(configMap.get("Tag"), ""); +// String tag = Util.null2DefaultStr(configMap.get("Tag"), ""); Message message; try { + producerLog.info(Util.logStr("requestId: {}, msg: {}", requestId, msg)); message = new Message(topic, msg.getBytes(RemotingHelper.DEFAULT_CHARSET)); } catch (Exception e) { throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage())); @@ -190,12 +201,12 @@ public class RocketConsumerUtil { } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) { throw new CustomerException(Util.logStr("producer send message error!: {}", e.getMessage())); } - log.info(Util.logStr("requestId: {}, result : {}",requestId, JSONObject.toJSONString(result))); + producerLog.info(Util.logStr("requestId: {}, result : {}",requestId, JSONObject.toJSONString(result))); SendStatus sendStatus = result.getSendStatus(); // 如果失败 if (!SendStatus.SEND_OK.equals(sendStatus)) { String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus); - log.error(error); + producerLog.error(error); // 如果重试超过最大次数 if(count >= RocketMQConstant.SEND_MAX_COUNT){ throw new CustomerException(error + " and retry > max"); diff --git a/src/main/resources/WEB-INF/prop/prop2map/OACarTest.properties b/src/main/resources/WEB-INF/prop/prop2map/OACarTest.properties new file mode 100644 index 0000000..516ecc6 --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/OACarTest.properties @@ -0,0 +1,5 @@ +producerGroup=weaver-car +serverAddr=114.115.168.220:9876 +topic=AUTH_CONSOLE_ORG_TOPIC +tag=* +consumerGroup=weaver-car-consumer diff --git a/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties b/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties new file mode 100644 index 0000000..448dd3f --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/ShBigdataConf.properties @@ -0,0 +1,24 @@ +# ??????? +corpSecret=5eab6957b4944d75acfa9cfcc8feff5a +agentId=10000060 +corpId=wwdbb6b075752cc1b9 +# ??token??? +tokenUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/gettoken +# ?????? +userInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/user/get +# ?????? +departmentInfoUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/department/list +# ?????? +addTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/create +# ?????? +updateTodoTaskUrl=http://ramos-develop.shdata.com:11080/uranus/cgi-bin/request/task/update +# ?????????appId +appId=wwdbb6b075752cc1b9 +# ????????????ID +modelId=112 +# ???????????sql ????????outkey ??sql?? select outkey from hrmresource where id in (${ids}) ?? +hrmSenderConvertRuleSql=select lastname from hrmresource where id in (${ids}) +# ????? +hrmReceiveConvertRuleSql=select lastname from hrmresource where id in (${ids}) +# oa token?????????? +expiryBeforeTime=5 \ No newline at end of file diff --git a/src/main/resources/WEB-INF/prop/prop2map/VmsKafka.properties b/src/main/resources/WEB-INF/prop/prop2map/VmsKafka.properties new file mode 100644 index 0000000..33eb23e --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/VmsKafka.properties @@ -0,0 +1,5 @@ +bootstrap.servers=10.184.42.41:9094,10.184.42.42:9094,10.184.42.40:9094 +acks=all +retries=1 +key.serializer=org.apache.kafka.common.serialization.StringSerializer +value.serializer=org.apache.kafka.common.serialization.StringSerializer \ No newline at end of file diff --git a/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java b/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java index c1ea590..cadd360 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java +++ b/src/test/java/xuanran/wang/http_test/annotations/CusRequestClient.java @@ -1,5 +1,9 @@ package xuanran.wang.http_test.annotations; +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.request_type.CusRequestType; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + import java.lang.annotation.*; /** @@ -11,5 +15,10 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @Documented +@CusRequestAddress() public @interface CusRequestClient { + @AliasFor(annotation = CusRequestAddress.class, attribute = "host") + String host() default ""; + @AliasFor(annotation = CusRequestAddress.class, attribute = "port") + int port() default 0; } diff --git a/src/test/java/xuanran/wang/http_test/annotations/CusRequestUrl.java b/src/test/java/xuanran/wang/http_test/annotations/CusRequestUrl.java new file mode 100644 index 0000000..299db5e --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/CusRequestUrl.java @@ -0,0 +1,16 @@ +package xuanran.wang.http_test.annotations; + +import java.lang.annotation.*; + +/** + *

请求地址

+ * + * @author xuanran.wang + * @date 2023/3/16 19:59 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Documented +public @interface CusRequestUrl { + String url(); +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/body/CusRequestBody.java b/src/test/java/xuanran/wang/http_test/annotations/body/CusRequestBody.java new file mode 100644 index 0000000..0b72ed0 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/body/CusRequestBody.java @@ -0,0 +1,16 @@ +package xuanran.wang.http_test.annotations.body; + +import java.lang.annotation.*; + +/** + *

请求体

+ * + * @author xuanran.wang + * @date 2023/3/20 21:27 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +@Documented +public @interface CusRequestBody { + +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/handle/CusHandle.java b/src/test/java/xuanran/wang/http_test/annotations/handle/CusHandle.java new file mode 100644 index 0000000..ee01d9c --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/handle/CusHandle.java @@ -0,0 +1,16 @@ +package xuanran.wang.http_test.annotations.handle; + +import java.lang.annotation.*; + +/** + *

自定义handle注解

+ * + * @author xuanran.wang + * @date 2023/3/16 15:37 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Documented +public @interface CusHandle { + int order() default 0; +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/handle/CusPreLoadHandle.java b/src/test/java/xuanran/wang/http_test/annotations/handle/CusPreLoadHandle.java new file mode 100644 index 0000000..54e9634 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/handle/CusPreLoadHandle.java @@ -0,0 +1,23 @@ +package xuanran.wang.http_test.annotations.handle; + +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.annotations.request_type.CusRequestType; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + +import java.lang.annotation.*; + +/** + *

请求前置加载

+ * + * @author xuanran.wang + * @date 2023/3/20 21:14 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Documented +@CusHandle(order = 0) +public @interface CusPreLoadHandle { + @AliasFor(annotation = CusHandle.class, attribute = "order") + int order() default 0; +} 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 new file mode 100644 index 0000000..172c5af --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/handle/CusReqAfterHandleRegister.java @@ -0,0 +1,19 @@ +package xuanran.wang.http_test.annotations.handle; + +import xuanran.wang.http_test.handle.CusRequestAfterHandle; +import xuanran.wang.http_test.test.TestRequestAfterHandle; + +import java.lang.annotation.*; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/24 14:44 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@Documented +public @interface CusReqAfterHandleRegister { + Class afterHandle(); +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/handle/CusResponseSuccessHandle.java b/src/test/java/xuanran/wang/http_test/annotations/handle/CusResponseSuccessHandle.java new file mode 100644 index 0000000..5f2755d --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/handle/CusResponseSuccessHandle.java @@ -0,0 +1,19 @@ +package xuanran.wang.http_test.annotations.handle; + +import java.lang.annotation.*; + +/** + *

响应体成功失败标识

+ * + * @author xuanran.wang + * @date 2023/3/22 11:29 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +@Documented +public @interface CusResponseSuccessHandle { + String successKey(); + String successCondition(); + String errorMsg(); + String data(); +} diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_path/CusPathQuery.java b/src/test/java/xuanran/wang/http_test/annotations/request_path/CusPathQuery.java index c6c3706..3fc2936 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/request_path/CusPathQuery.java +++ b/src/test/java/xuanran/wang/http_test/annotations/request_path/CusPathQuery.java @@ -14,7 +14,7 @@ import java.lang.annotation.*; * @date 2023/3/14 22:50 */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) +@Target({ElementType.METHOD,ElementType.PARAMETER}) @Documented public @interface CusPathQuery { /** diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestDelete.java b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestDelete.java index a20a87a..427f25f 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestDelete.java +++ b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestDelete.java @@ -1,5 +1,9 @@ package xuanran.wang.http_test.annotations.request_type; +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + import java.lang.annotation.*; /** @@ -11,6 +15,12 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @Documented +@CusRequestUrl(url = "") +@CusRequestType(requestType = CusRequestClientConstant.DELETE) public @interface CusRequestDelete { - String url() default ""; + @AliasFor(annotation = CusRequestUrl.class, attribute = "url") + String url(); + + @AliasFor(annotation = CusRequestType.class, attribute = "requestType") + int requestType() default CusRequestClientConstant.DELETE; } diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestGet.java b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestGet.java index 14a7ec2..ad1fe1d 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestGet.java +++ b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestGet.java @@ -1,5 +1,9 @@ package xuanran.wang.http_test.annotations.request_type; +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + import java.lang.annotation.*; /** @@ -9,8 +13,14 @@ import java.lang.annotation.*; * @date 2023/3/10 10:15 */ @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) +@Target({ElementType.METHOD, ElementType.TYPE}) @Documented +@CusRequestUrl(url = "") +@CusRequestType(requestType = CusRequestClientConstant.GET) public @interface CusRequestGet{ - String url() default ""; + @AliasFor(annotation = CusRequestUrl.class, attribute = "url") + String url(); + + @AliasFor(annotation = CusRequestType.class, attribute = "requestType") + int requestType() default CusRequestClientConstant.GET; } 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 4871a05..57f6806 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 @@ -1,5 +1,9 @@ package xuanran.wang.http_test.annotations.request_type; +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + import java.lang.annotation.*; /** @@ -11,6 +15,12 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Documented +@CusRequestUrl(url = "") +@CusRequestType(requestType = CusRequestClientConstant.POST) public @interface CusRequestPost { - String url() default ""; + @AliasFor(annotation = CusRequestUrl.class, attribute = "url") + String url(); + + @AliasFor(annotation = CusRequestType.class, attribute = "requestType") + int requestType() default CusRequestClientConstant.POST; } diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPut.java b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPut.java index 0fd5c5d..9a06cb2 100644 --- a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPut.java +++ b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestPut.java @@ -1,5 +1,9 @@ package xuanran.wang.http_test.annotations.request_type; +import aiyh.utils.tool.cn.hutool.core.annotation.AliasFor; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.constant.CusRequestClientConstant; + import java.lang.annotation.*; /** @@ -11,6 +15,12 @@ import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Documented +@CusRequestUrl(url = "") +@CusRequestType(requestType = CusRequestClientConstant.PUT) public @interface CusRequestPut { - String url() default ""; + @AliasFor(annotation = CusRequestUrl.class, attribute = "url") + String url(); + + @AliasFor(annotation = CusRequestType.class, attribute = "requestType") + int requestType() default CusRequestClientConstant.PUT; } diff --git a/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestType.java b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestType.java new file mode 100644 index 0000000..53b12a9 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/annotations/request_type/CusRequestType.java @@ -0,0 +1,16 @@ +package xuanran.wang.http_test.annotations.request_type; + +import java.lang.annotation.*; + +/** + *

请求类型

+ * + * @author xuanran.wang + * @date 2023/3/16 23:07 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@Documented +public @interface CusRequestType { + int requestType() default 0; +} diff --git a/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java b/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java index d368610..0d83b8d 100644 --- a/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java +++ b/src/test/java/xuanran/wang/http_test/constant/CusRequestClientConstant.java @@ -1,5 +1,16 @@ package xuanran.wang.http_test.constant; +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; +import xuanran.wang.http_test.entity.CusRequestEntity; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + /** *

请求工具常量

* @@ -11,5 +22,51 @@ public class CusRequestClientConstant { public static final int POST = 1; public static final int DELETE = 2; public static final int PUT = 3; - public static final int HEADER = -1; + public static final int HTTP_SUCCESS_CODE = 200; + public static final Map> CONVERT = new HashMap<>(); + public static final String IS_NOT_NULL = "{ is not null }"; + public static final String EQUALS = "{ equals }"; + public static final String EQUALS_IGNORE_CASE = "{ equalsIgnoreCase }"; + + static { + CONVERT.put(IS_NOT_NULL, cusRequest ->{ + Map responseMap = cusRequest.getResponseMap(); + CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle(); + String key = responseSuccessHandle.successKey(); + String errorMsg = responseSuccessHandle.errorMsg(); + String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),""); + if (successValue == null) { + throw new CustomerException(Util.logStr("is not null check response error! the error is {}", responseMap.get(errorMsg))); + } + return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data())); + }); + + CONVERT.put(EQUALS, cusRequest ->{ + Map responseMap = cusRequest.getResponseMap(); + CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle(); + String key = responseSuccessHandle.successKey(); + String successCondition = responseSuccessHandle.successCondition(); + String errorMsg = responseSuccessHandle.errorMsg(); + String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),""); + String successConditionValue = successCondition.trim().replace(EQUALS, "").trim(); + if(!successConditionValue.equals(successValue)){ + throw new CustomerException(Util.logStr("equals check response error! the error is {}", responseMap.get(errorMsg))); + } + return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data())); + }); + + CONVERT.put(EQUALS_IGNORE_CASE, cusRequest ->{ + Map responseMap = cusRequest.getResponseMap(); + CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle(); + String key = responseSuccessHandle.successKey(); + String successCondition = responseSuccessHandle.successCondition(); + String errorMsg = responseSuccessHandle.errorMsg(); + String successValue = Util.null2DefaultStr(Util.getValueByKeyStr(key, responseMap),""); + String successConditionValue = successCondition.trim().replace(EQUALS_IGNORE_CASE, "").trim(); + if(!successConditionValue.equalsIgnoreCase(Util.null2DefaultStr(successValue,""))){ + throw new CustomerException(Util.logStr("equalsIgnoreCase check response error! the error is {}", responseMap.get(errorMsg))); + } + return JSONObject.toJSONString(responseMap.get(responseSuccessHandle.data())); + }); + } } diff --git a/src/test/java/xuanran/wang/http_test/entity/CusHandleEntity.java b/src/test/java/xuanran/wang/http_test/entity/CusHandleEntity.java new file mode 100644 index 0000000..9fe49f0 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/entity/CusHandleEntity.java @@ -0,0 +1,16 @@ +package xuanran.wang.http_test.entity; + +import lombok.Data; + +/** + *

自定义handle

+ * + * @author xuanran.wang + * @date 2023/3/16 16:07 + */ +@Data +public class CusHandleEntity { + private Class handleClass; + private int order; + private String packageName; +} 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 143ac83..67c06e9 100644 --- a/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java +++ b/src/test/java/xuanran/wang/http_test/entity/CusRequestEntity.java @@ -4,7 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; +import xuanran.wang.http_test.handle.CusRequestAfterHandle; +import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; @@ -19,11 +22,17 @@ import java.util.function.Consumer; @Setter @Getter public class CusRequestEntity{ - private String url; - private Map headers; - private Map pathParams; - private Object bodyParams; - private int requestType; + private String url = ""; + private Map headers = new HashMap<>(); + private Map pathParams = new HashMap<>(); + private Object bodyParams = new Object(); + private int requestType = -1; private Consumer consumer; - private boolean async; + private boolean async = false; + private String host = ""; + private int port; + private Class returnType; + private CusRequestAfterHandle cusRequestAfter; + private CusResponseSuccessHandle responseSuccessHandle; + private Map responseMap; } diff --git a/src/test/java/xuanran/wang/http_test/entity/CusResponseSuccess.java b/src/test/java/xuanran/wang/http_test/entity/CusResponseSuccess.java new file mode 100644 index 0000000..3bed5a1 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/entity/CusResponseSuccess.java @@ -0,0 +1,21 @@ +package xuanran.wang.http_test.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + *

接口响应成功标识对象

+ * + * @author xuanran.wang + * @date 2023/3/29 16:58 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CusResponseSuccess { + private String successKey; + private String successCondition; + private String errorMsg; + private String data; +} diff --git a/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java b/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java new file mode 100644 index 0000000..4bcafaa --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/CusHandleCenter.java @@ -0,0 +1,129 @@ +package xuanran.wang.http_test.handle; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import org.apache.log4j.Logger; +import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister; +import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; +import xuanran.wang.http_test.annotations.request_type.CusRequestType; +import xuanran.wang.http_test.constant.CusRequestClientConstant; +import xuanran.wang.http_test.entity.CusHandleEntity; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.path_handle.CusBodyParseHandle; +import xuanran.wang.http_test.handle.request_handle.CusRequestGetHandle; +import xuanran.wang.http_test.handle.request_handle.CusRequestPostHandle; +import xuanran.wang.http_test.handle.request_handle.CusUrlHandle; +import xuanran.wang.http_test.handle.request_handle.CusDefaultRequestAfterHandle; +import xuanran.wang.http_test.handle.util.HandleUtil; +import xuanran.wang.http_test.proxy.RequestUtil; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

处理器中心对象

+ * + * @author xuanran.wang + * @date 2023/3/16 22:38 + */ +public class CusHandleCenter{ + + private final Logger log = Util.getLogger(); + + private final Queue preloadQueue = new LinkedList<>(); + private final Map requestHandle = new HashMap<>(); + private final CusRequestAfterHandle cusRequestAfterHandle = new CusDefaultRequestAfterHandle(); + + { + requestHandle.put(CusRequestClientConstant.GET, new CusRequestGetHandle()); + requestHandle.put(CusRequestClientConstant.POST, new CusRequestPostHandle()); + preloadQueue.add(new CusUrlHandle()); + preloadQueue.add(new CusBodyParseHandle()); + } + + public void requestBeforeHandle(CusRequestEntity cusRequest, Method method, Object[] args){ + try { + log.info("preloadQueue => " + JSONObject.toJSONString(preloadQueue)); + // 前置加载处理 + for (CusRequestBeforeHandle handle : preloadQueue) { + handle.handle(cusRequest, method, args); + } + // 扫描执行handle包下面的所有加了CusHandle注解的实现方法并按order进行排序 包的顺序随机 + HashMap> scan = HandleUtil.scanHandle(); + log.info("scan => " + JSONObject.toJSONString(scan)); + for (Map.Entry> entry : scan.entrySet()) { + List value = entry.getValue(); + List collect = value.stream().sorted(Comparator.comparingInt(CusHandleEntity::getOrder)).collect(Collectors.toList()); + log.info("扫描到的handle : " + JSONObject.toJSONString(collect)); + for (CusHandleEntity handle : collect) { + Class handleClass = handle.getHandleClass(); + if (CusRequestBeforeHandle.class.isAssignableFrom(handleClass)) { + CusRequestBeforeHandle o = (CusRequestBeforeHandle) handleClass.newInstance(); + o.handle(cusRequest, method, args); + } + } + } + }catch (Exception e){ + throw new CustomerException("execute requestBeforeHandle error! " + e.getMessage()); + } + } + + public ResponeVo requestHandle(CusRequestEntity cusRequest, Method method){ + try { + CusRequestType requestType = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestType.class); + return requestHandle.get(requestType.requestType()).execute(cusRequest); + }catch (Exception e){ + throw new CustomerException("request error! " + e.getMessage()); + } + } + + 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); + } + } +// Type genericReturnType = method.getGenericReturnType(); + cusRequest.setReturnType(method.getReturnType()); + CusResponseSuccessHandle cusResponseSuccessHandle = method.getDeclaredAnnotation(CusResponseSuccessHandle.class); + if(cusResponseSuccessHandle != null && cusRequest.getResponseSuccessHandle() == null){ + cusRequest.setResponseSuccessHandle(cusResponseSuccessHandle); + } + return requestAfterHandle(cusRequest, responseVo); + } + + private Object requestAfterHandle(CusRequestEntity cusRequest, ResponeVo responseVo){ + if(responseVo == null){ + throw new CustomerException("CusRequestAfterHandle responseVo is null!"); + } + int code = responseVo.getCode(); + if(CusRequestClientConstant.HTTP_SUCCESS_CODE != code){ + String url = cusRequest.getUrl(); + log.error(Util.logStr("can not fetch [{}],this request params is [{}]," + // 构建日志字符串 + "this request heard is [{}],but response status code is [{}]," + + "this response is [{}]", cusRequest.getUrl(), JSON.toJSON(cusRequest.getBodyParams()), JSON.toJSONString(cusRequest.getHeaders()), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // + } + CusRequestAfterHandle handle = cusRequest.getCusRequestAfter() == null ? new CusDefaultRequestAfterHandle() : cusRequest.getCusRequestAfter(); + cusRequest.setCusRequestAfter(handle); + log.info(Util.logStr("cusRequest: {}", JSONObject.toJSONString(cusRequest))); + Object res = handle.parseResponse(cusRequest, responseVo); + handle.service(cusRequest, responseVo); + return res; + } + + + public void registerPreHandle(CusRequestBeforeHandle handle){ + preloadQueue.add(handle); + } + +} diff --git a/src/test/java/xuanran/wang/http_test/handle/CusRequestAfterHandle.java b/src/test/java/xuanran/wang/http_test/handle/CusRequestAfterHandle.java new file mode 100644 index 0000000..543f6b0 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/CusRequestAfterHandle.java @@ -0,0 +1,31 @@ +package xuanran.wang.http_test.handle; + +import aiyh.utils.httpUtil.ResponeVo; +import xuanran.wang.http_test.entity.CusRequestEntity; + + +/** + *

请求后处理器

+ * + * @author xuanran.wang + * @date 2023/3/16 23:57 + */ +public interface CusRequestAfterHandle{ + /** + *

解析响应方法

+ * @author xuanran.wang + * @dateTime 2023/3/24 15:32 + * @param cusRequest 请求对象 + * @param responseVo 响应对象 + **/ + Object parseResponse(CusRequestEntity cusRequest, ResponeVo responseVo); + + /** + *

do something

+ * @author xuanran.wang + * @dateTime 2023/3/24 15:32 + * @param cusRequest 请求对象 + * @param responseVo 响应对象 + **/ + void service(CusRequestEntity cusRequest, ResponeVo responseVo); +} diff --git a/src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java b/src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java index 48faa20..4e0e80b 100644 --- a/src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/CusRequestBeforeHandle.java @@ -10,6 +10,6 @@ import java.lang.reflect.Method; * @author xuanran.wang * @date 2023/3/10 11:38 */ -public interface RequestBeforeHandle { - void handle(CusRequestEntity requestEntity, Method method, Object[] args); +public interface CusRequestBeforeHandle { + void handle(CusRequestEntity cusRequest, Method method, Object[] args); } diff --git a/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java b/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java new file mode 100644 index 0000000..06901f6 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/CusRequestHandle.java @@ -0,0 +1,42 @@ +package xuanran.wang.http_test.handle; + +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import xuanran.wang.http_test.entity.CusRequestEntity; + +import java.io.IOException; +import java.lang.reflect.Method; + +/** + *

请求参数初始化之后请求之前handle

+ * + * @author xuanran.wang + * @date 2023/3/16 23:21 + */ +public abstract class CusRequestHandle { + protected HttpUtils httpUtils = new HttpUtils(); + + protected final ResponeVo execute(CusRequestEntity cusRequest) throws IOException{ + String host = cusRequest.getHost(); + int port = cusRequest.getPort(); + String url = cusRequest.getUrl(); + StringBuilder realRequestUrl = new StringBuilder(); + if(url.startsWith("http:") || url.startsWith("https:")){ + realRequestUrl.append(url); + }else { + realRequestUrl.append(host); + if(!host.endsWith(":")){ + realRequestUrl.append(":"); + } + realRequestUrl.append(port); + if(!url.endsWith("/")){ + realRequestUrl.append("/"); + } + realRequestUrl.append(url); + } + cusRequest.setUrl(realRequestUrl.toString()); + return request(cusRequest); + } + // 执行具体的请求方法 + protected abstract ResponeVo request(CusRequestEntity cusRequest) throws IOException; +} 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 new file mode 100644 index 0000000..7baeadb --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/header_handle/RequestHeaderHandle.java @@ -0,0 +1,84 @@ +package xuanran.wang.http_test.handle.header_handle; +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import xuanran.wang.http_test.annotations.handle.CusHandle; +import xuanran.wang.http_test.annotations.header.CusRequestHeader; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestBeforeHandle; +import xuanran.wang.http_test.interfaces.CusCreateRequestHeader; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.HashMap; +import java.util.Map; + +/** + *

请求头处理

+ * + * @author xuanran.wang + * @date 2023/3/10 14:42 + */ +@CusHandle +public class RequestHeaderHandle implements CusRequestBeforeHandle { + + @Override + public void handle(CusRequestEntity cusRequest, Method method, Object[] args) { + CusRequestHeader methodCusRequestHeader = method.getDeclaredAnnotation(CusRequestHeader.class); + if(methodCusRequestHeader == null){ + return; + } + // 数组形式 + String[] headersArr = methodCusRequestHeader.cusHeaders(); + HashMap headers = new HashMap<>(); + if(headersArr != null){ + for (String headerStr : headersArr) { + String[] split = headerStr.split(":"); + String key = Util.null2DefaultStr(split[0],"").trim(); + String val = Util.null2DefaultStr(split[1],"").trim(); + if(StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)){ + headers.put(key, val); + } + } + } + + // java代码自定义 + String path = Util.null2DefaultStr(methodCusRequestHeader.cusHeadersClassPath(),""); + if(StringUtils.isNotBlank(path)){ + Class clazz; + try { + clazz = Class.forName(path); + } catch (ClassNotFoundException e) { + throw new CustomerException(Util.logStr("自定义请求头java类文件没找到!: {}", path)); + } + if(!CusCreateRequestHeader.class.isAssignableFrom(clazz)){ + throw new CustomerException(Util.logStr("当前类路径:[{}] ,未实现CusCreateRequestHeader接口!", path)); + } + CusCreateRequestHeader o; + try { + o = (CusCreateRequestHeader) clazz.newInstance(); + }catch (InstantiationException | IllegalAccessException e) { + throw new CustomerException(Util.logStr("实例化 [{}] 对象失败! error:{}", path, e.getMessage())); + } + Map cusCreateHeader = o.createHeader(); + if(MapUtils.isNotEmpty(cusCreateHeader)){ + headers.putAll(cusCreateHeader); + } + } + // 参数中 + Parameter[] parameters = method.getParameters(); + for (int i = 0; i < parameters.length; i++) { + 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); + } + } + } + cusRequest.getHeaders().putAll(headers); + } +} diff --git a/src/test/java/xuanran/wang/http_test/handle/path_handle/CusBodyParseHandle.java b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusBodyParseHandle.java new file mode 100644 index 0000000..03735dd --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusBodyParseHandle.java @@ -0,0 +1,39 @@ +package xuanran.wang.http_test.handle.path_handle; + +import aiyh.utils.excention.CustomerException; +import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil; +import org.springframework.web.bind.annotation.RequestBody; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.annotations.body.CusRequestBody; +import xuanran.wang.http_test.annotations.request_type.CusRequestType; +import xuanran.wang.http_test.constant.CusRequestClientConstant; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestBeforeHandle; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Map; + +/** + *

请求体处理

+ * + * @author xuanran.wang + * @date 2023/3/20 21:21 + */ +public class CusBodyParseHandle implements CusRequestBeforeHandle { + @Override + public void handle(CusRequestEntity cusRequest, Method method, Object[] args) { + Parameter[] parameters = method.getParameters(); + for (int i = 0; i < parameters.length; i++) { + Parameter parameter = parameters[i]; + CusRequestBody requestBody = parameter.getDeclaredAnnotation(CusRequestBody.class); + CusRequestType requestType = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestType.class); + if(null != requestBody && + null != requestType && + requestType.requestType() != CusRequestClientConstant.GET){ + cusRequest.setBodyParams(args[i]); + } + } + } +} diff --git a/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java index d9cf5b8..dc874d8 100644 --- a/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java +++ b/src/test/java/xuanran/wang/http_test/handle/path_handle/CusPathParseHandle.java @@ -2,9 +2,10 @@ package xuanran.wang.http_test.handle.path_handle; import aiyh.utils.Util; import org.apache.commons.lang3.StringUtils; +import xuanran.wang.http_test.annotations.handle.CusHandle; import xuanran.wang.http_test.annotations.request_path.CusPathQuery; import xuanran.wang.http_test.entity.CusRequestEntity; -import xuanran.wang.http_test.handle.RequestBeforeHandle; +import xuanran.wang.http_test.handle.CusRequestBeforeHandle; import java.lang.reflect.Method; import java.lang.reflect.Parameter; @@ -16,11 +17,12 @@ import java.util.Map; * @author xuanran.wang * @date 2023/3/14 23:11 */ -public class CusFieldKeyParseHandle implements RequestBeforeHandle { +@CusHandle +public class CusPathParseHandle implements CusRequestBeforeHandle { @Override - public void handle(CusRequestEntity requestEntity, Method method, Object[] args) { + public void handle(CusRequestEntity cusRequest, Method method, Object[] args) { Parameter[] parameters = method.getParameters(); - String url = requestEntity.getUrl(); + String url = cusRequest.getUrl(); for (int i = 0; i < parameters.length; i++) { Parameter parameter = parameters[i]; CusPathQuery cusPathQuery = parameter.getDeclaredAnnotation(CusPathQuery.class); @@ -33,11 +35,11 @@ public class CusFieldKeyParseHandle implements RequestBeforeHandle { }else { Class clazz = parameter.getType(); if(clazz.isAssignableFrom(Map.class)){ - requestEntity.getPathParams().putAll((Map) arg); + cusRequest.getPathParams().putAll((Map) arg); } } } } - requestEntity.setUrl(url); + cusRequest.setUrl(url); } } diff --git a/src/test/java/xuanran/wang/http_test/handle/path_handle/TestHandle.java b/src/test/java/xuanran/wang/http_test/handle/path_handle/TestHandle.java new file mode 100644 index 0000000..3133ded --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/path_handle/TestHandle.java @@ -0,0 +1,22 @@ +package xuanran.wang.http_test.handle.path_handle; + +import xuanran.wang.http_test.annotations.handle.CusHandle; +import xuanran.wang.http_test.annotations.handle.CusPreLoadHandle; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestBeforeHandle; + +import java.lang.reflect.Method; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/16 16:22 + */ +@CusHandle +public class TestHandle implements CusRequestBeforeHandle { + @Override + public void handle(CusRequestEntity cusRequest, Method method, Object[] args) { + System.out.println("TestHandle 111"); + } +} 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 new file mode 100644 index 0000000..500e3c0 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusDefaultRequestAfterHandle.java @@ -0,0 +1,47 @@ +package xuanran.wang.http_test.handle.request_handle; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; +import xuanran.wang.http_test.constant.CusRequestClientConstant; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestAfterHandle; + +import java.util.Map; + +/** + *

默认的请求后处理响应类

+ * + * @author xuanran.wang + * @date 2023/3/17 11:03 + */ +public class CusDefaultRequestAfterHandle implements CusRequestAfterHandle { + + @Override + public Object parseResponse(CusRequestEntity cusRequest, ResponeVo responseVo) { + Class returnType = cusRequest.getReturnType(); + if(ResponeVo.class.isAssignableFrom(returnType)) { + return responseVo; + } + String json = responseVo.getEntityString(); + cusRequest.setResponseMap(responseVo.getResponseMap()); + CusResponseSuccessHandle responseSuccessHandle = cusRequest.getResponseSuccessHandle(); + if(responseSuccessHandle != null){ + String successCondition = responseSuccessHandle.successCondition(); + String str = successCondition.substring(0, successCondition.lastIndexOf("}") + 1); + json = Util.null2DefaultStr(CusRequestClientConstant.CONVERT + .get(str) + .apply(cusRequest),""); + } + return JSONObject.parseObject(json, returnType); + } + + @Override + public void service(CusRequestEntity cusRequest, ResponeVo responeVo){ + + } + +} diff --git a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestGetHandle.java b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestGetHandle.java new file mode 100644 index 0000000..6d8b84c --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestGetHandle.java @@ -0,0 +1,21 @@ +package xuanran.wang.http_test.handle.request_handle; + +import aiyh.utils.httpUtil.ResponeVo; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestHandle; + +import java.io.IOException; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/16 23:20 + */ +public class CusRequestGetHandle extends CusRequestHandle { + + @Override + protected ResponeVo request(CusRequestEntity cusRequest) throws IOException { + return httpUtils.apiGet(cusRequest.getUrl(), cusRequest.getPathParams(), cusRequest.getHeaders()); + } +} diff --git a/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestPostHandle.java b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestPostHandle.java new file mode 100644 index 0000000..56719ea --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusRequestPostHandle.java @@ -0,0 +1,21 @@ +package xuanran.wang.http_test.handle.request_handle; + +import aiyh.utils.httpUtil.ResponeVo; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestHandle; + +import java.io.IOException; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/16 23:20 + */ +public class CusRequestPostHandle extends CusRequestHandle { + + @Override + protected ResponeVo request(CusRequestEntity cusRequest) throws IOException { + return httpUtils.apiPostObject(cusRequest.getUrl(), cusRequest.getBodyParams(), cusRequest.getHeaders()); + } +} 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 new file mode 100644 index 0000000..d5c9edb --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/request_handle/CusUrlHandle.java @@ -0,0 +1,29 @@ +package xuanran.wang.http_test.handle.request_handle; + +import aiyh.utils.excention.CustomerException; +import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil; +import xuanran.wang.http_test.annotations.CusRequestUrl; +import xuanran.wang.http_test.annotations.request_type.CusRequestType; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.CusRequestBeforeHandle; + +import java.lang.reflect.Method; + +/** + *

方法路径拼接处理

+ * + * @author xuanran.wang + * @date 2023/3/16 19:51 + */ +public class CusUrlHandle implements CusRequestBeforeHandle { + @Override + public void handle(CusRequestEntity cusRequest, Method method, Object[] args) { + CusRequestUrl requestUrl = AnnotationUtil.getSynthesizedAnnotation(method, CusRequestUrl.class); + if(requestUrl == null){ + throw new CustomerException("method not found CusRequestUrl!"); + } + cusRequest.setUrl(requestUrl.url()); + Class returnType = method.getReturnType(); + cusRequest.setReturnType(returnType); + } +} diff --git a/src/test/java/xuanran/wang/http_test/handle/util/HandleUtil.java b/src/test/java/xuanran/wang/http_test/handle/util/HandleUtil.java new file mode 100644 index 0000000..1590e99 --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/handle/util/HandleUtil.java @@ -0,0 +1,179 @@ +package xuanran.wang.http_test.handle.util; + +import aiyh.utils.excention.CustomerException; +import ebu7common.youhong.ai.bean.Builder; +import xuanran.wang.http_test.annotations.handle.CusHandle; +import xuanran.wang.http_test.entity.CusHandleEntity; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/16 15:42 + */ +public class HandleUtil { + /** + *

扫描指定路径下对class文件

+ * @author xuanran.wang + * @dateTime 2023/3/16 16:02 + * @return class + **/ + public static HashMap> scanHandle() throws ClassNotFoundException{ + String packageName = HandleUtil.class.getPackage().getName(); + return scan(packageName.substring(0, packageName.lastIndexOf("."))); + } + + /** + * 扫描指定路径下的类文件 + * + * @param packagePath 包路径 + */ + private static HashMap> scan(String packagePath) throws ClassNotFoundException { + // 转化包路径为文件路径 + String scanPath = packagePath.replace(".", "/"); + // 扫描 + ClassLoader classLoader = HandleUtil.class.getClassLoader(); + URL resource = classLoader.getResource(scanPath); + Set fileNameSet = new LinkedHashSet<>(); + if (resource == null) { + throw new CustomerException("package is not found! :" + packagePath); + } + String rootPath = getRootPath(resource); + if (isJarFile(resource.getFile())) { + try { + // 是jar包使用JarInputStream + JarInputStream jarInputStream = new JarInputStream(Files.newInputStream(Paths.get(rootPath))); + JarEntry nextJarEntry = jarInputStream.getNextJarEntry(); + // 遍历 + while (null != nextJarEntry) { + String name = nextJarEntry.getName(); + // 如果是指定包名下的文件并且是.class结尾,那就保存它 + if (name.startsWith(scanPath) && isClassFile(name)) { + fileNameSet.add(name.replace(".class", "")); + } + nextJarEntry = jarInputStream.getNextJarEntry(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + // 是文件夹,获取该文件夹下所有文件 + Set allFilePath = getAllFilePath(rootPath); + for (String filePath : allFilePath) { + fileNameSet.add(transFilePathToPackagePath(filePath, scanPath)); + } + } + HashMap> maps = new HashMap<>(); + for (String fileName : fileNameSet) { + String packageName = fileName.substring(0, fileName.lastIndexOf(".")); + Class scanClass = Class.forName(fileName, false, HandleUtil.class.getClassLoader()); + CusHandle annotation = scanClass.getAnnotation(CusHandle.class); + if(null != annotation){ + CusHandleEntity cusHandleEntity = Builder.builder(CusHandleEntity::new) + .with(CusHandleEntity::setHandleClass, scanClass) + .with(CusHandleEntity::setOrder, annotation.order()) + .with(CusHandleEntity::setPackageName, packageName) + .build(); + List cusHandleEntities = new ArrayList<>(); + if(maps.containsKey(packageName)){ + cusHandleEntities = maps.get(packageName); + } + cusHandleEntities.add(cusHandleEntity); + maps.put(packageName, cusHandleEntities); + } + } + return maps; + } + + /** + * 遍历获取某个文件下所有文件名称 + * + * @param path path + * @return Set + */ + private static Set getAllFilePath(String path) { + Set fileSet = new LinkedHashSet<>(); + File file = new File(path); + return getAllFilePath(fileSet, file); + } + + /** + * 递归遍历获取某个文件下所有文件名称 + * + * @param fileSet fileSet + * @param file 源文件 + * @return Set + */ + private static Set getAllFilePath(Set fileSet, File file) { + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files != null) { + for (File file1 : files) { + getAllFilePath(fileSet, file1); + } + } + } else { + if (isClassFile(file.getAbsolutePath())) { + fileSet.add(file.getAbsolutePath()); + } + return fileSet; + } + return fileSet; + } + + /** + * 把文件路径转为包路径 + * + * @param filePath filePath + * @param scanPath 扫描路径 + * @return String + */ + private static String transFilePathToPackagePath(String filePath, String scanPath) { + filePath = filePath.replace("\\", "/"); + String substring = filePath.substring(filePath.indexOf(scanPath), filePath.indexOf(".class")); + return substring.replace("\\", ".").replace("/", "."); + } + + /** + * 判断一个文件是不是jar包 + * + * @param fileName fileName + * @return true-是,false-否 + */ + private static boolean isJarFile(String fileName) { + return fileName.contains(".jar!"); + } + + /** + * 判断一个文件class文件 + * + * @param fileName fileName + * @return true-是,false-否 + */ + private static boolean isClassFile(String fileName) { + return fileName.endsWith(".class"); + } + + /** + * 获取文件路径 + * + * @param url url + * @return String + */ + private static String getRootPath(URL url) { + String path = url.getFile(); + if (path.contains("!")) { + return path.substring(5, path.indexOf("!")); + } + return path; + } + +} 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 f0c7cc2..169237b 100644 --- a/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java +++ b/src/test/java/xuanran/wang/http_test/proxy/RequestUtil.java @@ -3,30 +3,21 @@ package xuanran.wang.http_test.proxy; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; import aiyh.utils.httpUtil.ResponeVo; -import aiyh.utils.httpUtil.util.HttpUtils; -import com.alibaba.fastjson.JSON; +import aiyh.utils.tool.cn.hutool.core.annotation.AnnotationUtil; import com.alibaba.fastjson.JSONObject; import org.apache.log4j.Logger; import xuanran.wang.http_test.annotations.*; -import xuanran.wang.http_test.annotations.async.CusAsync; -import xuanran.wang.http_test.annotations.request_type.CusRequestDelete; -import xuanran.wang.http_test.annotations.request_type.CusRequestGet; -import xuanran.wang.http_test.annotations.request_type.CusRequestPost; -import xuanran.wang.http_test.annotations.request_type.CusRequestPut; -import xuanran.wang.http_test.constant.RequestUtilConstant; +import xuanran.wang.http_test.annotations.handle.CusReqAfterHandleRegister; +import xuanran.wang.http_test.annotations.handle.CusResponseSuccessHandle; import xuanran.wang.http_test.entity.CusRequestEntity; -import xuanran.wang.http_test.handle.*; -import xuanran.wang.http_test.handle.path_handle.CusFieldKeyParseHandle; +import xuanran.wang.http_test.handle.CusHandleCenter; +import xuanran.wang.http_test.handle.CusRequestAfterHandle; -import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import java.lang.reflect.Parameter; import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; + /** *

声明式发送http请求

@@ -36,57 +27,59 @@ import java.util.function.Function; */ public class RequestUtil implements InvocationHandler { private CusRequestAddress cusRequestAddress = null; - private final HttpUtils httpUtils = new HttpUtils(); private final Logger log = Util.getLogger(); - private boolean async = false; + private final CusHandleCenter handleCenter = new CusHandleCenter(); + private final CusRequestEntity cusRequest = new CusRequestEntity(); public T getRequestClient(Class clazz){ - Annotation annotation = clazz.getDeclaredAnnotation(CusRequest.class); + Annotation annotation = clazz.getDeclaredAnnotation(CusRequestClient.class); if(annotation == null){ - throw new CustomerException("该类未添加CusRequest注解!"); + throw new CustomerException(Util.logStr(clazz.getName() + " not found CusRequestClient annotation!")); + } + // 请求后处理 + CusReqAfterHandleRegister cusReqAfterHandleRegister = clazz.getDeclaredAnnotation(CusReqAfterHandleRegister.class); + if(cusReqAfterHandleRegister != null){ + setCusRequestAfter(cusReqAfterHandleRegister, cusRequest); + } + // 响应处理 + CusResponseSuccessHandle cusResponseSuccessHandle = clazz.getDeclaredAnnotation(CusResponseSuccessHandle.class); + if(cusResponseSuccessHandle != null){ + cusRequest.setResponseSuccessHandle(cusResponseSuccessHandle); } cusRequestAddress = clazz.getDeclaredAnnotation(CusRequestAddress.class); - if(null != clazz.getDeclaredAnnotation(CusAsync.class)){ - async = true; - } + cusRequestAddress = AnnotationUtil.getSynthesizedAnnotation(clazz, CusRequestAddress.class); +// if(null != clazz.getDeclaredAnnotation(CusAsync.class)){ +// async = true; +// } return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, this); } @Override public Object invoke(Object proxy, Method method, Object[] args) { - StringBuilder url = new StringBuilder(); - CusRequestEntity cusRequest = new CusRequestEntity(); if(cusRequestAddress != null){ String host = Util.null2DefaultStr(cusRequestAddress.host(),""); int port = Util.getIntValue( Util.null2DefaultStr(cusRequestAddress.port(),""),0); - url.append(host) - .append(":") - .append(port); - cusRequest.setUrl(url.toString()); + cusRequest.setHost(host); + cusRequest.setPort(port); } - CusFieldKeyParseHandle keyParseHandle = new CusFieldKeyParseHandle(); - keyParseHandle.handle(cusRequest, method, args); - log.info("cusRequest : \n" + JSONObject.toJSONString(cusRequest)); - return ""; + handleCenter.requestBeforeHandle(cusRequest, method, args); + log.info("requestHandle : \n" + JSONObject.toJSONString(cusRequest)); + ResponeVo responeVo = handleCenter.requestHandle(cusRequest, method); + return handleCenter.requestAfterHandle(method, cusRequest, responeVo); } - private String appendPath(StringBuilder url, String path){ - if(!path.endsWith("/")){ - url.append("/"); - } - url.append(path); - return url.toString(); - } - - public Object get(String url, Map params, Map headers) throws IOException { - return httpUtils.apiGet(url, params, headers); - } - - public static boolean isJSON(String str) { - try { - JSON.parse(str); - return true; - } catch (Exception e) { - return false; + 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())); + } + } } } + } 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 00e770b..e74ea59 100644 --- a/src/test/java/xuanran/wang/http_test/service/TestService.java +++ b/src/test/java/xuanran/wang/http_test/service/TestService.java @@ -1,11 +1,15 @@ package xuanran.wang.http_test.service; -import aiyh.utils.httpUtil.ResponeVo; import xuanran.wang.http_test.annotations.*; +import xuanran.wang.http_test.annotations.body.CusRequestBody; +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 java.util.List; import java.util.Map; /** @@ -14,19 +18,20 @@ import java.util.Map; * @author xuanran.wang * @date 2023/3/10 12:39 */ -@CusRequest -@CusRequestAddress(host = "http://114.115.168.220/educate-plat/api/v1/class/getClassList/{test}", port = 8191) +@CusRequestClient(host = "http://114.115.168.220", port = 8191) +//@CusReqAfterHandleRegister(afterHandle = TestRequestAfterHandle.class) public interface TestService { - - @CusRequestGet(url = "educate-plat/api/v1/class/getClassList/{test}") - @CusRequestHeader(cusHeaders = {"sa: sasa", "sas:11212"}) - String getStu(Map path, - @PostBody Map body, - @CusRequestHeader("hsjhdsad") String test, - @CusPathQuery("test") String test1); - - @CusRequestPost(url = "test/post/sas") - @CusRequestHeader(cusHeaders = {"content-Type: application/json"}, cusHeadersClassPath = "java.fsdfds") - String getStu(@PostBody Map body); + @CusRequestGet(url = "educate-plat/api/v1/class/getClassList") + @CusRequestHeader(cusHeaders = {"sa: sasa", "sas:11212","content-Type:application/json"}) + @CusResponseSuccessHandle( + successKey = "code", + successCondition = CusRequestClientConstant.EQUALS + " 0 ", + errorMsg = "msg", + data = "data" + ) + Map 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 ca18084..7b3dccf 100644 --- a/src/test/java/xuanran/wang/http_test/test/RequestTest.java +++ b/src/test/java/xuanran/wang/http_test/test/RequestTest.java @@ -1,13 +1,18 @@ package xuanran.wang.http_test.test; -import aiyh.utils.httpUtil.ResponeVo; import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.api.doc.migrate.util.FtpUtil; +import com.jcraft.jsch.ChannelSftp; import org.junit.Test; +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.proxy.RequestUtil; import xuanran.wang.http_test.service.TestService; -import java.util.HashMap; +import java.util.*; +import java.util.stream.Collectors; /** *

@@ -24,7 +29,6 @@ public class RequestTest extends BaseTest { map.put("a","1"); map.put("b","2"); HashMap body = new HashMap<>(); - body.put("a","3"); body.put("b","4"); @@ -32,10 +36,29 @@ public class RequestTest extends BaseTest { path.put("e","5"); path.put("f","6"); - requestClient.getStu(map, body, "a", "test1111"); + Map stu = requestClient.getStu(map, body, "a", "test1111"); + log.info("stu : \n" + JSONObject.toJSONString(stu)); +// 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); + } + + @Test + public void testA(){ + try { + HashMap> scan = HandleUtil.scanHandle(); + for (Map.Entry> entry : scan.entrySet()) { + List value = entry.getValue(); + List collect = value.stream().sorted(Comparator.comparingInt(CusHandleEntity::getOrder)).collect(Collectors.toList()); + log.info("collect : " + JSONObject.toJSONString(collect)); + } + log.info("scan => " + JSONObject.toJSONString(scan)); + }catch (Exception e){ + log.info("erro => " + e.getMessage()); + } + } } diff --git a/src/test/java/xuanran/wang/http_test/test/TestRequestAfterHandle.java b/src/test/java/xuanran/wang/http_test/test/TestRequestAfterHandle.java new file mode 100644 index 0000000..a55804d --- /dev/null +++ b/src/test/java/xuanran/wang/http_test/test/TestRequestAfterHandle.java @@ -0,0 +1,20 @@ +package xuanran.wang.http_test.test; + +import aiyh.utils.httpUtil.ResponeVo; +import xuanran.wang.http_test.entity.CusRequestEntity; +import xuanran.wang.http_test.handle.request_handle.CusDefaultRequestAfterHandle; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/20 14:48 + */ +public class TestRequestAfterHandle extends CusDefaultRequestAfterHandle { + + @Override + public void service(CusRequestEntity cusRequest, ResponeVo responseVo) { + System.out.println("============== ceshi xia ==============="); + } + +} diff --git a/src/test/java/xuanran/wang/immc/Kafka/MQTest.java b/src/test/java/xuanran/wang/immc/Kafka/MQTest.java new file mode 100644 index 0000000..d2d69fe --- /dev/null +++ b/src/test/java/xuanran/wang/immc/Kafka/MQTest.java @@ -0,0 +1,363 @@ +package xuanran.wang.immc.Kafka; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.sun.tools.internal.ws.wsdl.document.soap.SOAPUse; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.junit.Test; + +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.Future; +import java.util.stream.Collectors; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.springframework.beans.BeanUtils; +import weaver.conn.RecordSet; +import weaver.workflow.request.todo.RequestStatusObj; +import weaver.xuanran.wang.common.annocation.SqlFieldMapping; +import weaver.xuanran.wang.common.annocation.SqlUpdateWhereField; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; +import weaver.xuanran.wang.sh_bigdata.common.util.SendTodoTaskUtil; +import weaver.xuanran.wang.sh_bigdata.common.util.ShBigDataUtil; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.entity.OtherSysDepartment; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.OrgHrmAsyncApiService; +import weaver.xuanran.wang.sh_bigdata.org_hrm_async.service.impl.OrgHrmAsyncApiServiceImpl; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTask; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusDoneTaskOA; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTask; +import weaver.xuanran.wang.sh_bigdata.task_async.entity.CusTodoTaskToOADetail; +import weaver.xuanran.wang.sh_bigdata.task_async.mapper.SendTodoTaskMapper; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/30 11:06 + */ +public class MQTest extends BaseTest { + + @Test + public void testProducer(){ + // 设置Kafka生产者的配置属性 + Properties props = new Properties(); + props.put("bootstrap.servers", "10.184.42.41:9094,10.184.42.42:9094,10.184.42.40:9094"); +// props.put("acks", "all"); +// props.put("retries", 0); +// props.put("batch.size", 16384); +// props.put("linger.ms", 1); +// props.put("buffer.memory", 33554432); + props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); + props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); + Map configMap = Util.getProperties2Map("VmsKafka"); + if(MapUtils.isEmpty(configMap)){ + throw new CustomerException("please check /web-inf/prop2map has VmsKafka.properties"); + } + // 创建Kafka生产者实例 + KafkaProducer producer =new KafkaProducer(configMap); + + // 发送消息到指定主题 + String topic = "oa_service_immc_topic_uat"; + String message = "Hello, Kafka!"; + ProducerRecord record = new ProducerRecord<>(topic, message); + Future send = producer.send(record); + + // 关闭Kafka生产者实例 + producer.close(); + + + + } + + @Test + public void testA(){ + RecordSet rs = new RecordSet(); + rs.executeQuery("select je from formtable_main_20 where requestid = ?", 353354); + rs.next(); + Map mapMapping = getMapMapping(rs); + System.out.println("mapMapping => " + JSONObject.toJSONString(mapMapping)); + } + + @Test + public void testB(){ + String json = "{\n" + + " \"errcode\":0,\n" + + " \"errmsg\":\"ok\",\n" + + " \"access_token\": \"accesstoken000001\",\n" + + " \"expires_in\": 7200\n" + + "}"; + Map map = JSONObject.parseObject(json, Map.class); + String dataKey = "access_token"; + String parse = parse(map, dataKey).toString(); + System.out.println("parse => " +JSONObject.toJSONString(parse)); + } + + public T parse(Map response, String dataKey){ + dataKey = Util.null2DefaultStr(dataKey, ""); + String[] split = 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]); + } + + private static Map getMapMapping(RecordSet rs) { + Map map = new HashMap<>(); + String[] columnType = rs.getColumnTypeName(); + int colCounts; + colCounts = rs.getColCounts() == 0 ? columnType.length : rs.getColCounts(); + for (int i = 1; i <= colCounts; i++) { + String key; + String type = "varchar"; + if (columnType != null) { + if (columnType.length != colCounts) { + type = "varchar"; + } else { + type = columnType[i - 1]; + } + } + key = rs.getColumnName(i).toLowerCase(); + if ("int".equalsIgnoreCase(type) || "Integer".equalsIgnoreCase(type) + || "Long".equalsIgnoreCase(type) || "BIGINT".equalsIgnoreCase(type) + || "NUMBER".equalsIgnoreCase(type) || "INTEGER".equalsIgnoreCase(type) + || "TINYINT".equalsIgnoreCase(type) || "SMALLINT".equalsIgnoreCase(type)) { + map.put(key, rs.getInt(i) == -1 ? rs.getString(i) : rs.getInt(i)); + continue; + } + if ("FLOAT".equalsIgnoreCase(type)) { + map.put(key, rs.getFloat(i)); + continue; + } + if ("DATE".equalsIgnoreCase(type) || "TIMESTAMP".equalsIgnoreCase(type) + || "DATETIME".equalsIgnoreCase(type)) { + map.put(key, rs.getString(i)); + continue; + } + if ("DOUBLE".equalsIgnoreCase(type)) { + map.put(key, rs.getDouble(i)); + continue; + } + if ("DECIMAL".equalsIgnoreCase(type) || "NUMERIC".equalsIgnoreCase(type)) { + String val = weaver.general.Util.null2String(rs.getString(i)); + BigDecimal decimal; + if(StringUtils.isBlank(val)){ + decimal = new BigDecimal("0"); + }else { + decimal = new BigDecimal(val); + } + map.put(key, decimal); + continue; + } + map.put(key, rs.getString(i)); + } + return map; + } + + private final OrgHrmAsyncApiService orgHrmAsyncApiService = new OrgHrmAsyncApiServiceImpl(); + @Test + public void testC(){ + String json = "[{\"id\":1,\"name\":\"上海市\",\"parentid\":-1,\"order\":100000000,\"hasChild\":1},{\"id\":2,\"name\":\"市委\",\"parentid\":1,\"order\":100000000,\"hasChild\":0},{\"id\":14,\"name\":\"市人大\",\"parentid\":1,\"order\":99999500,\"hasChild\":1},{\"id\":15,\"name\":\"市人大常委会办公厅\",\"parentid\":14,\"order\":100000000,\"hasChild\":0},{\"id\":16,\"name\":\"市政府\",\"parentid\":1,\"order\":99999000,\"hasChild\":1},{\"id\":18,\"name\":\"市政府办公厅\",\"parentid\":16,\"order\":99999500,\"hasChild\":1},{\"id\":19,\"name\":\"秘书处\",\"parentid\":18,\"order\":100000000,\"hasChild\":0},{\"id\":20,\"name\":\"督查室\",\"parentid\":18,\"order\":99999500,\"hasChild\":0},{\"id\":21,\"name\":\"建议提案处\",\"parentid\":18,\"order\":99999000,\"hasChild\":0},{\"id\":22,\"name\":\"综合处\",\"parentid\":18,\"order\":99998500,\"hasChild\":0},{\"id\":23,\"name\":\"区政处\",\"parentid\":18,\"order\":99998000,\"hasChild\":0},{\"id\":24,\"name\":\"联络处\",\"parentid\":18,\"order\":99997500,\"hasChild\":0},{\"id\":25,\"name\":\"总值班室\",\"parentid\":18,\"order\":99997000,\"hasChild\":0},{\"id\":26,\"name\":\"政务公开办公室\",\"parentid\":18,\"order\":99996500,\"hasChild\":0},{\"id\":27,\"name\":\"数据发展管理办\",\"parentid\":18,\"order\":99996000,\"hasChild\":0},{\"id\":28,\"name\":\"法律事务办\",\"parentid\":18,\"order\":99995500,\"hasChild\":0},{\"id\":29,\"name\":\"政府职能转变协调处\",\"parentid\":18,\"order\":99995000,\"hasChild\":0},{\"id\":30,\"name\":\"政务服务处\",\"parentid\":18,\"order\":99994500,\"hasChild\":0},{\"id\":31,\"name\":\"上海发布办公室\",\"parentid\":18,\"order\":99994000,\"hasChild\":0},{\"id\":32,\"name\":\"打击走私综合治理处\",\"parentid\":18,\"order\":99993500,\"hasChild\":0},{\"id\":33,\"name\":\"城运规划处\",\"parentid\":18,\"order\":99993000,\"hasChild\":0},{\"id\":34,\"name\":\"指挥协调处\",\"parentid\":18,\"order\":99992500,\"hasChild\":0},{\"id\":35,\"name\":\"党政办公室\",\"parentid\":18,\"order\":99992000,\"hasChild\":0},{\"id\":36,\"name\":\"人事处\",\"parentid\":18,\"order\":99991500,\"hasChild\":0},{\"id\":37,\"name\":\"行政处\",\"parentid\":18,\"order\":99991000,\"hasChild\":0},{\"id\":38,\"name\":\"驻办公厅纪检组\",\"parentid\":18,\"order\":99990500,\"hasChild\":0},{\"id\":39,\"name\":\"市大数据中心\",\"parentid\":18,\"order\":99990000,\"hasChild\":0},{\"id\":40,\"name\":\"文印中心\",\"parentid\":18,\"order\":99989500,\"hasChild\":0},{\"id\":41,\"name\":\"离退休干部管理服务中心\",\"parentid\":18,\"order\":99989000,\"hasChild\":0},{\"id\":42,\"name\":\"市发展改革委\",\"parentid\":16,\"order\":99999000,\"hasChild\":1},{\"id\":43,\"name\":\"委领导\",\"parentid\":42,\"order\":100000000,\"hasChild\":0},{\"id\":44,\"name\":\"内设机构\",\"parentid\":42,\"order\":99999500,\"hasChild\":0},{\"id\":45,\"name\":\"直属单位\",\"parentid\":42,\"order\":99999000,\"hasChild\":0},{\"id\":46,\"name\":\"市经济信息化委\",\"parentid\":16,\"order\":99998500,\"hasChild\":1},{\"id\":47,\"name\":\"委领导\",\"parentid\":46,\"order\":100000000,\"hasChild\":0},{\"id\":48,\"name\":\"内设机构\",\"parentid\":46,\"order\":99999500,\"hasChild\":0},{\"id\":49,\"name\":\"直属单位\",\"parentid\":46,\"order\":99999000,\"hasChild\":0},{\"id\":50,\"name\":\"市商务委\",\"parentid\":16,\"order\":99998000,\"hasChild\":1},{\"id\":51,\"name\":\"委领导\",\"parentid\":50,\"order\":100000000,\"hasChild\":0},{\"id\":52,\"name\":\"内设机构\",\"parentid\":50,\"order\":99999500,\"hasChild\":0},{\"id\":53,\"name\":\"直属单位\",\"parentid\":50,\"order\":99999000,\"hasChild\":0},{\"id\":54,\"name\":\"市教委\",\"parentid\":16,\"order\":99997500,\"hasChild\":1},{\"id\":55,\"name\":\"委领导\",\"parentid\":54,\"order\":100000000,\"hasChild\":0},{\"id\":56,\"name\":\"内设机构\",\"parentid\":54,\"order\":99999500,\"hasChild\":0},{\"id\":57,\"name\":\"直属单位\",\"parentid\":54,\"order\":99999000,\"hasChild\":0},{\"id\":58,\"name\":\"市科委\",\"parentid\":16,\"order\":99997000,\"hasChild\":1},{\"id\":59,\"name\":\"委领导\",\"parentid\":58,\"order\":100000000,\"hasChild\":0},{\"id\":60,\"name\":\"内设机构\",\"parentid\":58,\"order\":99999500,\"hasChild\":0},{\"id\":61,\"name\":\"直属单位\",\"parentid\":58,\"order\":99999000,\"hasChild\":0},{\"id\":62,\"name\":\"市民族宗教局\",\"parentid\":16,\"order\":99996500,\"hasChild\":1},{\"id\":63,\"name\":\"委领导\",\"parentid\":62,\"order\":100000000,\"hasChild\":0},{\"id\":64,\"name\":\"内设机构\",\"parentid\":62,\"order\":99999500,\"hasChild\":0},{\"id\":65,\"name\":\"直属单位\",\"parentid\":62,\"order\":99999000,\"hasChild\":0},{\"id\":66,\"name\":\"市公安局\",\"parentid\":16,\"order\":99996000,\"hasChild\":1},{\"id\":67,\"name\":\"委领导\",\"parentid\":66,\"order\":100000000,\"hasChild\":0},{\"id\":68,\"name\":\"内设机构\",\"parentid\":66,\"order\":99999500,\"hasChild\":0},{\"id\":69,\"name\":\"直属单位\",\"parentid\":66,\"order\":99999000,\"hasChild\":0},{\"id\":70,\"name\":\"市民政局\",\"parentid\":16,\"order\":99995500,\"hasChild\":1},{\"id\":71,\"name\":\"局领导\",\"parentid\":70,\"order\":100000000,\"hasChild\":0},{\"id\":72,\"name\":\"内设机构\",\"parentid\":70,\"order\":99999500,\"hasChild\":0},{\"id\":73,\"name\":\"直属单位\",\"parentid\":70,\"order\":99999000,\"hasChild\":0},{\"id\":74,\"name\":\"市司法局\",\"parentid\":16,\"order\":99995000,\"hasChild\":1},{\"id\":75,\"name\":\"局领导\",\"parentid\":74,\"order\":100000000,\"hasChild\":0},{\"id\":76,\"name\":\"内设机构\",\"parentid\":74,\"order\":99999500,\"hasChild\":0},{\"id\":77,\"name\":\"直属单位\",\"parentid\":74,\"order\":99999000,\"hasChild\":0},{\"id\":78,\"name\":\"市财政局\",\"parentid\":16,\"order\":99994500,\"hasChild\":1},{\"id\":79,\"name\":\"局领导\",\"parentid\":78,\"order\":100000000,\"hasChild\":0},{\"id\":80,\"name\":\"内设机构\",\"parentid\":78,\"order\":99999500,\"hasChild\":0},{\"id\":81,\"name\":\"直属单位\",\"parentid\":78,\"order\":99999000,\"hasChild\":0},{\"id\":82,\"name\":\"市人力资源社会保障局\",\"parentid\":16,\"order\":99994000,\"hasChild\":1},{\"id\":83,\"name\":\"局领导\",\"parentid\":82,\"order\":100000000,\"hasChild\":0},{\"id\":84,\"name\":\"内设机构\",\"parentid\":82,\"order\":99999500,\"hasChild\":0},{\"id\":85,\"name\":\"直属单位\",\"parentid\":82,\"order\":99999000,\"hasChild\":0},{\"id\":86,\"name\":\"市规划资源局\",\"parentid\":16,\"order\":99993500,\"hasChild\":1},{\"id\":87,\"name\":\"内设机构\",\"parentid\":86,\"order\":100000000,\"hasChild\":0},{\"id\":88,\"name\":\"直属单位\",\"parentid\":86,\"order\":99999500,\"hasChild\":0},{\"id\":89,\"name\":\"市生态环境局\",\"parentid\":16,\"order\":99993000,\"hasChild\":1},{\"id\":93,\"name\":\"市住房城乡建设管理委\",\"parentid\":16,\"order\":99992500,\"hasChild\":1},{\"id\":94,\"name\":\"委领导\",\"parentid\":93,\"order\":100000000,\"hasChild\":0},{\"id\":95,\"name\":\"内设机构\",\"parentid\":93,\"order\":99999500,\"hasChild\":0},{\"id\":96,\"name\":\"直属单位\",\"parentid\":93,\"order\":99999000,\"hasChild\":0},{\"id\":97,\"name\":\"市交通委\",\"parentid\":16,\"order\":99992000,\"hasChild\":1},{\"id\":98,\"name\":\"委领导\",\"parentid\":97,\"order\":100000000,\"hasChild\":0},{\"id\":99,\"name\":\"内设机构\",\"parentid\":97,\"order\":99999500,\"hasChild\":0},{\"id\":100,\"name\":\"直属单位\",\"parentid\":97,\"order\":99999000,\"hasChild\":0},{\"id\":101,\"name\":\"市农业农村委\",\"parentid\":16,\"order\":99991500,\"hasChild\":1},{\"id\":102,\"name\":\"委领导\",\"parentid\":101,\"order\":100000000,\"hasChild\":0},{\"id\":103,\"name\":\"内设机构\",\"parentid\":101,\"order\":99999500,\"hasChild\":0},{\"id\":104,\"name\":\"直属单位\",\"parentid\":101,\"order\":99999000,\"hasChild\":0},{\"id\":105,\"name\":\"市水务局\",\"parentid\":16,\"order\":99991000,\"hasChild\":1},{\"id\":107,\"name\":\"局机关\",\"parentid\":105,\"order\":100000000,\"hasChild\":1},{\"id\":108,\"name\":\"局属单位\",\"parentid\":105,\"order\":99999500,\"hasChild\":1},{\"id\":109,\"name\":\"市文化旅游局\",\"parentid\":16,\"order\":99990500,\"hasChild\":1},{\"id\":110,\"name\":\"局领导\",\"parentid\":109,\"order\":100000000,\"hasChild\":0},{\"id\":111,\"name\":\"内设机构\",\"parentid\":109,\"order\":99999500,\"hasChild\":0},{\"id\":112,\"name\":\"直属单位\",\"parentid\":109,\"order\":99999000,\"hasChild\":0},{\"id\":113,\"name\":\"市卫生健康委\",\"parentid\":16,\"order\":99990000,\"hasChild\":1},{\"id\":114,\"name\":\"委领导\",\"parentid\":113,\"order\":100000000,\"hasChild\":0},{\"id\":115,\"name\":\"内设机构\",\"parentid\":113,\"order\":99999500,\"hasChild\":0},{\"id\":116,\"name\":\"直属单位\",\"parentid\":113,\"order\":99999000,\"hasChild\":0},{\"id\":117,\"name\":\"市退役军人局\",\"parentid\":16,\"order\":99989500,\"hasChild\":1},{\"id\":119,\"name\":\"局机关\",\"parentid\":117,\"order\":100000000,\"hasChild\":1},{\"id\":120,\"name\":\"局属单位\",\"parentid\":117,\"order\":99999500,\"hasChild\":1},{\"id\":121,\"name\":\"市应急局\",\"parentid\":16,\"order\":99989000,\"hasChild\":1},{\"id\":122,\"name\":\"局领导\",\"parentid\":121,\"order\":100000000,\"hasChild\":0},{\"id\":123,\"name\":\"内设机构\",\"parentid\":121,\"order\":99999500,\"hasChild\":0},{\"id\":124,\"name\":\"直属单位\",\"parentid\":121,\"order\":99999000,\"hasChild\":0},{\"id\":125,\"name\":\"市消防救援总队\",\"parentid\":121,\"order\":99998500,\"hasChild\":0},{\"id\":126,\"name\":\"市审计局\",\"parentid\":16,\"order\":99988500,\"hasChild\":1},{\"id\":127,\"name\":\"局领导\",\"parentid\":126,\"order\":100000000,\"hasChild\":0},{\"id\":128,\"name\":\"内设机构\",\"parentid\":126,\"order\":99999500,\"hasChild\":0},{\"id\":129,\"name\":\"直属单位\",\"parentid\":126,\"order\":99999000,\"hasChild\":0},{\"id\":130,\"name\":\"市市场监管局\",\"parentid\":16,\"order\":99988000,\"hasChild\":1},{\"id\":131,\"name\":\"局领导\",\"parentid\":130,\"order\":100000000,\"hasChild\":0},{\"id\":132,\"name\":\"内设机构\",\"parentid\":130,\"order\":99999500,\"hasChild\":0},{\"id\":133,\"name\":\"直属单位\",\"parentid\":130,\"order\":99999000,\"hasChild\":0},{\"id\":134,\"name\":\"市地方金融监管局\",\"parentid\":16,\"order\":99987500,\"hasChild\":1},{\"id\":135,\"name\":\"局领导\",\"parentid\":134,\"order\":100000000,\"hasChild\":0},{\"id\":136,\"name\":\"内设机构\",\"parentid\":134,\"order\":99999500,\"hasChild\":0},{\"id\":137,\"name\":\"直属单位\",\"parentid\":134,\"order\":99999000,\"hasChild\":0},{\"id\":138,\"name\":\"市政府外办\",\"parentid\":16,\"order\":99987000,\"hasChild\":1},{\"id\":139,\"name\":\"办领导\",\"parentid\":138,\"order\":100000000,\"hasChild\":0},{\"id\":140,\"name\":\"内设机构\",\"parentid\":138,\"order\":99999500,\"hasChild\":0},{\"id\":141,\"name\":\"直属单位\",\"parentid\":138,\"order\":99999000,\"hasChild\":0},{\"id\":142,\"name\":\"市国资委\",\"parentid\":16,\"order\":99986500,\"hasChild\":1},{\"id\":144,\"name\":\"委机关\",\"parentid\":142,\"order\":100000000,\"hasChild\":1},{\"id\":145,\"name\":\"委属单位\",\"parentid\":142,\"order\":99999500,\"hasChild\":1},{\"id\":146,\"name\":\"市体育局\",\"parentid\":16,\"order\":99986000,\"hasChild\":1},{\"id\":150,\"name\":\"市统计局\",\"parentid\":16,\"order\":99985500,\"hasChild\":1},{\"id\":151,\"name\":\"局领导\",\"parentid\":150,\"order\":100000000,\"hasChild\":0},{\"id\":152,\"name\":\"内设机构\",\"parentid\":150,\"order\":99999500,\"hasChild\":0},{\"id\":153,\"name\":\"直属单位\",\"parentid\":150,\"order\":99999000,\"hasChild\":0},{\"id\":154,\"name\":\"市医保局\",\"parentid\":16,\"order\":99985000,\"hasChild\":1},{\"id\":155,\"name\":\"局领导\",\"parentid\":154,\"order\":100000000,\"hasChild\":0},{\"id\":156,\"name\":\"内设机构\",\"parentid\":154,\"order\":99999500,\"hasChild\":0},{\"id\":157,\"name\":\"直属单位\",\"parentid\":154,\"order\":99999000,\"hasChild\":0},{\"id\":158,\"name\":\"市绿化市容局\",\"parentid\":16,\"order\":99984500,\"hasChild\":1},{\"id\":159,\"name\":\"局领导\",\"parentid\":158,\"order\":100000000,\"hasChild\":0},{\"id\":160,\"name\":\"内设机构\",\"parentid\":158,\"order\":99999500,\"hasChild\":0},{\"id\":161,\"name\":\"直属单位\",\"parentid\":158,\"order\":99999000,\"hasChild\":0},{\"id\":162,\"name\":\"市机管局\",\"parentid\":16,\"order\":99984000,\"hasChild\":1},{\"id\":166,\"name\":\"市民防办\",\"parentid\":16,\"order\":99983500,\"hasChild\":1},{\"id\":170,\"name\":\"市政府合作交流办\",\"parentid\":16,\"order\":99983000,\"hasChild\":1},{\"id\":171,\"name\":\"办领导\",\"parentid\":170,\"order\":100000000,\"hasChild\":0},{\"id\":172,\"name\":\"内设机构\",\"parentid\":170,\"order\":99999500,\"hasChild\":0},{\"id\":173,\"name\":\"直属单位\",\"parentid\":170,\"order\":99999000,\"hasChild\":0},{\"id\":174,\"name\":\"市政府研究室\",\"parentid\":16,\"order\":99982500,\"hasChild\":1},{\"id\":175,\"name\":\"室领导\",\"parentid\":174,\"order\":100000000,\"hasChild\":0},{\"id\":177,\"name\":\"直属单位\",\"parentid\":174,\"order\":99999000,\"hasChild\":0},{\"id\":178,\"name\":\"市政府参事室\",\"parentid\":16,\"order\":99982000,\"hasChild\":1},{\"id\":182,\"name\":\"市知识产权局\",\"parentid\":16,\"order\":99981500,\"hasChild\":1},{\"id\":183,\"name\":\"局领导\",\"parentid\":182,\"order\":100000000,\"hasChild\":0},{\"id\":184,\"name\":\"内设机构\",\"parentid\":182,\"order\":99999500,\"hasChild\":0},{\"id\":185,\"name\":\"直属单位\",\"parentid\":182,\"order\":99999000,\"hasChild\":0},{\"id\":186,\"name\":\"市粮食物资储备局\",\"parentid\":16,\"order\":99981000,\"hasChild\":1},{\"id\":187,\"name\":\"局领导\",\"parentid\":186,\"order\":100000000,\"hasChild\":0},{\"id\":188,\"name\":\"内设机构\",\"parentid\":186,\"order\":99999500,\"hasChild\":0},{\"id\":189,\"name\":\"直属单位\",\"parentid\":186,\"order\":99999000,\"hasChild\":0},{\"id\":190,\"name\":\"市监狱管理局\",\"parentid\":16,\"order\":99980500,\"hasChild\":1},{\"id\":191,\"name\":\"局领导\",\"parentid\":190,\"order\":100000000,\"hasChild\":0},{\"id\":192,\"name\":\"内设机构\",\"parentid\":190,\"order\":99999500,\"hasChild\":0},{\"id\":193,\"name\":\"直属单位\",\"parentid\":190,\"order\":99999000,\"hasChild\":0},{\"id\":194,\"name\":\"市城管执法局\",\"parentid\":16,\"order\":99980000,\"hasChild\":1},{\"id\":195,\"name\":\"局领导\",\"parentid\":194,\"order\":100000000,\"hasChild\":0},{\"id\":196,\"name\":\"内设机构\",\"parentid\":194,\"order\":99999500,\"hasChild\":0},{\"id\":197,\"name\":\"直属单位\",\"parentid\":194,\"order\":99999000,\"hasChild\":0},{\"id\":198,\"name\":\"市房屋管理局\",\"parentid\":16,\"order\":99979500,\"hasChild\":1},{\"id\":199,\"name\":\"局领导\",\"parentid\":198,\"order\":100000000,\"hasChild\":0},{\"id\":200,\"name\":\"内设机构\",\"parentid\":198,\"order\":99999500,\"hasChild\":0},{\"id\":201,\"name\":\"直属单位\",\"parentid\":198,\"order\":99999000,\"hasChild\":0},{\"id\":202,\"name\":\"市药品监督管理局\",\"parentid\":16,\"order\":99979000,\"hasChild\":1},{\"id\":203,\"name\":\"局领导\",\"parentid\":202,\"order\":100000000,\"hasChild\":0},{\"id\":204,\"name\":\"内设机构\",\"parentid\":202,\"order\":99999500,\"hasChild\":0},{\"id\":205,\"name\":\"直属单位\",\"parentid\":202,\"order\":99999000,\"hasChild\":0},{\"id\":206,\"name\":\"市道路运输管理局\",\"parentid\":16,\"order\":99978500,\"hasChild\":1},{\"id\":207,\"name\":\"局领导\",\"parentid\":206,\"order\":100000000,\"hasChild\":0},{\"id\":208,\"name\":\"内设机构\",\"parentid\":206,\"order\":99999500,\"hasChild\":0},{\"id\":209,\"name\":\"直属单位\",\"parentid\":206,\"order\":99999000,\"hasChild\":0},{\"id\":210,\"name\":\"国家税务总局上海市税务局\",\"parentid\":16,\"order\":99978000,\"hasChild\":1},{\"id\":211,\"name\":\"局领导\",\"parentid\":210,\"order\":100000000,\"hasChild\":0},{\"id\":212,\"name\":\"内设机构\",\"parentid\":210,\"order\":99999500,\"hasChild\":0},{\"id\":213,\"name\":\"直属单位\",\"parentid\":210,\"order\":99999000,\"hasChild\":0},{\"id\":214,\"name\":\"市政府发展研究中心\",\"parentid\":16,\"order\":99977500,\"hasChild\":1},{\"id\":215,\"name\":\"中心领导\",\"parentid\":214,\"order\":100000000,\"hasChild\":0},{\"id\":216,\"name\":\"内设机构\",\"parentid\":214,\"order\":99999500,\"hasChild\":0},{\"id\":217,\"name\":\"直属单位\",\"parentid\":214,\"order\":99999000,\"hasChild\":0},{\"id\":218,\"name\":\"市政协\",\"parentid\":1,\"order\":99997500,\"hasChild\":1},{\"id\":219,\"name\":\"市政协办公厅\",\"parentid\":218,\"order\":100000000,\"hasChild\":0},{\"id\":220,\"name\":\"市法院\",\"parentid\":1,\"order\":99998500,\"hasChild\":0},{\"id\":221,\"name\":\"市检察院\",\"parentid\":1,\"order\":99998000,\"hasChild\":0},{\"id\":222,\"name\":\"各区\",\"parentid\":1,\"order\":99997000,\"hasChild\":1},{\"id\":223,\"name\":\"浦东新区\",\"parentid\":222,\"order\":100000000,\"hasChild\":1},{\"id\":224,\"name\":\"区委\",\"parentid\":223,\"order\":100000000,\"hasChild\":0},{\"id\":225,\"name\":\"区人大\",\"parentid\":223,\"order\":99999500,\"hasChild\":0},{\"id\":226,\"name\":\"区政府\",\"parentid\":223,\"order\":99999000,\"hasChild\":0},{\"id\":227,\"name\":\"区政协\",\"parentid\":223,\"order\":99998500,\"hasChild\":0},{\"id\":228,\"name\":\"区法院\",\"parentid\":223,\"order\":99998000,\"hasChild\":0},{\"id\":229,\"name\":\"区检察院\",\"parentid\":223,\"order\":99997500,\"hasChild\":0},{\"id\":230,\"name\":\"街镇\",\"parentid\":223,\"order\":99997000,\"hasChild\":0},{\"id\":231,\"name\":\"黄浦区\",\"parentid\":222,\"order\":99999500,\"hasChild\":1},{\"id\":232,\"name\":\"区委\",\"parentid\":231,\"order\":100000000,\"hasChild\":0},{\"id\":233,\"name\":\"区人大\",\"parentid\":231,\"order\":99999500,\"hasChild\":0},{\"id\":234,\"name\":\"区政府\",\"parentid\":231,\"order\":99999000,\"hasChild\":0},{\"id\":235,\"name\":\"区政协\",\"parentid\":231,\"order\":99998500,\"hasChild\":0},{\"id\":236,\"name\":\"区法院\",\"parentid\":231,\"order\":99998000,\"hasChild\":0},{\"id\":237,\"name\":\"区检察院\",\"parentid\":231,\"order\":99997500,\"hasChild\":0},{\"id\":238,\"name\":\"街道\",\"parentid\":231,\"order\":99997000,\"hasChild\":0},{\"id\":239,\"name\":\"静安区\",\"parentid\":222,\"order\":99999000,\"hasChild\":1},{\"id\":240,\"name\":\"区委\",\"parentid\":239,\"order\":100000000,\"hasChild\":0},{\"id\":241,\"name\":\"区人大\",\"parentid\":239,\"order\":99999500,\"hasChild\":0},{\"id\":242,\"name\":\"区政府\",\"parentid\":239,\"order\":99999000,\"hasChild\":0},{\"id\":243,\"name\":\"区政协\",\"parentid\":239,\"order\":99998500,\"hasChild\":0},{\"id\":244,\"name\":\"区法院\",\"parentid\":239,\"order\":99998000,\"hasChild\":0},{\"id\":245,\"name\":\"区检察院\",\"parentid\":239,\"order\":99997500,\"hasChild\":0},{\"id\":246,\"name\":\"街镇\",\"parentid\":239,\"order\":99997000,\"hasChild\":0},{\"id\":247,\"name\":\"徐汇区\",\"parentid\":222,\"order\":99998500,\"hasChild\":1},{\"id\":248,\"name\":\"区委\",\"parentid\":247,\"order\":100000000,\"hasChild\":0},{\"id\":249,\"name\":\"区人大\",\"parentid\":247,\"order\":99999500,\"hasChild\":0},{\"id\":250,\"name\":\"区政府\",\"parentid\":247,\"order\":99999000,\"hasChild\":1},{\"id\":251,\"name\":\"区政协\",\"parentid\":247,\"order\":99998500,\"hasChild\":0},{\"id\":252,\"name\":\"区法院\",\"parentid\":247,\"order\":99998000,\"hasChild\":0},{\"id\":253,\"name\":\"区检察院\",\"parentid\":247,\"order\":99997500,\"hasChild\":0},{\"id\":254,\"name\":\"街镇\",\"parentid\":247,\"order\":99997000,\"hasChild\":0},{\"id\":255,\"name\":\"长宁区\",\"parentid\":222,\"order\":99998000,\"hasChild\":1},{\"id\":256,\"name\":\"区委\",\"parentid\":255,\"order\":100000000,\"hasChild\":0},{\"id\":257,\"name\":\"区人大\",\"parentid\":255,\"order\":99999500,\"hasChild\":0},{\"id\":258,\"name\":\"区政府\",\"parentid\":255,\"order\":99999000,\"hasChild\":0},{\"id\":259,\"name\":\"区政协\",\"parentid\":255,\"order\":99998500,\"hasChild\":0},{\"id\":260,\"name\":\"区法院\",\"parentid\":255,\"order\":99998000,\"hasChild\":0},{\"id\":261,\"name\":\"区检察院\",\"parentid\":255,\"order\":99997500,\"hasChild\":0},{\"id\":262,\"name\":\"街镇\",\"parentid\":255,\"order\":99997000,\"hasChild\":0},{\"id\":263,\"name\":\"普陀区\",\"parentid\":222,\"order\":99997500,\"hasChild\":1},{\"id\":264,\"name\":\"区委\",\"parentid\":263,\"order\":100000000,\"hasChild\":0},{\"id\":265,\"name\":\"区人大\",\"parentid\":263,\"order\":99999500,\"hasChild\":0},{\"id\":266,\"name\":\"区政府\",\"parentid\":263,\"order\":99999000,\"hasChild\":0},{\"id\":267,\"name\":\"区政协\",\"parentid\":263,\"order\":99998500,\"hasChild\":0},{\"id\":268,\"name\":\"区法院\",\"parentid\":263,\"order\":99998000,\"hasChild\":0},{\"id\":269,\"name\":\"区检察院\",\"parentid\":263,\"order\":99997500,\"hasChild\":0},{\"id\":270,\"name\":\"街镇\",\"parentid\":263,\"order\":99997000,\"hasChild\":0},{\"id\":271,\"name\":\"虹口区\",\"parentid\":222,\"order\":99997000,\"hasChild\":1},{\"id\":272,\"name\":\"区委\",\"parentid\":271,\"order\":100000000,\"hasChild\":0},{\"id\":273,\"name\":\"区人大\",\"parentid\":271,\"order\":99999500,\"hasChild\":0},{\"id\":274,\"name\":\"区政府\",\"parentid\":271,\"order\":99999000,\"hasChild\":0},{\"id\":275,\"name\":\"区政协\",\"parentid\":271,\"order\":99998500,\"hasChild\":0},{\"id\":276,\"name\":\"区法院\",\"parentid\":271,\"order\":99998000,\"hasChild\":0},{\"id\":277,\"name\":\"区检察院\",\"parentid\":271,\"order\":99997500,\"hasChild\":0},{\"id\":278,\"name\":\"街镇\",\"parentid\":271,\"order\":99997000,\"hasChild\":0},{\"id\":279,\"name\":\"杨浦区\",\"parentid\":222,\"order\":99996500,\"hasChild\":1},{\"id\":280,\"name\":\"区委\",\"parentid\":279,\"order\":100000000,\"hasChild\":0},{\"id\":281,\"name\":\"区人大\",\"parentid\":279,\"order\":99999500,\"hasChild\":0},{\"id\":282,\"name\":\"区政府\",\"parentid\":279,\"order\":99999000,\"hasChild\":0},{\"id\":283,\"name\":\"区政协\",\"parentid\":279,\"order\":99998500,\"hasChild\":0},{\"id\":284,\"name\":\"区法院\",\"parentid\":279,\"order\":99998000,\"hasChild\":0},{\"id\":285,\"name\":\"区检察院\",\"parentid\":279,\"order\":99997500,\"hasChild\":0},{\"id\":286,\"name\":\"街镇\",\"parentid\":279,\"order\":99997000,\"hasChild\":0},{\"id\":287,\"name\":\"宝山区\",\"parentid\":222,\"order\":99996000,\"hasChild\":1},{\"id\":288,\"name\":\"区委\",\"parentid\":287,\"order\":100000000,\"hasChild\":0},{\"id\":289,\"name\":\"区人大\",\"parentid\":287,\"order\":99999500,\"hasChild\":0},{\"id\":290,\"name\":\"区政府\",\"parentid\":287,\"order\":99999000,\"hasChild\":0},{\"id\":291,\"name\":\"区政协\",\"parentid\":287,\"order\":99998500,\"hasChild\":0},{\"id\":292,\"name\":\"区法院\",\"parentid\":287,\"order\":99998000,\"hasChild\":0},{\"id\":293,\"name\":\"区检察院\",\"parentid\":287,\"order\":99997500,\"hasChild\":0},{\"id\":294,\"name\":\"街镇\",\"parentid\":287,\"order\":99997000,\"hasChild\":0},{\"id\":295,\"name\":\"闵行区\",\"parentid\":222,\"order\":99995500,\"hasChild\":1},{\"id\":296,\"name\":\"区委\",\"parentid\":295,\"order\":100000000,\"hasChild\":0},{\"id\":297,\"name\":\"区人大\",\"parentid\":295,\"order\":99999500,\"hasChild\":0},{\"id\":298,\"name\":\"区政府\",\"parentid\":295,\"order\":99999000,\"hasChild\":0},{\"id\":299,\"name\":\"区政协\",\"parentid\":295,\"order\":99998500,\"hasChild\":0},{\"id\":300,\"name\":\"区法院\",\"parentid\":295,\"order\":99998000,\"hasChild\":0},{\"id\":301,\"name\":\"区检察院\",\"parentid\":295,\"order\":99997500,\"hasChild\":0},{\"id\":302,\"name\":\"街镇\",\"parentid\":295,\"order\":99997000,\"hasChild\":0},{\"id\":303,\"name\":\"嘉定区\",\"parentid\":222,\"order\":99995000,\"hasChild\":1},{\"id\":304,\"name\":\"区委\",\"parentid\":303,\"order\":100000000,\"hasChild\":0},{\"id\":305,\"name\":\"区人大\",\"parentid\":303,\"order\":99999500,\"hasChild\":0},{\"id\":306,\"name\":\"区政府\",\"parentid\":303,\"order\":99999000,\"hasChild\":0},{\"id\":307,\"name\":\"区政协\",\"parentid\":303,\"order\":99998500,\"hasChild\":0},{\"id\":308,\"name\":\"区法院\",\"parentid\":303,\"order\":99998000,\"hasChild\":0},{\"id\":309,\"name\":\"区检察院\",\"parentid\":303,\"order\":99997500,\"hasChild\":0},{\"id\":310,\"name\":\"街镇\",\"parentid\":303,\"order\":99997000,\"hasChild\":0},{\"id\":311,\"name\":\"金山区\",\"parentid\":222,\"order\":99994500,\"hasChild\":1},{\"id\":312,\"name\":\"区委\",\"parentid\":311,\"order\":100000000,\"hasChild\":0},{\"id\":313,\"name\":\"区人大\",\"parentid\":311,\"order\":99999500,\"hasChild\":0},{\"id\":314,\"name\":\"区政府\",\"parentid\":311,\"order\":99999000,\"hasChild\":0},{\"id\":315,\"name\":\"区政协\",\"parentid\":311,\"order\":99998500,\"hasChild\":0},{\"id\":316,\"name\":\"区法院\",\"parentid\":311,\"order\":99998000,\"hasChild\":0},{\"id\":317,\"name\":\"区检察院\",\"parentid\":311,\"order\":99997500,\"hasChild\":0},{\"id\":318,\"name\":\"街镇\",\"parentid\":311,\"order\":99997000,\"hasChild\":0},{\"id\":319,\"name\":\"松江区\",\"parentid\":222,\"order\":99994000,\"hasChild\":1},{\"id\":320,\"name\":\"区委\",\"parentid\":319,\"order\":100000000,\"hasChild\":0},{\"id\":321,\"name\":\"区人大\",\"parentid\":319,\"order\":99999500,\"hasChild\":0},{\"id\":322,\"name\":\"区政府\",\"parentid\":319,\"order\":99999000,\"hasChild\":0},{\"id\":323,\"name\":\"区政协\",\"parentid\":319,\"order\":99998500,\"hasChild\":0},{\"id\":324,\"name\":\"区法院\",\"parentid\":319,\"order\":99998000,\"hasChild\":0},{\"id\":325,\"name\":\"区检察院\",\"parentid\":319,\"order\":99997500,\"hasChild\":0},{\"id\":326,\"name\":\"街镇\",\"parentid\":319,\"order\":99997000,\"hasChild\":0},{\"id\":327,\"name\":\"青浦区\",\"parentid\":222,\"order\":99993500,\"hasChild\":1},{\"id\":328,\"name\":\"区委\",\"parentid\":327,\"order\":100000000,\"hasChild\":0},{\"id\":329,\"name\":\"区人大\",\"parentid\":327,\"order\":99999500,\"hasChild\":0},{\"id\":330,\"name\":\"区政府\",\"parentid\":327,\"order\":99999000,\"hasChild\":0},{\"id\":331,\"name\":\"区政协\",\"parentid\":327,\"order\":99998500,\"hasChild\":0},{\"id\":332,\"name\":\"区法院\",\"parentid\":327,\"order\":99998000,\"hasChild\":0},{\"id\":333,\"name\":\"区检察院\",\"parentid\":327,\"order\":99997500,\"hasChild\":0},{\"id\":334,\"name\":\"街镇\",\"parentid\":327,\"order\":99997000,\"hasChild\":0},{\"id\":335,\"name\":\"奉贤区\",\"parentid\":222,\"order\":99993000,\"hasChild\":1},{\"id\":336,\"name\":\"区委\",\"parentid\":335,\"order\":100000000,\"hasChild\":0},{\"id\":337,\"name\":\"区人大\",\"parentid\":335,\"order\":99999500,\"hasChild\":0},{\"id\":338,\"name\":\"区政府\",\"parentid\":335,\"order\":99999000,\"hasChild\":0},{\"id\":339,\"name\":\"区政协\",\"parentid\":335,\"order\":99998500,\"hasChild\":0},{\"id\":340,\"name\":\"区法院\",\"parentid\":335,\"order\":99998000,\"hasChild\":0},{\"id\":341,\"name\":\"区检察院\",\"parentid\":335,\"order\":99997500,\"hasChild\":0},{\"id\":342,\"name\":\"街镇\",\"parentid\":335,\"order\":99997000,\"hasChild\":0},{\"id\":343,\"name\":\"崇明区\",\"parentid\":222,\"order\":99992500,\"hasChild\":1},{\"id\":344,\"name\":\"区委\",\"parentid\":343,\"order\":100000000,\"hasChild\":0},{\"id\":345,\"name\":\"区人大\",\"parentid\":343,\"order\":99999500,\"hasChild\":0},{\"id\":346,\"name\":\"区政府\",\"parentid\":343,\"order\":99999000,\"hasChild\":0},{\"id\":347,\"name\":\"区政协\",\"parentid\":343,\"order\":99998500,\"hasChild\":0},{\"id\":348,\"name\":\"区法院\",\"parentid\":343,\"order\":99998000,\"hasChild\":0},{\"id\":349,\"name\":\"区检察院\",\"parentid\":343,\"order\":99997500,\"hasChild\":0},{\"id\":350,\"name\":\"街道乡镇\",\"parentid\":343,\"order\":99997000,\"hasChild\":0},{\"id\":351,\"name\":\"业务条线\",\"parentid\":1,\"order\":99996500,\"hasChild\":1},{\"id\":352,\"name\":\"办公室和值班室系统\",\"parentid\":351,\"order\":99999500,\"hasChild\":0},{\"id\":353,\"name\":\"城运系统\",\"parentid\":351,\"order\":99999000,\"hasChild\":0},{\"id\":354,\"name\":\"网格系统\",\"parentid\":351,\"order\":99998500,\"hasChild\":0},{\"id\":355,\"name\":\"防汛防台系统\",\"parentid\":351,\"order\":99998000,\"hasChild\":0},{\"id\":356,\"name\":\"统一综合执法系统\",\"parentid\":351,\"order\":99997000,\"hasChild\":0},{\"id\":357,\"name\":\"重要会议保障\",\"parentid\":351,\"order\":99997500,\"hasChild\":0},{\"id\":358,\"name\":\"TEST-ZONE\",\"parentid\":667,\"order\":100000000,\"hasChild\":1},{\"id\":360,\"name\":\"正通过管理通讯录同时可手动编辑正\",\"parentid\":404,\"order\":100000000,\"hasChild\":1},{\"id\":362,\"name\":\"测试数据\",\"parentid\":358,\"order\":99999500,\"hasChild\":0},{\"id\":363,\"name\":\"测试数据1\",\"parentid\":358,\"order\":99993500,\"hasChild\":1},{\"id\":364,\"name\":\"测试数据2\",\"parentid\":358,\"order\":99994500,\"hasChild\":0},{\"id\":365,\"name\":\"超长部门名称测试超长部门名称测试\",\"parentid\":363,\"order\":100000000,\"hasChild\":0},{\"id\":366,\"name\":\"测试子部门\",\"parentid\":450,\"order\":99999500,\"hasChild\":0},{\"id\":368,\"name\":\"新建子部门\",\"parentid\":408,\"order\":99999000,\"hasChild\":0},{\"id\":369,\"name\":\"测试\",\"parentid\":358,\"order\":99998000,\"hasChild\":1},{\"id\":376,\"name\":\"1\",\"parentid\":450,\"order\":100000000,\"hasChild\":0},{\"id\":377,\"name\":\"23333\",\"parentid\":450,\"order\":99998500,\"hasChild\":0},{\"id\":378,\"name\":\"3\",\"parentid\":405,\"order\":100000000,\"hasChild\":1},{\"id\":380,\"name\":\"2\",\"parentid\":358,\"order\":99996000,\"hasChild\":1},{\"id\":399,\"name\":\"正在通过管理员权限\",\"parentid\":360,\"order\":100000000,\"hasChild\":0},{\"id\":400,\"name\":\"正在通过\",\"parentid\":405,\"order\":99999500,\"hasChild\":0},{\"id\":403,\"name\":\"1\",\"parentid\":358,\"order\":99996500,\"hasChild\":0},{\"id\":404,\"name\":\"21\",\"parentid\":450,\"order\":99999000,\"hasChild\":1},{\"id\":405,\"name\":\"dy测试\",\"parentid\":358,\"order\":99998500,\"hasChild\":1},{\"id\":406,\"name\":\"asdfa\",\"parentid\":408,\"order\":100000000,\"hasChild\":0},{\"id\":407,\"name\":\"asdfasdf'\",\"parentid\":408,\"order\":99998500,\"hasChild\":0},{\"id\":408,\"name\":\"dy测试22\",\"parentid\":405,\"order\":99999000,\"hasChild\":1},{\"id\":410,\"name\":\"局领导班子\",\"parentid\":107,\"order\":100000000,\"hasChild\":0},{\"id\":411,\"name\":\"二级巡视员\",\"parentid\":107,\"order\":99999500,\"hasChild\":0},{\"id\":412,\"name\":\"办公室\",\"parentid\":107,\"order\":99999000,\"hasChild\":0},{\"id\":413,\"name\":\"政策研究室\",\"parentid\":107,\"order\":99998500,\"hasChild\":0},{\"id\":414,\"name\":\"法规处\",\"parentid\":107,\"order\":99998000,\"hasChild\":0},{\"id\":415,\"name\":\"组织人事处(老干部处)\",\"parentid\":107,\"order\":99997500,\"hasChild\":0},{\"id\":416,\"name\":\"综合规划处\",\"parentid\":107,\"order\":99997000,\"hasChild\":0},{\"id\":417,\"name\":\"计划财务处\",\"parentid\":107,\"order\":99996500,\"hasChild\":0},{\"id\":418,\"name\":\"科技信息处(社会宣传处)\",\"parentid\":107,\"order\":99996000,\"hasChild\":0},{\"id\":419,\"name\":\"河长制工作处(综合督导处)\",\"parentid\":107,\"order\":99995500,\"hasChild\":0},{\"id\":420,\"name\":\"水资源管理处(上海市节约用水办公室)\",\"parentid\":107,\"order\":99995000,\"hasChild\":0},{\"id\":421,\"name\":\"建设管理处\",\"parentid\":107,\"order\":99994500,\"hasChild\":0},{\"id\":422,\"name\":\"水利管理处(水土保持处)\",\"parentid\":107,\"order\":99994000,\"hasChild\":0},{\"id\":423,\"name\":\"海域海岛管理处(海洋经济协调处)\",\"parentid\":107,\"order\":99993500,\"hasChild\":0},{\"id\":424,\"name\":\"水旱和海洋灾害防御处\",\"parentid\":107,\"order\":99993000,\"hasChild\":0},{\"id\":425,\"name\":\"设施运行管理处(安全监督处)\",\"parentid\":107,\"order\":99992500,\"hasChild\":0},{\"id\":426,\"name\":\"审计室\",\"parentid\":107,\"order\":99992000,\"hasChild\":0},{\"id\":427,\"name\":\"工会\",\"parentid\":107,\"order\":99991500,\"hasChild\":0},{\"id\":428,\"name\":\"机关党委\",\"parentid\":107,\"order\":99991000,\"hasChild\":0},{\"id\":429,\"name\":\"团委\",\"parentid\":107,\"order\":99990500,\"hasChild\":0},{\"id\":430,\"name\":\"纪检监察组\",\"parentid\":107,\"order\":99990000,\"hasChild\":0},{\"id\":431,\"name\":\"文印室\",\"parentid\":107,\"order\":99989500,\"hasChild\":0},{\"id\":432,\"name\":\"局网站编辑部\",\"parentid\":107,\"order\":99989000,\"hasChild\":0},{\"id\":433,\"name\":\"水务志编辑室\",\"parentid\":107,\"order\":99988500,\"hasChild\":0},{\"id\":434,\"name\":\"老干部活动中心\",\"parentid\":107,\"order\":99988000,\"hasChild\":0},{\"id\":435,\"name\":\"上海市水务局执法总队(中国海监上海市总队)\",\"parentid\":108,\"order\":100000000,\"hasChild\":0},{\"id\":436,\"name\":\"上海市水务局行政服务中心(上海市海洋局行政服务中心)\",\"parentid\":108,\"order\":99999500,\"hasChild\":0},{\"id\":437,\"name\":\"上海市水利管理事务中心(上海市河湖管理事务中心)\",\"parentid\":108,\"order\":99999000,\"hasChild\":0},{\"id\":438,\"name\":\"上海市供水管理事务中心(上海市节约用水促进中心)\",\"parentid\":108,\"order\":99998500,\"hasChild\":0},{\"id\":439,\"name\":\"上海市排水管理事务中心\",\"parentid\":108,\"order\":99998000,\"hasChild\":0},{\"id\":440,\"name\":\"上海市堤防泵闸建设运行中心\",\"parentid\":108,\"order\":99997500,\"hasChild\":0},{\"id\":441,\"name\":\"上海市水文总站\",\"parentid\":108,\"order\":99997000,\"hasChild\":0},{\"id\":442,\"name\":\"上海市水务规划设计研究院(上海市海洋规划设计研究院)\",\"parentid\":108,\"order\":99996500,\"hasChild\":0},{\"id\":443,\"name\":\"上海市供水调度监测中心\",\"parentid\":108,\"order\":99996000,\"hasChild\":0},{\"id\":444,\"name\":\"上海市水务建设工程安全质量监督中心站(上海市水务工程定额管理站)\",\"parentid\":108,\"order\":99995500,\"hasChild\":0},{\"id\":445,\"name\":\"上海市水旱灾害防御技术中心\",\"parentid\":108,\"order\":99995000,\"hasChild\":0},{\"id\":446,\"name\":\"上海市海洋管理事务中心\",\"parentid\":108,\"order\":99994500,\"hasChild\":0},{\"id\":447,\"name\":\"上海市海洋监测预报中心\",\"parentid\":108,\"order\":99994000,\"hasChild\":0},{\"id\":449,\"name\":\"一个部门\",\"parentid\":378,\"order\":99999000,\"hasChild\":0},{\"id\":450,\"name\":\"test\",\"parentid\":380,\"order\":99999500,\"hasChild\":1},{\"id\":453,\"name\":\"委领导\",\"parentid\":144,\"order\":100000000,\"hasChild\":0},{\"id\":454,\"name\":\"党委办公室\",\"parentid\":144,\"order\":99999500,\"hasChild\":0},{\"id\":455,\"name\":\"组织处\",\"parentid\":144,\"order\":99999000,\"hasChild\":0},{\"id\":456,\"name\":\"宣传处\",\"parentid\":144,\"order\":99998500,\"hasChild\":0},{\"id\":457,\"name\":\"企业领导人员管理处\",\"parentid\":144,\"order\":99998000,\"hasChild\":0},{\"id\":458,\"name\":\"老干部处\",\"parentid\":144,\"order\":99997500,\"hasChild\":0},{\"id\":459,\"name\":\"办公室\",\"parentid\":144,\"order\":99997000,\"hasChild\":0},{\"id\":460,\"name\":\"人事处\",\"parentid\":144,\"order\":99996500,\"hasChild\":0},{\"id\":461,\"name\":\"研究室\",\"parentid\":144,\"order\":99996000,\"hasChild\":0},{\"id\":462,\"name\":\"政策法规处\",\"parentid\":144,\"order\":99995500,\"hasChild\":0},{\"id\":463,\"name\":\"规划发展处\",\"parentid\":144,\"order\":99995000,\"hasChild\":0},{\"id\":464,\"name\":\"创新发展处\",\"parentid\":144,\"order\":99994500,\"hasChild\":0},{\"id\":465,\"name\":\"企业改革处(城镇集体资产管理处)\",\"parentid\":144,\"order\":99994000,\"hasChild\":0},{\"id\":466,\"name\":\"金融企业发展处\",\"parentid\":144,\"order\":99993500,\"hasChild\":0},{\"id\":467,\"name\":\"产权管理处(资本运营管理处)\",\"parentid\":144,\"order\":99993000,\"hasChild\":0},{\"id\":468,\"name\":\"评估管理处\",\"parentid\":144,\"order\":99992500,\"hasChild\":0},{\"id\":469,\"name\":\"审计监督处(稽查办公室)\",\"parentid\":144,\"order\":99992000,\"hasChild\":0},{\"id\":470,\"name\":\"财务评价处\",\"parentid\":144,\"order\":99991500,\"hasChild\":0},{\"id\":471,\"name\":\"业绩考核处\",\"parentid\":144,\"order\":99991000,\"hasChild\":0},{\"id\":472,\"name\":\"分配保障处\",\"parentid\":144,\"order\":99990500,\"hasChild\":0},{\"id\":473,\"name\":\"综合协调处\",\"parentid\":144,\"order\":99990000,\"hasChild\":0},{\"id\":474,\"name\":\"公司治理处\",\"parentid\":144,\"order\":99989500,\"hasChild\":0},{\"id\":475,\"name\":\"信息化管理处\",\"parentid\":144,\"order\":99989000,\"hasChild\":0},{\"id\":476,\"name\":\"信访办公室\",\"parentid\":144,\"order\":99988500,\"hasChild\":0},{\"id\":477,\"name\":\"直属机关党委\",\"parentid\":144,\"order\":99988000,\"hasChild\":0},{\"id\":478,\"name\":\"上海市国有资产监督管理委员会企业发展服务中心\",\"parentid\":145,\"order\":100000000,\"hasChild\":0},{\"id\":479,\"name\":\"上海市国资国企改革发展研究中心\",\"parentid\":145,\"order\":99999500,\"hasChild\":0},{\"id\":480,\"name\":\"上海市国有企业绩效评价中心(上海市国有资产监督管理委员会稽查事务中心)\",\"parentid\":145,\"order\":99999000,\"hasChild\":0},{\"id\":481,\"name\":\"局领导\",\"parentid\":119,\"order\":100000000,\"hasChild\":0},{\"id\":482,\"name\":\"办公室\",\"parentid\":119,\"order\":99999500,\"hasChild\":0},{\"id\":483,\"name\":\"组织人事处\",\"parentid\":119,\"order\":99999000,\"hasChild\":0},{\"id\":484,\"name\":\"政策法规处\",\"parentid\":119,\"order\":99998500,\"hasChild\":0},{\"id\":485,\"name\":\"规划财务处\",\"parentid\":119,\"order\":99998000,\"hasChild\":0},{\"id\":486,\"name\":\"思想政治和权益维护处\",\"parentid\":119,\"order\":99997500,\"hasChild\":0},{\"id\":487,\"name\":\"移交安置处(就业创业处)\",\"parentid\":119,\"order\":99997000,\"hasChild\":0},{\"id\":488,\"name\":\"军休服务管理处\",\"parentid\":119,\"order\":99996500,\"hasChild\":0},{\"id\":489,\"name\":\"拥军优抚处(褒扬纪念处)\",\"parentid\":119,\"order\":99996000,\"hasChild\":0},{\"id\":490,\"name\":\"直属机关党委\",\"parentid\":119,\"order\":99995500,\"hasChild\":0},{\"id\":491,\"name\":\"上海市双拥服务中心\",\"parentid\":120,\"order\":100000000,\"hasChild\":0},{\"id\":492,\"name\":\"上海市军队离休退休干部活动中心\",\"parentid\":120,\"order\":99999500,\"hasChild\":0},{\"id\":493,\"name\":\"上海市荣誉军人疗养院\",\"parentid\":120,\"order\":99999000,\"hasChild\":0},{\"id\":494,\"name\":\"上海市龙华烈士陵园(龙华烈士纪念馆)\",\"parentid\":120,\"order\":99998500,\"hasChild\":0},{\"id\":495,\"name\":\"上海市军队离退休干部古美休养所\",\"parentid\":120,\"order\":99998000,\"hasChild\":0},{\"id\":496,\"name\":\"上海市军供站\",\"parentid\":120,\"order\":99997500,\"hasChild\":0},{\"id\":497,\"name\":\"上海市退役军人服务中心\",\"parentid\":120,\"order\":99997000,\"hasChild\":0},{\"id\":498,\"name\":\"参事室领导\",\"parentid\":178,\"order\":100000000,\"hasChild\":0},{\"id\":499,\"name\":\"秘书处\",\"parentid\":503,\"order\":100000000,\"hasChild\":0},{\"id\":500,\"name\":\"宣传交流处\",\"parentid\":503,\"order\":99999500,\"hasChild\":0},{\"id\":501,\"name\":\"参事业务处\",\"parentid\":503,\"order\":99999000,\"hasChild\":0},{\"id\":502,\"name\":\"组织人事处\",\"parentid\":503,\"order\":99998500,\"hasChild\":0},{\"id\":503,\"name\":\"内设机构\",\"parentid\":178,\"order\":99999500,\"hasChild\":1},{\"id\":504,\"name\":\"局机关\",\"parentid\":162,\"order\":100000000,\"hasChild\":1},{\"id\":505,\"name\":\"办公室\",\"parentid\":504,\"order\":100000000,\"hasChild\":0},{\"id\":506,\"name\":\"政策法规处(研究室)\",\"parentid\":504,\"order\":99999500,\"hasChild\":0},{\"id\":507,\"name\":\"人事处(老干部处)\",\"parentid\":504,\"order\":99999000,\"hasChild\":0},{\"id\":508,\"name\":\"财务处(审计室)\",\"parentid\":504,\"order\":99998500,\"hasChild\":0},{\"id\":509,\"name\":\"国有资产管理处\",\"parentid\":504,\"order\":99998000,\"hasChild\":0},{\"id\":510,\"name\":\"办公用房与人防设施处\",\"parentid\":504,\"order\":99997500,\"hasChild\":0},{\"id\":511,\"name\":\"车辆管理处\",\"parentid\":504,\"order\":99997000,\"hasChild\":0},{\"id\":512,\"name\":\"公共机构节能管理处\",\"parentid\":504,\"order\":99996500,\"hasChild\":0},{\"id\":513,\"name\":\"服务监管处(后勤改革指导处)\",\"parentid\":504,\"order\":99996000,\"hasChild\":0},{\"id\":514,\"name\":\"住房管理处\",\"parentid\":504,\"order\":99995500,\"hasChild\":0},{\"id\":515,\"name\":\"局管单位\",\"parentid\":162,\"order\":99999000,\"hasChild\":1},{\"id\":516,\"name\":\"上海市孙中山宋庆龄文物管理委员会\",\"parentid\":515,\"order\":100000000,\"hasChild\":0},{\"id\":517,\"name\":\"上海上勤(集团)有限公司\",\"parentid\":515,\"order\":99999500,\"hasChild\":0},{\"id\":518,\"name\":\"上海展览中心(集团)有限公司\",\"parentid\":515,\"order\":99999000,\"hasChild\":0},{\"id\":519,\"name\":\"上海孙中山故居纪念馆\",\"parentid\":515,\"order\":99998500,\"hasChild\":0},{\"id\":520,\"name\":\"上海宋庆龄故居纪念馆\",\"parentid\":515,\"order\":99998000,\"hasChild\":0},{\"id\":521,\"name\":\"中华人民共和国名誉主席宋庆龄陵园管理处(上海市万国公墓管理处)\",\"parentid\":515,\"order\":99997500,\"hasChild\":0},{\"id\":522,\"name\":\"局机关\",\"parentid\":146,\"order\":100000000,\"hasChild\":1},{\"id\":523,\"name\":\"局领导\",\"parentid\":522,\"order\":100000000,\"hasChild\":0},{\"id\":524,\"name\":\"办公室\",\"parentid\":522,\"order\":99999500,\"hasChild\":0},{\"id\":525,\"name\":\"规划产业处(法规处)\",\"parentid\":522,\"order\":99999000,\"hasChild\":0},{\"id\":526,\"name\":\"人事处(外事处)\",\"parentid\":522,\"order\":99998500,\"hasChild\":0},{\"id\":527,\"name\":\"财务处(设施建设处)\",\"parentid\":522,\"order\":99998000,\"hasChild\":0},{\"id\":528,\"name\":\"群众体育处\",\"parentid\":522,\"order\":99997500,\"hasChild\":0},{\"id\":529,\"name\":\"竞技体育处\",\"parentid\":522,\"order\":99997000,\"hasChild\":0},{\"id\":530,\"name\":\"青少年体育处(科教处)\",\"parentid\":522,\"order\":99996500,\"hasChild\":0},{\"id\":531,\"name\":\"竞赛处\",\"parentid\":522,\"order\":99996000,\"hasChild\":0},{\"id\":532,\"name\":\"局属单位\",\"parentid\":146,\"order\":99999500,\"hasChild\":1},{\"id\":533,\"name\":\"上海棋院(上海市棋牌运动管理中心)\",\"parentid\":532,\"order\":100000000,\"hasChild\":0},{\"id\":534,\"name\":\"上海市第二体育运动学校(上海市体育中学)\",\"parentid\":532,\"order\":99999500,\"hasChild\":0},{\"id\":535,\"name\":\"上海市划船俱乐部\",\"parentid\":532,\"order\":99999000,\"hasChild\":0},{\"id\":536,\"name\":\"上海市竞技体育训练管理中心\",\"parentid\":532,\"order\":99998500,\"hasChild\":0},{\"id\":537,\"name\":\"上海市科技体育运动管理中心\",\"parentid\":532,\"order\":99998000,\"hasChild\":0},{\"id\":538,\"name\":\"上海市马术运动管理中心\",\"parentid\":532,\"order\":99997500,\"hasChild\":0},{\"id\":539,\"name\":\"上海市青少年训练管理中心\",\"parentid\":532,\"order\":99997000,\"hasChild\":0},{\"id\":540,\"name\":\"上海市社会体育管理中心\",\"parentid\":532,\"order\":99996500,\"hasChild\":0},{\"id\":541,\"name\":\"上海市体育彩票管理中心\",\"parentid\":532,\"order\":99996000,\"hasChild\":0},{\"id\":542,\"name\":\"上海市体育场馆设施管理中心\",\"parentid\":532,\"order\":99995500,\"hasChild\":0},{\"id\":543,\"name\":\"上海市体育发展服务中心\",\"parentid\":532,\"order\":99995000,\"hasChild\":0},{\"id\":544,\"name\":\"上海市体育宣传教育中心\",\"parentid\":532,\"order\":99994500,\"hasChild\":0},{\"id\":545,\"name\":\"上海市体育训练基地管理中心\",\"parentid\":532,\"order\":99994000,\"hasChild\":0},{\"id\":546,\"name\":\"上海市体育运动学校\",\"parentid\":532,\"order\":99993500,\"hasChild\":0},{\"id\":547,\"name\":\"上海体育科学研究所(上海市反兴奋剂中心)\",\"parentid\":532,\"order\":99993000,\"hasChild\":0},{\"id\":548,\"name\":\"上海武术院(上海市健身气功管理中心)\",\"parentid\":532,\"order\":99992500,\"hasChild\":0},{\"id\":549,\"name\":\"上海市体育发展基金会\",\"parentid\":532,\"order\":99992000,\"hasChild\":0},{\"id\":550,\"name\":\"办机关\",\"parentid\":166,\"order\":100000000,\"hasChild\":1},{\"id\":551,\"name\":\"办领导\",\"parentid\":550,\"order\":100000000,\"hasChild\":0},{\"id\":552,\"name\":\"秘书处\",\"parentid\":550,\"order\":99999500,\"hasChild\":0},{\"id\":553,\"name\":\"政策法规处(审计监督室)\",\"parentid\":550,\"order\":99999000,\"hasChild\":0},{\"id\":554,\"name\":\"指挥通信处\",\"parentid\":550,\"order\":99998500,\"hasChild\":0},{\"id\":555,\"name\":\"工程处\",\"parentid\":550,\"order\":99998000,\"hasChild\":0},{\"id\":556,\"name\":\"科技宣教处\",\"parentid\":550,\"order\":99997500,\"hasChild\":0},{\"id\":557,\"name\":\"计划财务处\",\"parentid\":550,\"order\":99997000,\"hasChild\":0},{\"id\":558,\"name\":\"组织人事处\",\"parentid\":550,\"order\":99996500,\"hasChild\":0},{\"id\":559,\"name\":\"直属单位\",\"parentid\":166,\"order\":99999500,\"hasChild\":1},{\"id\":560,\"name\":\"上海市民防监督管理事务中心\",\"parentid\":559,\"order\":100000000,\"hasChild\":0},{\"id\":561,\"name\":\"上海市民防科学研究所\",\"parentid\":559,\"order\":99999500,\"hasChild\":0},{\"id\":562,\"name\":\"上海市民防指挥信息保障中心\",\"parentid\":559,\"order\":99999000,\"hasChild\":0},{\"id\":563,\"name\":\"上海市民防特种救援中心\",\"parentid\":559,\"order\":99998500,\"hasChild\":0},{\"id\":564,\"name\":\"上海市民防教育培训中心\",\"parentid\":559,\"order\":99998000,\"hasChild\":0},{\"id\":565,\"name\":\"局机关\",\"parentid\":89,\"order\":100000000,\"hasChild\":1},{\"id\":566,\"name\":\"局领导\",\"parentid\":565,\"order\":100000000,\"hasChild\":0},{\"id\":567,\"name\":\"办公室(宣传教育处、信访办公室)\",\"parentid\":565,\"order\":99999500,\"hasChild\":0},{\"id\":568,\"name\":\"生态环境保护督察办公室  \",\"parentid\":565,\"order\":99999000,\"hasChild\":0},{\"id\":569,\"name\":\"综合规划处(区域协作处)\",\"parentid\":565,\"order\":99998500,\"hasChild\":0},{\"id\":570,\"name\":\"法规与标准处\",\"parentid\":565,\"order\":99998000,\"hasChild\":0},{\"id\":571,\"name\":\"干部人事处\",\"parentid\":565,\"order\":99997500,\"hasChild\":0},{\"id\":572,\"name\":\"科技与国际合作处\",\"parentid\":565,\"order\":99997000,\"hasChild\":0},{\"id\":573,\"name\":\"自然生态保护处 \",\"parentid\":565,\"order\":99996500,\"hasChild\":0},{\"id\":574,\"name\":\"水生态环境处\",\"parentid\":565,\"order\":99996000,\"hasChild\":0},{\"id\":575,\"name\":\"海洋生态环境处\",\"parentid\":565,\"order\":99995500,\"hasChild\":0},{\"id\":576,\"name\":\"大气生态环境处\",\"parentid\":565,\"order\":99995000,\"hasChild\":0},{\"id\":577,\"name\":\"应对气候变化处\",\"parentid\":565,\"order\":99994500,\"hasChild\":0},{\"id\":578,\"name\":\"土壤生态环境处(固体废物与化学品处)\",\"parentid\":565,\"order\":99994000,\"hasChild\":0},{\"id\":579,\"name\":\"辐射安全管理处\",\"parentid\":565,\"order\":99993500,\"hasChild\":0},{\"id\":580,\"name\":\"环境影响评价与排放管理处\",\"parentid\":565,\"order\":99993000,\"hasChild\":0},{\"id\":581,\"name\":\"生态环境监测处\",\"parentid\":565,\"order\":99992500,\"hasChild\":0},{\"id\":582,\"name\":\"生态环境执法与应急处\",\"parentid\":565,\"order\":99992000,\"hasChild\":0},{\"id\":583,\"name\":\"局属单位\",\"parentid\":89,\"order\":99999500,\"hasChild\":1},{\"id\":584,\"name\":\"上海市环境科学研究院\",\"parentid\":583,\"order\":100000000,\"hasChild\":0},{\"id\":585,\"name\":\"上海市环境监测中心\",\"parentid\":583,\"order\":99999500,\"hasChild\":0},{\"id\":586,\"name\":\"上海市生态环境局执法总队\",\"parentid\":583,\"order\":99999000,\"hasChild\":0},{\"id\":587,\"name\":\"上海市辐射环境安全技术中心\",\"parentid\":583,\"order\":99998500,\"hasChild\":0},{\"id\":588,\"name\":\"上海市固体废物与化学品管理技术中心\",\"parentid\":583,\"order\":99998000,\"hasChild\":0},{\"id\":589,\"name\":\"上海市环境保护宣传教育中心\",\"parentid\":583,\"order\":99997500,\"hasChild\":0},{\"id\":590,\"name\":\"测试部门\",\"parentid\":358,\"order\":99997500,\"hasChild\":1},{\"id\":591,\"name\":\"测试子部门\",\"parentid\":590,\"order\":99999500,\"hasChild\":0},{\"id\":592,\"name\":\"测试子部门1\",\"parentid\":590,\"order\":100000000,\"hasChild\":0},{\"id\":593,\"name\":\"测试子部门2\",\"parentid\":590,\"order\":99999000,\"hasChild\":0},{\"id\":599,\"name\":\"推送简单\",\"parentid\":358,\"order\":99997000,\"hasChild\":1},{\"id\":602,\"name\":\"推送主节点变更测试\",\"parentid\":599,\"order\":99999500,\"hasChild\":0},{\"id\":603,\"name\":\"推送子部门\",\"parentid\":675,\"order\":100000000,\"hasChild\":1},{\"id\":606,\"name\":\"导出\",\"parentid\":358,\"order\":99995500,\"hasChild\":0},{\"id\":607,\"name\":\"ces\",\"parentid\":358,\"order\":99995000,\"hasChild\":0},{\"id\":610,\"name\":\"测试10-12\",\"parentid\":380,\"order\":100000000,\"hasChild\":0},{\"id\":611,\"name\":\"上海市大数据股份有限公司\",\"parentid\":351,\"order\":100000000,\"hasChild\":1},{\"id\":612,\"name\":\"人力资源管理部门\",\"parentid\":611,\"order\":99998500,\"hasChild\":0},{\"id\":613,\"name\":\"其他一些股份制有限公司\",\"parentid\":358,\"order\":99999000,\"hasChild\":1},{\"id\":614,\"name\":\"技术研发部门\",\"parentid\":611,\"order\":99998000,\"hasChild\":1},{\"id\":615,\"name\":\"行政执行部门\",\"parentid\":611,\"order\":99999500,\"hasChild\":0},{\"id\":616,\"name\":\"总裁办公室\",\"parentid\":611,\"order\":100000000,\"hasChild\":0},{\"id\":618,\"name\":\"行业集成组\",\"parentid\":614,\"order\":99999000,\"hasChild\":0},{\"id\":619,\"name\":\"云资源管理组\",\"parentid\":614,\"order\":100000000,\"hasChild\":0},{\"id\":620,\"name\":\"网络安全与运营维护组\",\"parentid\":614,\"order\":99998000,\"hasChild\":1},{\"id\":621,\"name\":\"大数据组\",\"parentid\":614,\"order\":99997500,\"hasChild\":0},{\"id\":622,\"name\":\"局属单位\",\"parentid\":162,\"order\":99999500,\"hasChild\":1},{\"id\":623,\"name\":\"离职人员\",\"parentid\":613,\"order\":100000000,\"hasChild\":0},{\"id\":624,\"name\":\"上海市市级机关建设管理事务中心\",\"parentid\":622,\"order\":100000000,\"hasChild\":0},{\"id\":625,\"name\":\"上海市市级机关国有资产事务中心(上海市机关事务行政服务中心)\",\"parentid\":622,\"order\":99999500,\"hasChild\":0},{\"id\":626,\"name\":\"上海市机关事务管理局人防工程管理中心(上海市机关事务管理局老干部活动室)\",\"parentid\":622,\"order\":99999000,\"hasChild\":0},{\"id\":627,\"name\":\"上海市市级机关第二幼儿园\",\"parentid\":622,\"order\":99998500,\"hasChild\":0},{\"id\":628,\"name\":\"上海市政府采购中心\",\"parentid\":622,\"order\":99998000,\"hasChild\":0},{\"id\":629,\"name\":\"财务会计部门\",\"parentid\":611,\"order\":99999000,\"hasChild\":0},{\"id\":647,\"name\":\"推送23\",\"parentid\":408,\"order\":99999500,\"hasChild\":0},{\"id\":648,\"name\":\"项目管理部门\",\"parentid\":614,\"order\":99998500,\"hasChild\":0},{\"id\":649,\"name\":\"SHDATA办公平台测试部门\",\"parentid\":358,\"order\":100000000,\"hasChild\":0},{\"id\":651,\"name\":\"0313测试部门全程\",\"parentid\":653,\"order\":100000000,\"hasChild\":1},{\"id\":653,\"name\":\"0313测试子部门全称\",\"parentid\":651,\"order\":100000000,\"hasChild\":1},{\"id\":665,\"name\":\"真的有很多人\",\"parentid\":668,\"order\":100000000,\"hasChild\":1},{\"id\":666,\"name\":\"泛微网络\",\"parentid\":351,\"order\":99996500,\"hasChild\":0},{\"id\":667,\"name\":\"测试组\",\"parentid\":614,\"order\":99999500,\"hasChild\":1},{\"id\":668,\"name\":\"可能有一个人\",\"parentid\":665,\"order\":100000000,\"hasChild\":1},{\"id\":670,\"name\":\"测试推全子部门\",\"parentid\":674,\"order\":100000000,\"hasChild\":1},{\"id\":674,\"name\":\"22\",\"parentid\":670,\"order\":100000000,\"hasChild\":1},{\"id\":675,\"name\":\"推送子子部门\",\"parentid\":603,\"order\":100000000,\"hasChild\":1},{\"id\":676,\"name\":\"区政府办公厅\",\"parentid\":250,\"order\":100000000,\"hasChild\":1},{\"id\":677,\"name\":\"区大数据中心\",\"parentid\":676,\"order\":100000000,\"hasChild\":0},{\"id\":678,\"name\":\"测试组\",\"parentid\":247,\"order\":99996500,\"hasChild\":0},{\"id\":679,\"name\":\"测试部门3\",\"parentid\":620,\"order\":100000001,\"hasChild\":0},{\"id\":680,\"name\":\"测试部门2\",\"parentid\":620,\"order\":99999500,\"hasChild\":0},{\"id\":681,\"name\":\"测试部门2_1\",\"parentid\":620,\"order\":100000001,\"hasChild\":0},{\"id\":682,\"name\":\"测试部门4\",\"parentid\":620,\"order\":100000001,\"hasChild\":0},{\"id\":683,\"name\":\"测试部门5\",\"parentid\":620,\"order\":100000000,\"hasChild\":0},{\"id\":688,\"name\":\"k测试5\",\"parentid\":369,\"order\":100000000,\"hasChild\":0},{\"id\":689,\"name\":\"k测试6\",\"parentid\":369,\"order\":99999500,\"hasChild\":0},{\"id\":690,\"name\":\"d测试1\",\"parentid\":667,\"order\":99999500,\"hasChild\":0},{\"id\":691,\"name\":\"d测试2\",\"parentid\":667,\"order\":99999000,\"hasChild\":0},{\"id\":692,\"name\":\"d测试3\",\"parentid\":667,\"order\":99998500,\"hasChild\":1},{\"id\":693,\"name\":\"d测试4\",\"parentid\":692,\"order\":100000000,\"hasChild\":1},{\"id\":694,\"name\":\"d测试5\",\"parentid\":693,\"order\":100000000,\"hasChild\":1},{\"id\":695,\"name\":\"d测试6\",\"parentid\":694,\"order\":100000000,\"hasChild\":1},{\"id\":696,\"name\":\"d测试7\",\"parentid\":695,\"order\":100000000,\"hasChild\":1},{\"id\":697,\"name\":\"d测试8\",\"parentid\":696,\"order\":100000000,\"hasChild\":1},{\"id\":698,\"name\":\"d测试9\",\"parentid\":697,\"order\":100000000,\"hasChild\":1},{\"id\":699,\"name\":\"d测试10\",\"parentid\":698,\"order\":100000000,\"hasChild\":0},{\"id\":700,\"name\":\"技术支持厂商\",\"parentid\":1,\"order\":99996000,\"hasChild\":1},{\"id\":701,\"name\":\"公务之家测试单位\",\"parentid\":700,\"order\":100000000,\"hasChild\":1},{\"id\":705,\"name\":\"局领导\",\"parentid\":701,\"order\":100000000,\"hasChild\":0},{\"id\":706,\"name\":\"财务处\",\"parentid\":701,\"order\":99999500,\"hasChild\":1},{\"id\":707,\"name\":\"开发部\",\"parentid\":701,\"order\":99999000,\"hasChild\":0},{\"id\":708,\"name\":\"测试部\",\"parentid\":701,\"order\":99998500,\"hasChild\":1},{\"id\":709,\"name\":\"财务一处\",\"parentid\":706,\"order\":100000000,\"hasChild\":1},{\"id\":710,\"name\":\"会计\",\"parentid\":709,\"order\":100000000,\"hasChild\":0},{\"id\":711,\"name\":\"一部\",\"parentid\":708,\"order\":100000000,\"hasChild\":0},{\"id\":712,\"name\":\"二部\",\"parentid\":708,\"order\":99999500,\"hasChild\":0}]"; +// List list = JSONObject.parseObject(json, List.class); + List departmentInfo = orgHrmAsyncApiService.getDepartmentInfo(); + System.out.println("departmentInfoList => " + departmentInfo); + // 过滤出父节点并根据id进行升序排序 + List rootDepList = departmentInfo + .stream() + .filter(item -> 1 == item.getHasChild() && -1 != item.getParentid()) + .sorted(Comparator.comparing(OtherSysDepartment::getId)) + .collect(Collectors.toList()); + System.out.println("rootDepList => "+ JSONObject.toJSONString(rootDepList)); + for (OtherSysDepartment sysDepartment : rootDepList) { + setChildList(sysDepartment, departmentInfo); + } + // 过滤出父节点并根据id进行升序排序 + + System.out.println("departmentInfo => " + JSONObject.toJSONString(departmentInfo, SerializerFeature.DisableCircularReferenceDetect)); + } + + public void setChildList(OtherSysDepartment department, List departmentList){ + if(department.getHasChild() == 0){ + return; + } + List childList = departmentList + .stream() + .filter(item -> department.getId() == item.getParentid()) + .collect(Collectors.toList()); + System.out.println("childList => " + JSONObject.toJSONString(childList)); + department.setChildList(childList); + for (OtherSysDepartment sysDepartment : childList) { + setChildList(sysDepartment, departmentList); + } + } + private final SendTodoTaskMapper mapper = Util.getMapper(SendTodoTaskMapper.class); + @Test + public void testD(){ + ArrayList details = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + CusTodoTaskToOADetail detail = new CusTodoTaskToOADetail(); + detail.setTaskNum("14672332" + (System.currentTimeMillis() / 1000)); + detail.setRequestUrl("11111"); + detail.setTaskName("taskName" + i); + detail.setTaskType(0); + detail.setStatus(0); + detail.setSuccess(0); + detail.setResponse("{\n" + + " \"code\": 200,\n" + + " \"msg\": \"操作成功\", //返回文字描述\n" + + " \"data\": null,\n" + + " \"total\": null,\n" + + " \"totalPage\": null,\n" + + " \"takeTime\": null\n" + + "}"); + detail.setRequestJson(JSONObject.toJSONString(detail)); + String sourceTaskId = detail.getTaskNum().substring(0, detail.getTaskNum().length() - 10); + detail.setSourceTaskId(sourceTaskId); + details.add(detail); + } +// CusInfoToOAUtil.executeBatchByEntity(111, details,""); + ArrayList list = new ArrayList<>(); + ArrayList successTaskIds = new ArrayList<>(); + List lists = mapper.queryUnSendTodoTaskList("14672332"); + for (String num : lists) { + int success = 0; + CusDoneTaskOA taskOA = new CusDoneTaskOA(); + taskOA.setTaskNum(num); + taskOA.setTaskType(1); + String sourceTaskId =num.substring(0, num.length() - 10); + taskOA.setSourceTaskId(sourceTaskId); + taskOA.setResponse("{\n" + + " \"code\": 200,\n" + + " \"msg\": \"操作成功\", //返回文字描述\n" + + " \"data\": null,\n" + + " \"total\": null,\n" + + " \"totalPage\": null,\n" + + " \"takeTime\": null\n" + + "}"); + taskOA.setRequestUrl("22222222"); + taskOA.setRequestJson(JSONObject.toJSONString(num)); + taskOA.setSuccess(success); + list.add(taskOA); + successTaskIds.add(num); + } + CusInfoToOAUtil.executeBatchByEntity(111, list,""); + mapper.updateStatusByTaskNum(successTaskIds); + } + + public void sqlTest(int modelId, List list, String whereSql){ + List> params = new ArrayList<>(); + List> whereParams = new ArrayList<>(); + StringBuilder whereSqlSb = new StringBuilder(); + LinkedHashSet whereFields = new LinkedHashSet<>(); + for (Object o : list) { + if(Objects.isNull(o)){ + continue; + } + Class clazz = o.getClass(); + Field[] fields = clazz.getDeclaredFields(); + LinkedHashMap linkedHashMap = new LinkedHashMap<>(); + ArrayList whereParam = new ArrayList<>(); + List fieldArr = Arrays.stream(fields).collect(Collectors.toList()); + Class superclass = clazz.getSuperclass(); + // 找出父类所有的字段 + while (superclass != null){ + fieldArr.addAll(Arrays.stream(superclass.getDeclaredFields()).collect(Collectors.toList())); + superclass = superclass.getSuperclass(); + } + for (Field field : fieldArr) { + field.setAccessible(true); + String fieldName = field.getName(); + Object fieldValue; + try { + fieldValue = field.get(o); + } catch (IllegalAccessException e) { + throw new CustomerException(Util.logStr("field get error! the error is :[{}]," + + "current field is: [{}], current obj is: [{}]", e.getMessage(), fieldName, JSONObject.toJSONString(o))); + } + if(Objects.isNull(fieldValue)){ + continue; + } + // 数据库字段映射 如果注解中没有值那么写入数据库就是实体类字段名 + SqlFieldMapping sqlFieldMapping = field.getAnnotation(SqlFieldMapping.class); + if(null == sqlFieldMapping){ + continue; + } + String sqlFieldMappingValue = sqlFieldMapping.value(); + if(StringUtils.isNotBlank(sqlFieldMappingValue)){ + fieldName = sqlFieldMappingValue; + } + linkedHashMap.put(fieldName, fieldValue); + + // 更新条件字段注解 + SqlUpdateWhereField sqlUpdateWhereField = field.getAnnotation(SqlUpdateWhereField.class); + if(null == sqlUpdateWhereField || !sqlUpdateWhereField.value()){ + continue; + } + if(StringUtils.isBlank(whereSql)){ + whereFields.add(fieldName + " = ? "); + } + whereParam.add(fieldValue.toString()); + } + params.add(linkedHashMap); + whereParams.add(whereParam); + } + if(!whereFields.isEmpty()){ + whereSqlSb = new StringBuilder("select id from #{tableName} where "); + for (String field : whereFields) { + whereSqlSb.append(field).append(" and "); + } + whereSql = whereSqlSb.substring(0, whereSqlSb.length() - 4); + } + System.out.println("params => " +JSONObject.toJSONString(params)); + System.out.println("whereParams => " +JSONObject.toJSONString(whereParams)); + System.out.println("whereSql => " +JSONObject.toJSONString(whereSql)); + + } + + + SendTodoTaskUtil sendTodoTaskUtil = new SendTodoTaskUtil(); + @Test + public void testToken(){ + String hrmConvertRuleSql = ShBigDataUtil.getPropertiesValByKey("hrmSenderConvertRuleSql"); + System.out.println("hrm =>" + hrmConvertRuleSql); + RequestStatusObj obj = new RequestStatusObj(); + obj.setRequestid(121323); + obj.setNodeid(12); + System.out.println("convert => " + sendTodoTaskUtil.getConvertHrm(0, obj, 22 + "," + 23)); +// String requestid = "8288283"; +// String detail = requestid + "" + (System.currentTimeMillis() / 1000); +// System.out.println(detail.substring(0, detail.length() - 10)); +// for (int i = 0; i < 10; i++) { +// int finalI = i; +// new Thread(()->{ +// try { +// if(finalI > 5){ +// Thread.sleep(1000 * 5 * finalI); +// } +// System.out.println("多线程校验token => " + ShBigDataUtil.getToken()); +// }catch (Exception e){ +// +// } +// +// }).start(); +// } +// +// try { +// Thread.sleep(1000 * 60 * 3); +// String token1 = ShBigDataUtil.getToken(); +// System.out.println("模拟过期 => " + token1); +// }catch (Exception e){ +// +// } + } +} diff --git a/src/test/java/xuanran/wang/mq/CusMQType.java b/src/test/java/xuanran/wang/mq/CusMQType.java new file mode 100644 index 0000000..37aebdb --- /dev/null +++ b/src/test/java/xuanran/wang/mq/CusMQType.java @@ -0,0 +1,17 @@ +package xuanran.wang.mq; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/3 15:13 + */ +public enum CusMQType { + ROCKET_MQ("RocketMQ",0), + KAFKA("Kafka",1), + RABBIT_MQ("RabbitMQ",2), + ACTIVE_MQ("ActiveMQ",3); + + CusMQType(String type, int code) { + } +} diff --git a/src/test/java/xuanran/wang/mq/consumer/DefaultConsumer.java b/src/test/java/xuanran/wang/mq/consumer/DefaultConsumer.java new file mode 100644 index 0000000..2c4e646 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/consumer/DefaultConsumer.java @@ -0,0 +1,21 @@ +package xuanran.wang.mq.consumer; + +import com.weaverboot.frame.ioc.anno.classAnno.WeaSysInitComponent; +import xuanran.wang.mq.infaces.CusMQClient; +import xuanran.wang.mq.infaces.callback.CusMQCallBack; +import xuanran.wang.mq.mq.CusMQFactory; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/4/3 15:04 + */ +@WeaSysInitComponent("MQ-消费者") +public class DefaultConsumer { + + public static void registerConsumer(String configName, String type, CusMQCallBack callBack){ + CusMQClient cusMQ = CusMQFactory.createCusMQ(configName, type); + cusMQ.consumer(callBack); + } +} diff --git a/src/test/java/xuanran/wang/mq/infaces/CusBaseMQ.java b/src/test/java/xuanran/wang/mq/infaces/CusBaseMQ.java new file mode 100644 index 0000000..734b7f7 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/CusBaseMQ.java @@ -0,0 +1,27 @@ +package xuanran.wang.mq.infaces; + +import aiyh.utils.Util; +import org.apache.log4j.Logger; +import xuanran.wang.mq.infaces.aop.CusMQAop; + +/** + *

mq基础类

+ * + * @author xuanran.wang + * @date 2023/3/31 11:47 + */ +public interface CusBaseMQ { + Logger log = Util.getLogger(); + /** + *

初始化生产者

+ **/ + void initProducer(String configName); + /** + *

初始化消费者

+ **/ + void initConsumer(String configName); + /** + *

销毁

+ **/ + void destroy(); +} diff --git a/src/test/java/xuanran/wang/mq/infaces/CusConsumer.java b/src/test/java/xuanran/wang/mq/infaces/CusConsumer.java new file mode 100644 index 0000000..fbdcc67 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/CusConsumer.java @@ -0,0 +1,16 @@ +package xuanran.wang.mq.infaces; + +import xuanran.wang.mq.infaces.callback.CusMQCallBack; + +/** + *

消费者

+ * + * @author xuanran.wang + * @date 2023/3/31 11:56 + */ +public interface CusConsumer extends CusBaseMQ{ + /** + *

消费

+ **/ + void consumer(CusMQCallBack callBack); +} diff --git a/src/test/java/xuanran/wang/mq/infaces/CusMQClient.java b/src/test/java/xuanran/wang/mq/infaces/CusMQClient.java new file mode 100644 index 0000000..6c0d88f --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/CusMQClient.java @@ -0,0 +1,11 @@ +package xuanran.wang.mq.infaces; + +/** + *

客户端

+ * + * @author xuanran.wang + * @date 2023/3/31 13:09 + */ +public interface CusMQClient extends CusProducer, CusConsumer { +} + diff --git a/src/test/java/xuanran/wang/mq/infaces/CusProducer.java b/src/test/java/xuanran/wang/mq/infaces/CusProducer.java new file mode 100644 index 0000000..84cc44a --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/CusProducer.java @@ -0,0 +1,16 @@ +package xuanran.wang.mq.infaces; + +import java.util.Map; + +/** + *

生产者方法

+ * + * @author xuanran.wang + * @date 2023/3/30 11:37 + */ +public interface CusProducer extends CusBaseMQ{ + /** + *

生产者

+ **/ + void send(Object message); +} diff --git a/src/test/java/xuanran/wang/mq/infaces/aop/CusMQAop.java b/src/test/java/xuanran/wang/mq/infaces/aop/CusMQAop.java new file mode 100644 index 0000000..a5184af --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/aop/CusMQAop.java @@ -0,0 +1,18 @@ +package xuanran.wang.mq.infaces.aop; + +import aiyh.utils.tool.cn.hutool.core.collection.CollUtil; + +/** + *

切面

+ * + * @author xuanran.wang + * @date 2023/3/31 12:52 + */ +public interface CusMQAop { + void sendBefore(); + void sendAfter(); + void consumerBefore(); + void consumerAfter(); + void destroyBefore(); + void destroyAfter(); +} diff --git a/src/test/java/xuanran/wang/mq/infaces/callback/CusMQCallBack.java b/src/test/java/xuanran/wang/mq/infaces/callback/CusMQCallBack.java new file mode 100644 index 0000000..81a19a6 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/infaces/callback/CusMQCallBack.java @@ -0,0 +1,35 @@ +package xuanran.wang.mq.infaces.callback; + +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.message.MessageExt; + +import java.util.List; + + +/** + *

回调

+ * + * @author xuanran.wang + * @date 2023/3/31 13:13 + */ +public interface CusMQCallBack { + /** + *

kafka 回调

+ * @author xuanran.wang + * @dateTime 2023/4/3 14:55 + * @param records 消息对象 + **/ + void kafkaCallBack(ConsumerRecords records); + /** + *

rocket-MQ 回调

+ * @author xuanran.wang + * @dateTime 2023/4/3 14:55 + * @param msgList 消息列表 + * @param context 上下文 + * @return 状态 + **/ + ConsumeConcurrentlyStatus rocketCallBack(List msgList, ConsumeConcurrentlyContext context); +} diff --git a/src/test/java/xuanran/wang/mq/mq/CusKafkaMQ.java b/src/test/java/xuanran/wang/mq/mq/CusKafkaMQ.java new file mode 100644 index 0000000..b17dc4d --- /dev/null +++ b/src/test/java/xuanran/wang/mq/mq/CusKafkaMQ.java @@ -0,0 +1,86 @@ +package xuanran.wang.mq.mq; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import lombok.NoArgsConstructor; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerRecord; +import xuanran.wang.mq.infaces.*; +import xuanran.wang.mq.infaces.aop.CusMQAop; +import xuanran.wang.mq.infaces.callback.CusMQCallBack; +import xuanran.wang.mq.util.CusMQUtil; + +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Map; + +/** + *

kafka

+ * + * @author xuanran.wang + * @date 2023/3/30 11:44 + */ +@NoArgsConstructor +public class CusKafkaMQ implements CusMQClient { + private KafkaProducer producer = null; + private KafkaConsumer consumer = null; + private Map config = null; + private CusMQAop cusMQAop = new DefaultCusMQAop(); + public CusKafkaMQ(CusMQAop cusMQAop){ + this.cusMQAop = cusMQAop; + } + + @Override + public void initProducer(String configName) { + config = CusMQUtil.getConfigMapByName(configName); + producer = new KafkaProducer<>(config); + } + + @Override + public void initConsumer(String configName) { + config = CusMQUtil.getConfigMapByName(configName); + consumer = new KafkaConsumer<>(config); + } + + @Override + public void send(Object message) { + String topic = Util.null2DefaultStr(config.get("topic"),""); + try { + producer.send(new ProducerRecord<>(topic, JSONObject.toJSONString(message))).get(); + }catch (Exception e){ + log.error(Util.logStr("kafka producer topic: {}, message: {}, error: {}", topic, JSONObject.toJSONString(message), e.getMessage())); + throw new CustomerException("kafka producer send message error!"); + }finally { + this.destroy(); + } + } + + @Override + public void consumer(CusMQCallBack callBack) { + new Thread(() -> { + try { + while (true) { + /*轮询获取数据*/ + ConsumerRecords records = consumer.poll(Duration.of(100, ChronoUnit.MILLIS)); + callBack.kafkaCallBack(records); + } + } finally { + consumer.close(); + } + }).start(); + } + + @Override + public void destroy() { + if(producer != null){ + producer.close(); + } + if(consumer != null){ + consumer.close(); + } + } + +} diff --git a/src/test/java/xuanran/wang/mq/mq/CusMQFactory.java b/src/test/java/xuanran/wang/mq/mq/CusMQFactory.java new file mode 100644 index 0000000..e2b9352 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/mq/CusMQFactory.java @@ -0,0 +1,45 @@ +package xuanran.wang.mq.mq; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import xuanran.wang.mq.infaces.CusMQClient; +import xuanran.wang.mq.infaces.aop.CusMQAop; + +/** + *

工厂

+ * + * @author xuanran.wang + * @date 2023/3/30 11:38 + */ +public class CusMQFactory { + + public static final String ROCKET_MQ = "0"; + + public static final String KAFKA = "1"; + + public static final String RABBIT_MQ = "2"; + + public static final String ACTIVE_MQ = "3"; + + public static CusMQClient createCusMQ(String configName, String type) { + return createCusMQ(configName, type, null); + } + + public static CusMQClient createCusMQ(String configName, String type, CusMQAop cusMQAop){ + CusMQClient cusAbstractMQ; + switch (type){ + case ROCKET_MQ: { + cusAbstractMQ = new CusRocketMQ(); + break; + } + case KAFKA: { + cusAbstractMQ = new CusKafkaMQ(); + break; + } + default: throw new CustomerException(Util.logStr("create CusMQClient error! type: {}, not support!", type)); + } + cusAbstractMQ.initConsumer(configName); + cusAbstractMQ.initProducer(configName); + return cusAbstractMQ; + } +} diff --git a/src/test/java/xuanran/wang/mq/mq/CusRocketMQ.java b/src/test/java/xuanran/wang/mq/mq/CusRocketMQ.java new file mode 100644 index 0000000..83f8497 --- /dev/null +++ b/src/test/java/xuanran/wang/mq/mq/CusRocketMQ.java @@ -0,0 +1,146 @@ +package xuanran.wang.mq.mq; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import lombok.NoArgsConstructor; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.exception.MQBrokerException; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.client.producer.DefaultMQProducer; +import org.apache.rocketmq.client.producer.SendResult; +import org.apache.rocketmq.client.producer.SendStatus; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.apache.rocketmq.remoting.common.RemotingHelper; +import org.apache.rocketmq.remoting.exception.RemotingException; +import weaver.xuanran.wang.shyl_mq.constant.RocketMQConstant; +import xuanran.wang.mq.infaces.CusMQClient; +import xuanran.wang.mq.infaces.aop.CusMQAop; +import xuanran.wang.mq.infaces.callback.CusMQCallBack; +import xuanran.wang.mq.util.CusMQUtil; + +import java.util.List; +import java.util.Map; + +/** + *

自定义rocket-mq

+ * + * @author xuanran.wang + * @date 2023/3/31 13:02 + */ +@NoArgsConstructor +public class CusRocketMQ implements CusMQClient { + private DefaultMQProducer producer = null; + + private DefaultMQPushConsumer consumer = null; + + private Map config = null; + private CusMQAop cusMQAop = new DefaultCusMQAop(); + + public CusRocketMQ(CusMQAop cusMQAop){ + this.cusMQAop = cusMQAop; + } + + @Override + public void initProducer(String configName) { + Map configMap = CusMQUtil.getConfigMapByName(configName); + this.config = configMap; + producer = new DefaultMQProducer(Util.null2DefaultStr(configMap.get("producerGroup"),"")); + // 发送消息最大超时时间 默认60000 + int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT); + producer.setSendMsgTimeout(sendMsgTimeOut); + producer.setVipChannelEnabled(false); + producer.setNamesrvAddr(Util.null2String(configMap.get("serverAddr"))); + try { + producer.start(); + }catch (MQClientException e){ + throw new CustomerException(Util.logStr("producer start error!:{}",e.getMessage())); + } + } + + @Override + public void initConsumer(String configName) { + Map configMap = CusMQUtil.getConfigMapByName(configName); + this.config = configMap; + try { + int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("maxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES); + // 声明一个消费者consumer,需要传入一个组 weaver-consumer + consumer = new DefaultMQPushConsumer(Util.null2String(configMap.get("consumerGroup"))); + // 设置集群的NameServer地址,多个地址之间以分号分隔 183.192.65.118:9876 + consumer.setNamesrvAddr(Util.null2String(configMap.get("serverAddr"))); + // 设置consumer的消费策略 + consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); + // 集群模式消费,广播消费不会重试 + consumer.setMessageModel(MessageModel.CLUSTERING); + // 设置最大重试次数,默认是16次 + consumer.setMaxReconsumeTimes(maxReconsumeTimes); + // 设置consumer所订阅的Topic和Tag,*代表全部的Tag AUTH_CONSOLE_USERINFO_TOPIC + consumer.subscribe(Util.null2String(configMap.get("topic")),"*"); + // 是否开启vip + consumer.setVipChannelEnabled(false); + }catch (Exception e){ + throw new CustomerException(Util.logStr("init rocket MQ consumer error: {}!",e.getMessage())); + } + } + + @Override + public void destroy() { + if(producer != null){ + producer.shutdown(); + } + if(consumer != null){ + consumer.shutdown(); + } + } + + @Override + public void send(Object message) { + cusMQAop.sendBefore(); + // 队列名 + String topic = Util.null2DefaultStr(config.get("topic"), ""); + Message msg; + try { + msg = new Message(topic, JSONObject.toJSONString(message).getBytes(RemotingHelper.DEFAULT_CHARSET)); + } catch (Exception e) { + throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage())); + } + // 发送成功标识 + boolean sendOk = false; + // 发送次数 + int count = 0; + do { + SendResult result; + count++; + try { + result = producer.send(msg); + } catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) { + throw new CustomerException(Util.logStr("producer send message error!: {}", e.getMessage())); + } + SendStatus sendStatus = result.getSendStatus(); + // 如果失败 + if (!SendStatus.SEND_OK.equals(sendStatus)) { + String error = Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus); + // 如果重试超过最大次数 + if(count >= RocketMQConstant.SEND_MAX_COUNT){ + throw new CustomerException(error + " and retry > max"); + } + }else { + sendOk = true; + } + } while (!sendOk); + cusMQAop.sendAfter(); + } + + + @Override + public void consumer(CusMQCallBack callBack) { + consumer.registerMessageListener(callBack::rocketCallBack); + try { + consumer.start(); + }catch (Exception e){ + throw new CustomerException("consumer start error : " + e.getMessage()); + } + } +} diff --git a/src/test/java/xuanran/wang/mq/mq/DefaultCusMQAop.java b/src/test/java/xuanran/wang/mq/mq/DefaultCusMQAop.java new file mode 100644 index 0000000..483264a --- /dev/null +++ b/src/test/java/xuanran/wang/mq/mq/DefaultCusMQAop.java @@ -0,0 +1,41 @@ +package xuanran.wang.mq.mq; + +import xuanran.wang.mq.infaces.aop.CusMQAop; + +/** + *

默认的aop

+ * + * @author xuanran.wang + * @date 2023/3/31 12:56 + */ +public class DefaultCusMQAop implements CusMQAop { + @Override + public void sendBefore() { + + } + + @Override + public void sendAfter() { + + } + + @Override + public void consumerBefore() { + + } + + @Override + public void consumerAfter() { + + } + + @Override + public void destroyBefore() { + + } + + @Override + public void destroyAfter() { + + } +} diff --git a/src/test/java/xuanran/wang/mq/test/MQTest.java b/src/test/java/xuanran/wang/mq/test/MQTest.java new file mode 100644 index 0000000..a9a99df --- /dev/null +++ b/src/test/java/xuanran/wang/mq/test/MQTest.java @@ -0,0 +1,58 @@ +package xuanran.wang.mq.test; + +import basetest.BaseTest; +import org.junit.Test; +import weaver.general.Util; +import xuanran.wang.mq.infaces.CusMQClient; +import xuanran.wang.mq.infaces.aop.CusMQAop; +import xuanran.wang.mq.mq.CusMQFactory; + +/** + *

+ * + * @author xuanran.wang + * @date 2023/3/31 12:34 + */ +public class MQTest extends BaseTest { + + @Test + public void testKafka(){ + CusMQAop cusMQAop = new CusMQAop() { + @Override + public void sendBefore() { + System.out.println("发送前!"); + } + + @Override + public void sendAfter() { + System.out.println("发送后!"); + } + + @Override + public void consumerBefore() { + System.out.println("消费前!"); + } + + @Override + public void consumerAfter() { + System.out.println("消费后!"); + } + + @Override + public void destroyBefore() { + System.out.println("销毁前!"); + } + + @Override + public void destroyAfter() { + System.out.println("销毁前!"); + } + }; + + CusMQClient cusMQ = CusMQFactory.createCusMQ("OACarTest", CusMQFactory.ROCKET_MQ); + + cusMQ.send("11212121212"); + + } + +} diff --git a/src/test/java/xuanran/wang/mq/util/CusMQUtil.java b/src/test/java/xuanran/wang/mq/util/CusMQUtil.java new file mode 100644 index 0000000..29d318b --- /dev/null +++ b/src/test/java/xuanran/wang/mq/util/CusMQUtil.java @@ -0,0 +1,53 @@ +package xuanran.wang.mq.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; + +import java.util.HashMap; +import java.util.Map; + +/** + *

mq工具类

+ * + * @author xuanran.wang + * @date 2023/3/31 11:52 + */ +public class CusMQUtil { + private static final Logger log = Util.getLogger(); + private static final String[] checkField = new String[]{"serverAddr", "topic"}; + /** + *

配置文件本地存储对象

+ **/ + public static Map> CONFIG_MAPS = new HashMap<>(16); + + /** + *

通过配置文件名称获取配置map

+ * @author xuanran.wang + * @dateTime 2023/1/4 13:18 + * @param configName 配置文件名称 + * @return 配置文件map + **/ + public synchronized static Map getConfigMapByName(String configName){ + Map configMap = new HashMap<>(); + if(!CONFIG_MAPS.containsKey(configName)){ + configMap = Util.getProperties2Map(configName); + checkConfig(configMap); + CONFIG_MAPS.put(configName, configMap); + }else { + configMap = CONFIG_MAPS.get(configName); + } + return configMap; + } + + public static void checkConfig(Map configMap){ + for (String field : checkField) { + if(!configMap.containsKey(field) && StringUtils.isBlank(Util.null2DefaultStr(configMap.get(field),""))){ + log.error("MQ config : " + JSONObject.toJSONString(configMap)); + throw new CustomerException("MQ config map not contains " + field + " or " + field + " is empty!"); + } + } + } +} diff --git a/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java b/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java index 563e1dc..057a32b 100644 --- a/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java +++ b/src/test/java/xuanran/wang/shyl/dataasync/AsyncTest.java @@ -174,25 +174,9 @@ public class AsyncTest extends BaseTest { consumer.registerMessageListener(new MessageListenerConcurrently() { @Override public ConsumeConcurrentlyStatus consumeMessage(List list, ConsumeConcurrentlyContext consumeConcurrentlyContext) { - MessageExt messageExt = list.get(0); - String msgBody; - MQMessage mqMessage; - try { - msgBody = new String(messageExt.getBody(), StandardCharsets.UTF_8); - if (StringUtils.isBlank(msgBody)) { - throw new CustomerException("MQ msgBody is empty!"); - } - mqMessage = JSONObject.parseObject(msgBody, MQMessage.class); - // 业务主体 - String content = Util.null2DefaultStr(mqMessage.getContent(), ""); - if (StringUtils.isBlank(content)) { - throw new CustomerException(Util.logStr("the messageId : {}, content is empty!", Util.null2DefaultStr(mqMessage.getId(), ""))); - } - log.info(Util.logStr("MQMessage : {} ", mqMessage)); - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; - } catch (Exception e) { - throw new CustomerException("consumeMessage => " + e.getMessage()); - } + System.out.println("msgs : " + JSONObject.toJSONString(list)); + System.out.println("context : " + JSONObject.toJSONString(consumeConcurrentlyContext)); + return ConsumeConcurrentlyStatus.RECONSUME_LATER; } }); consumer.start(); diff --git a/src/test/java/xuanran/wang/shyl/dataasync/MapperTest.java b/src/test/java/xuanran/wang/shyl/dataasync/MapperTest.java index 98a6fa5..1c548b6 100644 --- a/src/test/java/xuanran/wang/shyl/dataasync/MapperTest.java +++ b/src/test/java/xuanran/wang/shyl/dataasync/MapperTest.java @@ -6,14 +6,16 @@ import com.api.meeting.util.FieldUtil; import com.api.xuanran.wang.shyl.entity.meeting.MeetingCusFieldConfigMain; import com.api.xuanran.wang.shyl.service.MeetingService; import org.junit.Test; +import weaver.file.ImageFileManager; import weaver.general.TimeUtil; import weaver.general.Util; import weaver.systeminfo.SystemEnv; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; /** *

@@ -42,8 +44,32 @@ public class MapperTest extends BaseTest { } @Test - public void testC(){ - String s = TimeUtil.dateAdd("2023-03-02", -3); - log.info("time => " + s); + public void testC() throws IOException { + InputStream inputStream = new FileInputStream("/Users/wangxuanran/Downloads/chrome/1589665325711042c4c7c0e4ff4c6868.png"); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + byte[] bytes = outputStream.toByteArray(); + String str = Base64.getEncoder().encodeToString(bytes); + System.out.println("str => " + str); + + } + + @Test + public void testD(){ + String cusSql = "select a.docsubject fileName, concat('http://10.184.45.196/zjdownload?filed=', a.id)\n" + + " fullPath, RIGHT(c.imagefilename, INSTR(REVERSE(c.imagefilename),'.')) downloadType\n" + + "from docdetail a\n" + + "left join docimagefile b\n" + + "on a.id = b.docid\n" + + "left join docimagefile c\n" + + "on b.imagefileid = c.imagefileid\n" + + "where a.id in ${docIds}"; + String docIds = "1,2,3"; + cusSql = cusSql.replace("${docIds}", "( " + docIds + " )"); + System.out.println("cus => " + cusSql); } }