mq消息队列开发
parent
50789e184b
commit
868fc51f2d
|
@ -21,6 +21,7 @@ const detail2ComPayDateId = WfForm.convertFieldNameToId("yjfkrq",detailTable);
|
||||||
const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
const detail2TempDateField = WfForm.convertFieldNameToId("dyrq", detailTable);
|
||||||
// 需要计算的款项类型集合
|
// 需要计算的款项类型集合
|
||||||
const computeDatePayType = ['0'];
|
const computeDatePayType = ['0'];
|
||||||
|
const DETAIL_MAX_SIZE = 5;
|
||||||
// 款项类型预计对应日期取值
|
// 款项类型预计对应日期取值
|
||||||
const paymentTypeGetValue = {
|
const paymentTypeGetValue = {
|
||||||
0: (index)=>{
|
0: (index)=>{
|
||||||
|
@ -37,16 +38,22 @@ jQuery().ready(function(){
|
||||||
'computeDatePayType': computeDatePayType,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue
|
||||||
}
|
}
|
||||||
|
let rowArr = WfForm.getDetailAllRowIndexStr(detailTable).split(",");
|
||||||
|
|
||||||
|
if(rowArr.length !== DETAIL_MAX_SIZE){
|
||||||
// 默认增加5条
|
// 默认增加5条
|
||||||
for (let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}});
|
WfForm.addDetailRow(detailTable,{ [detail2PaymentTypeId]: {value: i}});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
||||||
|
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj);
|
mainFieldChangeDetailCom(contractSignDateId, detailTable, configObj);
|
||||||
|
|
||||||
// 明细的款项类型字段变化绑定
|
// 明细的款项类型字段变化绑定
|
||||||
detailFieldChangeDetailCom(`${detail2AroundId},${detail2DayId}`, configObj);
|
detailFieldChangeDetailCom(`${detail2PaymentTypeId},${detail2AroundId},${detail2DayId}`, configObj);
|
||||||
|
|
||||||
submitCallback(detailTable, detail2PayProportionId);
|
submitCallback(detailTable, detail2PayProportionId);
|
||||||
|
|
||||||
|
|
|
@ -152,3 +152,24 @@ function changeDetailPayDate(obj){
|
||||||
WfForm.changeFieldAttr(`${detailComPayDateId}_${index}`, EDIT);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
*/
|
*/
|
||||||
// 明细表
|
// 明细表
|
||||||
const detailTable = "detail_3";
|
const detailTable = "detail_3";
|
||||||
// 主表项目字段
|
// 主表订单编号字段
|
||||||
const mainProjectId = WfForm.convertFieldNameToId("xmmc");
|
const mainProjectId = WfForm.convertFieldNameToId("ddh1");
|
||||||
// 主表合同签订日期
|
// 主表合同签订日期
|
||||||
const contractSignDateId = WfForm.convertFieldNameToId("htqdrq");
|
const contractSignDateId = WfForm.convertFieldNameToId("htqdrq");
|
||||||
|
// 主表订单申请日期
|
||||||
|
const mainPOApplyId = WfForm.convertFieldNameToId("rkdsqrq");
|
||||||
// 明细2付款比例字段
|
// 明细2付款比例字段
|
||||||
const detailPayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable);
|
const detailPayProportionId = WfForm.convertFieldNameToId("fkbl",detailTable);
|
||||||
// 明细2款项类型
|
// 明细2款项类型
|
||||||
|
@ -28,10 +30,10 @@ const paymentTypeGetValue = {
|
||||||
WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(contractSignDateId)});
|
WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(contractSignDateId)});
|
||||||
},
|
},
|
||||||
2: (index)=>{
|
2: (index)=>{
|
||||||
WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainActualCheckId)});
|
WfForm.changeFieldValue(`${detailTempDateField}_${index}`,{value : WfForm.getFieldValue(mainPOApplyId)});
|
||||||
},
|
},
|
||||||
4: (index)=>{
|
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,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue
|
||||||
}
|
}
|
||||||
|
changeDetailFieldReadOnly(detailTable, detailComPayDateId, detailPaymentTypeId, computeDatePayType)
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj);
|
mainFieldChangeDetailCom(`${mainProjectId},${contractSignDateId}`, detailTable, obj);
|
||||||
// 明细的款项类型字段变化绑定
|
// 明细的款项类型字段变化绑定
|
||||||
|
|
|
@ -52,6 +52,7 @@ function init(){
|
||||||
'computeDatePayType': computeDatePayType,
|
'computeDatePayType': computeDatePayType,
|
||||||
'paymentTypeGetValue': paymentTypeGetValue
|
'paymentTypeGetValue': paymentTypeGetValue
|
||||||
}
|
}
|
||||||
|
changeDetailFieldReadOnly(detailTable, detail2ComPayDateId, detail2PaymentTypeId, computeDatePayType)
|
||||||
// 主表字段发生变化
|
// 主表字段发生变化
|
||||||
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
|
mainFieldChangeDetailCom(mainProjectId, detailTable, obj);
|
||||||
// 明细的款项类型字段变化绑定
|
// 明细的款项类型字段变化绑定
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -80,6 +80,14 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
|
<artifactId>rocketmq-client</artifactId>
|
||||||
|
<version>4.4.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
@ -56,7 +56,8 @@ public class ContractApplyComDateAction extends SafeCusBaseAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
|
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);
|
rs.setAutoCommit(false);
|
||||||
try {
|
try {
|
||||||
Map<String, String> mainTableValue = getMainTableValue(requestInfo);
|
Map<String, String> mainTableValue = getMainTableValue(requestInfo);
|
||||||
|
@ -74,13 +75,13 @@ public class ContractApplyComDateAction extends SafeCusBaseAction {
|
||||||
if(StringUtils.isNotBlank(updateWhere)){
|
if(StringUtils.isNotBlank(updateWhere)){
|
||||||
updateSql += " and " + updateWhere;
|
updateSql += " and " + updateWhere;
|
||||||
}
|
}
|
||||||
|
log.info(Util.logStr("更新合同明细表sql:{}, 参数:{}, {}", updateSql, checkDate, mainId));
|
||||||
if(!rs.executeUpdate(updateSql, checkDate, mainId)){
|
if(!rs.executeUpdate(updateSql, checkDate, mainId)){
|
||||||
log.error(Util.logStr("更新合同明细表sql:{}, 参数:{}", updateSql, new String[]{checkDate, mainId}));
|
|
||||||
throw new CustomerException("更新合同sql错误!");
|
throw new CustomerException("更新合同sql错误!");
|
||||||
}
|
}
|
||||||
rs.commit();
|
rs.commit();
|
||||||
}else{
|
}else{
|
||||||
log.error(Util.logStr("查询施工合同关联项目sql : {}", selectSql));
|
log.error(Util.logStr("查询施工合同关联项目sql暂未查到数据! sql {} ,{}", selectSql, requestId));
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
rs.rollback();
|
rs.rollback();
|
||||||
|
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 = "";
|
||||||
|
}
|
|
@ -3,19 +3,25 @@ package weaver.xuanran.wang.epdi.datapush.eneity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <h1>配置表明细表实体类</h1>
|
||||||
|
*
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/6/18 16:47
|
* @Date 2022/12/23 16:20
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class DetailRequestConfig {
|
public class DetailRequestConfig {
|
||||||
private String paramName;
|
private String paramName;
|
||||||
|
private String paramNodeType;
|
||||||
|
private String detailIndex;
|
||||||
|
private String parentName;
|
||||||
private String paramType;
|
private String paramType;
|
||||||
private String getValueType;
|
private String getValueType;
|
||||||
private String valueContext;
|
private String valueContext;
|
||||||
private String tableName;
|
|
||||||
private String workFlowField;
|
private String workFlowField;
|
||||||
private String fieldName;
|
private String dataSource;
|
||||||
private String detailId;
|
private String workFlowFieldName;
|
||||||
private String parentName;
|
private List<DetailRequestConfig> detailRequestConfigList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,10 @@ import lombok.Data;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <h1>配置表主表实体类</h1>
|
||||||
|
*
|
||||||
* @Author xuanran.wang
|
* @Author xuanran.wang
|
||||||
* @Date 2022/6/18 15:43
|
* @Date 2022/12/23 16:20
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class MainRequestConfig {
|
public class MainRequestConfig {
|
||||||
|
@ -15,11 +17,8 @@ public class MainRequestConfig {
|
||||||
private String uniqueCode;
|
private String uniqueCode;
|
||||||
private String workflow;
|
private String workflow;
|
||||||
private String requestUrl;
|
private String requestUrl;
|
||||||
private String dataSource;
|
|
||||||
private String detailIndex;
|
|
||||||
private String cusSql;
|
private String cusSql;
|
||||||
private String configFilePath;
|
|
||||||
private String enable;
|
private String enable;
|
||||||
private String methodParameterClassName;
|
private String tableName;
|
||||||
private List<DetailRequestConfig> detailRequestConfigList;
|
private List<DetailRequestConfig> detailRequestConfigList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ import aiyh.utils.Util;
|
||||||
import basetest.BaseTest;
|
import basetest.BaseTest;
|
||||||
import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService;
|
import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import weaver.interfaces.encode.AuthorizationBasic4OAuth2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h1>安波福校验用户测试类</h1>
|
* <h1>安波福校验用户测试类</h1>
|
||||||
|
@ -24,4 +25,12 @@ public class CheckUserTest extends BaseTest {
|
||||||
log.error(Util.getErrString(e));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue