mq消息队列开发

main
wangxuanran 2023-01-03 09:40:04 +08:00
parent 50789e184b
commit 868fc51f2d
34 changed files with 1556 additions and 22 deletions

View File

@ -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);

View File

@ -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);
}
}
}
}

View File

@ -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);
// 明细的款项类型字段变化绑定

View File

@ -52,6 +52,7 @@ function init(){
'computeDatePayType': computeDatePayType,
'paymentTypeGetValue': paymentTypeGetValue
}
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
// 主表字段发生变化
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
// 明细的款项类型字段变化绑定

View File

@ -80,6 +80,14 @@
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
<repositories>

View File

@ -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<String, String> 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();

View File

@ -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;
/**
* <h1>action</h1>
*
* @Author xuanran.wang
* @Date 2022/12/26 11:11
*/
public class AssetDataPushAction extends SafeCusBaseAction {
/**
* <h2></h2>
**/
@RequiredMark
@PrintParamMark
private String uniqueCode;
/**
* <h2></h2>
**/
@PrintParamMark
private String backField;
/**
* <h2>token</h2>
**/
@RequiredMark
@PrintParamMark
private String tokenUniqueCode;
/**
* <h2></h2>
* <p>
*
* </p>
**/
@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()));
}
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/26 11:13
*/
public class AssetDataPushService {
/**
* <h2></h2>
**/
private static final String MESSAGE_FIELD = "repmsg";
/**
* <h2></h2>
**/
private static final String SUCCESS_CODE = "1";
/**
* <h2></h2>
**/
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();
/**
* <h1></h1>
* @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);
}
/**
* <h1></h1>
* @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<String, Object> requestParam = requestPushService.getRequestParam(config, requestId);
String url = config.getRequestUrl();
Map<String, String> 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<String, Object> 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;
}
}

View File

@ -0,0 +1,94 @@
package weaver.xuanran.wang.epdi.datapush.constant;
/**
* <h1>uf_request_push</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:18
*/
public class RequestPushConstant {
/**
* <h2></h2>
**/
public static final String MODEL_TABLE_NAME = "uf_request_push";
/**
* <h2>-</h2>
**/
public static final String PARAM_NODE_TYPE_GENERAL = "0";
/**
* <h2>-</h2>
**/
public static final String PARAM_NODE_TYPE_OBJ = "1";
/**
* <h2>-</h2>
**/
public static final String PARAM_NODE_TYPE_LIST = "2";
/**
* <h2></h2>
**/
public static final String CONFIG_ENABLE = "0";
/**
* <h2>-String</h2>
**/
public static final String DATA_TYPE_STRING = "0";
/**
* <h2>-Int</h2>
**/
public static final String DATA_TYPE_INT = "1";
/**
* <h2>-Double</h2>
**/
public static final String DATA_TYPE_DOUBLE = "2";
/**
* <h2>-Date</h2>
**/
public static final String DATA_TYPE_DATE = "3";
/**
* <h2>-DateTime</h2>
**/
public static final String DATA_TYPE_DATE_TIME = "4";
/**
* <h2>-</h2>
**/
public static final String DATA_TYPE_CUS_DATE = "7";
/**
* <h2>-</h2>
**/
public static final String DATA_TYPE_TIME_TIMESTAMP = "8";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_TABLE_FIELD = "0";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_DEFAULT = "1";
/**
* <h2>-SQL</h2>
**/
public static final String CONVERT_RULES_NOW_TIME = "3";
/**
* <h2>-</h2>
**/
public static final String CONVERT_RULES_CUS_SQL = "4";
/**
* <h2>-requestId</h2>
**/
public static final String CONVERT_RULES_REQUEST_ID = "5";
/**
* <h2>-id</h2>
**/
public static final String CONVERT_RULES_DATA_ID = "6";
/**
* <h2></h2>
**/
public static final String DATASOURCE_MAIN_TABLE = "0";
/**
* <h2></h2>
**/
public static final String DATASOURCE_DETAIL_TABLE = "1";
/**
* <h2></h2>
**/
public static final String ROOT_NODE = "";
}

View File

@ -3,19 +3,25 @@ package weaver.xuanran.wang.epdi.datapush.eneity;
import lombok.Data;
import java.util.List;
/**
* <h1></h1>
*
* @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<DetailRequestConfig> detailRequestConfigList;
}

View File

@ -6,8 +6,10 @@ import lombok.Data;
import java.util.List;
/**
* <h1></h1>
*
* @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<DetailRequestConfig> detailRequestConfigList;
}

View File

@ -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;
/**
* <h1>mapper</h1>
*
* @Author xuanran.wang
* @Date 2022/12/1 14:35
*/
@SqlMapper
public interface RequestPushMapper {
/**
* <h1></h1>
* @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);
/**
* <h1></h1>
* @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<DetailRequestConfig> getRequestPushDetailConfig(@ParamMapper("mainId") String mainId);
}

View File

@ -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;
/**
* <h1></h1>
*
* @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();
/**
* <h1></h1>
* @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<DetailRequestConfig> requestPushDetailConfig = requestPushMapper.getRequestPushDetailConfig(requestPushMainConfig.getId());
Assert.notEmpty(requestPushDetailConfig, "明细表配置集合获取为空, 请检查!");
requestPushMainConfig.setDetailRequestConfigList(requestPushDetailConfig);
return requestPushMainConfig;
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/23 17:17
* @param mainRequestConfig
* @param requestId id
* @return map
**/
public Map<String, Object> getRequestParam(MainRequestConfig mainRequestConfig, String requestId){
HashMap<String, Object> res = new HashMap<>();
// 请求配置的表
try {
List<DetailRequestConfig> configList = mainRequestConfig.getDetailRequestConfigList();
// 过滤根节点
List<DetailRequestConfig> 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></h1>
* @author xuanran.wang
* @dateTime 2022/12/23 17:16
* @param detailRequestConfig
* @param detailRequestConfigList
**/
private void setChildList(DetailRequestConfig detailRequestConfig, List<DetailRequestConfig> detailRequestConfigList){
try {
// 节点类型
String paramNodeType = detailRequestConfig.getParamNodeType();
// 参数名称
String paramName = detailRequestConfig.getParamName();
// 递归设置子节点
if(!RequestPushConstant.PARAM_NODE_TYPE_GENERAL.equals(paramNodeType)){
List<DetailRequestConfig> 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());
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/23 17:25
* @param configList
* @param res map
* @param mainRs
* @param detailRs
**/
private void setObjValue(List<DetailRequestConfig> configList, HashMap<String, Object> res, RecordSet mainRs, RecordSet detailRs) {
try {
for (DetailRequestConfig requestConfig : configList) {
// 参数类型
String paramType = requestConfig.getParamNodeType();
String paramName = requestConfig.getParamName();
List<DetailRequestConfig> childConfigList = requestConfig.getDetailRequestConfigList();
// 集合
if (RequestPushConstant.PARAM_NODE_TYPE_LIST.equals(paramType)) {
List<Object> list = new ArrayList<>();
setListValue(requestConfig,childConfigList, list, mainRs);
res.put(paramName, list);
} else if (RequestPushConstant.PARAM_NODE_TYPE_OBJ.equals(paramType)) {
// 对象
HashMap<String, Object> 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());
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/23 17:26
* @param detailRequestConfig
* @param childList
* @param list
* @param mainRs
**/
private void setListValue(DetailRequestConfig detailRequestConfig,
List<DetailRequestConfig> childList,
List<Object> list,
RecordSet mainRs) {
try {
// 子项数据来源
String dataSource = detailRequestConfig.getDataSource();
// 主表
if (RequestPushConstant.DATASOURCE_MAIN_TABLE.equals(dataSource)) {
HashMap<String, Object> 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<String, Object> map = new HashMap<>();
this.setObjValue(childList, map, mainRs, detailRs);
list.add(map);
}
}
}
}catch (Exception e){
throw new RuntimeException("执行setListValue发生异常 : " + e.getMessage());
}
}
/**
* <h1></h1>
* @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;
}
/**
* <h1></h1>
* @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;
}
/**
* <h1>Date</h1>
*
* @param dateStr
* @return
*/
private static Date parseDate(String dateStr) {
ThreadLocal<SimpleDateFormat> 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);
}
}

View File

@ -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;
/**
* <h1>rocketMQ</h1>
*
* @Author xuanran.wang
* @Date 2022/12/29 14:21
*/
public class RocketMQFactory {
public static Map<String, Map<String,Object>> CONFIG_MAPS = new HashMap<>(16);
public static DefaultMQPushConsumer getMQPushConsumer(String configName, MessageListenerConcurrently messageListenerConcurrently){
try {
Map<String, Object> 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()));
}
}
}

View File

@ -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;
/**
* <h1>RocketMQListener</h1>
*
* @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();
}
/**
* <h1></h1>
* @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));
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/29 21:49
* @return MessageListenerConcurrently
**/
public abstract MessageListenerConcurrently service();
}

View File

@ -0,0 +1,15 @@
package weaver.xuanran.wang.shyl.mq.constant;
/**
* <h1>RocketMQ</h1>
*
* @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;
}

View File

@ -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;
/**
* <h1></h1>
*
* @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<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext)->{
Map<String, Object> map = RocketMQFactory.CONFIG_MAPS.get(CONFIG_NAME);
log.info(Util.logStr("{} service config is {}", CONFIG_NAME, JSONObject.toJSONString(map)));
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
};
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @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<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext)->{
Map<String, Object> map = RocketMQFactory.CONFIG_MAPS.get(CONFIG_NAME);
log.info(Util.logStr("{} service config is {}", CONFIG_NAME, JSONObject.toJSONString(map)));
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
};
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @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<MessageExt> msg, ConsumeConcurrentlyContext consumeConcurrentlyContext)-> RocketUtil.execute(msg, consumeConcurrentlyContext, userInfoService, CONFIG_NAME);
}
}

View File

@ -0,0 +1,44 @@
package weaver.xuanran.wang.shyl.mq.entity;
import lombok.Data;
/**
* <h1>mq</h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:09
*/
@Data
public class MQMessage {
/**
* <h2>ID</h2>
**/
private String id;
/**
* <h2></h2>
* <p>
* AUTH_CONSOLE_USERINFO_TOPIC: ;
* AUTH_CONSOLE_ORG_TOPIC: ;
* AUTH_CONSOLE_USERINFO_PASSWORD_TOPIC:
* </p>
**/
private String topic;
/**
* <h2></h2>
* <p>
* CREATE_ACTION;
* UPDATE_ACTION: ;
* DELETE_ACTION: ;
* PASSWORD_ACTION:
* </p>
**/
private String actionType;
/**
* <h2></h2>
**/
private String sendTime;
/**
* <h2>,json ,()</h2>
**/
private String content;
}

View File

@ -0,0 +1,43 @@
package weaver.xuanran.wang.shyl.mq.entity;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:59
*/
public class ModifyPassWord {
/**
* <h2></h2>
**/
private String id;
/**
* <h2>ID</h2>
**/
private String uid;
/**
* <h2></h2>
**/
private String username;
/**
* <h2></h2>
**/
private String displayName;
/**
* <h2></h2>
**/
private String oldPassword;
/**
* <h2></h2>
**/
private String password;
/**
* <h2></h2>
**/
private String confirmPassword;
/**
* <h2></h2>
**/
private String decipherable;
}

View File

@ -0,0 +1,38 @@
package weaver.xuanran.wang.shyl.mq.entity;
import lombok.Data;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:56
*/
@Data
public class Org {
/**
* <h2>ID</h2>
**/
private String id;
/**
* <h2></h2>
**/
private String orgCode;
/**
* <h2></h2>
**/
private String orgName;
/**
* <h2>ID</h2>
**/
private String parentId;
/**
* <h2></h2>
**/
private String sortIndex;
/**
* <h2></h2>
**/
private String status;
}

View File

@ -0,0 +1,61 @@
package weaver.xuanran.wang.shyl.mq.entity;
import lombok.Data;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:52
*/
@Data
public class UserInfo {
/**
* <h2>ID</h2>
**/
private String id;
/**
* <h2></h2>
**/
private String userName;
/**
* <h2></h2>
**/
private String displayName;
/**
* <h2></h2>
**/
private String gender;
/**
* <h2></h2>
**/
private String birthDate;
/**
* <h2></h2>
**/
private String idType;
/**
* <h2></h2>
**/
private String idCardNo;
/**
* <h2></h2>
**/
private String email;
/**
* <h2></h2>
**/
private String mobile;
/**
* <h2>ID</h2>
**/
private String departmentId;
/**
* <h2></h2>
**/
private String department;
/**
* <h2></h2>
**/
private String status;
}

View File

@ -0,0 +1,35 @@
package weaver.xuanran.wang.shyl.mq.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Update;
/**
* <h1>mapper</h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 14:19
*/
public interface ConsumerMapper {
/**
* <h1>outKey</h1>
* @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);
/**
* <h1>outKey</h1>
* @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);
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:04
*/
public abstract class CusInfoActionService implements CreateAction, DeleteAction, UpdateAction {
/**
* <h2>consumer-mapper</h2>
**/
protected final ConsumerMapper consumerMapper = Util.getMapper(ConsumerMapper.class);
}

View File

@ -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;
/**
* <h1></h1>
*
* @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;
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @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;
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:00
*/
public interface CreateAction {
ConsumeConcurrentlyStatus cusCreateAction(MQMessage message);
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:02
*/
public interface DeleteAction {
ConsumeConcurrentlyStatus cusDeleteAction(MQMessage message);
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:03
*/
public interface PassWordAction {
ConsumeConcurrentlyStatus cusPassWordAction(MQMessage message);
}

View File

@ -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;
/**
* <h1></h1>
*
* @Author xuanran.wang
* @Date 2022/12/30 13:01
*/
public interface UpdateAction {
ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message);
}

View File

@ -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;
/**
* <h1>rocketMQ</h1>
*
* @Author xuanran.wang
* @Date 2022/12/29 21:03
*/
public class RocketUtil {
private static final Logger log = Util.getLogger();
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2022/12/29 12:53
**/
public static Map<String, Object> initMQConfigMap(String configName){
Map<String, Object> 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<String, Object> 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;
}
/**
* <h1></h1>
* @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<MessageExt> msg, ConsumeConcurrentlyContext consumeConcurrentlyContext,
CusInfoActionService cusInfoActionService, String configName){
Map<String, Object> 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;
}
}

View File

@ -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;
/**
* <h1></h1>
@ -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));
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @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<String, Object> requestParam = requestDataPush.getRequestParam(config, requestId);
log.info("请求参数: " + JSONObject.toJSONString(requestParam));
}
}