2023-01-12 施罗德代码测试提交与mq部分代码

main
xuanran.wang 2023-01-12 16:47:02 +08:00
parent 4bbe6a2df8
commit 557afeaa25
22 changed files with 423 additions and 138 deletions

View File

@ -32,23 +32,8 @@ public class CheckUserController {
String checkContent = request.getParameter("checkContent");
try {
CheckUserService checkUserService = new CheckUserService();
return ApiResult.success(checkUserService.checkADHasUser(checkContent),"ok");
}catch (Exception e){
String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage());
log.error(error);
log.error(Util.getErrString(e));
return ApiResult.error(500, error);
}
}
@Path("logUser")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String logUser(@Context HttpServletRequest request, @Context HttpServletResponse response) {
try {
CheckUserService checkUserService = new CheckUserService();
checkUserService.logAllUser();
return ApiResult.successNoData();
boolean has = checkUserService.checkADHasUser(checkContent);
return ApiResult.success(has,"ok");
}catch (Exception e){
String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage());
log.error(error);

View File

@ -65,7 +65,8 @@ public class CheckUserService {
// 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果
NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchControl);
boolean has = answer.hasMoreElements();
while (answer.hasMoreElements()) {
log.info("has " + has);
if(has){
SearchResult sr = (SearchResult) answer.next();
String dn = sr.getName();
log.info("dn " + dn);

View File

@ -1,9 +1,13 @@
package com.api.xuanran.wang.schroeder.download_file.controller;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import com.api.xuanran.wang.schroeder.download_file.service.DownLoadFileService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.docs.docs.DocInfo;
import weaver.file.ImageFileManager;
import javax.servlet.http.HttpServletRequest;
@ -43,6 +47,9 @@ public class DownLoadFileController {
Map<String, Object> fileInfo = downLoadFileService.getFileInfo(docId);
String fileName = Util.null2String(fileInfo.get("fileName"));
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
if(StringUtils.isBlank(fileName) || imageFileId < 0){
throw new CustomerException(Util.logStr("文件信息部分字段查询为空!当前查询结果map:[{}]", JSONObject.toJSONString(fileInfo)));
}
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
byte[] bytes = IOUtils.toByteArray(is);
StreamingOutput output = outputStream ->{

View File

@ -1,33 +0,0 @@
package com.api.xuanran.wang.schroeder.download_file.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import java.util.Map;
/**
* <h1>mapper</h1>
*
* @Author xuanran.wang
* @Date 2022/12/7 10:58
*/
@SqlMapper
public interface DownLoadFileMapper {
/**
* <h1>docId</h1>
* @author xuanran.wang
* @dateTime 2022/12/7 11:01
* @param docId docId
* @return imageField
**/
@Select("select t3.imagefileid imageFileId,t3.imagefilename fileName,t3.filerealpath filePath " +
"from DocDetail t1 " +
"left join DocImageFile t2 " +
"on t2.docid = t1.id " +
"left join ImageFile t3 " +
"on t3.imagefileid = t2.imagefileid " +
"where t1.id = #{docId}")
Map<String, Object> selectDocInfoByDocId(@ParamMapper("docId") String docId);
}

View File

@ -2,11 +2,11 @@ package com.api.xuanran.wang.schroeder.download_file.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import java.util.HashMap;
import java.util.Map;
/**
@ -24,7 +24,6 @@ public class DownLoadFileService {
* <h2>sql</h2>
**/
private static final String SELECT_DOC_LOG_SQL = "select 1 from " + DOC_LOG_TABLE_NAME + " where docId = ? and enable = 0";
private final DownLoadFileMapper downLoadFileMapper = Util.getMapper(DownLoadFileMapper.class);
/**
* <h1>docId</h1>
@ -33,23 +32,29 @@ public class DownLoadFileService {
* @param docId docId
**/
public Map<String, Object> getFileInfo(String docId) {
RecordSet rs = new RecordSet();
if(StringUtils.isBlank(docId)) {
throw new CustomerException(Util.logStr("下载文件失败, 请求路径中不包含指定的docId!当前请求docId:{}", docId));
}
RecordSet rs = new RecordSet();
if (!rs.executeQuery(SELECT_DOC_LOG_SQL, docId) || !rs.next()) {
throw new CustomerException("下载文件失败, 请确认文件记录表中是否存在docId = [ " + docId + " ]的文件!");
}
Map<String, Object> fileInfoMap = downLoadFileMapper.selectDocInfoByDocId(docId);
if(MapUtils.isEmpty(fileInfoMap)){
throw new CustomerException("执行查询文件信息sql失败!");
String sql = " select t3.imagefileid imageFileId,t3.imagefilename fileName " +
" from DocDetail t1 " +
" left join DocImageFile t2 " +
" on t2.docid = t1.id " +
" left join ImageFile t3 " +
" on t3.imagefileid = t2.imagefileid " +
" where t1.id = ?";
HashMap<String, Object> res = new HashMap<>();
if (rs.executeQuery(sql, docId) && rs.next()) {
res.put("imageFileId", rs.getString("imageFileId"));
res.put("fileName", rs.getString("fileName"));
}
String fileName = Util.null2DefaultStr(fileInfoMap.get("fileName"),"");
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfoMap.get("imageFileId"),""), -1);
if(StringUtils.isBlank(fileName) ||imageFileId < 0){
throw new CustomerException(Util.logStr("文件信息部分字段查询为空!当前查询结果map:[{}]", JSONObject.toJSONString(fileInfoMap)));
if(MapUtils.isEmpty(res)){
throw new CustomerException(Util.logStr("执行查询文件信息sql失败! 当前sql : {}", sql));
}
return fileInfoMap;
return res;
}

View File

@ -12,6 +12,8 @@ import org.apache.log4j.Logger;
import weaver.conn.RecordSet;
import weaver.formmode.data.ModeDataApproval;
import weaver.hrm.User;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
import weaver.xuanran.wang.common.annocation.CusDateFormat;
import weaver.xuanran.wang.common.annocation.ParamNotNull;
import weaver.xuanran.wang.common.mapper.CommonMapper;
@ -594,6 +596,22 @@ public class CommonUtil {
return commonMapper.getModelNameByModelId(String.valueOf(modelId));
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/1/4 15:10
* @param requestMappingConfig
* @param tableName
* @return sql
**/
public static String getSelectSql( RequestMappingConfig requestMappingConfig, String tableName){
String cusWhere = Util.null2DefaultStr(requestMappingConfig.getCusWhereSql(), "");
if (StringUtils.isNotBlank(cusWhere)) {
cusWhere = " and " + DealWithMapping.sbc2dbcCase(cusWhere); // 全角转半角
}
return "select * from " + tableName + " where requestid = ? " + cusWhere;
}
}

View File

@ -4,6 +4,8 @@ import aiyh.utils.Util;
import aiyh.utils.action.SafeCusBaseAction;
import aiyh.utils.annotation.RequiredMark;
import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPObject;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;
@ -119,20 +121,18 @@ public class PushSealTaskAction extends SafeCusBaseAction { // 基础的action
delSql = "delete from " + detailTable + " where mainid = ? ";
}
try{
// 获取明细表数据
List<Map<String, String>> detailList = schroederQRCodeService.getDetailList(detailTable, mainId);
List<String> docIds = detailList.stream()
.map(item -> Util.null2DefaultStr(item.get(fileField), ""))
.filter(StringUtils::isNotBlank).collect(Collectors.toList());
List<String> detailFileId = schroederQRCodeService.getDetailFileId(fileField, detailTable, mainId);
log.info(Util.logStr("明细docId集合 : {}", JSONObject.toJSONString(detailFileId)));
List<LinkedHashMap<String, Object>> docLogParamList = new ArrayList<>();
for (String docId : docIds) {
for (String docId : detailFileId) {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("docId", docId);
map.put("enable", 0);
docLogParamList.add(map);
}
log.info(Util.logStr("docLogParamList集合 : {}", JSONObject.toJSONString(docLogParamList)));
// 将docLog数据写入建模
docLogModelIdList = CusInfoToOAUtil.executeBatch(Util.getIntValue(docLogModelId, -1), docLogParamList, "select id from #{tableName} where docId = ?", docIds);
docLogModelIdList = CusInfoToOAUtil.executeBatch(Util.getIntValue(docLogModelId, -1), docLogParamList);
// requestLog写入建模
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
int count = schroederQRCodeService.getTaskIdByRequestId(requestId);

View File

@ -1,10 +1,7 @@
package weaver.xuanran.wang.schroeder.action;
import aiyh.utils.Util;
import aiyh.utils.action.SafeCusBaseAction;
import aiyh.utils.annotation.RequiredMark;
import aiyh.utils.excention.CustomerException;
import weaver.hrm.User;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
@ -14,32 +11,35 @@ import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService;
* @Author xuanran.wang
* @Date 2022/12/23 10:49
*/
public class SalesforceEndpointAction extends SafeCusBaseAction {
public class SalesforceEndpointAction implements Action {
/**
* <h2></h2>
**/
@RequiredMark
private String onlyMark;
/**
* <h2></h2>
**/
@RequiredMark
private String successCode;
/**
* <h2></h2>
**/
@RequiredMark
private String type;
private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService();
@Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
public String execute(RequestInfo requestInfo) {
try {
String billTable = requestInfo.getRequestManager().getBillTableName();
String requestId = requestInfo.getRequestid();
schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId,type, successCode,"","");
return Action.SUCCESS;
}catch (Exception e){
throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage())); //
requestInfo.getRequestManager().setMessageid(String.valueOf(System.currentTimeMillis()));
requestInfo.getRequestManager().setMessagecontent(Util.logStr("执行提交方法异常:{}", e.getMessage()));
return Action.FAILURE_AND_CONTINUE;
}
}
}

View File

@ -6,12 +6,12 @@ import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import weaver.conn.ConnStatementDataSource;
import weaver.conn.RecordSet;
import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; // 自定义获取参数值
import weaver.zwl.common.ToolUtil; // 常用工具方法-公用类
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
/**
* <h1></h1>
@ -20,7 +20,6 @@ import java.util.stream.Collectors;
* @Date 2022/12/2 16:10
*/
public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定义获取参数值
private final ToolUtil toolUtil = new ToolUtil(); // 常用工具方法-公用类 构造方法
private final Logger logger = Util.getLogger(); // 获取日志对象
@ -46,11 +45,19 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定
int detailId = -1;
if(MapUtils.isNotEmpty(detailMap)){
detailId = Util.getIntValue(String.valueOf(detailMap.get("id")), -1);
if(detailId < 0){
detailId = Util.getIntValue(String.valueOf(detailMap.get("ID")), -1);
}
}
String requestId = String.valueOf(mainMap.get("requestid"));
if(StringUtils.isBlank(requestId)){
requestId = String.valueOf(mainMap.get("REQUESTID"));
}
logger.info(Util.logStr("requestId : {}, detailId : {}", requestId, detailId));
for (String val : currentValue.split(",")) {
// 印章类型转换执行自定义sql
String inSealVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealSnCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),""); // 用数据库值,根据规则转换,获取其最终结果
String inSealNumVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealNumCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),""); // 用数据库值,根据规则转换,获取其最终结果
String inSealVal = Util.null2DefaultStr(getValueByChangeRule(sealSnCusSql, val, requestId, detailId,""),""); // 用数据库值,根据规则转换,获取其最终结果
String inSealNumVal = Util.null2DefaultStr(getValueByChangeRule(sealNumCusSql, val, requestId, detailId,""),""); // 用数据库值,根据规则转换,获取其最终结果
HashMap<String, Object> map = new HashMap<>();
map.put(sealSnField, inSealVal);
map.put(sealNumField, inSealNumVal);
@ -59,6 +66,85 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定
return list;
}
/**
*
* @param cus_sql SQL
* @param value
* @param requestid ID
* @param detailKeyvalue
* @pram datasourceid ID
* @return
*/
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue,String datasourceid){
String endValue = "";
cus_sql = cus_sql.replace("&nbsp;", " ");
cus_sql = cus_sql.replace("{?dt.id}", String.valueOf(detailKeyvalue));
//参数进行替换
String sqlString = cus_sql.replace("{?requestid}", requestid);
sqlString = sqlString.replace("?", value);
sqlString = ToDBC(sqlString);
logger.info(Util.logStr("查询sql : {} ", sqlString));
try {
if(datasourceid != null && !"".equals(datasourceid)){
ConnStatementDataSource csds = new ConnStatementDataSource(datasourceid);
csds.setStatementSql(sqlString);
csds.executeQuery();
if(csds.next()){
endValue = weaver.general.Util.null2String(csds.getString(1));
}
csds.close();
}else{
RecordSet rs = new RecordSet();
if(rs.executeQuery(sqlString)){
if (rs.next()) {
endValue = weaver.general.Util.null2String(rs.getString(1));
logger.info(Util.logStr("执行自定义sql 返回结果 : {}", endValue));
}else {
logger.error("当前查询没有查询结果!");
}
}else {
logger.error("当前sql查询失败");
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return endValue;
}
/**
*
* @param input
* @return
*/
public String ToDBC(String input) {
char c[] = input.toCharArray();
for (int i = 0; i < c.length; i++) {
if (c[i] == '\u3000') {
c[i] = ' ';
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
c[i] = (char) (c[i] - 65248);
}
}
String returnString = new String(c);
return returnString;
}
public boolean checkBlank(String ... args){
return Arrays.stream(args).anyMatch(StringUtils::isBlank);
}

View File

@ -39,9 +39,9 @@ public interface SchroederMapper {
* @return
**/
@Select("select $t{fileField} from $t{tableName} where mainid = #{mainId}")
List<Map<String, Object>> selectSealFileList(@ParamMapper("fileField") String fileField,
@ParamMapper("tableName") String tableName,
@ParamMapper("mainId") String mainId);
List<String> selectSealFileList(@ParamMapper("fileField") String fileField,
@ParamMapper("tableName") String tableName,
@ParamMapper("mainId") String mainId);
/**
* <h1>Id</h1>
* @author xuanran.wang
@ -56,6 +56,6 @@ public interface SchroederMapper {
Integer selectTaskId(@ParamMapper("cusRequestId") String cusRequestId);
@Select("select * from $t{tableName} where mainid = #{mainId}")
List<Map<String, String>> detailList(@ParamMapper("tableName") String tableName,
List<Map<String, Object>> detailList(@ParamMapper("tableName") String tableName,
@ParamMapper("mainId") String mainId);
}

View File

@ -5,6 +5,7 @@ import aiyh.utils.excention.CustomerException; // 自定义异常类 create 20
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -188,22 +189,31 @@ public class SchroederQRCodeService {
**/
public void changeRequestMap(Map<String, Object> requestParam, String billTable, String mainId, String filePeopleType) {
List<Map<String, Object>> files = (List<Map<String, Object>>) requestParam.get("file");
List<Map<String, Object>> detail1List = schroederMapper.selectSealTaskInfoList(billTable, mainId);
if (CollectionUtils.isEmpty(detail1List) || CollectionUtils.isEmpty(files)) {
if (CollectionUtils.isEmpty(files)) {
return;
}
// 遍历明细数据
for (Map<String, Object> detailItem : detail1List) {
RecordSet detailRs = new RecordSet();
String sql = "select yywj,qfzzl,qfzcs from " + billTable + " where mainid = ? and sfjgqfz = 0";
if(!detailRs.executeQuery(sql, mainId)){
throw new CustomerException(Util.logStr("查询明细数据sql执行失败sql : {}, mainId : {}", sql, mainId));
}
// 貌似有bug 把mapper改成原生recordSet
while (detailRs.next()) {
// 用印文件
String sealFile = Util.null2String(detailItem.get("yywj"));
String sealFile = Util.null2String(detailRs.getString("yywj"));
if(StringUtils.isBlank(sealFile)){
sealFile = Util.null2String(detailRs.getString("YYWJ"));
}
// 从生成的请求参数map中开始匹配
String finalSealFile = sealFile;
List<Map<String, Object>> filterFiles = files.stream()
.filter(item -> {
String filePath = Util.null2DefaultStr(item.get("fileUrlPath"), "");
String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1), "");
return sealFile.equals(docId);
return finalSealFile.equals(docId);
})
.collect(Collectors.toList());
log.info(Util.logStr("filterFiles : {} ", JSONObject.toJSONString(finalSealFile)));
if (CollectionUtils.isNotEmpty(filterFiles)) {
// 只有一个能匹配
Map<String, Object> o = filterFiles.get(0);
@ -211,8 +221,19 @@ public class SchroederQRCodeService {
// 印章集合
List<HashMap<String, Object>> sealList = new ArrayList<>();
HashMap<String, Object> seal = new HashMap<>();
seal.put("sealSn", Util.null2DefaultStr(detailItem.get("qfzzl"), ""));
seal.put("sealNum", Util.null2DefaultStr(detailItem.get("qfzcs"), "0"));
// 骑缝章总类
String qfzzl = Util.null2DefaultStr(detailRs.getString("qfzzl"),"");
if(StringUtils.isBlank(qfzzl)){
qfzzl = Util.null2DefaultStr(detailRs.getString("QFZZL"),"");
}
log.info(Util.logStr("骑缝章总类 : {}", qfzzl));
seal.put("sealSn", qfzzl);
String qfzcs = Util.null2DefaultStr(detailRs.getString("qfzcs"),"");
if(StringUtils.isBlank(qfzcs)){
qfzcs = Util.null2DefaultStr(detailRs.getString("QFZCS"),"");
}
log.info(Util.logStr("骑缝章次数 : {}", qfzcs));
seal.put("sealNum", Util.null2DefaultStr(qfzcs, "0"));
sealList.add(seal);
tempMap.put("seal", sealList);
tempMap.put("filePeopleType", filePeopleType);
@ -242,10 +263,25 @@ public class SchroederQRCodeService {
* @author xuanran.wang
* @dateTime 2022/12/21 18:03
**/
public List<Map<String, String>> getDetailList(String tableName, String mainId) {
public List<Map<String, Object>> getDetailList(String tableName, String mainId) {
return schroederMapper.detailList(tableName, mainId);
}
/**
* <h1>1id</h1>
*
* @param fileField
* @param tableName
* @param mainId id
* @return
* @author xuanran.wang
* @dateTime 2022/12/21 18:03
**/
public List<String> getDetailFileId(String fileField,String tableName, String mainId) {
return schroederMapper.selectSealFileList(fileField,tableName, mainId);
}
}

View File

@ -8,7 +8,6 @@ import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import java.util.Map;
/**
* <h1>RocketMQListener</h1>
@ -16,12 +15,12 @@ import java.util.Map;
* @Author xuanran.wang
* @Date 2022/12/29 12:25
*/
public abstract class RocketMQListener extends HttpServlet {
public abstract class RocketMQConsumerListener extends HttpServlet {
private static final Logger log = Util.getLogger();
private String configName;
public RocketMQListener() {
public RocketMQConsumerListener() {
}
public RocketMQListener(String configName) {
public RocketMQConsumerListener(String configName) {
this.configName = configName;
}
@Override

View File

@ -4,6 +4,8 @@ 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.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
import weaver.xuanran.wang.shyl.mq.constant.RocketMQConstant;
@ -11,6 +13,7 @@ import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* <h1>rocketMQ</h1>
@ -19,14 +22,28 @@ import java.util.Map;
* @Date 2022/12/29 14:21
*/
public class RocketMQFactory {
/**
* <h2></h2>
**/
public static Map<String, Map<String,Object>> CONFIG_MAPS = new HashMap<>(16);
/**
* <h2>map</h2>
**/
private static Map<String, DefaultMQProducer> PRODUCER_MAP = new ConcurrentHashMap<>(16);
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/1/4 12:55
* @param configName
* @param messageListenerConcurrently
* @return
**/
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);
}
Map<String, Object> configMap = getConfigMapByName(configName);
// 最大重试次数
int maxReconsumeTimes = Util.getIntValue(Util.null2String(configMap.get("MaxReconsumeTimes")), RocketMQConstant.DEFAULT_MAX_RECONSUME_TIMES);
// 声明一个消费者consumer需要传入一个组 weaver-consumer
@ -49,4 +66,55 @@ public class RocketMQFactory {
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/1/4 12:59
* @param configName
* @return
**/
public static DefaultMQProducer getMQProducer(String configName){
DefaultMQProducer defaultMQProducer = null;
if(PRODUCER_MAP.containsKey(configName)){
return PRODUCER_MAP.get(configName);
}else {
synchronized (RocketMQFactory.class){
if(PRODUCER_MAP.containsKey(configName)){
return PRODUCER_MAP.get(configName);
}else {
Map<String, Object> configMap = getConfigMapByName(configName);
defaultMQProducer = new DefaultMQProducer();
// 发送消息最大超时时间 默认60000
int sendMsgTimeOut = Util.getIntValue(Util.null2String(configMap.get("sendMsgTimeOut")), RocketMQConstant.PRODUCER_SEND_MSG_TIME_OUT);
defaultMQProducer.setSendMsgTimeout(sendMsgTimeOut);
try {
defaultMQProducer.start();
}catch (MQClientException e){
throw new CustomerException("producer start error!");
}
// mq地址
defaultMQProducer.setNamesrvAddr(Util.null2String(configMap.get("NameServer")));
PRODUCER_MAP.put(configName, defaultMQProducer);
}
}
}
return defaultMQProducer;
}
/**
* <h1>map</h1>
* @author xuanran.wang
* @dateTime 2023/1/4 13:18
* @param configName
* @return map
**/
private synchronized static Map<String, Object> getConfigMapByName(String configName){
Map<String, Object> configMap = new HashMap<>();
if(!CONFIG_MAPS.containsKey(configName)){
configMap = RocketUtil.initMQConfigMap(configName);
CONFIG_MAPS.put(configName, configMap);
}
return configMap;
}
}

View File

@ -0,0 +1,31 @@
package weaver.xuanran.wang.shyl.mq.action;
import aiyh.utils.action.SafeCusBaseAction;
import aiyh.utils.annotation.RequiredMark;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;
/**
* <h1>action mq</h1>
*
* @author xuanran.wang
* @date 2023/1/4 14:47
*/
public class ProducerAction extends SafeCusBaseAction {
/**
* <h2>mq</h2>
**/
@RequiredMark
private String MQConfigName;
/**
* <h2></h2>
**/
@RequiredMark
private String onlyMark;
@Override
public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) {
}
}

View File

@ -25,6 +25,7 @@ public class RocketMQConstant {
public static final String ID_TYPE_STU_CARD = "4";
public static final String ID_TYPE_SOLDIER_CARD = "5";
public static final String DEFAULT_PASSWORD = "1";
public static final int PRODUCER_SEND_MSG_TIME_OUT = 60000;
public static Map<String, String> SEX_MAPPING = new HashMap<>();

View File

@ -1,19 +1,15 @@
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.RocketMQConsumerListener;
import weaver.xuanran.wang.shyl.mq.service.impl.OrgServiceImpl;
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
import java.util.List;
import java.util.Map;
/**
* <h1></h1>
@ -21,7 +17,7 @@ import java.util.Map;
* @Author xuanran.wang
* @Date 2022/12/29 14:35
*/
public class OrgConsumer extends RocketMQListener {
public class OrgConsumer extends RocketMQConsumerListener {
private static final Logger log = Util.getLogger();
private static final String CONFIG_NAME = "OrgConsumer";

View File

@ -1,19 +1,15 @@
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.RocketMQConsumerListener;
import weaver.xuanran.wang.shyl.mq.service.impl.PassWordServiceImpl;
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
import java.util.List;
import java.util.Map;
/**
* <h1></h1>
@ -21,7 +17,7 @@ import java.util.Map;
* @Author xuanran.wang
* @Date 2022/12/29 14:35
*/
public class PassWordConsumer extends RocketMQListener {
public class PassWordConsumer extends RocketMQConsumerListener {
private static final Logger log = Util.getLogger();
public static final String CONFIG_NAME = "PassWordConsumer";

View File

@ -5,7 +5,7 @@ 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.RocketMQConsumerListener;
import weaver.xuanran.wang.shyl.mq.service.impl.UserServiceImpl;
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
@ -17,7 +17,7 @@ import java.util.List;
* @Author xuanran.wang
* @Date 2022/12/29 14:35
*/
public class UserInfoConsumer extends RocketMQListener {
public class UserInfoConsumer extends RocketMQConsumerListener {
private static final Logger log = Util.getLogger();
public static final String CONFIG_NAME = "UserInfoConsumer";

View File

@ -0,0 +1,42 @@
package weaver.xuanran.wang.shyl.mq.service;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.xiao.commons.config.entity.RequestMappingConfig;
import weaver.xiao.commons.config.service.DealWithMapping;
import weaver.xuanran.wang.common.util.CommonUtil;
import weaver.xuanran.wang.shyl.mq.util.RocketUtil;
import java.util.HashMap;
import java.util.Map;
/**
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/1/4 14:54
*/
public class ProducerService {
private final DealWithMapping dealWithMapping = new DealWithMapping();
public void pushWorkFlowToMQ(String configName, String onlyMark, String requestId, String tableName){
RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(onlyMark);
String selectMainSql = CommonUtil.getSelectSql(requestMappingConfig, tableName);
RecordSet recordSet = new RecordSet();
recordSet.executeQuery(selectMainSql, requestId);
Map<String, Object> requestParam = new HashMap<>();
if (recordSet.next()) {
dealWithMapping.setMainTable(tableName);
requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig);
}
if(MapUtils.isEmpty(requestParam)){
throw new CustomerException("convert workflow information to json error!");
}
RocketUtil.producerSendMsg(configName, JSONObject.toJSONString(requestParam));
}
}

View File

@ -24,6 +24,7 @@ import java.util.List;
* @Date 2022/12/30 15:05
*/
public class OrgServiceImpl extends CusInfoActionService {
/**
* <h1></h1>
* @author xuanran.wang
@ -41,7 +42,7 @@ public class OrgServiceImpl extends CusInfoActionService {
String subId = "";
RecordSet insertRs = new RecordSet();
if(StringUtils.isBlank(subId)){
throw new CustomerException("SubCompany can not be empey!");
throw new CustomerException("SubCompany can not be empty!");
}
//使用存储过程新增分部
String para = org.getOrgName() + separator + org.getOrgName() + separator +
@ -83,6 +84,13 @@ public class OrgServiceImpl extends CusInfoActionService {
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/1/4 14:44
* @param message mq
* @return /
**/
@Override
public ConsumeConcurrentlyStatus cusUpdateAction(MQMessage message) {
try {
@ -102,6 +110,14 @@ public class OrgServiceImpl extends CusInfoActionService {
}
}
/**
* <h1></h1>
* @author xuanran.wang
* @dateTime 2023/1/4 14:45
* @param depId id
* @param subId id
* @param org
**/
public void updateDepartmentInfo(String depId, String subId, Org org){
String insertSQL = "update hrmdepartment set created = ?, creater = ?, modified = ?, modifier = ?," +
" departmentcode = ?, tlevel = ?, showorder = ?, canceled = ?,departmentmark = ?, " +

View File

@ -9,7 +9,15 @@ 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.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;
import weaver.xuanran.wang.shyl.mq.constant.RocketMQConstant;
import weaver.xuanran.wang.shyl.mq.RocketMQFactory;
import weaver.xuanran.wang.shyl.mq.entity.MQMessage;
@ -67,8 +75,8 @@ public class RocketUtil {
try {
if (CollectionUtils.isNotEmpty(msg)) {
MessageExt messageExt = msg.get(0);
String msgBody = "";
MQMessage mqMessage = null;
String msgBody;
MQMessage mqMessage;
try {
msgBody = new String(messageExt.getBody(), StandardCharsets.UTF_8);
if(StringUtils.isBlank(msgBody)){
@ -107,6 +115,7 @@ public class RocketUtil {
} catch (Exception e) {
// 如果重试达到最大还是异常那么先返回成功 oa将错误日志记录到日志中
if (msg.get(0).getReconsumeTimes() == maxReconsumeTimes) {
//TODO
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
} else {
return ConsumeConcurrentlyStatus.RECONSUME_LATER;
@ -114,4 +123,40 @@ public class RocketUtil {
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
/**
* <h1>mq</h1>
* @author xuanran.wang
* @dateTime 2023/1/4 14:30
* @param configName
* @param msg
**/
public static void producerSendMsg(String configName, String msg) {
// 先从本地缓存中获取生产者对象
DefaultMQProducer producer = RocketMQFactory.getMQProducer(configName);
// 获取配置信息
Map<String, Object> configMap = RocketMQFactory.CONFIG_MAPS.get(configName);
// 队列名
String topic = Util.null2DefaultStr(configMap.get("Topic"),"");
// tag
String tag = Util.null2DefaultStr(configMap.get("Tag"),"");
Message message;
try {
message = new Message(topic, tag, msg.getBytes(RemotingHelper.DEFAULT_CHARSET));
}catch (Exception e){
throw new CustomerException(Util.logStr("init message error : {} !", e.getMessage()));
}
SendResult result;
try {
result = producer.send(message);
} catch (MQClientException | RemotingException | MQBrokerException | InterruptedException e) {
throw new CustomerException(Util.logStr("producer send message error!", e.getMessage()));
}
SendStatus sendStatus = result.getSendStatus();
// 如果成功
if(SendStatus.SEND_OK.equals(sendStatus)){
log.error(Util.logStr("producer send message call back status is not ok! the message is {}, the status is {}.", msg, sendStatus));
}
}
}

View File

@ -4,7 +4,6 @@ import aiyh.utils.Util;
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import basetest.BaseTest;
import com.alibaba.fastjson.JSONObject;
import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper;
import com.icbc.api.internal.apache.http.impl.cookie.S;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -32,19 +31,6 @@ import java.util.stream.Collectors;
* @Date 2022/12/7 11:58
*/
public class DownLoadFileTest extends BaseTest {
private final DownLoadFileMapper downLoadFileMapper = Util.getMapper(DownLoadFileMapper.class);
@Test
public void testSelectFileInfo() throws IOException {
Map<String, Object> fileInfo = downLoadFileMapper.selectDocInfoByDocId("95");
log.info("map " + fileInfo);
String fileName = Util.null2String(fileInfo.get("fileName"));
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
log.info("imageFileId " + imageFileId);
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
log.info(null == is);
}
@Test
public void testImageFileInputSteam(){