日志增加shopId,改动打印机,增加注册时默认四种支付方式

This commit is contained in:
liuyingfang
2024-03-13 10:57:00 +08:00
parent 2c5c32883d
commit 6568318806
11 changed files with 173 additions and 25 deletions

View File

@@ -17,10 +17,10 @@ package cn.ysk.cashier.aspect;
import cn.ysk.cashier.domain.Log;
import cn.ysk.cashier.service.LogService;
import cn.ysk.cashier.utils.RequestHolder;
import cn.ysk.cashier.utils.SecurityUtils;
import cn.ysk.cashier.utils.StringUtils;
import cn.ysk.cashier.utils.ThrowableUtil;
import cn.ysk.cashier.utils.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -28,6 +28,8 @@ import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
@@ -41,6 +43,9 @@ import javax.servlet.http.HttpServletRequest;
public class LogAspect {
private final LogService logService;
@Lazy
@Autowired
private RedisUtils redisUtils;
ThreadLocal<Long> currentTime = new ThreadLocal<>();
@@ -69,7 +74,16 @@ public class LogAspect {
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
currentTime.remove();
HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
Object o = redisUtils.get("online-token-"+getToken(request));
JSONObject jsonObject = null;
Integer shopId = null;
if (o!= null){
String jsonString = JSON.toJSONString(o);
jsonObject = JSONObject.parseObject(jsonString);
shopId = (Integer)jsonObject.get("shopId");
}
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log, shopId);
return result;
}
@@ -85,7 +99,15 @@ public class LogAspect {
currentTime.remove();
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
HttpServletRequest request = RequestHolder.getHttpServletRequest();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log);
Object o = redisUtils.get("online-token-"+getToken(request));
JSONObject jsonObject = null;
Integer shopId = null;
if (o!= null){
String jsonString = JSON.toJSONString(o);
jsonObject = JSONObject.parseObject(jsonString);
shopId = (Integer)jsonObject.get("shopId");
}
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log, shopId);
}
public String getUsername() {
@@ -95,4 +117,11 @@ public class LogAspect {
return "";
}
}
public String getToken(HttpServletRequest request) {
final String requestHeader = request.getHeader("Authorization");
if (requestHeader != null && requestHeader.startsWith("Bearer")) {
return requestHeader.substring(7);
}
return null;
}
}

View File

@@ -69,6 +69,8 @@ public class Log implements Serializable {
/** 异常详细 */
private byte[] exceptionDetail;
private Integer shopId;
/** 创建日期 */
@CreationTimestamp
private Timestamp createTime;

View File

@@ -63,7 +63,7 @@ public interface LogService {
* @param log 日志实体
*/
@Async
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log);
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log,Integer shopId);
/**
* 查询异常详情

View File

@@ -77,7 +77,7 @@ public class LogServiceImpl implements LogService {
@Override
@Transactional(rollbackFor = Exception.class)
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log) {
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log,Integer shopId) {
if (log == null) {
throw new IllegalArgumentException("Log 不能为 null!");
}
@@ -103,6 +103,7 @@ public class LogServiceImpl implements LogService {
log.setParams(JSONUtil.toJsonStr(Dict.create().set("username", log.getUsername())));
}
log.setBrowser(browser);
log.setShopId(shopId);
logRepository.save(log);
}