From e9bd4fd92a2397e5d7d4b9ab1a85a5703ed9cfa1 Mon Sep 17 00:00:00 2001 From: "youHong.ai" <774495953@qq.com> Date: Tue, 22 Nov 2022 16:24:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=82=96=E5=B7=A5=E5=85=B7=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/weaver/general/GCONST.java | 4 + .../commons/config/dao/ConfigMappingCMD.java | 163 ++ .../commons/config/entity/DocImageFile.java | 40 + .../commons/config/entity/FieldMessage.java | 26 + .../config/entity/ListMapIndexValue.java | 17 + .../commons/config/entity/MappingDetail.java | 53 + .../commons/config/entity/MultipartFile.java | 37 + .../config/entity/RequestMappingConfig.java | 48 + .../config/entity/ResponseMapping.java | 17 + .../config/enumtype/DataSourceEnum.java | 35 + .../config/enumtype/GetValueTypeEnum.java | 44 + .../config/enumtype/ParamTypeEnum.java | 43 + .../interfacies/CusInterfaceGetValue.java | 38 + .../interfacies/CusInterfaceListValue.java | 25 + .../config/service/DealWithMapping.java | 1312 +++++++++++++++++ .../commons/exception/RequestException.java | 21 + .../commons/exception/ValueDealException.java | 22 + .../weaver/xiao/commons/utils/JsonResult.java | 70 + .../weaver/xiao/commons/utils/LogUtil.java | 73 + .../weaver/xiao/commons/utils/PreMap.java | 26 + .../weaver/xiao/commons/utils/PropUtil.java | 57 + .../xiao/commons/utils/RequestBaseInfo.java | 59 + .../xiao/commons/utils/RequestUtil.java | 165 +++ .../weaver/xiao/commons/utils/SqlUtil.java | 260 ++++ .../utils/annotation/SqlFieldMapping.java | 21 + .../hrorganization/sftp/FetchDataUtil.java | 20 + src/test/java/baseTest/BaseTest.java | 2 +- .../java/youhong/ai/pcn/TestOrganization.java | 31 + 28 files changed, 2728 insertions(+), 1 deletion(-) create mode 100644 src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/DocImageFile.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/FieldMessage.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/ListMapIndexValue.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/MappingDetail.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/MultipartFile.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/RequestMappingConfig.java create mode 100644 src/main/java/weaver/xiao/commons/config/entity/ResponseMapping.java create mode 100644 src/main/java/weaver/xiao/commons/config/enumtype/DataSourceEnum.java create mode 100644 src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java create mode 100644 src/main/java/weaver/xiao/commons/config/enumtype/ParamTypeEnum.java create mode 100644 src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceGetValue.java create mode 100644 src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceListValue.java create mode 100644 src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java create mode 100644 src/main/java/weaver/xiao/commons/exception/RequestException.java create mode 100644 src/main/java/weaver/xiao/commons/exception/ValueDealException.java create mode 100644 src/main/java/weaver/xiao/commons/utils/JsonResult.java create mode 100644 src/main/java/weaver/xiao/commons/utils/LogUtil.java create mode 100644 src/main/java/weaver/xiao/commons/utils/PreMap.java create mode 100644 src/main/java/weaver/xiao/commons/utils/PropUtil.java create mode 100644 src/main/java/weaver/xiao/commons/utils/RequestBaseInfo.java create mode 100644 src/main/java/weaver/xiao/commons/utils/RequestUtil.java create mode 100644 src/main/java/weaver/xiao/commons/utils/SqlUtil.java create mode 100644 src/main/java/weaver/xiao/commons/utils/annotation/SqlFieldMapping.java create mode 100644 src/test/java/youhong/ai/pcn/TestOrganization.java diff --git a/src/main/java/weaver/general/GCONST.java b/src/main/java/weaver/general/GCONST.java index cfdc9ed..905a488 100644 --- a/src/main/java/weaver/general/GCONST.java +++ b/src/main/java/weaver/general/GCONST.java @@ -177,6 +177,10 @@ public class GCONST { return propertyPath; } + public static String setLogPath() { + return ROOT_PATH + "log" + File.separatorChar; + } + public static String getLogPath() { return ROOT_PATH + "log" + File.separatorChar; } diff --git a/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java b/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java new file mode 100644 index 0000000..037b7fb --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/dao/ConfigMappingCMD.java @@ -0,0 +1,163 @@ +package weaver.xiao.commons.config.dao; + +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.xiao.commons.config.entity.DocImageFile; +import weaver.xiao.commons.config.entity.FieldMessage; +import weaver.xiao.commons.config.entity.MappingDetail; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.enumtype.DataSourceEnum; +import weaver.xiao.commons.exception.ValueDealException; +import weaver.xiao.commons.utils.SqlUtil; +import weaver.zwl.common.ToolUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + + +/** + * @author XiaoBokang + * @create 2021/12/29 9:46 + */ + +public class ConfigMappingCMD { + + private final ToolUtil toolUtil = new ToolUtil(); + private final String configTableName = "uf_request_config"; + private final SqlUtil sqlUtil = new SqlUtil(); + + public RequestMappingConfig selectByUniqueCode(String uniqueCode) { + toolUtil.writeDebuggerLog("=======================查询配置列表======================="); + RequestMappingConfig requestMappingConfig = new RequestMappingConfig(); + RecordSet recordSet = new RecordSet(); + String querySql = "select id,workflow,requestUrl,dataSource,uniqueCode, relationWorkFlow,cusWhereSql from " + configTableName + " where uniqueCode = ?"; + toolUtil.writeDebuggerLog("执行查询的sql query mainRequestMappingConfig list sql new>>>>" + querySql + " uniqueCode >>" + uniqueCode); + recordSet.executeQuery(querySql, uniqueCode); + if (recordSet.next()) { + int mainId = Util.getIntValue(recordSet.getString("id")); + requestMappingConfig = sqlUtil.recordSetToEntityByEntity(recordSet, RequestMappingConfig.class); + this.setDetailMapping(mainId, requestMappingConfig); + } + return requestMappingConfig; + } + + private void setDetailMapping(int mainId, RequestMappingConfig requestMappingConfig) { + // 查询明细1的信息 + RecordSet detail1RecordSet = new RecordSet(); + String dataSource = requestMappingConfig.getDataSource(); + if (Objects.isNull(dataSource) || "".equals(dataSource)) { + dataSource = "0"; + } + DataSourceEnum anEnum = DataSourceEnum.getEnum(dataSource); + String queryDetail1Sql = ""; + switch (anEnum) { + case CUS_TABLE: + queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext," + + " from " + configTableName + "_dt1 config "; + break; + case WORKFLOW: + queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,valueContext,relationWorkFlowField, " + + " fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " + + " from " + configTableName + "_dt1 config " + + " left join workflow_field_table_view fv " + + " on config.workflowField = fv.id or config.relationWorkFlowField = fv.id" + + " where mainid = ? "; + break; + case MODEL: + queryDetail1Sql = "select paramName,paramType,getValueType,dataSource,belongTo,workflowField,modelField,fieldName,valueContext, " + + " fv.id fieldId,fv.fieldname,fv.tablename,fv.indexdesc " + + " from " + configTableName + "_dt1 config " + + " left join workflow_field_table_view fv on config.modelField = fv.id " + + " where mainid = ? "; + break; + default: + throw new ValueDealException("不支持的数据来源"); + } + toolUtil.writeDebuggerLog("执行查询的明细1sql query detail1Sql >>>>" + queryDetail1Sql + " mainId:" + mainId); + detail1RecordSet.executeQuery(queryDetail1Sql, mainId); + List mappingDetails = new ArrayList<>(); + while (detail1RecordSet.next()) { + MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail1RecordSet, MappingDetail.class); + String getValueType = mappingDetail.getGetValueType(); + // 设置流程字段相关信息 +// if("0".equals(getValueType) || "4".equals(getValueType)){ + FieldMessage fieldMessage = sqlUtil.recordSetToEntityByEntity(detail1RecordSet, FieldMessage.class); + mappingDetail.setFieldMassage(fieldMessage); +// } + mappingDetails.add(mappingDetail); + } + // 查询明细2的信息 + RecordSet detail2RecordSet = new RecordSet(); + String queryDetail2Sql = "select paramName,belongTo,childType,dataSource,detailId,cusWhereSql from uf_request_config_dt2 where mainid = ?"; + toolUtil.writeDebuggerLog("执行查询的明细sql query detail2Sql >>>>" + queryDetail2Sql + " mainId:" + mainId); + detail2RecordSet.executeQuery(queryDetail2Sql, mainId); + while (detail2RecordSet.next()) { + MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail2RecordSet, MappingDetail.class); + mappingDetail.setParamType("6");// 设置参数类型为List + mappingDetails.add(mappingDetail); + } + // 查询明细3的信息 + RecordSet detail3RecordSet = new RecordSet(); + String queryDetail3Sql = "select paramName,belongTo from uf_request_config_dt3 where mainid = ?"; + toolUtil.writeDebuggerLog("执行查询的明细sql query detail3Sql >>>>" + queryDetail3Sql + " mainId:" + mainId); + detail3RecordSet.executeQuery(queryDetail3Sql, mainId); + while (detail3RecordSet.next()) { + MappingDetail mappingDetail = sqlUtil.recordSetToEntityByEntity(detail3RecordSet, MappingDetail.class); + mappingDetail.setParamType("5");// 设置参数类型为Object + mappingDetails.add(mappingDetail); + } + requestMappingConfig.setConfigDetail(mappingDetails); +// //查询明细4的信息 +// RecordSet detail4RecordSet = new RecordSet(); +// List responseMappingList = new ArrayList<>(); +// String queryDetail4Sql = "select responseFieldName,workflowField,mainOrDetail,detailTableId,workflowFieldName from uf_request_config_dt4 where mainid = ?"; +// toolUtil.writeDebuggerLog("执行查询的明细sql query detail4Sql >>>>"+queryDetail4Sql+" mainId:"+mainId); +// detail4RecordSet.executeQuery(queryDetail4Sql,mainId); +// while (detail4RecordSet.next()){ +// ResponseMapping responseMapping = sqlUtil.recordSetToEntityByEntity(detail4RecordSet, ResponseMapping.class); +// responseMappingList.add(responseMapping); +// } +// requestMappingConfig.setResponseMappingList(responseMappingList); + requestMappingConfig.setConfigDetail(mappingDetails); + } + + + /** + *

查询附件信息

+ * + * @param docIds 文档id + * @return 附件信息 + * @author YouHong.ai + */ + public List selectDocImageFileList(String docIds) { + String sql = "select docfile.IMAGEFILEID,docfile.IMAGEFILENAME,docfile.DOCID,docfile.ID, " + + " imf.FILESIZE " + + "from docimagefile docfile " + + "left join imagefile imf on imf.IMAGEFILEID = docfile.IMAGEFILEID " + + "where docid in (" + docIds + ")"; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql); + List docImageFileList = new ArrayList<>(); + while (rs.next()) { + String IMAGEFILEID = rs.getString("IMAGEFILEID"); + String IMAGEFILENAME = rs.getString("IMAGEFILENAME"); + String DOCID = rs.getString("DOCID"); + String ID = rs.getString("ID"); + String fileSize = rs.getString("FILESIZE"); + DocImageFile docImageFile = new DocImageFile(); + docImageFile.setImageFileId(Util.getIntValue(IMAGEFILEID)); + docImageFile.setImageFileName(IMAGEFILENAME); + docImageFile.setDocId(Util.getIntValue(DOCID)); + docImageFile.setId(Util.getIntValue(ID)); + docImageFile.setFileSize(Util.getIntValue(fileSize) / 1024L); + docImageFileList.add(docImageFile); + } + if (docImageFileList.isEmpty()) { + throw new NullPointerException("附件字段不存在值!请检查数据表或配置表数据类型是否正确!"); + } + return docImageFileList; + } + + +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/DocImageFile.java b/src/main/java/weaver/xiao/commons/config/entity/DocImageFile.java new file mode 100644 index 0000000..21d8e69 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/DocImageFile.java @@ -0,0 +1,40 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + *

附件信息

+ * + *

create: 2022-11-21 10:55

+ * + * @author youHong.ai + */ + +@Getter +@Setter +@ToString +public class DocImageFile { + /** + * 文件id + */ + private Integer imageFileId; + /** + * 文件名称 + */ + private String imageFileName; + /** + * docId + */ + private Integer docId; + /** + * id + */ + private Integer id; + + /** + * 文件大小 + */ + private Long fileSize; +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/FieldMessage.java b/src/main/java/weaver/xiao/commons/config/entity/FieldMessage.java new file mode 100644 index 0000000..4dab770 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/FieldMessage.java @@ -0,0 +1,26 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Data; +import weaver.xiao.commons.utils.annotation.SqlFieldMapping; + +/** + * @author XiaoBokang + * @create 2021/12/31 10:15 + */ + +@Data +public class FieldMessage { + + @SqlFieldMapping("fieldId") + private String fieldId; + + @SqlFieldMapping("fieldName") + private String fieldName; + + @SqlFieldMapping("indexDesc") + private String indexDesc; + + @SqlFieldMapping("tableName") + private String tableName; + +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/ListMapIndexValue.java b/src/main/java/weaver/xiao/commons/config/entity/ListMapIndexValue.java new file mode 100644 index 0000000..3726685 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/ListMapIndexValue.java @@ -0,0 +1,17 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Data; + +/** + *

list分割暂存类

+ * + *

create: 2022-08-05 11:25

+ * + * @author aiyh EBU7-dev-1 + */ + +@Data +public class ListMapIndexValue { + private String key; + private Object value; +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/MappingDetail.java b/src/main/java/weaver/xiao/commons/config/entity/MappingDetail.java new file mode 100644 index 0000000..41b7252 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/MappingDetail.java @@ -0,0 +1,53 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Data; +import weaver.xiao.commons.utils.annotation.SqlFieldMapping; + +import java.util.List; + +/** + * @author XiaoBokang + * @create 2021/12/28 17:45 + */ + +@Data +public class MappingDetail { + + @SqlFieldMapping("paramName") + private String paramName; + + @SqlFieldMapping("paramType") + private String paramType; + + @SqlFieldMapping("getValueType") + private String getValueType; + + @SqlFieldMapping("childType") + private String childType; + + @SqlFieldMapping("dataSource") + private String dataSource; + + @SqlFieldMapping("detailId") + private String detailId; + + @SqlFieldMapping("belongTo") + private String belongTo; + + @SqlFieldMapping("workflowField") + private String workflowField; + + @SqlFieldMapping("valueContext") + private String valueContext; + + @SqlFieldMapping("relationWorkFlowField") + private String relationWorkFlowField; + + @SqlFieldMapping("cusWhereSql") + private String cusWhereSql; + + private List childList; + + private FieldMessage fieldMassage; + +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/MultipartFile.java b/src/main/java/weaver/xiao/commons/config/entity/MultipartFile.java new file mode 100644 index 0000000..0e8e73f --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/MultipartFile.java @@ -0,0 +1,37 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.io.InputStream; + +/** + *

+ * + *

create: 2022-11-21 11:12

+ * + * @author youHong.ai + */ + +@Setter +@Getter +@ToString +public class MultipartFile { + /** + * 文件名 + */ + String fileName; + /** + * 上传文件的key + */ + String fileKey; + /** + * 文件流信息 + */ + InputStream stream; + /** + * 文件大小 + */ + Long fileSize; +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/RequestMappingConfig.java b/src/main/java/weaver/xiao/commons/config/entity/RequestMappingConfig.java new file mode 100644 index 0000000..ec678f5 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/RequestMappingConfig.java @@ -0,0 +1,48 @@ +package weaver.xiao.commons.config.entity; + + +import lombok.Data; +import weaver.xiao.commons.utils.annotation.SqlFieldMapping; + +import java.util.List; + +/** + * @author XiaoBokang + * @create 2021/12/28 17:43 + */ + +@Data +public class RequestMappingConfig { + + @SqlFieldMapping("workflow") + private String workflow; + + @SqlFieldMapping("requestUrl") + private String requestUrl; + + @SqlFieldMapping("uniqueCode") + private String uniqueCode; + + @SqlFieldMapping("dataSource") + private String dataSource; + + @SqlFieldMapping("modelId") + private String modelId; + + @SqlFieldMapping("tableName") + private String tableName; + + @SqlFieldMapping("urlDesc") + private String urlDesc; + + @SqlFieldMapping("relationWorkFlow") + private String relationWorkFlow; + + @SqlFieldMapping("cusWhereSql") + private String cusWhereSql; + + private List configDetail; + + private List responseMappingList; + +} diff --git a/src/main/java/weaver/xiao/commons/config/entity/ResponseMapping.java b/src/main/java/weaver/xiao/commons/config/entity/ResponseMapping.java new file mode 100644 index 0000000..529788f --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/entity/ResponseMapping.java @@ -0,0 +1,17 @@ +package weaver.xiao.commons.config.entity; + +import lombok.Data; + +/** + * @author XiaoBokang + * @create 2022/4/12 22:28 + */ + +@Data +public class ResponseMapping { + private String responseFieldName; + private String workflowField; + private String mainOrDetail; + private String detailTableId; + private String workflowFieldName; +} diff --git a/src/main/java/weaver/xiao/commons/config/enumtype/DataSourceEnum.java b/src/main/java/weaver/xiao/commons/config/enumtype/DataSourceEnum.java new file mode 100644 index 0000000..7a5bf58 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/enumtype/DataSourceEnum.java @@ -0,0 +1,35 @@ +package weaver.xiao.commons.config.enumtype; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @author XiaoBokang + * @create 2022/6/14 12:26 + */ + +public enum DataSourceEnum { + + WORKFLOW("0"), + MODEL("1"), + CUS_TABLE("2"); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (DataSourceEnum dataSource : EnumSet.allOf(DataSourceEnum.class)){ + LOOK_UP.put(dataSource.value,dataSource); + } + } + public final String value; + + DataSourceEnum(String value){ + this.value = value; + } + + public static DataSourceEnum getEnum(String value){ + return LOOK_UP.get(value); + } + +} diff --git a/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java new file mode 100644 index 0000000..17abac8 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java @@ -0,0 +1,44 @@ +package weaver.xiao.commons.config.enumtype; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @author XiaoBokang + * @create 2022/6/14 13:13 + */ + +public enum GetValueTypeEnum { + + WORKFLOW_FIELD("0"), + DEFAULT_VALUE("1"), + CURRENT_TIME("3"), + CUS_SQL("4"), + REQUEST_ID("5"), + MAIN_DATA_ID("6"), + RANDOM("7"), + ATTACHMENT("8"), + + CUS_INTERFACE("9"), + + CUS_FIELD("10"); + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (GetValueTypeEnum getValueTypeEnum : EnumSet.allOf(GetValueTypeEnum.class)) { + LOOK_UP.put(getValueTypeEnum.value, getValueTypeEnum); + } + } + + public final String value; + + GetValueTypeEnum(String value) { + this.value = value; + } + + public static GetValueTypeEnum getEnum(String value) { + return LOOK_UP.get(value); + } +} diff --git a/src/main/java/weaver/xiao/commons/config/enumtype/ParamTypeEnum.java b/src/main/java/weaver/xiao/commons/config/enumtype/ParamTypeEnum.java new file mode 100644 index 0000000..2bf21a8 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/enumtype/ParamTypeEnum.java @@ -0,0 +1,43 @@ +package weaver.xiao.commons.config.enumtype; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +/** + * @author XiaoBokang + * @create 2022/6/14 12:56 + */ + +public enum ParamTypeEnum { + + STRING("0"), + INT("1"), + DOUBLE("2"), + DATE("3"), + DATE_TIME("4"), + OBJECT("5"), + LIST("6"), + CUS_DATE_STR("7"), + TIME_STAMP("8"), + DATE_VAL("9"), + Boolean("10"); + + + private static final Map LOOK_UP = new HashMap<>(8); + + static { + for (ParamTypeEnum paramTypeEnum : EnumSet.allOf(ParamTypeEnum.class)){ + LOOK_UP.put(paramTypeEnum.value,paramTypeEnum); + } + } + public final String value; + + ParamTypeEnum(String value){ + this.value = value; + } + + public static ParamTypeEnum getEnum(String value){ + return LOOK_UP.get(value); + } +} diff --git a/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceGetValue.java b/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceGetValue.java new file mode 100644 index 0000000..8e0e8b3 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceGetValue.java @@ -0,0 +1,38 @@ +package weaver.xiao.commons.config.interfacies; + +import org.apache.log4j.Logger; +import weaver.xiao.commons.utils.LogUtil; + +import java.util.Map; + +/** + *

自定义获取参数值

+ * + * @author EBU7-dev-1 aiyh + *

create: 2022-07-25 14:18

+ */ + +public interface CusInterfaceGetValue { + + final String START_LEFT = "{"; + final String VAR_START_STR = "#{"; + final String MAIN = "main."; + final String DETAIL = "detail."; + final String END_STR = "}"; + + final String SQL_START = "#sql{"; + + final Logger log = LogUtil.getLogger(); + + /** + * 获取参数值 + * + * @param mainMap 主表数据 + * @param detailMap 明细表数据 + * @param currentValue 当前字段值 + * @param pathParam 路径参数 + * @return 最终返回参数 + */ + Object execute(Map mainMap, Map detailMap, String currentValue, + Map pathParam); +} diff --git a/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceListValue.java b/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceListValue.java new file mode 100644 index 0000000..3e85dae --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/interfacies/CusInterfaceListValue.java @@ -0,0 +1,25 @@ +package weaver.xiao.commons.config.interfacies; + +import java.util.List; +import java.util.Map; + +/** + *

自定义数组数据来源

+ * + *

create: 2022-08-15 15:38

+ * + * @author aiyh EBU7-dev-1 + */ + +public interface CusInterfaceListValue { + + /** + *

自定义数组数据来源

+ * + * @param pathParam 路径参数 + * @param mainMap 主表数据 + * @param mainTable 主表表明 + * @return 数组 + */ + List execute(Map pathParam, Map mainMap, String mainTable); +} diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java new file mode 100644 index 0000000..6522823 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -0,0 +1,1312 @@ +package weaver.xiao.commons.config.service; + +import com.alibaba.fastjson.JSON; +import com.google.common.base.Strings; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.file.ImageFileManager; +import weaver.general.Util; +import weaver.xiao.commons.config.dao.ConfigMappingCMD; +import weaver.xiao.commons.config.entity.*; +import weaver.xiao.commons.config.enumtype.GetValueTypeEnum; +import weaver.xiao.commons.config.enumtype.ParamTypeEnum; +import weaver.xiao.commons.config.interfacies.CusInterfaceGetValue; +import weaver.xiao.commons.config.interfacies.CusInterfaceListValue; +import weaver.xiao.commons.exception.ValueDealException; +import weaver.zwl.common.ToolUtil; + +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.security.SecureRandom; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * @author XiaoBokang & aiyh + * @create 2021/12/29 10:10 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DealWithMapping extends ToolUtil { + + public static final char SBC_SPACE = 12288; // 全角空格 12288 + public static final char DBC_SPACE = 32; // 半角空格 32 + // ASCII character 33-126 <-> unicode 65281-65374 + public static final char ASCII_START = 33; + public static final char ASCII_END = 126; + public static final char UNICODE_START = 65281; + public static final char UNICODE_END = 65374; + public static final char DBC_SBC_STEP = 65248; // + private final ConfigMappingCMD mappingCMD = new ConfigMappingCMD(); + private String mainTable; + private String forMatString; + private List fileNames = new ArrayList<>(); + private List fileInputStreams = new ArrayList<>(); + private List multipartFileList = new ArrayList<>(); + + private RecordSet tempRs; + + /** + *

将日期字符串转换为Date对象

+ * + * @param dateStr 日期字符串 + * @return 日期对象 + */ + public static Date parseDate(String dateStr) { + ThreadLocal SIMPLE_DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); + if (dateStr == null || dateStr.length() == 0) { + return null; + } + String regex = "\\/|\\.|年|月|日"; + Date date = null; + try { + date = SIMPLE_DATE_FORMAT.get().parse(dateStr.replaceAll(regex, "-")); + return date; + } catch (ParseException e) { + // TODO Auto-generated catch block + throw new ValueDealException("无法将" + dateStr + "转换为日期对象!", e); + } + } + + private static Map getMapMapping(RecordSet rs) { + Map map = new HashMap<>(); + String[] columnType = rs.getColumnTypeName(); + int colCounts; + colCounts = rs.getColCounts() == 0 ? columnType.length : rs.getColCounts(); + for (int i = 1; i <= colCounts; i++) { + String key; + String type = "varchar"; + if (columnType != null) { + if (columnType.length != colCounts) { + type = "varchar"; + } else { + type = columnType[i - 1]; + } + } + key = rs.getColumnName(i).toLowerCase(); + if ("int".equalsIgnoreCase(type) || "Integer".equalsIgnoreCase(type) + || "Long".equalsIgnoreCase(type) || "BIGINT".equalsIgnoreCase(type) + || "NUMBER".equalsIgnoreCase(type) || "INTEGER".equalsIgnoreCase(type) + || "TINYINT".equalsIgnoreCase(type) || "SMALLINT".equalsIgnoreCase(type)) { + map.put(key, rs.getInt(i) == -1 ? rs.getString(i) : rs.getInt(i)); + continue; + } + if ("FLOAT".equalsIgnoreCase(type)) { + map.put(key, rs.getFloat(i)); + continue; + } + if ("DATE".equalsIgnoreCase(type) || "TIMESTAMP".equalsIgnoreCase(type) + || "DATETIME".equalsIgnoreCase(type)) { + map.put(key, rs.getString(i)); + continue; + } + if ("DOUBLE".equalsIgnoreCase(type)) { + map.put(key, rs.getDouble(i)); + continue; + } + if ("DECIMAL".equalsIgnoreCase(type) || "NUMERIC".equalsIgnoreCase(type)) { + map.put(key, rs.getDouble(i)); + continue; + } + map.put(key, rs.getString(i)); + } + return map; + } + + /** + * 全角转半角 + * + * @param src 全角字符 + * @return 半角字符 + */ + public static char sbc2dbc(char src) { + if (src == SBC_SPACE) { + return DBC_SPACE; + } + + if (src >= UNICODE_START && src <= UNICODE_END) { + return (char) (src - DBC_SBC_STEP); + } + + return src; + } + + /** + * 全角转半角 + * + * @param src 全角字符串 + * @return DBC case + */ + public static String sbc2dbcCase(String src) { + if (src == null) { + return null; + } + char[] c = src.toCharArray(); + for (int i = 0; i < c.length; i++) { + c[i] = sbc2dbc(c[i]); + } + return new String(c); + } + + /** + * 将配置参数通过唯一标识查询处理成树形结构 + * + * @param uniqueCode 唯一标识 + * @return + */ + public RequestMappingConfig treeDealWithUniqueCode(String uniqueCode) { + this.writeDebuggerLog("============== 根据uniqueCode查询请求配置树形列表 treeDealWith begin ================="); + RequestMappingConfig tempConfig = mappingCMD.selectByUniqueCode(uniqueCode); + return this.dealWith(tempConfig); + } + + /** + * 处理成树形结构 + * + * @param tempConfig 配置列表 + * @return + */ + public RequestMappingConfig dealWith(RequestMappingConfig tempConfig) { + this.writeDebuggerLog("查询到的请求配置列表 query RequestMappingConfig list >>>" + JSON.toJSONString(tempConfig)); + List mappingDetails = tempConfig.getConfigDetail(); + List subMappingDetailList = new ArrayList<>(); + // 过滤出指定节点的子节点,并返回除去子节点之外的节点列表 + List collect = this.filterList(mappingDetails, subMappingDetailList, "rootNode"); + // 将数据库查询出来的信息赋值给要返回的配置信息树 + RequestMappingConfig requestMappingConfig = new RequestMappingConfig(); + requestMappingConfig.setRequestUrl(tempConfig.getRequestUrl()); + requestMappingConfig.setWorkflow(tempConfig.getWorkflow()); + requestMappingConfig.setResponseMappingList(tempConfig.getResponseMappingList()); + requestMappingConfig.setRelationWorkFlow(tempConfig.getRelationWorkFlow()); + requestMappingConfig.setCusWhereSql(tempConfig.getCusWhereSql()); + List mappingDetailList = new ArrayList<>(); + // 循环判断根节点 + for (MappingDetail mappingDetail : collect) { + String paramType = mappingDetail.getParamType(); + ParamTypeEnum anEnum = ParamTypeEnum.getEnum(paramType); + if (ParamTypeEnum.OBJECT == anEnum || ParamTypeEnum.LIST == anEnum) { + List childList = new ArrayList<>(); + mappingDetail.setChildList(childList); + this.getChildList(mappingDetail, mappingDetails, childList); + } + mappingDetailList.add(mappingDetail); + } + requestMappingConfig.setConfigDetail(mappingDetailList); + this.writeDebuggerLog("通过处理后得到的树形参数列表 deal with tree >>>" + JSON.toJSONString(requestMappingConfig)); + return requestMappingConfig; + } + + /** + * 通过递归的方式设置子节点信息 + * + * @param mappingDetail 当前节点 + * @param mappingDetailList 所有节点 + * @param childList 子节点 + */ + private void getChildList(MappingDetail mappingDetail, List mappingDetailList, List childList) { + String paramName = mappingDetail.getParamName(); + String paramType = mappingDetail.getParamType(); + if ("5".equals(paramType) || "6".equals(paramType)) { + List list = new ArrayList<>(); + mappingDetail.setChildList(list); + List subMappingDetailList = new ArrayList<>(); + List collect = this.filterList(mappingDetailList, subMappingDetailList, paramName); + for (MappingDetail detail : collect) { + this.getChildList(detail, subMappingDetailList, list); + } + } + childList.add(mappingDetail); + } + + /** + * 过滤list集合信息 + * + * @param mappingDetailList 原始集合 + * @param subMappingDetailList 过滤后集合 + * @param paramName 过滤信息 + * @return + */ + private List filterList(List mappingDetailList, List subMappingDetailList, String paramName) { + List tempList = new ArrayList<>(); + for (MappingDetail mappingDetail : mappingDetailList) { + String belongTo = mappingDetail.getBelongTo(); + if (paramName.equals(belongTo)) { + tempList.add(mappingDetail); + } else { + subMappingDetailList.add(mappingDetail); + } + } + return tempList; + } + + /** + * 解析请求参数配置树,转换成请求参数 + * + * @param recordSet 主表数据结果集 + * @param requestMappingConfig 配置树 + * @return + */ + public Map getRequestParam(RecordSet recordSet, RequestMappingConfig requestMappingConfig) { + this.fileInputStreams.clear(); + this.multipartFileList.clear(); + this.fileNames.clear(); + Map requestParam = new HashMap<>(); + List configDetail = requestMappingConfig.getConfigDetail(); + Map mainMap = getMapMapping(recordSet); + this.objValueDeal(mainMap, null, configDetail, requestParam); + return requestParam; + } + + /** + * 解析请求参数配置树,转换成请求参数 + * + * @param recordSet 主表数据结果集 + * @param requestMappingConfig 配置树 + * @param relationRs 关联表数据 + * @return + */ + public Map getRequestParamsByRelationWorkFlow(RecordSet recordSet, RequestMappingConfig requestMappingConfig, RecordSet relationRs, String sql) { + this.fileInputStreams.clear(); + this.multipartFileList.clear(); + this.fileNames.clear(); + Map requestParam = new HashMap<>(); + List configDetail = requestMappingConfig.getConfigDetail(); + Map mainMap = getMapMapping(recordSet); + tempRs = new RecordSet(); + tempRs.executeQuery(sql); + tempRs.next(); + this.objValueDeal(mainMap, null, relationRs, configDetail, requestParam); + return requestParam; + } + + /** + * 解析请求参数配置树,转换成请求参数 + * + * @param recordSet 主表数据结果集 + * @param requestMappingConfig 配置树 + * @return + */ + public List getRequestListParam(RecordSet recordSet, RequestMappingConfig requestMappingConfig) { + this.fileInputStreams.clear(); + this.multipartFileList.clear(); + this.fileNames.clear(); + Map requestParam = new HashMap<>(); + List configDetail = requestMappingConfig.getConfigDetail(); + Map mainMap = getMapMapping(recordSet); + this.objValueDeal(mainMap, null, configDetail, requestParam); + List rootList = (List) requestParam.get("rootList"); + return rootList; + } + + /** + * 解析请求参数配置树,转换成请求参数 + * + * @param recordSet 主表数据结果集 + * @param detailRecordSet 明细表数据集 + * @param requestMappingConfig 配置树 + * @return + */ + public List> getRequestParams(RecordSet recordSet, RecordSet detailRecordSet, RequestMappingConfig requestMappingConfig) { + this.fileInputStreams.clear(); + this.multipartFileList.clear(); + this.fileNames.clear(); + List> list = new ArrayList<>(); + while (detailRecordSet.next()) { + Map requestParam = new HashMap<>(); + List configDetail = requestMappingConfig.getConfigDetail(); + Map mainMap = getMapMapping(recordSet); + Map detailMap = getMapMapping(detailRecordSet); + this.objValueDeal(mainMap, detailMap, configDetail, requestParam); + list.add(requestParam); + } + return list; + } + + /** + * 对象类型处理 + * + * @param mainMap 主表数据结果集 + * @param detailMap 明细数据结果集 + * @param configDetail 配置列表集合 + * @param requestParam 节点参数 + */ + private void objValueDeal(Map mainMap, Map detailMap, List configDetail, Map requestParam) { + for (MappingDetail mappingDetail : configDetail) { + String paramType = mappingDetail.getParamType(); + ParamTypeEnum anEnum = ParamTypeEnum.getEnum(paramType); + String paramName = mappingDetail.getParamName(); + // 5为对象类型 + if (ParamTypeEnum.OBJECT == anEnum) { + List childList = mappingDetail.getChildList(); + Map map = new HashMap<>(); + requestParam.put(paramName, map); + this.objValueDeal(mainMap, detailMap, childList, map); + } + // 6为List类型 + else if (ParamTypeEnum.LIST == anEnum) { + String childType = mappingDetail.getChildType(); + List childList = mappingDetail.getChildList(); + List list = new ArrayList<>(); + requestParam.put(paramName, list); + this.listValueDeal(mainMap, childList, list, mappingDetail); + List tempList = new ArrayList(); + for (Object o : list) { + if (o instanceof Map) { +// map处理 key->1的类型 + Map mapItem = (Map) o; + Map> tempMap = new HashMap<>(8); + for (Map.Entry entry : mapItem.entrySet()) { + String key = entry.getKey(); + String pattern = "(?\\S+)->(\\[(?[0-9]+)])"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(key); + Object value = entry.getValue(); + if (matcher.find()) { + String tempKey = matcher.group("key"); + if (key.endsWith("_")) { + tempKey = tempKey + "_"; + } + ListMapIndexValue listMapIndexValue = new ListMapIndexValue(); + listMapIndexValue.setValue(value); + listMapIndexValue.setKey(tempKey); + String index = matcher.group("index"); + List listMapIndexValues = tempMap.get(index); + if (null == listMapIndexValues) { + listMapIndexValues = new ArrayList<>(); + } + listMapIndexValues.add(listMapIndexValue); + tempMap.put(index, listMapIndexValues); + } else { + ListMapIndexValue listMapIndexValue = new ListMapIndexValue(); + listMapIndexValue.setValue(value); + listMapIndexValue.setKey(key); + List listMapIndexValues = tempMap.get("default"); + if (null == listMapIndexValues) { + listMapIndexValues = new ArrayList<>(); + } + listMapIndexValues.add(listMapIndexValue); + tempMap.put("default", listMapIndexValues); + } + } + for (Map.Entry> entrty : tempMap.entrySet()) { + Map map = new HashMap<>(); + List valueList = entrty.getValue(); + for (ListMapIndexValue listMapIndexValue : valueList) { + map.put(listMapIndexValue.getKey(), listMapIndexValue.getValue()); + } + tempList.add(map); + } + } + } +// tempList.addAll(list); + requestParam.put(paramName, tempList); +// if (!tempList.isEmpty()) { +// requestParam.put(paramName, tempList); +// } + } else { + Object value = this.normalValueDeal(mainMap, detailMap, mappingDetail); + if (!Objects.isNull(value)) { + requestParam.put(paramName, value); + } + } + } + } + + /** + * 对象类型处理 方法重载 + * + * @param mainMap 主表数据结果集 + * @param detailMap 明细数据结果集 + * @param configDetail 配置列表集合 + * @param requestParam 节点参数 + * @auhor XuanRan.Wang + */ + private void objValueDeal(Map mainMap, Map detailMap, RecordSet relationRs, List configDetail, Map requestParam) { + for (MappingDetail mappingDetail : configDetail) { + String paramType = mappingDetail.getParamType(); + ParamTypeEnum anEnum = ParamTypeEnum.getEnum(paramType); + String paramName = mappingDetail.getParamName(); + // 5为对象类型 + if (ParamTypeEnum.OBJECT == anEnum) { + List childList = mappingDetail.getChildList(); + Map map = new HashMap<>(); + requestParam.put(paramName, map); + this.objValueDeal(mainMap, detailMap, relationRs, childList, map); + } + // 6为List类型 + else if (ParamTypeEnum.LIST == anEnum) { + String childType = mappingDetail.getChildType(); + List childList = mappingDetail.getChildList(); + List list = new ArrayList<>(); + requestParam.put(paramName, list); + this.listValueDeal(mainMap, childList, list, mappingDetail, relationRs); + List tempList = new ArrayList(); + for (Object o : list) { + if (o instanceof Map) { +// map处理 + Map mapItem = (Map) o; + Map> tempMap = new HashMap<>(8); + for (Map.Entry entry : mapItem.entrySet()) { + String key = entry.getKey(); + String pattern = "(?\\S+)->(\\[(?[0-9]+)])"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(key); + Object value = entry.getValue(); + if (matcher.find()) { + String tempKey = matcher.group("key"); + if (key.endsWith("_")) { + tempKey = tempKey + "_"; + } + ListMapIndexValue listMapIndexValue = new ListMapIndexValue(); + listMapIndexValue.setValue(value); + listMapIndexValue.setKey(tempKey); + String index = matcher.group("index"); + List listMapIndexValues = tempMap.get(index); + if (null == listMapIndexValues) { + listMapIndexValues = new ArrayList<>(); + } + listMapIndexValues.add(listMapIndexValue); + tempMap.put(index, listMapIndexValues); + } else { + ListMapIndexValue listMapIndexValue = new ListMapIndexValue(); + listMapIndexValue.setValue(value); + listMapIndexValue.setKey(key); + List listMapIndexValues = tempMap.get("default"); + if (null == listMapIndexValues) { + listMapIndexValues = new ArrayList<>(); + } + listMapIndexValues.add(listMapIndexValue); + tempMap.put("default", listMapIndexValues); + } + } + for (Map.Entry> entrty : tempMap.entrySet()) { + Map map = new HashMap<>(); + List valueList = entrty.getValue(); + for (ListMapIndexValue listMapIndexValue : valueList) { + map.put(listMapIndexValue.getKey(), listMapIndexValue.getValue()); + } + tempList.add(map); + } + } + } +// tempList.addAll(list); + requestParam.put(paramName, tempList); +// if (!tempList.isEmpty()) { +// requestParam.put(paramName, tempList); +// } + } else { + Object value = this.normalValueDeal(mainMap, detailMap, relationRs, mappingDetail); + if (!Objects.isNull(value)) { + requestParam.put(paramName, value); + } + } + } + } + + /** + * 普通类型处理 + * + * @param mainMap 主表数据结果集 + * @param detailMap 明细数据结果集 + * @param mappingDetail 配置节点信息 + * @return + */ + private Object normalValueDeal(Map mainMap, Map detailMap, MappingDetail mappingDetail) { + + String paramType = mappingDetail.getParamType(); + ParamTypeEnum typeEnum = ParamTypeEnum.getEnum(paramType); + String getValueType = mappingDetail.getGetValueType(); + GetValueTypeEnum getValueTypeEnum = GetValueTypeEnum.getEnum(getValueType); + String valueContext = mappingDetail.getValueContext(); + String childSource = mappingDetail.getDataSource(); + String paramName = mappingDetail.getParamName(); + Object value = ""; + switch (getValueTypeEnum) { + // 流程字段 + case WORKFLOW_FIELD: { + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String fieldName = fieldMassage.getFieldName().toLowerCase(); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else { + value = Util.null2String(mainMap.get(fieldName)); + } + } + break; + // 默认值 + case DEFAULT_VALUE: { + value = valueContext; + } + break; + // 当前时间 + case CURRENT_TIME: { + value = new Date(); + } + break; + // 自定义sql查询 + case CUS_SQL: { + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String tempValue = ""; + int detailId = -1; + if (fieldMassage != null) { + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + tempValue = Util.null2String(detailMap.get(fieldName)); + detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1); + } else { + tempValue = Util.null2String(mainMap.get(fieldName)); + } + } + String requestId = Util.null2String(mainMap.get("requestid")); + tempValue = "'" + tempValue + "'"; + value = this.getValueByChangeRule(valueContext, tempValue, requestId, detailId); + } + break; + // requestId + case REQUEST_ID: { + value = Util.null2String(mainMap.get("requestid")); + } + break; + // 数据id + case MAIN_DATA_ID: { + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get("id")); + } else { + value = Util.null2String(mainMap.get("id")); + } +// value = Util.null2String(main.getString("id")); + } + break; + // 随机数 + case RANDOM: { + int bit = Util.getIntValue(valueContext, 10); + value = this.getGUID(bit); + } + break; + // 附件 + case ATTACHMENT: { + /*int imageFileId = Util.getIntValue(String.valueOf(value)); + InputStream inputStream = ImageFileManager.getInputStreamById(imageFileId); + String fileName = this.getFileNameById(imageFileId); + fileInputStreams.add(inputStream); + fileNames.add(fileName);*/ + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else { + value = Util.null2String(mainMap.get(fieldName)); + } + String fileIds = Util.null2String(value); + if ("".equals(fileIds)) { + return null; + } + List docImageFiles = mappingCMD.selectDocImageFileList(fileIds); + for (DocImageFile docImageFile : docImageFiles) { + MultipartFile multipartFile = new MultipartFile(); + InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId()); + multipartFile.setFileKey(paramName); + multipartFile.setStream(fileInputStream); + multipartFile.setFileName(docImageFile.getImageFileName()); + multipartFile.setFileSize(docImageFile.getFileSize() / 1024); + multipartFileList.add(multipartFile); + } + return null; + } +// 自定义接口 + case CUS_INTERFACE: { + if (null == valueContext || valueContext.length() == 0) { + } else { + Map pathParamMap = new HashMap<>(8); + CusInterfaceGetValue o = getCusInterfaceObj(valueContext, CusInterfaceGetValue.class, pathParamMap); + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) { + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else { + value = Util.null2String(mainMap.get(fieldName)); + } + } + value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap); + } + } + break; + case CUS_FIELD: { + value = detailMap.get(valueContext.trim()); + } + break; + default: + throw new ValueDealException("不支持的取值方式"); + } + switch (typeEnum) { + // String类型 + case STRING: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + value = Util.null2String(String.valueOf(value)); + } + break; + // int类型 + case INT: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = -1; + break; + } + value = Util.getIntValue(String.valueOf(value)); + } + break; + // double类型 + case DOUBLE: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = 0.00; + break; + } + value = Util.getDoubleValue(String.valueOf(value)); + } + break; + // 日期类型 + case DATE: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd"); + } catch (Exception e) { + this.writeDebuggerLog("时间处理异常:" + e); + throw new ValueDealException("时间处理异常:参数>>" + paramName); + } + } + break; + // 时间日期类型 + case DATE_TIME: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss"); + } catch (Exception e) { + this.writeDebuggerLog("时间处理异常:" + e); + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e); + } + } + break; + // 自定义时间格式化类型 + case CUS_DATE_STR: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + forMatString = valueContext; + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, forMatString); + } catch (Exception e) { + this.writeDebuggerLog("时间处理异常:" + e); + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + // 时间戳类型 + case TIME_STAMP: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = date.getTime(); + } catch (Exception e) { + this.writeDebuggerLog("时间处理异常:" + e); + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + case Boolean: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = false; + break; + } + value = Boolean.valueOf(String.valueOf(value)); + } + break; + default: + return value; + } + + return value; + } + + /** + * 普通类型处理 + * + * @param mainMap 主表数据结果集 + * @param detailMap 明细数据结果集 + * @param mappingDetail 配置节点信息 + * @param relationRs 关联流程数据集合 + * @return + */ + private Object normalValueDeal(Map mainMap, Map detailMap, RecordSet relationRs, MappingDetail mappingDetail) { + String paramType = mappingDetail.getParamType(); + ParamTypeEnum typeEnum = ParamTypeEnum.getEnum(paramType); + String getValueType = mappingDetail.getGetValueType(); + GetValueTypeEnum getValueTypeEnum = GetValueTypeEnum.getEnum(getValueType); + String valueContext = mappingDetail.getValueContext(); + String childSource = mappingDetail.getDataSource(); + String paramName = mappingDetail.getParamName(); + Object value = ""; + switch (getValueTypeEnum) { + // 流程字段 + case WORKFLOW_FIELD: { + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String fieldName = fieldMassage.getFieldName().toLowerCase(); + this.writeDebuggerLog("fieldName:" + fieldName); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else if ("0".equals(childSource)) { + value = Util.null2String(mainMap.get(fieldName)); + } else { + value = Util.null2String(relationRs.getString(fieldName)); + } + if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) { + writeDebuggerLog("主表取关联流程字段 => " + paramName); + value = Util.null2String(tempRs.getString(fieldName)); + } + } + break; + // 默认值 + case DEFAULT_VALUE: { + value = valueContext; + } + break; + // 当前时间 + case CURRENT_TIME: { + value = new Date(); + } + break; + // 自定义sql查询 + case CUS_SQL: { + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String tempValue = ""; + String requestId = Util.null2String(mainMap.get("requestid")); + int detailId = -1; + if (fieldMassage != null) { + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + tempValue = Util.null2String(detailMap.get(fieldName)); + // 明细 + detailId = Util.getIntValue(Util.null2String(detailMap.get("id")), -1); + } else if ("0".equals(childSource)) { + tempValue = Util.null2String(mainMap.get(fieldName)); + } else { + tempValue = Util.null2String(relationRs.getString(fieldName)); + requestId = Util.null2String(relationRs.getString("requestid")); + } + if ("rootNode".equals(mappingDetail.getBelongTo()) && "2".equals(childSource)) { + writeDebuggerLog("主表取关联流程字段 => " + paramName); + tempValue = Util.null2String(tempRs.getString(fieldName)); + } + } + tempValue = "'" + tempValue + "'"; + value = this.getValueByChangeRule(valueContext, tempValue, requestId, detailId); + } + break; + // requestId + case REQUEST_ID: { + value = Util.null2String(mainMap.get("requestid")); + if ("2".equals(childSource)) { + value = Util.null2String(relationRs.getString("requestid")); + } + } + break; + // 数据id + case MAIN_DATA_ID: { + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get("id")); + } else if ("0".equals(childSource)) { + value = Util.null2String(mainMap.get("id")); + } else { + value = Util.null2String(relationRs.getString("id")); + } + } + break; + // 随机数 + case RANDOM: { + int bit = Util.getIntValue(valueContext, 10); + value = this.getGUID(bit); + } + break; + // 附件 + case ATTACHMENT: { + /*int imageFileId = Util.getIntValue(String.valueOf(value)); + InputStream inputStream = ImageFileManager.getInputStreamById(imageFileId); + String fileName = this.getFileNameById(imageFileId); + fileInputStreams.add(inputStream); + fileNames.add(fileName);*/ + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else { + value = Util.null2String(mainMap.get(fieldName)); + } + String fileIds = Util.null2String(value); + if ("".equals(fileIds)) { + return null; + } + List docImageFiles = mappingCMD.selectDocImageFileList(fileIds); + for (DocImageFile docImageFile : docImageFiles) { + MultipartFile multipartFile = new MultipartFile(); + InputStream fileInputStream = ImageFileManager.getInputStreamById(docImageFile.getImageFileId()); + multipartFile.setFileKey(paramName); + multipartFile.setStream(fileInputStream); + multipartFile.setFileName(docImageFile.getImageFileName()); + multipartFile.setFileSize(docImageFile.getFileSize() / 1024); + multipartFileList.add(multipartFile); + } + return null; + } +// 自定义接口 + case CUS_INTERFACE: { + if (null == valueContext || valueContext.length() == 0) { + } else { + Map pathParamMap = new HashMap<>(8); + CusInterfaceGetValue o = getCusInterfaceObj(valueContext, CusInterfaceGetValue.class, pathParamMap); + FieldMessage fieldMassage = mappingDetail.getFieldMassage(); + if (null != fieldMassage && !StringUtils.isEmpty(fieldMassage.getFieldName())) { + String fieldName = fieldMassage.getFieldName(); + if ("1".equals(childSource)) { + value = Util.null2String(detailMap.get(fieldName)); + } else { + value = Util.null2String(mainMap.get(fieldName)); + } + } + value = o.execute(mainMap, detailMap, String.valueOf(value == null ? "" : value), pathParamMap); + } + } + break; + case CUS_FIELD: { + value = detailMap.get(valueContext.trim()); + if ("2".equals(childSource)) { + value = Util.null2String(relationRs.getString(valueContext.trim())); + } + } + break; + default: + throw new ValueDealException("不支持的取值方式"); + } + this.writeDebuggerLog("value1:" + value); + switch (typeEnum) { + // String类型 + case STRING: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + value = Util.null2String(String.valueOf(value)); + } + break; + // int类型 + case INT: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = -1; + break; + } + value = Util.getIntValue(String.valueOf(value)); + } + break; + // double类型 + case DOUBLE: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = 0.00; + break; + } + value = Util.getDoubleValue(String.valueOf(value)); + } + break; + // 日期类型 + case DATE: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd"); + } catch (Exception e) { + throw new ValueDealException("时间处理异常:参数>>" + paramName); + } + + } + break; + // 时间日期类型 + case DATE_TIME: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, "yyyy-MM-dd HH:mm:ss"); + } catch (Exception e) { + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e); + } + } + break; + // 自定义时间格式化类型 + case CUS_DATE_STR: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + forMatString = valueContext; + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = this.diyDateFortMat(date, forMatString); + } catch (Exception e) { + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + // 时间戳类型 + case TIME_STAMP: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = ""; + break; + } + try { + Date date = value instanceof Date ? (Date) value : parseDate(String.valueOf(value)); + value = date.getTime(); + } catch (Exception e) { + throw new ValueDealException("时间处理异常:参数>>" + paramName + " 异常信息:" + e.getMessage()); + } + } + break; + case Boolean: { + if (null == value || Strings.isNullOrEmpty(String.valueOf(value))) { + value = false; + break; + } + value = Boolean.valueOf(String.valueOf(value)); + } + break; + default: + return value; + } + return value; + } + + /** + * list类型处理 + * + * @param mainMap 主表数据集 + * @param childList 子节点配置列表 + * @param list 子节点参数 + * @param detail 当前节点 + */ + private void listValueDeal(Map mainMap, List childList, List list, MappingDetail detail) throws ValueDealException { + String childSource = detail.getDataSource(); + String childType = detail.getChildType(); + if ("1".equals(childSource)) { + int mainId = Util.getIntValue(Util.null2String(mainMap.get("id"))); + int detailId = Util.getIntValue(detail.getDetailId()); + String detailTableName = mainTable + "_dt" + detailId; + // 自定义sql参数 + String cusWhere = Util.null2String(detail.getCusWhereSql()); + if (StringUtils.isNotBlank(cusWhere)) { + cusWhere = sbc2dbcCase(cusWhere); + } + String querySql = "select * from " + detailTableName + " where mainid = ? " + cusWhere; + RecordSet recordSetDetail = new RecordSet(); + recordSetDetail.executeQuery(querySql, mainId); + while (recordSetDetail.next()) { + Map detailMap = getMapMapping(recordSetDetail); + if ("0".equals(childType)) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, detailMap, childList, item); + } else { + for (MappingDetail mappingDetail : childList) { + Object o = this.normalValueDeal(mainMap, detailMap, mappingDetail); + list.add(o); + } + } + } + } else if ("0".equals(childSource)) { + if ("0".equals(childType)) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, null, childList, item); + } else { + for (MappingDetail mappingDetail : childList) { + Object o = this.normalValueDeal(mainMap, null, mappingDetail); + list.add(o); + } + } +// for (MappingDetail mappingDetail : childList) { +// Object o = this.normalValueDeal(recordSet, null, mappingDetail); +// list.add(o); +// } + } else if ("2".equals(childSource)) { + // 自定义接口 + Map pathParamMap = new HashMap<>(8); + CusInterfaceListValue cusInterfaceObj = getCusInterfaceObj(detail.getDetailId(), CusInterfaceListValue.class, pathParamMap); + List resultList = cusInterfaceObj.execute(pathParamMap, mainMap, mainTable); + if (null == resultList || resultList.isEmpty()) { + return; + } + if ("0".equals(childType)) { + + // 对象类型 + for (Object o : resultList) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, (Map) o, childList, item); + } + } else { + // 普通数据类型 + for (Object o : resultList) { + for (MappingDetail mappingDetail : childList) { + if (o instanceof Map) { + Object value = this.normalValueDeal(mainMap, (Map) o, mappingDetail); + list.add(value); + } else { + list.add(o); + } + } + } + } + } + } + + /** + * list类型处理 + * + * @param mainMap 主表数据集 + * @param childList 子节点配置列表 + * @param list 子节点参数 + * @param detail 当前节点 + * @param relationRs 关联流程数据集合 + */ + private void listValueDeal(Map mainMap, List childList, List list, MappingDetail detail, RecordSet relationRs) throws ValueDealException { + String childSource = detail.getDataSource(); + String childType = detail.getChildType(); + if ("1".equals(childSource)) { + int mainId = Util.getIntValue(Util.null2String(mainMap.get("id"))); + int detailId = Util.getIntValue(detail.getDetailId()); + String detailTableName = mainTable + "_dt" + detailId; + String querySql = "select * from " + detailTableName + " where mainid = ?"; + RecordSet recordSetDetail = new RecordSet(); + recordSetDetail.executeQuery(querySql, mainId); + while (recordSetDetail.next() && relationRs.next()) { + Map detailMap = getMapMapping(recordSetDetail); + if ("0".equals(childType)) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, detailMap, relationRs, childList, item); + } else { + for (MappingDetail mappingDetail : childList) { + Object o = this.normalValueDeal(mainMap, detailMap, relationRs, mappingDetail); + list.add(o); + } + } + } + } else if ("0".equals(childSource)) { + if ("0".equals(childType)) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, null, relationRs, childList, item); + } else { + for (MappingDetail mappingDetail : childList) { + Object o = this.normalValueDeal(mainMap, null, relationRs, mappingDetail); + list.add(o); + } + } +// for (MappingDetail mappingDetail : childList) { +// Object o = this.normalValueDeal(recordSet, null, mappingDetail); +// list.add(o); +// } + } else if ("2".equals(childSource)) { + // 自定义接口 + Map pathParamMap = new HashMap<>(8); + CusInterfaceListValue cusInterfaceObj = getCusInterfaceObj(detail.getDetailId(), CusInterfaceListValue.class, pathParamMap); + List resultList = cusInterfaceObj.execute(pathParamMap, mainMap, mainTable); + if (null == resultList || resultList.isEmpty()) { + return; + } + if ("0".equals(childType)) { + + // 对象类型 + for (Object o : resultList) { + Map item = new HashMap<>(); + list.add(item); + this.objValueDeal(mainMap, (Map) o, childList, item); + } + } else { + // 普通数据类型 + for (Object o : resultList) { + for (MappingDetail mappingDetail : childList) { + if (o instanceof Map) { + Object value = this.normalValueDeal(mainMap, (Map) o, mappingDetail); + list.add(value); + } else { + list.add(o); + } + } + } + } + } + } + + /** + * 自定义时间格式化 + * + * @param date 日期 + * @param tempStr 格式化字符串 + * @return + */ + private String diyDateFortMat(Date date, String tempStr) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(tempStr); + return simpleDateFormat.format(date); + } + + private String getGUID(int bit) { + + StringBuilder uid = new StringBuilder(); + + // 产生16位的强随机数 + + Random rd = new SecureRandom(); + + for (int i = 0; i < bit; i++) { + + // 产生0-2的3位随机数 + int type = rd.nextInt(3); + + switch (type) { + case 0: + // 0-9的随机数 + uid.append(rd.nextInt(10)); + break; + case 1: + // ASCII在65-90之间为大写,获取大写随机 + uid.append((char) (rd.nextInt(25) + 65)); + break; + case 2: + // ASCII在97-122之间为小写,获取小写随机 + uid.append((char) (rd.nextInt(25) + 97)); + break; + default: + break; + } + } + return uid.toString(); + } + + /** + * 通过文件id获取文件名 + * + * @param fileId 文件id + * @return + */ + public String getFileNameById(int fileId) { + String fileName = ""; + String querySql = "select filename from docimagefile where imgagefileid = ?"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(querySql, fileId); + if (recordSet.next()) { + fileName = recordSet.getString("filename"); + } + return fileName; + } + + public T getCusInterfaceObj(String path, Class clazz, Map pathParamMap) { + path = sbc2dbcCase(path); + String[] split = path.split("\\?"); + String classPath = split[0]; + String paramStr = ""; + if (split.length > 1) { + paramStr = Arrays.stream(split).skip(1).collect(Collectors.joining("")); + } +/* 获取?后的参数:"weaver.aiyh_jitu.pushdata.service.toones.GetRequestValueCusGetValueImpl?" + + "requestType=get&apiOnlyMark=getAssign&valueKey=data&assign=#{main.zd2}&" + + "#processorClass=weaver.aiyh_jitu.pushdata.service.toones.GetAssignProcessorProcessorImpl" + + "&afterProcessor.hrmId=#{main.zd2}&beforeProcessor.hrmId=#{main.zd2}&高=udh高殿下g" + + "&assignValue=#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})}&hah=haode"; + 最终获取到的map,如下 + key:requestType + value:get + key:apiOnlyMark + value:getAssign + key:valueKey + value:data + key:assign + value:#{main.zd2} + key:#processorClass + value:weaver.aiyh_jitu.pushdata.service.toones.GetAssignProcessorProcessorImpl + key:afterProcessor.hrmId + value:#{main.zd2} + key:beforeProcessor.hrmId + value:#{main.zd2} + key:高 + value:udh高殿下g + key:assignValue + value:#sql{select workcode from hrmresource where id = #{main.zd1} and test = #{h-hah} and a in (${hrmids})} + key:hah + value:haode*/ +// 最终通过反射调用weaver.aiyh_jitu.pushdata.service.GetAssignProcessorProcessorImpl类,将参数传递给这个类, 使用``包裹的字符串会被解析为一个字符串 + String pattern = "&?(?([#.\\w\\u4E00-\\u9FA5]+))=" + + "(?((`([():/\\-&$#={ }.\\w\\u4E00-\\u9FA5?]*)`)|" + + "((#(\\{|sql\\{))?([():/\\-$#={ }.\\w\\u4E00-\\u9FA5?]+)?}?)))&?"; + Pattern compile = Pattern.compile(pattern); + Matcher matcher = compile.matcher(paramStr); + 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); + } + Class aClass; + try { + aClass = Class.forName(classPath); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("未能找到自定义接口:" + classPath); + } + if (!clazz.isAssignableFrom(aClass)) { + throw new IllegalArgumentException("自定义接口:" + classPath + " 不是" + + clazz.getName() + "的子类或实现类!"); + } + Constructor constructor; + try { + constructor = aClass.getConstructor(); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(classPath + "没有空参构造方法,无法获取构造方法对象!"); + } + T o; + try { + o = (T) constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("无法构造" + classPath + "对象!"); + } + return o; + } + +} diff --git a/src/main/java/weaver/xiao/commons/exception/RequestException.java b/src/main/java/weaver/xiao/commons/exception/RequestException.java new file mode 100644 index 0000000..ecc632d --- /dev/null +++ b/src/main/java/weaver/xiao/commons/exception/RequestException.java @@ -0,0 +1,21 @@ +package weaver.xiao.commons.exception; + +/** + * @author XiaoBokang + * @create 2022/1/12 11:06 + */ + +public class RequestException extends RuntimeException{ + public RequestException(String message){ + super(message); + } + + public RequestException(String message, Throwable cause) { + super(message, cause); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return super.fillInStackTrace(); + } +} diff --git a/src/main/java/weaver/xiao/commons/exception/ValueDealException.java b/src/main/java/weaver/xiao/commons/exception/ValueDealException.java new file mode 100644 index 0000000..ef8cea3 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/exception/ValueDealException.java @@ -0,0 +1,22 @@ +package weaver.xiao.commons.exception; + +/** + * @author XiaoBokang + * @create 2022/1/4 9:50 + */ + +public class ValueDealException extends RuntimeException{ + + public ValueDealException(String message){ + super(message); + } + + public ValueDealException(String message, Throwable cause) { + super(message, cause); + } + + @Override + public synchronized Throwable fillInStackTrace() { + return super.fillInStackTrace(); + } +} diff --git a/src/main/java/weaver/xiao/commons/utils/JsonResult.java b/src/main/java/weaver/xiao/commons/utils/JsonResult.java new file mode 100644 index 0000000..61f2b1e --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/JsonResult.java @@ -0,0 +1,70 @@ +package weaver.xiao.commons.utils; + +import com.alibaba.fastjson.JSONObject; + + +/** + * @author XiaoBokang + * @create 2021/9/9 19:33 + */ + +public class JsonResult { + + private Integer code; + private String message; + private Object Data; + + public JsonResult(Integer code, String message, Object data) { + this.code = code; + this.message = message; + Data = data; + } + + public static String success(String message){ + return JSONObject.toJSONString(new JsonResult(200,message,null)); + } + public static String success(){ + return JSONObject.toJSONString(new JsonResult(200,"success",null)); + } + public static String successData(String message,Object data){ + return JSONObject.toJSONString(new JsonResult(200,message,data)); + } + public static String successData(Object data){ + return JSONObject.toJSONString(new JsonResult(200,"success",data)); + } + + public static String error(int code,String message){ + return JSONObject.toJSONString(new JsonResult(code,message,null)); + } + public static String error(String message){ + return JSONObject.toJSONString(new JsonResult(500,message,null)); + } + public static String error(){ + return JSONObject.toJSONString(new JsonResult(500,"fail",null)); + } + + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Object getData() { + return Data; + } + + public void setData(Object data) { + Data = data; + } +} diff --git a/src/main/java/weaver/xiao/commons/utils/LogUtil.java b/src/main/java/weaver/xiao/commons/utils/LogUtil.java new file mode 100644 index 0000000..56a3211 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/LogUtil.java @@ -0,0 +1,73 @@ +package weaver.xiao.commons.utils; + +import org.apache.log4j.*; + +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * @author XiaoBokang + * @create 2022/3/3 14:16 + */ + +public class LogUtil { + + private static volatile Logger log = null; + + public static Logger getLogger(){ + return LogUtil.getLogger(weaver.general.GCONST.getLogPath() + "cus" + File.separator + "util_cus" + File.separator + "cus.log"); + } + + /** + * 获取日志对象 + * @return 日志对象 + */ + public static Logger getLogger(String file) { + if (log == null) { + synchronized (LogUtil.class) { + if (log == null) { + DailyRollingFileAppender appender = new DailyRollingFileAppender(); + log = Logger.getLogger("xbk_cus"); + appender.setName("xbk_cus"); + appender.setEncoding("UTF-8"); + appender.setDatePattern("'_'yyyyMMdd'.log'"); + appender.setFile(file); + appender.setThreshold(Priority.DEBUG); + appender.setLayout(new PatternLayout("[%-5p] [%d{yyyy-MM-dd HH:mm:ss,SSS}] [%r] [Thread:%t][%F.%M:%L] ==> : %m %x %n")); + appender.setAppend(true); + appender.activateOptions(); + log.addAppender(appender); + boolean enableDebug = true; + if (!enableDebug) { + log.setLevel(Level.INFO); + } + } + } + } + return log; + } + + public static Logger getSqlLogger(){ + return LogUtil.getLogger(weaver.general.GCONST.getLogPath() + "cus" + File.separator + "sql" + File.separator + "cussql.log"); + } + + + /** + * 获取堆栈中的异常信息 + * @param throwable 异常 + * @return + */ + public static String getExceptionStr(Throwable throwable){ + StringWriter stringWriter = new StringWriter(); + throwable.printStackTrace(new PrintWriter(stringWriter,true)); + String s = stringWriter.getBuffer().toString(); + try{ + stringWriter.close(); + }catch (Exception ignored){ + ignored.printStackTrace(); + } + return s; + } + +} diff --git a/src/main/java/weaver/xiao/commons/utils/PreMap.java b/src/main/java/weaver/xiao/commons/utils/PreMap.java new file mode 100644 index 0000000..62c4a0c --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/PreMap.java @@ -0,0 +1,26 @@ +package weaver.xiao.commons.utils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author XiaoBokang + * @create 2021/8/20 14:01 + */ + +public class PreMap extends HashMap implements Map { + + public PreMap(){ + super(); + } + + public static PreMap create(){ + return new PreMap(); + } + + @Override + public PreMap put(String key, Object value){ + super.put(key,value); + return this; + } +} diff --git a/src/main/java/weaver/xiao/commons/utils/PropUtil.java b/src/main/java/weaver/xiao/commons/utils/PropUtil.java new file mode 100644 index 0000000..9a33569 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/PropUtil.java @@ -0,0 +1,57 @@ +package weaver.xiao.commons.utils; + +import weaver.common.util.string.StringUtil; +import weaver.general.GCONST; + +import java.io.*; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * @author XiaoBokang + * @create 2022/3/10 11:13 + */ + +public class PropUtil { + /** + * 通过文件名获取到对应的配置文件map对象 + * @param fileName prop/文件夹下的文件名(不包含.properties) + * @return 配置文件对应的map对象 + */ + public static Map getProperties2Map(String fileName) { + String propertyPath = GCONST.getPropertyPath(); + if (StringUtil.isNullOrEmpty(fileName)) { + return null; + } + if (fileName.contains(".properties")) { + fileName = fileName.replace(".properties", ""); + } + String path = propertyPath + File.separator + fileName + ".properties"; + Properties prop = new Properties(); + Map map = new HashMap<>(); + InputStream inputStream = null; + try { + inputStream = new BufferedInputStream(new FileInputStream(path)); + prop.load(inputStream); + Enumeration enumeration = prop.propertyNames(); + while (enumeration.hasMoreElements()) { + String key = String.valueOf(enumeration.nextElement()); + map.put(key, prop.getProperty(key)); + } + } catch (IOException e) { + throw new RuntimeException("找不到文件:" + path); + } finally { + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return map; + } + +} diff --git a/src/main/java/weaver/xiao/commons/utils/RequestBaseInfo.java b/src/main/java/weaver/xiao/commons/utils/RequestBaseInfo.java new file mode 100644 index 0000000..5d0c65d --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/RequestBaseInfo.java @@ -0,0 +1,59 @@ +package weaver.xiao.commons.utils; + +import lombok.Data; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * @author XiaoBokang + * @create 2021/8/23 16:34 + */ + +@Data +public class RequestBaseInfo{ + + private String type; + private String url; + private Object params; + private InputStream[] inputStreams; + private String[] fileNames; + private String fileField; + private Map headers; + + private static final Map HEADER_NORMAL = new HashMap<>(); + private static final Map PARAMS_NORMAL = new HashMap<>(); + + + public static RequestBaseInfo create(String type, String url){ + return create(type,url,HEADER_NORMAL,PARAMS_NORMAL); + } + + public static RequestBaseInfo create(String type, String url, Map headers){ + return create(type,url,headers,PARAMS_NORMAL); + } + + public static RequestBaseInfo create(String type, String url, Map headers, Object params){ + RequestBaseInfo requestInfo = new RequestBaseInfo(); + requestInfo.setType(type.toUpperCase()); + requestInfo.setUrl(url); + requestInfo.setParams(params); + requestInfo.setHeaders(headers); + return requestInfo; + } + + public static RequestBaseInfo createByFile(String type, String url, Map headers, Object params, InputStream[] inputStreams, String fileField, String[] fileNames){ + RequestBaseInfo requestInfo = new RequestBaseInfo(); + requestInfo.setType(type.toUpperCase()); + requestInfo.setUrl(url); + requestInfo.setParams(params); + requestInfo.setHeaders(headers); + requestInfo.setInputStreams(inputStreams); + requestInfo.setFileNames(fileNames); + requestInfo.setFileField(fileField); + return requestInfo; + } + + +} diff --git a/src/main/java/weaver/xiao/commons/utils/RequestUtil.java b/src/main/java/weaver/xiao/commons/utils/RequestUtil.java new file mode 100644 index 0000000..1b51784 --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/RequestUtil.java @@ -0,0 +1,165 @@ +package weaver.xiao.commons.utils; + +import com.alibaba.fastjson.JSON; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.*; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import weaver.xiao.commons.exception.RequestException; +import weaver.zwl.common.ToolUtil; +import weaver.wechat.request.HttpManager; + +import javax.ws.rs.core.MediaType; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import java.util.Map; + + +/** + * @author XiaoBokang + * @create 2021/8/9 10:09 + */ + +public class RequestUtil { + + public static T apiRequest(RequestBaseInfo requestInfo, Class tClass){ + + Map headers = requestInfo.getHeaders(); + T result = null; + + switch(requestInfo.getType()){ + case "GET" :{ + String sendUrl = serializableUrl(requestInfo.getUrl(), (Map) requestInfo.getParams()); + HttpGet httpGet = new HttpGet(sendUrl); + headers.forEach(httpGet::setHeader); + result = apiSend(httpGet,tClass); + }break; + case "POST" :{ + HttpPost httpPost = new HttpPost(requestInfo.getUrl()); + headers.forEach(httpPost::setHeader); + httpPost.setEntity(new StringEntity(JSON.toJSONString(requestInfo.getParams()),"UTF-8")); + new ToolUtil().writeErrorLog("请求信息:url:"+requestInfo.getUrl()+" params:"+JSON.toJSONString(requestInfo.getParams())); + result = apiSend(httpPost,tClass);}break; + case "PUT" :{ + HttpPut httpPut = new HttpPut(requestInfo.getUrl()); + headers.forEach(httpPut::setHeader); + httpPut.setEntity(new StringEntity(JSON.toJSONString(requestInfo.getParams()),"UTF-8")); + result = apiSend(httpPut,tClass);}break; + } + + return result; + } + + public static T POSTBySerializableUrl(RequestBaseInfo requestInfo, Class tClass){ + T result = null; + Map headers = requestInfo.getHeaders(); + String url = serializableUrl(requestInfo.getUrl(), (Map) requestInfo.getParams()); + HttpPost httpPost = new HttpPost(url); + headers.forEach(httpPost::setHeader); + new ToolUtil().writeErrorLog("请求信息:url:"+requestInfo.getUrl()+" params:"+JSON.toJSONString(requestInfo.getParams())); + result = apiSend(httpPost,tClass); + return result; + } + + public static T apiUploadFileByInputStream(RequestBaseInfo requestInfo, Class tClass){ + Map params = (Map) requestInfo.getParams(); + HttpPost httpPost = new HttpPost(requestInfo.getUrl()); + requestInfo.getHeaders().forEach(httpPost::setHeader); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setCharset(StandardCharsets.UTF_8); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + InputStream[] inputStreams = requestInfo.getInputStreams(); + String[] fileNames = requestInfo.getFileNames(); + for (int i = 0; i < inputStreams.length; i++) { + builder.addBinaryBody(requestInfo.getFileField(),inputStreams[i],ContentType.MULTIPART_FORM_DATA,fileNames[i]); + } + params.forEach((k,v)->{ + builder.addTextBody(k,JSON.toJSONString(v),ContentType.create(MediaType.TEXT_PLAIN,"UTF-8")); + }); + HttpEntity entity = builder.build(); + httpPost.setEntity(entity); + return apiSend(httpPost,tClass); + } + + public static T apiSend( + HttpUriRequest httpRequest, + Class resClass + ){ + DefaultHttpClient httpClient = HttpManager.getHttpClient(); + CloseableHttpResponse execute = null; + T res = null; + try { + new ToolUtil().writeDebuggerLog("开始发送请求:request start -----------------"); + execute = httpClient.execute(httpRequest); + if(execute.getStatusLine().getStatusCode() == 200){ + new ToolUtil().writeDebuggerLog("请求发送成功:request send success -----------------"); + HttpEntity entity = execute.getEntity(); + String response= EntityUtils.toString(entity,"utf-8"); +// ObjectMapper mapper = new ObjectMapper(); +// CollectionType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, Map.class); +// List> list = mapper.readValue(response, listType); +// result.put("res",list); + if(resClass.equals(String.class)){ + return (T) response; + }else { + ObjectMapper objectMapper = new ObjectMapper(); + res = objectMapper.readValue(response, resClass); + } + }else { + HttpEntity entity = execute.getEntity(); + String response = EntityUtils.toString(entity,"utf-8"); + new ToolUtil().writeDebuggerLog("请求状态不为200,返回信息为:"+response); + throw new RequestException("请求状态异常:"+response); + } + } catch (IOException e) { + new ToolUtil().writeDebuggerLog("请求发生异常 request error>>>"+e); + try { + if(execute != null) { + execute.close(); + } + } catch (IOException ioException) { + ioException.printStackTrace(); + } + e.printStackTrace(); + throw new RequestException("请求调用异常:"+e); + } + return res; + } + + public static String serializableUrl(String url,Map params){ + if(params == null || params.isEmpty()){ + return url; + } + url += "?"; + for (Map.Entry entry: params.entrySet()){ + url += entry.getKey() + "=" + entry.getValue() + "&"; + } + return url.substring(0,url.length()-1); + } + + /** + * 获取堆栈中的异常信息 + * @param throwable 异常 + * @return + */ + public static String getExceptionStr(Throwable throwable){ + StringWriter stringWriter = new StringWriter(); + throwable.printStackTrace(new PrintWriter(stringWriter,true)); + String s = stringWriter.getBuffer().toString(); + try{ + stringWriter.close(); + }catch (Exception ignored){ + ignored.printStackTrace(); + } + return s; + } + +} diff --git a/src/main/java/weaver/xiao/commons/utils/SqlUtil.java b/src/main/java/weaver/xiao/commons/utils/SqlUtil.java new file mode 100644 index 0000000..fdb753a --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/SqlUtil.java @@ -0,0 +1,260 @@ +package weaver.xiao.commons.utils; + +import org.apache.log4j.Logger; +import weaver.conn.RecordSet; +import weaver.formmode.data.ModeDataIdUpdate; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.xiao.commons.utils.annotation.SqlFieldMapping; + + +import java.lang.reflect.Field; +import java.util.*; + +/** + * @author XiaoBokang + * @create 2021/12/7 14:19 + */ + +public class SqlUtil { + + private final Logger logger = LogUtil.getSqlLogger(); + ModeDataIdUpdate mdu = ModeDataIdUpdate.getInstance(); + ModeRightInfo mri = new ModeRightInfo(); + + /** + * 通过列名将数据库结果集转换成指定的实体类 + * @param recordSet 数据库结果集 + * @param tClass 实体类文件 + * @param 泛型 + * @return + */ + public T recordSetToEntityByEntity(RecordSet recordSet, Class tClass){ + T res = null; + try{ + String[] columnNames = recordSet.getColumnName(); + if(tClass.equals(Map.class)){ + Map tempRes = new HashMap<>(); + for (String columnName : columnNames) { + tempRes.put(columnName,recordSet.getString(columnName)); + } + res = (T) tempRes; + }else { + Field[] declaredFields = tClass.getDeclaredFields(); + res = tClass.newInstance(); + for (Field field : declaredFields) { + field.setAccessible(true); + SqlFieldMapping annotation = field.getAnnotation(SqlFieldMapping.class); + Class fieldType = field.getType(); + if(annotation != null){ + String value = annotation.value(); + int type = annotation.type(); + Object valueText = null; + switch (type){ + case 1:{ + String tempValue = Util.null2String(recordSet.getString(value)); + valueText = this.getFieldVal(fieldType,tempValue); + }break; + case 2:{ + valueText = this.getFieldVal(fieldType,value); + }break; + } + field.set(res,valueText); + } + } + } + }catch (Exception e){ + logger.info("转换实体类异常:"+e); + } + return res; + } + + /** + * 通过字段类型获取字段的值 + * @param fieldType 字段类型 + * @param tempValue 转换前的字符串值 + * @return + */ + public Object getFieldVal(Class fieldType,String tempValue){ + Object fieldVal = null; + if(fieldType.equals(int.class)){ + fieldVal = Util.getIntValue(tempValue); + }else if(fieldType.equals(String.class)){ + fieldVal = Util.null2String(tempValue); + }else if(fieldType.equals(boolean.class)){ + fieldVal = Boolean.parseBoolean(tempValue); + }else { + fieldVal = ""; + } + return fieldVal; + } + + /** + * 构建更新语句 + * @param tableName 表名 + * @param updateParam 更新参数 + * @param whereParam 条件参数 + * @return + */ + public boolean updateMode(String tableName, Map updateParam, Map whereParam) { + RecordSet recordSet = new RecordSet(); + List paramList = new ArrayList<>(); + String updateSql = buildUpdateSql(tableName, updateParam, whereParam, paramList); + logger.info("向表"+tableName+"更新数据>>>" + updateSql + " param:" + paramList); + boolean updateFlag = recordSet.executeUpdate(updateSql, paramList); + logger.info("更新标识:" + updateFlag); + return updateFlag; + } + + /** + * 构建更新sql语句,收集参数信息 + * @param tableName 表名 + * @param updateParam 更新参数 + * @param whereParam 条件参数 + * @param paramList 参数集合 + * @return + */ + public String buildUpdateSql(String tableName, Map updateParam, Map whereParam,List paramList){ + StringBuilder updateBuilder = new StringBuilder("update "); + updateBuilder.append(tableName).append(" set "); + Set> updateEntries = updateParam.entrySet(); + for (Map.Entry updateEntry : updateEntries) { + updateBuilder.append(updateEntry.getKey()) + .append(" = ?,"); + paramList.add(updateEntry.getValue()); + } + StringBuilder whereBuilder = new StringBuilder(); + Set> whereEntries = whereParam.entrySet(); + for (Map.Entry whereEntry : whereEntries) { + whereBuilder.append(" and ") + .append(whereEntry.getKey()) + .append(" = ? "); + paramList.add(whereEntry.getValue()); + } + String preStr = updateBuilder.substring(0, updateBuilder.length() - 1) + " "; + String fixStr = whereBuilder.toString(); + if(!"".equals(fixStr)){ + fixStr = fixStr.replaceFirst(" and "," where "); + } + return preStr + fixStr; + } + + /** + * 向表插入数据 + * @param tableName 表名 + * @param insertParam 插入参数 + * @return + */ + public boolean insertTable(String tableName, Map insertParam) { + RecordSet recordSet = new RecordSet(); + //构建新建sql语句,收集参数信息 + List paramList = new ArrayList<>(); + String insertSql = buildInsetSql(tableName, insertParam, paramList); + logger.info("向表"+tableName+"插入数据>>>" + insertSql + " param:" + paramList); + boolean flag = recordSet.executeUpdate(insertSql, paramList); + logger.info("插入标识:" + flag); + return flag; + } + + /** + * 构建新建sql语句,收集参数信息 + * @param tableName 表名 + * @param insertParam 插入参数 + * @param paramList 返回数据集合 + * @return + */ + public String buildInsetSql(String tableName, Map insertParam,List paramList){ + StringBuilder suffixBuilder = new StringBuilder(); + StringBuilder prefixBuilder = new StringBuilder(); + prefixBuilder.append("insert into ") + .append(tableName).append("("); + suffixBuilder.append(" values ("); + Set> entries = insertParam.entrySet(); + for (Map.Entry entry : entries) { + String key = entry.getKey(); + Object value = entry.getValue(); + prefixBuilder.append(key).append(","); + suffixBuilder.append("?,"); + paramList.add(value); + } + String suffixString = suffixBuilder.substring(0, suffixBuilder.length() - 1); + String prefixString = prefixBuilder.substring(0, prefixBuilder.length() - 1); + String insertSql = prefixString + ")" + suffixString+")"; + return insertSql; + } + + + /** + * 将接口调用信息插入至建模中 + * @param tableName 表名 + * @param param 插入信息 + * @param modeId 模块id + * @return + */ + public int insertToMode(String tableName,Map param,String modeId){ + logger.info("=====插入建模信息===="); + if(modeId == null || "".equals(modeId)) { + modeId = this.getModeIdByTableName(tableName); + } + logger.info("通过表名获取modeId ==>modeId"+modeId+" tableName==>"+tableName); + Map whereParam = new HashMap<>(); + int dataId = mdu.getModeDataNewId(tableName, Util.getIntValue(modeId,-1), 1, 0, TimeUtil.getCurrentDateString(), TimeUtil.getOnlyCurrentTimeString()); + whereParam.put("id",dataId); + boolean updateFlag = this.updateMode(tableName, param, whereParam); + if(updateFlag){ + mri.rebuildModeDataShareByEdit(1, Util.getIntValue(modeId,-1),dataId); + }else { + logger.info("更新失败,从表==>"+tableName+" 删除数据:"+dataId); + String deleteSql = "delete from "+tableName+" where id = ?"; + RecordSet deleteRecordSet = new RecordSet(); + deleteRecordSet.executeUpdate(deleteSql,dataId); + } + return dataId; + } + + /** + * 将接口调用信息插入至建模中不做权限重构 + * @param tableName 表名 + * @param param 插入信息 + * @param modeId 模块id + * @return + */ + public int insertToModeNoRight(String tableName,Map param,String modeId){ + logger.info("=====插入建模信息===="); + if(modeId == null || "".equals(modeId)) { + modeId = this.getModeIdByTableName(tableName); + } + logger.info("通过表名获取modeId ==>modeId"+modeId+" tableName==>"+tableName); + Map whereParam = new HashMap<>(); + int dataId = mdu.getModeDataNewId(tableName, Util.getIntValue(modeId,-1), 1, 0, TimeUtil.getCurrentDateString(), TimeUtil.getOnlyCurrentTimeString()); + whereParam.put("id",dataId); + boolean updateFlag = this.updateMode(tableName, param, whereParam); + if(updateFlag){ + return dataId; + }else { + logger.info("更新失败,从表==>"+tableName+" 删除数据:"+dataId); + String deleteSql = "delete from "+tableName+" where id = ?"; + RecordSet deleteRecordSet = new RecordSet(); + deleteRecordSet.executeUpdate(deleteSql,dataId); + } + return -1; + } + + /** + * 通过表名查询模块id + * @param tableName 表名 + * @return + */ + public String getModeIdByTableName(String tableName){ + String modeId = ""; + String querySql = "select id from modeinfo where formid = (select id from workflow_bill where tablename = ?)"; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(querySql,tableName); + if(recordSet.next()){ + modeId = Util.null2String(recordSet.getString("id")); + } + return modeId; + } + +} diff --git a/src/main/java/weaver/xiao/commons/utils/annotation/SqlFieldMapping.java b/src/main/java/weaver/xiao/commons/utils/annotation/SqlFieldMapping.java new file mode 100644 index 0000000..8f6a5bd --- /dev/null +++ b/src/main/java/weaver/xiao/commons/utils/annotation/SqlFieldMapping.java @@ -0,0 +1,21 @@ +package weaver.xiao.commons.utils.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author XiaoBokang + * @create 2022/5/10 18:22 + */ + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface SqlFieldMapping { + /** 字段所属 1:数据库值,2:默认值 */ + int type() default 1; + /** 数据库字段名或默认值 */ + String value(); + +} diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java index aca3531..234418f 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/sftp/FetchDataUtil.java @@ -1,5 +1,9 @@ package weaver.youhong.ai.pcn.hrorganization.sftp; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.fileUtil.sftp.SftpConnectUtil; +import com.jcraft.jsch.SftpException; + /** *

获取数据工具

* @@ -16,4 +20,20 @@ public class FetchDataUtil { + + public FetchDataUtil(){ + + } + + + + public void downloadFile(SftpConnectUtil sftpConnectUtil,String fileName, + String targetFile){ + try { + sftpConnectUtil.get(fileName, targetFile); + } catch (SftpException e) { + throw new CustomerException("下载文件出错,down file error!"); + } + } + } \ No newline at end of file diff --git a/src/test/java/baseTest/BaseTest.java b/src/test/java/baseTest/BaseTest.java index f192277..123cb0f 100644 --- a/src/test/java/baseTest/BaseTest.java +++ b/src/test/java/baseTest/BaseTest.java @@ -17,7 +17,7 @@ public class BaseTest { public void before() { GCONST.setServerName("ecology"); GCONST.setRootPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/"); - GCONST.setSystemFilePath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/file"); + GCONST.setSystemFilePath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/file"); } @Test diff --git a/src/test/java/youhong/ai/pcn/TestOrganization.java b/src/test/java/youhong/ai/pcn/TestOrganization.java new file mode 100644 index 0000000..53245e0 --- /dev/null +++ b/src/test/java/youhong/ai/pcn/TestOrganization.java @@ -0,0 +1,31 @@ +package youhong.ai.pcn; + +import aiyh.utils.fileUtil.sftp.SftpConnectUtil; +import baseTest.BaseTest; +import org.junit.Test; +import weaver.general.GCONST; +import weaver.youhong.ai.pcn.hrorganization.sftp.FetchDataUtil; + +/** + *

测试类

+ * + *

create: 2022-11-22 15:56

+ * + * @author youHong.ai + */ + +public class TestOrganization extends BaseTest { + + + @Test + public void testSftp(){ + SftpConnectUtil sftpConnectUtil = new SftpConnectUtil( + "HR Digital_PROD", + "/Users/aoey.oct.22/company/Fan_wei/ssl/pcn/HR_Digital_PROD.ppk",null,"222.73.197.242", + null,1000 * 10 + ); + FetchDataUtil fetchDataUtil = new FetchDataUtil(); + fetchDataUtil.downloadFile(sftpConnectUtil, + "HRIS_DepartmentExport20200503", GCONST.getSysFilePath() + "HRIS_DepartmentExport20200503.csv"); + } +}