From da145d2d3203cd4680e4a2a7d82ec9ce39215945 Mon Sep 17 00:00:00 2001 From: "youhong.ai" Date: Fri, 16 Jun 2023 18:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E6=97=B6=E6=8D=B7=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E5=AE=9A=E4=BD=8Daciton=EF=BC=8C=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../annotation/recordset/ToLowerCase.java | 16 ++ .../utils/fileUtil/WordKeywordFinder.java | 86 ++++++++++ .../java/aiyh/utils/function/Bi4Function.java | 2 +- .../aiyh/utils/httpUtil/util/HttpUtils.java | 93 ++++++++--- .../aiyh/utils/recordset/ResultMapper.java | 138 ++++++++++------ .../orgchart/service/OrgChartService.java | 5 +- .../CheckWorkflowRequestParamsMapper.java | 7 +- .../pojo/CheckCreateConfig.java | 4 +- .../pojo/CheckCreateConfigDetail.java | 6 +- .../CheckCreateRequestCustomerInterface.java | 22 +++ .../util/CheckFunctionParam.java | 29 ++++ .../util/CheckRuleMethodUtil.java | 156 +++++++++++++----- .../util/CheckWorkflowRequestParamsUtil.java | 83 +++++++++- .../LocationKeywordAction.java | 119 +++++++++++++ .../mapper/LocationKeywordMapper.java | 14 ++ .../java/youhong/ai/utiltest/GenericTest.java | 3 + .../java/youhong/ai/utiltest/TestApi.java | 39 ++++- .../ai/utiltest/{ => excel}/ExcelBody.java | 4 +- .../ai/utiltest/{ => excel}/ExcelCell.java | 2 +- .../ai/utiltest/{ => excel}/ExcelHead.java | 2 +- .../ai/utiltest/{ => excel}/ExcelPort.java | 2 +- .../ai/utiltest/{ => excel}/ExcelRow.java | 2 +- .../ai/utiltest/{ => excel}/ExcelSheet.java | 2 +- .../{ => excel}/IExcelCellStyleCreator.java | 2 +- .../youhong/ai/utiltest/wordread/Main.java | 32 ++++ .../utiltest/wordread/WordKeywordFinder.java | 67 ++++++++ 26 files changed, 797 insertions(+), 140 deletions(-) create mode 100644 src/main/java/aiyh/utils/annotation/recordset/ToLowerCase.java create mode 100644 src/main/java/aiyh/utils/fileUtil/WordKeywordFinder.java create mode 100644 src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckCreateRequestCustomerInterface.java create mode 100644 src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckFunctionParam.java create mode 100644 src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/LocationKeywordAction.java create mode 100644 src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/mapper/LocationKeywordMapper.java rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelBody.java (70%) rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelCell.java (90%) rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelHead.java (87%) rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelPort.java (98%) rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelRow.java (89%) rename src/test/java/youhong/ai/utiltest/{ => excel}/ExcelSheet.java (89%) rename src/test/java/youhong/ai/utiltest/{ => excel}/IExcelCellStyleCreator.java (94%) create mode 100644 src/test/java/youhong/ai/utiltest/wordread/Main.java create mode 100644 src/test/java/youhong/ai/utiltest/wordread/WordKeywordFinder.java diff --git a/src/main/java/aiyh/utils/annotation/recordset/ToLowerCase.java b/src/main/java/aiyh/utils/annotation/recordset/ToLowerCase.java new file mode 100644 index 0000000..bc7406a --- /dev/null +++ b/src/main/java/aiyh/utils/annotation/recordset/ToLowerCase.java @@ -0,0 +1,16 @@ +package aiyh.utils.annotation.recordset; + +import java.lang.annotation.*; + +/** + *

小写键

+ * + *

create: 2023/6/16 13:02

+ * + * @author youHong.ai + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Documented +public @interface ToLowerCase { +} diff --git a/src/main/java/aiyh/utils/fileUtil/WordKeywordFinder.java b/src/main/java/aiyh/utils/fileUtil/WordKeywordFinder.java new file mode 100644 index 0000000..50f5ba8 --- /dev/null +++ b/src/main/java/aiyh/utils/fileUtil/WordKeywordFinder.java @@ -0,0 +1,86 @@ +package aiyh.utils.fileUtil; + +import aiyh.utils.excention.CustomerException; +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.extractor.WordExtractor; +import org.apache.poi.xwpf.extractor.XWPFWordExtractor; +import org.apache.poi.xwpf.usermodel.XWPFDocument; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + *

word关键字查找

+ * + * @author ebu7-dev1 youhong.ai + */ +public class WordKeywordFinder { + + /** + *

查找关键字

+ * + * @param inputStream 文件流 + * @param keyword 关键字 + * @param fileName 文件名称 + * @return 关键字信息 + * @throws IOException io异常 + */ + public static List findKeywords(InputStream inputStream, String keyword, String fileName) { + try { + List keywordLocations = new ArrayList<>(); + if (fileName.endsWith(".docx")) { + XWPFDocument docx = new XWPFDocument(inputStream); + XWPFWordExtractor extractor = new XWPFWordExtractor(docx); + String text = extractor.getText(); + String[] paragraphs = text.split("\n"); + for (int i = 0; i < paragraphs.length; i++) { + String paragraph = paragraphs[i]; + if (paragraph.contains(keyword)) { + keywordLocations.add(new KeywordLocation(keyword, i + 1)); + } + } + extractor.close(); + docx.close(); + } else if (fileName.endsWith(".doc")) { + HWPFDocument doc = new HWPFDocument(inputStream); + WordExtractor extractor = new WordExtractor(doc); + String text = extractor.getText(); + String[] paragraphs = text.split("\n"); + for (int i = 0; i < paragraphs.length; i++) { + String paragraph = paragraphs[i]; + if (paragraph.contains(keyword)) { + keywordLocations.add(new KeywordLocation(keyword, i + 1)); + } + } + extractor.close(); + doc.close(); + } else { + throw new IllegalArgumentException("Unsupported file format: " + fileName); + } + + return keywordLocations; + } catch (Exception e) { + throw new CustomerException(e); + } + } + + public static class KeywordLocation { + private final String keyword; + private final int paragraphNumber; + + public KeywordLocation(String keyword, int paragraphNumber) { + this.keyword = keyword; + this.paragraphNumber = paragraphNumber; + } + + public String getKeyword() { + return keyword; + } + + public int getParagraphNumber() { + return paragraphNumber; + } + } +} diff --git a/src/main/java/aiyh/utils/function/Bi4Function.java b/src/main/java/aiyh/utils/function/Bi4Function.java index efd9a3c..7a19c8c 100644 --- a/src/main/java/aiyh/utils/function/Bi4Function.java +++ b/src/main/java/aiyh/utils/function/Bi4Function.java @@ -1,7 +1,7 @@ package aiyh.utils.function; /** - *

三个参数的function

+ *

四个参数的function

* *

create: 2023/6/14 21:30

* diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java index bc39ea2..77ea7c8 100644 --- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java +++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java @@ -84,7 +84,7 @@ public class HttpUtils { } public HttpUtils() { - + } public void setCredentialsProvider(CredentialsProvider credentialsProvider) { @@ -215,7 +215,7 @@ public class HttpUtils { httpUtilParamInfo.setParams(params); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpGet); } @@ -244,7 +244,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpDelete); } @@ -274,7 +274,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpGet); } @@ -296,7 +296,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpDelete); } @@ -318,7 +318,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpGet); } @@ -350,7 +350,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } return baseRequest(httpConnection, httpDelete); } @@ -381,7 +381,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } callBackRequest(httpConnection, httpGet, consumer); } @@ -412,7 +412,7 @@ public class HttpUtils { httpUtilParamInfo.setUrl(getUrl.trim()); HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.set(httpUtilParamInfo); } catch (Exception ignore) { - + } callBackRequest(httpConnection, httpDelete, consumer); } @@ -708,7 +708,7 @@ public class HttpUtils { SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat))); } catch (Exception ignore) { - + } HTTP_UTIL_PARAM_INFO_THREAD_LOCAL.remove(); ExtendedIOUtils.closeQuietly(httpClient); @@ -755,7 +755,7 @@ public class HttpUtils { SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat))); } catch (Exception ignore) { - + } ExtendedIOUtils.closeQuietly(httpClient); ExtendedIOUtils.closeQuietly(response); @@ -793,7 +793,7 @@ public class HttpUtils { SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat))); } catch (Exception ignore) { - + } } catch (Exception e) { log.error(" http调用失败:" + Util.getErrString(e)); @@ -805,7 +805,7 @@ public class HttpUtils { SerializerFeature.PrettyFormat, SerializerFeature.WriteDateUseDateFormat))); } catch (Exception ignore) { - + } throw e; } finally { @@ -1066,9 +1066,18 @@ public class HttpUtils { List nvps = new ArrayList<>(); for (Map.Entry entry : params.entrySet()) { // nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); - // 修复请求form表单提交时,参数值被双引号括了起来 - nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + // nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + /* ******************* 修改参数转换为string的逻辑,如果是对象则进行json序列化 youhong.ai 20230616 ******************* */ + if (entry.getValue() instanceof Map) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (entry.getValue() instanceof Collection) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (isBean(entry.getValue())) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else { + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + } } httpPost.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); @@ -1076,11 +1085,19 @@ public class HttpUtils { List nvps = new ArrayList<>(); for (Map.Entry entry : params.entrySet()) { // nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); - // 修复请求form表单提交时,参数值被双引号括了起来 - nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + /* ******************* 修改参数转换为string的逻辑,如果是对象则进行json序列化 youhong.ai 20230616 ******************* */ + if (entry.getValue() instanceof Map) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (entry.getValue() instanceof Collection) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (isBean(entry.getValue())) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else { + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + } } - httpPost.setEntity(new UrlEncodedFormEntity(nvps)); + httpPost.setEntity(new UrlEncodedFormEntity(nvps, DEFAULT_ENCODING)); // } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) { } else { StringEntity stringEntity; @@ -1095,6 +1112,22 @@ public class HttpUtils { return httpPost; } + private boolean isBean(Object o) { + if (o instanceof Number) { + return false; + } + if (o instanceof String) { + return false; + } + if (o instanceof Boolean) { + return false; + } + if (Objects.isNull(o)) { + return false; + } + return !o.getClass().isPrimitive(); + } + private HttpPost handleHttpPost(String url, Map headerMap, Map paramsMap) throws UnsupportedEncodingException { return handleHttpPostObject(url, headerMap, paramsMap); } @@ -1261,7 +1294,17 @@ public class HttpUtils { for (Map.Entry entry : paramsMap.entrySet()) { // nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); // 修复请求form表单提交时,参数值被双引号括了起来 - nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + // nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + /* ******************* 修改参数转换为string的逻辑,如果是对象则进行json序列化 youhong.ai 20230616 ******************* */ + if (entry.getValue() instanceof Map) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (entry.getValue() instanceof Collection) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (isBean(entry.getValue())) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else { + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + } } httpPut.setHeader("Content-Type", HttpArgsType.DEFAULT_CONTENT_TYPE); httpPut.setEntity(new UrlEncodedFormEntity(nvps)); @@ -1270,7 +1313,17 @@ public class HttpUtils { for (Map.Entry entry : paramsMap.entrySet()) { // nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); // 修复请求form表单提交时,参数值被双引号括了起来 - nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + // nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + /* ******************* 修改参数转换为string的逻辑,如果是对象则进行json序列化 youhong.ai 20230616 ******************* */ + if (entry.getValue() instanceof Map) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (entry.getValue() instanceof Collection) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else if (isBean(entry.getValue())) { + nvps.add(new BasicNameValuePair(entry.getKey(), JSON.toJSONString(entry.getValue()))); + } else { + nvps.add(new BasicNameValuePair(entry.getKey(), Util.null2String(entry.getValue()))); + } } httpPut.setEntity(new UrlEncodedFormEntity(nvps)); } else if (contentType.toUpperCase().startsWith(HttpArgsType.APPLICATION_JSON.toUpperCase())) { diff --git a/src/main/java/aiyh/utils/recordset/ResultMapper.java b/src/main/java/aiyh/utils/recordset/ResultMapper.java index c25e24e..c5305cf 100644 --- a/src/main/java/aiyh/utils/recordset/ResultMapper.java +++ b/src/main/java/aiyh/utils/recordset/ResultMapper.java @@ -312,44 +312,60 @@ public class ResultMapper { try { if (o instanceof Map) { + ToLowerCase toLowerCase = method.getAnnotation(ToLowerCase.class); for (int i = 0; i < columnName.length; i++) { String columnType = columnTypeName[i]; if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) { - if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); - continue; + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); + } else { + if (enable) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); + continue; + } + if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); + } + ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getInt(i + 1)); + ((Map) o).put(columnName[i], rs.getInt(i + 1)); } - if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); - } - ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getInt(i + 1)); - ((Map) o).put(columnName[i], rs.getInt(i + 1)); continue; } if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) { + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1)); + } else { + if (enable) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1)); + continue; + } + if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1)); + } + ((Map) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getFloat(i + 1)); + ((Map) o).put(columnName[i], rs.getFloat(i + 1)); + } + continue; + } + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + } else { if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1)); + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); continue; } if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getFloat(i + 1)); + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); } - ((Map) o).put(columnName[i].toLowerCase(), rs.getFloat(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getFloat(i + 1)); - ((Map) o).put(columnName[i], rs.getFloat(i + 1)); - continue; + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i], rs.getString(i + 1)); } - if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); - continue; - } - if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); - } - ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i], rs.getString(i + 1)); continue; } return o; @@ -451,6 +467,7 @@ public class ResultMapper { try { if (o instanceof Map) { + ToLowerCase toLowerCase = method.getAnnotation(ToLowerCase.class); for (int i = 0; i < columnName.length; i++) { String columnType = ""; if (i >= columnTypeName.length) { @@ -459,29 +476,39 @@ public class ResultMapper { columnType = columnTypeName[i]; } if ("int".equalsIgnoreCase(columnType) || "long".equalsIgnoreCase(columnType) || "number".equalsIgnoreCase(columnType) || "MEDIUMINT".equalsIgnoreCase(columnType) || "TINYINT".equalsIgnoreCase(columnType) || "SMALLINT".equalsIgnoreCase(columnType) || "BIGINT".equalsIgnoreCase(columnType) || "INTEGER".equalsIgnoreCase(columnType)) { - if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(columnName[i])); - continue; + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); + } else { + if (enable) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(columnName[i])); + continue; + } + if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); + } + ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getInt(i + 1)); + ((Map) o).put(columnName[i], rs.getInt(i + 1)); } - if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getInt(i + 1)); - } - ((Map) o).put(columnName[i].toLowerCase(), rs.getInt(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getInt(i + 1)); - ((Map) o).put(columnName[i], rs.getInt(i + 1)); continue; } if ("FLOAT".equalsIgnoreCase(columnType) || "DOUBLE".equalsIgnoreCase(columnType) || "DECIMAL".equalsIgnoreCase(columnType)) { - if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); - continue; + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + } else { + if (enable) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); + continue; + } + if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); + } + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i], rs.getString(i + 1)); } - if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); - } - ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i], rs.getString(i + 1)); continue; } if (method.isAnnotationPresent(Associations.class)) { @@ -506,16 +533,23 @@ public class ResultMapper { } } } - if (enable) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); - continue; + + if (Objects.nonNull(toLowerCase)) { + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + } else { + if (enable) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(columnName[i])); + continue; + } + if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { + ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); + } + ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); + ((Map) o).put(columnName[i], rs.getString(i + 1)); + } - if (DBConstant.DB_TYPE_ORACLE.equals(rs.getDBType())) { - ((Map) o).put(Util.toCamelCase(columnName[i]), rs.getString(i + 1)); - } - ((Map) o).put(columnName[i].toLowerCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i].toUpperCase(), rs.getString(i + 1)); - ((Map) o).put(columnName[i], rs.getString(i + 1)); + } return o; } diff --git a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java index b4606e3..6f5519e 100644 --- a/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java +++ b/src/main/java/com/api/youhong/ai/pcn/organization/orgchart/service/OrgChartService.java @@ -50,7 +50,10 @@ public class OrgChartService { /* ******************* 次账号处理逻辑 ******************* */ String accountType = logInUser.getAccount_type(); if ("1".equals(accountType)) { - return secondaryAccountTree(hrmResourceDtoList); + // 对当前账号过滤当前分部信息 + List collect = hrmResourceDtoList.stream().filter(item -> logInUser.getUserSubCompany1() == item.getSubCompanyId()) + .collect(Collectors.toList()); + return secondaryAccountTree(collect); } filterCurrentSubCom(hrmResourceDtoList, currentUser, logInUser); /* ******************* 查询当前用户的是否全部展示或显示小红点的配置信息 ******************* */ diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/mapper/CheckWorkflowRequestParamsMapper.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/mapper/CheckWorkflowRequestParamsMapper.java index f13c335..effce62 100644 --- a/src/main/java/com/customization/youhong/pcn/createrworkflow/mapper/CheckWorkflowRequestParamsMapper.java +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/mapper/CheckWorkflowRequestParamsMapper.java @@ -20,7 +20,7 @@ import java.util.Map; public interface CheckWorkflowRequestParamsMapper { - @Select("select * from table where workflow_type = #{workflowId}") + @Select("select * from uf_check_request_create where workflow_type = #{workflowId}") @CollectionMappings({ @CollectionMapping( property = "detailList", @@ -36,7 +36,7 @@ public interface CheckWorkflowRequestParamsMapper { CheckCreateConfig selectCheckConfig(int workflowId); - @Select("select * from table_dt1 where mainid = #{mainId}") + @Select("select * from uf_check_request_create_dt1 where mainid = #{mainId}") @Associations({ @Association( property = "workflowField", @@ -49,12 +49,13 @@ public interface CheckWorkflowRequestParamsMapper { List selectCheckDetail(String mainId); - @Select("select * from table_dt2 where mainid = #{mainId}") + @Select("select * from uf_check_request_create_dt2 where mainid = #{mainId}") @CollectionMethod(value = 2, desc = "查询明细表2,条件配置参数") List selectConditionDetail(String mainId); @Select(custom = true) + @ToLowerCase Map selectCustomerSql(@SqlString String sql, @ParamMapper("value") String value, @ParamMapper("user") User user); diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfig.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfig.java index 2763cc5..a4e6b5e 100644 --- a/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfig.java +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfig.java @@ -18,10 +18,10 @@ import java.util.List; @ToString public class CheckCreateConfig { /** 流程id */ - private Integer workflowId; + private Integer workflowType; /** 描述 */ - private String desc; + private String description; /** 检查配置明细 */ private List detailList; diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfigDetail.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfigDetail.java index 01f38a7..e6e39ae 100644 --- a/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfigDetail.java +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/pojo/CheckCreateConfigDetail.java @@ -23,11 +23,11 @@ public class CheckCreateConfigDetail { /** 流程字段 */ private FieldViewInfo workflowField; - /** 是否允许为null */ - private String allowNull; + /** 错误提示消息 */ + private String errorMsg; /** 校验规则 */ - private String checkRule; + private Integer checkRule; /** 自定义值 */ private String customerValue; diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckCreateRequestCustomerInterface.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckCreateRequestCustomerInterface.java new file mode 100644 index 0000000..d8ef36f --- /dev/null +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckCreateRequestCustomerInterface.java @@ -0,0 +1,22 @@ +package com.customization.youhong.pcn.createrworkflow.util; + +import java.util.Map; + +/** + *

自定义校验接口

+ * + *

create: 2023/6/15 19:59

+ * + * @author youHong.ai + */ +public interface CheckCreateRequestCustomerInterface { + + /** + *

自定义检查方法接口

+ * + * @param checkFunctionParam 检查方法参数 + * @param pathParam 路径参数 + * @return 是否符合条件 + */ + boolean check(CheckFunctionParam checkFunctionParam, Map pathParam); +} diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckFunctionParam.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckFunctionParam.java new file mode 100644 index 0000000..e17ffcf --- /dev/null +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckFunctionParam.java @@ -0,0 +1,29 @@ +package com.customization.youhong.pcn.createrworkflow.util; + +import com.customization.youhong.pcn.createrworkflow.pojo.CheckConditionItem; +import com.customization.youhong.pcn.createrworkflow.pojo.CheckCreateConfigDetail; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import weaver.hrm.User; +import weaver.workflow.webservices.WorkflowRequestTableField; + +import java.util.Map; + +/** + *

检查方法参数实体

+ * + *

create: 2023/6/15 15:24

+ * + * @author youHong.ai + */ +@Getter +@Setter +@ToString +public class CheckFunctionParam { + private WorkflowRequestTableField workflowRequestTableField; + private CheckCreateConfigDetail checkCreateConfigDetail; + private Map checkConditionMap; + private User user; + private CheckConditionItem checkConditionItem; +} diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckRuleMethodUtil.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckRuleMethodUtil.java index dc65634..8c83117 100644 --- a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckRuleMethodUtil.java +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckRuleMethodUtil.java @@ -3,7 +3,6 @@ package com.customization.youhong.pcn.createrworkflow.util; import aiyh.utils.ScriptUtil; import aiyh.utils.Util; import aiyh.utils.annotation.MethodRuleNo; -import aiyh.utils.function.Bi4Function; import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; import aiyh.utils.tool.cn.hutool.core.util.StrUtil; import com.customization.youhong.pcn.createrworkflow.mapper.CheckWorkflowRequestParamsMapper; @@ -13,11 +12,9 @@ import org.apache.log4j.Logger; import weaver.hrm.User; import weaver.workflow.webservices.WorkflowRequestTableField; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.function.Function; /** *

检查方法校验工具

@@ -28,17 +25,11 @@ import java.util.Map; */ public class CheckRuleMethodUtil { - private static final Logger log = Util.getLogger(); + private static final Logger log = Util.getLogger("workflow"); private static final CheckWorkflowRequestParamsMapper MAPPER = Util.getMapper(CheckWorkflowRequestParamsMapper.class); public static final Map + Function > CHECK_RULE_MAP = new HashMap<>(8); static { @@ -46,14 +37,14 @@ public class CheckRuleMethodUtil { Class checkRuleMethodUtilClass = CheckRuleMethodUtil.class; Method[] methods = checkRuleMethodUtilClass.getDeclaredMethods(); for (Method method : methods) { - if (method.isAnnotationPresent(MethodRuleNo.class)) { MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class); int value = annotation.value(); - CHECK_RULE_MAP.put(value, (workflowRequestTableField, checkCreateConfigDetail, checkConditionItem, user) -> { + CHECK_RULE_MAP.put(value, (checkFunctionParam) -> { try { - return (Boolean) method.invoke(null, workflowRequestTableField, checkCreateConfigDetail, checkConditionItem, user); - } catch (IllegalAccessException | InvocationTargetException e) { + return (Boolean) method.invoke(null, checkFunctionParam); + } catch (Exception e) { + log.error("调用CheckRuleMethodUtil类中注解方法失败!" + Util.getErrString(e)); throw new RuntimeException(e); } }); @@ -62,21 +53,18 @@ public class CheckRuleMethodUtil { } catch (Exception e) { log.error("初始化CheckRuleMethodUtil失败!" + Util.getErrString(e)); } - } @MethodRuleNo(value = 0, desc = "不为null") - public static boolean noNull(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean noNull(CheckFunctionParam checkFunctionParam) { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); return StrUtil.isNotBlank(workflowRequestTableField.getFieldValue()); } @MethodRuleNo(value = 1, desc = "整数类型") - public static boolean isNumber(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean isNumber(CheckFunctionParam checkFunctionParam) { try { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); Integer.parseInt(workflowRequestTableField.getFieldValue()); return true; } catch (Exception e) { @@ -85,9 +73,8 @@ public class CheckRuleMethodUtil { } @MethodRuleNo(value = 2, desc = "小数类型") - public static boolean isDouble(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean isDouble(CheckFunctionParam checkFunctionParam) { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); try { Double.parseDouble(workflowRequestTableField.getFieldValue()); return true; @@ -97,11 +84,15 @@ public class CheckRuleMethodUtil { } @MethodRuleNo(value = 3, desc = "枚举值") - public static boolean isEnumerate(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean isEnumerate(CheckFunctionParam checkFunctionParam) { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); String fieldValue = workflowRequestTableField.getFieldValue(); String customerValue = checkCreateConfigDetail.getCustomerValue(); + CheckConditionItem checkConditionItem = checkFunctionParam.getCheckConditionItem(); + if (Objects.nonNull(checkConditionItem)) { + customerValue = checkConditionItem.getCustomerValue(); + } if (StrUtil.isNotBlank(customerValue)) { String[] split = customerValue.split(","); return Arrays.asList(split).contains(fieldValue); @@ -110,21 +101,36 @@ public class CheckRuleMethodUtil { } @MethodRuleNo(value = 4, desc = "自定义sql存在值") - public static boolean customerSqlHasValue(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean customerSqlHasValue(CheckFunctionParam checkFunctionParam) { + CheckConditionItem checkConditionItem = checkFunctionParam.getCheckConditionItem(); + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); + User user = checkFunctionParam.getUser(); String fieldValue = workflowRequestTableField.getFieldValue(); - String customerValue = checkCreateConfigDetail.getCustomerValue(); + String customerValue; + if (Objects.nonNull(checkConditionItem)) { + // 条件组调用方法 + customerValue = checkConditionItem.getCustomerValue(); + } else { + customerValue = checkCreateConfigDetail.getCustomerValue(); + } Map map = MAPPER.selectCustomerSql(customerValue, fieldValue, user); return CollectionUtil.isNotEmpty(map); } @MethodRuleNo(value = 5, desc = "自定义sql校验表达式") - public static boolean customerSqlCheck(WorkflowRequestTableField workflowRequestTableField, - CheckCreateConfigDetail checkCreateConfigDetail, - CheckConditionItem checkConditionItem, User user) { + private static boolean customerSqlCheck(CheckFunctionParam checkFunctionParam) { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); + User user = checkFunctionParam.getUser(); String fieldValue = workflowRequestTableField.getFieldValue(); - String customerValue = checkCreateConfigDetail.getCustomerValue(); + CheckConditionItem checkConditionItem = checkFunctionParam.getCheckConditionItem(); + String customerValue; + if (Objects.nonNull(checkConditionItem)) { + customerValue = checkConditionItem.getCustomerValue(); + } else { + customerValue = checkCreateConfigDetail.getCustomerValue(); + } Map map = MAPPER.selectCustomerSql(customerValue, fieldValue, user); if (CollectionUtil.isNotEmpty(map)) { String checkExpression = checkCreateConfigDetail.getCheckExpression(); @@ -136,4 +142,78 @@ public class CheckRuleMethodUtil { } + @MethodRuleNo(value = 6, desc = "自定义表达式") + private static boolean checkCustomerExpression(CheckFunctionParam checkFunctionParam) { + WorkflowRequestTableField workflowRequestTableField = checkFunctionParam.getWorkflowRequestTableField(); + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); + String fieldValue = workflowRequestTableField.getFieldValue(); + CheckConditionItem checkConditionItem = checkFunctionParam.getCheckConditionItem(); + String checkExpression; + if (Objects.nonNull(checkConditionItem)) { + checkExpression = checkConditionItem.getCustomerValue(); + } else { + checkExpression = checkCreateConfigDetail.getCheckExpression(); + } + Map map = new HashMap<>(8); + map.put("value", fieldValue); + if (StrUtil.isNotBlank(checkExpression)) { + return (Boolean) ScriptUtil.invokeScript(checkExpression, map); + } else { + return false; + } + } + + @MethodRuleNo(value = 7, desc = "自定义条件组") + private static boolean checkCustomerConditionGroup(CheckFunctionParam checkFunctionParam) { + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); + Map checkConditionMap = checkFunctionParam.getCheckConditionMap(); + String customerValue = checkCreateConfigDetail.getCheckExpression(); + String replace = customerValue.replace("(", " ") + .replace(")", " "); + String[] groups = replace.split(" "); + List groupList = new ArrayList<>(); + for (String group : groups) { + if (StrUtil.isBlank(group) || "and".equalsIgnoreCase(group) || "or".equalsIgnoreCase(group)) { + continue; + } + if ("||".equalsIgnoreCase(group) || "&&".equalsIgnoreCase(group)) { + continue; + } + groupList.add(group); + } + if (CollectionUtil.isEmpty(groupList)) { + return false; + } + Map conditionMap = new HashMap<>(8); + for (String groupName : groupList) { + CheckConditionItem checkConditionItem = checkConditionMap.get(groupName); + checkFunctionParam.setCheckConditionItem(checkConditionItem); + Function checkFunctionParamBooleanFunction = CHECK_RULE_MAP.get(checkConditionItem.getConditionRule()); + if (Objects.nonNull(checkFunctionParamBooleanFunction)) { + Boolean check = checkFunctionParamBooleanFunction.apply(checkFunctionParam); + conditionMap.put(groupName, check); + } + } + String checkExpression = checkCreateConfigDetail.getCheckExpression(); + if (StrUtil.isNotBlank(checkExpression)) { + return (Boolean) ScriptUtil.invokeScript(checkExpression, conditionMap); + } + return false; + } + + + @MethodRuleNo(value = 8, desc = "自定义校验") + private static boolean checkCustomerInterface(CheckFunctionParam checkFunctionParam) { + CheckCreateConfigDetail checkCreateConfigDetail = checkFunctionParam.getCheckCreateConfigDetail(); + String customerValue = checkCreateConfigDetail.getCustomerValue(); + CheckConditionItem checkConditionItem = checkFunctionParam.getCheckConditionItem(); + if (Objects.nonNull(checkConditionItem)) { + customerValue = checkConditionItem.getCustomerValue(); + } + Map map = Util.parseCusInterfacePathParam(customerValue); + String classPath = map.remove("_ClassPath"); + CheckCreateRequestCustomerInterface instance = Util.getClassInstance(classPath, CheckCreateRequestCustomerInterface.class); + return instance.check(checkFunctionParam, map); + } + } diff --git a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckWorkflowRequestParamsUtil.java b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckWorkflowRequestParamsUtil.java index e4eeca4..8165b72 100644 --- a/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckWorkflowRequestParamsUtil.java +++ b/src/main/java/com/customization/youhong/pcn/createrworkflow/util/CheckWorkflowRequestParamsUtil.java @@ -8,13 +8,14 @@ import com.customization.youhong.pcn.createrworkflow.pojo.CheckConditionItem; import com.customization.youhong.pcn.createrworkflow.pojo.CheckCreateConfig; import com.customization.youhong.pcn.createrworkflow.pojo.CheckCreateConfigDetail; import com.engine.workflow.entity.publicApi.ReqOperateRequestEntity; +import com.engine.workflow.entity.publicApi.WorkflowDetailTableInfoEntity; +import org.apache.log4j.Logger; import weaver.hrm.User; import weaver.workflow.webservices.WorkflowRequestTableField; +import weaver.workflow.webservices.WorkflowRequestTableRecord; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -28,6 +29,7 @@ public class CheckWorkflowRequestParamsUtil { private final CheckWorkflowRequestParamsMapper mapper = Util.getMapper(CheckWorkflowRequestParamsMapper.class); + private final Logger log = Util.getLogger("workflow"); /** * ************************************************************ @@ -70,15 +72,80 @@ public class CheckWorkflowRequestParamsUtil { value -> value ) ); - checkMainData(checkDetailMap, checkConditionItemMap, requestParam); + // 校验主表数据 + checkMainData(checkDetailMap, checkConditionItemMap, requestParam, user); + // 校验明细表参数 + checkDetailData(checkDetailMap, checkConditionItemMap, requestParam, user); + if (CollectionUtil.isNotEmpty(checkDetailMap)) { + List required = new ArrayList<>(); + for (Map.Entry entry : checkDetailMap.entrySet()) { + required.add(entry.getKey()); + } + throw new CreateRequestException(Util.logStr("必填参数校验未通过,[{}]字段必填!", Util.join(required, ","))); + } } + /** + *

校验主表数据

+ * + * @param checkDetailMap 校验规则map + * @param checkConditionItemMap 校验自定义条件组map + * @param requestParam 流程参数 + * @param user 用户 + */ private void checkMainData(Map checkDetailMap, Map checkConditionItemMap, - ReqOperateRequestEntity requestParam) { + ReqOperateRequestEntity requestParam, User user) { List mainData = requestParam.getMainData(); - for (WorkflowRequestTableField mainDatum : mainData) { - String fieldName = mainDatum.getFieldName(); + checkData(checkDetailMap, checkConditionItemMap, mainData, user, "主表"); + } + + private void checkDetailData(Map checkDetailMap, + Map checkConditionItemMap, + ReqOperateRequestEntity requestParam, User user) { + List detailData = requestParam.getDetailData(); + if (CollectionUtil.isEmpty(detailData)) { + return; + } + for (WorkflowDetailTableInfoEntity detailDatum : detailData) { + WorkflowRequestTableRecord[] workflowRequestTableRecords = detailDatum.getWorkflowRequestTableRecords(); + if (Objects.isNull(workflowRequestTableRecords)) { + continue; + } + for (WorkflowRequestTableRecord workflowRequestTableRecord : workflowRequestTableRecords) { + WorkflowRequestTableField[] workflowRequestTableFields = workflowRequestTableRecord.getWorkflowRequestTableFields(); + if (Objects.isNull(workflowRequestTableFields)) { + continue; + } + List dataList + = Arrays.asList(workflowRequestTableFields); + checkData(checkDetailMap, checkConditionItemMap, dataList, user, detailDatum.getTableDBName()); + } + } + } + + private void checkData(Map checkDetailMap, + Map checkConditionItemMap, + List dataList, User user, String tableDesc) { + for (WorkflowRequestTableField dataItem : dataList) { + String fieldName = dataItem.getFieldName(); + CheckCreateConfigDetail checkCreateConfigDetail = checkDetailMap.get(fieldName); + if (Objects.isNull(checkCreateConfigDetail)) { + continue; + } + checkDetailMap.remove(fieldName); + CheckFunctionParam checkFunctionParam = new CheckFunctionParam(); + checkFunctionParam.setCheckCreateConfigDetail(checkCreateConfigDetail); + checkFunctionParam.setCheckConditionMap(checkConditionItemMap); + checkFunctionParam.setUser(user); + checkFunctionParam.setWorkflowRequestTableField(dataItem); + Integer checkRule = checkCreateConfigDetail.getCheckRule(); + Function function = CheckRuleMethodUtil.CHECK_RULE_MAP.get(checkRule); + Boolean apply = function.apply(checkFunctionParam); + if (!apply) { + throw new CreateRequestException(Util.logStr("[{}] 表数据校验未通过,字段[{}],错误信息[{}]", + tableDesc, fieldName, checkCreateConfigDetail.getErrorMsg())); + } } } } diff --git a/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/LocationKeywordAction.java b/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/LocationKeywordAction.java new file mode 100644 index 0000000..ad57fcf --- /dev/null +++ b/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/LocationKeywordAction.java @@ -0,0 +1,119 @@ +package weaver.youhong.ai.pcn.actioin.locationkeyword; + +import aiyh.utils.Util; +import aiyh.utils.action.SafeCusBaseAction; +import aiyh.utils.annotation.ActionDefaultTestValue; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.ActionOptionalParam; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.entity.DocImageInfo; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.fileUtil.WordKeywordFinder; +import aiyh.utils.fileUtil.pdf.PdfPointItem; +import aiyh.utils.fileUtil.pdf.PdfUtil; +import aiyh.utils.mapper.UtilMapper; +import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; +import aiyh.utils.tool.cn.hutool.core.util.StrUtil; +import lombok.Setter; +import weaver.file.ImageFileManager; +import weaver.hrm.User; +import weaver.soa.workflow.request.RequestInfo; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + *

定位查找关键字

+ * + *

create: 2023/6/16 16:38

+ * + * @author youHong.ai + */ +@Setter +@ActionDesc(author = "youhong.ai", value = "word文件和pdf文件关键字识别,是否存在关键字") +public class LocationKeywordAction extends SafeCusBaseAction { + + @RequiredMark(desc = "关键字,多个关键字之间使用;分割") + @ActionDefaultTestValue("盖章关键字;日期关键字") + private String keywords; + + @RequiredMark(desc = "附件字段字段名") + @ActionDefaultTestValue("fj") + private String docField; + + @ActionOptionalParam(value = "false", desc = "报错是否自动退回") + @ActionDefaultTestValue("false") + private String isBack = "false"; + + + private final UtilMapper mapper = Util.getMapper(UtilMapper.class); + + + @Override + public void doSubmit(String requestId, String billTable, int workflowId, User user, RequestInfo requestInfo) { + + Map mainData = getMainTableValue(requestInfo); + String docIds = mainData.get(docField); + if (StrUtil.isBlank(docIds)) { + return; + } + List docImageInfos = mapper.selectDocImageInfos(docIds); + if (CollectionUtil.isEmpty(docImageInfos)) { + log.error("未查询到物理文件信息!=>" + docIds); + Util.actionFailException(requestInfo.getRequestManager(), "系统异常,请联系管理员"); + } + String[] keywordArr = keywords.split(";"); + Map keyMap = new HashMap<>(8); + for (DocImageInfo docImageInfo : docImageInfos) { + Map keyword = findKeyWord(docImageInfo, keywordArr); + for (Map.Entry entry : keyword.entrySet()) { + if (keyMap.containsKey(entry.getKey())) { + Boolean isKeyword = keyMap.get(entry.getKey()); + if (!isKeyword) { + keyMap.put(entry.getKey(), entry.getValue()); + } + } else { + keyMap.put(entry.getKey(), entry.getValue()); + } + } + } + if (!Boolean.parseBoolean(isBack)) { + return; + } + for (Map.Entry entry : keyMap.entrySet()) { + if (!entry.getValue()) { + throw new CustomerException(Util.logStr("关键字[{}]定位异常!文件中不存在关键字!", entry.getKey())); + } + } + } + + + private Map findKeyWord(DocImageInfo docImageInfo, String[] keywordArr) { + String imageFileName = docImageInfo.getImageFileName(); + Integer imageFileId = docImageInfo.getImageFileId(); + Map result = new HashMap<>(8); + InputStream inputStream = ImageFileManager.getInputStreamById(imageFileId); + if (imageFileName.endsWith(".pdf")) { + for (String keyword : keywordArr) { + List keywordPoints = PdfUtil.findKeywordPoints(inputStream, keyword); + if (CollectionUtil.isEmpty(keywordPoints)) { + result.put(keyword, false); + } else { + result.put(keyword, true); + } + } + } else if (imageFileName.endsWith(".doc") || imageFileName.endsWith(".docx")) { + for (String keyword : keywordArr) { + List keywordPoints = WordKeywordFinder.findKeywords(inputStream, keyword, imageFileName); + if (CollectionUtil.isEmpty(keywordPoints)) { + result.put(keyword, false); + } else { + result.put(keyword, true); + } + } + } + return result; + } +} diff --git a/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/mapper/LocationKeywordMapper.java b/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/mapper/LocationKeywordMapper.java new file mode 100644 index 0000000..934ce61 --- /dev/null +++ b/src/main/java/weaver/youhong/ai/pcn/actioin/locationkeyword/mapper/LocationKeywordMapper.java @@ -0,0 +1,14 @@ +package weaver.youhong.ai.pcn.actioin.locationkeyword.mapper; + +import aiyh.utils.annotation.recordset.SqlMapper; + +/** + *

+ * + *

create: 2023/6/16 16:56

+ * + * @author youHong.ai + */ +@SqlMapper +public interface LocationKeywordMapper { +} diff --git a/src/test/java/youhong/ai/utiltest/GenericTest.java b/src/test/java/youhong/ai/utiltest/GenericTest.java index b0c0be6..b567c20 100644 --- a/src/test/java/youhong/ai/utiltest/GenericTest.java +++ b/src/test/java/youhong/ai/utiltest/GenericTest.java @@ -13,6 +13,9 @@ import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.junit.Test; import weaver.youhong.ai.pcn.actioin.doctoavatar.DocToAvatarAction; +import youhong.ai.utiltest.excel.ExcelCell; +import youhong.ai.utiltest.excel.ExcelPort; +import youhong.ai.utiltest.excel.ExcelRow; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; diff --git a/src/test/java/youhong/ai/utiltest/TestApi.java b/src/test/java/youhong/ai/utiltest/TestApi.java index fb9d2ef..8c33456 100644 --- a/src/test/java/youhong/ai/utiltest/TestApi.java +++ b/src/test/java/youhong/ai/utiltest/TestApi.java @@ -9,9 +9,9 @@ import cn.hutool.crypto.asymmetric.KeyType; import cn.hutool.crypto.asymmetric.RSA; import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONUtil; -import com.alibaba.fastjson.JSON; import org.junit.Test; +import javax.ws.rs.core.MediaType; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -32,7 +32,8 @@ public class TestApi extends BaseTest { @Test public void testApi() { - String api = "https://ecology.yeyaguitu.cn/api/aiyh/test/req-msg/test/cus-api"; + // String api = "https://ecology.yeyaguitu.cn/api/aiyh/test/req-msg/test/cus-api"; + String api = "https://ecology.yeyaguitu.cn/api/workflow/paService/doCreateRequest"; String token = (String) testGetoken("https://ecology.yeyaguitu.cn").get("token"); String spk = SYSTEM_CACHE.get("SERVER_PUBLIC_KEY"); // 封装请求头参数 @@ -44,13 +45,43 @@ public class TestApi extends BaseTest { head.put("token", token); head.put("userid", encryptUserid); HttpUtils httpUtils = new HttpUtils(); + Map body = new HashMap<>(); + body.put("mainData", "[{\n" + + "\t\"fieldName\":\"cs1\",\n" + + "\t\"fieldValue\":\"api测试1\"\n" + + "},{\n" + + "\t\"fieldName\":\"cs2\",\n" + + "\t\"fieldValue\":\"api测试2\"\n" + + "},{\n" + + "\t\"fieldName\":\"cs3\",\n" + + "\t\"fieldValue\":\"api测试3\"\n" + + "},{\n" + + "\t\"fieldName\":\"sjid\",\n" + + "\t\"fieldValue\":\"8\"\n" + + "},{\n" + + "\t\"fieldName\":\"bmllan\",\n" + + "\t\"fieldValue\":\"5\"\n" + + "},{\n" + + "\t\"fieldName\":\"mc\",\n" + + "\t\"fieldValue\":\"不1道\"\n" + + "}]"); + body.put("requestName", "api流程测试调用接口校验参数"); + body.put("workflowId", "44"); ResponeVo responeVo = null; + head.put("Content-Type", MediaType.APPLICATION_FORM_URLENCODED + ";charset=utf-8"); try { - responeVo = httpUtils.apiGet(api, head); + responeVo = httpUtils.apiPost(api, body, head); } catch (IOException e) { throw new RuntimeException(e); } - System.out.println(JSON.toJSONString(responeVo)); + System.out.println(responeVo); + // ResponeVo responeVo = null; + // try { + // responeVo = httpUtils.apiGet(api, head); + // } catch (IOException e) { + // throw new RuntimeException(e); + // } + // System.out.println(JSON.toJSONString(responeVo)); } /** diff --git a/src/test/java/youhong/ai/utiltest/ExcelBody.java b/src/test/java/youhong/ai/utiltest/excel/ExcelBody.java similarity index 70% rename from src/test/java/youhong/ai/utiltest/ExcelBody.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelBody.java index e143903..cea4c27 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelBody.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelBody.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import lombok.Getter; import lombok.Setter; @@ -14,5 +14,5 @@ import lombok.ToString; @Getter @Setter @ToString -public class ExcelBody extends ExcelCell{ +public class ExcelBody extends ExcelCell { } diff --git a/src/test/java/youhong/ai/utiltest/ExcelCell.java b/src/test/java/youhong/ai/utiltest/excel/ExcelCell.java similarity index 90% rename from src/test/java/youhong/ai/utiltest/ExcelCell.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelCell.java index 8f38d69..083a975 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelCell.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelCell.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import lombok.Getter; import lombok.Setter; diff --git a/src/test/java/youhong/ai/utiltest/ExcelHead.java b/src/test/java/youhong/ai/utiltest/excel/ExcelHead.java similarity index 87% rename from src/test/java/youhong/ai/utiltest/ExcelHead.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelHead.java index 6ede4bf..a7a9b9b 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelHead.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelHead.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import lombok.Getter; import lombok.Setter; diff --git a/src/test/java/youhong/ai/utiltest/ExcelPort.java b/src/test/java/youhong/ai/utiltest/excel/ExcelPort.java similarity index 98% rename from src/test/java/youhong/ai/utiltest/ExcelPort.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelPort.java index 73f7db6..7a285af 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelPort.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelPort.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import aiyh.utils.Util; import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; diff --git a/src/test/java/youhong/ai/utiltest/ExcelRow.java b/src/test/java/youhong/ai/utiltest/excel/ExcelRow.java similarity index 89% rename from src/test/java/youhong/ai/utiltest/ExcelRow.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelRow.java index 5b538f9..d83748d 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelRow.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelRow.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import lombok.Getter; import lombok.Setter; diff --git a/src/test/java/youhong/ai/utiltest/ExcelSheet.java b/src/test/java/youhong/ai/utiltest/excel/ExcelSheet.java similarity index 89% rename from src/test/java/youhong/ai/utiltest/ExcelSheet.java rename to src/test/java/youhong/ai/utiltest/excel/ExcelSheet.java index da992d6..63804c3 100644 --- a/src/test/java/youhong/ai/utiltest/ExcelSheet.java +++ b/src/test/java/youhong/ai/utiltest/excel/ExcelSheet.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import lombok.Getter; import lombok.Setter; diff --git a/src/test/java/youhong/ai/utiltest/IExcelCellStyleCreator.java b/src/test/java/youhong/ai/utiltest/excel/IExcelCellStyleCreator.java similarity index 94% rename from src/test/java/youhong/ai/utiltest/IExcelCellStyleCreator.java rename to src/test/java/youhong/ai/utiltest/excel/IExcelCellStyleCreator.java index e5d581f..932a83c 100644 --- a/src/test/java/youhong/ai/utiltest/IExcelCellStyleCreator.java +++ b/src/test/java/youhong/ai/utiltest/excel/IExcelCellStyleCreator.java @@ -1,4 +1,4 @@ -package youhong.ai.utiltest; +package youhong.ai.utiltest.excel; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.xssf.streaming.SXSSFCell; diff --git a/src/test/java/youhong/ai/utiltest/wordread/Main.java b/src/test/java/youhong/ai/utiltest/wordread/Main.java new file mode 100644 index 0000000..59c3f91 --- /dev/null +++ b/src/test/java/youhong/ai/utiltest/wordread/Main.java @@ -0,0 +1,32 @@ +package youhong.ai.utiltest.wordread; + +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; + +public class Main { + public static void main(String[] args) { + try { + String fileName = "/Users/aoey.oct.22/Downloads/offer 发放测试 0522 RC (1).docx"; + String keyword = "Human Resource"; + InputStream inputStream = Files.newInputStream(Paths.get(fileName)); + + List keywordLocations = WordKeywordFinder.findKeywords(inputStream, keyword, fileName); + + if (keywordLocations.isEmpty()) { + System.out.println("未找到关键字:" + keyword); + } else { + for (WordKeywordFinder.KeywordLocation location : keywordLocations) { + System.out.println("关键字:" + location.getKeyword()); + System.out.println("段落编号:" + location.getParagraphNumber()); + System.out.println("-----------------------"); + } + } + + inputStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/youhong/ai/utiltest/wordread/WordKeywordFinder.java b/src/test/java/youhong/ai/utiltest/wordread/WordKeywordFinder.java new file mode 100644 index 0000000..f88651d --- /dev/null +++ b/src/test/java/youhong/ai/utiltest/wordread/WordKeywordFinder.java @@ -0,0 +1,67 @@ +package youhong.ai.utiltest.wordread; + +import org.apache.poi.hwpf.HWPFDocument; +import org.apache.poi.hwpf.extractor.WordExtractor; +import org.apache.poi.xwpf.extractor.XWPFWordExtractor; +import org.apache.poi.xwpf.usermodel.XWPFDocument; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +public class WordKeywordFinder { + + public static List findKeywords(InputStream inputStream, String keyword, String fileName) throws IOException { + List keywordLocations = new ArrayList<>(); + if (fileName.endsWith(".docx")) { + XWPFDocument docx = new XWPFDocument(inputStream); + XWPFWordExtractor extractor = new XWPFWordExtractor(docx); + String text = extractor.getText(); + String[] paragraphs = text.split("\n"); + for (int i = 0; i < paragraphs.length; i++) { + String paragraph = paragraphs[i]; + if (paragraph.contains(keyword)) { + keywordLocations.add(new KeywordLocation(keyword, i + 1)); + } + } + extractor.close(); + docx.close(); + } else if (fileName.endsWith(".doc")) { + HWPFDocument doc = new HWPFDocument(inputStream); + WordExtractor extractor = new WordExtractor(doc); + String text = extractor.getText(); + String[] paragraphs = text.split("\n"); + for (int i = 0; i < paragraphs.length; i++) { + String paragraph = paragraphs[i]; + if (paragraph.contains(keyword)) { + keywordLocations.add(new KeywordLocation(keyword, i + 1)); + } + } + extractor.close(); + doc.close(); + } else { + throw new IllegalArgumentException("Unsupported file format: " + fileName); + } + + return keywordLocations; + } + + public static class KeywordLocation { + private final String keyword; + private final int paragraphNumber; + + public KeywordLocation(String keyword, int paragraphNumber) { + this.keyword = keyword; + this.paragraphNumber = paragraphNumber; + } + + public String getKeyword() { + return keyword; + } + + public int getParagraphNumber() { + return paragraphNumber; + } + } +}