From 868fc51f2db97b61cac8220434f00ef8ff3192ee Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Tue, 3 Jan 2023 09:40:04 +0800 Subject: [PATCH] =?UTF-8?q?mq=E6=B6=88=E6=81=AF=E9=98=9F=E5=88=97=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xuanran.wang/bme/js/BuildContractApply.js | 15 +- javascript/xuanran.wang/bme/js/Common.js | 21 + .../bme/js/PurchaseContractApply.js | 12 +- .../xuanran.wang/bme/js/SaleContractApply.js | 1 + pom.xml | 8 + .../action/ContractApplyComDateAction.java | 7 +- .../asset/action/AssetDataPushAction.java | 65 +++ .../asset/service/AssetDataPushService.java | 111 +++++ .../constant/RequestPushConstant.java | 94 ++++ .../datapush/eneity/DetailRequestConfig.java | 16 +- .../datapush/eneity/MainRequestConfig.java | 9 +- .../datapush/mapper/RequestPushMapper.java | 50 +++ .../datapush/service/RequestPushService.java | 401 ++++++++++++++++++ .../xuanran/wang/shyl/mq/RocketMQFactory.java | 51 +++ .../wang/shyl/mq/RocketMQListener.java | 68 +++ .../shyl/mq/constant/RocketMQConstant.java | 15 + .../wang/shyl/mq/consumer/OrgConsumer.java | 41 ++ .../shyl/mq/consumer/PassWordConsumer.java | 40 ++ .../shyl/mq/consumer/UserInfoConsumer.java | 35 ++ .../wang/shyl/mq/entity/MQMessage.java | 44 ++ .../wang/shyl/mq/entity/ModifyPassWord.java | 43 ++ .../xuanran/wang/shyl/mq/entity/Org.java | 38 ++ .../xuanran/wang/shyl/mq/entity/UserInfo.java | 61 +++ .../wang/shyl/mq/mapper/ConsumerMapper.java | 35 ++ .../shyl/mq/service/CusInfoActionService.java | 20 + .../shyl/mq/service/impl/OrgServiceImpl.java | 28 ++ .../shyl/mq/service/impl/UserServiceImpl.java | 49 +++ .../mq/service/interfaces/CreateAction.java | 14 + .../mq/service/interfaces/DeleteAction.java | 14 + .../mq/service/interfaces/PassWordAction.java | 14 + .../mq/service/interfaces/UpdateAction.java | 14 + .../xuanran/wang/shyl/mq/util/RocketUtil.java | 104 +++++ .../wang/ambofo/checkuser/CheckUserTest.java | 9 + .../wang/epdi/datapush/RequestDataPush.java | 31 ++ 34 files changed, 1556 insertions(+), 22 deletions(-) create mode 100644 src/main/java/weaver/xuanran/wang/epdi/asset/action/AssetDataPushAction.java create mode 100644 src/main/java/weaver/xuanran/wang/epdi/asset/service/AssetDataPushService.java create mode 100644 src/main/java/weaver/xuanran/wang/epdi/datapush/constant/RequestPushConstant.java create mode 100644 src/main/java/weaver/xuanran/wang/epdi/datapush/mapper/RequestPushMapper.java create mode 100644 src/main/java/weaver/xuanran/wang/epdi/datapush/service/RequestPushService.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/entity/MQMessage.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/entity/ModifyPassWord.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/entity/Org.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/entity/UserInfo.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/CreateAction.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/DeleteAction.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/PassWordAction.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/UpdateAction.java create mode 100644 src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java create mode 100644 src/test/java/xuanran/wang/epdi/datapush/RequestDataPush.java diff --git a/javascript/xuanran.wang/bme/js/BuildContractApply.js b/javascript/xuanran.wang/bme/js/BuildContractApply.js index a58d098..723ec25 100644 --- a/javascript/xuanran.wang/bme/js/BuildContractApply.js +++ b/javascript/xuanran.wang/bme/js/BuildContractApply.js @@ -21,6 +21,7 @@ const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable); const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable); // 需要计算的款项类型集合 const computeDatePayType = ['0']; +const DETAIL_MAX_SIZE = 5; // 款项类型预计对应日期取值 const paymentTypeGetValue = { 0: (index)=>{ @@ -37,16 +38,22 @@ jQuery().ready(function(){ 'computeDatePayType': computeDatePayType, 'paymentTypeGetValue': paymentTypeGetValue } - // 默认增加5条 - for (let i = 0; i < 5; i++) { - WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}}); + let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(","); + + if(rowArr.length !== DETAIL_MAX_SIZE){ + // 默认增加5条 + for (let i = 0; i < 5; i++) { + WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}}); + } } + changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType) + // 主表字段发生变化 mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj); // 明细的款项类型字段变化绑定 - detailFieldChangeDetailCom(`${detail2AroundId},${detail2DayId}`, configObj); + detailFieldChangeDetailCom(`${detail2PaymentTypeId},${detail2AroundId},${detail2DayId}`, configObj); submitCallback(detailTable, detail2PayProportionId); diff --git a/javascript/xuanran.wang/bme/js/Common.js b/javascript/xuanran.wang/bme/js/Common.js index 230e7f0..4aae9d3 100644 --- a/javascript/xuanran.wang/bme/js/Common.js +++ b/javascript/xuanran.wang/bme/js/Common.js @@ -152,3 +152,24 @@ function changeDetailPayDate(obj){ WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT); } } + +/** + * 改变明细表字段只读 + * @param detailTable + * @param detailComDateField + * @param detailPaymentTypeId + * @param readOnlyArr + */ +function changeDetailFieldReadOnly(detailTable, detailComDateField, detailPaymentTypeId, readOnlyArr){ + let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(","); + for(let i=0; i < rowArr.length; i++){ + let index = rowArr[i]; + if(index !== ""){ + let paymentType = WfForm.getFieldValue(`${detailPaymentTypeId}_${index}`); + // 先进行赋值 + if(readOnlyArr.includes(paymentType)){ + WfForm.changeFieldAttr(`${detailComDateField}_${index}`, READ_ONLY); + } + } + } +} diff --git a/javascript/xuanran.wang/bme/js/PurchaseContractApply.js b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js index f4b95b1..4303665 100644 --- a/javascript/xuanran.wang/bme/js/PurchaseContractApply.js +++ b/javascript/xuanran.wang/bme/js/PurchaseContractApply.js @@ -4,10 +4,12 @@ */ // 明细表 const detailTable = "detail_3"; -// 主表项目字段 -const mainProjectId = WfForm.convertFieldNameToId("xmmc"); +// 主表订单编号字段 +const mainProjectId = WfForm.convertFieldNameToId("ddh1"); // 主表合同签订日期 const contractSignDateId = WfForm.convertFieldNameToId("htqdrq"); +// 主表订单申请日期 +const mainPOApplyId = WfForm.convertFieldNameToId("rkdsqrq"); // 明细2付款比例字段 const detailPayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable); // 明细2款项类型 @@ -28,10 +30,10 @@ const paymentTypeGetValue = { WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(contractSignDateId)}); }, 2: (index)=>{ - WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainPOApplyId)}); }, 4: (index)=>{ - WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)}); + WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainPOApplyId)}); } } $(()=>{ @@ -49,7 +51,7 @@ function init(){ 'computeDatePayType': computeDatePayType, 'paymentTypeGetValue': paymentTypeGetValue } - + changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, computeDatePayType) // 主表字段发生变化 mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj); // 明细的款项类型字段变化绑定 diff --git a/javascript/xuanran.wang/bme/js/SaleContractApply.js b/javascript/xuanran.wang/bme/js/SaleContractApply.js index 87cb38d..2836a58 100644 --- a/javascript/xuanran.wang/bme/js/SaleContractApply.js +++ b/javascript/xuanran.wang/bme/js/SaleContractApply.js @@ -52,6 +52,7 @@ function init(){ 'computeDatePayType': computeDatePayType, 'paymentTypeGetValue': paymentTypeGetValue } + changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType) // 主表字段发生变化 mainFieldChangeDetailCom(mainProjectId, detailTable, obj); // 明细的款项类型字段变化绑定 diff --git a/pom.xml b/pom.xml index 348d3ae..35aac38 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,14 @@ + + org.apache.rocketmq + rocketmq-client + 4.4.0 + + + + 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 000e4d5..2739c08 100644 --- a/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java +++ b/src/main/java/weaver/xuanran/wang/bme/action/ContractApplyComDateAction.java @@ -56,7 +56,8 @@ public class ContractApplyComDateAction extends SafeCusBaseAction { @Override public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { - RecordSetTrans rs = requestInfo.getRsTrans(); + log.info(Util.logStr("--------------- requestId : {} Begin ---------------", requestId)); + RecordSetTrans rs = new RecordSetTrans(); rs.setAutoCommit(false); try { Map mainTableValue = getMainTableValue(requestInfo); @@ -74,13 +75,13 @@ public class ContractApplyComDateAction extends SafeCusBaseAction { if(StringUtils.isNotBlank(updateWhere)){ updateSql += " and " + updateWhere; } + log.info(Util.logStr("更新合同明细表sql:{}, 参数:{}, {}", updateSql, checkDate, mainId)); if(!rs.executeUpdate(updateSql, checkDate, mainId)){ - log.error(Util.logStr("更新合同明细表sql:{}, 参数:{}", updateSql, new String[]{checkDate, mainId})); throw new CustomerException("更新合同sql错误!"); } rs.commit(); }else{ - log.error(Util.logStr("查询施工合同关联项目sql : {}", selectSql)); + log.error(Util.logStr("查询施工合同关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId)); } }catch (Exception e){ rs.rollback(); diff --git a/src/main/java/weaver/xuanran/wang/epdi/asset/action/AssetDataPushAction.java b/src/main/java/weaver/xuanran/wang/epdi/asset/action/AssetDataPushAction.java new file mode 100644 index 0000000..20a60c0 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/asset/action/AssetDataPushAction.java @@ -0,0 +1,65 @@ +package weaver.xuanran.wang.epdi.asset.action; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.excention.CustomerException; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; +import weaver.xuanran.wang.epdi.asset.service.AssetDataPushService; +/** + *

