Commit d367dd7b authored by yanzg's avatar yanzg

消除成功接收处理

parent 4d5ca41b
......@@ -311,7 +311,7 @@ public class ObjectHelper {
}
String methodNameSource = method.getName();
String methodNameSimple = methodNameSource.toLowerCase();
if (methodNameSource.equals("getClass")) {
if ("getClass".equals(methodNameSource)) {
continue;
} else if (methodNameSimple.startsWith("set")) {
if (method.getParameterTypes().length != 1) {
......
......@@ -230,7 +230,7 @@ public class MemoryCache<T> {
* @throws Throwable
*/
@Override
protected void finalize() throws Throwable {
protected void finalize(){
this.close();
}
}
......@@ -2,7 +2,7 @@ package com.yanzuoguang.util.cache;
import com.yanzuoguang.util.extend.ConfigBase;
import com.yanzuoguang.util.thread.ThreadHelper;
import com.yanzuoguang.util.thread.ThreadList;
import com.yanzuoguang.util.thread.AbstractThreadList;
import java.util.List;
import java.util.Vector;
......@@ -32,7 +32,7 @@ public class MemoryCacheCenter {
do {
clear();
// 等待1秒
ThreadHelper.sleep(ConfigBase.MemoryClearTimeout);
ThreadHelper.sleep(ConfigBase.MEMORY_CLEAR_TIMEOUT);
} while (true);
}
});
......@@ -44,7 +44,7 @@ public class MemoryCacheCenter {
private static void clear() {
// todo: 需要修改
// 死循环处理
ThreadList<MemoryCache> threadList = new ThreadList<MemoryCache>(1) {
AbstractThreadList<MemoryCache> threadList = new AbstractThreadList<MemoryCache>(1) {
@Override
public void run(MemoryCache item) {
item.clearTimeout();
......
......@@ -10,12 +10,12 @@ public class ConfigBase {
/**
* 打印线程相关参数
*/
public static final boolean PrintThread = false;
public static final boolean PRINT_THREAD = false;
/**
* 内存缓存自动清除时间
*/
public static final int MemoryClearTimeout = 5 * 1000;
public static final int MEMORY_CLEAR_TIMEOUT = 5 * 1000;
/**
* 写入日志对象
......
......@@ -17,7 +17,6 @@ public class DateHelper {
private static final String FORMAT_DAY_STRING = "yyyy-MM-dd";
private static final String FORMAT_SECOND_STRING = "yyyy-MM-dd HH:mm:ss";
private static SimpleDateFormat FORMAT_DAY = new SimpleDateFormat(FORMAT_DAY_STRING);
/**
* 获取时间
......@@ -423,12 +422,12 @@ public class DateHelper {
public static String getWeekName1(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (week_index < 0) {
week_index = 0;
int weekIndex = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (weekIndex < 0) {
weekIndex = 0;
}
String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
return weeks[week_index];
return weeks[weekIndex];
}
/**
......@@ -574,7 +573,8 @@ public class DateHelper {
return from;
}
try {
return FORMAT_DAY.format(FORMAT_DAY.parse(from));
SimpleDateFormat format = new SimpleDateFormat(FORMAT_DAY_STRING);
return format.format(format.parse(from));
} catch (ParseException e) {
ExceptionHelper.handleException(DateHelper.class, e, from);
}
......@@ -588,7 +588,8 @@ public class DateHelper {
* @return 获取到的日期字符串
*/
public static String toDay(Date date) {
return FORMAT_DAY.format(date);
SimpleDateFormat format = new SimpleDateFormat(FORMAT_DAY_STRING);
return format.format(date);
}
/**
......@@ -598,7 +599,8 @@ public class DateHelper {
* @return 获取到的日期字符串
*/
public static String toDay(long date) {
return FORMAT_DAY.format(new Date(date));
SimpleDateFormat format = new SimpleDateFormat(FORMAT_DAY_STRING);
return format.format(new Date(date));
}
/**
......
......@@ -57,7 +57,7 @@ public class EnumHelper {
Method[] vMets = vType.getMethods();
for (Method vMet : vMets) {
String vName = vMet.getName();
if (vName.equals("forValue")
if ("forValue".equals(vName)
&& vMet.getParameterTypes().length == 1) {
Class vTempType = vMet.getParameterTypes()[0];
Object obj = vMet.invoke(null, i);
......
......@@ -9,8 +9,10 @@ import java.util.List;
* @param <T>
*/
public class Event<T> {
// 事件列表
private List<T> m_List = new ArrayList<>();
/**
* 事件列表
*/
private List<T> list = new ArrayList<>();
/**
* 添加处理对象
......@@ -19,7 +21,7 @@ public class Event<T> {
*/
public void add(T t) {
if (t != null) {
m_List.add(t);
list.add(t);
}
}
......@@ -31,8 +33,8 @@ public class Event<T> {
* @throws Exception
*/
public <M extends EventRun<T>> void exeucte(M m) throws Exception {
for (T item : m_List) {
m.Execute(item);
for (T item : list) {
m.run(item);
}
}
......@@ -44,7 +46,7 @@ public class Event<T> {
*/
public boolean remove(T t) {
if (t != null) {
return m_List.remove(t);
return list.remove(t);
}
return false;
}
......@@ -53,7 +55,7 @@ public class Event<T> {
* 清除所有事件
*/
public void clear() {
m_List.clear();
list.clear();
}
/**
......@@ -64,7 +66,7 @@ public class Event<T> {
*/
public boolean contants(T t) {
if (t != null) {
return m_List.contains(t);
return list.contains(t);
}
return false;
}
......@@ -75,7 +77,7 @@ public class Event<T> {
* @return 事件列表集合
*/
public List<T> getList() {
return m_List;
return list;
}
/**
......@@ -84,6 +86,6 @@ public class Event<T> {
* @return 长度
*/
public int size() {
return m_List.size();
return list.size();
}
}
......@@ -13,5 +13,5 @@ public interface EventRun<T> {
* @param t 接口
* @throws Exception 异常错误
*/
void Execute(T t) throws Exception;
void run(T t) throws Exception;
}
......@@ -258,7 +258,7 @@ public class StringHelper {
} else if (type.equals(vBase)) {
return true;
}
if (type.toString().equals("System.Object")) {
if ("System.Object".equals(type.toString())) {
return false;
} else {
return isType(type.getSuperclass(), vBase);
......@@ -467,10 +467,10 @@ public class StringHelper {
* @return 转换成功后的值
*/
public static double toDecimal(Object from) {
Double result = new Double(0);
Double result = Double.valueOf(0);
try {
if (!isEmpty(from)) {
result = new Double(from.toString());
result = Double.valueOf(from.toString());
}
} catch (Exception ex) {
ExceptionHelper.handleException(StringHelper.class, ex, from);
......@@ -768,7 +768,7 @@ public class StringHelper {
// 使用指定的字节数组更新摘要。
md.update(from.getBytes());
// 通过执行诸如填充之类的最终操作完成哈希计算。
byte b[] = md.digest();
byte[] b = md.digest();
// 生成具体的md5密码到buf数组
int i;
StringBuilder buf = new StringBuilder();
......@@ -882,7 +882,7 @@ public class StringHelper {
*/
public static String getCamelCase(String from) {
StringBuilder result = new StringBuilder();
String a[] = from.split("_");
String[] a = from.split("_");
for (String s : a) {
if (result.length() == 0) {
result.append(s.substring(0, 1).toLowerCase());
......
......@@ -62,7 +62,7 @@ public class UrlHelper {
return ips.get(0);
}
for (String ip : ips) {
if (ip.equals("127.0.0.1") || ip.equals("0.0.0.0")) {
if ("127.0.0.1".equals(ip) || "0.0.0.0".equals(ip)) {
continue;
}
return ip;
......@@ -84,7 +84,8 @@ public class UrlHelper {
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
if (inetAddress != null && inetAddress instanceof Inet4Address) { // IPV4
// IPV4
if (inetAddress != null && inetAddress instanceof Inet4Address) {
String ip = inetAddress.getHostAddress();
ipList.add(ip);
}
......
......@@ -5,6 +5,8 @@ import java.util.List;
/**
* 表格头
*
* @author 颜佐光
*/
public class TableHead {
......@@ -12,61 +14,61 @@ public class TableHead {
* 构造函数
*/
public TableHead() {
this.TotalColumn = 0;
this.TotalRow = 0;
this.DataColumn = 0;
this.Columns = new ArrayList<>();
this.totalColumn = 0;
this.totalRow = 0;
this.dataColumn = 0;
this.columns = new ArrayList<>();
}
/**
* 总行数
*/
private int TotalRow;
private int totalRow;
/**
* 总列数
*/
private int TotalColumn;
private int totalColumn;
/**
* 已添加数据列
*/
private int DataColumn;
private int dataColumn;
/**
* 列头数
*/
private List<TableHeadItem> Columns;
private List<TableHeadItem> columns;
public int getTotalRow() {
return TotalRow;
return totalRow;
}
public void setTotalRow(int totalRow) {
TotalRow = totalRow;
this.totalRow = totalRow;
}
public int getTotalColumn() {
return TotalColumn;
return totalColumn;
}
public void setTotalColumn(int totalColumn) {
TotalColumn = totalColumn;
this.totalColumn = totalColumn;
}
public int getDataColumn() {
return DataColumn;
return dataColumn;
}
public void setDataColumn(int dataColumn) {
DataColumn = dataColumn;
this.dataColumn = dataColumn;
}
public List<TableHeadItem> getColumns() {
return Columns;
return columns;
}
public void setColumns(List<TableHeadItem> columns) {
Columns = columns;
this.columns = columns;
}
}
......@@ -8,42 +8,42 @@ public class TableHeadItem {
/**
* 最高级别
*/
private String Name;
private String name;
/**
* 路径
*/
private String Path;
private String path;
/**
* 级别
*/
private int Level;
private int level;
/**
* 当前列的最大级别
*/
private int LevelMax;
private int levelMax;
/**
* 第几行
*/
private int Row;
private int row;
/**
* 合并多少行
*/
private int RowCell;
private int rowCell;
/**
* 第几列
*/
private int Column;
private int column;
/**
* 合并多少列
*/
private int ColumnCell;
private int columnCell;
/**
* 是否属于数据列
......@@ -51,67 +51,67 @@ public class TableHeadItem {
private boolean dataColumn;
public String getName() {
return Name;
return name;
}
public void setName(String name) {
Name = name;
this.name = name;
}
public String getPath() {
return Path;
return path;
}
public void setPath(String path) {
Path = path;
this.path = path;
}
public int getLevel() {
return Level;
return level;
}
public void setLevel(int level) {
Level = level;
this.level = level;
}
public int getLevelMax() {
return LevelMax;
return levelMax;
}
public void setLevelMax(int levelMax) {
LevelMax = levelMax;
this.levelMax = levelMax;
}
public int getRow() {
return Row;
return row;
}
public void setRow(int row) {
Row = row;
this.row = row;
}
public int getRowCell() {
return RowCell;
return rowCell;
}
public void setRowCell(int rowCell) {
RowCell = rowCell;
this.rowCell = rowCell;
}
public int getColumn() {
return Column;
return column;
}
public void setColumn(int column) {
Column = column;
this.column = column;
}
public int getColumnCell() {
return ColumnCell;
return columnCell;
}
public void setColumnCell(int columnCell) {
ColumnCell = columnCell;
this.columnCell = columnCell;
}
public boolean isDataColumn() {
......
......@@ -3,17 +3,14 @@ package com.yanzuoguang.util.thread;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.log.Log;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/**
* 多线程处理队列
*/
public abstract class ThreadList<T extends Object> implements ThreadWaitExecute {
public abstract class AbstractThreadList<T extends Object> implements ThreadWaitExecute {
private long threadID;
/**
* 线程等待间隔
......@@ -60,7 +57,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
*
* @param threadCount
*/
public ThreadList(int threadCount) {
public AbstractThreadList(int threadCount) {
this.threadID = Thread.currentThread().getId();
threadCount = Math.max(threadCount, 0);
this.threadCount = threadCount;
......@@ -118,17 +115,8 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
* @param list
*/
public void add(T... list) {
if (list == null || list.length == 0) {
return;
}
int size = list.length;
this.initRowTotal(size);
for (int i = 0; i < size; i++) {
T item = list[i];
if (item == null) {
continue;
}
this.add(item);
if (list != null) {
this.add(Arrays.asList(list));
}
}
......@@ -141,8 +129,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
if (list == null || list.size() == 0) {
return;
}
T[] to = (T[]) list.toArray();
this.add(to);
int size = list.size();
this.initRowTotal(size);
for (T item : list) {
if (item == null) {
continue;
}
this.add(item);
}
}
/**
......@@ -181,12 +175,12 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
public void run() {
long threadID = Thread.currentThread().getId();
try {
if (threadID != ThreadList.this.threadID) {
if (threadID != AbstractThreadList.this.threadID) {
Log.threadBegin();
}
threadExecute();
} finally {
if (threadID != ThreadList.this.threadID) {
if (threadID != AbstractThreadList.this.threadID) {
Log.threadCommit();
}
}
......@@ -295,7 +289,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
threadListNum.addSuccess();
} catch (RuntimeException ex) {
threadListNum.addError();
LogError(ex);
logError(ex);
}
}
......@@ -321,7 +315,7 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
* @param log
*/
private void log(String log) {
Log.info(ThreadList.class, log);
Log.info(AbstractThreadList.class, log);
}
/**
......@@ -329,14 +323,14 @@ public abstract class ThreadList<T extends Object> implements ThreadWaitExecute
*
* @param ex
*/
private void LogError(RuntimeException ex) {
private void logError(RuntimeException ex) {
this.exception = ex;
}
/**
* 抛出线程中的异常数据
*/
public ThreadList<T> throwThreadError() {
public AbstractThreadList<T> throwThreadError() {
if (this.exception != null) {
throw this.exception;
}
......
......@@ -12,10 +12,9 @@ public class RunExecute implements EventRun<Runnable> {
* 执行时间
*
* @param t 接口 需要执行的对象
* @throws Exception 跑出异常
*/
@Override
public void Execute(Runnable t) {
public void run(Runnable t) {
t.run();
}
}
......@@ -7,49 +7,49 @@ public class RunInterval {
/**
* 当前线程
*/
private Thread Thread;
private Thread thread;
/**
* 间隔时间,毫秒
*/
private int Time;
private int time;
/**
* 执行的代码
*/
private Runnable Code;
private Runnable code;
/**
* 是否终端
*/
private boolean Break;
private boolean breakFlag;
public java.lang.Thread getThread() {
return Thread;
return thread;
}
public void setThread(java.lang.Thread thread) {
Thread = thread;
this.thread = thread;
}
public int getTime() {
return Time;
return time;
}
public void setTime(int time) {
Time = time;
this.time = time;
}
public Runnable getCode() {
return Code;
return code;
}
public void setCode(Runnable code) {
Code = code;
this.code = code;
}
public boolean isBreak() {
return Break;
public boolean isBreakFlag() {
return breakFlag;
}
public void setBreak(boolean aBreak) {
Break = aBreak;
public void setBreakFlag(boolean breakFlag) {
this.breakFlag = breakFlag;
}
}
\ No newline at end of file
......@@ -12,17 +12,29 @@ import java.util.List;
* 自动执行任务
*/
public class RunPlan {
// 任务锁
private Object m_Lock = new Object();
// 任务队列
private List<RunPlanData> m_List = new ArrayList<>();
// 增加时触发的事件队列
/**
* 任务锁
*/
private Object lock = new Object();
/**
* 任务队列
*/
private List<RunPlanData> list = new ArrayList<>();
/**
* 增加时触发的事件队列
*/
private Event<Runnable> onAdd = new Event<>();
// 增加时触发的事件队列
/**
* 增加时触发的事件队列
*/
private Event<Runnable> onRemove = new Event<>();
// 单项成功执行时的事件队列
/**
* 单项成功执行时的事件队列
*/
private Event<Runnable> onItemExecuted = new Event<>();
// 全部执行完时触发的事件队列
/**
* 全部执行完时触发的事件队列
*/
private Event<Runnable> onExecuted = new Event<>();
/**
......@@ -67,12 +79,12 @@ public class RunPlan {
* @param isRemove 执行完成是否删除
* @param maxError 最大错误次数
*/
public final void Execute(boolean isRemove, int maxError) {
for (int i = m_List.size() - 1; i >= 0; i--) {
public final void run(boolean isRemove, int maxError) {
for (int i = list.size() - 1; i >= 0; i--) {
Date now = new Date();
RunPlanData item;
synchronized (this.m_Lock) {
item = m_List.size() > i ? m_List.get(i) : null;
synchronized (this.lock) {
item = list.size() > i ? list.get(i) : null;
}
if (item == null) {
......@@ -110,8 +122,8 @@ public class RunPlan {
try {
if (isRemove) {
synchronized (this.m_Lock) {
this.m_List.remove(i);
synchronized (this.lock) {
this.list.remove(i);
this.triggerEvent(this.onRemove);
}
}
......@@ -130,15 +142,15 @@ public class RunPlan {
* @param vTime 间隔时间
* @return 执行标志
*/
public final String Set(Runnable run, int vTime) {
public final String set(Runnable run, int vTime) {
// 创建临时任务数据
RunPlanData temp = new RunPlanData();
temp.setFlag(StringHelper.getNewID());
temp.setExecute(run);
temp.setTime(vTime);
synchronized (m_Lock) {
m_List.add(temp);
synchronized (lock) {
list.add(temp);
}
this.triggerEvent(this.onAdd);
......@@ -151,10 +163,10 @@ public class RunPlan {
* @param flag 执行标志
*/
public final void remove(String flag) {
synchronized (m_Lock) {
for (RunPlanData item : this.m_List) {
synchronized (lock) {
for (RunPlanData item : this.list) {
if (item.getFlag().equals(flag)) {
this.m_List.remove(item);
this.list.remove(item);
this.triggerEvent(this.onRemove);
break;
}
......@@ -168,10 +180,10 @@ public class RunPlan {
* @param run 执行的方法,注意有多个同样的方法时,只会清除第一个
*/
public final void remove(Runnable run) {
synchronized (m_Lock) {
for (RunPlanData item : this.m_List) {
synchronized (lock) {
for (RunPlanData item : this.list) {
if (item.getExecute().equals(run)) {
this.m_List.remove(item);
this.list.remove(item);
this.triggerEvent(this.onRemove);
break;
}
......@@ -200,6 +212,6 @@ public class RunPlan {
* @return 长度信息
*/
public final int getCount() {
return this.m_List.size();
return this.list.size();
}
}
......@@ -5,7 +5,7 @@ import com.yanzuoguang.util.exception.CodeException;
/**
* 根据指定的线程数量, 执行多个Runnable对象
*/
public class RunnableList extends ThreadList<Runnable> {
public class RunnableList extends AbstractThreadList<Runnable> {
/**
* 线程数量
*
......
......@@ -24,8 +24,8 @@ public final class RunnableListAuto {
*
* @param codes
*/
public static ThreadList<RunnableListAutoItem> Execute(Runnable... codes) {
return Execute(Arrays.asList(codes));
public static AbstractThreadList<RunnableListAutoItem> run(Runnable... codes) {
return run(Arrays.asList(codes));
}
/**
......@@ -33,12 +33,12 @@ public final class RunnableListAuto {
*
* @param codes
*/
public static ThreadList<RunnableListAutoItem> Execute(List<Runnable> codes) {
public static AbstractThreadList<RunnableListAutoItem> run(List<Runnable> codes) {
List<RunnableListAutoItem> autos = new ArrayList<RunnableListAutoItem>();
for (Runnable code : codes) {
autos.add(new RunnableListAutoItem(code));
}
return ExecuteAuto(autos);
return runAuto(autos);
}
/**
......@@ -46,8 +46,8 @@ public final class RunnableListAuto {
*
* @param methods
*/
public static ThreadList<RunnableListAutoItem> ExecuteAuto(RunnableListAutoItem... methods) {
return ExecuteAuto(Arrays.asList(methods));
public static AbstractThreadList<RunnableListAutoItem> runAuto(RunnableListAutoItem... methods) {
return runAuto(Arrays.asList(methods));
}
/**
......@@ -55,7 +55,7 @@ public final class RunnableListAuto {
*
* @param methods
*/
public static ThreadList<RunnableListAutoItem> ExecuteAuto(List<RunnableListAutoItem> methods) {
public static AbstractThreadList<RunnableListAutoItem> runAuto(List<RunnableListAutoItem> methods) {
// 获取历史执行时间
int zeroCount = 0;
long totalAvg = 0;
......@@ -119,18 +119,18 @@ public final class RunnableListAuto {
continue;
}
RunnableListAutoItem toItem = cache.get(item.getKey());
WriteLog("上次执行时间", toItem, finalThreadCount);
writeLog("上次执行时间", toItem, finalThreadCount);
}
}
// 开始线程列表
ThreadList<RunnableListAutoItem> threadList = new ThreadList<RunnableListAutoItem>(finalThreadCount) {
AbstractThreadList<RunnableListAutoItem> threadList = new AbstractThreadList<RunnableListAutoItem>(finalThreadCount) {
@Override
public void run(RunnableListAutoItem item) {
try {
item.execute();
if (IsLog) {
WriteLog("执行时间", item, finalThreadCount);
writeLog("执行时间", item, finalThreadCount);
}
} finally {
RunnableListAutoItem to = cache.get(item.getKey());
......@@ -147,7 +147,7 @@ public final class RunnableListAuto {
return threadList;
}
private static void WriteLog(String tag, RunnableListAutoItem item, int threadCount) {
private static void writeLog(String tag, RunnableListAutoItem item, int threadCount) {
if (!IsLog) {
return;
}
......
......@@ -40,26 +40,26 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
if (name == null) {
name = "";
}
this.ClassType = code.getClass();
this.Name = name;
this.classType = code.getClass();
this.name = name;
this.code = code;
this.Key = StringHelper.getMD5Id(this.ClassType.getName() + ":" + name);
this.key = StringHelper.getMD5Id(this.classType.getName() + ":" + name);
}
/**
* 关键字
*/
private volatile String Key;
private volatile String key;
/**
* 类型
*/
private volatile Class<?> ClassType;
private volatile Class<?> classType;
/**
* 名称
*/
private volatile String Name;
private volatile String name;
/**
* 执行代码
......@@ -69,21 +69,21 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
/**
* 总执行时间
*/
private volatile long Time;
private volatile long time;
/**
* 执行次数
*/
private volatile int Count;
private volatile int count;
/**
* 需要注意当达到 Time > Long.MaxValue / 2 或者 count > Integer.MaxValue /2 时
* 则Time = Time/2, count = count/2;
* 需要注意当达到 time > Long.MaxValue / 2 或者 count > Integer.MaxValue /2 时
* 则Time = time/2, count = count/2;
*/
private synchronized void init() {
if (this.Time > Long.MAX_VALUE / 2 || this.Count > Integer.MAX_VALUE / 2) {
this.Time = this.Time / 2;
this.Count = this.Count / 2;
if (this.time > Long.MAX_VALUE / 2 || this.count > Integer.MAX_VALUE / 2) {
this.time = this.time / 2;
this.count = this.count / 2;
}
}
......@@ -93,11 +93,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
* @param to
*/
public synchronized void add(RunnableListAutoItem to) {
if (this.ClassType != to.ClassType || !this.Name.equals(to.Name)) {
if (this.classType != to.classType || !this.name.equals(to.name)) {
return;
}
this.Time += to.Time;
this.Count += to.Count;
this.time += to.time;
this.count += to.count;
this.init();
}
......@@ -107,10 +107,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
* @return
*/
public synchronized long getAvgTime() {
if (this.Count == 0) {
if (this.count == 0) {
return 0;
}
return this.Time / this.Count;
return this.time / this.count;
}
/**
......@@ -120,11 +120,11 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
*/
public synchronized RunnableListAutoItem newBase() {
RunnableListAutoItem to = new RunnableListAutoItem();
to.Key = this.Key;
to.ClassType = this.ClassType;
to.Name = this.Name;
to.Count = this.Count;
to.Time = this.Time;
to.key = this.key;
to.classType = this.classType;
to.name = this.name;
to.count = this.count;
to.time = this.time;
return to;
}
......@@ -139,10 +139,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
this.code.run();
} catch (Exception ex) {
this.HandleException(ex);
this.handleException(ex);
} finally {
this.Count++;
this.Time += System.currentTimeMillis() - start.getTime();
this.count++;
this.time += System.currentTimeMillis() - start.getTime();
}
}
......@@ -151,7 +151,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
*
* @param ex
*/
private void HandleException(Throwable ex) {
private void handleException(Throwable ex) {
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
......@@ -165,15 +165,15 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
public String getKey() {
return Key;
return key;
}
public Class<?> getClassType() {
return ClassType;
return classType;
}
public String getName() {
return Name;
return name;
}
public Runnable getCode() {
......@@ -181,10 +181,10 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
}
public long getTime() {
return Time;
return time;
}
public int getCount() {
return Count;
return count;
}
}
......@@ -17,7 +17,7 @@ public class ThreadHelper {
private static RunPlan timeout;
private static RunPlan interval;
// 线程对象
private static ExecutorService _ExecuteService = Executors.newCachedThreadPool();
private static ExecutorService executeService = Executors.newCachedThreadPool();
/**
* 初始化线程对象,需要调用该函数之后才能使用
......@@ -32,27 +32,27 @@ public class ThreadHelper {
Runnable addExecute = new Runnable() {
@Override
public void run() {
OnExecuteAdd();
onExecuteAdd();
}
};
Runnable itemExecuted = new Runnable() {
@Override
public void run() {
OnItemExecuted();
onItemExecuted();
}
};
timeout.getOnAdd().add(addExecute);
timeout.getOnItemExecuted().add(itemExecuted);
interval.getOnAdd().add(addExecute);
interval.getOnItemExecuted().add(itemExecuted);
StartMonitor();
startMonitor();
}
private static void OnItemExecuted() {
private static void onItemExecuted() {
threadDate = new Date();
}
private static void OnExecuteAdd() {
private static void onExecuteAdd() {
startThread();
}
......@@ -67,12 +67,12 @@ public class ThreadHelper {
threadIsRun = true;
while (threadIsRun) {
try {
timeout.Execute(true, -1);
timeout.run(true, -1);
} catch (Exception ex) {
ExceptionHelper.handleException(ThreadHelper.class, ex);
}
try {
interval.Execute(false, -1);
interval.run(false, -1);
} catch (Exception ex) {
ExceptionHelper.handleException(ThreadHelper.class, ex);
}
......@@ -90,7 +90,7 @@ public class ThreadHelper {
/**
* 监控线程的方法,防止线程执行死机
*/
private static void StartMonitor() {
private static void startMonitor() {
runThread(new Runnable() {
@Override
public void run() {
......@@ -120,7 +120,7 @@ public class ThreadHelper {
* @return 执行标志
*/
public static String setTimeout(Runnable run, int vTime) {
return timeout.Set(run, vTime);
return timeout.set(run, vTime);
}
/**
......@@ -149,7 +149,7 @@ public class ThreadHelper {
* @return 执行标志
*/
public static String setInterval(Runnable run, int vTime) {
return interval.Set(run, vTime);
return interval.set(run, vTime);
}
/**
......@@ -202,7 +202,7 @@ public class ThreadHelper {
* @param run
*/
public static void runThread(final Runnable run) {
_ExecuteService.execute(new Runnable() {
executeService.execute(new Runnable() {
@Override
public void run() {
executeCatch(run);
......@@ -219,7 +219,7 @@ public class ThreadHelper {
runThread(new Runnable() {
@Override
public void run() {
while (!run.isBreak()) {
while (!run.isBreakFlag()) {
try {
run.getCode().run();
} catch (Exception ex) {
......
......@@ -57,7 +57,7 @@ public class ThreadWait {
}
this.stopPrint();
}
if (ConfigBase.PrintThread) {
if (ConfigBase.PRINT_THREAD) {
Log.info(ThreadWait.class, "客户端结束时间");
}
}
......@@ -78,7 +78,7 @@ public class ThreadWait {
public synchronized void finish() {
if (this.execute.isFinally()) {
this.notify();
if (ConfigBase.PrintThread) {
if (ConfigBase.PRINT_THREAD) {
Log.info(ThreadWait.class, "客户端结束时间");
}
}
......
......@@ -41,7 +41,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>();
// 缓存的每次请求的结果
protected MemoryCache<RequestCacheResult> _cacheResult = new MemoryCache<>(cacheTime);
protected MemoryCache<RequestCacheResult> cacheResult = new MemoryCache<>(cacheTime);
public BaseRequestAspect() {
ThreadNext.start(this, "save log error");
......
......@@ -116,7 +116,7 @@ public class WebAspect extends BaseRequestAspect {
reqId = StringHelper.getId(ObjectHelper.getString(firstArgs, "companyId"), reqId);
}
String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl());
RequestCacheResult req = _cacheResult.get(reqFull, new RequestCacheResult(reqFull));
RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull));
// 缓存的键值对
if (req.getResult() == null) {
synchronized (req) {
......
......@@ -4,48 +4,59 @@ package com.yanzuoguang.dao;
* created by yanzu on 2017/5/30.
*/
public class DaoConst {
public static final int OperatorTypeCreate = 0;
public static final int OperatorTypeUpdate = 1;
public static final int OperatorTypeRemove = 2;
public static final int OperatorTypeLoad = 3;
/**
* 创建操作
*/
public static final int OPERATOR_TYPE_CREATE = 0;
/**
* 更新操作
*/
public static final int OPERATOR_TYPE_UPDATE = 1;
/**
* 删除操作
*/
public static final int OPERATOR_TYPE_REMOVE = 2;
/**
* 加载操作
*/
public static final int OPERATOR_TYPE_LOAD = 3;
/**
* 创建
*/
public static final String Create = "create";
public static final String CREATE = "create";
/**
* 修改
*/
public static final String Update = "update";
public static final String UPDATE = "update";
/**
* 删除
*/
public static final String Remove = "remove";
public static final String REMOVE = "remove";
/**
* 加载
*/
public static final String Load = "load";
public static final String LOAD = "load";
/**
* 查询
*/
public static final String Query = "query";
public static final String QUERY = "query";
/**
* GROUP增加数据的SQL语句
*/
public static final String GroupAdd = "GroupAdd";
public static final String GROUP_ADD = "GroupAdd";
/**
* GROUP查询数据的SQL语句
*/
public static final String GroupQuery = "GroupQuery";
public static final String GROUP_QUERY = "GroupQuery";
/**
* 驼峰式命名
*/
public static final int RowNameTypeCamelCase = 0;
public static final int ROW_NAME_TYPE_CAMEL_CASE = 0;
/**
* 原字段
*/
public static final int RowNameTypeNoChange = 1;
public static final int ROW_NAME_TYPE_NO_CHANGE = 1;
}
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.db.Impl.AllBeanRowMapper;
import com.yanzuoguang.db.impl.AllBeanRowMapper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.DateHelper;
......@@ -36,10 +36,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @return 获取主键名称
*/
protected String getKey() {
if (this.Table == null) {
if (this.table == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现表结构");
}
return this.Table.Table.getKeyName();
return this.table.table.getKeyName();
}
/**
......@@ -103,7 +103,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
@Override
public String create(Object model) {
// 判断主键是字符串和需要生成主键
boolean isKeyString = this.Table.Table.getKeyType() == String.class;
boolean isKeyString = this.table.table.getKeyType() == String.class;
String keyString = this.getKeyString(model);
// 生成主键
......@@ -113,10 +113,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
// 检测数据合法性
this.check(DaoConst.OperatorTypeCreate, keyString, model);
this.check(DaoConst.OPERATOR_TYPE_CREATE, keyString, model);
// 执行创建的SQL语句
int ret = updateSql(DaoConst.Create, model);
int ret = updateSql(DaoConst.CREATE, model);
// 判断是否需要获取自增编号(主键为整形)
if (StringHelper.isEmpty(keyString) && !isKeyString) {
keyString = this.getIdentity();
......@@ -142,10 +142,10 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
public String update(Object model) {
String keyString = this.getKeyString(model);
if (StringHelper.isEmpty(keyString)) {
throw new CodeException("表" + this.Table.Table.getName() + "主键值为空时不能更新");
throw new CodeException("表" + this.table.table.getName() + "主键值为空时不能更新");
}
this.check(DaoConst.OperatorTypeUpdate, keyString, model);
SqlData sqlData = this.getSql(DaoConst.Update);
this.check(DaoConst.OPERATOR_TYPE_UPDATE, keyString, model);
SqlData sqlData = this.getSql(DaoConst.UPDATE);
int ret = updateSql(sqlData, model);
String retVal = ret > 0 ? keyString : "";
return retVal;
......@@ -198,21 +198,21 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
from = new HashMap<String, Object>();
this.setKeyString(from, keyString);
// 调用删除日志
this.check(DaoConst.OperatorTypeRemove, keyString, from);
this.check(DaoConst.OPERATOR_TYPE_REMOVE, keyString, from);
} else {
List<MapRow> rows = this.query(MapRow.class, DaoConst.Load, from);
List<MapRow> rows = this.query(MapRow.class, DaoConst.LOAD, from);
for (MapRow row : rows) {
keyString = this.getKeyString(from);
if (StringHelper.isEmpty(keyString)) {
keyString = StringHelper.toString(AllBeanRowMapper.getLoweRowField(row, this.getKey()));
}
// 调用删除日志
this.check(DaoConst.OperatorTypeRemove, keyString, row);
this.check(DaoConst.OPERATOR_TYPE_REMOVE, keyString, row);
}
}
// 调用删除语句
SqlData sqlData = this.getSql(DaoConst.Remove);
SqlData sqlData = this.getSql(DaoConst.REMOVE);
return updateSql(sqlData, from);
}
......@@ -237,7 +237,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
// 通过传入数据进行加载
T to = this.queryFirst(cls, DaoConst.Load, from);
T to = this.queryFirst(cls, DaoConst.LOAD, from);
if (to == null) {
return to;
}
......@@ -247,7 +247,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
key = this.getKeyString(to);
}
check(DaoConst.OperatorTypeLoad, key, to);
check(DaoConst.OPERATOR_TYPE_LOAD, key, to);
return to;
}
......@@ -267,22 +267,22 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
// 获取前台分组的MD5标识
String md5 = this.getMd5(DaoConst.GroupQuery, model);
if (!StringHelper.isEmpty(this.Table.Table.getMD5KeyName())) {
ObjectHelper.set(model, this.Table.Table.getMD5KeyName(), md5);
String md5 = this.getMd5(DaoConst.GROUP_QUERY, model);
if (!StringHelper.isEmpty(this.table.table.getMD5KeyName())) {
ObjectHelper.set(model, this.table.table.getMD5KeyName(), md5);
}
// 获取标识的实体
T from;
if (this.Table.Table.getKeyType() == String.class) {
if (this.table.table.getKeyType() == String.class) {
from = model;
this.setKeyString(model, md5);
} else if (!StringHelper.isEmpty(this.Table.Table.getMD5KeyName())) {
} else if (!StringHelper.isEmpty(this.table.table.getMD5KeyName())) {
Map<String, Object> map = new HashMap<String, Object>();
map.put(this.Table.Table.getMD5KeyName(), md5);
map.put(this.table.table.getMD5KeyName(), md5);
from = this.load(map, cls);
} else {
from = this.queryFirst(cls, DaoConst.GroupQuery, model);
from = this.queryFirst(cls, DaoConst.GROUP_QUERY, model);
}
// 当没有存在,则创建,否则 UpdateAdd
......@@ -295,7 +295,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
ObjectHelper.set(model, keyField, key);
// 执行更新SQL语句
SqlData sqlData = this.getSql(DaoConst.GroupAdd);
SqlData sqlData = this.getSql(DaoConst.GROUP_ADD);
int ret = this.updateSql(sqlData, model);
if (ret < 1) {
return this.create(model);
......
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import com.yanzuoguang.dao.TableAnnotation;
import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.db.Impl.DbRow;
import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
......@@ -36,7 +36,7 @@ public abstract class BaseDaoSql {
/**
* 当前Dao的表结构SQL语句信息
*/
protected TableSqlCache Table = null;
protected TableSqlCache table = null;
/**
* 缓存的表结构和SQL语句
......@@ -65,11 +65,11 @@ public abstract class BaseDaoSql {
private void initTable() {
String cls = this.getClass().getName();
// 外检测,防止锁影响性能
this.Table = Cache.get(cls);
this.table = Cache.get(cls);
// 判断是否已经取到对象
if (this.Table == null) {
this.Table = new TableSqlCache();
Cache.put(cls, this.Table);
if (this.table == null) {
this.table = new TableSqlCache();
Cache.put(cls, this.table);
this.init();
}
}
......@@ -104,8 +104,8 @@ public abstract class BaseDaoSql {
// 生成表结构
TableStruct table = new TableStruct(tableName, clsModel);
// 根据表结构生成基本的SQL语句
table.init(this.Table);
return this.Table;
table.init(this.table);
return this.table;
}
/**
......@@ -125,10 +125,10 @@ public abstract class BaseDaoSql {
* @return 对应名称的SQL语句
*/
protected SqlData getSql(String name, boolean isThrow) {
if (this.Table == null) {
if (this.table == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现表结构");
}
SqlData sql = this.Table.Sqls.get(name);
SqlData sql = this.table.Sqls.get(name);
if (isThrow && sql == null) {
throw new CodeException("类" + this.getClass().getName() + "未发现SQL语句" + name);
}
......@@ -155,7 +155,7 @@ public abstract class BaseDaoSql {
protected int updateSql(SqlData sqlData, Object model) {
List<Object> paras = new ArrayList<Object>();
String sql = this.getQueryPara(paras, sqlData, model);
int ret = db.update(this.getClass(), sqlData.Name, sql, paras.toArray());
int ret = db.update(this.getClass(), sqlData.name, sql, paras.toArray());
this.onUpdateSql(model);
return ret;
}
......@@ -183,7 +183,7 @@ public abstract class BaseDaoSql {
protected Object queryCell(SqlData sqlData, Object model) {
List<Object> paras = new ArrayList<Object>();
String sql = this.getQueryPara(paras, sqlData, model);
Object cell = this.queryCellWithCache(sql, sqlData.Name, paras.toArray());
Object cell = this.queryCellWithCache(sql, sqlData.name, paras.toArray());
return cell;
}
......@@ -211,7 +211,7 @@ public abstract class BaseDaoSql {
protected <T extends Object> List<T> queryData(Class<T> cls, SqlData sqlData, Object model) {
List<Object> paras = new ArrayList<Object>();
String sql = this.getQueryPara(paras, sqlData, model);
List<T> list = this.queryWithCache(cls, sqlData.Name, sql, paras.toArray());
List<T> list = this.queryWithCache(cls, sqlData.name, sql, paras.toArray());
return list;
}
......@@ -227,7 +227,7 @@ public abstract class BaseDaoSql {
List<Object> paras = new ArrayList<Object>();
String sql = this.getQueryPara(paras, sqlData, model);
// 查询数据
db.query(this.getClass(), cls, handle, sqlData.Name, sql, paras);
db.query(this.getClass(), cls, handle, sqlData.name, sql, paras);
}
/**
......@@ -290,7 +290,7 @@ public abstract class BaseDaoSql {
SqlData from = this.getSql(sqlName);
// 对SQL语句进行分页处理
SqlData to = from.copy();
to.Sql = from.Sql;
to.sql = from.sql;
to.addCode("{LIMIT}", " LIMIT " + pageSize.getPageStart() + "," + pageSize.getPageSize());
return queryData(cls, to, model);
}
......@@ -417,7 +417,7 @@ public abstract class BaseDaoSql {
String[] lastCode = new String[]{"{WHERE}", "{GROUP}", "{HAVING}", "{ORDER}", "{LIMIT}"};
// 将SQL语句进行代码片段追加
String sql = sqlData.Sql;
String sql = sqlData.sql;
for (String code : lastCode) {
if (sql.indexOf(code) == -1) {
sql += code;
......@@ -449,7 +449,7 @@ public abstract class BaseDaoSql {
// 判断代码片段是否合法
if (field.codes.size() % 2 == 1) {
throw new CodeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.Name + ":" + field.paraName + "为单数");
throw new CodeException("代码片段" + this.getClass().getSimpleName() + ":" + sqlData.name + ":" + field.paraName + "为单数");
}
// 处理代码片段
for (int i = 0; i < field.codes.size(); i = i + 2) {
......@@ -475,16 +475,16 @@ public abstract class BaseDaoSql {
}
}
// 通过正则表达式处理参数 @Name 并替换SQL语句成 ?
// 通过正则表达式处理参数 @name 并替换SQL语句成 ?
{
String regex = "@([a-zA-Z0-9_]+)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(sql);
// 寻找到的代码片段 不包含分括号
while (m.find()) {
// SQL参数名称 @Name\s
// SQL参数名称 @name\s
String name = m.group();
// 对应的前台输入字段 Name
// 对应的前台输入字段 name
String field = m.group(1);
// 根据输入字段从参数中取值
Object val = ObjectHelper.get(model, field);
......@@ -593,19 +593,19 @@ public abstract class BaseDaoSql {
sb.append(",");
}
switch (from.getGroupType()) {
case CaseSqlModel.GroupTypeSUM:
case CaseSqlModel.GROUP_TYPE_SUM:
sb.append("SUM");
break;
case CaseSqlModel.GroupTypeCOUNT:
case CaseSqlModel.GROUP_TYPE_COUNT:
sb.append("COUNT");
break;
case CaseSqlModel.GroupTypeMAX:
case CaseSqlModel.GROUP_TYPE_MAX:
sb.append("MAX");
break;
case CaseSqlModel.GroupTypeMIN:
case CaseSqlModel.GROUP_TYPE_MIN:
sb.append("MIN");
break;
case CaseSqlModel.GroupTypeAVG:
case CaseSqlModel.GROUP_TYPE_AVG:
sb.append("AVG");
break;
default:
......
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
/**
* 行转列实体
*
* @author 颜佐光
*/
public class CaseSqlModel {
public final static int GroupTypeSUM = 0;
public final static int GroupTypeCOUNT = 1;
public final static int GroupTypeAVG = 2;
public final static int GroupTypeMIN = 3;
public final static int GroupTypeMAX = 4;
public final static int GROUP_TYPE_SUM = 0;
public final static int GROUP_TYPE_COUNT = 1;
public final static int GROUP_TYPE_AVG = 2;
public final static int GROUP_TYPE_MIN = 3;
public final static int GROUP_TYPE_MAX = 4;
public CaseSqlModel(String caseField, String caseValue, String valueField, String toName) {
this(GroupTypeSUM, caseField, caseValue, valueField, toName);
this(GROUP_TYPE_SUM, caseField, caseValue, valueField, toName);
}
public CaseSqlModel(int groupType, String caseField, String caseValue, String valueField, String toName) {
this.GroupType = groupType;
this.CaseField = caseField;
this.CaseValue = caseValue;
this.ValueField = valueField;
this.ToName = toName;
this.AndWhere = "";
this.groupType = groupType;
this.caseField = caseField;
this.caseValue = caseValue;
this.valueField = valueField;
this.toName = toName;
this.andWhere = "";
}
public CaseSqlModel(String caseField, String caseValue, Object value, String toName, String andWhere) {
this(GroupTypeSUM, caseField, caseValue, value, toName, andWhere);
this(GROUP_TYPE_SUM, caseField, caseValue, value, toName, andWhere);
}
public CaseSqlModel(int groupType, String caseField, String caseValue, Object value, String toName, String andWhere) {
this.GroupType = groupType;
this.CaseField = caseField;
this.CaseValue = caseValue;
this.Value = value;
this.ToName = toName;
this.AndWhere = andWhere;
this.groupType = groupType;
this.caseField = caseField;
this.caseValue = caseValue;
this.value = value;
this.toName = toName;
this.andWhere = andWhere;
}
public CaseSqlModel(String caseField, String caseValue, String valueField, String toName, String andWhere) {
this(GroupTypeSUM, caseField, caseValue, valueField, toName, andWhere);
this(GROUP_TYPE_SUM, caseField, caseValue, valueField, toName, andWhere);
}
public CaseSqlModel(int groupType, String caseField, String caseValue, String valueField, String toName, String andWhere) {
this.GroupType = groupType;
this.CaseField = caseField;
this.CaseValue = caseValue;
this.ValueField = valueField;
this.ToName = toName;
this.AndWhere = andWhere;
this.groupType = groupType;
this.caseField = caseField;
this.caseValue = caseValue;
this.valueField = valueField;
this.toName = toName;
this.andWhere = andWhere;
}
/**
* 统计纬度
*/
private int GroupType;
private int groupType;
/**
* 需要判断的字段
*/
private String CaseField;
private String caseField;
/**
* 需要判断的值
*/
private String CaseValue;
private String caseValue;
/**
* 需要统计的字段,和 Value 只能存在一个,ValueField优先级更高
* 需要统计的字段,和 value 只能存在一个,ValueField优先级更高
*/
private String ValueField;
private String valueField;
/**
* 需要统计的值,和 ValueField只能存在一个,ValueField优先级更高
*/
private Object Value;
private Object value;
/**
* 目标字段名称
*/
private String ToName;
private String toName;
/**
* 需要判断的CASE字段的附加条件
*/
private String AndWhere;
private String andWhere;
public int getGroupType() {
return GroupType;
return groupType;
}
public void setGroupType(int groupType) {
GroupType = groupType;
this.groupType = groupType;
}
public String getCaseField() {
return CaseField;
return caseField;
}
public void setCaseField(String caseField) {
CaseField = caseField;
this.caseField = caseField;
}
public String getCaseValue() {
return CaseValue;
return caseValue;
}
public void setCaseValue(String caseValue) {
CaseValue = caseValue;
this.caseValue = caseValue;
}
public String getValueField() {
return ValueField;
return valueField;
}
public void setValueField(String valueField) {
ValueField = valueField;
this.valueField = valueField;
}
public Object getValue() {
return Value;
return value;
}
public void setValue(Object value) {
Value = value;
this.value = value;
}
public String getToName() {
return ToName;
return toName;
}
public void setToName(String toName) {
ToName = toName;
this.toName = toName;
}
public String getAndWhere() {
return AndWhere;
return andWhere;
}
public void setAndWhere(String andWhere) {
AndWhere = andWhere;
this.andWhere = andWhere;
}
}
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import java.util.ArrayList;
import java.util.List;
......@@ -12,17 +12,17 @@ public class SqlData {
/**
* 对应的参数顺序
*/
public List<SqlDataField> sqlDataFields = new ArrayList<SqlDataField>();
private List<SqlDataField> sqlDataFields = new ArrayList<SqlDataField>();
/**
* SQL语句的名称
*/
public String Name;
private String name;
/**
* SQL语句
*/
public String Sql;
private String sql;
/**
* 构造函数
......@@ -31,6 +31,26 @@ public class SqlData {
this("", "");
}
public List<SqlDataField> getSqlDataFields() {
return sqlDataFields;
}
public void setSqlDataFields(List<SqlDataField> sqlDataFields) {
this.sqlDataFields = sqlDataFields;
}
public String getName() {
return name;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
/**
* SQL语句的基本信息
*
......@@ -39,8 +59,8 @@ public class SqlData {
* @param paras SQL语句参数名称数组
*/
public SqlData(String name, String sql, String... paras) {
this.Name = name;
this.Sql = sql;
this.name = name;
this.sql = sql;
for (String input : paras) {
this.add(input);
}
......@@ -220,7 +240,7 @@ public class SqlData {
* @return 复制的结果
*/
public SqlData copy() {
SqlData to = new SqlData(this.Name, this.Sql);
SqlData to = new SqlData(this.name, this.sql);
for (SqlDataField sqlDataField : this.sqlDataFields) {
to.sqlDataFields.add(sqlDataField.copy());
}
......@@ -234,7 +254,7 @@ public class SqlData {
* @return
*/
public SqlData setName(String name) {
this.Name = name;
this.name = name;
return this;
}
}
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import java.util.ArrayList;
import java.util.List;
......
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yanzu on 2017/6/6.
*
* @author 颜佐光
*/
public class TableFieldString {
/**
* 其他字段
*/
public List<String> Fields = new ArrayList<String>();
private List<String> fields = new ArrayList<>();
/**
* 构造函数
......@@ -20,7 +22,7 @@ public class TableFieldString {
*/
public TableFieldString(String... fields) {
for (String field : fields) {
this.Fields.add(field);
this.fields.add(field);
}
}
......@@ -31,7 +33,15 @@ public class TableFieldString {
*/
public TableFieldString(List<String> fields) {
for (String field : fields) {
this.Fields.add(field);
this.fields.add(field);
}
}
public List<String> getFields() {
return fields;
}
public void setFields(List<String> fields) {
this.fields = fields;
}
}
package com.yanzuoguang.dao.Impl;
package com.yanzuoguang.dao.impl;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
......@@ -25,18 +25,18 @@ public class TableSqlCache {
/**
* 表信息
*/
public TableStruct Table;
private TableStruct table;
/**
* 缓存的SQL信息
*/
public MemoryCache<SqlData> Sqls = new MemoryCache<SqlData>();
private MemoryCache<SqlData> sqls = new MemoryCache<SqlData>();
/**
* 构造函数
*/
public TableSqlCache() {
this.Table = new TableStruct();
this.table = new TableStruct();
}
/**
......@@ -57,7 +57,7 @@ public class TableSqlCache {
*/
public SqlData add(SqlData sql) {
if (sql != null) {
this.Sqls.put(sql.Name, sql);
this.sqls.put(sql.getName(), sql);
}
return sql;
}
......@@ -83,8 +83,8 @@ public class TableSqlCache {
*/
public SqlData addPageSize(SqlData from, String sql) {
SqlData to = from.copy();
to.Sql = sql;
to.Name += TableSqlCache.PAGE_SIZE_TAG;
to.sql = sql;
to.name += TableSqlCache.PAGE_SIZE_TAG;
return this.add(to);
}
......@@ -95,7 +95,7 @@ public class TableSqlCache {
* @param addField
*/
public void addGroup(TableFieldString tableWhereField, TableFieldString addField) {
this.Table.addGroupSql(this, tableWhereField, addField);
this.table.addGroupSql(this, tableWhereField, addField);
}
......@@ -106,7 +106,7 @@ public class TableSqlCache {
* @param whereFields
*/
public void addSaveWith(String sqlName, TableFieldString whereFields) {
this.Table.addSaveWithSql(this, sqlName, whereFields);
this.table.addSaveWithSql(this, sqlName, whereFields);
}
/**
......@@ -146,48 +146,48 @@ public class TableSqlCache {
}
// 2. 判断所有纬度字段是否已经存在
for (String item : tableWhereField.Fields) {
for (String item : tableWhereField.fields) {
String name = item.toLowerCase();
if (!sqlFieldHas.containsKey(name)) {
throw new CodeException("SQL语句" + item + "不存在纬度" + item);
}
sqlFieldWhere.put(name, true);
}
for (String item : addField.Fields) {
for (String item : addField.fields) {
String name = item.toLowerCase();
sqlFieldAdd.put(name, true);
}
// 3. 生成SQL语句
String selectModel = "SELECT {FromField} FROM ( {SQL} )t";
String initModel = "INSERT INTO {Table}( {CreateField} ) " +
String initModel = "INSERT INTO {table}( {CreateField} ) " +
"SELECT {FromInitField} FROM( {SelectSQL} )a " +
"LEFT JOIN {Table} AS b ON a.{Key} = b.{Key} WHERE b.{Key} IS NULL";
String addModel = "UPDATE {Table} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} ";
"LEFT JOIN {table} AS b ON a.{Key} = b.{Key} WHERE b.{Key} IS NULL";
String addModel = "UPDATE {table} AS a INNER JOIN ( {SelectSQL} ) AS b ON a.{Key} = b.{Key} SET {addConst} ";
// 定义需要处理的SQL对象
Map<String, StringBuilder> map = new HashMap<String, StringBuilder>();
addString(map, "{SQL}", sql);
addString(map, "{Table}", this.Table.getName());
addString(map, "{table}", this.table.getName());
if (this.Table.getKeyType() == String.class) {
addString(map, "{Key}", this.Table.getKeyName());
} else if (!StringHelper.isEmpty(this.Table.getMD5KeyName())) {
addString(map, "{Key}", this.Table.getMD5KeyName());
if (this.table.getKeyType() == String.class) {
addString(map, "{Key}", this.table.getKeyName());
} else if (!StringHelper.isEmpty(this.table.getMD5KeyName())) {
addString(map, "{Key}", this.table.getMD5KeyName());
} else {
throw new CodeException("表中未包含MD5字段");
}
String lowerKey = this.Table.getKeyName().toLowerCase();
String lowerMD5Key = this.Table.getMD5KeyName().toLowerCase();
String lowerKey = this.table.getKeyName().toLowerCase();
String lowerMD5Key = this.table.getMD5KeyName().toLowerCase();
List<TableFieldVo> allField = new ArrayList<TableFieldVo>();
allField.add(this.Table.getKey());
allField.addAll(this.Table.getFields());
allField.add(this.table.getKey());
allField.addAll(this.table.getFields());
for (TableFieldVo fieldVo : allField) {
String fieldName = fieldVo.name;
String fieldLName = fieldVo.lName;
if (fieldLName.equals(lowerKey) && this.Table.getKeyType() != String.class) {
if (fieldLName.equals(lowerKey) && this.table.getKeyType() != String.class) {
continue;
}
......@@ -202,7 +202,7 @@ public class TableSqlCache {
// 处理需要MD5的字段
addString(map, "{FromField}", "MD5(CONCAT(");
int i = 0;
for (String whereField : tableWhereField.Fields) {
for (String whereField : tableWhereField.fields) {
if (i > 0) {
addString(map, "{FromField}", ",':',");
}
......@@ -231,7 +231,7 @@ public class TableSqlCache {
addString(map, "{FromInitField}", "0 AS " + fieldName);
} else {
addString(map, "{FromInitField}", "a." + fieldName);
System.err.println("纬度" + this.Table.getName() + "->" + sqlName + "->" + fieldName + "存在,但是没有统计");
System.err.println("纬度" + this.table.getName() + "->" + sqlName + "->" + fieldName + "存在,但是没有统计");
}
}
}
......@@ -239,8 +239,8 @@ public class TableSqlCache {
// 最终SQL语句处理
selectModel = replaceString(map, selectModel);
addString(map, "{SelectSQL}", selectModel);
sqlInit.Sql = replaceString(map, initModel);
sqlAdd.Sql = replaceString(map, addModel);
sqlInit.sql = replaceString(map, initModel);
sqlAdd.sql = replaceString(map, addModel);
this.add(sqlInit);
this.add(sqlAdd);
......@@ -258,7 +258,7 @@ public class TableSqlCache {
* @param fields 字段
*/
public void addExist(String sqlName, String... fields) {
this.Table.addExist(this, sqlName, fields);
this.table.addExist(this, sqlName, fields);
}
private void addString(Map<String, StringBuilder> map, String name, String value) {
......@@ -282,4 +282,20 @@ public class TableSqlCache {
}
return sql;
}
public TableStruct getTable() {
return table;
}
public void setTable(TableStruct table) {
this.table = table;
}
public MemoryCache<SqlData> getSqls() {
return sqls;
}
public void setSqls(MemoryCache<SqlData> sqls) {
this.sqls = sqls;
}
}
package com.yanzuoguang.db;
import com.yanzuoguang.db.Impl.DbRow;
import com.yanzuoguang.db.impl.DbRow;
import com.yanzuoguang.util.vo.MapRow;
import java.util.List;
......
package com.yanzuoguang.db.Impl;
package com.yanzuoguang.db.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.extend.ConfigDb;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.MapRow;
......@@ -20,7 +19,6 @@ import java.lang.reflect.Modifier;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -251,9 +249,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/
private String getCamelCase(String column) {
switch (configDb.getRowNameType()) {
case DaoConst.RowNameTypeNoChange:
case DaoConst.ROW_NAME_TYPE_NO_CHANGE:
break;
case DaoConst.RowNameTypeCamelCase:
case DaoConst.ROW_NAME_TYPE_CAMEL_CASE:
default:
column = StringHelper.getCamelCase(column);
break;
......
package com.yanzuoguang.db.Impl;
package com.yanzuoguang.db.impl;
import com.yanzuoguang.db.DbExecute;
import com.yanzuoguang.extend.ConfigDb;
......@@ -14,7 +14,6 @@ import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
......
package com.yanzuoguang.db.Impl;
package com.yanzuoguang.db.impl;
import com.yanzuoguang.extend.ConfigDb;
import com.yanzuoguang.util.helper.StringHelper;
......
package com.yanzuoguang.service.Impl;
package com.yanzuoguang.service.impl;
import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.service.BaseService;
......
package com.yanzuoguang.mq.dao.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.Impl.BaseDaoImpl;
import com.yanzuoguang.dao.Impl.SqlData;
import com.yanzuoguang.dao.impl.BaseDaoImpl;
import com.yanzuoguang.dao.impl.SqlData;
import com.yanzuoguang.mq.dao.MessageDao;
import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.util.vo.MapRow;
......@@ -20,11 +20,11 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
protected void init() {
register(MessageVo.class);
Table.add(DaoConst.Query, "SELECT a.* FROM Queue_Message AS a WHERE 1=1 ")
table.add(DaoConst.QUERY, "SELECT a.* FROM Queue_Message AS a WHERE 1=1 ")
.add("batchId", "AND a.batchId=?")
;
Table.add(UPDATE_BATCH_SQL, "UPDATE Queue_Message AS a " +
table.add(UPDATE_BATCH_SQL, "UPDATE Queue_Message AS a " +
"INNER JOIN ( SELECT * FROM Queue_Message WHERE (HandleTime IS NULL OR HandleTime < NOW()) " +
"ORDER BY HandleTime ASC,MessageId ASC {LIMIT} ) AS b ON a.MessageId = b.MessageId " +
"SET a.BatchId = ?,a.HandleTime=DATE_ADD(NOW(),INTERVAL 5 MINUTE) ", "batchId");
......@@ -57,6 +57,6 @@ public class MessageDaoImpl extends BaseDaoImpl implements MessageDao {
public List<MessageVo> getListByBatch(String batchId) {
MapRow row = new MapRow();
row.put("batchId", batchId);
return this.query(MessageVo.class, DaoConst.Query, row);
return this.query(MessageVo.class, DaoConst.QUERY, row);
}
}
package com.yanzuoguang.mq.dao.impl;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.dao.Impl.BaseDaoImpl;
import com.yanzuoguang.dao.Impl.TableFieldString;
import com.yanzuoguang.dao.impl.BaseDaoImpl;
import com.yanzuoguang.dao.impl.TableFieldString;
import com.yanzuoguang.mq.dao.QueueDao;
import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.mq.vo.req.QueueQueryReqVo;
......@@ -24,9 +24,9 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
// 根据实体生成增删改查语句
register(QueueVo.class);
Table.addSaveWith(SAVE_WITH_SQL, new TableFieldString("queueName", "exchangeName", "routeKey"));
table.addSaveWith(SAVE_WITH_SQL, new TableFieldString("queueName", "exchangeName", "routeKey"));
Table.add(DaoConst.Query, "SELECT * FROM Queue_Queue WHERE 1=1 ")
table.add(DaoConst.QUERY, "SELECT * FROM Queue_Queue WHERE 1=1 ")
.add("queueName", "AND ( QueueName LIKE CONCAT('%',?,'%') OR DelayQueueName LIKE CONCAT('%',?,'%') )")
.add("exchangeName", "AND ( ExchangeName LIKE CONCAT('%',?,'%') OR DelayExchangeName LIKE CONCAT('%',?,'%') )")
.add("routeKey", "AND ( RouteKey LIKE CONCAT('%',?,'%') OR DelayRouteKey LIKE CONCAT('%',?,'%') )")
......@@ -53,7 +53,7 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
*/
@Override
public PageSizeData<QueueVo> query(QueueQueryReqVo req) {
return this.queryPage(QueueVo.class, req, DaoConst.Query, req);
return this.queryPage(QueueVo.class, req, DaoConst.QUERY, req);
}
/**
......@@ -63,6 +63,6 @@ public class QueueDaoImpl extends BaseDaoImpl implements QueueDao {
*/
@Override
public List<QueueVo> list() {
return this.query(QueueVo.class, DaoConst.Query, null);
return this.query(QueueVo.class, DaoConst.QUERY, null);
}
}
......@@ -48,7 +48,7 @@ public interface MqService {
* @param req
* @return
*/
String message_error(MessageVo req);
String messageError(MessageVo req);
/**
* 消息收到确认
......
......@@ -77,7 +77,7 @@ public class MqServiceImpl implements MqService {
* @return
*/
@Override
public String message_error(MessageVo req) {
public String messageError(MessageVo req) {
req.check();
return messageService.onError(req);
}
......
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