专利墙开发,贵酒流程赋值修改,props文件解析,添加密码重置修改人员状态

dev
IT-xiaoXiong 2021-12-01 10:22:22 +08:00
parent cd579ffc21
commit b9dac47eb9
12 changed files with 906 additions and 99 deletions

View File

@ -5,6 +5,7 @@ import aiyh.utils.entity.AInputStream;
import aiyh.utils.entity.AZipOutputStream; import aiyh.utils.entity.AZipOutputStream;
import aiyh.utils.entity.ApiConfigMainDTO; import aiyh.utils.entity.ApiConfigMainDTO;
import aiyh.utils.entity.ListZipEntity; import aiyh.utils.entity.ListZipEntity;
import aiyh.utils.fileUtil.ProperUtil;
import aiyh.utils.mapUtil.UtilHashMap; import aiyh.utils.mapUtil.UtilHashMap;
import aiyh.utils.mapUtil.UtilLinkedHashMap; import aiyh.utils.mapUtil.UtilLinkedHashMap;
import aiyh.utils.service.UtilService; import aiyh.utils.service.UtilService;
@ -1041,6 +1042,203 @@ public class Util extends weaver.general.Util {
return map; return map;
} }
/**
*
* @param fileName
* @param prefix
* @return
*/
public static Map<String, Object> readProperties2Map(String fileName, String prefix) {
String propertyPath = GCONST.getPropertyPath();
if (StringUtil.isNullOrEmpty(fileName)) {
return null;
}
if (fileName.contains(".properties")) {
fileName.replace(".properties", "");
}
String path = propertyPath + "prop2map" + File.separator + fileName + ".properties";
ProperUtil prop = new ProperUtil();
Map<String, Object> map = new HashMap<>();
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(path));
prop.load(inputStream);
// Enumeration<?> enumeration = prop.propertyNames();
// 顺序读取
Enumeration<?> enumeration = prop.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = prop.getProperty(key);
keyHandler(prefix, key, value, map);
}
} catch (IOException e) {
throw new RuntimeException("找不到文件:" + path);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
/**
* keyvalue
* @param prePrefix
* @param key key
* @param value value
* @param preResult
* @return
*/
public static Map<String, Object> keyHandler(String prePrefix, String key, Object value, Map<String, Object> preResult) {
String objRegex = "^(" + prePrefix + "\\.)(?<key>(\\w+))$";
Pattern compile = Pattern.compile(objRegex);
Matcher matcher = compile.matcher(key);
if (matcher.find()) {
// 只匹配前缀.key=value模式的
String resultKey = matcher.group("key");
preResult.put(resultKey, prop2MapPutValue(value));
}
String moreKey = "^(" + prePrefix + "\\.)(?<key>(?<objKey>(\\w+))\\.(\\S)+(?!\\[))";
compile = Pattern.compile(moreKey);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key1.key2=value模式的
String objKey = matcher.group("objKey");
String prefixStr = prePrefix + "." + objKey;
Map<String, Object> valueMap;
if (preResult.containsKey(objKey)) {
valueMap = (Map<String, Object>) preResult.get(objKey);
keyHandler(prefixStr, key, value, valueMap);
return null;
}
valueMap = new HashMap<>();
keyHandler(prefixStr, key, value, valueMap);
preResult.put(objKey, valueMap);
return null;
}
String strList = "^(" + prePrefix + "\\.)(?<key>(\\w+))(\\[(?<index>([0-9])+)])$";
compile = Pattern.compile(strList);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key[0]=value模式的
String objKey = matcher.group("key");
int index = Integer.parseInt(matcher.group("index"));
if (preResult.containsKey(objKey)) {
// 存在值
List<Object> valueList = (List<Object>) preResult.get(objKey);
if (index >= valueList.size()) {
valueList.add(prop2MapPutValue(value));
} else {
valueList.set(index, prop2MapPutValue(value));
}
return null;
}
List<Object> valueList = new ArrayList<>();
valueList.add(prop2MapPutValue(value));
preResult.put(objKey, valueList);
return null;
}
String objArray = "^(" + prePrefix + "\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])\\.(?<objKey>(\\S)+)$";
// String objArray = "^("+prePrefix+"\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])(\\.(?<objKey>(\\S)+))+";
compile = Pattern.compile(objArray);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key[0].name=value的模式
String arrKey = matcher.group("arrKey");
String objKey = matcher.group("objKey");
int index = Integer.parseInt(matcher.group("index"));
List<Map<String, Object>> mapList;
if (preResult.containsKey(arrKey)) {
// 存在
mapList = (List<Map<String, Object>>) preResult.get(arrKey);
// mapList
Map<String, Object> valueMap;
if (index >= mapList.size()) {
valueMap = new HashMap<>();
valueMap.put(objKey, prop2MapPutValue(value));
mapList.add(valueMap);
return null;
}
valueMap = mapList.get(index);
String arrMoreKey = "(?<key>(\\w+))\\.(\\S)+(?!\\[)";
Pattern arrMoreKeyCompile = Pattern.compile(arrMoreKey);
Matcher arrMoreKeyMatcher = arrMoreKeyCompile.matcher(objKey);
if (arrMoreKeyMatcher.find()) {
String arrMoreObjKey = arrMoreKeyMatcher.group("key");
Map<String, Object> arrMoreValue;
if (valueMap.containsKey(arrMoreObjKey)) {
arrMoreValue = (Map<String, Object>) valueMap.get(arrMoreObjKey);
keyHandler(arrMoreObjKey, objKey, value, arrMoreValue);
return null;
}
arrMoreValue = new HashMap<>();
keyHandler(arrMoreObjKey, objKey, value, arrMoreValue);
valueMap.put(arrMoreObjKey, arrMoreValue);
return null;
}
arrMoreKey = "(?<key>(\\w+))(\\[(?<index>([0-9])+)])$";
arrMoreKeyCompile = Pattern.compile(arrMoreKey);
arrMoreKeyMatcher = arrMoreKeyCompile.matcher(objKey);
if (arrMoreKeyMatcher.find()) {
String arrMoreArrKey = arrMoreKeyMatcher.group("key");
int arrMoreIndex = Integer.parseInt(arrMoreKeyMatcher.group("index"));
List<Object> arrMoreListValue;
if (valueMap.containsKey(arrMoreArrKey)) {
// 存在值
arrMoreListValue = (List<Object>) valueMap.get(arrMoreArrKey);
if (arrMoreIndex >= arrMoreListValue.size()) {
arrMoreListValue.add(prop2MapPutValue(value));
} else {
arrMoreListValue.set(arrMoreIndex, prop2MapPutValue(value));
}
return null;
}
arrMoreListValue = new ArrayList<>();
arrMoreListValue.add(prop2MapPutValue(value));
valueMap.put(arrMoreArrKey, arrMoreListValue);
return null;
}
// 直接添加
valueMap.put(objKey, prop2MapPutValue(value));
return null;
}
// 不存在
mapList = new ArrayList<>();
Map<String, Object> valueMap = new HashMap<>();
valueMap.put(objKey, prop2MapPutValue(value));
mapList.add(valueMap);
preResult.put(arrKey, mapList);
}
return null;
}
public static Object prop2MapPutValue(Object value) {
if(value == null){
return null;
}
String valueStr = String.valueOf(value).trim();
if (valueStr.startsWith("\"") && valueStr.endsWith("\"")) {
return valueStr.substring(1, valueStr.length() - 1);
}
if (valueStr.contains(",")) {
if(valueStr.contains("\\,")){
String[] split = valueStr.split("(?<!\\\\),");
for (int i = 0; i < split.length; i ++){
split[i] = split[i].replaceAll("\\\\,",",");
}
return split;
}
return valueStr.split(",");
}
return value;
}
/** /**
* map * map
* *
@ -1048,6 +1246,7 @@ public class Util extends weaver.general.Util {
* @param prefix * @param prefix
* @return map * @return map
*/ */
@Deprecated
public static Map<String, Object> getProperties2Map(String fileName, String prefix) { public static Map<String, Object> getProperties2Map(String fileName, String prefix) {
String propertyPath = GCONST.getPropertyPath(); String propertyPath = GCONST.getPropertyPath();
if (StringUtil.isNullOrEmpty(fileName)) { if (StringUtil.isNullOrEmpty(fileName)) {
@ -1414,7 +1613,7 @@ public class Util extends weaver.general.Util {
if(StringUtils.isNullOrEmpty(objStr) && !StringUtils.isNullOrEmpty(defaultStr)){ if(StringUtils.isNullOrEmpty(objStr) && !StringUtils.isNullOrEmpty(defaultStr)){
return defaultStr; return defaultStr;
} }
return ""; return objStr;
} }

View File

@ -0,0 +1,55 @@
package aiyh.utils.fileUtil;
import java.util.*;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/29 0029 13:53
*/
public class ProperUtil extends Properties {
//LinkedHashSet有序可以保证读取出来顺序不变
private final LinkedHashSet<Object> keys = new LinkedHashSet<>();
/**
* key
*/
@Override
public Set<String> stringPropertyNames() {
Set<String> set = new LinkedHashSet<>();
for (Object key : keys) {
set.add((String) key);
}
return set;
}
@Override
public Set<Object> keySet() {
return keys;
}
/**
* iterator
* 使stringPropertyNames
*/
@Override
public synchronized Enumeration<Object> keys() {
return Collections.enumeration(keys);
}
@Override
public synchronized Object put(Object key, Object value) {
keys.add(key);
return super.put(key, value);
}
/**
* remove
*/
@Override
public Object remove(Object o) {
keys.remove(o);
return super.remove(o);
}
}

View File

@ -41,6 +41,11 @@ public class ChangeStatusImpl {
ChangeStatusUtil.changeHrmResourceStatus(weaBeforeReplaceParam, "id", 2); ChangeStatusUtil.changeHrmResourceStatus(weaBeforeReplaceParam, "id", 2);
} }
@WeaReplaceBefore(value = "/api/hrm/forgotPassword/saveResetPassword", order = 1, description = "重置密码")
public void saveResetPasswordBefore(WeaBeforeReplaceParam weaBeforeReplaceParam) {
ChangeStatusUtil.changeHrmResourceStatus(weaBeforeReplaceParam, "id", 2);
}
/** /**
* *
* *

View File

@ -360,21 +360,22 @@ public class WorkflowQueueService {
String isAppend = param.get("isAppend"); String isAppend = param.get("isAppend");
// String sourceField = param.get("sourceField"); // String sourceField = param.get("sourceField");
String requestId = param.get("requestId"); String requestId = param.get("requestId");
String oldFileIds = param.get("oldFileIds");
if ("true".equals(isWrite)) { if ("true".equals(isWrite)) {
if ("true".equals(isAppend)) { if ("true".equals(isAppend)) {
// // 查询原字段是否存在图片 // // 查询原字段是否存在图片
String queryStr = ""; // String queryStr = "";
try { // try {
queryStr = "select " + fieldName + " from " + tableName + " where requestid = ?"; // queryStr = "select " + fieldName + " from " + tableName + " where requestid = ?";
rs.executeQuery(queryStr, requestId); // rs.executeQuery(queryStr, requestId);
rs.next(); // rs.next();
String oldImg = Util.null2String(rs.getString(1)); // String oldImg = Util.null2String(rs.getString(1));
if (!StringUtils.isNullOrEmpty(oldImg)) { // if (!StringUtils.isNullOrEmpty(oldImg)) {
newDocIds.append(",").append(oldImg); newDocIds.append(",").append(oldFileIds);
} // }
}catch (Exception e){ // }catch (Exception e){
toolUtil.writeErrorLog("查询错误:" + queryStr); // toolUtil.writeErrorLog("查询错误:" + queryStr);
} // }
} }
if ("0".equals(isSaveResource)) { if ("0".equals(isSaveResource)) {
// 不保存原来的图片 // 不保存原来的图片

View File

@ -1,14 +1,20 @@
package com.api.aiyh_pcn.patentWall.controller; package com.api.aiyh_pcn.patentWall.controller;
import aiyh.utils.ApiResult; import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import com.api.aiyh_pcn.patentWall.dto.FilterWhere; import com.api.aiyh_pcn.patentWall.dto.FilterWhere;
import com.api.aiyh_pcn.patentWall.service.PatentWallService; import com.api.aiyh_pcn.patentWall.service.PatentWallService;
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 io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.parameters.RequestBody;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.ws.rs.GET; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path; import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -23,17 +29,32 @@ import java.util.Map;
public class PatentWallController { public class PatentWallController {
private final PatentWallService patentWallService = new PatentWallService(); private final PatentWallService patentWallService = new PatentWallService();
@Path("/getList") @Path("/getSearchList/{prefix}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getPatentList(@Context HttpServletRequest request, @Context HttpServletResponse response,
@PathParam("prefix") String prefix){
User user = HrmUserVarify.getUser(request, response);
int languageId = user.getLanguage();
List<SearchInputVO> result = patentWallService.getSearchList(prefix,languageId);
return ApiResult.success(result);
}
@Path("/getList/{prefix}")
@POST @POST
public String getPatentList(@RequestBody List<FilterWhere> filterWheres){ @Produces(MediaType.APPLICATION_JSON)
List<PatentVO> result = patentWallService.getList(filterWheres); @Consumes(MediaType.APPLICATION_JSON)
public String getPatentList(@RequestBody List<FilterWhere> filterWheres, @PathParam("prefix") String prefix){
List<PatentVO> result = patentWallService.getList(filterWheres,prefix);
return ApiResult.success(result); return ApiResult.success(result);
} }
@Path("/clearConf") @Path("/clearConf")
@GET @GET
@Produces(MediaType.APPLICATION_JSON)
public String clearPatentWallConf(){ public String clearPatentWallConf(){
patentWallService.clearPatentWallConf(); patentWallService.clearPatentWallConf();
patentWallService.clearPatentWallSerachConf();
return ApiResult.success("清除配置缓存成功!"); return ApiResult.success("清除配置缓存成功!");
} }
} }

View File

@ -25,63 +25,25 @@ public class PatentWallMapping {
rs.executeQuery(query); rs.executeQuery(query);
return Util.recordSet2MapList(rs); return Util.recordSet2MapList(rs);
} }
public List<Map<String,Object>> getListByFilterWhere(List<FilterWhere> filterWheres, String tableName) {
StringBuilder whereBuilder = new StringBuilder(" where "); public List<Map<String,Object>> getListByFilterWhere(StringBuilder whereBuilder,List<String> args, String tableName) {
List<String> args = new ArrayList<>();
for (FilterWhere filterWhere : filterWheres) {
whereBuilder.append(" add ");
if(filterWhere.getType() == 1){
// 等于
whereBuilder.append(filterWhere.getDbField())
.append(" = ? ");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 2){
// 大于
whereBuilder.append(filterWhere.getDbField())
.append(" > ?");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 3){
// 小于
whereBuilder.append(filterWhere.getDbField())
.append(" < ?");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 4){
// in
whereBuilder.append(filterWhere.getDbField())
.append(" in ( ")
.append(filterWhere.getValue())
.append(") ");
continue;
}
if(filterWhere.getType() == 5){
// 日期大于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') > ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
if(filterWhere.getType() == 6){
// 日期小于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') < ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
}
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
String query = "select * from " + tableName + whereBuilder.toString().replace(" where add "," where "); String query = "select * from " + tableName + whereBuilder.toString().replace(" where add "," where ");
rs.executeQuery(query,args); rs.executeQuery(query,args);
toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}",query,args)); toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}",query,args));
return Util.recordSet2MapList(rs); return Util.recordSet2MapList(rs);
} }
public List<Map<String,Object>> getSelectOptions(String dataResource, String dbFieldName) {
RecordSet rs = new RecordSet();
String query = "select wbf.id,wbf.fieldname,wbf.fieldlabel,wb.tablename, " +
"ws.selectname,ws.selectvalue " +
"from workflow_billfield wbf " +
"left join workflow_bill wb on wbf.billid = wb.id " +
"left join workflow_selectitem ws on ws.fieldid = wbf.id " +
"where wb.tablename = ? and fieldname = ? ";
rs.executeQuery(query,dataResource,dbFieldName);
toolUtil.writeDebuggerLog(String.format("执行SQL {%s} ---> 参数: {%s}",query,dataResource + " -- " + dbFieldName));
return Util.recordSet2MapList(rs);
}
} }

View File

@ -14,7 +14,7 @@ import lombok.ToString;
@Getter @Getter
@ToString @ToString
public class FilterWhere { public class FilterWhere {
private int type; private int searchType;
private String dbField; private String dbField;
private String value; private String value;
} }

View File

@ -2,9 +2,12 @@ package com.api.aiyh_pcn.patentWall.service;
import aiyh.utils.Util; import aiyh.utils.Util;
import aiyh.utils.zwl.common.ToolUtil; 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.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.PatentVO; 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 weaver.conn.RecordSet;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,40 +27,139 @@ public class PatentWallService {
private final PatentWallMapping patentWallMapping = new PatentWallMapping(); private final PatentWallMapping patentWallMapping = new PatentWallMapping();
private final ToolUtil toolUtil = new ToolUtil(); private final ToolUtil toolUtil = new ToolUtil();
private Map<String, Object> patentWallConf; private Map<String, Object> patentWallConf;
private Map<String, Object> patentWallSearchConf;
private final RecordSet rs = new RecordSet();
public List<PatentVO> getList(List<FilterWhere> filterWheres) {
Map<String, Object> patentWallConf = getPatentWallConf(); /**
*
*
* @param prefix
* @return
*/
public List<SearchInputVO> getSearchList(String prefix,int languageId) {
Map<String, Object> patentWallSearchConf = getPatentWallSearchConf(prefix + ".search");
String dataResource = String.valueOf(patentWallSearchConf.get("dataResource"));
List<Map<String, Object>> inputs = (List<Map<String, Object>>) patentWallSearchConf.get("inputs");
List<SearchInputVO> searchInputList = new ArrayList<>();
for (Map<String, Object> input : inputs) {
SearchInputVO searchInputVO = new SearchInputVO();
int type = Integer.parseInt(Util.null2DefaultStr(input.get("type"), "0"));
String dbFieldName = Util.null2String(input.get("dbFieldName"));
String value = Util.null2String(input.get("value"));
String labelName = Util.null2String(input.get("labelName"));
Integer labelIndex = Integer.valueOf(Util.null2DefaultStr(input.get("labelIndex"),"0"));
Integer searchType = Integer.valueOf(Util.null2DefaultStr(input.get("searchType"),"0"));
Boolean multiple = Boolean.valueOf(Util.null2DefaultStr(input.get("multiple"),"false"));
searchInputVO.setType(type);
searchInputVO.setLabelName(labelName);
searchInputVO.setSearchType(searchType);
searchInputVO.setDbFieldName(dbFieldName);
searchInputVO.setLabelIndex(labelIndex);
searchInputVO.setLabelIndex(labelIndex);
searchInputVO.setMultiple(multiple);
searchInputVO.setValue(value);
searchInputList.add(searchInputVO);
switch (type) {
case 1:
// 下拉框 查询options
List<SelectOptionsVo> optionsVos = getSelectOptions(dataResource, dbFieldName,languageId);
searchInputVO.setSelectOptions(optionsVos);
case 2:
// 单行文本
break;
case 3:
// 日期
case 4:
// 单人力资源
break;
case 5:
// 多人力资源
break;
case 6:
// 流程路径
break;
case 7:
// 多流程路径
break;
default:
toolUtil.writeDebuggerLog("未匹配输入框类型!请检查配置文件是否正确!");
break;
}
}
return searchInputList;
}
private List<SelectOptionsVo> getSelectOptions(String dataResource, String dbFieldName, int languageId) {
List<Map<String, Object>> selectOptions = patentWallMapping.getSelectOptions(dataResource, dbFieldName);
List<SelectOptionsVo> optionsVos = new ArrayList<>();
SelectOptionsVo optionsDefault = new SelectOptionsVo();
optionsDefault.setSelected(true);
optionsDefault.setKey("");
optionsDefault.setShowname("");
optionsVos.add(optionsDefault);
for (Map<String, Object> selectOption : selectOptions) {
SelectOptionsVo optionsVo = new SelectOptionsVo();
optionsVo.setSelected(false);
optionsVo.setKey(Util.null2DefaultStr(selectOption.get("selectvalue"),""));
String selectName = Util.null2DefaultStr(selectOption.get("selectname"), "");
String showName = selectName;
if (selectName.startsWith("~`~`") && selectName.endsWith("`~`~")) {
String pattern = "(`~`" + languageId + " )(?<label>(\\w*|\\W*|[\\u4e00-\\u9fa5]*))(`~`)";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(selectName);
if (matcher.find()) {
showName = matcher.group("label");
}
}
optionsVo.setShowname(showName);
optionsVos.add(optionsVo);
}
return optionsVos;
}
/**
*
*
* @param filterWheres
* @param prefix
* @return
*/
public List<PatentVO> getList(List<FilterWhere> filterWheres, String prefix) {
Map<String, Object> patentWallConf = getPatentWallConf(prefix + ".voMapping");
List<Map<String, Object>> dataList; List<Map<String, Object>> dataList;
toolUtil.writeDebuggerLog(String.format("查询数据,接收到的过滤信息为: %s", JSON.toJSONString(filterWheres)));
if (filterWheres == null || filterWheres.isEmpty()) { if (filterWheres == null || filterWheres.isEmpty()) {
// 查询全部 // 查询全部
dataList = patentWallMapping.getAllList(Util.null2String(patentWallConf.get("dataResource"))); dataList = patentWallMapping.getAllList(Util.null2String(patentWallConf.get("dataResource")));
} else { } else {
// 筛选查询 // 筛选查询
dataList = patentWallMapping.getListByFilterWhere(filterWheres dataList = handleFilterWhere(filterWheres
, Util.null2String(patentWallConf.get("dataResource"))); , Util.null2String(patentWallConf.get("dataResource")));
} }
List<PatentVO> list = new ArrayList<>(); List<PatentVO> list = new ArrayList<>();
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
for (Map<String, Object> data : dataList) { for (Map<String, Object> data : dataList) {
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()); String parsing = String.valueOf(entry.getValue());
// TODO 值解析 // TODO 值解析
// 解析 ${}类型的参数,直接替换 // 解析 ${}类型的参数,直接替换
String pattern = "\\$\\{(?<field>(\\s\\S)+?)}"; String pattern = "\\$\\{(?<field>(\\s|\\S)+?)}";
Pattern compile = Pattern.compile(pattern); Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(parsing); Matcher matcher = compile.matcher(parsing);
while (matcher.find()) { while (matcher.find()) {
parsing = parsing.replaceFirst(pattern,Util.null2String(data.get(patentVoField))); parsing = parsing.replaceFirst(pattern, Util.null2String(data.get(matcher.group("field"))));
} }
// 解析#{}类型的参数,替换为?并按照顺序收集args // 解析#{}类型的参数,替换为?并按照顺序收集args
pattern = "#\\{(?<field>(\\s\\S)+?)}"; pattern = "#\\{(?<field>(\\s|\\S)+?)}";
compile = Pattern.compile(pattern); compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing); matcher = compile.matcher(parsing);
while (matcher.find()) { while (matcher.find()) {
parsing = parsing.replaceFirst(pattern, "?"); parsing = parsing.replaceFirst(pattern, "?");
args.add(Util.null2String(data.get(patentVoField))); args.add(Util.null2String(data.get(matcher.group("field"))));
} }
// 解析#sql{}类型的参数并执行SQL获取到SQL的值 // 解析#sql{}类型的参数并执行SQL获取到SQL的值
pattern = "#sql\\{(?<sqlStr>([\\s\\S])+?)}"; pattern = "#sql\\{(?<sqlStr>([\\s\\S])+?)}";
@ -73,11 +175,11 @@ public class PatentWallService {
// 清除参数信息 // 清除参数信息
args.clear(); args.clear();
// 修改数据 // 修改数据
patentWallConf.replace(patentVoField,parsing); config.replace(patentVoField, parsing);
} }
PatentVO patentVO = null; PatentVO patentVO = null;
try { try {
patentVO = Util.mapToObject(patentWallConf, PatentVO.class); patentVO = Util.mapToObject(config, PatentVO.class);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
toolUtil.writeErrorLog("map转为PatentVO失败"); toolUtil.writeErrorLog("map转为PatentVO失败");
@ -87,14 +189,72 @@ public class PatentWallService {
return list; return list;
} }
public List<Map<String, Object>> handleFilterWhere(List<FilterWhere> filterWheres, String tableName) {
StringBuilder whereBuilder = new StringBuilder(" where ");
List<String> args = new ArrayList<>();
for (FilterWhere filterWhere : filterWheres) {
whereBuilder.append(" add ");
if (filterWhere.getSearchType() == 1) {
// 等于
whereBuilder.append(filterWhere.getDbField())
.append(" = ? ");
args.add(filterWhere.getValue());
continue;
}
if (filterWhere.getSearchType() == 2) {
// 大于
whereBuilder.append(filterWhere.getDbField())
.append(" > ?");
args.add(filterWhere.getValue());
continue;
}
if (filterWhere.getSearchType() == 3) {
// 小于
whereBuilder.append(filterWhere.getDbField())
.append(" < ?");
args.add(filterWhere.getValue());
continue;
}
if (filterWhere.getSearchType() == 4) {
// in
whereBuilder.append(filterWhere.getDbField())
.append(" in ( ")
.append(filterWhere.getValue())
.append(") ");
continue;
}
if (filterWhere.getSearchType() == 5) {
// 日期大于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') > ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
if (filterWhere.getSearchType() == 6) {
// 日期小于
whereBuilder.append(" DATE_FORMAT(")
.append(filterWhere.getDbField())
.append(",'%y-%m-%d') < ")
.append("DATE_FORMAT(?,'%y-%m-%d')");
args.add(filterWhere.getValue());
continue;
}
}
return patentWallMapping.getListByFilterWhere(whereBuilder, args, tableName);
}
/** /**
* *
*
* @return * @return
*/ */
private Map<String, Object> getPatentWallConf() { private Map<String, Object> getPatentWallConf(String prefix) {
synchronized (this) { synchronized (this) {
if (this.patentWallConf == null) { if (this.patentWallConf == null) {
this.patentWallConf = Util.getProperties2Map("PatentWall", "aiyh.patentWall"); this.patentWallConf = Util.readProperties2Map("PatentWall", "aiyh." + prefix);
} }
if (this.patentWallConf == null) { if (this.patentWallConf == null) {
return new HashMap<>(0); return new HashMap<>(0);
@ -106,4 +266,26 @@ public class PatentWallService {
public void clearPatentWallConf() { public void clearPatentWallConf() {
this.patentWallConf = null; this.patentWallConf = null;
} }
/**
*
*
* @return
*/
private Map<String, Object> getPatentWallSearchConf(String prefix) {
synchronized (this) {
if (this.patentWallSearchConf == null) {
this.patentWallSearchConf = Util.readProperties2Map("PatentWall", "aiyh." + prefix);
}
if (this.patentWallSearchConf == null) {
return new HashMap<>(0);
}
return new HashMap<>(this.patentWallSearchConf);
}
}
public void clearPatentWallSerachConf() {
this.patentWallSearchConf = null;
}
} }

View File

@ -0,0 +1,27 @@
package com.api.aiyh_pcn.patentWall.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/29 0029 18:27
* VO
*/
@Getter
@Setter
@ToString
public class SearchInputVO {
private Integer type;
private String dbFieldName;
private String labelName;
private String value;
private Integer labelIndex;
private Integer searchType;
private Boolean multiple;
private List<SelectOptionsVo> selectOptions;
}

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/11/29 0029 18:37
*/
@Getter
@Setter
@ToString
public class SelectOptionsVo {
private String key;
private boolean selected;
private String showname;
}

View File

@ -750,7 +750,7 @@ public class AiyhUtilTest extends BaseTest {
@Test @Test
public void testGetList(){ public void testGetList(){
PatentWallService patentWallService = new PatentWallService(); PatentWallService patentWallService = new PatentWallService();
patentWallService.getList(null); patentWallService.getList(null,"");
} }
@Test @Test

View File

@ -0,0 +1,336 @@
package customization.test;
import aiyh.utils.Util;
import aiyh.utils.fileUtil.ProperUtil;
import com.alibaba.fastjson.JSON;
import com.api.aiyh_pcn.patentWall.service.PatentWallService;
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import com.api.aiyh_pcn.patentWall.vo.SearchInputVO;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import weaver.common.util.string.StringUtil;
import weaver.general.GCONST;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/29 0029 10:16
*/
public class NewUtilTest {
@Before
public void before() throws Exception {
GCONST.setServerName("ecology");
GCONST.setRootPath("H:\\e-cology-dev\\web\\");
}
@AfterClass
public static void after() {
System.out.println("单元测试结束!");
}
@Test
public void testKey() {
String key = "aiyh.patent.config[11].public";
String pattern = "^(aiyh.patent\\.)(?<key>(\\w+))$";
String pattern1 = "^(aiyh.patent\\.)(?<key>(?<objKey>(\\w+))\\.(\\S)+(?!\\[))";
String pattern2 = "^(aiyh.patent\\.)(?<key>(\\w+))(\\[([0-9])+])$";
String pattern3 = "^(aiyh.patent\\.)(?<key>(\\w+))(\\[(?<index>([0-9])+)])\\.(?<objKey>(\\S)+)$";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(key);
while (matcher.find()) {
System.out.println("单一值");
System.out.println(matcher.group("key"));
}
compile = Pattern.compile(pattern2);
matcher = compile.matcher(key);
while (matcher.find()) {
System.out.println("数组");
System.out.println(matcher.group("key"));
}
compile = Pattern.compile(pattern3);
matcher = compile.matcher(key);
while (matcher.find()) {
System.out.println("对象数组");
System.out.println(matcher.group("key"));
System.out.println(matcher.group("objKey"));
System.out.println(matcher.group("index"));
}
compile = Pattern.compile(pattern1);
matcher = compile.matcher(key);
while (matcher.find()) {
System.out.println("多个");
System.out.println(matcher.group("key"));
System.out.println(matcher.group("objKey"));
}
}
@Test
public void testGetPro() {
String key = "aiyh.patent.config[0]";
String prefix = "aiyh.patent";
String value = "第一个元素";
getPro(prefix, key, value);
}
public void getPro(String prefix, String key, Object value) {
Map<String, Object> result = new HashMap<>();
// result = keyHandler(prefix, key, value, result);
String key2 = "aiyh.patent.config[1]";
// result = keyHandler(prefix, key2, "第二个元素", result);
System.out.println(JSON.toJSONString(result));
}
@Test
public void redPro() {
String fileName = "test";
String prefix = "aiyh.patentWall";
Map<String, Object> result = Util.readProperties2Map(fileName, prefix);
System.out.println(JSON.toJSONString(result));
}
public Map<String, Object> getProperties2Map(String fileName, String prefix) {
String propertyPath = GCONST.getPropertyPath();
if (StringUtil.isNullOrEmpty(fileName)) {
return null;
}
if (fileName.contains(".properties")) {
fileName.replace(".properties", "");
}
String path = propertyPath + "prop2map" + File.separator + fileName + ".properties";
ProperUtil prop = new ProperUtil();
Map<String, Object> map = new HashMap<>();
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(path));
prop.load(inputStream);
// Enumeration<?> enumeration = prop.propertyNames();
// 顺序读取
Enumeration<?> enumeration = prop.keys();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
String value = prop.getProperty(key);
System.out.println(key);
keyHandler(prefix, key, value, map);
;
}
} catch (IOException e) {
throw new RuntimeException("找不到文件:" + path);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
public Map<String, Object> keyHandler(String prePrefix, String key, Object value, Map<String, Object> preResult) {
String objRegex = "^(" + prePrefix + "\\.)(?<key>(\\w+))$";
Pattern compile = Pattern.compile(objRegex);
Matcher matcher = compile.matcher(key);
if (matcher.find()) {
// 只匹配前缀.key=value模式的
String resultKey = matcher.group("key");
preResult.put(resultKey, prop2MapPutValue(value));
}
String moreKey = "^(" + prePrefix + "\\.)(?<key>(?<objKey>(\\w+))\\.(\\S)+(?!\\[))";
compile = Pattern.compile(moreKey);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key1.key2=value模式的
String objKey = matcher.group("objKey");
String prefixStr = prePrefix + "." + objKey;
Map<String, Object> valueMap;
if (preResult.containsKey(objKey)) {
valueMap = (Map<String, Object>) preResult.get(objKey);
keyHandler(prefixStr, key, value, valueMap);
return null;
}
valueMap = new HashMap<>();
keyHandler(prefixStr, key, value, valueMap);
preResult.put(objKey, valueMap);
return null;
}
String strList = "^(" + prePrefix + "\\.)(?<key>(\\w+))(\\[(?<index>([0-9])+)])$";
compile = Pattern.compile(strList);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key[0]=value模式的
String objKey = matcher.group("key");
int index = Integer.parseInt(matcher.group("index"));
if (preResult.containsKey(objKey)) {
// 存在值
List<Object> valueList = (List<Object>) preResult.get(objKey);
if (index >= valueList.size()) {
valueList.add(prop2MapPutValue(value));
} else {
valueList.set(index, prop2MapPutValue(value));
}
return null;
}
List<Object> valueList = new ArrayList<>();
valueList.add(prop2MapPutValue(value));
preResult.put(objKey, valueList);
return null;
}
String objArray = "^(" + prePrefix + "\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])\\.(?<objKey>(\\S)+)$";
// String objArray = "^("+prePrefix+"\\.)(?<arrKey>(\\w+))(\\[(?<index>([0-9])+)])(\\.(?<objKey>(\\S)+))+";
compile = Pattern.compile(objArray);
matcher = compile.matcher(key);
if (matcher.find()) {
// 匹配前缀.key[0].name=value的模式
String arrKey = matcher.group("arrKey");
String objKey = matcher.group("objKey");
int index = Integer.parseInt(matcher.group("index"));
List<Map<String, Object>> mapList;
if (preResult.containsKey(arrKey)) {
// 存在
mapList = (List<Map<String, Object>>) preResult.get(arrKey);
// mapList
Map<String, Object> valueMap;
if (index >= mapList.size()) {
valueMap = new HashMap<>();
valueMap.put(objKey, prop2MapPutValue(value));
mapList.add(valueMap);
return null;
}
valueMap = mapList.get(index);
String arrMoreKey = "(?<key>(\\w+))\\.(\\S)+(?!\\[)";
Pattern arrMoreKeyCompile = Pattern.compile(arrMoreKey);
Matcher arrMoreKeyMatcher = arrMoreKeyCompile.matcher(objKey);
if (arrMoreKeyMatcher.find()) {
String arrMoreObjKey = arrMoreKeyMatcher.group("key");
Map<String, Object> arrMoreValue;
if (valueMap.containsKey(arrMoreObjKey)) {
arrMoreValue = (Map<String, Object>) valueMap.get(arrMoreObjKey);
keyHandler(arrMoreObjKey, objKey, value, arrMoreValue);
return null;
}
arrMoreValue = new HashMap<>();
keyHandler(arrMoreObjKey, objKey, value, arrMoreValue);
valueMap.put(arrMoreObjKey, arrMoreValue);
return null;
}
arrMoreKey = "(?<key>(\\w+))(\\[(?<index>([0-9])+)])$";
arrMoreKeyCompile = Pattern.compile(arrMoreKey);
arrMoreKeyMatcher = arrMoreKeyCompile.matcher(objKey);
if (arrMoreKeyMatcher.find()) {
String arrMoreArrKey = arrMoreKeyMatcher.group("key");
int arrMoreIndex = Integer.parseInt(arrMoreKeyMatcher.group("index"));
List<Object> arrMoreListValue;
if (valueMap.containsKey(arrMoreArrKey)) {
// 存在值
arrMoreListValue = (List<Object>) valueMap.get(arrMoreArrKey);
if (arrMoreIndex >= arrMoreListValue.size()) {
arrMoreListValue.add(prop2MapPutValue(value));
} else {
arrMoreListValue.set(arrMoreIndex, prop2MapPutValue(value));
}
return null;
}
arrMoreListValue = new ArrayList<>();
arrMoreListValue.add(prop2MapPutValue(value));
valueMap.put(arrMoreArrKey, arrMoreListValue);
return null;
}
// 直接添加
valueMap.put(objKey, prop2MapPutValue(value));
return null;
}
// 不存在
mapList = new ArrayList<>();
Map<String, Object> valueMap = new HashMap<>();
valueMap.put(objKey, prop2MapPutValue(value));
mapList.add(valueMap);
preResult.put(arrKey, mapList);
}
return null;
}
public Object prop2MapPutValue(Object value) {
if(value == null){
return null;
}
String valueStr = String.valueOf(value).trim();
if (valueStr.startsWith("\"") && valueStr.endsWith("\"")) {
return valueStr.substring(1, valueStr.length() - 1);
}
if (valueStr.contains(",")) {
return valueStr.split(",");
}
return value;
}
@Test
public void testSubstr() {
System.out.println("\"这个是文本框\"".trim().substring(1, "\"这个是文本框\"".trim().length() - 1));
}
@Test
public void testSplit() {
String str = "12,343,89\\,99";
String str1 = "abcd'efg'hig?'klmn";
String[] data = str1.split("(?<!\\?)'");
System.out.println(Arrays.toString(data));
String[] split = str.split("(?<!\\\\),");
System.out.println(Arrays.toString(split));
for (int i = 0; i < split.length; i ++){
split[i] = split[i].replaceAll("\\\\,",",");
}
for (String s : split){
System.out.println(s);
}
}
@Test
public void testLanguage(){
String selectName = "~`~`7 其它 不知道 管他呢,阿斯顿发的`~`8 other`~`9 其它`~`~";
String showName = selectName;
if(selectName.startsWith("~`~`") && selectName.endsWith("`~`~")){
String pattern = "(`~`7 )(?<lable>(\\w*|\\W*|[\\u4e00-\\u9fa5]*))(`~`)";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(selectName);
if(matcher.find()){
showName = matcher.group("lable");
}
}
System.out.println(showName);
}
@Test
public void testPatentServer(){
PatentWallService patentWallService = new PatentWallService();
List<SearchInputVO> inputList = patentWallService.getSearchList("patentWall", 8);
System.out.println(JSON.toJSONString(inputList));
List<PatentVO> patentWallList = patentWallService.getList(null, "patentWall");
System.out.println(JSON.toJSONString(patentWallList));
}
@Test
public void testRegx(){
String pattern = "\\$\\{(?<field>(\\s|\\S)+?)}";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher("${id}");
if (matcher.find()){
System.out.println(matcher.group("field"));
}
}
}