修改配置文件与实体类映射关系,修改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.api.aiyh_pcn.patentWall.dao.PatentWallMapping;
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.SearchInputVO;
import com.api.aiyh_pcn.patentWall.vo.SelectOptionsVo;
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.HashMap;
import java.util.List;
@ -144,7 +150,71 @@ public class PatentWallService {
Map<String, Object> config = new HashMap<>(patentWallConf);
for (Map.Entry<String, Object> entry : patentWallConf.entrySet()) {
String patentVoField = entry.getKey();
String parsing = String.valueOf(entry.getValue());
// linkList
String parsing = null;
// 值解析
if("linkList".equals(patentVoField)){
List<LinkUrlVO> linkUrlVOS = new ArrayList<>();
List<Map<String,Object>> linkUrlList = (List<Map<String, Object>>) entry.getValue();
for (Map<String, Object> linkUrlMap : linkUrlList) {
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();
}
}
PatentVO patentVO = null;
try {
patentVO = Util.mapToObject(config, PatentVO.class);
} catch (Exception e) {
e.printStackTrace();
toolUtil.writeErrorLog("map转为PatentVO失败");
}
list.add(patentVO);
}
return list;
}
public String handleParsingConf(String parsing, Map<String, Object> data,List<String> args){
// TODO 值解析
// 解析 ${}类型的参数,直接替换
String pattern = "\\$\\{(?<field>(\\s|\\S)+?)}";
@ -172,21 +242,7 @@ public class PatentWallService {
rs.next();
parsing = parsing.replaceFirst(pattern, Util.null2String(rs.getString(1)));;
}
// 清除参数信息
args.clear();
// 修改数据
config.replace(patentVoField, parsing);
}
PatentVO patentVO = null;
try {
patentVO = Util.mapToObject(config, PatentVO.class);
} catch (Exception e) {
e.printStackTrace();
toolUtil.writeErrorLog("map转为PatentVO失败");
}
list.add(patentVO);
}
return list;
return parsing;
}

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.ToString;
import java.util.List;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:31
@ -16,7 +18,8 @@ public class PatentVO {
private String id;
private String icon;
private String activeIcon;
private String linkUrl;
// private String linkUrl;
private List<LinkUrlVO> linkList;
private String title;
private String docId;
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.service.impl.FaDDServiceImpl;
import com.api.aiyh_pcn.fadada.util.FaDDRequestUtils;
import com.api.aiyh_pcn.patentWall.vo.LinkUrlVO;
import com.weaver.general.TimeUtil;
import org.apache.axiom.util.base64.Base64Utils;
import org.apache.commons.codec.binary.Hex;
@ -33,7 +34,13 @@ import weaver.hrm.User;
import weaver.soa.workflow.FileProcessor;
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.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@ -497,12 +504,23 @@ public class NewTest extends BaseTest {
}
@Test
public void tesetLong(){
// SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
// Sheet sheet = sxssfWorkbook.createSheet("人员信息");
// Row desc = sheet.createRow(0);
// desc.createCell(1).setCellValue(null);
// System.out.println(i);
public void tesetLong() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IntrospectionException {
LinkUrlVO linkUrlVO = new LinkUrlVO();
String linkUrl = "linkUrl";
BeanInfo beanInfo = Introspector.getBeanInfo(LinkUrlVO.class,Object.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
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\"}";
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);
}
}