肖工具添加

main
youHong.ai 2022-11-22 16:24:35 +08:00
parent a1dd155733
commit e9bd4fd92a
28 changed files with 2728 additions and 1 deletions

View File

@ -177,6 +177,10 @@ public class GCONST {
return propertyPath; return propertyPath;
} }
public static String setLogPath() {
return ROOT_PATH + "log" + File.separatorChar;
}
public static String getLogPath() { public static String getLogPath() {
return ROOT_PATH + "log" + File.separatorChar; return ROOT_PATH + "log" + File.separatorChar;
} }

View File

@ -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<MappingDetail> 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<ResponseMapping> 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);
}
/**
* <h2></h2>
*
* @param docIds id
* @return
* @author YouHong.ai
*/
public List<DocImageFile> 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<DocImageFile> 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;
}
}

View File

@ -0,0 +1,40 @@
package weaver.xiao.commons.config.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* <h1></h1>
*
* <p>create: 2022-11-21 10:55</p>
*
* @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;
}

View File

@ -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;
}

View File

@ -0,0 +1,17 @@
package weaver.xiao.commons.config.entity;
import lombok.Data;
/**
* <h1>list</h1>
*
* <p>create: 2022-08-05 11:25</p>
*
* @author aiyh EBU7-dev-1
*/
@Data
public class ListMapIndexValue {
private String key;
private Object value;
}

View File

@ -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<MappingDetail> childList;
private FieldMessage fieldMassage;
}

View File

@ -0,0 +1,37 @@
package weaver.xiao.commons.config.entity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.InputStream;
/**
* <h1></h1>
*
* <p>create: 2022-11-21 11:12</p>
*
* @author youHong.ai
*/
@Setter
@Getter
@ToString
public class MultipartFile {
/**
*
*/
String fileName;
/**
* key
*/
String fileKey;
/**
*
*/
InputStream stream;
/**
*
*/
Long fileSize;
}

View File

@ -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<MappingDetail> configDetail;
private List<ResponseMapping> responseMappingList;
}

View File

@ -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;
}

View File

@ -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<String, DataSourceEnum> 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);
}
}

View File

@ -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<String, GetValueTypeEnum> 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);
}
}

View File

@ -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<String, ParamTypeEnum> 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);
}
}

View File

@ -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;
/**
* <h1></h1>
*
* @author EBU7-dev-1 aiyh
* <p>create: 2022-07-25 14:18</p>
*/
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<String, Object> mainMap, Map<String, Object> detailMap, String currentValue,
Map<String, String> pathParam);
}

View File

@ -0,0 +1,25 @@
package weaver.xiao.commons.config.interfacies;
import java.util.List;
import java.util.Map;
/**
* <h1></h1>
*
* <p>create: 2022-08-15 15:38</p>
*
* @author aiyh EBU7-dev-1
*/
public interface CusInterfaceListValue {
/**
* <h2></h2>
*
* @param pathParam
* @param mainMap
* @param mainTable
* @return
*/
List<Object> execute(Map<String, String> pathParam, Map<String, Object> mainMap, String mainTable);
}

File diff suppressed because it is too large Load Diff

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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<String,Object> implements Map<String,Object> {
public PreMap(){
super();
}
public static PreMap create(){
return new PreMap();
}
@Override
public PreMap put(String key, Object value){
super.put(key,value);
return this;
}
}

View File

@ -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<String, Object> 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<String, Object> 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;
}
}

View File

@ -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<String,String > headers;
private static final Map<String,String > HEADER_NORMAL = new HashMap<>();
private static final Map<String,Object > 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<String, String> headers){
return create(type,url,headers,PARAMS_NORMAL);
}
public static RequestBaseInfo create(String type, String url, Map<String, String> 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<String, String> 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;
}
}

View File

@ -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> T apiRequest(RequestBaseInfo requestInfo, Class<T> tClass){
Map<String,String> headers = requestInfo.getHeaders();
T result = null;
switch(requestInfo.getType()){
case "GET" :{
String sendUrl = serializableUrl(requestInfo.getUrl(), (Map<String, Object>) 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> T POSTBySerializableUrl(RequestBaseInfo requestInfo, Class<T> tClass){
T result = null;
Map<String,String> headers = requestInfo.getHeaders();
String url = serializableUrl(requestInfo.getUrl(), (Map<String, Object>) 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> T apiUploadFileByInputStream(RequestBaseInfo requestInfo, Class<T> tClass){
Map<String,Object> params = (Map<String, Object>) 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> T apiSend(
HttpUriRequest httpRequest,
Class<T> 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<Map<String,Object>> 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<String,Object> 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;
}
}

View File

@ -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 <T>
* @return
*/
public <T> T recordSetToEntityByEntity(RecordSet recordSet, Class<T> tClass){
T res = null;
try{
String[] columnNames = recordSet.getColumnName();
if(tClass.equals(Map.class)){
Map<String,Object> 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<String, Object> updateParam, Map<String, Object> whereParam) {
RecordSet recordSet = new RecordSet();
List<Object> 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<String, Object> updateParam, Map<String, Object> whereParam,List<Object> paramList){
StringBuilder updateBuilder = new StringBuilder("update ");
updateBuilder.append(tableName).append(" set ");
Set<Map.Entry<String, Object>> updateEntries = updateParam.entrySet();
for (Map.Entry<String, Object> updateEntry : updateEntries) {
updateBuilder.append(updateEntry.getKey())
.append(" = ?,");
paramList.add(updateEntry.getValue());
}
StringBuilder whereBuilder = new StringBuilder();
Set<Map.Entry<String, Object>> whereEntries = whereParam.entrySet();
for (Map.Entry<String, Object> 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<String, Object> insertParam) {
RecordSet recordSet = new RecordSet();
//构建新建sql语句,收集参数信息
List<Object> 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<String, Object> insertParam,List<Object> paramList){
StringBuilder suffixBuilder = new StringBuilder();
StringBuilder prefixBuilder = new StringBuilder();
prefixBuilder.append("insert into ")
.append(tableName).append("(");
suffixBuilder.append(" values (");
Set<Map.Entry<String, Object>> entries = insertParam.entrySet();
for (Map.Entry<String, Object> 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<String,Object> param,String modeId){
logger.info("=====插入建模信息====");
if(modeId == null || "".equals(modeId)) {
modeId = this.getModeIdByTableName(tableName);
}
logger.info("通过表名获取modeId ==>modeId"+modeId+" tableName==>"+tableName);
Map<String,Object> 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<String,Object> param,String modeId){
logger.info("=====插入建模信息====");
if(modeId == null || "".equals(modeId)) {
modeId = this.getModeIdByTableName(tableName);
}
logger.info("通过表名获取modeId ==>modeId"+modeId+" tableName==>"+tableName);
Map<String,Object> 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;
}
}

View File

@ -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();
}

View File

@ -1,5 +1,9 @@
package weaver.youhong.ai.pcn.hrorganization.sftp; package weaver.youhong.ai.pcn.hrorganization.sftp;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.fileUtil.sftp.SftpConnectUtil;
import com.jcraft.jsch.SftpException;
/** /**
* <h1></h1> * <h1></h1>
* *
@ -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!");
}
}
} }

View File

@ -17,7 +17,7 @@ public class BaseTest {
public void before() { public void before() {
GCONST.setServerName("ecology"); GCONST.setServerName("ecology");
GCONST.setRootPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/"); 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 @Test

View File

@ -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;
/**
* <h1></h1>
*
* <p>create: 2022-11-22 15:56</p>
*
* @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");
}
}