diff --git a/src/main/java/aiyh/utils/action/CusBaseAction.java b/src/main/java/aiyh/utils/action/CusBaseAction.java index 9b114a6..35827b6 100644 --- a/src/main/java/aiyh/utils/action/CusBaseAction.java +++ b/src/main/java/aiyh/utils/action/CusBaseAction.java @@ -31,6 +31,10 @@ public abstract class CusBaseAction implements Action { * 全局requestInfo对象 */ protected RequestInfo globalRequestInfo; + /** + *

线程局部变量

+ **/ + protected static ThreadLocal requestInfoThreadLocal = new ThreadLocal<>(); /** *

初始化流程默认的处理方法

@@ -49,6 +53,7 @@ public abstract class CusBaseAction implements Action { @Override public final String execute(RequestInfo requestInfo) { + requestInfoThreadLocal.set(requestInfo); this.globalRequestInfo = requestInfo; RequestManager requestManager = requestInfo.getRequestManager(); String billTable = requestManager.getBillTableName(); @@ -91,6 +96,9 @@ public abstract class CusBaseAction implements Action { if (this.exceptionCallback(e, requestManager)) { return Action.FAILURE_AND_CONTINUE; } + }finally { + // 无论成功还是失败 都将该线程的requestInfo进行移除 + requestInfoThreadLocal.remove(); } return Action.SUCCESS; } 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 new file mode 100644 index 0000000..5adc100 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java @@ -0,0 +1,59 @@ +package com.api.xuanran.wang.ambofo.checkuser.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService; +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +/** + *

安波福从AD域中校验用户是否存在

+ * + * @Author xuanran.wang + * @Date 2022/12/12 14:24 + */ +@Path("/wxr/ambofo/") +public class CheckUserController { + + private final Logger log = Util.getLogger(); + + @Path("checkUser") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String checkUser(@Context HttpServletRequest request, @Context HttpServletResponse response) { + 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(); + }catch (Exception e){ + String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage()); + log.error(error); + log.error(Util.getErrString(e)); + return ApiResult.error(500, 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 new file mode 100644 index 0000000..4a3c165 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java @@ -0,0 +1,149 @@ +package com.api.xuanran.wang.ambofo.checkuser.service; + + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.collections.MapUtils; +import org.apache.log4j.Logger; +import javax.naming.Context; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; +import javax.naming.ldap.InitialLdapContext; +import javax.naming.ldap.LdapContext; +import java.util.Hashtable; +import java.util.Map; + +/** + *

安波福从AD校验用户是否存在业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/12 14:29 + */ +public class CheckUserService { + + private Map ADConfig = null; + private final Logger log = Util.getLogger(); + /** + *

构造方法中初始化配置文件

+ * @author xuanran.wang + * @dateTime 2022/12/12 15:31 + **/ + public CheckUserService(){ + // AD配置文件 + ADConfig = Util.getProperties2Map("AmbofoADConfig"); + if(MapUtils.isEmpty(ADConfig)){ + throw new CustomerException("请检查/filesystem/prop/prop2map 文件夹下是否存在AmbofoADConfig.properties文件!"); + } + + log.info(Util.logStr("AD配置对象 : [{}]", JSONObject.toJSONString(ADConfig))); + } + + /** + *

校验AD是否存在指定用户

+ * @author xuanran.wang + * @dateTime 2022/12/12 15:22 + * @param checkInfo 校验内容 + * @return true/false 有/没有 + **/ + public boolean checkADHasUser(String checkInfo) { + //连接到AD + LdapContext ldapContext = login(); + try { + // 域节点 + String searchBase = Util.null2String(ADConfig.get("searchBase")); + // LDAP搜索过滤器类 cn=*name*模糊查询 cn=name 精确查询 String searchFilter = "(objectClass="+type+")"; + //查询域帐号 + String searchFilter = Util.null2String(ADConfig.get("queryField")) + "=" + checkInfo; + log.info("searchFilter : " + searchFilter); + // 创建搜索控制器 + SearchControls searchControl = new SearchControls(); + // 设置搜索范围 深度 + searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE); + // 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果 + NamingEnumeration answer = ldapContext.search(searchBase, searchFilter, searchControl); + // 初始化搜索结果数为0 + return answer.hasMoreElements(); + } catch (NamingException e) { + throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage())); + } finally { + close(ldapContext); + } + } + + public void logAllUser() { + //连接到AD + LdapContext ldapContext = login(); + try { + // 域节点 + String searchBase = Util.null2String(ADConfig.get("searchBase")); + // LDAP搜索过滤器类 cn=*name*模糊查询 cn=name 精确查询 String searchFilter = "(objectClass="+type+")"; + // 创建搜索控制器 + SearchControls searchControl = new SearchControls(); + // 设置搜索范围 深度 + searchControl.setSearchScope(SearchControls.SUBTREE_SCOPE); + // 根据设置的域节点、过滤器类和搜索控制器搜索LDAP得到结果 + NamingEnumeration answer = ldapContext.search(searchBase, "", searchControl); + //4. 获取查询的内容 + while (answer.hasMoreElements()) { + SearchResult sr = (SearchResult) answer.next(); + String dn = sr.getName(); + log.info("dn " + dn); + } + } catch (NamingException e) { + throw new CustomerException(Util.logStr("从AD搜索用户异常:[{}]",e.getMessage())); + } finally { + close(ldapContext); + } + } + + /** + *

创建LDAP连接

+ * @author xuanran.wang + * @dateTime 2022/12/12 15:21 + * @return LDAP连接对象 + **/ + private LdapContext login() { + String userName = Util.null2String(ADConfig.get("userName")); + String password = Util.null2String(ADConfig.get("password")); + String server = Util.null2String(ADConfig.get("server")); + String driver = Util.null2String(ADConfig.get("driver")); + String authentication = Util.null2String(ADConfig.get("authentication")); + try { + Hashtable env = new Hashtable<>(); + //用户名称,cn,ou,dc 分别:用户,组,域 + env.put(Context.SECURITY_PRINCIPAL, userName); + //用户密码 cn 的密码 + env.put(Context.SECURITY_CREDENTIALS, password); + //url 格式:协议://ip:端口/组,域 ,直接连接到域或者组上面 + env.put(Context.PROVIDER_URL, server); + //LDAP 工厂 + env.put(Context.INITIAL_CONTEXT_FACTORY, driver); + //验证的类型 "none", "simple", "strong" + env.put(Context.SECURITY_AUTHENTICATION, authentication); + return new InitialLdapContext(env, null); + } catch (NamingException e) { + throw new CustomerException(Util.logStr("连接AD失败! : {}", e.getMessage())); + } + } + + + /** + *

关闭连接

+ * @author xuanran.wang + * @dateTime 2022/12/12 15:30 + * @param lct AD连接对象 + **/ + private void close(LdapContext lct) { + try { + if (lct != null){ + //关闭连接 + lct.close(); + } + } catch (NamingException e) { + throw new CustomerException(Util.logStr("关闭AD连接失败! : {}", e.getMessage())); + } + } +} 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 b2dd097..49f5ef6 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 @@ -19,7 +19,7 @@ public class DownLoadFileService { /** *

文件记录表

**/ - private static final String DOC_LOG_TABLE_NAME = "doc_log"; + private static final String DOC_LOG_TABLE_NAME = "uf_doc_log"; /** *

查询文件记录sql

**/ diff --git a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java index c5431e4..b02e57f 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CusInfoToOAUtil.java @@ -90,6 +90,29 @@ public class CusInfoToOAUtil { return executeBatch(modelId, params, "", Collections.emptyList(), true); } + /** + *

将自定义信息写入建模

+ * @author xuanran.wang + * @dateTime 2022/11/23 17:00 + * @param modelId 模块id + * @param params 需要插入的数据map + * @param whereSql 重复数据条件sql + * @param whereParams 重复数据参数集合 + * @return 建模数据id集合 + **/ + public static List executeBatch( int modelId, + List> params, + String whereSql, + List whereParams) { + if(modelId < 0){ + throw new RuntimeException("建模模块id不能小于0!"); + } + String tableName = commonMapper.getModelNameByModelId(String.valueOf(modelId)); + if(StringUtils.isBlank(tableName)){ + throw new CustomerException("模块id为 " + modelId + ", 在系统中暂没查询到对应表单!"); + } + return executeBatch(modelId, tableName, params, whereSql, whereParams, true); + } /** *

将自定义信息写入建模

* @author xuanran.wang @@ -148,10 +171,11 @@ public class CusInfoToOAUtil { if(StringUtils.isNotBlank(whereSql)){ whereSql = Util.sbc2dbcCase(whereSql); whereSql = whereSql.replaceAll(TABLE_NAME_PLACEHOLDER, tableName); - log.info("whereSql : " + whereSql); - log.info("参数 : " + whereParams); if (rs.executeQuery(whereSql, whereParams) && rs.next()) { mainId = Util.getIntValue(rs.getString(1),-1); + }else { + log.info("whereSql : " + whereSql); + log.info("参数 : " + whereParams); } } if(mainId < 0){ 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 5e53045..4a43775 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/action/PushSealTaskAction.java @@ -4,11 +4,19 @@ import aiyh.utils.Util; import aiyh.utils.action.CusBaseAction; // 基础的action,实现一些基础的参数 import aiyh.utils.annotation.RequiredMark; import aiyh.utils.excention.CustomerException; // 自定义异常类 create 2022/3/9 2:20 PM +import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSetTrans; import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; import weaver.workflow.request.RequestManager; +import weaver.xuanran.wang.common.util.CommonUtil; +import weaver.xuanran.wang.common.util.CusInfoToOAUtil; import weaver.xuanran.wang.schroeder.service.SchroederQRCodeService; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + /** *

施罗德创建二维码action

@@ -30,25 +38,53 @@ public class PushSealTaskAction extends CusBaseAction { // 基础的action, @RequiredMark private String QRCodeField; + /** + *

用印文件字段 会将这个字段所有的值存到用印文件记录表中

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

文档记录表模块id

+ **/ + @RequiredMark + private String modelId; + private final SchroederQRCodeService schroederQRCodeService = new SchroederQRCodeService(); // 施罗德业务方法 施罗德业务方法 + + @Override // action 提交流程业务处理方法 具体业务逻辑实现 public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestManager requestManager) { log.info("---------- PushSealTaskSealValue Begin " + requestId + "----------"); + RequestInfo requestInfo = requestInfoThreadLocal.get(); String scanNum = schroederQRCodeService.pushSealTask(onlyMark, billTable, requestId); // 推送数据创建任务 建模配置唯一标识 RecordSetTrans trans = requestManager.getRsTrans(); trans.setAutoCommit(false); String updateSql = "update " + billTable + " set " + QRCodeField + " = ? where requestid = ?"; // 二维码来源字段 try{ if(!trans.executeUpdate(updateSql, scanNum, requestId)){ - throw new CustomerException(Util.logStr("更新表单sql执行失败!sql : {}, 参数 scanNum : {}, requestId : {}", scanNum, requestId)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 + throw new CustomerException(Util.logStr("更新表单sql执行失败!sql : {}, 参数 scanNum : {}, requestId : {}", scanNum, requestId)); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } + // 获取明细表数据 + List> detailList = getDetailTableValueByDetailNo(1, requestInfo); + List docIds = detailList.stream() + .map(item -> Util.null2DefaultStr(item.get(fileField), "")) + .filter(StringUtils::isNotBlank).collect(Collectors.toList()); + ArrayList> list = new ArrayList<>(); + for (String docId : docIds) { + LinkedHashMap map = new LinkedHashMap<>(); + map.put("docId", docId); + map.put("enable", 0); + list.add(map); + } + // 将数据写入建模 + CusInfoToOAUtil.executeBatch(Util.getIntValue(modelId, -1), list, "select 1 from #{tableName} where docId = ?", docIds); }catch (Exception e){ trans.rollback(); throw new CustomerException(Util.logStr("执行提交方法异常:{}", e.getMessage())); // 自定义异常类 create 2022/3/9 2:20 PM 构建日志字符串 } trans.commit(); } - } 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 d4859d7..1b9dc5b 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 @@ -26,7 +26,8 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue { // 自定 @Override // 获取参数值 public Object execute(Map mainMap, Map detailMap, String currentValue, Map pathParam) { - logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam))); // 构建日志字符串 + logger.info(Util.logStr("路径参数:[{}]", JSONObject.toJSONString(pathParam))); + logger.info("路径参数(字符串拼接) : " + JSONObject.toJSONString(pathParam));// 构建日志字符串 // 接口字段 String sealSnField = pathParam.get("sealSnField"); String sealNumField = pathParam.get("sealNumField"); diff --git a/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java new file mode 100644 index 0000000..1812c4c --- /dev/null +++ b/src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java @@ -0,0 +1,45 @@ +package weaver.xuanran.wang.schroeder.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +import java.util.List; +import java.util.Map; + +/** + *

施罗德查询方法

+ * + * @Author xuanran.wang + * @Date 2022/12/13 13:05 + */ +@SqlMapper +public interface SchroederMapper { + + /** + *

查询明细一数据集

+ * @author xuanran.wang + * @dateTime 2022/12/13 13:10 + * @param tableName 表名 + * @param mainId 主表id + * @return 明细表数据集合 + **/ + @Select("select yywj,qfzzl,qfzcs from $t{tableName} where mainid = #{mainId} and sfjgqfz = 0") + List> selectSealTaskInfoList(@ParamMapper("tableName") String tableName, + @ParamMapper("mainId") String mainId); + + /** + *

查询明细一用印文件docId/h1> + * @author xuanran.wang + * @dateTime 2022/12/13 13:10 + * @param fileField 用印文件字段 + * @param tableName 表名 + * @param mainId 主表id + * @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); + +} 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 6b28b52..ad6af3b 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/service/SchroederQRCodeService.java @@ -8,16 +8,27 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.google.zxing.qrcode.encoder.QRCode; +import com.icbc.api.internal.apache.http.M; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; +import org.junit.Test; +import org.springframework.beans.BeanUtils; import weaver.conn.RecordSet; import weaver.mobile.plugin.ecology.QRCodeComInfo; import weaver.xiao.commons.config.entity.RequestMappingConfig; import weaver.xiao.commons.config.service.DealWithMapping; +import weaver.xuanran.wang.schroeder.mapper.SchroederMapper; import javax.ws.rs.core.MediaType; +import java.io.File; import java.io.IOException; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; /** *

施罗德业务方法

@@ -49,6 +60,7 @@ public class SchroederQRCodeService { { httpUtils.getGlobalCache().header.put("Content-Type", MediaType.APPLICATION_JSON); // 全局请求头 } + private final SchroederMapper schroederMapper = Util.getMapper(SchroederMapper.class); /** *

推送数据创建任务

@@ -72,7 +84,10 @@ public class SchroederQRCodeService { recordSet.executeQuery(selectMainSql, requestId); if (recordSet.next()) { dealWithMapping.setMainTable(billTable); - Map requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); // 解析请求参数配置树,转换成请求参数 + Map requestParam = dealWithMapping.getRequestParam(recordSet, requestMappingConfig); + // 如果明细数据存在骑缝章时候增加一行数据进去 + changeRequestMap(requestParam, billTable + "_dt1", recordSet.getString("id")); + // 解析请求参数配置树,转换成请求参数 log.info(Util.logStr("请求json : {}", JSONObject.toJSONString(requestParam))); // 构建日志字符串 String url = requestMappingConfig.getRequestUrl(); ResponeVo responeVo = null; @@ -111,6 +126,47 @@ public class SchroederQRCodeService { } return res; } + + /** + *

骑缝章修改请求参数

+ * @author xuanran.wang + * @dateTime 2022/12/13 14:15 + * @param requestParam 请求参数 + * @param billTable 表名 + * @param mainId 主表id + **/ + public void changeRequestMap(Map requestParam, String billTable, String mainId){ + List> files = (List>) requestParam.get("file"); + List> detail1List = schroederMapper.selectSealTaskInfoList(billTable, mainId); + if(CollectionUtils.isEmpty(detail1List) || CollectionUtils.isEmpty(files)){ + return; + } + // 遍历明细数据 + for (Map detailItem : detail1List) { + // 用印文件 + String sealFile = Util.null2String(detailItem.get("yywj")); + // 从生成的请求参数map中开始匹配 + List> filterFiles = files.stream() + .filter(item -> { + String filePath = Util.null2DefaultStr(item.get("filePath"), ""); + String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1),""); + return sealFile.equals(docId); + }) + .collect(Collectors.toList()); + if(CollectionUtils.isNotEmpty(filterFiles)){ + // 只有一个能匹配 + Map o = filterFiles.get(0); + HashMap tempMap = o.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, HashMap::new)); + // 印章集合 + HashMap seal = new HashMap<>(); + seal.put("sealSn",Util.null2DefaultStr(detailItem.get("qfzzl"),"")); + seal.put("sealNum",Util.null2DefaultStr(detailItem.get("qfzcs"),"0")); + tempMap.put("seal", seal); + files.add(tempMap); + } + } + } + } diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a7cfc61 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: aiyh.utils.Util + diff --git a/src/main/resources/WEB-INF/prop/prop2map/AmbofoADConfig.properties b/src/main/resources/WEB-INF/prop/prop2map/AmbofoADConfig.properties new file mode 100644 index 0000000..015bb4b --- /dev/null +++ b/src/main/resources/WEB-INF/prop/prop2map/AmbofoADConfig.properties @@ -0,0 +1,7 @@ +userName = SID_ECOLOGY +password = BDw5FzWQ@ +server = ldap://LDAP_ASIA.Aptiv.com:389 +driver = com.sun.jndi.ldap.LdapCtxFactory +authentication = simple +searchBase=CN=Users,DC=aptiv,DC=com +queryField=uid \ No newline at end of file diff --git a/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java new file mode 100644 index 0000000..ebc2770 --- /dev/null +++ b/src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java @@ -0,0 +1,27 @@ +package xuanran.wang.ambofo.checkuser; + +import aiyh.utils.Util; +import basetest.BaseTest; +import com.api.xuanran.wang.ambofo.checkuser.service.CheckUserService; +import org.junit.Test; + +/** + *

安波福校验用户测试类

+ * + * @Author xuanran.wang + * @Date 2022/12/12 15:35 + */ +public class CheckUserTest extends BaseTest { + + @Test + public void testProperties(){ + try{ + CheckUserService checkUserService = new CheckUserService(); + checkUserService.logAllUser(); + }catch (Exception e){ + String error = Util.logStr("AD查询接口发生异常:{}", e.getMessage()); + log.error(error); + log.error(Util.getErrString(e)); + } + } +} 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 48ef944..cfd995b 100644 --- a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java +++ b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java @@ -5,8 +5,10 @@ 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; import org.junit.Test; +import org.springframework.beans.BeanUtils; import weaver.file.ImageFileManager; import weaver.general.TimeUtil; import weaver.xuanran.wang.common.util.CommonUtil; @@ -56,7 +58,6 @@ public class DownLoadFileTest extends BaseTest { @Test public void testParseStr(){ - String str = ""; String pattern = "(?<=\\{).+(?=})"; Pattern compile = Pattern.compile(pattern); @@ -75,4 +76,82 @@ public class DownLoadFileTest extends BaseTest { } } } + + @Test + public void testAddItem(){ + String json = "{\"requestId\":\"189567\",\"super\":\"luchenghong\",\"orgNo\":\"junhe\",\"title\":\"鲁诚鸿\",\"sealPlace\":\"2\",\"useSealType\":\"1\",\"userPassword\":\"672518\",\"useSealEquipment\":\"2\",\"file\":[{\"fileName\":\"拜访函(景德镇).docx\",\"filePath\":\"http://oa.junheland.com/hyu/seal.download?docId=12\",\"waterAndSeal\":\"2\",\"crosssealType\":\"2\",\"printCount\":\"1\",\"printType\":\"0\",\"seal\":[{\"sealType\":\"124\",\"sealNum\":\"1\"}]},{\"fileName\":\"附件6-变更签证办理协议.pdf\",\"filePath\":\"http://erp.junheland.com:9070/view?docId=13\",\"waterAndSeal\":\"2\",\"crosssealType\":\"1\",\"printCount\":\"6\",\"printType\":\"1\",\"seal\":[{\"sealType\":\"164\",\"sealNum\":\"6\"}]}]}"; + Map requestParam = JSONObject.parseObject(json, Map.class); + log.info("requestParam " + requestParam); + ArrayList> detail1List = new ArrayList<>(); + HashMap map = new HashMap<>(); + // yywj,qfzzl,qfzcs + map.put("yywj","12"); + map.put("qfzzl","2"); + map.put("qfzcs","3"); + detail1List.add(map); + // 过滤出集合类型的参数 + List> files = (List>) requestParam.get("file"); + if(CollectionUtils.isNotEmpty(files)){ + // 加盖骑缝章的明细数据 + if(CollectionUtils.isNotEmpty(detail1List)){ + // 遍历明细数据 + for (Map detailItem : detail1List) { + // 用印文件 + String sealFile = Util.null2String(detailItem.get("yywj")); + log.info("sealFile : " + sealFile); + // 从生成的请求参数map中开始匹配 + List> filterFiles = files.stream() + .filter(item -> { + String filePath = Util.null2DefaultStr(item.get("filePath"), ""); + String docId = Util.null2DefaultStr(filePath.substring(filePath.lastIndexOf("=") + 1),""); + log.info("filePath : " + filePath + " , docId : " + docId); + return sealFile.equals(docId); + }) + .collect(Collectors.toList()); + log.info("filterFiles " + JSONObject.toJSONString(filterFiles)); + if(CollectionUtils.isNotEmpty(filterFiles)){ + // 只有一个能匹配 + Map o = filterFiles.get(0); + HashMap tempMap = o.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, HashMap::new)); + // 印章集合 + HashMap seal = new HashMap<>(); + seal.put("sealSn",Util.null2DefaultStr(detailItem.get("qfzzl"),"")); + seal.put("sealNum",Util.null2DefaultStr(detailItem.get("qfzcs"),"0")); + tempMap.put("seal", seal); + log.info("tempMap " + tempMap); + files.add(tempMap); + } + } + } + } + log.info("requestParam : " + JSONObject.toJSONString(requestParam) ); + } + + @Test + public void testParse(){ + String paramStr = "weaver.xuanran.wang.schroeder.cus_field_value.PushSealTaskSealValue?sealSnField=sealSn&sealNumField=sealNum&sealSnCusSql=`select\n" + + " ? from jkfdjsfk where id\n" + + " =1`&sealNumCusSql=`select case ? when 0 then htzyzcs when 1 then gzcs else frzcs end from formtable_main_22_dt1 where id = {?dt.id}`&hah=liuliu&cus=`select? * fr$%&#@!)(<>?/\\{}「」【【】[]~、asfom table where id = '' and teset = #{name}`&niua=卧槽"; + + String pattern = "&?(?([#.\\w\\u4E00-\\u9FA5]+))=" + + "(?((`([^`]*)`)|" + + "((#(\\{|sql\\{))?([():/\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(paramStr); + HashMap pathParamMap = new HashMap<>(); + while (matcher.find()) { + String key = matcher.group("key"); + String paramValue = matcher.group("value"); + if (paramValue != null && paramValue.startsWith("`") && paramValue.endsWith("`")) { + paramValue = paramValue.substring(1, paramValue.length() - 1); + } + pathParamMap.put(key, paramValue); + } + log.info("pathParamMap : " + JSONObject.toJSONString(pathParamMap)); + + String text ="123456"; + String replacement = "two$two"; + String resultString = text.replaceAll("2", replacement); + log.info("resultString " + resultString); + } }