Commit 02b4927f authored by yanzg's avatar yanzg

常规BUG的修改

parent 57e0e808
...@@ -12,21 +12,62 @@ public class MethodField { ...@@ -12,21 +12,62 @@ public class MethodField {
/** /**
* 名称 * 名称
*/ */
public String name; private String name;
/** /**
* 缩写名称 * 缩写名称
*/ */
public String nameSimple; private String nameSimple;
/** /**
* 对应的字段 * 对应的字段
*/ */
public Field field; private Field field;
/** /**
* 对应的获取方法 * 对应的获取方法
*/ */
public Method getMethod; private Method getMethod;
/** /**
* 对应的设置方法 * 对应的设置方法
*/ */
public Method setMethod; private Method setMethod;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNameSimple() {
return nameSimple;
}
public void setNameSimple(String nameSimple) {
this.nameSimple = nameSimple;
}
public Field getField() {
return field;
}
public void setField(Field field) {
this.field = field;
}
public Method getGetMethod() {
return getMethod;
}
public void setGetMethod(Method getMethod) {
this.getMethod = getMethod;
}
public Method getSetMethod() {
return setMethod;
}
public void setSetMethod(Method setMethod) {
this.setMethod = setMethod;
}
} }
...@@ -156,10 +156,10 @@ public class ObjectHelper { ...@@ -156,10 +156,10 @@ public class ObjectHelper {
return null; return null;
} }
try { try {
if (item.field != null && Modifier.isPublic(item.field.getModifiers())) { if (item.getField() != null && Modifier.isPublic(item.getField().getModifiers())) {
return item.field.get(target); return item.getField().get(target);
} else if (item.getMethod != null && Modifier.isPublic(item.getMethod.getModifiers())) { } else if (item.getGetMethod() != null && Modifier.isPublic(item.getGetMethod().getModifiers())) {
return item.getMethod.invoke(target); return item.getGetMethod().invoke(target);
} }
} catch (Exception ex) { } catch (Exception ex) {
ExceptionHelper.handleException(ObjectHelper.class, ex, field); ExceptionHelper.handleException(ObjectHelper.class, ex, field);
...@@ -206,14 +206,14 @@ public class ObjectHelper { ...@@ -206,14 +206,14 @@ public class ObjectHelper {
return; return;
} }
try { try {
if (item.field != null && Modifier.isPublic(item.field.getModifiers())) { if (item.getField() != null && Modifier.isPublic(item.getField().getModifiers())) {
Class toType = item.field.getType(); Class toType = item.getField().getType();
Object toValue = StringHelper.to(toType, value); Object toValue = StringHelper.to(toType, value);
item.field.set(target, toValue); item.getField().set(target, toValue);
} else if (item.setMethod != null && Modifier.isPublic(item.setMethod.getModifiers())) { } else if (item.getSetMethod() != null && Modifier.isPublic(item.getSetMethod().getModifiers())) {
Class toType = item.setMethod.getParameterTypes()[0]; Class toType = item.getSetMethod().getParameterTypes()[0];
Object toValue = StringHelper.to(toType, value); Object toValue = StringHelper.to(toType, value);
item.setMethod.invoke(target, toValue); item.getSetMethod().invoke(target, toValue);
} }
} catch (Exception ex) { } catch (Exception ex) {
ExceptionHelper.handleException(ObjectHelper.class, ex, field); ExceptionHelper.handleException(ObjectHelper.class, ex, field);
...@@ -254,8 +254,8 @@ public class ObjectHelper { ...@@ -254,8 +254,8 @@ public class ObjectHelper {
if (!typeCache.containsKey(toName)) { if (!typeCache.containsKey(toName)) {
MethodField newObj = new MethodField(); MethodField newObj = new MethodField();
typeCache.put(toName, newObj); typeCache.put(toName, newObj);
newObj.name = fromName; newObj.setName(fromName);
newObj.nameSimple = toName; newObj.setNameSimple(toName);
} }
return typeCache.get(toName); return typeCache.get(toName);
} }
...@@ -307,8 +307,8 @@ public class ObjectHelper { ...@@ -307,8 +307,8 @@ public class ObjectHelper {
if (Modifier.isStatic(field.getModifiers())) { if (Modifier.isStatic(field.getModifiers())) {
continue; continue;
} }
if (obj.field == null) { if (obj.getField() == null) {
obj.field = field; obj.setField(field);
} }
} }
for (Method method : methods) { for (Method method : methods) {
...@@ -324,24 +324,24 @@ public class ObjectHelper { ...@@ -324,24 +324,24 @@ public class ObjectHelper {
continue; continue;
} }
MethodField obj = getField(typeCache, methodNameSource); MethodField obj = getField(typeCache, methodNameSource);
if (obj.setMethod == null) { if (obj.getSetMethod() == null) {
obj.setMethod = method; obj.setSetMethod(method);
} }
} else if (methodNameSimple.startsWith("get")) { } else if (methodNameSimple.startsWith("get")) {
if (method.getReturnType() == null) { if (method.getReturnType() == null) {
continue; continue;
} }
MethodField obj = getField(typeCache, methodNameSource); MethodField obj = getField(typeCache, methodNameSource);
if (obj.getMethod == null) { if (obj.getGetMethod() == null) {
obj.getMethod = method; obj.setGetMethod(method);
} }
} else if (methodNameSimple.startsWith("is")) { } else if (methodNameSimple.startsWith("is")) {
if (method.getReturnType() == null) { if (method.getReturnType() == null) {
continue; continue;
} }
MethodField obj = getField(typeCache, methodNameSource); MethodField obj = getField(typeCache, methodNameSource);
if (obj.getMethod == null) { if (obj.getGetMethod() == null) {
obj.getMethod = method; obj.setGetMethod(method);
} }
} }
} }
...@@ -538,7 +538,7 @@ public class ObjectHelper { ...@@ -538,7 +538,7 @@ public class ObjectHelper {
return to; return to;
} }
for (Map.Entry<String, MethodField> field : mapField.entrySet()) { for (Map.Entry<String, MethodField> field : mapField.entrySet()) {
String name = field.getValue().name; String name = field.getValue().getName();
Object fromValue = ObjectHelper.get(from, name); Object fromValue = ObjectHelper.get(from, name);
if (StringHelper.isEmpty(fromValue)) { if (StringHelper.isEmpty(fromValue)) {
continue; continue;
......
...@@ -16,7 +16,7 @@ public class MemoryCacheCenter { ...@@ -16,7 +16,7 @@ public class MemoryCacheCenter {
/** /**
* 缓存的对象 * 缓存的对象
*/ */
public static List<MemoryCache> CLEAR_LIST = new Vector<MemoryCache>(); public final static List<MemoryCache> CLEAR_LIST = new Vector<MemoryCache>();
static { static {
init(); init();
......
...@@ -11,12 +11,13 @@ import java.util.regex.Pattern; ...@@ -11,12 +11,13 @@ import java.util.regex.Pattern;
/** /**
* 参数业务逻辑校验 * 参数业务逻辑校验
*
* @author 颜佐光 * @author 颜佐光
*/ */
public final class CheckerHelper { public final class CheckerHelper {
public static final String PARAM_NOT_NULL_TIPS = "param [%s] is null"; public static final String PARAM_NOT_NULL_TIPS = "param [%s] is null";
public static final String PARAM_NOT_EMPTY_TIPS = "param [%s] is empty"; public static final String PARAM_NOT_EMPTY_TIPS = "param [%s] is empty";
public static final String PARAM_NOT_NUMBER = "param [%s] must be number"; public static final String PARAM_NOT_NUMBER = "param [%s] value [%s] must be number";
public static final String PARAM_OVER_MAX_LENGTH = "param [%s] maxlength is "; public static final String PARAM_OVER_MAX_LENGTH = "param [%s] maxlength is ";
public static final String PARAM_NOT_DATE_MONTH = "param [%s] must be yyyyMM"; public static final String PARAM_NOT_DATE_MONTH = "param [%s] must be yyyyMM";
...@@ -176,9 +177,6 @@ public final class CheckerHelper { ...@@ -176,9 +177,6 @@ public final class CheckerHelper {
String eL = ""; String eL = "";
String msg = ""; String msg = "";
if (StringHelper.isEmpty(paramVal)) { if (StringHelper.isEmpty(paramVal)) {
msg = PARAM_NOT_NULL_TIPS;
this.checkResult = String.format(msg, paramName, paramVal);
this.setValid(false);
return this; return this;
} }
if (DATE_CHECK_TYPE_DAY.equals(queryType)) { if (DATE_CHECK_TYPE_DAY.equals(queryType)) {
...@@ -328,7 +326,7 @@ public final class CheckerHelper { ...@@ -328,7 +326,7 @@ public final class CheckerHelper {
return this; return this;
} }
if (paramVal < min) { if (paramVal < min) {
this.checkResult = String.format(PARAM_NOT_MIN, min, paramName); this.checkResult = String.format(PARAM_NOT_MIN, paramName, min);
this.setValid(false); this.setValid(false);
} }
return this; return this;
...@@ -347,7 +345,7 @@ public final class CheckerHelper { ...@@ -347,7 +345,7 @@ public final class CheckerHelper {
return this; return this;
} }
if (paramVal > max) { if (paramVal > max) {
this.checkResult = String.format(PARAM_NOT_MAX, max, paramName); this.checkResult = String.format(PARAM_NOT_MAX, paramName, max);
this.setValid(false); this.setValid(false);
} }
return this; return this;
...@@ -367,7 +365,7 @@ public final class CheckerHelper { ...@@ -367,7 +365,7 @@ public final class CheckerHelper {
return this; return this;
} }
if (paramVal > max || paramVal < min) { if (paramVal > max || paramVal < min) {
this.checkResult = String.format(PARAM_NOT_RANGE, min, max, paramName); this.checkResult = String.format(PARAM_NOT_RANGE, paramName, min, max);
this.setValid(false); this.setValid(false);
} }
return this; return this;
......
...@@ -87,18 +87,24 @@ public class FileHelper { ...@@ -87,18 +87,24 @@ public class FileHelper {
try { try {
// 删除文件 // 删除文件
if (file.exists()) { if (file.exists()) {
file.delete(); if (!file.delete()) {
throw new CodeException("文件删除失败");
}
} }
if (file.exists()) { if (file.exists()) {
throw new CodeException("文件删除失败"); throw new CodeException("文件删除失败");
} }
// 创建文件夹 // 创建文件夹
File parentFile = file.getParentFile(); File parentFile = file.getParentFile();
if (parentFile != null && !parentFile.exists()) { if (parentFile != null) {
parentFile.mkdirs(); if (!parentFile.exists()) {
} if (!parentFile.mkdirs()) {
if (!parentFile.exists()) { throw new CodeException("创建文件夹失败");
throw new CodeException("创建文件夹失败"); }
}
if (!parentFile.exists()) {
throw new CodeException("创建文件夹失败");
}
} }
file.createNewFile(); file.createNewFile();
// 写入文件 // 写入文件
......
...@@ -86,7 +86,7 @@ public class HttpHelper { ...@@ -86,7 +86,7 @@ public class HttpHelper {
*/ */
public static String post(HttpURLConnection httpConn, String jsonString) throws IOException { public static String post(HttpURLConnection httpConn, String jsonString) throws IOException {
// 返回的结果 // 返回的结果
String result = ""; StringBuilder result = new StringBuilder();
// 读取响应输入流 // 读取响应输入流
BufferedReader in = null; BufferedReader in = null;
PrintWriter out = null; PrintWriter out = null;
...@@ -107,7 +107,7 @@ public class HttpHelper { ...@@ -107,7 +107,7 @@ public class HttpHelper {
String line; String line;
// 读取返回的内容 // 读取返回的内容
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
result += line; result.append(line);
} }
} finally { } finally {
if (out != null) { if (out != null) {
...@@ -117,7 +117,7 @@ public class HttpHelper { ...@@ -117,7 +117,7 @@ public class HttpHelper {
in.close(); in.close();
} }
} }
return result; return result.toString();
} }
/** /**
......
...@@ -2,10 +2,12 @@ package com.yanzuoguang.util.helper; ...@@ -2,10 +2,12 @@ package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.contants.SystemContants; import com.yanzuoguang.util.contants.SystemContants;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
/** /**
* 随机码生成工具 * 随机码生成工具
*
* @author 颜佐光 * @author 颜佐光
*/ */
public final class RandomHelper { public final class RandomHelper {
...@@ -75,7 +77,7 @@ public final class RandomHelper { ...@@ -75,7 +77,7 @@ public final class RandomHelper {
* 随机生成指定字符集、指定长度的的随机码 * 随机生成指定字符集、指定长度的的随机码
* *
* @param charset 基础字符集 * @param charset 基础字符集
* @param len 生成随机码长度 * @param len 生成随机码长度
* @return * @return
*/ */
public static String generateRandomCode(String charset, int len) { public static String generateRandomCode(String charset, int len) {
...@@ -102,12 +104,12 @@ public final class RandomHelper { ...@@ -102,12 +104,12 @@ public final class RandomHelper {
* @return * @return
*/ */
private static String generateRandomCodeOne(String charset, int len) { private static String generateRandomCodeOne(String charset, int len) {
int index = (int) (Math.random() * len); int index = new Random().nextInt(len);
return String.valueOf(charset.charAt(index)); return String.valueOf(charset.charAt(index));
} }
private static String replace(String str, String olds, String news) { private static String replace(String str, String olds, String news) {
if(null == str) { if (null == str) {
return ""; return "";
} }
while (str.indexOf(olds) > -1) { while (str.indexOf(olds) > -1) {
......
...@@ -13,7 +13,7 @@ public class RunHelper { ...@@ -13,7 +13,7 @@ public class RunHelper {
/** /**
* 执行次数 * 执行次数
*/ */
public static int REQ_SIZE = 3; public final static int REQ_SIZE = 3;
/** /**
* 执行次数,并且获取最后一次的异常 * 执行次数,并且获取最后一次的异常
......
...@@ -5,6 +5,7 @@ import com.yanzuoguang.util.exception.CodeException; ...@@ -5,6 +5,7 @@ import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.exception.ExceptionHelper; import com.yanzuoguang.util.exception.ExceptionHelper;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
...@@ -531,7 +532,7 @@ public class StringHelper { ...@@ -531,7 +532,7 @@ public class StringHelper {
try { try {
buff = from.getBytes(charset); buff = from.getBytes(charset);
// 将字节流转换为字符串 // 将字节流转换为字符串
from = new String(buff); from = new String(buff, charset);
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);
...@@ -781,7 +782,7 @@ public class StringHelper { ...@@ -781,7 +782,7 @@ public class StringHelper {
// 生成实现指定摘要算法的 MessageDigest 对象。 // 生成实现指定摘要算法的 MessageDigest 对象。
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
// 使用指定的字节数组更新摘要。 // 使用指定的字节数组更新摘要。
md.update(from.getBytes()); md.update(from.getBytes(Charset.forName("utf-8")));
// 通过执行诸如填充之类的最终操作完成哈希计算。 // 通过执行诸如填充之类的最终操作完成哈希计算。
byte[] b = md.digest(); byte[] b = md.digest();
// 生成具体的md5密码到buf数组 // 生成具体的md5密码到buf数组
......
...@@ -16,7 +16,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait ...@@ -16,7 +16,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
/** /**
* 线程等待间隔 * 线程等待间隔
*/ */
public static int PrintTimeout = 1000 * 2; public final static int PrintTimeout = 1000 * 2;
/** /**
* 线程数量 * 线程数量
...@@ -283,7 +283,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait ...@@ -283,7 +283,7 @@ public abstract class AbstractThreadList<T extends Object> implements ThreadWait
} }
ThreadListData<T> data = cacheThread.get(Thread.currentThread()); ThreadListData<T> data = cacheThread.get(Thread.currentThread());
data.setDate(new Date()); data.setDate(System.currentTimeMillis());
data.setData(item); data.setData(item);
try { try {
this.run(item); this.run(item);
......
...@@ -10,6 +10,7 @@ import java.util.List; ...@@ -10,6 +10,7 @@ import java.util.List;
/** /**
* 自动执行任务 * 自动执行任务
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class RunPlan { public class RunPlan {
...@@ -82,7 +83,7 @@ public class RunPlan { ...@@ -82,7 +83,7 @@ public class RunPlan {
*/ */
public final void run(boolean isRemove, int maxError) { public final void run(boolean isRemove, int maxError) {
for (int i = list.size() - 1; i >= 0; i--) { for (int i = list.size() - 1; i >= 0; i--) {
Date now = new Date(); long now = System.currentTimeMillis();
RunPlanData item; RunPlanData item;
synchronized (this.lock) { synchronized (this.lock) {
item = list.size() > i ? list.get(i) : null; item = list.size() > i ? list.get(i) : null;
...@@ -96,10 +97,10 @@ public class RunPlan { ...@@ -96,10 +97,10 @@ public class RunPlan {
// 在Window CE中时间相减可能会出错 // 在Window CE中时间相减可能会出错
try { try {
// 处理非法改动时间 // 处理非法改动时间
if (item.getDate().compareTo(now) > 0) { if (item.getDate() > now) {
item.setDate(now); item.setDate(now);
} }
millSeconds = (now.getTime() - item.getDate().getTime()); millSeconds = (now - item.getDate());
} catch (Exception ex) { } catch (Exception ex) {
ExceptionHelper.handleException(ThreadHelper.class, ex); ExceptionHelper.handleException(ThreadHelper.class, ex);
} }
......
...@@ -10,7 +10,7 @@ public class RunPlanData { ...@@ -10,7 +10,7 @@ public class RunPlanData {
/** /**
* 任务开始时间 * 任务开始时间
*/ */
private Date date; private long date;
/** /**
* 执行标记 * 执行标记
*/ */
...@@ -39,11 +39,11 @@ public class RunPlanData { ...@@ -39,11 +39,11 @@ public class RunPlanData {
this.initDate(); this.initDate();
} }
public Date getDate() { public long getDate() {
return date; return date;
} }
public void setDate(Date date) { public void setDate(long date) {
this.date = date; this.date = date;
} }
...@@ -106,6 +106,6 @@ public class RunPlanData { ...@@ -106,6 +106,6 @@ public class RunPlanData {
* 重置时间 * 重置时间
*/ */
public void initDate() { public void initDate() {
this.date = new Date(); this.date = System.currentTimeMillis();
} }
} }
...@@ -17,7 +17,7 @@ public final class RunnableListAuto { ...@@ -17,7 +17,7 @@ public final class RunnableListAuto {
/** /**
* 是否打印线程日志 * 是否打印线程日志
*/ */
public static boolean IsLog = false; public final static boolean IsLog = false;
/** /**
* 缓存的执行对象的数据大小 * 缓存的执行对象的数据大小
......
...@@ -13,18 +13,18 @@ public class ThreadListData<T> { ...@@ -13,18 +13,18 @@ public class ThreadListData<T> {
/** /**
* 执行时间 * 执行时间
*/ */
private Date date; private long date;
/** /**
* 执行的数据 * 执行的数据
*/ */
private T data; private T data;
public Date getDate() { public long getDate() {
return date; return date;
} }
public void setDate(Date date) { public void setDate(long date) {
this.date = date; this.date = date;
} }
......
...@@ -8,6 +8,7 @@ package com.yanzuoguang.util.vo; ...@@ -8,6 +8,7 @@ package com.yanzuoguang.util.vo;
*/ */
public class Ref<T> { public class Ref<T> {
public T value; public T value;
public Ref(T value) { public Ref(T value) {
this.value = value; this.value = value;
} }
......
...@@ -10,6 +10,7 @@ import java.util.Random; ...@@ -10,6 +10,7 @@ import java.util.Random;
/** /**
* 加密算法0版实现 * 加密算法0版实现
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class CodePwdImpl implements CodePwd { public class CodePwdImpl implements CodePwd {
...@@ -38,25 +39,26 @@ public class CodePwdImpl implements CodePwd { ...@@ -38,25 +39,26 @@ public class CodePwdImpl implements CodePwd {
*/ */
@Override @Override
public String getCode(String rand, String day, String index, String pwd) { public String getCode(String rand, String day, String index, String pwd) {
String ret = ""; StringBuilder ret = new StringBuilder();
// 1. 将随即数和天数进行组合生成字符串 // 1. 将随即数和天数进行组合生成字符串
String randDay = ""; StringBuilder sb = new StringBuilder();
{ {
int randSize = rand.length(); int randSize = rand.length();
int daySize = day.length(); int daySize = day.length();
int maxLen = Math.max(rand.length(), day.length()); int maxLen = Math.max(rand.length(), day.length());
for (int i = 0; i < maxLen; i++) { for (int i = 0; i < maxLen; i++) {
if (i < daySize) { if (i < daySize) {
randDay += day.charAt(i); sb.append(day.charAt(i));
} }
if (i < randSize) { if (i < randSize) {
randDay += rand.charAt(i); sb.append(rand.charAt(i));
} }
} }
} }
// 2. 将组合后的数字进行交换 // 2. 将组合后的数字进行交换
String randDay = sb.toString();
int randDaySize = randDay.length(); int randDaySize = randDay.length();
char[] dayChars = new char[randDaySize]; char[] dayChars = new char[randDaySize];
{ {
...@@ -71,7 +73,7 @@ public class CodePwdImpl implements CodePwd { ...@@ -71,7 +73,7 @@ public class CodePwdImpl implements CodePwd {
} }
} }
for (int i = 0; i < randDaySize; i++) { for (int i = 0; i < randDaySize; i++) {
ret += dayChars[i]; ret.append(dayChars[i]);
} }
} }
...@@ -121,10 +123,10 @@ public class CodePwdImpl implements CodePwd { ...@@ -121,10 +123,10 @@ public class CodePwdImpl implements CodePwd {
for (int i = 0; i < newSize; i++) { for (int i = 0; i < newSize; i++) {
newValue[i] = (newValue[i] % 10 + 10) % 10; newValue[i] = (newValue[i] % 10 + 10) % 10;
ret += newValue[i]; ret.append(newValue[i]);
} }
return ret; return ret.toString();
} }
public static void test(String[] args) { public static void test(String[] args) {
......
...@@ -44,7 +44,7 @@ public abstract class BaseDaoSql { ...@@ -44,7 +44,7 @@ public abstract class BaseDaoSql {
/** /**
* 缓存的表结构和SQL语句 * 缓存的表结构和SQL语句
*/ */
protected static MemoryCache<TableSqlCache> cache = new MemoryCache<>(); protected final static MemoryCache<TableSqlCache> cache = new MemoryCache<>();
/** /**
* 获取数据库执行类 * 获取数据库执行类
...@@ -416,16 +416,17 @@ public abstract class BaseDaoSql { ...@@ -416,16 +416,17 @@ public abstract class BaseDaoSql {
String[] lastCode = new String[]{"{WHERE}", "{GROUP}", "{HAVING}", "{ORDER}", "{LIMIT}"}; String[] lastCode = new String[]{"{WHERE}", "{GROUP}", "{HAVING}", "{ORDER}", "{LIMIT}"};
// 将SQL语句进行代码片段追加 // 将SQL语句进行代码片段追加
String sql = sqlData.getSql(); StringBuilder sb = new StringBuilder(sqlData.getSql());
for (String code : lastCode) { for (String code : lastCode) {
if (sql.indexOf(code) == -1) { if (sb.indexOf(code) == -1) {
sql += code; sb.append(code);
} }
} }
// 代码片段缓存 // 代码片段缓存
Map<String, List<String>> codeMap = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE); Map<String, List<String>> codeMap = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
// 处理字段以及代码片段 // 处理字段以及代码片段
String sql = sb.toString();
sql = handleCodeRelease(sql, sqlData, model, codeMap); sql = handleCodeRelease(sql, sqlData, model, codeMap);
sql = handleCodeReplace(sql, codeMap); sql = handleCodeReplace(sql, codeMap);
...@@ -682,7 +683,7 @@ public abstract class BaseDaoSql { ...@@ -682,7 +683,7 @@ public abstract class BaseDaoSql {
} }
// 将对象转换为 Map 对象 // 将对象转换为 Map 对象
Map to = new HashMap<String, Object>(DaoConst.COLLECTION_INIT_SIZE); Map<String, Object> to = new HashMap<>(DaoConst.COLLECTION_INIT_SIZE);
if (from instanceof Map) { if (from instanceof Map) {
to = (Map) from; to = (Map) from;
} else { } else {
...@@ -694,16 +695,16 @@ public abstract class BaseDaoSql { ...@@ -694,16 +695,16 @@ public abstract class BaseDaoSql {
sb.append(" SELECT "); sb.append(" SELECT ");
// 处理列 // 处理列
for (Object oItemKey : to.keySet()) { for (Map.Entry<String, Object> oItemKey : to.entrySet()) {
if (column > 0) { if (column > 0) {
sb.append(","); sb.append(",");
} }
String itemKey = StringHelper.toString(oItemKey); String itemKey = oItemKey.getKey();
sb.append("? AS " + itemKey); sb.append("? AS " + itemKey);
// 处理参数 // 处理参数
Object itemValue = to.get(oItemKey); Object itemValue = oItemKey.getValue();
itemValue = this.getParaValue(itemValue); itemValue = this.getParaValue(itemValue);
paras.add(itemValue); paras.add(itemValue);
column++; column++;
......
...@@ -14,6 +14,7 @@ import java.util.regex.Pattern; ...@@ -14,6 +14,7 @@ import java.util.regex.Pattern;
/** /**
* 缓存的SQL语句信息 * 缓存的SQL语句信息
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class TableSqlCache { public class TableSqlCache {
...@@ -278,8 +279,8 @@ public class TableSqlCache { ...@@ -278,8 +279,8 @@ public class TableSqlCache {
} }
private String replaceString(Map<String, StringBuilder> map, String sql) { private String replaceString(Map<String, StringBuilder> map, String sql) {
for (String key : map.keySet()) { for (Map.Entry<String, StringBuilder> key : map.entrySet()) {
sql = sql.replace(key, map.get(key).toString()); sql = sql.replace(key.getKey(), key.getValue().toString());
} }
return sql; return sql;
} }
......
...@@ -95,20 +95,20 @@ public class TableStruct { ...@@ -95,20 +95,20 @@ public class TableStruct {
// 字段信息获取 // 字段信息获取
MethodField field = entry.getValue(); MethodField field = entry.getValue();
if (field.field == null && field.getMethod == null) { if (field.getField() == null && field.getGetMethod() == null) {
continue; continue;
} }
String fieldName = field.name; String fieldName = field.getName();
String fieldInputName = field.name; String fieldInputName = field.getName();
Class<?> fieldType = String.class; Class<?> fieldType = String.class;
TableAnnotation annotation = null; TableAnnotation annotation = null;
if (field.field != null) { if (field.getField() != null) {
annotation = field.field.getAnnotation(TableAnnotation.class); annotation = field.getField().getAnnotation(TableAnnotation.class);
fieldType = field.field.getType(); fieldType = field.getField().getType();
} else if (field.getMethod != null) { } else if (field.getGetMethod() != null) {
annotation = field.getMethod.getAnnotation(TableAnnotation.class); annotation = field.getGetMethod().getAnnotation(TableAnnotation.class);
fieldType = field.getMethod.getReturnType(); fieldType = field.getGetMethod().getReturnType();
} }
if (annotation != null) { if (annotation != null) {
fieldName = annotation.value(); fieldName = annotation.value();
......
...@@ -25,6 +25,7 @@ import java.util.Map; ...@@ -25,6 +25,7 @@ import java.util.Map;
/** /**
* 将数据映射为结果 * 将数据映射为结果
*
* @author 颜佐光 * @author 颜佐光
*/ */
public class AllBeanRowMapper<T> implements RowMapper<T> { public class AllBeanRowMapper<T> implements RowMapper<T> {
...@@ -138,8 +139,8 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -138,8 +139,8 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/ */
public static MapRow toLoweRow(MapRow from) { public static MapRow toLoweRow(MapRow from) {
MapRow to = new MapRow(); MapRow to = new MapRow();
for (String key : from.keySet()) { for (Map.Entry<String, Object> key : from.entrySet()) {
to.put(underscoreNameBase(key), from.get(key)); to.put(underscoreNameBase(key.getKey()), key.getValue());
} }
return to; return to;
} }
...@@ -152,9 +153,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -152,9 +153,9 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
*/ */
public static Object getLoweRowField(MapRow from, String field) { public static Object getLoweRowField(MapRow from, String field) {
field = underscoreNameBase(field); field = underscoreNameBase(field);
for (String key : from.keySet()) { for (Map.Entry<String, Object> key : from.entrySet()) {
if (underscoreNameBase(key).equals(field)) { if (underscoreNameBase(key.getKey()).equals(field)) {
return from.get(key); return key.getValue();
} }
} }
return null; return null;
...@@ -202,7 +203,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -202,7 +203,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
Log.info(AllBeanRowMapper.class, Log.info(AllBeanRowMapper.class,
"Intercepted TypeMismatchException for row %d and column '%s' with " + "Intercepted TypeMismatchException for row %d and column '%s' with " +
"value %s when setting property '%s' of type %s on object: %s", "value %s when setting property '%s' of type %s on object: %s",
rowNumber, column, value, pd.getName(), type, mappedObject); rowNumber, column, StringHelper.EMPTY, pd.getName(), type, mappedObject);
} else { } else {
throw e; throw e;
} }
...@@ -225,7 +226,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -225,7 +226,7 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
Log.info(AllBeanRowMapper.class, Log.info(AllBeanRowMapper.class,
"Intercepted TypeMismatchException for row %d and column '%s' with " + "Intercepted TypeMismatchException for row %d and column '%s' with " +
"value %s when setting property '%s' of type %s on object: %s", "value %s when setting property '%s' of type %s on object: %s",
rowNumber, column, value, pd.getName(), type, mappedObject); rowNumber, column, StringHelper.EMPTY, pd.getName(), type, mappedObject);
} else { } else {
throw e; throw e;
} }
......
...@@ -336,7 +336,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> { ...@@ -336,7 +336,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
workbook = null; workbook = null;
} }
File file = new File(this.getFileName()); File file = new File(this.getFileName());
if (file.exists() && file.delete()) { if (file.exists()) {
if (!file.delete()) {
throw new CodeException("文件删除失败");
}
} }
return this; return this;
} }
......
...@@ -40,7 +40,7 @@ public class TokenHelper { ...@@ -40,7 +40,7 @@ public class TokenHelper {
/** /**
* 内存缓存 * 内存缓存
*/ */
protected static MemoryCache<TokenData> cache = new MemoryCache<>(); protected final static MemoryCache<TokenData> cache = new MemoryCache<>();
/** /**
......
package com.yanzuoguang.token; package com.yanzuoguang.token;
import com.yanzuoguang.util.vo.MapRow;
/** /**
* 动态加载Token * 动态加载Token
* *
......
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