修改配置文件与实体类映射关系,修改linkURL为linkList,采用内省方式对javabean赋值

dev
IT-xiaoXiong 2021-12-06 11:48:09 +08:00
parent 9858befefd
commit de2395f623
5 changed files with 158 additions and 38 deletions

View File

@ -5,11 +5,17 @@ import aiyh.utils.zwl.common.ToolUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.api.aiyh_pcn.patentWall.dao.PatentWallMapping; import com.api.aiyh_pcn.patentWall.dao.PatentWallMapping;
import com.api.aiyh_pcn.patentWall.dto.FilterWhere; import com.api.aiyh_pcn.patentWall.dto.FilterWhere;
import com.api.aiyh_pcn.patentWall.vo.LinkUrlVO;
import com.api.aiyh_pcn.patentWall.vo.PatentVO; import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import com.api.aiyh_pcn.patentWall.vo.SearchInputVO; import com.api.aiyh_pcn.patentWall.vo.SearchInputVO;
import com.api.aiyh_pcn.patentWall.vo.SelectOptionsVo; import com.api.aiyh_pcn.patentWall.vo.SelectOptionsVo;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -144,38 +150,57 @@ public class PatentWallService {
Map<String, Object> config = new HashMap<>(patentWallConf); Map<String, Object> config = new HashMap<>(patentWallConf);
for (Map.Entry<String, Object> entry : patentWallConf.entrySet()) { for (Map.Entry<String, Object> entry : patentWallConf.entrySet()) {
String patentVoField = entry.getKey(); String patentVoField = entry.getKey();
String parsing = String.valueOf(entry.getValue()); // linkList
// TODO 值解析 String parsing = null;
// 解析 ${}类型的参数,直接替换 // 值解析
String pattern = "\\$\\{(?<field>(\\s|\\S)+?)}"; if("linkList".equals(patentVoField)){
Pattern compile = Pattern.compile(pattern); List<LinkUrlVO> linkUrlVOS = new ArrayList<>();
Matcher matcher = compile.matcher(parsing); List<Map<String,Object>> linkUrlList = (List<Map<String, Object>>) entry.getValue();
while (matcher.find()) { for (Map<String, Object> linkUrlMap : linkUrlList) {
parsing = parsing.replaceFirst(pattern, Util.null2String(data.get(matcher.group("field")))); LinkUrlVO linkUrlVO = new LinkUrlVO();
BeanInfo beanInfo = null;
try {
beanInfo = Introspector.getBeanInfo(LinkUrlVO.class, Object.class);
} catch (IntrospectionException e) {
e.printStackTrace();
toolUtil.writeDebuggerLog("获取beanInfo错误");
continue;
}
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String keyName = propertyDescriptor.getName();
String parsingValue = String.valueOf(linkUrlMap.get(keyName));
parsingValue = handleParsingConf(parsingValue,data,args);
// 清除参数信息
args.clear();
if(propertyDescriptor.getPropertyType().equals(Integer.class)){
try {
propertyDescriptor.getWriteMethod().invoke(linkUrlVO,Integer.valueOf(parsingValue));
} catch (IllegalAccessException | InvocationTargetException e) {
toolUtil.writeErrorLog("设置值失败调用beanInfo的set方法错误");
e.printStackTrace();
}
}else {
try {
propertyDescriptor.getWriteMethod().invoke(linkUrlVO,parsingValue);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
toolUtil.writeErrorLog("设置值失败调用beanInfo的set方法错误");
}
}
}
linkUrlVOS.add(linkUrlVO);
}
config.replace(patentVoField, linkUrlVOS);
}else{
parsing = String.valueOf(entry.getValue());
parsing = handleParsingConf(parsing,data,args);
// 修改数据
config.replace(patentVoField, parsing);
// 清除参数信息
args.clear();
} }
// 解析#{}类型的参数,替换为?并按照顺序收集args
pattern = "#\\{(?<field>(\\s|\\S)+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing);
while (matcher.find()) {
parsing = parsing.replaceFirst(pattern, "?");
args.add(Util.null2String(data.get(matcher.group("field"))));
}
// 解析#sql{}类型的参数并执行SQL获取到SQL的值
pattern = "#sql\\{(?<sqlStr>([\\s\\S])+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing);
while (matcher.find()) {
String sqlStr = matcher.group("sqlStr");
toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}", sqlStr, args));
rs.executeQuery(sqlStr, args);
rs.next();
parsing = parsing.replaceFirst(pattern, Util.null2String(rs.getString(1)));;
}
// 清除参数信息
args.clear();
// 修改数据
config.replace(patentVoField, parsing);
} }
PatentVO patentVO = null; PatentVO patentVO = null;
try { try {
@ -189,6 +214,37 @@ public class PatentWallService {
return list; return list;
} }
public String handleParsingConf(String parsing, Map<String, Object> data,List<String> args){
// TODO 值解析
// 解析 ${}类型的参数,直接替换
String pattern = "\\$\\{(?<field>(\\s|\\S)+?)}";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(parsing);
while (matcher.find()) {
parsing = parsing.replaceFirst(pattern, Util.null2String(data.get(matcher.group("field"))));
}
// 解析#{}类型的参数,替换为?并按照顺序收集args
pattern = "#\\{(?<field>(\\s|\\S)+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing);
while (matcher.find()) {
parsing = parsing.replaceFirst(pattern, "?");
args.add(Util.null2String(data.get(matcher.group("field"))));
}
// 解析#sql{}类型的参数并执行SQL获取到SQL的值
pattern = "#sql\\{(?<sqlStr>([\\s\\S])+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing);
while (matcher.find()) {
String sqlStr = matcher.group("sqlStr");
toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}", sqlStr, args));
rs.executeQuery(sqlStr, args);
rs.next();
parsing = parsing.replaceFirst(pattern, Util.null2String(rs.getString(1)));;
}
return parsing;
}
public List<Map<String, Object>> handleFilterWhere(List<FilterWhere> filterWheres, String tableName) { public List<Map<String, Object>> handleFilterWhere(List<FilterWhere> filterWheres, String tableName) {
StringBuilder whereBuilder = new StringBuilder(" where "); StringBuilder whereBuilder = new StringBuilder(" where ");

View File

@ -0,0 +1,19 @@
package com.api.aiyh_pcn.patentWall.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author EBU7-dev1-ayh
* @create 2021/12/6 0006 10:59
*/
@Getter
@Setter
@ToString
public class LinkUrlVO {
private String labelName;
private Integer labelIndex;
private String linkUrl;
}

View File

@ -4,6 +4,8 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import java.util.List;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:31 * @create 2021/11/25 0025 15:31
@ -16,7 +18,8 @@ public class PatentVO {
private String id; private String id;
private String icon; private String icon;
private String activeIcon; private String activeIcon;
private String linkUrl; // private String linkUrl;
private List<LinkUrlVO> linkList;
private String title; private String title;
private String docId; private String docId;
private String imageFileId; private String imageFileId;

View File

@ -16,6 +16,7 @@ import com.alibaba.fastjson.JSONObject;
import com.api.aiyh_pcn.fadada.dao.FaDDServiceMapping; import com.api.aiyh_pcn.fadada.dao.FaDDServiceMapping;
import com.api.aiyh_pcn.fadada.service.impl.FaDDServiceImpl; import com.api.aiyh_pcn.fadada.service.impl.FaDDServiceImpl;
import com.api.aiyh_pcn.fadada.util.FaDDRequestUtils; import com.api.aiyh_pcn.fadada.util.FaDDRequestUtils;
import com.api.aiyh_pcn.patentWall.vo.LinkUrlVO;
import com.weaver.general.TimeUtil; import com.weaver.general.TimeUtil;
import org.apache.axiom.util.base64.Base64Utils; import org.apache.axiom.util.base64.Base64Utils;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
@ -33,7 +34,13 @@ import weaver.hrm.User;
import weaver.soa.workflow.FileProcessor; import weaver.soa.workflow.FileProcessor;
import weaver.workflow.workflow.WorkflowVersion; import weaver.workflow.workflow.WorkflowVersion;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.*; import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -497,12 +504,23 @@ public class NewTest extends BaseTest {
} }
@Test @Test
public void tesetLong(){ public void tesetLong() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IntrospectionException {
// SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(); LinkUrlVO linkUrlVO = new LinkUrlVO();
// Sheet sheet = sxssfWorkbook.createSheet("人员信息"); String linkUrl = "linkUrl";
// Row desc = sheet.createRow(0); BeanInfo beanInfo = Introspector.getBeanInfo(LinkUrlVO.class,Object.class);
// desc.createCell(1).setCellValue(null); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
// System.out.println(i); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
System.out.println(propertyDescriptor.getName());
if (propertyDescriptor.getPropertyType().equals(Integer.class)){
propertyDescriptor.getWriteMethod().invoke(linkUrlVO,1);
}else{
propertyDescriptor.getWriteMethod().invoke(linkUrlVO,propertyDescriptor.getName());
}
}
// Class<? extends LinkUrlVO> aClass = linkUrlVO.getClass();
// Method method = aClass.getMethod("set" + linkUrl.substring(0, 1).toUpperCase() + linkUrl.substring(1));
// method.invoke(linkUrlVO,"https://baidu.com");
System.out.println(linkUrlVO);
} }
} }

