Commit 8a8367fb authored by yanzg's avatar yanzg

修改实例化关系

parent bd6ac76b
...@@ -13,55 +13,58 @@ public class YzgError { ...@@ -13,55 +13,58 @@ public class YzgError {
private static YzgErrorData error = new YzgErrorData("999."); private static YzgErrorData error = new YzgErrorData("999.");
private static void init() { private static void init() {
error.add("000","%s"); error.add("000", "%s");
error.add("001", "该页面未绑定表"); error.add("001", "该页面未绑定表");
error.add("002", "类%s未发现表结构"); error.add("002", "类%s未发现表结构");
error.add("003", "类%s未发现SQL语句%s"); error.add("003", "类%s未发现SQL语句%s");
error.add("004", "泛型继承检测错误"); error.add("004", "泛型继承检测错误");
error.add("005","视频文件不存在"); error.add("005", "视频文件不存在");
error.add("006","对象%s不能复制"); error.add("006", "对象%s不能复制");
error.add("007","整形转换成字节的PCD码必须小于100"); error.add("007", "整形转换成字节的PCD码必须小于100");
error.add("008","不能识别文件类型%s"); error.add("008", "不能识别文件类型%s");
error.add("009","文件类型不为图片、音频、视频"); error.add("009", "文件类型不为图片、音频、视频");
error.add("010","文件%s已存在文件,不能创建目录"); error.add("010", "文件%s已存在文件,不能创建目录");
error.add("011","创建文件夹失败"); error.add("011", "创建文件夹失败");
error.add("012","文件删除失败"); error.add("012", "文件删除失败");
error.add("013","变量名%s不支持"); error.add("013", "变量名%s不支持");
error.add("014","正则表达式错误"); error.add("014", "正则表达式错误");
error.add("015","length params is error, must be greater than 0, this params is [%s]"); error.add("015", "length params is error, must be greater than 0, this params is [%s]");
error.add("016","random code, essential data is empty."); error.add("016", "random code, essential data is empty.");
error.add("017","生成时间搓 MD5 ID 时,时间不能为空"); error.add("017", "生成时间搓 MD5 ID 时,时间不能为空");
error.add("018","压缩时文件夹对象不能为空。"); error.add("018", "压缩时文件夹对象不能为空。");
error.add("019","[%s]不是一个文件夹,或者不存在。"); error.add("019", "[%s]不是一个文件夹,或者不存在。");
error.add("020","删除文件失败"); error.add("020", "删除文件[%s]失败");
error.add("021","文件%s不存在"); error.add("021", "文件%s不存在");
error.add("022","没有抛出异常"); error.add("022", "没有抛出异常");
error.add("023","监视错误"); error.add("023", "获取Web请求上下文错误");
error.add("024","导出时请传入配置信息"); error.add("024", "导出时请传入配置信息");
error.add("025","不能处理非本条件的字段"); error.add("025", "不能处理非本条件的字段");
error.add("026","代码片段%s:%s:%s为单数"); error.add("026", "代码片段%s:%s:%s为单数");
error.add("027","SqlCondItem不支持输入参数,必须带代码片段"); error.add("027", "SqlCondItem不支持输入参数,必须带代码片段");
error.add("028","需要格式化的字符串不支持"); error.add("028", "需要格式化的字符串不支持");
error.add("029","表%s主键值为空时不能更新"); error.add("029", "表%s主键值为空时不能更新");
error.add("030","修改失败,请确认是否被其他人修改,版本号传入是否正确"); error.add("030", "修改失败,请确认是否被其他人修改,版本号传入是否正确");
error.add("031","统计类型[%s]不支持"); error.add("031", "统计类型[%s]不支持");
error.add("032","SQL语句%s不存在纬度%s"); error.add("032", "SQL语句%s不存在纬度%s");
error.add("033","表中未包含MD5字段"); error.add("033", "表中未包含MD5字段");
error.add("034","Excel已初始化"); error.add("034", "Excel已初始化");
error.add("035","保存失败"); error.add("035", "保存失败");
error.add("036","保存路径%s失败"); error.add("036", "保存路径%s失败");
error.add("037","%s失败,该数据可能已被修改"); error.add("037", "%s失败,该数据可能已被修改");
error.add("038","size请在0~1之间"); error.add("038", "size请在0~1之间");
error.add("039","视频转码压缩时文件不存在:%s"); error.add("039", "视频转码压缩时文件不存在:%s");
error.add("040","audioBitRateZip请在0~1之间"); error.add("040", "audioBitRateZip请在0~1之间");
error.add("041","videoSizeZip请在0~1之间"); error.add("041", "videoSizeZip请在0~1之间");
error.add("042","videoBitRateZip请在0~1之间"); error.add("042", "videoBitRateZip请在0~1之间");
error.add("043","你需要格式化的字符串格式为空"); error.add("043", "你需要格式化的字符串格式为空");
error.add("044","不能获取文件Mime类型%s"); error.add("044", "不能获取文件Mime类型%s");
error.add("045","下载失败"); error.add("045", "下载失败:%s");
error.add("046","创建对象%s出错"); error.add("046", "创建对象%s出错");
error.add("047","不能识别模板"); error.add("047", "不能识别模板:%s");
error.add("048","获取视频所缩类图失败:%s"); error.add("048", "获取视频所缩类图失败:%s");
error.add("049", "%s %s");
error.add("050", "%s");
error.add("051", "%s");
} }
...@@ -86,7 +89,7 @@ public class YzgError { ...@@ -86,7 +89,7 @@ public class YzgError {
* @param code * @param code
* @param args * @param args
*/ */
public static CodeException throwException(Exception ex, String code, Object... args) { public static CodeException throwException(Throwable ex, String code, Object... args) {
throw error.getCodeException(ex, code, args); throw error.getCodeException(ex, code, args);
} }
...@@ -106,7 +109,7 @@ public class YzgError { ...@@ -106,7 +109,7 @@ public class YzgError {
* @param code * @param code
* @param args * @param args
*/ */
public static CodeException getException(Exception ex, String code, Object... args) { public static CodeException getException(Throwable ex, String code, Object... args) {
return error.getCodeException(ex, code, args); return error.getCodeException(ex, code, args);
} }
...@@ -126,7 +129,7 @@ public class YzgError { ...@@ -126,7 +129,7 @@ public class YzgError {
* @param code * @param code
* @param args * @param args
*/ */
public static RuntimeCodeException throwRuntimeException(Exception ex, String code, Object... args) { public static RuntimeCodeException throwRuntimeException(Throwable ex, String code, Object... args) {
throw error.getRuntimeException(ex, code, args); throw error.getRuntimeException(ex, code, args);
} }
...@@ -146,7 +149,7 @@ public class YzgError { ...@@ -146,7 +149,7 @@ public class YzgError {
* @param code * @param code
* @param args * @param args
*/ */
public static RuntimeCodeException getRuntimeException(Exception ex, String code, Object... args) { public static RuntimeCodeException getRuntimeException(Throwable ex, String code, Object... args) {
return error.getRuntimeException(ex, code, args); return error.getRuntimeException(ex, code, args);
} }
......
...@@ -54,7 +54,7 @@ public class YzgErrorData { ...@@ -54,7 +54,7 @@ public class YzgErrorData {
* @param code * @param code
* @param args * @param args
*/ */
public CodeException getCodeException(Exception ex, String code, Object... args) { public CodeException getCodeException(Throwable ex, String code, Object... args) {
String message = getMessage(ErrorCode, code, args); String message = getMessage(ErrorCode, code, args);
if (ex != null) { if (ex != null) {
return new CodeException(TAG + code, message, ex); return new CodeException(TAG + code, message, ex);
...@@ -79,7 +79,7 @@ public class YzgErrorData { ...@@ -79,7 +79,7 @@ public class YzgErrorData {
* @param code * @param code
* @param args * @param args
*/ */
public RuntimeCodeException getRuntimeException(Exception ex, String code, Object... args) { public RuntimeCodeException getRuntimeException(Throwable ex, String code, Object... args) {
String message = getMessage(ErrorCode, code, args); String message = getMessage(ErrorCode, code, args);
if (ex != null) { if (ex != null) {
return new RuntimeCodeException(TAG + code, message, ex); return new RuntimeCodeException(TAG + code, message, ex);
......
...@@ -63,15 +63,7 @@ public final class RandomHelper { ...@@ -63,15 +63,7 @@ public final class RandomHelper {
* @return * @return
*/ */
public static String generateRandomCodeSix(int len) { public static String generateRandomCodeSix(int len) {
if (len < 1) { return generateRandomCode(RANDOM_CHARSET, len);
throw YzgError.getRuntimeException("015",len);
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < len; i++) {
sb.append(generateRandomCodeOne(RANDOM_CHARSET, RANDOM_CHARSET_LEN));
}
return sb.toString();
} }
/** /**
...@@ -87,7 +79,7 @@ public final class RandomHelper { ...@@ -87,7 +79,7 @@ public final class RandomHelper {
} }
if (len < 1) { if (len < 1) {
throw YzgError.getRuntimeException("015",len); throw YzgError.getRuntimeException("015", len);
} }
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
......
...@@ -36,13 +36,13 @@ public class RunHelper { ...@@ -36,13 +36,13 @@ public class RunHelper {
* @param size 需要执行的次数 * @param size 需要执行的次数
*/ */
public static void run(String tag, Runnable run, int sleep, int size) { public static void run(String tag, Runnable run, int sleep, int size) {
Exception ex = null; RuntimeException ex = null;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
try { try {
run.run(); run.run();
ex = null; ex = null;
break; break;
} catch (Exception e) { } catch (RuntimeException e) {
if (i < size) { if (i < size) {
// 间隔100ms,防止服务器重启时请求失败 // 间隔100ms,防止服务器重启时请求失败
ThreadHelper.sleep(sleep); ThreadHelper.sleep(sleep);
...@@ -51,7 +51,7 @@ public class RunHelper { ...@@ -51,7 +51,7 @@ public class RunHelper {
} }
} }
if (ex != null) { if (ex != null) {
throw YzgError.getRuntimeException(ex,"000",tag + ex.getMessage()); throw YzgError.getRuntimeException(ex, "049", tag, ex.getMessage());
} }
} }
} }
package com.yanzuoguang.util.helper; package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.YzgError; import com.yanzuoguang.util.YzgError;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
...@@ -43,7 +35,7 @@ public class ZipHelper { ...@@ -43,7 +35,7 @@ public class ZipHelper {
throw YzgError.getRuntimeException("018"); throw YzgError.getRuntimeException("018");
} }
if (!dirFile.isDirectory()) { if (!dirFile.isDirectory()) {
throw YzgError.getRuntimeException("019",dirFile.getName()); throw YzgError.getRuntimeException("019", dirFile.getName());
} }
if (zipFile == null) { if (zipFile == null) {
zipFile = new File(dirFile.getAbsolutePath() + ".zip"); zipFile = new File(dirFile.getAbsolutePath() + ".zip");
...@@ -159,7 +151,7 @@ public class ZipHelper { ...@@ -159,7 +151,7 @@ public class ZipHelper {
if (flag) { if (flag) {
tempFile.renameTo(zipTo); tempFile.renameTo(zipTo);
} else { } else {
throw YzgError.getRuntimeException("020"); throw YzgError.getRuntimeException("020", tempFile.getName());
} }
} }
} }
...@@ -217,7 +209,7 @@ public class ZipHelper { ...@@ -217,7 +209,7 @@ public class ZipHelper {
*/ */
private static void zipFile(String sourcePath, File file, ZipOutputStream zipOutStream, BufferedOutputStream bufferOutStream) throws IOException { private static void zipFile(String sourcePath, File file, ZipOutputStream zipOutStream, BufferedOutputStream bufferOutStream) throws IOException {
if (!file.exists()) { if (!file.exists()) {
throw YzgError.getRuntimeException("021",file.getAbsolutePath()); throw YzgError.getRuntimeException("021", file.getAbsolutePath());
} }
// 创建压缩文件实体 // 创建压缩文件实体
ZipEntry entry = new ZipEntry(sourcePath + file.getName()); ZipEntry entry = new ZipEntry(sourcePath + file.getName());
......
...@@ -29,7 +29,7 @@ public class RunnableList extends AbstractThreadList<Runnable> { ...@@ -29,7 +29,7 @@ public class RunnableList extends AbstractThreadList<Runnable> {
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
throw ex; throw ex;
} catch (Exception ex) { } catch (Exception ex) {
throw YzgError.getRuntimeException("000",ex.getMessage()); throw YzgError.getRuntimeException("050", ex.getMessage());
} }
} }
} }
...@@ -158,7 +158,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> { ...@@ -158,7 +158,7 @@ public class RunnableListAutoItem implements Comparable<RunnableListAutoItem> {
if (ex instanceof RuntimeException) { if (ex instanceof RuntimeException) {
throw (RuntimeException) ex; throw (RuntimeException) ex;
} else { } else {
throw YzgError.getRuntimeException("000",ex.getMessage()); throw YzgError.getRuntimeException(ex, "051", ex.getMessage());
} }
} }
......
...@@ -137,7 +137,7 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> { ...@@ -137,7 +137,7 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
} catch (IOException e) { } catch (IOException e) {
isDown = true; isDown = true;
e.printStackTrace(); e.printStackTrace();
throw YzgError.getRuntimeException(e,"045"); throw YzgError.getRuntimeException(e, "045", e.getMessage());
} finally { } finally {
if (isDown) { if (isDown) {
// 删除生成的临时文件 // 删除生成的临时文件
......
...@@ -102,7 +102,7 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> { ...@@ -102,7 +102,7 @@ public abstract class SqlCondBase<T extends SqlCondBase> implements SqlCond<T> {
String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0); String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
// 判断代码片段是否合法 // 判断代码片段是否合法
if (sqlDataField.getCodes().size() % 2 == 1) { if (sqlDataField.getCodes().size() % 2 == 1) {
throw YzgError.getRuntimeException("026",this.getClass().getSimpleName(),sqlData.getName(),fieldName); throw YzgError.getRuntimeException("026", this.getClass().getSimpleName(), sqlData.getName(), fieldName);
} }
// 处理代码片段 // 处理代码片段
for (int i = 0; i < sqlDataField.getCodes().size(); i = i + DaoConst.CODE_UNIT) { for (int i = 0; i < sqlDataField.getCodes().size(); i = i + DaoConst.CODE_UNIT) {
......
...@@ -76,7 +76,7 @@ public class SqlCondItem extends SqlCondBase<SqlCondItem> { ...@@ -76,7 +76,7 @@ public class SqlCondItem extends SqlCondBase<SqlCondItem> {
String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0); String fieldName = this.fields.isEmpty() ? StringHelper.EMPTY : this.fields.get(0);
// 判断代码片段是否合法 // 判断代码片段是否合法
if (sqlDataField.getCodes().size() % 2 == 1) { if (sqlDataField.getCodes().size() % 2 == 1) {
throw YzgError.getRuntimeException("026",this.getClass().getSimpleName(),sqlData.getName(),fieldName); throw YzgError.getRuntimeException("026", this.getClass().getSimpleName(), sqlData.getName(), fieldName);
} }
Object value = ObjectHelper.get(model, fieldName); Object value = ObjectHelper.get(model, fieldName);
List list = ArrayHelper.getList(value); List list = ArrayHelper.getList(value);
......
...@@ -171,7 +171,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -171,7 +171,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
public String update(Object model) { public String update(Object model) {
String keyString = this.getKeyString(model); String keyString = this.getKeyString(model);
if (StringHelper.isEmpty(keyString)) { if (StringHelper.isEmpty(keyString)) {
throw YzgError.getRuntimeException("029",this.table.getTable().getName()); throw YzgError.getRuntimeException("029", this.table.getTable().getName());
} }
this.check(DaoConst.OPERATOR_TYPE_UPDATE, keyString, model); this.check(DaoConst.OPERATOR_TYPE_UPDATE, keyString, model);
SqlData sqlData = this.getSql(DaoConst.UPDATE); SqlData sqlData = this.getSql(DaoConst.UPDATE);
...@@ -866,7 +866,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -866,7 +866,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
try { try {
from = cls.newInstance(); from = cls.newInstance();
} catch (Exception ex) { } catch (Exception ex) {
throw YzgError.getRuntimeException(ex,"046",cls.getName()); throw YzgError.getRuntimeException(ex, "046", cls.getName());
} }
ObjectHelper.writeWithFrom(from, request); ObjectHelper.writeWithFrom(from, request);
return this.create(from); return this.create(from);
......
...@@ -792,7 +792,7 @@ public abstract class BaseDaoSql { ...@@ -792,7 +792,7 @@ public abstract class BaseDaoSql {
sb.append("AVG"); sb.append("AVG");
break; break;
default: default:
throw YzgError.getRuntimeException("031",from.getGroupType()); throw YzgError.getRuntimeException("031", from.getGroupType());
} }
sb.append("( CASE WHEN "); sb.append("( CASE WHEN ");
sb.append(from.getCaseField()); sb.append(from.getCaseField());
......
...@@ -170,7 +170,7 @@ public class TableSqlCache { ...@@ -170,7 +170,7 @@ public class TableSqlCache {
for (String item : tableWhereField.getFields()) { for (String item : tableWhereField.getFields()) {
String name = item.toLowerCase(); String name = item.toLowerCase();
if (!sqlFieldHas.containsKey(name)) { if (!sqlFieldHas.containsKey(name)) {
throw YzgError.getRuntimeException("032",item,item); throw YzgError.getRuntimeException("032", sqlName, item);
} }
sqlFieldWhere.put(name, true); sqlFieldWhere.put(name, true);
} }
......
...@@ -140,7 +140,7 @@ public class MediaHelper extends ImageHelper { ...@@ -140,7 +140,7 @@ public class MediaHelper extends ImageHelper {
// 源文件判断 // 源文件判断
File source = new File(fromFile); File source = new File(fromFile);
if (!source.exists()) { if (!source.exists()) {
throw YzgError.getRuntimeException("039",fromFile); throw YzgError.getRuntimeException("039", fromFile);
} }
File target = new File(toFile); File target = new File(toFile);
if (!target.getParentFile().exists()) { if (!target.getParentFile().exists()) {
...@@ -163,7 +163,7 @@ public class MediaHelper extends ImageHelper { ...@@ -163,7 +163,7 @@ public class MediaHelper extends ImageHelper {
String suffix = toFile.substring(toFile.lastIndexOf(".") + 1); String suffix = toFile.substring(toFile.lastIndexOf(".") + 1);
getGrabberFFmpegImage(fromFile, toFile, suffix, FRAME_INDEX); getGrabberFFmpegImage(fromFile, toFile, suffix, FRAME_INDEX);
} catch (IOException ex) { } catch (IOException ex) {
throw YzgError.getRuntimeException(ex,"048",ex.getMessage()); throw YzgError.getRuntimeException(ex, "048", ex.getMessage());
} }
} }
......
...@@ -67,7 +67,7 @@ public class PrinterHelper { ...@@ -67,7 +67,7 @@ public class PrinterHelper {
try { try {
pager = JsonHelper.deserialize(from.getPager(), PrinterPagerData.class); pager = JsonHelper.deserialize(from.getPager(), PrinterPagerData.class);
} catch (Exception ex) { } catch (Exception ex) {
throw YzgError.getRuntimeException(ex,"047"); throw YzgError.getRuntimeException(ex, "047", ex.getMessage());
} }
// 设置偏移量 // 设置偏移量
pager.setMarginTop(pager.getMarginTop() + top); pager.setMarginTop(pager.getMarginTop() + top);
......
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