diff --git a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java index 5adc100..d33caa7 100644 --- a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java @@ -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); diff --git a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java index e2b72c2..1ced546 100644 --- a/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java @@ -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); diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java index 1d09cfc..bd06044 100644 --- a/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java +++ b/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java @@ -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 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 ->{ diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java deleted file mode 100644 index 6223c91..0000000 --- a/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java +++ /dev/null @@ -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; - -/** - *

文件下载mapper

- * - * @Author xuanran.wang - * @Date 2022/12/7 10:58 - */ -@SqlMapper -public interface DownLoadFileMapper { - - /** - *

根据docId查询附件信息

- * @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 selectDocInfoByDocId(@ParamMapper("docId") String docId); -} diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java index 49f5ef6..9e83c02 100644 --- a/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java +++ b/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java @@ -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 { *

查询文件记录sql

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

根据docId获取文件信息

@@ -33,23 +32,29 @@ public class DownLoadFileService { * @param docId docId **/ public Map 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 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 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; } diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index 0a037d3..ef493ae 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -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)); } + /** + *

将建模配置表中的自定义数据条件进行拼接

+ * @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; + } + } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java b/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java index ca81f9e..4464b7b 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java @@ -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> detailList = schroederQRCodeService.getDetailList(detailTable, mainId); - List docIds = detailList.stream() - .map(item -> Util.null2DefaultStr(item.get(fileField), "")) - .filter(StringUtils::isNotBlank).collect(Collectors.toList()); + List detailFileId = schroederQRCodeService.getDetailFileId(fileField, detailTable, mainId); + log.info(Util.logStr("明细docId集合 : {}", JSONObject.toJSONString(detailFileId))); List> docLogParamList = new ArrayList<>(); - for (String docId : docIds) { + for (String docId : detailFileId) { LinkedHashMap 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 map = new LinkedHashMap<>(); int count = schroederQRCodeService.getTaskIdByRequestId(requestId); diff --git a/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java b/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java index 2bc8c97..ada21ba 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/action/SalesforceEndpointAction.java @@ -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 { /** *

建模配置唯一标识

**/ - @RequiredMark private String onlyMark; /** *

响应成功状态码

**/ - @RequiredMark private String successCode; /** *

请求方式

**/ - @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; } } } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java index eb4605c..83c29da 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java @@ -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; /** *

@@ -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 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(" ", " "); + + 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); } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java index 9e53859..8fda5f3 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java @@ -39,9 +39,9 @@ public interface SchroederMapper { * @return 明细表数据集合 **/ @Select("select $t{fileField} from $t{tableName} where mainid = #{mainId}") - List> selectSealFileList(@ParamMapper("fileField") String fileField, - @ParamMapper("tableName") String tableName, - @ParamMapper("mainId") String mainId); + List selectSealFileList(@ParamMapper("fileField") String fileField, + @ParamMapper("tableName") String tableName, + @ParamMapper("mainId") String mainId); /** *

得到任务Id

* @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> detailList(@ParamMapper("tableName") String tableName, + List> detailList(@ParamMapper("tableName") String tableName, @ParamMapper("mainId") String mainId); } diff --git a/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java b/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java index 8d1f67a..79cf853 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java @@ -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 requestParam, String billTable, String mainId, String filePeopleType) { List> files = (List>) requestParam.get("file"); - List> detail1List = schroederMapper.selectSealTaskInfoList(billTable, mainId); - if (CollectionUtils.isEmpty(detail1List) || CollectionUtils.isEmpty(files)) { + if (CollectionUtils.isEmpty(files)) { return; } - // 遍历明细数据 - for (Map 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> 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 o = filterFiles.get(0); @@ -211,8 +221,19 @@ public class SchroederQRCodeService { // 印章集合 List> sealList = new ArrayList<>(); HashMap 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> getDetailList(String tableName, String mainId) { + public List> getDetailList(String tableName, String mainId) { return schroederMapper.detailList(tableName, mainId); } + + /** + *

获取明细1文件数据id

+ * + * @param fileField 用印文件字段名 + * @param tableName 明细表名 + * @param mainId 主id + * @return 明细表数据 + * @author xuanran.wang + * @dateTime 2022/12/21 18:03 + **/ + public List getDetailFileId(String fileField,String tableName, String mainId) { + return schroederMapper.selectSealFileList(fileField,tableName, mainId); + } + } diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQConsumerListener.java similarity index 92% rename from src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java rename to src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQConsumerListener.java index b72f25c..366a1b1 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQListener.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQConsumerListener.java @@ -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; /** *

上海团校RocketMQListener

@@ -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 diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java index 1153f0f..ee9bee2 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/RocketMQFactory.java @@ -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; /** *

rocketMQ工厂

@@ -19,14 +22,28 @@ import java.util.Map; * @Date 2022/12/29 14:21 */ public class RocketMQFactory { + + /** + *

配置文件本地存储对象

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

生产者map

+ **/ + private static Map PRODUCER_MAP = new ConcurrentHashMap<>(16); + + /** + *

根据配置文件生成消费者对象

+ * @author xuanran.wang + * @dateTime 2023/1/4 12:55 + * @param configName 配置文件名称 + * @param messageListenerConcurrently 消息监听处理业务方法 + * @return 消费者 + **/ public static DefaultMQPushConsumer getMQPushConsumer(String configName, MessageListenerConcurrently messageListenerConcurrently){ try { - Map configMap = new HashMap<>(); - if(!CONFIG_MAPS.containsKey(configName)){ - configMap = RocketUtil.initMQConfigMap(configName); - CONFIG_MAPS.put(configName, configMap); - } + Map 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 { } } + /** + *

根据配置文件获取生产者对象

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

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

+ * @author xuanran.wang + * @dateTime 2023/1/4 13:18 + * @param configName 配置文件名称 + * @return 配置文件map + **/ + private synchronized static Map getConfigMapByName(String configName){ + Map configMap = new HashMap<>(); + if(!CONFIG_MAPS.containsKey(configName)){ + configMap = RocketUtil.initMQConfigMap(configName); + CONFIG_MAPS.put(configName, configMap); + } + return configMap; + } + } diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java b/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java new file mode 100644 index 0000000..f117afd --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/action/ProducerAction.java @@ -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; + +/** + *

生产者action 将流程数据发送到mq中

+ * + * @author xuanran.wang + * @date 2023/1/4 14:47 + */ +public class ProducerAction extends SafeCusBaseAction { + + /** + *

mq配置文件名称

+ **/ + @RequiredMark + private String MQConfigName; + /** + *

配置文件唯一标识

+ **/ + @RequiredMark + private String onlyMark; + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java index d015a63..db980e2 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/constant/RocketMQConstant.java @@ -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 SEX_MAPPING = new HashMap<>(); diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java index 2633780..b5c11a1 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/OrgConsumer.java @@ -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; /** *

部门队列消费者

@@ -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"; diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java index e45de99..f400e56 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/PassWordConsumer.java @@ -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; /** *

密码修改队列消费者

@@ -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"; diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java index 708c069..f87a276 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/consumer/UserInfoConsumer.java @@ -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"; diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java new file mode 100644 index 0000000..fb9580f --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/ProducerService.java @@ -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; + +/** + *

生产者业务方法

+ * + * @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 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)); + } +} diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java index 5a715b1..c944603 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/service/impl/OrgServiceImpl.java @@ -24,6 +24,7 @@ import java.util.List; * @Date 2022/12/30 15:05 */ public class OrgServiceImpl extends CusInfoActionService { + /** *

部门创建

* @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 { } } + /** + *

部门更新

+ * @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 { } } + /** + *

更新部门信息

+ * @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 = ?, " + diff --git a/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java index a168ece..d1782fe 100644 --- a/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java +++ b/src/main/java/weaver/xuanran/wang/shyl/mq/util/RocketUtil.java @@ -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; } + + /** + *

向mq中发送消息

+ * @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 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)); + } + } + } diff --git a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java index a3e0bf2..359ac05 100644 --- a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java +++ b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java @@ -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 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(){