Commit eac429ae authored by gongzuquan's avatar gongzuquan

Merge remote-tracking branch 'origin/xy' into xy

# Conflicts:
#	yzg-util-base/src/main/java/com/yanzuoguang/util/YzgError.java
parents 0c950623 8a8367fb
...@@ -19,84 +19,51 @@ public class YzgError { ...@@ -19,84 +19,51 @@ public class YzgError {
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", "长度参数为错误,必须大于0,此参数为[%s]"); error.add("015","length params is error, must be greater than 0, this params is [%s]");
error.add("016", "随机码,基本数据为空。"); 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","删除文件失败");
error.add("021", "文件%s不存在"); error.add("021","文件%s不存在");
error.add("022", "没有抛出异常"); error.add("022","没有抛出异常");
error.add("023", "监视错误"); error.add("023","监视错误");
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","下载失败");
error.add("046", "创建对象%s出错"); error.add("046","创建对象%s出错");
error.add("047", "不能识别模板"); error.add("047","不能识别模板");
error.add("048", "获取视频所缩类图失败:%s"); error.add("048","获取视频所缩类图失败:%s");
error.add("049", "没有找到%s的数据");
error.add("050", "地区编码不合法,长度不为9");
error.add("051", "地区编码不合法,长度大于9");
error.add("052", "获取百度接口日期失败");
error.add("053", "获取百度日期正则表达式失败");
error.add("054", "获取百度日期返回错误状态:%s");
error.add("055", "获取百度日期数据格式已修改");
error.add("056", "解密失败:%s");
error.add("057", "请配置yzg.upload.server");
error.add("058", "请配置yzg.upload.display");
error.add("059", "Cookies缺少[%s]");
error.add("060", "名称不能为空");
error.add("061", "请先登录");
error.add("062", "请上传文件");
error.add("063", "文件[%s]保存失败");
error.add("064", "文件[%s]不存在");
error.add("065", "文件[%s]是目录");
error.add("066", "请传入需要移动的文件");
error.add("067", "移动来源路径不能为空");
error.add("068", "移动目标路径不能为空");
error.add("069", "不能用文件 %s 覆盖文件夹 %s");
error.add("070", "移动文件 %s 到 %s 失败,原因:%s");
error.add("071", "来源文件不存在");
error.add("072", "来源文件不为视频");
error.add("073", "获取视频缩略图失败");
error.add("074", "请传入%s文件");
error.add("075", "文件夹不能包含两个.");
error.add("076", "文件夹不能包含\\u");
error.add("077", "队列 %s 不存在");
error.add("078", "交换器 %s 不存在");
error.add("079", "算法错误");
error.add("080", "当前队列没有消息");
error.add("081", "消息队列%s消息%s已经执行");
error.add("082", "请传入queue和messageId");
} }
......
...@@ -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);
......
...@@ -5,39 +5,56 @@ package com.yanzuoguang.util.exception; ...@@ -5,39 +5,56 @@ package com.yanzuoguang.util.exception;
* *
* @author 颜佐光 * @author 颜佐光
*/ */
public class HttpCodeException extends RuntimeException { public class HttpCodeException extends RuntimeCodeException {
private static final long serialVersionUID = -4625832188480820883L;
/**
* 错误码
*/
private String code = "99";
/** /**
* 包含的数据 * Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/ */
private Object target = null; public HttpCodeException(String code, String message, Throwable cause) {
super(code, message, cause);
}
/** /**
* 获取错误码 * 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
* *
* @return 返回的结果 * @param message  错误消息
* @param target  错误数据源,如订单数据
*/ */
public String getCode() { public HttpCodeException(String message, Object target) {
return this.code; super(message, target);
} }
/** /**
* 来源数据 * 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
* *
* @return * @param message  错误消息
* @param target  错误数据源,如订单数据
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/ */
public Object getTarget() { public HttpCodeException(String message, Object target, Throwable cause) {
return target; super(message, target, cause);
} }
/** /**
* 构造函数 * 构造函数
* throw new CodeException("01","该订单已过期",order); * throw new CodeException("01","该订单已过期",order);
...@@ -45,11 +62,10 @@ public class HttpCodeException extends RuntimeException { ...@@ -45,11 +62,10 @@ public class HttpCodeException extends RuntimeException {
* *
* @param code  错误码 * @param code  错误码
* @param message  错误消息 * @param message  错误消息
* @param target  错误数据源,如订单数据
*/ */
public HttpCodeException(String code, String message) { public HttpCodeException(String code, String message, Object target) {
super(message); super(code, message, target);
this.code = code;
this.target = null;
} }
/** /**
...@@ -66,8 +82,77 @@ public class HttpCodeException extends RuntimeException { ...@@ -66,8 +82,77 @@ public class HttpCodeException extends RuntimeException {
* unknown.) * unknown.)
*/ */
public HttpCodeException(String code, String message, Object target, Throwable cause) { public HttpCodeException(String code, String message, Object target, Throwable cause) {
super(code, message, target, cause);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public HttpCodeException(String message, Throwable cause) {
super(message, cause); super(message, cause);
this.code = code; }
this.target = target;
/**
* Constructs a new runtime exception with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
public HttpCodeException() {
super();
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public HttpCodeException(String code, String message) {
super(code, message);
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public HttpCodeException(String message) {
super(message);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public HttpCodeException(Throwable cause) {
super(cause);
} }
} }
...@@ -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());
} }
} }
} }
...@@ -1008,6 +1008,18 @@ public class StringHelper { ...@@ -1008,6 +1008,18 @@ public class StringHelper {
return getMD5Id(froms); return getMD5Id(froms);
} }
/**
* 获取组合编号
*
* @param args 需要组合的编号
* @return 将ID列表进行组合生成ID
*/
public static String getIdShort(String from, Object... args) {
String id = getId(args);
return from.replaceFirst(id + ":", "");
}
/** /**
* 获取组合编号 * 获取组合编号
* *
......
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());
} }
} }
......
...@@ -22,6 +22,11 @@ public class BaseVo implements Serializable { ...@@ -22,6 +22,11 @@ public class BaseVo implements Serializable {
*/ */
@Override @Override
public String toString() { public String toString() {
try {
return JsonHelper.serialize(this); return JsonHelper.serialize(this);
} catch (Exception ex) {
ex.printStackTrace();
return super.toString();
}
} }
} }
...@@ -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());
} }
} }
......
...@@ -63,11 +63,7 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem ...@@ -63,11 +63,7 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem
try { try {
if (ack && correlationData != null if (ack && correlationData != null
&& !StringHelper.isEmpty(correlationData.getId())) { && !StringHelper.isEmpty(correlationData.getId())) {
String toId = getId(correlationData.getId()); messageSendService.onSuccess(correlationData.getId());
// 不是临时数据
if (toId.equals(correlationData.getId())) {
messageSendService.onSuccess(toId);
}
} else if (!ack) { } else if (!ack) {
System.out.println("丢失消息:" + ack + " msg:" + cause); System.out.println("丢失消息:" + ack + " msg:" + cause);
} }
...@@ -94,15 +90,10 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem ...@@ -94,15 +90,10 @@ public class MqConfigurable implements RabbitTemplate.ConfirmCallback, RabbitTem
String content = new String(message.getBody(), charset); String content = new String(message.getBody(), charset);
// 组成消息 // 组成消息
MessageVo messageVo = new MessageVo(exchange, routingKey, content); MessageVo messageVo = new MessageVo(exchange, routingKey, content);
messageVo.setMessageId(getId(messageProperties.getMessageId()));
// 写入数据库 // 写入数据库
messageSendService.onError(messageVo); messageSendService.onError(messageVo);
} catch (Exception ex) { } catch (Exception ex) {
Log.error(MqConfigurable.class, ex); Log.error(MqConfigurable.class, ex);
} }
} }
private String getId(String from) {
return from.replace("temp:", "");
}
} }
...@@ -35,6 +35,8 @@ public class MessageLogDaoImpl extends BaseDaoImpl implements MessageLogDao, Ini ...@@ -35,6 +35,8 @@ public class MessageLogDaoImpl extends BaseDaoImpl implements MessageLogDao, Ini
*/ */
@Override @Override
protected void init() { protected void init() {
// 设置缓存3秒
cacheList.setClearSecond(3);
// 注册表结构 // 注册表结构
register(MessageLogVo.class); register(MessageLogVo.class);
} }
......
...@@ -32,6 +32,8 @@ import java.util.List; ...@@ -32,6 +32,8 @@ import java.util.List;
@Component @Component
public class MessageSendServiceImpl implements MessageSendService { public class MessageSendServiceImpl implements MessageSendService {
public static final String TEMP_ID = "temp";
@Autowired @Autowired
private MyRabbitTemplate rabbitTemplate; private MyRabbitTemplate rabbitTemplate;
...@@ -77,12 +79,11 @@ public class MessageSendServiceImpl implements MessageSendService { ...@@ -77,12 +79,11 @@ public class MessageSendServiceImpl implements MessageSendService {
@Override @Override
public String send(MessageVo req) { public String send(MessageVo req) {
req.check(); req.check();
// 获取消息临时Id // 获取消息临时Id,消息Id为空时标识为第一次发送,并设置默认消息Id
String finalMessageId = StringHelper.getFirst(req.getMessageId(), StringHelper.getId("temp", StringHelper.getNewID())); String finalMessageId = StringHelper.getFirst(req.getMessageId(), StringHelper.getId(TEMP_ID, StringHelper.getNewID()));
// 设置编号 // 设置编号
CorrelationData correlationData = new CorrelationData(); CorrelationData correlationData = new CorrelationData();
correlationData.setId(finalMessageId); correlationData.setId(finalMessageId);
rabbitTemplate.getRabbitTemplate().convertAndSend(req.getExchangeName(), req.getRouteKey(), req.getMessage(), new MessagePostProcessor() { rabbitTemplate.getRabbitTemplate().convertAndSend(req.getExchangeName(), req.getRouteKey(), req.getMessage(), new MessagePostProcessor() {
@Override @Override
public Message postProcessMessage(Message message) throws AmqpException { public Message postProcessMessage(Message message) throws AmqpException {
...@@ -91,8 +92,7 @@ public class MessageSendServiceImpl implements MessageSendService { ...@@ -91,8 +92,7 @@ public class MessageSendServiceImpl implements MessageSendService {
// 设置持久化 // 设置持久化
properties.setDeliveryMode(MessageDeliveryMode.PERSISTENT); properties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
// 设置消息编号 // 设置消息编号
properties.setMessageId(finalMessageId); properties.setMessageId(StringHelper.getIdShort(finalMessageId, TEMP_ID));
if (req.getDedTime() > 0) { if (req.getDedTime() > 0) {
properties.setExpiration(req.getDedTime() + ""); properties.setExpiration(req.getDedTime() + "");
} }
...@@ -109,10 +109,13 @@ public class MessageSendServiceImpl implements MessageSendService { ...@@ -109,10 +109,13 @@ public class MessageSendServiceImpl implements MessageSendService {
*/ */
@Override @Override
public String onSuccess(String messageId) { public String onSuccess(String messageId) {
if (!StringHelper.isEmpty(messageId)) { String toId = StringHelper.getIdShort(messageId, TEMP_ID);
messageDao.remove(messageId); // 不是临时数据
if (!toId.equals(messageId) || StringHelper.isEmpty(toId)) {
return StringHelper.EMPTY;
} }
return messageId; messageDao.remove(toId);
return toId;
} }
/** /**
...@@ -122,6 +125,7 @@ public class MessageSendServiceImpl implements MessageSendService { ...@@ -122,6 +125,7 @@ public class MessageSendServiceImpl implements MessageSendService {
*/ */
@Override @Override
public String onError(MessageVo messageVo) { public String onError(MessageVo messageVo) {
messageVo.setMessageId(StringHelper.getIdShort(messageVo.getMessageId(), TEMP_ID));
messageVo.check(); messageVo.check();
// 设置处理次数 // 设置处理次数
messageVo.setHandleCount(messageVo.getHandleCount() + 1); messageVo.setHandleCount(messageVo.getHandleCount() + 1);
......
...@@ -6,6 +6,7 @@ import com.yanzuoguang.mq.service.*; ...@@ -6,6 +6,7 @@ import com.yanzuoguang.mq.service.*;
import com.yanzuoguang.mq.vo.MessageVo; import com.yanzuoguang.mq.vo.MessageVo;
import com.yanzuoguang.mq.vo.QueueVo; import com.yanzuoguang.mq.vo.QueueVo;
import com.yanzuoguang.mq.vo.req.*; import com.yanzuoguang.mq.vo.req.*;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
...@@ -67,6 +68,13 @@ public class MqServiceImpl implements MqService { ...@@ -67,6 +68,13 @@ public class MqServiceImpl implements MqService {
@Override @Override
public String message(MessageVo req, boolean now) { public String message(MessageVo req, boolean now) {
req.check(); req.check();
// 设置默认消息Id
String defaultId = StringHelper.getFirst(req.getMessageId(), StringHelper.getNewID());
// 将Id去掉temp:
String simpleId = StringHelper.getId(MessageSendServiceImpl.TEMP_ID, StringHelper.getIdShort(defaultId, MessageSendServiceImpl.TEMP_ID));
// 增加temp标识第一次发送
req.setMessageId(simpleId);
return yzgMqProcedure.send(req, now); return yzgMqProcedure.send(req, now);
} }
......
...@@ -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