View File

@ -360,4 +360,28 @@ public class NewUtilTest {
String bizContent = "{\"contractExtension\":\".pdf\",\"contractTitle\":\"PCN Template - Non-Disclosure Agreement (Corporate).pdf\",\"uploadType\":1,\"customerNo\":\"ecef845ba95a409393cb66271a41b0a6\"}"; String bizContent = "{\"contractExtension\":\".pdf\",\"contractTitle\":\"PCN Template - Non-Disclosure Agreement (Corporate).pdf\",\"uploadType\":1,\"customerNo\":\"ecef845ba95a409393cb66271a41b0a6\"}";
System.out.println(cn.hutool.core.util.URLUtil.encodeAll(bizContent, Charset.forName("UTF-8"))); System.out.println(cn.hutool.core.util.URLUtil.encodeAll(bizContent, Charset.forName("UTF-8")));
} }
@Test
public void testReg(){
String var15 = "<html> \n" +
" <head> \n" +
" <title></title> \n" +
" <link href=\"/cloudstore/resource/pc/ckeditor-4.6.2/weaver/contents.css\" rel=\"stylesheet\" type=\"text/css\" /> \n" +
" <link href=\"/cloudstore/resource/pc/ckeditor-4.6.2/plugins/copyformatting/styles/copyformatting.css\" rel=\"stylesheet\" type=\"text/css\" /> \n" +
" <link href=\"/cloudstore/resource/pc/ckeditor-4.6.2/plugins/tableselection/styles/tableselection.css\" rel=\"stylesheet\" type=\"text/css\" /> \n" +
" <link href=\"/cloudstore/resource/pc/ckeditor-4.6.2/plugins/image2/styles/image2.css\" rel=\"stylesheet\" type=\"text/css\" /> \n" +
" <link href=\"/cloudstore/resource/pc/ckeditor-4.6.2/plugins/widget/styles/widget.css\" rel=\"stylesheet\" type=\"text/css\" /> \n" +
" </head> \n" +
" <body style=\"height: 747px;\"> \n" +
" <p>< img alt=\"\" src=\"/weaver/weaver.file.FileDownload?fileid=acdde79d8027d30e809be35a885a28eb184a3d7609b33666049ac12a48c5c8c3c10908eae8d1f6d650bfffce6db986fb5069726005eaf18c1\" /></p > \n" +
" </body> \n" +
" </html> \n" +
" ";
ArrayList var17 = Util.matchAll(var15, "/weaver/weaver.file.FileDownload\\?fileid=([a-z0-9]+)", 1, 1);
System.out.println(var17.size());
System.out.println(var17);
}
} }