Commit 492a68f3 authored by yanzg's avatar yanzg

消除成功接收处理

parent 37d70485
...@@ -292,7 +292,8 @@ public class ObjectHelper { ...@@ -292,7 +292,8 @@ public class ObjectHelper {
while (tempClass != null) { while (tempClass != null) {
fields.addAll(Arrays.asList(tempClass.getDeclaredFields())); fields.addAll(Arrays.asList(tempClass.getDeclaredFields()));
methods.addAll(Arrays.asList(tempClass.getDeclaredMethods())); methods.addAll(Arrays.asList(tempClass.getDeclaredMethods()));
tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己 //得到父类,然后赋给自己
tempClass = tempClass.getSuperclass();
} }
// 忽略大小写、忽略下划线 _ // 忽略大小写、忽略下划线 _
......
...@@ -28,6 +28,8 @@ public final class CheckerHelper { ...@@ -28,6 +28,8 @@ public final class CheckerHelper {
public static final String PARAM_NOT_MIN = "param [%s] must be big %d"; public static final String PARAM_NOT_MIN = "param [%s] must be big %d";
public static final String PARAM_NOT_MAX = "param [%s] must be max %d"; public static final String PARAM_NOT_MAX = "param [%s] must be max %d";
public static final String PARAM_NOT_RANGE = "param [%s] must be range %d and %d"; public static final String PARAM_NOT_RANGE = "param [%s] must be range %d and %d";
public static final String DATE_CHECK_TYPE_DAY = "day";
public static final String DATE_CHECK_TYPE_MONTH = "month";
private boolean isValid = true; private boolean isValid = true;
private String checkResult; private String checkResult;
...@@ -178,10 +180,10 @@ public final class CheckerHelper { ...@@ -178,10 +180,10 @@ public final class CheckerHelper {
this.setValid(false); this.setValid(false);
return this; return this;
} }
if ("day".equals(queryType)) { if (DATE_CHECK_TYPE_DAY.equals(queryType)) {
eL = "[0-9]{4}[0-9]{2}[0-9]{2}"; eL = "[0-9]{4}[0-9]{2}[0-9]{2}";
msg = PARAM_NOT_DATE_DAY; msg = PARAM_NOT_DATE_DAY;
} else if ("month".equals(queryType)) { } else if (DATE_CHECK_TYPE_MONTH.equals(queryType)) {
eL = "[0-9]{4}[0-9]{2}"; eL = "[0-9]{4}[0-9]{2}";
msg = PARAM_NOT_DATE_MONTH; msg = PARAM_NOT_DATE_MONTH;
} }
......
...@@ -69,11 +69,17 @@ public class DateAutoHelper { ...@@ -69,11 +69,17 @@ public class DateAutoHelper {
* 时间格式字符串 * 时间格式字符串
*/ */
private static class DateReplace { private static class DateReplace {
// 正则表达式 /**
* 正则表达式
*/
public String regex; public String regex;
// 替换表达式 /**
* 替换表达式
*/
public String replace; public String replace;
// 终止标志位 /**
* 终止标志位
*/
public boolean end; public boolean end;
} }
......
...@@ -116,13 +116,16 @@ public class FileHelper { ...@@ -116,13 +116,16 @@ public class FileHelper {
boolean flag = false; boolean flag = false;
File file = new File(sPath); File file = new File(sPath);
// 判断目录或文件是否存在 // 判断目录或文件是否存在
if (!file.exists()) { // 不存在返回 false if (!file.exists()) {
// 不存在返回 false
return flag; return flag;
} else { } else {
// 判断是否为文件 // 判断是否为文件
if (file.isFile()) { // 为文件时调用删除文件方法 if (file.isFile()) {
// 为文件时调用删除文件方法
return deleteFile(sPath); return deleteFile(sPath);
} else { // 为目录时调用删除目录方法 } else {
// 为目录时调用删除目录方法
return deleteDirectory(sPath); return deleteDirectory(sPath);
} }
} }
......
...@@ -83,10 +83,13 @@ public class HttpHelper { ...@@ -83,10 +83,13 @@ public class HttpHelper {
* @return 远程响应结果 * @return 远程响应结果
*/ */
public static String post(HttpURLConnection httpConn, String url, String jsonString) throws IOException { public static String post(HttpURLConnection httpConn, String url, String jsonString) throws IOException {
String result = "";// 返回的结果 // 返回的结果
BufferedReader in = null;// 读取响应输入流 String result = "";
// 读取响应输入流
BufferedReader in = null;
PrintWriter out = null; PrintWriter out = null;
StringBuffer sb = new StringBuffer();// 处理请求参数 // 处理请求参数
StringBuffer sb = new StringBuffer();
String params = ""; String params = "";
try { try {
params = jsonString; params = jsonString;
......
...@@ -7,7 +7,12 @@ import com.alibaba.fastjson.TypeReference; ...@@ -7,7 +7,12 @@ import com.alibaba.fastjson.TypeReference;
* JSON序列化的处理 * JSON序列化的处理
* Created by yanzu on 2017/5/28. * Created by yanzu on 2017/5/28.
*/ */
public class JSONHelper { public class JsonHelper {
/**
* JSON对象开始标记
*/
public static final String OBJECT_START_FLAG = "{";
/** /**
* 将JSON字符串转化为JSON对象 * 将JSON字符串转化为JSON对象
...@@ -48,7 +53,7 @@ public class JSONHelper { ...@@ -48,7 +53,7 @@ public class JSONHelper {
return null; return null;
} }
json = json.trim(); json = json.trim();
if (json.startsWith("{")) { if (json.startsWith(OBJECT_START_FLAG)) {
json = String.format("[%s]", json); json = String.format("[%s]", json);
} }
return JSON.parseObject(json, type); return JSON.parseObject(json, type);
......
...@@ -42,7 +42,8 @@ public class RunHelper { ...@@ -42,7 +42,8 @@ public class RunHelper {
break; break;
} catch (Exception e) { } catch (Exception e) {
if (i < size) { if (i < size) {
ThreadHelper.sleep(sleep); // 间隔100ms,防止服务器重启时请求失败 // 间隔100ms,防止服务器重启时请求失败
ThreadHelper.sleep(sleep);
} }
ex = e; ex = e;
} }
......
...@@ -139,20 +139,23 @@ public class StringHelper { ...@@ -139,20 +139,23 @@ public class StringHelper {
boolean foundDigit = false; boolean foundDigit = false;
// deal with any possible sign up front // deal with any possible sign up front
final int start = (chars[0] == '-') ? 1 : 0; final int start = (chars[0] == '-') ? 1 : 0;
if (sz > start + 1 && chars[start] == '0') { // leading 0 // leading 0
if (sz > start + 1 && chars[start] == '0') {
if ( if (
(chars[start + 1] == 'x') || (chars[start + 1] == 'x') ||
(chars[start + 1] == 'X') (chars[start + 1] == 'X')
) { // leading 0x/0X ) { // leading 0x/0X
int i = start + 2; int i = start + 2;
if (i == sz) { if (i == sz) {
return false; // str == "0x" // str == "0x"
return false;
} }
// checking hex (it can't be anything else) // checking hex (it can't be anything else)
for (; i < chars.length; i++) { for (; i < chars.length; i++) {
if ((chars[i] < '0' || chars[i] > '9') boolean inputHex = (chars[i] < '0' || chars[i] > '9')
&& (chars[i] < 'a' || chars[i] > 'f') && (chars[i] < 'a' || chars[i] > 'f')
&& (chars[i] < 'A' || chars[i] > 'F')) { && (chars[i] < 'A' || chars[i] > 'F');
if (inputHex) {
return false; return false;
} }
} }
...@@ -200,7 +203,8 @@ public class StringHelper { ...@@ -200,7 +203,8 @@ public class StringHelper {
return false; return false;
} }
allowSigns = false; allowSigns = false;
foundDigit = false; // we need a digit after the E // we need a digit after the E
foundDigit = false;
} else { } else {
return false; return false;
} }
...@@ -223,11 +227,12 @@ public class StringHelper { ...@@ -223,11 +227,12 @@ public class StringHelper {
// single trailing decimal point after non-exponent is ok // single trailing decimal point after non-exponent is ok
return foundDigit; return foundDigit;
} }
if (!allowSigns boolean allowD = !allowSigns
&& (chars[i] == 'd' && (chars[i] == 'd'
|| chars[i] == 'D' || chars[i] == 'D'
|| chars[i] == 'f' || chars[i] == 'f'
|| chars[i] == 'F')) { || chars[i] == 'F');
if (allowD) {
return foundDigit; return foundDigit;
} }
if (chars[i] == 'l' if (chars[i] == 'l'
...@@ -467,7 +472,7 @@ public class StringHelper { ...@@ -467,7 +472,7 @@ public class StringHelper {
* @return 转换成功后的值 * @return 转换成功后的值
*/ */
public static double toDecimal(Object from) { public static double toDecimal(Object from) {
Double result = Double.valueOf(0); double result = 0;
try { try {
if (!isEmpty(from)) { if (!isEmpty(from)) {
result = Double.valueOf(from.toString()); result = Double.valueOf(from.toString());
...@@ -515,7 +520,8 @@ public class StringHelper { ...@@ -515,7 +520,8 @@ public class StringHelper {
byte[] buff; byte[] buff;
try { try {
buff = from.getBytes(charset); buff = from.getBytes(charset);
from = new String(buff); // 将字节流转换为字符串 // 将字节流转换为字符串
from = new String(buff);
from = from.replace("\0", "").replace("\n", ""); from = from.replace("\0", "").replace("\n", "");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
ExceptionHelper.handleException(StringHelper.class, e, from); ExceptionHelper.handleException(StringHelper.class, e, from);
......
...@@ -19,9 +19,9 @@ public class RunPlanData { ...@@ -19,9 +19,9 @@ public class RunPlanData {
*/ */
private double executeCount; private double executeCount;
/** /**
* 执行时错误次数 * 执行时错误次数,调试变量
*/ */
private double executeError; // 调试变量 private double executeError;
/** /**
* 执行时间 * 执行时间
*/ */
......
...@@ -64,7 +64,7 @@ public final class RunnableListAuto { ...@@ -64,7 +64,7 @@ public final class RunnableListAuto {
// 没有执行过的列表 // 没有执行过的列表
List<RunnableListAutoItem> initList = new ArrayList<RunnableListAutoItem>(); List<RunnableListAutoItem> initList = new ArrayList<RunnableListAutoItem>();
// 已经执行过的数据缓存,待排序 // 已经执行过的数据缓存,待排序
Map<String, List<RunnableListAutoItem>> executeMap = new HashMap<String, List<RunnableListAutoItem>>(); Map<String, List<RunnableListAutoItem>> executeMap = new HashMap<>(20);
// 已执行过的列表 // 已执行过的列表
List<RunnableListAutoItem> executedToList = new ArrayList<RunnableListAutoItem>(); List<RunnableListAutoItem> executedToList = new ArrayList<RunnableListAutoItem>();
......
...@@ -16,7 +16,9 @@ public class ThreadHelper { ...@@ -16,7 +16,9 @@ public class ThreadHelper {
private static Date threadDate = null; private static Date threadDate = null;
private static RunPlan timeout; private static RunPlan timeout;
private static RunPlan interval; private static RunPlan interval;
// 线程对象 /**
* 线程对象
*/
private static ExecutorService executeService = Executors.newCachedThreadPool(); private static ExecutorService executeService = Executors.newCachedThreadPool();
/** /**
......
...@@ -31,30 +31,35 @@ public class ThreadNext { ...@@ -31,30 +31,35 @@ public class ThreadNext {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
boolean isExecute = true; runNext(next);
Exception frontEx = null;
while (isExecute) {
try {
isExecute = next.next();
} catch (Exception ex) {
if (frontEx == null || !(frontEx.getClass() == ex.getClass() &&
StringHelper.compare(frontEx.getMessage(), ex.getMessage()))) {
Log.error(ThreadNext.class, ex);
}
frontEx = ex;
}
if (isExecute) {
try {
int max = Math.max(next.getNextTime(), 100);
Thread.sleep(max);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
break;
}
}
} }
}).start(); }).start();
} }
private static void runNext(Next next) {
boolean isExecute = true;
Exception frontEx = null;
while (isExecute) {
try {
isExecute = next.next();
} catch (Exception ex) {
boolean isHistoryEx = frontEx == null || !(frontEx.getClass() == ex.getClass() &&
StringHelper.compare(frontEx.getMessage(), ex.getMessage()));
if (isHistoryEx) {
Log.error(ThreadNext.class, ex);
}
frontEx = ex;
}
if (isExecute) {
try {
int max = Math.max(next.getNextTime(), 100);
Thread.sleep(max);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
break;
}
}
}
} }
package com.yanzuoguang.util.vo; package com.yanzuoguang.util.vo;
import com.yanzuoguang.util.helper.JSONHelper; import com.yanzuoguang.util.helper.JsonHelper;
import java.io.Serializable; import java.io.Serializable;
...@@ -18,6 +18,6 @@ public class BaseVo implements Serializable { ...@@ -18,6 +18,6 @@ public class BaseVo implements Serializable {
*/ */
@Override @Override
public String toString() { public String toString() {
return JSONHelper.serialize(this); return JsonHelper.serialize(this);
} }
} }
...@@ -40,7 +40,9 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -40,7 +40,9 @@ public class BaseRequestAspect implements ThreadNext.Next {
*/ */
protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>(); protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>();
// 缓存的每次请求的结果 /**
* 缓存的每次请求的结果
*/
protected MemoryCache<RequestCacheResult> cacheResult = new MemoryCache<>(cacheTime); protected MemoryCache<RequestCacheResult> cacheResult = new MemoryCache<>(cacheTime);
public BaseRequestAspect() { public BaseRequestAspect() {
...@@ -67,8 +69,10 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -67,8 +69,10 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected LogVo initLogInterVo(String url, ProceedingJoinPoint joinPoint, ResponseResult responseResult) { protected LogVo initLogInterVo(String url, ProceedingJoinPoint joinPoint, ResponseResult responseResult) {
LogVo logInterVo = new LogVo(); LogVo logInterVo = new LogVo();
logInterVo.setLogId(StringHelper.getNewID()); logInterVo.setLogId(StringHelper.getNewID());
logInterVo.setLogSources(applicationName);//平台名 //平台名
logInterVo.setInterUrl(url);//请求URL logInterVo.setLogSources(applicationName);
//请求URL
logInterVo.setInterUrl(url);
List<Object> para = new ArrayList<>(); List<Object> para = new ArrayList<>();
for (Object item : joinPoint.getArgs()) { for (Object item : joinPoint.getArgs()) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) { if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
...@@ -80,8 +84,10 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -80,8 +84,10 @@ public class BaseRequestAspect implements ThreadNext.Next {
if (para.size() == 1) { if (para.size() == 1) {
paraTo = para.get(0); paraTo = para.get(0);
} }
logInterVo.setContent(JSON.toJSONString(paraTo));//请求参数 //请求参数
logInterVo.setResult(JSON.toJSONString(responseResult));//返回参数 logInterVo.setContent(JSON.toJSONString(paraTo));
//返回参数
logInterVo.setResult(JSON.toJSONString(responseResult));
logInterVo.setStatus(responseResult != null && responseResult.getCode() == ResultConstants.SUCCESS ? 1 : 0); logInterVo.setStatus(responseResult != null && responseResult.getCode() == ResultConstants.SUCCESS ? 1 : 0);
return logInterVo; return logInterVo;
} }
......
...@@ -3,7 +3,7 @@ package com.yanzuoguang.cloud.aop; ...@@ -3,7 +3,7 @@ package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.contants.ResultConstants; import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper; import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JSONHelper; import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.LogVo; import com.yanzuoguang.util.vo.LogVo;
...@@ -51,7 +51,8 @@ public class WebAspect extends BaseRequestAspect { ...@@ -51,7 +51,8 @@ public class WebAspect extends BaseRequestAspect {
@Around(value = "webAspect()") @Around(value = "webAspect()")
public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable {
Log.threadBegin(); Log.threadBegin();
ResponseResult responseResult = null; // 用户数据库记录 // 用户数据库记录
ResponseResult responseResult = null;
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
String name = joinPoint.getSignature().getName(); String name = joinPoint.getSignature().getName();
try { try {
...@@ -100,17 +101,17 @@ public class WebAspect extends BaseRequestAspect { ...@@ -100,17 +101,17 @@ public class WebAspect extends BaseRequestAspect {
} }
private Object executeMethod(ProceedingJoinPoint joinPoint, String name) throws Throwable { private Object executeMethod(ProceedingJoinPoint joinPoint, String name) throws Throwable {
if (joinPoint.getArgs().length != 1 boolean dataArgs = joinPoint.getArgs().length != 1
|| joinPoint.getArgs().length == 1 && || joinPoint.getArgs().length == 1 &&
(joinPoint.getArgs()[0] instanceof ServletResponse || joinPoint.getArgs()[0] instanceof ServletRequest) (joinPoint.getArgs()[0] instanceof ServletResponse || joinPoint.getArgs()[0] instanceof ServletRequest);
) { if (dataArgs) {
return joinPoint.proceed(); return joinPoint.proceed();
} else { } else {
// 获取请求编号 // 获取请求编号
Object firstArgs = joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : null; Object firstArgs = joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : null;
String reqId = ObjectHelper.getString(firstArgs, "reqId"); String reqId = ObjectHelper.getString(firstArgs, "reqId");
if (StringHelper.isEmpty(reqId)) { if (StringHelper.isEmpty(reqId)) {
reqId = StringHelper.md5(JSONHelper.serialize(firstArgs)); reqId = StringHelper.md5(JsonHelper.serialize(firstArgs));
} else { } else {
// 请求编号和公司编号挂钩 // 请求编号和公司编号挂钩
reqId = StringHelper.getId(ObjectHelper.getString(firstArgs, "companyId"), reqId); reqId = StringHelper.getId(ObjectHelper.getString(firstArgs, "companyId"), reqId);
......
package com.yanzuoguang.code; package com.yanzuoguang.code;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.util.helper.ByteHelper; import com.yanzuoguang.util.helper.ByteHelper;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/** /**
* 加密算法0版实现 * 加密算法0版实现
*/ */
...@@ -120,28 +126,28 @@ public class CodePwdImpl implements CodePwd { ...@@ -120,28 +126,28 @@ public class CodePwdImpl implements CodePwd {
return ret; return ret;
} }
// public static void main(String[] args) { public static void test(String[] args) {
// int[] pos2 = {3, 4, 5, 6, 8}; int[] pos2 = {3, 4, 5, 6, 8};
// int startPos = 0; int startPos = 0;
// int endPos = 1000000; int endPos = 1000000;
//
// Date start = new Date(); Date start = new Date();
// CodePwdReplaceImpl item = new CodePwdReplaceImpl(); CodePwdImpl item = new CodePwdImpl();
// Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
// for (int i = startPos; i < endPos; i++) { for (int i = startPos; i < endPos; i++) {
// String index = String.format("%09d", i); String index = String.format("%09d", i);
// String code = item.getCode("", "", index, "18532354168"); String code = item.getCode("", "", index, "18532354168");
// if (map.containsKey(code)) { if (map.containsKey(code)) {
// map.put(code, map.get(code) + 1); map.put(code, map.get(code) + 1);
// System.err.println("code: " + map.get(code)); System.err.println("code: " + map.get(code));
// } else { } else {
// map.put(code, 1); map.put(code, 1);
// } }
// int rand2 = pos2[new Random().nextInt(pos2.length)]; int rand2 = pos2[new Random().nextInt(pos2.length)];
// String mobile = "1" + rand2 + code; String mobile = "1" + rand2 + code;
// System.out.println(mobile); System.out.println(mobile);
// } }
// Date end = new Date(); Date end = new Date();
// System.out.println("长度: " + (endPos - startPos) + " time:" + (end.getTime() - start.getTime())); System.out.println("长度: " + (endPos - startPos) + " time:" + (end.getTime() - start.getTime()));
// } }
} }
...@@ -116,4 +116,8 @@ public class DaoConst { ...@@ -116,4 +116,8 @@ public class DaoConst {
* ID字段 * ID字段
*/ */
public static final String ID_FIELD = "id"; public static final String ID_FIELD = "id";
/**
* 集合初始化大小
*/
public static final int COLLECTION_INIT_SIZE = 15;
} }
...@@ -195,7 +195,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -195,7 +195,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
// 当主键存在值时,直接通过主键删除 // 当主键存在值时,直接通过主键删除
if (!StringHelper.isEmpty(keyString)) { if (!StringHelper.isEmpty(keyString)) {
// 去掉其他非主键的属性 // 去掉其他非主键的属性
from = new HashMap<String, Object>(); from = new HashMap<String, Object>(DaoConst.COLLECTION_INIT_SIZE);
this.setKeyString(from, keyString); this.setKeyString(from, keyString);
// 调用删除日志 // 调用删除日志
this.check(DaoConst.OPERATOR_TYPE_REMOVE, keyString, from); this.check(DaoConst.OPERATOR_TYPE_REMOVE, keyString, from);
...@@ -232,7 +232,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -232,7 +232,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
// 当主键存在时,只通过主键加载 // 当主键存在时,只通过主键加载
if (!StringHelper.isEmpty(key)) { if (!StringHelper.isEmpty(key)) {
from = new HashMap<String, Object>(); from = new HashMap<String, Object>(DaoConst.COLLECTION_INIT_SIZE);
this.setKeyString(from, key); this.setKeyString(from, key);
} }
...@@ -278,7 +278,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -278,7 +278,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
from = model; from = model;
this.setKeyString(model, md5); this.setKeyString(model, md5);
} else if (!StringHelper.isEmpty(this.table.getTable().getMD5KeyName())) { } else if (!StringHelper.isEmpty(this.table.getTable().getMD5KeyName())) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
map.put(this.table.getTable().getMD5KeyName(), md5); map.put(this.table.getTable().getMD5KeyName(), md5);
from = this.load(map, cls); from = this.load(map, cls);
} else { } else {
......
...@@ -410,11 +410,7 @@ public abstract class BaseDaoSql { ...@@ -410,11 +410,7 @@ public abstract class BaseDaoSql {
* @return SQL条件 * @return SQL条件
*/ */
protected String getQueryPara(List<Object> paras, SqlData sqlData, Object model) { protected String getQueryPara(List<Object> paras, SqlData sqlData, Object model) {
// 定义可替换片段 // 定义可替换片段
// String fromNext = "{FIELD_Front}";
// String fromPrev = "{FIELD}";
// String wherePrev = "{INNER}";
String[] lastCode = new String[]{"{WHERE}", "{GROUP}", "{HAVING}", "{ORDER}", "{LIMIT}"}; String[] lastCode = new String[]{"{WHERE}", "{GROUP}", "{HAVING}", "{ORDER}", "{LIMIT}"};
// 将SQL语句进行代码片段追加 // 将SQL语句进行代码片段追加
...@@ -425,9 +421,25 @@ public abstract class BaseDaoSql { ...@@ -425,9 +421,25 @@ public abstract class BaseDaoSql {
} }
} }
// 代码片段处理
sql = handleCodeMap(sql, sqlData, model);
// 通过正则表达式处理参数 @name 并替换SQL语句成 ?
sql = handlePara(sql, paras, model);
return sql;
}
/**
* 代码片段处理
*
* @return
*/
private String handleCodeMap(String sql, SqlData sqlData, Object model) {
// 处理字段以及代码片段 // 处理字段以及代码片段
// 代码片段缓存 // 代码片段缓存
Map<String, List<String>> codeMap = new HashMap<>(); Map<String, List<String>> codeMap = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
// 循环处理字段 // 循环处理字段
for (SqlDataField field : sqlData.getSqlDataFields()) { for (SqlDataField field : sqlData.getSqlDataFields()) {
// 获取值 // 获取值
...@@ -470,38 +482,46 @@ public abstract class BaseDaoSql { ...@@ -470,38 +482,46 @@ public abstract class BaseDaoSql {
// 寻找到的代码片段 不包含分括号 // 寻找到的代码片段 不包含分括号
while (m.find()) { while (m.find()) {
String name = m.group(); String name = m.group();
// m.group(1);
List<String> codes = codeMap.containsKey(name) ? codeMap.get(name) : new ArrayList<String>(); List<String> codes = codeMap.containsKey(name) ? codeMap.get(name) : new ArrayList<String>();
String code = String.join("", codes); String code = String.join("", codes);
sql = sql.replace(name, code); sql = sql.replace(name, code);
} }
} }
// 通过正则表达式处理参数 @name 并替换SQL语句成 ? return sql;
{ }
String regex = "@([a-zA-Z0-9_]+)";
Pattern p = Pattern.compile(regex); /**
Matcher m = p.matcher(sql); * 通过正则表达式处理参数 @name 并替换SQL语句成 ?
// 寻找到的代码片段 不包含分括号 *
while (m.find()) { * @param sql 需要处理的SQL语句
// SQL参数名称 @name\s * @param paras 需要添加的参数
String name = m.group(); * @param model 需要获取的参数实体
// 对应的前台输入字段 name * @return 处理后的SQL语句
String field = m.group(1); */
// 根据输入字段从参数中取值 private String handlePara(String sql, List<Object> paras, Object model) {
Object val = ObjectHelper.get(model, field); String regex = "@([a-zA-Z0-9_]+)";
// 判断是否为数组 Pattern p = Pattern.compile(regex);
if (val != null && (val instanceof List || val.getClass().isArray())) { Matcher m = p.matcher(sql);
sql = getListSql(paras, sql, name, val); // 寻找到的代码片段 不包含分括号
} else { while (m.find()) {
// 当参数不为数组时,则直接增加 // SQL参数名称 @name\s
sql = sql.replaceFirst(name, "?"); String name = m.group();
val = this.getParaValue(val); // 对应的前台输入字段 name
paras.add(val); String field = m.group(1);
} // 根据输入字段从参数中取值
Object val = ObjectHelper.get(model, field);
// 判断是否为数组
boolean isArray = val != null && (val instanceof List || val.getClass().isArray());
if (isArray) {
sql = getListSql(paras, sql, name, val);
} else {
// 当参数不为数组时,则直接增加
sql = sql.replaceFirst(name, "?");
val = this.getParaValue(val);
paras.add(val);
} }
} }
return sql; return sql;
} }
...@@ -647,7 +667,7 @@ public abstract class BaseDaoSql { ...@@ -647,7 +667,7 @@ public abstract class BaseDaoSql {
} }
// 将对象转换为 Map 对象 // 将对象转换为 Map 对象
Map to = new HashMap<String, Object>(); Map to = new HashMap<String, Object>(DaoConst.COLLECTION_INIT_SIZE);
if (from instanceof Map) { if (from instanceof Map) {
to = (Map) from; to = (Map) from;
} else { } else {
......
package com.yanzuoguang.dao.impl; package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.util.cache.MemoryCache; import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
...@@ -120,9 +121,9 @@ public class TableSqlCache { ...@@ -120,9 +121,9 @@ public class TableSqlCache {
*/ */
public List<SqlData> addGroupList(String sqlName, TableFieldString tableWhereField, TableFieldString addField, public List<SqlData> addGroupList(String sqlName, TableFieldString tableWhereField, TableFieldString addField,
String sql, String... field) { String sql, String... field) {
Map<String, Boolean> sqlFieldHas = new HashMap<String, Boolean>(); Map<String, Boolean> sqlFieldHas = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
Map<String, Boolean> sqlFieldWhere = new HashMap<String, Boolean>(); Map<String, Boolean> sqlFieldWhere = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
Map<String, Boolean> sqlFieldAdd = new HashMap<String, Boolean>(); Map<String, Boolean> sqlFieldAdd = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
SqlData sqlInit = new SqlData(sqlName + "_GroupInit", "", field); SqlData sqlInit = new SqlData(sqlName + "_GroupInit", "", field);
SqlData sqlAdd = new SqlData(sqlName + "_GroupAdd", "", field); SqlData sqlAdd = new SqlData(sqlName + "_GroupAdd", "", field);
...@@ -166,7 +167,7 @@ public class TableSqlCache { ...@@ -166,7 +167,7 @@ public class TableSqlCache {
String addModel = "UPDATE {table} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} "; String addModel = "UPDATE {table} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} ";
// 定义需要处理的SQL对象 // 定义需要处理的SQL对象
Map<String, StringBuilder> map = new HashMap<String, StringBuilder>(); Map<String, StringBuilder> map = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
addString(map, "{SQL}", sql); addString(map, "{SQL}", sql);
addString(map, "{table}", this.table.getName()); addString(map, "{table}", this.table.getName());
......
...@@ -76,9 +76,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -76,9 +76,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/ */
protected void initialize(Class<T> mappedClass) { protected void initialize(Class<T> mappedClass) {
this.mappedClass = mappedClass; this.mappedClass = mappedClass;
this.mappedFields = new HashMap<>(); this.mappedFields = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
this.mappedPropertys = new HashMap<>(); this.mappedPropertys = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
this.mappedIsFields = new HashMap<>(); this.mappedIsFields = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
if (ObjectHelper.isSub(MapRow.class, mappedClass) || ObjectHelper.isSub(Map.class, mappedClass)) { if (ObjectHelper.isSub(MapRow.class, mappedClass) || ObjectHelper.isSub(Map.class, mappedClass)) {
isMapping = true; isMapping = true;
......
package com.yanzuoguang.mq.dao; package com.yanzuoguang.mq.dao;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
...@@ -19,7 +20,9 @@ public class BeanDao { ...@@ -19,7 +20,9 @@ public class BeanDao {
private static final String QUEUE = "queue"; private static final String QUEUE = "queue";
private static final String EXCHANGE = "exchange"; private static final String EXCHANGE = "exchange";
// 上下文 /**
* 上下文
*/
@Autowired @Autowired
private ApplicationContext context; private ApplicationContext context;
...@@ -83,7 +86,7 @@ public class BeanDao { ...@@ -83,7 +86,7 @@ public class BeanDao {
bean = new Queue(queueName, true, false, false); bean = new Queue(queueName, true, false, false);
amqpAdmin.declareQueue(bean); amqpAdmin.declareQueue(bean);
} else { } else {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
if (deadTime > 0) { if (deadTime > 0) {
params.put("x-message-ttl", deadTime); params.put("x-message-ttl", deadTime);
} }
......
...@@ -39,7 +39,7 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao { ...@@ -39,7 +39,7 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
*/ */
@Override @Override
public int updateBatch(String batchId, int size) { public int updateBatch(String batchId, int size) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(1);
map.put("batchId", batchId); map.put("batchId", batchId);
SqlData sql = this.getSql(UPDATE_BATCH_SQL).copy(); SqlData sql = this.getSql(UPDATE_BATCH_SQL).copy();
......
...@@ -19,12 +19,16 @@ import java.util.List; ...@@ -19,12 +19,16 @@ import java.util.List;
@Component @Component
public class QueueServiceImpl implements QueueService { public class QueueServiceImpl implements QueueService {
// 队列名称 /**
* 队列名称
*/
@Autowired @Autowired
private QueueDao queueDao; private QueueDao queueDao;
@Autowired @Autowired
private BeanDao beanDao; private BeanDao beanDao;
// 是否已经初始化 /**
* 是否已经初始化
*/
private boolean init; private boolean init;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment