Commit 02b4927f authored by yanzg's avatar yanzg

常规BUG的修改

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