编写新页面接口

dev
IT-xiaoXiong 2021-11-25 21:46:05 +08:00
parent 9ea873a7ca
commit 8ac1b5735b
20 changed files with 498 additions and 42 deletions

View File

@ -32,6 +32,7 @@ import java.beans.PropertyDescriptor;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.text.ParseException; import java.text.ParseException;
@ -1085,7 +1086,7 @@ public class Util extends weaver.general.Util {
public static Map<String, List<String>> parsingSq2Map(String sql) { public static Map<String, List<String>> parsingSq2Map(String sql) {
Map<String, List<String>> map = new HashMap<>(); Map<String, List<String>> map = new HashMap<>();
String pattern = "\\{{2}(?<table>((?!\\$)\\S)+?)\\.(?<field>\\S+?)}{2}"; String pattern = "\\{{2}(?<table>((?!\\$)\\s\\S)+?)\\.(?<field>\\s\\S+?)}{2}";
Pattern compile = Pattern.compile(pattern); Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(sql); Matcher matcher = compile.matcher(sql);
while (matcher.find()) { while (matcher.find()) {
@ -1101,7 +1102,7 @@ public class Util extends weaver.general.Util {
} }
public static Matcher parsingSql2Matcher(String sql) { public static Matcher parsingSql2Matcher(String sql) {
String pattern = "\\{{2}(?<table>((?!\\$)\\S)+?)\\.(?<field>\\S+?)}{2}"; String pattern = "\\{{2}(?<table>((?!\\$)\\s\\S)+?)\\.(?<field>\\s\\S+?)}{2}";
Pattern compile = Pattern.compile(pattern); Pattern compile = Pattern.compile(pattern);
return compile.matcher(sql); return compile.matcher(sql);
} }
@ -1415,4 +1416,24 @@ public class Util extends weaver.general.Util {
} }
return ""; return "";
} }
public static <T> T mapToObject(Map<String, Object> map, Class<T> t) throws Exception {
if (map == null) {
return null;
}
T obj = t.newInstance();
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {
int mod = field.getModifiers();
if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) {
continue;
}
field.setAccessible(true);
if (map.containsKey(field.getName())) {
field.set(obj, map.get(field.getName()));
}
}
return obj;
}
} }

View File

@ -0,0 +1,38 @@
package com.api.aiyh_pcn.patentWall.controller;
import aiyh.utils.ApiResult;
import com.api.aiyh_pcn.patentWall.service.PatentWallService;
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.List;
import java.util.Map;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:18
*
*/
@Path("/patten/")
public class PatentWallController {
private final PatentWallService patentWallService = new PatentWallService();
@Path("/getList")
@POST
public String getPatentList(@RequestBody Map<String,Object> map){
List<PatentVO> result = patentWallService.getList(map);
return ApiResult.success(result);
}
@Path("/clearConf")
@GET
public String clearPatentWallConf(){
patentWallService.clearPatentWallConf();
return ApiResult.success("清除配置缓存成功!");
}
}

View File

@ -0,0 +1,18 @@
package com.api.aiyh_pcn.patentWall.dao;
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import java.util.List;
import java.util.Map;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:28
*/
public class PatentWallMapping {
public List<Map<String,Object>> getList(Map<String, Object> map) {
return null;
}
}

View File

@ -0,0 +1,13 @@
package com.api.aiyh_pcn.patentWall.entity;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:30
*/
public class PatentEntity {
private String id;
private String icon;
private String linkUrl;
}

View File

@ -0,0 +1,100 @@
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;
}
}

View File

@ -0,0 +1,23 @@
package com.api.aiyh_pcn.patentWall.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 15:31
*/
@Getter
@Setter
@ToString
public class PatentVO {
private String id;
private String icon;
private String activeIcon;
private String linkUrl;
private String title;
private String docId;
private String imageFileId;
}

View File

