101 lines
3.1 KiB
Java
101 lines
3.1 KiB
Java
|
package com.api.aiyh_pcn.patentWall.service;
|
|||
|
|
|||
|
import aiyh.utils.Util;
|
|||
|
import aiyh.utils.zwl.common.ToolUtil;
|
|||
|
import com.api.aiyh_pcn.patentWall.dao.PatentWallMapping;
|
|||
|
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
|
|||
|
import weaver.conn.RecordSet;
|
|||
|
|
|||
|
import java.util.ArrayList;
|
|||
|
import java.util.HashMap;
|
|||
|
import java.util.List;
|
|||
|
import java.util.Map;
|
|||
|
import java.util.regex.Matcher;
|
|||
|
import java.util.regex.Pattern;
|
|||
|
|
|||
|
/**
|
|||
|
* @author EBU7-dev1-ayh
|
|||
|
* @create 2021/11/25 0025 15:23
|
|||
|
*/
|
|||
|
|
|||
|
|
|||
|
public class PatentWallService {
|
|||
|
private final PatentWallMapping patentWallMapping = new PatentWallMapping();
|
|||
|
private final ToolUtil toolUtil = new ToolUtil();
|
|||
|
private Map<String, Object> patentWallConf;
|
|||
|
|
|||
|
public List<PatentVO> getList(Map<String, Object> map) {
|
|||
|
Map<String, Object> patentWallConf = getPatentWallConf();
|
|||
|
List<Map<String, Object>> dataList = patentWallMapping.getList(map);
|
|||
|
List<PatentVO> list = new ArrayList<>();
|
|||
|
List<String> args = new ArrayList<>();
|
|||
|
RecordSet rs = new RecordSet();
|
|||
|
for (Map<String, Object> data : dataList) {
|
|||
|
for(Map.Entry<String,Object> entry : patentWallConf.entrySet()){
|
|||
|
String patentVoField = entry.getKey();
|
|||
|
String parsing = String.valueOf(entry.getValue());
|
|||
|
// 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(patentVoField)));
|
|||
|
}
|
|||
|
// 解析#{}类型的参数,替换为?并按照顺序收集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(patentVoField)));
|
|||
|
}
|
|||
|
// 解析#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 = Util.null2String(rs.getString(1));
|
|||
|
}
|
|||
|
// 清除参数信息
|
|||
|
args.clear();
|
|||
|
// 修改数据
|
|||
|
patentWallConf.replace(patentVoField,parsing);
|
|||
|
}
|
|||
|
PatentVO patentVO = null;
|
|||
|
try {
|
|||
|
patentVO = Util.mapToObject(patentWallConf, PatentVO.class);
|
|||
|
} catch (Exception e) {
|
|||
|
e.printStackTrace();
|
|||
|
toolUtil.writeErrorLog("map转为PatentVO失败!");
|
|||
|
}
|
|||
|
list.add(patentVO);
|
|||
|
}
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 获取单例的配置文件信息
|
|||
|
* @return
|
|||
|
*/
|
|||
|
private Map<String, Object> getPatentWallConf() {
|
|||
|
synchronized (this){
|
|||
|
if(this.patentWallConf == null){
|
|||
|
this.patentWallConf = Util.getProperties2Map("PatentWall", "aiyh.patentWall");
|
|||
|
}
|
|||
|
if(this.patentWallConf == null){
|
|||
|
return new HashMap<>(0);
|
|||
|
}
|
|||
|
return new HashMap<>(this.patentWallConf);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void clearPatentWallConf(){
|
|||
|
this.patentWallConf = null;
|
|||
|
}
|
|||
|
}
|