From 1654d4f765dfceeccde791647510df034d4b2d7c Mon Sep 17 00:00:00 2001
From: wangxuanran <3055088966@qq.com>
Date: Tue, 13 Dec 2022 18:03:24 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96CusBaseAction=E4=BB=A5?=
=?UTF-8?q?=E5=8F=8A=E6=96=BD=E7=BD=97=E5=BE=B7=E4=BB=A3=E7=A0=81=E5=AE=8C?=
=?UTF-8?q?=E5=96=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/aiyh/utils/action/CusBaseAction.java | 8 +
.../controller/CheckUserController.java | 59 +++++++
.../checkuser/service/CheckUserService.java | 149 ++++++++++++++++++
.../service/DownLoadFileService.java | 2 +-
.../wang/common/util/CusInfoToOAUtil.java | 28 +++-
.../schroeder/action/PushSealTaskAction.java | 40 ++++-
.../PushSealTaskSealValue.java | 3 +-
.../schroeder/mapper/SchroederMapper.java | 45 ++++++
.../service/SchroederQRCodeService.java | 58 ++++++-
src/main/resources/META-INF/MANIFEST.MF | 3 +
.../prop/prop2map/AmbofoADConfig.properties | 7 +
.../wang/ambofo/checkuser/CheckUserTest.java | 27 ++++
.../download_file/DownLoadFileTest.java | 81 +++++++++-
13 files changed, 502 insertions(+), 8 deletions(-)
create mode 100644 src/main/java/com/api/xuanran/wang/ambofo/checkuser/controller/CheckUserController.java
create mode 100644 src/main/java/com/api/xuanran/wang/ambofo/checkuser/service/CheckUserService.java
create mode 100644 src/main/java/weaver/xuanran/wang/schroeder/mapper/SchroederMapper.java
create mode 100644 src/main/resources/META-INF/MANIFEST.MF
create mode 100644 src/main/resources/WEB-INF/prop/prop2map/AmbofoADConfig.properties
create mode 100644 src/test/java/xuanran/wang/ambofo/checkuser/CheckUserTest.java
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