@ -16,6 +16,7 @@ import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.Where; import aiyh.utils.sqlUtil.whereUtil.Where;
import com.api.aiyh_guijiu.service.WorkflowQueueService; import com.api.aiyh_guijiu.service.WorkflowQueueService;
import com.api.aiyh_guijiu.vo.PicPsVO; import com.api.aiyh_guijiu.vo.PicPsVO;
import com.api.aiyh_pcn.patentWall.vo.PatentVO;
import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException; import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory; import com.drew.metadata.Directory;
@ -64,6 +65,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @author EBU7-dev1-ayh * @author EBU7-dev1-ayh
@ -697,4 +700,47 @@ public class AiyhUtilTest extends BaseTest {
net.sf.json.JSONObject jsonObject = HttpUtil.postImage(new byte[1], new User()); net.sf.json.JSONObject jsonObject = HttpUtil.postImage(new byte[1], new User());
System.out.println(jsonObject); System.out.println(jsonObject);
} }
}
@Test
public void getMap() {
Map<String, Object> patentWall = Util.getProperties2Map("PatentWall", "aiyh.patentWall");
List<String> args = new ArrayList<>();
patentWall.forEach((key,value)->{
System.out.println("key ——> " + key);
String pattern = "\\$\\{(?<field>(\\s\\S)+?)}";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(String.valueOf(value));
System.out.println("value --> " + value);
String parsing = String.valueOf(value);
while (matcher.find()){
System.out.println("解析 ---> " + matcher.group("field"));
parsing = parsing.replaceFirst(pattern,"反正是对的");
System.out.println("解析后———> " + parsing);
}
pattern = "#\\{(?<field>(\\s\\S)+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(String.valueOf(parsing));
while (matcher.find()){
parsing = parsing.replaceFirst(pattern,"?");
args.add("haoba ");
}
pattern = "#sql\\{(?<field>([\\s\\S])+?)}";
compile = Pattern.compile(pattern);
matcher = compile.matcher(parsing);
while (matcher.find()){
System.out.println("============执行SQL============");
System.out.println(matcher.group("field"));
System.out.println(args);
System.out.println("============执行SQL结束============");
}
args.clear();
});
System.out.println(patentWall);
}
@Test
public void testFormat(){
System.out.printf("sql %s参数 %s%n","我是SQL","我是参数");
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
package customutil.proxy.dynamicProxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:53
*/
public class Customer implements IOrderInterface{
@Override
public String order(String foodName){
System.out.println("顾客下单。。。");
return "已经下单了" + foodName;
}
}

View File

@ -0,0 +1,11 @@
package customutil.proxy.dynamicProxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:05
*/
public interface IOrderInterface {
public String order(String foodName);
}

View File

@ -0,0 +1,30 @@
package customutil.proxy.dynamicProxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:53
*/
public class Test {
public static void main(String[] args) {
Customer customer = new Customer();
IOrderInterface iOrderInterface = (IOrderInterface) Proxy.newProxyInstance(
customer.getClass().getClassLoader(),
customer.getClass().getInterfaces(),
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(customer,args);
System.out.println("接收到订单,正在去取餐途中。。。");
return result;
}
});
String result = iOrderInterface.order("鱼香肉丝");
System.out.println(result);
}
}

View File

@ -0,0 +1,29 @@
package customutil.proxy.dynamicProxy;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 13:06
*/
public class TestCGLIB {
public static void main(String[] args) {
Customer customer = new Customer();
Customer deliveryClerk = (Customer) Enhancer.create(Customer.class, new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object result = method.invoke(customer,objects);
System.out.println("接收到订单,正在去取餐途中。。。");
return result;
}
});
String result = deliveryClerk.order("口水鸡");
System.out.println(result);
}
}

View File

@ -0,0 +1,15 @@
package customutil.proxy.staticProxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 11:57
*
*/
public class Customer {
public String order(String foodName){
System.out.println("顾客下单。。。");
return "已经下单了" + foodName;
}
}

View File

@ -0,0 +1,17 @@
package customutil.proxy.staticProxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 11:59
*
*/
public class DeliverClerk extends Customer {
@Override
public String order(String foodName) {
String result = super.order(foodName);
System.out.println("接收到订单,正在去取餐途中。。。");
return result+",已经搅拌均匀";
}
}

View File

@ -0,0 +1,15 @@
package customutil.proxy.staticProxy;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:02
*/
public class Test {
public static void main(String[] args) {
Customer customer = new DeliverClerk();
String result = customer.order("小炒肉");
System.out.println(result);
}
}

View File

@ -0,0 +1,22 @@
package customutil.proxy.staticProxy.interfaceModel;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:07
*/
public class DeliverClerkImpl implements IOrderInterface {
private IOrderInterface iOrderInterface;
public DeliverClerkImpl(IOrderInterface iOrderInterface) {
this.iOrderInterface = iOrderInterface;
}
@Override
public String order(String foodName) {
String result = iOrderInterface.order(foodName);
System.out.println("接收到订单,正在去取餐途中。。。");
return result + ",已经搅拌均匀";
}
}

View File

@ -0,0 +1,11 @@
package customutil.proxy.staticProxy.interfaceModel;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:05
*/
public interface IOrderInterface {
public String order(String foodName);
}

View File

@ -0,0 +1,17 @@
package customutil.proxy.staticProxy.interfaceModel;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:09
*/
public class Test {
public static void main(String[] args) {
customerImpl customer = new customerImpl();
// 创建代理对象
IOrderInterface orderInterface = new DeliverClerkImpl(customer);
String result = orderInterface.order("红烧肉");
System.out.println(result);
}
}

View File

@ -0,0 +1,15 @@
package customutil.proxy.staticProxy.interfaceModel;
/**
* @author EBU7-dev1-ayh
* @create 2021/11/25 0025 12:06
*/
public class customerImpl implements IOrderInterface {
@Override
public String order(String foodName) {
System.out.println("顾客下单。。。");
return "已经下单了" + foodName;
}
}