From a27f64dafaa77015f2631bda312684a68b3825c3 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Tue, 24 Sep 2024 09:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=8F=8D?= =?UTF-8?q?=E6=89=93=E5=AE=9E=E7=8E=B0=EF=BC=8C=E9=81=BF=E5=85=8D=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A0=86=E6=A0=88=E4=BF=A1=E6=81=AF=E8=BF=87=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbCallTable.java | 48 ++++++++++++++- .../exception/GlobalExceptionHandler.java | 10 ++++ .../system/cashierservice/util/Utils.java | 58 ++++++++++++++++--- 3 files changed, 107 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java index af53a04..9d6a6f3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java @@ -8,7 +8,7 @@ import java.io.Serializable; import java.util.Date; /** - * + * 叫号桌型表 * @TableName tb_call_table */ @TableName(value ="tb_call_table") @@ -74,6 +74,16 @@ public class TbCallTable implements Serializable { */ private Date updateTime; + /** + * 顺延号码数量 + */ + private Integer isPostpone; + + /** + * 顺延号码数量 + */ + private Integer postponeNum; + @TableField(exist = false) private static final long serialVersionUID = 1L; @@ -245,6 +255,34 @@ public class TbCallTable implements Serializable { this.updateTime = updateTime; } + /** + * 顺延号码数量 + */ + public Integer getIsPostpone() { + return isPostpone; + } + + /** + * 顺延号码数量 + */ + public void setIsPostpone(Integer isPostpone) { + this.isPostpone = isPostpone; + } + + /** + * 顺延号码数量 + */ + public Integer getPostponeNum() { + return postponeNum; + } + + /** + * 顺延号码数量 + */ + public void setPostponeNum(Integer postponeNum) { + this.postponeNum = postponeNum; + } + @Override public boolean equals(Object that) { if (this == that) { @@ -268,7 +306,9 @@ public class TbCallTable implements Serializable { && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) && (this.getQrcode() == null ? other.getQrcode() == null : this.getQrcode().equals(other.getQrcode())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) - && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) + && (this.getIsPostpone() == null ? other.getIsPostpone() == null : this.getIsPostpone().equals(other.getIsPostpone())) + && (this.getPostponeNum() == null ? other.getPostponeNum() == null : this.getPostponeNum().equals(other.getPostponeNum())); } @Override @@ -287,6 +327,8 @@ public class TbCallTable implements Serializable { result = prime * result + ((getQrcode() == null) ? 0 : getQrcode().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + result = prime * result + ((getIsPostpone() == null) ? 0 : getIsPostpone().hashCode()); + result = prime * result + ((getPostponeNum() == null) ? 0 : getPostponeNum().hashCode()); return result; } @@ -308,6 +350,8 @@ public class TbCallTable implements Serializable { sb.append(", qrcode=").append(qrcode); sb.append(", createTime=").append(createTime); sb.append(", updateTime=").append(updateTime); + sb.append(", isPostpone=").append(isPostpone); + sb.append(", postponeNum=").append(postponeNum); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); return sb.toString(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/GlobalExceptionHandler.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/GlobalExceptionHandler.java index 4a9e39c..eda7f7f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.exception; import com.chaozhanggui.system.cashierservice.sign.Result; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody; * ControllerAdvice注解的含义是当异常抛到controller层时会拦截下来 */ @ControllerAdvice +@Slf4j public class GlobalExceptionHandler { /** @@ -26,6 +28,14 @@ public class GlobalExceptionHandler { return Result.fail("系统内部错误"); } + @ResponseBody + @ExceptionHandler(NotPrintException.class) + public Result exceptionNotPrint(Exception e) { + log.warn("获取到不打印堆栈异常, 异常信息: {}", e.getMessage()); + // 返回错误格式信息 + return Result.fail(e.getMessage()); + } + /** * 使用ExceptionHandler注解声明处理TestException异常 * diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java index c15a1d7..e5b9bf9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java @@ -21,7 +21,7 @@ public class Utils { public static void catchErrNoReturn(Supplier supplier) { try { supplier.get(); - }catch (Exception e) { + } catch (Exception e) { log.error("执行方法出现异常", e); } } @@ -47,8 +47,8 @@ public class Utils { } } - public static T runFunAndCheckKey(Supplier supplier, StringRedisTemplate redisTemplate, String lockKey) { - try{ + public static T runFunAndCheckKey(Supplier supplier, StringRedisTemplate redisTemplate, String lockKey) { + try { // 创建线程id, 用作判断 String clientId = UUID.randomUUID().toString(); // 设置分布式锁 @@ -62,12 +62,12 @@ public class Utils { lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS)); } return supplier.get(); - } catch (RuntimeException e){ + } catch (RuntimeException e) { log.info("执行出错:{}", e.getMessage()); throw e; } catch (InterruptedException e) { throw new RuntimeException(e); - } finally{ + } finally { redisTemplate.delete(lockKey); } } @@ -110,11 +110,11 @@ public class Utils { } public static void checkValueUnReturn(Object data, String msg, Func0... errFunc) { - if(data == null) { + if (data == null) { throw new MsgException(msg); } - if (data instanceof String && StrUtil.isBlank((String)data)) { + if (data instanceof String && StrUtil.isBlank((String) data)) { throw new MsgException(msg); } if (ObjectUtil.isEmpty(data)) { @@ -128,4 +128,48 @@ public class Utils { throw new MsgException(msg); } } + + public static void doPrintStack(Throwable t, int stackDepth, StringBuilder sb) { + StackTraceElement[] stackTraceElements = t.getStackTrace(); + if (sb.lastIndexOf("\t") > -1) { + sb.deleteCharAt(sb.length() - 1); + sb.append("Caused: "); + } + sb.append(t.getClass().getName()).append(": ").append(t.getMessage()).append("\n\t"); + for (int i = 0; i < stackDepth; ++i) { + if (i >= stackTraceElements.length) { + break; + } + StackTraceElement element = stackTraceElements[i]; + sb.append(element.getClassName()).append("#").append(element.getMethodName()).append(":").append(element.getLineNumber()).append("\n\t"); + } + } + + /** + * 递归逆向打印堆栈及cause(即从最底层的异常开始往上打) + * @param t 原始异常 * + * @param causeDepth 需要递归打印的cause的最大深度 * + * @param counter 当前打印的cause的深度计数器(这里必须用引用类型,如果用基本数据类型,你对计数器的修改只能对当前栈帧可见,但是这个计数器,又必须在所有栈帧中可见,所以只能用引用类型) * + * @param stackDepth 每一个异常栈的打印深度 * + * @param sb 字符串构造器 + */ + public static void recursiveReversePrintStackCause(Throwable t, int causeDepth, ForwardCounter counter, int stackDepth, StringBuilder sb) { + if (t == null) { + return; + } + if (t.getCause() != null) { + recursiveReversePrintStackCause(t.getCause(), causeDepth, counter, stackDepth, sb); + } + if (counter.i++ < causeDepth) { + doPrintStack(t, stackDepth, sb); + } + } + + public static class ForwardCounter { + private Integer i; + + public ForwardCounter(Integer i) { + this.i = i; + } + } }