资产模块action

+ * + * @Author xuanran.wang + * @Date 2022/12/26 11:11 + */ +public class AssetDataPushAction extends SafeCusBaseAction { + /** + *

配置唯一标识

+ **/ + @RequiredMark + @PrintParamMark + private String uniqueCode; + /** + *

接口返回字段

+ **/ + @PrintParamMark + private String backField; + /** + *

token建模配置唯一标识

+ **/ + @RequiredMark + @PrintParamMark + private String tokenUniqueCode; + /** + *

主表字段

+ *

+ * 如果存在数据回写 就会把接口返回字段对应的值回写到此字段中 + *

+ **/ + @PrintParamMark + private String tableField; + + private final AssetDataPushService assetDataPushService = new AssetDataPushService(); + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + try { + log.info("----------------- AssetDataPushAction Begin " + requestId + " -----------------"); + RecordSet updateRs = new RecordSet(); + String backVal = assetDataPushService.dataPush(uniqueCode, tokenUniqueCode, requestId, backField); + // 如果接口响应字段值不为空并且表单回写字段不为空 + if(StringUtils.isNotBlank(backVal) && StringUtils.isNotBlank(tableField)){ + String updateSql = "update " + billTable + " set " + tableField + " = ? where requestid = ?"; + if (!updateRs.executeUpdate(updateSql, backVal, requestId)) { + log.error(Util.logStr("更新表单sql : {}, 接口响应参数 : {}, 请求id : {}", backVal, requestId)); + throw new CustomerException("接口数据回写表单失败!"); + } + } + }catch (Exception e){ + throw new CustomerException(Util.logStr("数据推送action异常 : {}", e.getMessage())); + } + } +} diff --git a/src/main/java/weaver/xuanran/wang/epdi/asset/service/AssetDataPushService.java b/src/main/java/weaver/xuanran/wang/epdi/asset/service/AssetDataPushService.java new file mode 100644 index 0000000..f8260ca --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/asset/service/AssetDataPushService.java @@ -0,0 +1,111 @@ +package weaver.xuanran.wang.epdi.asset.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.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig; +import weaver.xuanran.wang.epdi.datapush.service.RequestPushService; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.util.Map; + +/** + *

上海电力研究院数据推送业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/26 11:13 + */ +public class AssetDataPushService { + /** + *

接口响应信息

+ **/ + private static final String MESSAGE_FIELD = "repmsg"; + /** + *

接口响应处理成功标识

+ **/ + private static final String SUCCESS_CODE = "1"; + /** + *

接口响应状态码字段

+ **/ + private static final String SUCCESS_CODE_FIELD = "repcode"; + private static final String TOKEN_FIELD = "token"; + private final RequestPushService requestPushService = new RequestPushService(); + private final HttpUtils httpUtils = new HttpUtils(); + { + httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 + } + private final Logger log = Util.getLogger(); + + /** + *

数据推送

+ * @author xuanran.wang + * @dateTime 2022/12/26 14:21 + * @param uniqueCode 请求体的建模配置唯一标识 + * @param tokenUniqueCode token建模配置唯一标识 + * @param requestId 请求id + * @param backField 回写字段 + * @return 响应返回信息 + **/ + public String dataPush(String uniqueCode, String tokenUniqueCode, String requestId, String backField){ + String token = dataPush(tokenUniqueCode, requestId, TOKEN_FIELD); + log.info(Util.logStr("token : [{}]", token)); + httpUtils.getGlobalCache().header.put("token", token); + return dataPush(uniqueCode, requestId, backField); + } + + /** + *

数据推送

+ * @author xuanran.wang + * @dateTime 2022/12/26 11:27 + * @param uniqueCode 配置唯一标识 + * @param requestId 请求id + * @param backField 响应返回字段 + * @return 响应返回信息 + **/ + private String dataPush(String uniqueCode, String requestId, String backField){ + String res = ""; + MainRequestConfig config = requestPushService.getRequestPushConfigByUniqueCode(uniqueCode); + Map requestParam = requestPushService.getRequestParam(config, requestId); + String url = config.getRequestUrl(); + Map headers = httpUtils.getGlobalCache().header;// 全局请 + ResponeVo responseVo = null; + try { + responseVo = httpUtils.apiPost(url, requestParam); + } catch (IOException e) { + throw new CustomerException(Util.logStr("发送请求发生异常! : {}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + if (responseVo.getCode() != 200) { // 相应状态码 + 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(headers), responseVo.getCode(), // 相应状态码 + responseVo.getEntityString())); // 相应内容 + throw new CustomerException(Util.logStr("can not fetch [{}]", url)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + Map response; + try { + response = responseVo.getEntityMap(); // 根据相应结果转化为map集合 + } catch (JsonProcessingException e) { + log.error(Util.logStr("push data error, can not parse response to map," + // 构建日志字符串 + "this response is [{}], url is [{}],request params is [{}], request heard is [{}];", + responseVo.getEntityString(), url, JSON.toJSONString(requestParam), JSON.toJSONString(headers))); // 相应内容 + throw new CustomerException(Util.logStr("push data error, can not parse response to map")); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + String successCode = Util.null2DefaultStr(response.get(SUCCESS_CODE_FIELD), ""); + if (!successCode.equals(SUCCESS_CODE)) { + throw new CustomerException(Util.logStr("接口响应码不为 : [{}],接口响应信息: {}", successCode, Util.null2DefaultStr(response.get(MESSAGE_FIELD), ""))); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + } + if(StringUtils.isNotBlank(backField)){ + res = Util.null2DefaultStr(response.get(backField), ""); + if (StringUtils.isBlank(res)) { + throw new CustomerException("获取接口中指定返回字段 [ " + backField+ " ] 为空, 请检查!"); // 自定义异常类 create 2022/3/9 2:20 PM + } + } + return res; + } +} diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/constant/RequestPushConstant.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/constant/RequestPushConstant.java new file mode 100644 index 0000000..6a93a84 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/constant/RequestPushConstant.java @@ -0,0 +1,94 @@ +package weaver.xuanran.wang.epdi.datapush.constant; + +/** + *

uf_request_push配置表常量

+ * + * @Author xuanran.wang + * @Date 2022/12/1 14:18 + */ +public class RequestPushConstant { + /** + *

配置建模表名

+ **/ + public static final String MODEL_TABLE_NAME = "uf_request_push"; + /** + *

数据类型-普通

+ **/ + public static final String PARAM_NODE_TYPE_GENERAL = "0"; + /** + *

数据类型-对象

+ **/ + public static final String PARAM_NODE_TYPE_OBJ = "1"; + /** + *

数据类型-数组

+ **/ + public static final String PARAM_NODE_TYPE_LIST = "2"; + /** + *

配置启用

+ **/ + public static final String CONFIG_ENABLE = "0"; + /** + *

数据类型-String

+ **/ + public static final String DATA_TYPE_STRING = "0"; + /** + *

数据类型-Int

+ **/ + public static final String DATA_TYPE_INT = "1"; + /** + *

数据类型-Double

+ **/ + public static final String DATA_TYPE_DOUBLE = "2"; + /** + *

数据类型-Date

+ **/ + public static final String DATA_TYPE_DATE = "3"; + /** + *

数据类型-DateTime

+ **/ + public static final String DATA_TYPE_DATE_TIME = "4"; + /** + *

数据类型-自定义时间格式

+ **/ + public static final String DATA_TYPE_CUS_DATE = "7"; + /** + *

数据类型-时间戳

+ **/ + public static final String DATA_TYPE_TIME_TIMESTAMP = "8"; + /** + *

转换类型-当前表单字段

+ **/ + public static final String CONVERT_RULES_TABLE_FIELD = "0"; + /** + *

转换类型-默认值

+ **/ + public static final String CONVERT_RULES_DEFAULT = "1"; + /** + *

转换类型-自定义SQL

+ **/ + public static final String CONVERT_RULES_NOW_TIME = "3"; + /** + *

转换类型-当前时间

+ **/ + public static final String CONVERT_RULES_CUS_SQL = "4"; + /** + *

转换类型-requestId

+ **/ + public static final String CONVERT_RULES_REQUEST_ID = "5"; + /** + *

转换类型-数据id

+ **/ + public static final String CONVERT_RULES_DATA_ID = "6"; + /** + *

主表

+ **/ + public static final String DATASOURCE_MAIN_TABLE = "0"; + /** + *

明细

+ **/ + public static final String DATASOURCE_DETAIL_TABLE = "1"; + /** + *

根节点

+ **/ + public static final String ROOT_NODE = ""; +} diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java index f227c77..6590154 100644 --- a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/DetailRequestConfig.java @@ -3,19 +3,25 @@ package weaver.xuanran.wang.epdi.datapush.eneity; import lombok.Data; +import java.util.List; + /** + *

配置表明细表实体类

+ * * @Author xuanran.wang - * @Date 2022/6/18 16:47 + * @Date 2022/12/23 16:20 */ @Data public class DetailRequestConfig { private String paramName; + private String paramNodeType; + private String detailIndex; + private String parentName; private String paramType; private String getValueType; private String valueContext; - private String tableName; private String workFlowField; - private String fieldName; - private String detailId; - private String parentName; + private String dataSource; + private String workFlowFieldName; + private List detailRequestConfigList; } diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java index bf884f1..fc9b565 100644 --- a/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/eneity/MainRequestConfig.java @@ -6,8 +6,10 @@ import lombok.Data; import java.util.List; /** + *

配置表主表实体类

+ * * @Author xuanran.wang - * @Date 2022/6/18 15:43 + * @Date 2022/12/23 16:20 */ @Data public class MainRequestConfig { @@ -15,11 +17,8 @@ public class MainRequestConfig { private String uniqueCode; private String workflow; private String requestUrl; - private String dataSource; - private String detailIndex; private String cusSql; - private String configFilePath; private String enable; - private String methodParameterClassName; + private String tableName; private List detailRequestConfigList; } diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/mapper/RequestPushMapper.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/mapper/RequestPushMapper.java new file mode 100644 index 0000000..a08f0eb --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/mapper/RequestPushMapper.java @@ -0,0 +1,50 @@ +package weaver.xuanran.wang.epdi.datapush.mapper; + +import aiyh.utils.annotation.recordset.CaseConversion; +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import weaver.xuanran.wang.epdi.datapush.constant.RequestPushConstant; +import weaver.xuanran.wang.epdi.datapush.eneity.DetailRequestConfig; +import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig; + +import java.util.List; + +/** + *

数据推送配置mapper

+ * + * @Author xuanran.wang + * @Date 2022/12/1 14:35 + */ +@SqlMapper +public interface RequestPushMapper { + + /** + *

获取配置表主表对象

+ * @author xuanran.wang + * @dateTime 2022/12/1 14:39 + * @return 主表配置对象 + **/ + @Select("select a.*,b.tablename tableName " + + "from "+ RequestPushConstant.MODEL_TABLE_NAME +" a " + + "left join workflow_table_view b " + + "on a.workFlow = b.id " + + "where uniqueCode = #{uniqueCode} and enable = " + RequestPushConstant.CONFIG_ENABLE) + @CaseConversion(value = false) + MainRequestConfig getRequestPushMainConfig(@ParamMapper("uniqueCode") String uniqueCod); + + /** + *

获取配置表明细对象集合

+ * @author xuanran.wang + * @dateTime 2022/12/1 14:40 + * @param mainId 主表主数据id + * @return 明细配置集合 + **/ + @Select("select a.*,b.fieldname workFlowFieldName " + + "from "+ RequestPushConstant.MODEL_TABLE_NAME + "_dt1 a " + + "left join workflow_field_table_view b " + + "on a.workFlowField = b.id " + + "where mainid = #{mainId} and enable = " + RequestPushConstant.CONFIG_ENABLE) + @CaseConversion(value = false) + List getRequestPushDetailConfig(@ParamMapper("mainId") String mainId); +} diff --git a/src/main/java/weaver/xuanran/wang/epdi/datapush/service/RequestPushService.java b/src/main/java/weaver/xuanran/wang/epdi/datapush/service/RequestPushService.java new file mode 100644 index 0000000..18e2558 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/epdi/datapush/service/RequestPushService.java @@ -0,0 +1,401 @@ +package weaver.xuanran.wang.epdi.datapush.service; + +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.springframework.util.Assert; +import weaver.conn.RecordSet; +import weaver.xuanran.wang.epdi.datapush.constant.RequestPushConstant; +import weaver.xuanran.wang.epdi.datapush.eneity.DetailRequestConfig; +import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig; +import weaver.xuanran.wang.epdi.datapush.mapper.RequestPushMapper; +import weaver.zwl.common.ToolUtil; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

上海电力设计院数据推送业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/23 16:20 + */ +public class RequestPushService { + private final RequestPushMapper requestPushMapper = Util.getMapper(RequestPushMapper.class); + private String tempTableName = ""; + private final ToolUtil toolUtil = new ToolUtil(); + + private final Logger logger = Util.getLogger(); + + /** + *

获取配置对象

+ * @author xuanran.wang + * @dateTime 2022/12/1 15:09 + * @param uniqueCode 唯一标识 + * @return 配置对象 + **/ + public MainRequestConfig getRequestPushConfigByUniqueCode(String uniqueCode){ + MainRequestConfig requestPushMainConfig = requestPushMapper.getRequestPushMainConfig(uniqueCode); + Assert.notNull(requestPushMainConfig,"主表配置对象获取为空, 请检查!"); + List requestPushDetailConfig = requestPushMapper.getRequestPushDetailConfig(requestPushMainConfig.getId()); + Assert.notEmpty(requestPushDetailConfig, "明细表配置集合获取为空, 请检查!"); + requestPushMainConfig.setDetailRequestConfigList(requestPushDetailConfig); + return requestPushMainConfig; + } + + /** + *

根据配置转换流程表单

+ * @author xuanran.wang + * @dateTime 2022/12/23 17:17 + * @param mainRequestConfig 建模配置对象 + * @param requestId 请求id + * @return 转换后的流程参数map + **/ + public Map getRequestParam(MainRequestConfig mainRequestConfig, String requestId){ + HashMap res = new HashMap<>(); + // 请求配置的表 + try { + List configList = mainRequestConfig.getDetailRequestConfigList(); + // 过滤根节点 + List rootNodeList = configList + .stream() + .filter(item -> RequestPushConstant.ROOT_NODE.equals(item.getParentName())) + .collect(Collectors.toList()); + // 设置子节点 + for (DetailRequestConfig detailRequestConfig : rootNodeList) { + setChildList(detailRequestConfig, configList); + } + String workflowType = mainRequestConfig.getWorkflow(); + if(StringUtils.isBlank(workflowType)){ + setObjValue(rootNodeList, res, null, null); + }else { + String mainTableName = mainRequestConfig.getTableName(); + this.tempTableName = mainTableName; + RecordSet mainRs = new RecordSet(); + String sql = "select * from " + mainTableName + " where requestid = ?"; + if (mainRs.executeQuery(sql,requestId)) { + if (mainRs.next()) { + setObjValue(rootNodeList, res, mainRs, null); + } + } + } + }catch (Exception e){ + throw new RuntimeException("执行getRequestParam发生异常 : " + e.getMessage()); + } + return res; + } + + /** + *

<递归设置子对象/h1> + * @author xuanran.wang + * @dateTime 2022/12/23 17:16 + * @param detailRequestConfig 明细配置对象 + * @param detailRequestConfigList 明细配置对象集合 + **/ + private void setChildList(DetailRequestConfig detailRequestConfig, List detailRequestConfigList){ + try { + // 节点类型 + String paramNodeType = detailRequestConfig.getParamNodeType(); + // 参数名称 + String paramName = detailRequestConfig.getParamName(); + // 递归设置子节点 + if(!RequestPushConstant.PARAM_NODE_TYPE_GENERAL.equals(paramNodeType)){ + List childList = + detailRequestConfigList.stream().filter( + config -> paramName.equals(config.getParentName()) + ).collect(Collectors.toList()); + detailRequestConfig.setDetailRequestConfigList(childList); + for (DetailRequestConfig requestConfig : childList) { + setChildList(requestConfig, detailRequestConfigList); + } + } + }catch (Exception e){ + throw new RuntimeException("执行setChildList发生异常 : " + e.getMessage()); + } + } + + /** + *

设置对象类型配置参数值

+ * @author xuanran.wang + * @dateTime 2022/12/23 17:25 + * @param configList 配置集合 + * @param res map + * @param mainRs 主表结果集 + * @param detailRs 明细结果集 + **/ + private void setObjValue(List configList, HashMap res, RecordSet mainRs, RecordSet detailRs) { + try { + for (DetailRequestConfig requestConfig : configList) { + // 参数类型 + String paramType = requestConfig.getParamNodeType(); + String paramName = requestConfig.getParamName(); + List childConfigList = requestConfig.getDetailRequestConfigList(); + // 集合 + if (RequestPushConstant.PARAM_NODE_TYPE_LIST.equals(paramType)) { + List list = new ArrayList<>(); + setListValue(requestConfig,childConfigList, list, mainRs); + res.put(paramName, list); + } else if (RequestPushConstant.PARAM_NODE_TYPE_OBJ.equals(paramType)) { + // 对象 + HashMap map = new HashMap<>(); + this.setObjValue(childConfigList, map, mainRs, detailRs); + }else{ + // 普通对象 + Object value = setCommonParamValue(requestConfig, mainRs, detailRs); + res.put(paramName, value); + } + } + }catch (Exception e){ + throw new RuntimeException("执行setObjValue发生异常 : " + e.getMessage()); + } + } + + /** + *

设置集合类型配置参数值

+ * @author xuanran.wang + * @dateTime 2022/12/23 17:26 + * @param detailRequestConfig 配置对象 + * @param childList 子节点配置集合 + * @param list 当前配置对象的集合 + * @param mainRs 主表结果集 + **/ + private void setListValue(DetailRequestConfig detailRequestConfig, + List childList, + List list, + RecordSet mainRs) { + try { + // 子项数据来源 + String dataSource = detailRequestConfig.getDataSource(); + // 主表 + if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) { + HashMap map = new HashMap<>(); + this.setObjValue(childList, map, mainRs, null); + list.add(map); + }else if(RequestPushConstant.DATASOURCE_DETAIL_TABLE.equals(dataSource)){ + // 子表 + int mainId = weaver.general.Util.getIntValue(mainRs.getString("id")); + String sql = "select * from " + tempTableName + "_dt" + detailRequestConfig.getDetailIndex() + " where mainid = " + mainId; + RecordSet detailRs = new RecordSet(); + if(detailRs.executeQuery(sql)){ + while (detailRs.next()) { + HashMap map = new HashMap<>(); + this.setObjValue(childList, map, mainRs, detailRs); + list.add(map); + } + } + } + }catch (Exception e){ + throw new RuntimeException("执行setListValue发生异常 : " + e.getMessage()); + } + } + + /** + *

设置普通参数类型配置参数值

+ * @author xuanran.wang + * @dateTime 2022/12/23 17:27 + * @param detailRequestConfig 配置对象 + * @param mainRs 主表结果集 + * @param detailRs 明细结果集 + * @return 转化后的值 + **/ + private Object setCommonParamValue(DetailRequestConfig detailRequestConfig, RecordSet mainRs, RecordSet detailRs){ + String paramType = detailRequestConfig.getParamType(); + String getValueType = detailRequestConfig.getGetValueType(); + String valueContext = detailRequestConfig.getValueContext(); + String dataSource = detailRequestConfig.getDataSource(); + String paramName = detailRequestConfig.getParamName(); + String requestId = ""; + int mainId = -1; + if(null != mainRs){ + requestId = mainRs.getString("requestid"); + mainId = Util.getIntValue(mainRs.getString("id")); + } + int detailId = -1; + if(null != detailRs){ + detailId = Util.getIntValue(detailRs.getString("id")); + } + Object value = ""; + switch (getValueType) { + // 流程字段 + case RequestPushConstant.CONVERT_RULES_TABLE_FIELD: { + value = getRecordsetVal(detailRequestConfig, mainRs, detailRs); + } + break; + // 默认值 + case RequestPushConstant.CONVERT_RULES_DEFAULT: { + value = getRecordsetVal(detailRequestConfig, mainRs, detailRs); + value = Util.null2String(valueContext) + .replace("{?requestid}", requestId) + .replace("{?}", String.valueOf(value)); + } + break; + // 当前时间 + case RequestPushConstant.CONVERT_RULES_NOW_TIME: { + value = new Date(); + } + break; + // 自定义sql查询 + case RequestPushConstant.CONVERT_RULES_CUS_SQL: { + String tempValue = Util.null2DefaultStr(getRecordsetVal(detailRequestConfig, mainRs, detailRs),""); + value = toolUtil.getValueByChangeRule(valueContext, tempValue, requestId, detailId); + } + break; + // requestId + case RequestPushConstant.CONVERT_RULES_REQUEST_ID: { + value = requestId; + } + break; + // 数据id + case RequestPushConstant.CONVERT_RULES_DATA_ID: { + if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) { + value = mainId; + } else { + value = detailId; + } + } + break; + default: + throw new CustomerException("不支持的取值方式"); + } + switch (paramType) { + // String类型 + case RequestPushConstant.DATA_TYPE_STRING: { + value = Util.null2DefaultStr(value, ""); + } + break; + // int类型 + case RequestPushConstant.DATA_TYPE_INT: { + value = Util.getIntValue(Util.null2DefaultStr(value, ""),0); + } + break; + // double类型 + case RequestPushConstant.DATA_TYPE_DOUBLE: { + value = Util.getDoubleValue(Util.null2DefaultStr(value, ""),0.00); + } + break; + // 日期类型 + case RequestPushConstant.DATA_TYPE_DATE: { + if (Objects.isNull(value)) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd"); + } catch (Exception e) { + throw new CustomerException("时间处理异常:参数>>" + paramName); + } + } + break; + // 时间日期类型 + case RequestPushConstant.DATA_TYPE_DATE_TIME: { + if (Objects.isNull(value)) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss"); + } catch (Exception e) { + throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e); + } + } + break; + // 自定义时间格式化类型 + case RequestPushConstant.DATA_TYPE_CUS_DATE: { + if (Objects.isNull(value)) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, valueContext); + } catch (Exception e) { + throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + // 时间戳类型 + case RequestPushConstant.DATA_TYPE_TIME_TIMESTAMP: { + if (Objects.isNull(value)) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + assert date != null; + value = date.getTime(); + } catch (Exception e) { + throw new CustomerException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + default: return value; + } + return value; + } + + /** + *

获取表单字段的值

+ * @author xuanran.wang + * @dateTime 2022/12/23 17:42 + * @param config 配置对象 + * @param mainRs 主表结果集 + * @param detailRs 明细表结果集 + * @return 结果集中的值 + **/ + public Object getRecordsetVal(DetailRequestConfig config, RecordSet mainRs, RecordSet detailRs){ + String fieldName = config.getWorkFlowFieldName(); + String dataSource = config.getDataSource(); + if(StringUtils.isBlank(fieldName) || StringUtils.isBlank(dataSource)){ + return ""; + } + Object value = ""; + if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) { + value = Util.null2DefaultStr(mainRs.getString(fieldName),""); + } else { + value = Util.null2DefaultStr(detailRs.getString(fieldName),""); + } + return value; + } + + /** + *

将日期字符串转换为Date对象

+ * + * @param dateStr 日期字符串 + * @return 日期对象 + */ + private static Date parseDate(String dateStr) { + ThreadLocal SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); + if (dateStr == null || dateStr.length() == 0) { + return null; + } + String regex = "\\/|\\.|年|月|日"; + Date date = null; + try { + date = SIMPLE_DATE_FORMAT.get().parse(dateStr.replaceAll(regex, "-")); + return date; + } catch (ParseException e) { + throw new CustomerException("无法将" + dateStr + "转换为日期对象!", e); + } + } + + /** + * 自定义时间格式化 + * + * @param date 日期 + * @param tempStr 格式化字符串 + * @return + */ + private String diyDateFortMat(Date date, String tempStr) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr); + return simpleDateFormat.format(date); + } + + + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java new file mode 100644 index 0000000..efeb869 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java @@ -0,0 +1,51 @@ +package weaver.xuanran.wang.shyl.mq; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.consumer.ConsumeFromWhere; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import weaver.xuanran.wang.shyl.mq.constant.RocketMQConstant; +import weaver.xuanran.wang.shyl.mq.util.RocketUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + *

rocketMQ工厂

+ * + * @Author xuanran.wang + * @Date 2022/12/29 14:21 + */ +public class RocketMQFactory { + public static Map> CONFIG_MAPS = new HashMap<>(16); + public static DefaultMQPushConsumer getMQPushConsumer(String configName, MessageListenerConcurrently messageListenerConcurrently){ + try { + Map configMap = new HashMap<>(); + if(!CONFIG_MAPS.containsKey(configName)){ + configMap = RocketUtil.initMQConfigMap(configName); + CONFIG_MAPS.put(configName, configMap); + } + int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES); + // 声明一个消费者consumer,需要传入一个组 weaver-consumer + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(Util.null2String(configMap.get("ConsumerGroup"))); + // 设置集群的NameServer地址,多个地址之间以分号分隔 183.192.65.118:9876 + consumer.setNamesrvAddr(Util.null2String(configMap.get("NameServer"))); + // 设置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")), Util.null2String(configMap.get("Tag"))); + // Listener,主要进行消息的逻辑处理,监听topic,如果有消息就会立即去消费 + consumer.registerMessageListener(messageListenerConcurrently); + return consumer; + }catch (Exception e){ + throw new CustomerException(Util.logStr("consumer init error, now config name is : {} error : {}",configName, e.getMessage())); + } + } + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java new file mode 100644 index 0000000..b72f25c --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java @@ -0,0 +1,68 @@ +package weaver.xuanran.wang.shyl.mq; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import org.apache.log4j.Logger; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import java.util.Map; + +/** + *

上海团校RocketMQListener

+ * + * @Author xuanran.wang + * @Date 2022/12/29 12:25 + */ +public abstract class RocketMQListener extends HttpServlet { + private static final Logger log = Util.getLogger(); + private String configName; + public RocketMQListener() { + } + public RocketMQListener(String configName) { + this.configName = configName; + } + @Override + public void init() throws ServletException { + super.init(); + initialized(); + } + + /** + *

消费者初始化

+ * @author xuanran.wang + * @dateTime 2022/12/29 21:48 + **/ + public void initialized() { + DefaultMQPushConsumer consumer = null; + log.info(Util.logStr("---- consumer : {} initialized start ----", configName)); + try { + try { + // 根据配置文件初始化一个consumer对象 + consumer = RocketMQFactory.getMQPushConsumer(configName, service()); + }catch (Exception e){ + throw new CustomerException(Util.logStr("the consumer init exception : {}", e.getMessage())); + } + try { + // 调用start()方法启动consumer + consumer.start(); + }catch (Exception e){ + throw new CustomerException(Util.logStr("the consumer start exception : {}", e.getMessage())); + } + log.info(Util.logStr("---- consumer : {} initialized end ----", configName)); + }catch (Exception e){ + log.info(Util.logStr("---- consumer : {} initialized error ----", configName)); + log.error(Util.getErrString(e)); + } + } + + /** + *

每个消费者自定义的消费业务方法

+ * @author xuanran.wang + * @dateTime 2022/12/29 21:49 + * @return MessageListenerConcurrently 消费者消费方法 + **/ + public abstract MessageListenerConcurrently service(); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java new file mode 100644 index 0000000..806fd5e --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java @@ -0,0 +1,15 @@ +package weaver.xuanran.wang.shyl.mq.constant; + +/** + *

RocketMQ常量

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:25 + */ +public class RocketMQConstant { + public static final String CREATE_ACTION = "CREATE_ACTION"; + public static final String UPDATE_ACTION = "UPDATE_ACTION"; + public static final String DELETE_ACTION = "DELETE_ACTION"; + public static final String PASSWORD_ACTION = "PASSWORD_ACTION"; + public static final int DEFAULT_MAX_RECONSUME_TIMES = 5; +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java new file mode 100644 index 0000000..0f2d536 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java @@ -0,0 +1,41 @@ +package weaver.xuanran.wang.shyl.mq.consumer; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; +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 weaver.xuanran.wang.shyl.mq.RocketMQFactory; +import weaver.xuanran.wang.shyl.mq.RocketMQListener; +import weaver.xuanran.wang.shyl.mq.util.RocketUtil; + +import java.util.List; +import java.util.Map; + +/** + *

部门队列消费者

+ * + * @Author xuanran.wang + * @Date 2022/12/29 14:35 + */ +public class OrgConsumer extends RocketMQListener { + + private static final Logger log = Util.getLogger(); + private static final String CONFIG_NAME = "OrgConsumer"; + + public OrgConsumer(){ + super(CONFIG_NAME); + } + + @Override + public MessageListenerConcurrently service() { + return (List list, ConsumeConcurrentlyContext consumeConcurrentlyContext)->{ + Map map = RocketMQFactory.CONFIG_MAPS.get(CONFIG_NAME); + log.info(Util.logStr("{} service config is {}", CONFIG_NAME, JSONObject.toJSONString(map))); + return ConsumeConcurrentlyStatus.RECONSUME_LATER; + }; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java new file mode 100644 index 0000000..38d28e9 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java @@ -0,0 +1,40 @@ +package weaver.xuanran.wang.shyl.mq.consumer; + +import aiyh.utils.Util; +import com.alibaba.fastjson.JSONObject; +import org.apache.log4j.Logger; +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 weaver.xuanran.wang.shyl.mq.RocketMQFactory; +import weaver.xuanran.wang.shyl.mq.RocketMQListener; + +import java.util.List; +import java.util.Map; + +/** + *

密码修改队列消费者

+ * + * @Author xuanran.wang + * @Date 2022/12/29 14:35 + */ +public class PassWordConsumer extends RocketMQListener { + + private static final Logger log = Util.getLogger(); + public static final String CONFIG_NAME = "PassWordConsumer"; + + public PassWordConsumer(){ + super(CONFIG_NAME); + } + + @Override + public MessageListenerConcurrently service() { + return (List list, ConsumeConcurrentlyContext consumeConcurrentlyContext)->{ + Map map = RocketMQFactory.CONFIG_MAPS.get(CONFIG_NAME); + log.info(Util.logStr("{} service config is {}", CONFIG_NAME, JSONObject.toJSONString(map))); + return ConsumeConcurrentlyStatus.RECONSUME_LATER; + }; + } + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java new file mode 100644 index 0000000..62909ef --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java @@ -0,0 +1,35 @@ +package weaver.xuanran.wang.shyl.mq.consumer; + +import aiyh.utils.Util; +import org.apache.log4j.Logger; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.message.MessageExt; +import weaver.xuanran.wang.shyl.mq.RocketMQListener; +import weaver.xuanran.wang.shyl.mq.service.impl.UserServiceImpl; +import weaver.xuanran.wang.shyl.mq.util.RocketUtil; + +import java.util.List; + +/** + *

用户队列消费者

+ * + * @Author xuanran.wang + * @Date 2022/12/29 14:35 + */ +public class UserInfoConsumer extends RocketMQListener { + private static final Logger log = Util.getLogger(); + public static final String CONFIG_NAME = "UserInfoConsumer"; + + public UserInfoConsumer(){ + super(CONFIG_NAME); + } + + private final UserServiceImpl userInfoService = new UserServiceImpl(); + + @Override + public MessageListenerConcurrently service() { + return (List msg, ConsumeConcurrentlyContext consumeConcurrentlyContext)-> RocketUtil.execute(msg, consumeConcurrentlyContext, userInfoService, CONFIG_NAME); + } + +} 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 new file mode 100644 index 0000000..1c005ab --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/MQMessage.java @@ -0,0 +1,44 @@ +package weaver.xuanran.wang.shyl.mq.entity; + +import lombok.Data; + +/** + *

mq消息实体类

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:09 + */ +@Data +public class MQMessage { + /** + *

消息ID

+ **/ + private String id; + /** + *

消息队列名

+ *

+ * AUTH_CONSOLE_USERINFO_TOPIC: 用户队列; + * AUTH_CONSOLE_ORG_TOPIC: 机构队列; + * AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC: 密码修改队列 + *

+ **/ + private String topic; + /** + *

消息内容操作类型

+ *

+ * CREATE_ACTION:新增; + * UPDATE_ACTION: 修改; + * DELETE_ACTION: 删除; + * PASSWORD_ACTION: 修改密码 + *

+ **/ + private String actionType; + /** + *

消息发送时间

+ **/ + private String sendTime; + /** + *

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

+ **/ + private String content; +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/entity/ModifyPassWord.java b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/ModifyPassWord.java new file mode 100644 index 0000000..6ba71b3 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/ModifyPassWord.java @@ -0,0 +1,43 @@ +package weaver.xuanran.wang.shyl.mq.entity; + +/** + *

密码修改

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:59 + */ +public class ModifyPassWord { + /** + *

主键

+ **/ + private String id; + /** + *

用户ID

+ **/ + private String uid; + /** + *

用户账号

+ **/ + private String username; + /** + *

用户名称

+ **/ + private String displayName; + /** + *

旧密码

+ **/ + private String oldPassword; + /** + *

新密码

+ **/ + private String password; + /** + *

确认密码

+ **/ + private String confirmPassword; + /** + *

盐值

+ **/ + private String decipherable; + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/entity/Org.java b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/Org.java new file mode 100644 index 0000000..10c9ad8 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/Org.java @@ -0,0 +1,38 @@ + +package weaver.xuanran.wang.shyl.mq.entity; + +import lombok.Data; + +/** + *

机构实体

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:56 + */ +@Data +public class Org { + /** + *

机构ID

+ **/ + private String id; + /** + *

机构编号

+ **/ + private String orgCode; + /** + *

机构名称

+ **/ + private String orgName; + /** + *

机构父级ID

+ **/ + private String parentId; + /** + *

机构排序号

+ **/ + private String sortIndex; + /** + *

机构状态

+ **/ + private String status; +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/entity/UserInfo.java b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/UserInfo.java new file mode 100644 index 0000000..2849a15 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/entity/UserInfo.java @@ -0,0 +1,61 @@ +package weaver.xuanran.wang.shyl.mq.entity; + +import lombok.Data; + +/** + *

用户实体

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:52 + */ +@Data +public class UserInfo { + /** + *

用户ID

+ **/ + private String id; + /** + *

用户账号

+ **/ + private String userName; + /** + *

用户名称

+ **/ + private String displayName; + /** + *

用户性别

+ **/ + private String gender; + /** + *

用户生日

+ **/ + private String birthDate; + /** + *

用户证件类型

+ **/ + private String idType; + /** + *

用户证件号

+ **/ + private String idCardNo; + /** + *

用户邮箱

+ **/ + private String email; + /** + *

用户手机号

+ **/ + private String mobile; + /** + *

用户机构ID

+ **/ + private String departmentId; + /** + *

用户机构名称

+ **/ + private String department; + /** + *

用户状态

+ **/ + private String status; +} 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 new file mode 100644 index 0000000..d9757b1 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/mapper/ConsumerMapper.java @@ -0,0 +1,35 @@ +package weaver.xuanran.wang.shyl.mq.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Update; + +/** + *

消费者mapper

+ * + * @Author xuanran.wang + * @Date 2022/12/30 14:19 + */ +public interface ConsumerMapper { + + /** + *

通过outKey更新人员状态为离职

+ * @author xuanran.wang + * @dateTime 2022/12/30 14:33 + * @param outKey 外部系统id + * @return 更新成功/失败 + **/ + @Update("update hrmresource set status = 5 where outkey = #{outKey}") + boolean updateUserStatusByOutKey(@ParamMapper("outKey") String outKey); + + /** + *

通过outKey删除部门信息

+ * @author xuanran.wang + * @dateTime 2022/12/30 14:33 + * @param outKey 外部系统id + * @return 删除是否成功 + **/ + @Update("delete hrmdepartment where outkey = #{outKey}") + boolean deleteDepartmentByOutKey(@ParamMapper("outKey") String outKey); + + +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java new file mode 100644 index 0000000..da25254 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/CusInfoActionService.java @@ -0,0 +1,20 @@ +package weaver.xuanran.wang.shyl.mq.service; + +import aiyh.utils.Util; +import weaver.xuanran.wang.shyl.mq.mapper.ConsumerMapper; +import weaver.xuanran.wang.shyl.mq.service.interfaces.CreateAction; +import weaver.xuanran.wang.shyl.mq.service.interfaces.DeleteAction; +import weaver.xuanran.wang.shyl.mq.service.interfaces.UpdateAction; + +/** + *

抽象类

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:04 + */ +public abstract class CusInfoActionService implements CreateAction, DeleteAction, UpdateAction { + /** + *

consumer-mapper

+ **/ + protected final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java new file mode 100644 index 0000000..86212be --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java @@ -0,0 +1,28 @@ +package weaver.xuanran.wang.shyl.mq.service.impl; + +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; +import weaver.xuanran.wang.shyl.mq.service.CusInfoActionService; + +/** + *

+ * + * @Author xuanran.wang + * @Date 2022/12/30 15:05 + */ +public class OrgServiceImpl extends CusInfoActionService { + @Override + public ConsumeConcurrentlyStatus cusCreateAction(MQMessage message) { + return null; + } + + @Override + public ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message) { + return null; + } + + @Override + public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) { + return null; + } +} 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..8beaee6 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/UserServiceImpl.java @@ -0,0 +1,49 @@ +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.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; +import weaver.xuanran.wang.shyl.mq.entity.UserInfo; +import weaver.xuanran.wang.shyl.mq.mapper.ConsumerMapper; +import weaver.xuanran.wang.shyl.mq.service.CusInfoActionService; + +/** + *

用户业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:04 + */ +public class UserServiceImpl extends CusInfoActionService { + + @Override + public ConsumeConcurrentlyStatus cusCreateAction(MQMessage message) { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + return null; + } + + @Override + public ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message) { + try { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + String id = userInfo.getId(); + boolean success = consumerMapper.updateUserStatusByOutKey(id); + if(!success){ + throw new CustomerException(Util.logStr("update user status error!")); + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + }catch (Exception e){ + throw new CustomerException(Util.logStr("cusDeleteAction execute error : [{}]!", e.getMessage())); + } + } + + @Override + public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) { + String content = message.getContent(); + UserInfo userInfo = JSONObject.parseObject(content, UserInfo.class); + return null; + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/CreateAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/CreateAction.java new file mode 100644 index 0000000..018e37a --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/CreateAction.java @@ -0,0 +1,14 @@ +package weaver.xuanran.wang.shyl.mq.service.interfaces; + +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; + +/** + *

新增接口

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:00 + */ +public interface CreateAction { + ConsumeConcurrentlyStatus cusCreateAction(MQMessage message); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/DeleteAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/DeleteAction.java new file mode 100644 index 0000000..ff2bc9e --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/DeleteAction.java @@ -0,0 +1,14 @@ +package weaver.xuanran.wang.shyl.mq.service.interfaces; + +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; + +/** + *

删除接口

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:02 + */ +public interface DeleteAction { + ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/PassWordAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/PassWordAction.java new file mode 100644 index 0000000..956e1cb --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/PassWordAction.java @@ -0,0 +1,14 @@ +package weaver.xuanran.wang.shyl.mq.service.interfaces; + +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; + +/** + *

密码修改接口

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:03 + */ +public interface PassWordAction { + ConsumeConcurrentlyStatus cusPassWordAction(MQMessage message); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/UpdateAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/UpdateAction.java new file mode 100644 index 0000000..0ad59b4 --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/interfaces/UpdateAction.java @@ -0,0 +1,14 @@ +package weaver.xuanran.wang.shyl.mq.service.interfaces; + +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; + +/** + *

更新接口

+ * + * @Author xuanran.wang + * @Date 2022/12/30 13:01 + */ +public interface UpdateAction { + ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message); +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java new file mode 100644 index 0000000..a3af6cc --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java @@ -0,0 +1,104 @@ +package weaver.xuanran.wang.shyl.mq.util; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.common.message.MessageExt; +import weaver.xuanran.wang.shyl.mq.constant.RocketMQConstant; +import weaver.xuanran.wang.shyl.mq.RocketMQFactory; +import weaver.xuanran.wang.shyl.mq.entity.MQMessage; +import weaver.xuanran.wang.shyl.mq.service.CusInfoActionService; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + *

rocketMQ集成工具类

+ * + * @Author xuanran.wang + * @Date 2022/12/29 21:03 + */ +public class RocketUtil { + private static final Logger log = Util.getLogger(); + + /** + *

初始化配置文件对象

+ * @author xuanran.wang + * @dateTime 2022/12/29 12:53 + **/ + public static Map initMQConfigMap(String configName){ + Map config = Util.getProperties2Map(configName); + if(MapUtils.isEmpty(config)){ + throw new CustomerException(Util.logStr("please check /filesystem/prop/prop2map {}.properties file is exist!", configName)); + } + for (Map.Entry entry : config.entrySet()) { + String key = Util.null2DefaultStr(entry.getKey(),""); + String value = Util.null2DefaultStr(entry.getValue(),""); + if(StringUtils.isBlank(key) || StringUtils.isBlank(value)){ + throw new CustomerException(Util.logStr("the config file key is empty or key = {} value is empty!", key)); + } + } + log.info(Util.logStr("ConfigName : {} , MQConfig : {} ",configName, JSONObject.toJSONString(config))); + return config; + } + + /** + *

执行自定义业务方法

+ * @author xuanran.wang + * @dateTime 2022/12/30 13:34 + * @param msg mq消息 + * @param consumeConcurrentlyContext 消费者 + * @param cusInfoActionService 传具体的业务方法 + * @param configName 配置名称 + * @return mq消费状态 + **/ + public static ConsumeConcurrentlyStatus execute(List msg, ConsumeConcurrentlyContext consumeConcurrentlyContext, + CusInfoActionService cusInfoActionService, String configName){ + Map configMap = RocketMQFactory.CONFIG_MAPS.get(configName); + log.info(Util.logStr("{} service config is {}", configName, JSONObject.toJSONString(configMap))); + int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")),RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES); + try { + if (CollectionUtils.isNotEmpty(msg)) { + MessageExt messageExt = msg.get(0); + String msgBody = ""; + MQMessage mqMessage = null; + try { + msgBody = new String(messageExt.getBody(), StandardCharsets.UTF_8); + mqMessage = JSONObject.parseObject(msgBody, MQMessage.class); + }catch (Exception e){ + throw new CustomerException(Util.logStr("parse msgBody to Message error current msgBody is {}, the error is {}", msg, e.getMessage())); + } + String actionType = mqMessage.getActionType(); + switch (actionType){ + case RocketMQConstant.CREATE_ACTION:{ + return cusInfoActionService.cusCreateAction(mqMessage); + } + case RocketMQConstant.UPDATE_ACTION:{ + return cusInfoActionService.cusUpdateAction(mqMessage); + } + case RocketMQConstant.DELETE_ACTION:{ + return cusInfoActionService.cusDeleteAction(mqMessage); + } + default: throw new CustomerException(Util.logStr("current actionType : [{}] is not supported!", actionType)); + } + }else { + log.error("the msgList is empty!"); + } + } catch (Exception e) { + // 如果重试达到最大还是异常那么先返回成功 oa将错误日志记录到日志中 + if (msg.get(0).getReconsumeTimes() == maxReconsumeTimes) { + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } else { + return ConsumeConcurrentlyStatus.RECONSUME_LATER; + } + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } +} diff --git a/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java index ebc2770..a7fe51f 100644 --- a/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java +++ b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java @@ -4,6 +4,7 @@ import aiyh.utils.Util; import basetest.BaseTest; import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService; import org.junit.Test; +import weaver.interfaces.encode.AuthorizationBasic4OAuth2; /** *

安波福校验用户测试类

@@ -24,4 +25,12 @@ public class CheckUserTest extends BaseTest { log.error(Util.getErrString(e)); } } + + @Test + public void testPA(){ + String clientId = "ai-689bbdb3c4834b15af692540c62dc126"; + String clientSecret = "7o88qSgOx0SOCQxR9xFGUm0n"; + AuthorizationBasic4OAuth2 auth2 = new AuthorizationBasic4OAuth2(); + log.info(auth2.encode(clientId + ":" + clientSecret)); + } } diff --git a/src/test/java/xuanran/wang/epdi/datapush/RequestDataPush.java b/src/test/java/xuanran/wang/epdi/datapush/RequestDataPush.java new file mode 100644 index 0000000..dafea68 --- /dev/null +++ b/src/test/java/xuanran/wang/epdi/datapush/RequestDataPush.java @@ -0,0 +1,31 @@ +package xuanran.wang.epdi.datapush; + +import basetest.BaseTest; +import com.alibaba.fastjson.JSONObject; +import org.junit.Test; +import weaver.xuanran.wang.epdi.datapush.eneity.MainRequestConfig; +import weaver.xuanran.wang.epdi.datapush.service.RequestPushService; + +import java.util.Map; + +/** + *

上海电力研究院测试类

+ * + * @Author xuanran.wang + * @Date 2022/12/26 10:14 + */ +public class RequestDataPush extends BaseTest { + + private final RequestPushService requestDataPush = new RequestPushService(); + + @Test + public void testCreatesJson(){ + String requestId = "798800"; + String tableName = ""; + String uniqueCode = "token"; + MainRequestConfig config = requestDataPush.getRequestPushConfigByUniqueCode(uniqueCode); + Map requestParam = requestDataPush.getRequestParam(config, requestId); + log.info("请求参数: " + JSONObject.toJSONString(requestParam)); + + } +}