Commit 8fd6c941 authored by 张永's avatar 张永

V1.1.7.4

parent bf7aa1c1
......@@ -209,7 +209,7 @@
</executions>
<configuration>
<repository>dockerhub.linkfern.com/b2c/shopapi</repository>
<tag>V1.1.7.3</tag>
<tag>V1.1.7.4</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
......
......@@ -18,6 +18,7 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
......@@ -26,6 +27,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.egolm.common.DateUtil;
import com.egolm.common.GsonUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.shop.bean.TIdcServicesLogs;
......@@ -44,15 +46,17 @@ import com.egolm.shop.common.utils.ShopUtil;
@Component
public class IDCSystemLogAspect {
private static final Log logger = LogFactory.getLog(IDCSystemLogAspect.class);
@Autowired
@Qualifier("log")
private JdbcTemplate jdbcTemplate;
@Value("${server.shop.name:shop}")
private String serverShopName;
@Value("${server.shop.insert.idcsystemlog:false}")
private boolean isInsertLog;
@Value("${log.isOpen:false}")
private Boolean isInsertLog;
// 扫描使用@LogResource注解的方法
@Pointcut("@annotation(com.egolm.shop.common.component.IDCLogResource)")
......@@ -95,17 +99,25 @@ public class IDCSystemLogAspect {
@Async
void syncSaveLog(ProceedingJoinPoint joinPoint, Date startTime, Date endTime,
String exception, String result, int statusCode) {
TIdcServicesLogs log = new TIdcServicesLogs();
log.setsChannel(serverShopName);
//TIdcServicesLogs log = new TIdcServicesLogs();
Map<String,Object> logMap = new HashMap<String,Object>();
//log.setsChannel(serverShopName);
logMap.put("sChannel", serverShopName);
try {
//获取请求参数,不通过 joinPoint.getArgs() 获取。
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
if (request != null) {
log.setsUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
/* log.setsUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
log.setsHttpMethod(request.getMethod());
log.setsIp(ShopUtil.getIpAddress(request));
log.setsRequestText(GsonUtil.toJson(ShopUtil.getParameterMap(request)));
log.setsRequestText(GsonUtil.toJson(ShopUtil.getParameterMap(request)));*/
logMap.put("sUserAgent", request.getHeader(HttpHeaders.USER_AGENT));
logMap.put("sHttpMethod", request.getMethod());
logMap.put("sIp", ShopUtil.getIpAddress(request));
logMap.put("sRequestText", GsonUtil.toJson(ShopUtil.getParameterMap(request)));
}
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
......@@ -113,9 +125,9 @@ public class IDCSystemLogAspect {
IDCLogResource annotation = method.getAnnotation(IDCLogResource.class);
if (annotation != null) {
//注解上的描述
//log.setOperateName(annotation.name());
log.setsName(annotation.name());
System.out.println("--------------------"+annotation.name());
//log.setsName(annotation.name());
logMap.put("sName", annotation.name());
}
......@@ -123,16 +135,31 @@ public class IDCSystemLogAspect {
System.out.println("aop 获取目标方法所属类的简单类名 "+joinPoint.getSignature().getDeclaringType().getName());
System.out.println("aop 返回 "+result);*/
log.setsClassName(joinPoint.getSignature().getDeclaringType().getName());
/* log.setsClassName(joinPoint.getSignature().getDeclaringType().getName());
log.setsFunctionName(joinPoint.getSignature().getName());
log.setdStartTime(startTime);
log.setdEndTime(endTime);
log.setsCreateUser("aop");
log.setsCreateUser("aop");*/
logMap.put("sClassName", joinPoint.getSignature().getDeclaringType().getName());
logMap.put("sFunctionName", joinPoint.getSignature().getName());
logMap.put("dStartTime", startTime);
logMap.put("dEndTime", endTime);
logMap.put("sCreateUser", "aop");
//入参
Long cost = endTime.getTime() - startTime.getTime();
log.setnCost(cost.intValue());
log.setsResponseText(result);
jdbcTemplate.saveOrUpdate(log);
/* log.setnCost(cost.intValue());
log.setsResponseText(result);*/
logMap.put("nCost", cost.intValue());
logMap.put("sResponseText", result);
// jdbcTemplate.saveOrUpdate(log);
logMap.put("nTag", 0);
logMap.put("dCreateDate", new Date());
logMap.put("dLastUpdateTime", new Date());
String daytime = DateUtil.format(new Date(), DateUtil.FMTDATE); //当天日期
jdbcTemplate.save("tIdcServicesLogs_"+daytime, logMap);
} catch (Exception e) {
logger.info("aop 保存日志异常:",e);
}
......
......@@ -7,7 +7,6 @@ server.session.timeout=90000
server.tomcat.uri-encoding=utf-8
server.shop.name=shop
server.shop.insert.idcsystemlog=false
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
......@@ -38,7 +37,7 @@ spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000
spring.datasource.filters=stat,log4j
log.isOpen=false
log.isOpen=true
log.datasource.username=ERP
log.datasource.password=qiyang@2013
log.datasource.url=jdbc:mysql://10.10.0.21:3306/shopLog?useSSL=false&useUnicode=true&characterEncoding=utf8
......
......@@ -24,6 +24,8 @@
</head>
<body>
<div id="app">
<el-divider content-position="left">V1.1.7.4 2024-2-28</el-divider>
<p class="title">1.将日志写入mysql 的idcSystemLog,一天一表: idcSystemLog_yyyyMMdd</p>
<el-divider content-position="left">V1.1.7.3 2024-2-27</el-divider>
<p class="title">1.增加开关,是否写idcSystemLog表</p>
<el-divider content-position="left">V1.1.7.2 2024-1-29</el-divider>
......
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