diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml
index 408a33c..f6abbf6 100644
--- a/.idea/dataSources.local.xml
+++ b/.idea/dataSources.local.xml
@@ -5,7 +5,6 @@
#@
`
- true
master_key
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index ad50fd9..6dbb144 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -1,6 +1,7 @@
+
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 5afb336..ca22935 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -9,5 +9,6 @@
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a7c58c5..7389f7c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,15 +4,27 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
@@ -22,9 +34,9 @@
@@ -57,8 +69,10 @@
"RequestMappingsPanelWidth1": "75",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "master",
+ "jdk.selected.JAVA_MODULE": "corretto-17",
"last_opened_file_path": "G:/File/Java/spzx-parent/spzx-manager/src/main/resources/mapper",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
@@ -67,7 +81,7 @@
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
- "settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler",
+ "settings.editor.selected.configurable": "preferences.lookFeel",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
@@ -114,6 +128,7 @@
1702710124940
+
@@ -147,7 +162,15 @@
1702735339646
-
+
+
+ 1702737501213
+
+
+
+ 1702737501213
+
+
@@ -158,7 +181,9 @@
-
+
+
+
diff --git a/spzx-common/common-log/pom.xml b/spzx-common/common-log/pom.xml
new file mode 100644
index 0000000..567ef0b
--- /dev/null
+++ b/spzx-common/common-log/pom.xml
@@ -0,0 +1,46 @@
+
+
+ 4.0.0
+
+ cn.bunny
+ spzx-common
+ 1.0-SNAPSHOT
+
+
+ common-log
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ cn.bunny
+ spzx-model
+ 1.0-SNAPSHOT
+ provided
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ provided
+
+
+
+ cn.bunny
+ common-util
+ 1.0-SNAPSHOT
+
+
+
+
\ No newline at end of file
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/EnableLogAspect.java b/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/EnableLogAspect.java
new file mode 100644
index 0000000..a51ded6
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/EnableLogAspect.java
@@ -0,0 +1,15 @@
+package cn.bunny.log.annotation;
+
+import cn.bunny.log.aspect.LogAspect;
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Import(value = LogAspect.class)
+public @interface EnableLogAspect {
+}
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/Log.java b/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/Log.java
new file mode 100644
index 0000000..0fee901
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/annotation/Log.java
@@ -0,0 +1,20 @@
+package cn.bunny.log.annotation;
+
+
+import cn.bunny.log.enums.OperatorType;
+import org.apache.poi.ss.usermodel.DataValidationConstraint;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Log {
+ public String title() ; // 模块名称
+ public OperatorType operatorType() default OperatorType.MANAGE; // 操作人类别
+ public int businessType() ; // 业务类型(0其它 1新增 2修改 3删除)
+ public boolean isSaveRequestData() default true; // 是否保存请求的参数
+ public boolean isSaveResponseData() default true; // 是否保存响应的参数
+}
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/aspect/LogAspect.java b/spzx-common/common-log/src/main/java/cn/bunny/log/aspect/LogAspect.java
new file mode 100644
index 0000000..f8438bb
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/aspect/LogAspect.java
@@ -0,0 +1,40 @@
+package cn.bunny.log.aspect;
+
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
+import cn.bunny.log.annotation.Log;
+import cn.bunny.log.service.AsyncOperLogService;
+import cn.bunny.log.utils.LogUtils;
+import lombok.extern.log4j.Log4j2;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Aspect
+@Component
+@Log4j2
+public class LogAspect {
+ @Autowired
+ private AsyncOperLogService asyncOperLogService;
+
+ @Around(value = "@annotation(sysLog)")
+ public Object doAroundAdvice(ProceedingJoinPoint joinPoint, Log sysLog) {
+ SysOperLog sysOperLog = new SysOperLog();
+ LogUtils.beforeHandleLog(sysLog,joinPoint,sysOperLog);
+
+ Object proceed = null;
+ try {
+ proceed = joinPoint.proceed();
+ LogUtils.afterHandlLog(sysLog,proceed,sysOperLog,0,null);
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ LogUtils.afterHandlLog(sysLog, proceed, sysOperLog, 1, e.getMessage());
+ throw new RuntimeException();
+ }
+
+ asyncOperLogService.saveSysOperLog(sysOperLog);
+ return proceed;
+ }
+}
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/enums/OperatorType.java b/spzx-common/common-log/src/main/java/cn/bunny/log/enums/OperatorType.java
new file mode 100644
index 0000000..a2c61b1
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/enums/OperatorType.java
@@ -0,0 +1,7 @@
+package cn.bunny.log.enums;
+
+public enum OperatorType {
+ OTHER, // 其他
+ MANAGE, // 后台用户
+ MOBILE // 手机端用户
+}
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/service/AsyncOperLogService.java b/spzx-common/common-log/src/main/java/cn/bunny/log/service/AsyncOperLogService.java
new file mode 100644
index 0000000..690582d
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/service/AsyncOperLogService.java
@@ -0,0 +1,8 @@
+package cn.bunny.log.service;
+
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
+
+public interface AsyncOperLogService {
+ // 保存日志数据
+ public abstract void saveSysOperLog(SysOperLog sysOperLog) ;
+}
diff --git a/spzx-common/common-log/src/main/java/cn/bunny/log/utils/LogUtils.java b/spzx-common/common-log/src/main/java/cn/bunny/log/utils/LogUtils.java
new file mode 100644
index 0000000..ae21f82
--- /dev/null
+++ b/spzx-common/common-log/src/main/java/cn/bunny/log/utils/LogUtils.java
@@ -0,0 +1,61 @@
+package cn.bunny.log.utils;
+
+import cn.bunny.common.AuthContextUtil;
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
+import cn.bunny.log.annotation.Log;
+import com.alibaba.fastjson.JSON;
+import jakarta.servlet.http.HttpServletRequest;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.http.HttpMethod;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class LogUtils {
+ //操作执行之后调用
+ public static void afterHandlLog(Log sysLog, Object proceed,
+ SysOperLog sysOperLog, int status ,
+ String errorMsg) {
+ if(sysLog.isSaveResponseData()) {
+ sysOperLog.setJsonResult(JSON.toJSONString(proceed));
+ }
+ sysOperLog.setStatus(status);
+ sysOperLog.setErrorMsg(errorMsg);
+ }
+
+ //操作执行之前调用
+ public static void beforeHandleLog(Log sysLog,
+ ProceedingJoinPoint joinPoint,
+ SysOperLog sysOperLog) {
+
+ // 设置操作模块名称
+ sysOperLog.setTitle(sysLog.title());
+ sysOperLog.setOperatorType(sysLog.operatorType().name());
+
+ // 获取目标方法信息
+ MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature() ;
+ Method method = methodSignature.getMethod();
+ sysOperLog.setMethod(method.getDeclaringClass().getName());
+
+ // 获取请求相关参数
+ ServletRequestAttributes requestAttributes = (ServletRequestAttributes)
+ RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = requestAttributes.getRequest();
+ sysOperLog.setRequestMethod(request.getMethod());
+ sysOperLog.setOperUrl(request.getRequestURI());
+ sysOperLog.setOperIp(request.getRemoteAddr());
+
+ // 设置请求参数
+ if(sysLog.isSaveRequestData()) {
+ String requestMethod = sysOperLog.getRequestMethod();
+ if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
+ String params = Arrays.toString(joinPoint.getArgs());
+ sysOperLog.setOperParam(params);
+ }
+ }
+ sysOperLog.setOperName(AuthContextUtil.get().getUserName());
+ }
+}
diff --git a/spzx-common/pom.xml b/spzx-common/pom.xml
index 60059f3..a6919e7 100644
--- a/spzx-common/pom.xml
+++ b/spzx-common/pom.xml
@@ -14,6 +14,7 @@
common-util
common-service
+ common-log
diff --git a/spzx-manager/pom.xml b/spzx-manager/pom.xml
index 0433159..065178b 100644
--- a/spzx-manager/pom.xml
+++ b/spzx-manager/pom.xml
@@ -61,5 +61,12 @@
pagehelper-spring-boot-starter
1.4.3
+
+
+ cn.bunny
+ common-log
+ 1.0-SNAPSHOT
+
+
\ No newline at end of file
diff --git a/spzx-manager/src/main/java/cn/bunny/MangerApplication.java b/spzx-manager/src/main/java/cn/bunny/MangerApplication.java
index e4d73b3..a6e1970 100644
--- a/spzx-manager/src/main/java/cn/bunny/MangerApplication.java
+++ b/spzx-manager/src/main/java/cn/bunny/MangerApplication.java
@@ -1,5 +1,6 @@
package cn.bunny;
+import cn.bunny.log.annotation.EnableLogAspect;
import cn.bunny.properties.MinioProperties;
import cn.bunny.properties.UserProperties;
import org.springframework.boot.SpringApplication;
@@ -7,6 +8,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
+@EnableLogAspect
@SpringBootApplication
@EnableConfigurationProperties(value = {UserProperties.class, MinioProperties.class})
@EnableScheduling
diff --git a/spzx-manager/src/main/java/cn/bunny/controller/OrderInfoController.java b/spzx-manager/src/main/java/cn/bunny/controller/OrderInfoController.java
index d6fee27..d916a90 100644
--- a/spzx-manager/src/main/java/cn/bunny/controller/OrderInfoController.java
+++ b/spzx-manager/src/main/java/cn/bunny/controller/OrderInfoController.java
@@ -4,6 +4,7 @@ import cn.bunny.common.spzx.model.dto.order.OrderStatisticsDto;
import cn.bunny.common.spzx.model.vo.common.Result;
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
import cn.bunny.common.spzx.model.vo.order.OrderStatisticsVo;
+import cn.bunny.log.annotation.Log;
import cn.bunny.service.OrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -19,6 +20,7 @@ public class OrderInfoController {
@Autowired
private OrderInfoService orderInfoService;
+ @Log(title = "统计查询接口", businessType = 1)
@Operation(summary = "统计查询", description = "统计查询")
@GetMapping("getOrderStatisticsData")
public Result getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
diff --git a/spzx-manager/src/main/java/cn/bunny/mapper/SysOperLogMapper.java b/spzx-manager/src/main/java/cn/bunny/mapper/SysOperLogMapper.java
new file mode 100644
index 0000000..166c014
--- /dev/null
+++ b/spzx-manager/src/main/java/cn/bunny/mapper/SysOperLogMapper.java
@@ -0,0 +1,11 @@
+package cn.bunny.mapper;
+
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface SysOperLogMapper {
+ // 保存日志数据
+ public void insert(SysOperLog sysOperLog);
+}
+
diff --git a/spzx-manager/src/main/java/cn/bunny/service/CategoryBrandService.java b/spzx-manager/src/main/java/cn/bunny/service/CategoryBrandService.java
index 0f8b9ec..df32b8b 100644
--- a/spzx-manager/src/main/java/cn/bunny/service/CategoryBrandService.java
+++ b/spzx-manager/src/main/java/cn/bunny/service/CategoryBrandService.java
@@ -3,6 +3,7 @@ package cn.bunny.service;
import cn.bunny.common.spzx.model.dto.product.CategoryBrandDto;
import cn.bunny.common.spzx.model.entity.product.Brand;
import cn.bunny.common.spzx.model.entity.product.CategoryBrand;
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
import com.github.pagehelper.PageInfo;
import java.util.List;
@@ -22,4 +23,10 @@ public interface CategoryBrandService {
// 根据id查询对应商品数据
List findBrandByCategoryId(Long categoryId);
+
+ interface AsyncOperLogService {
+
+ // 保存日志数据
+ public abstract void saveSysOperLog(SysOperLog sysOperLog) ;
+ }
}
diff --git a/spzx-manager/src/main/java/cn/bunny/service/impl/AsyncOperLogServiceImpl.java b/spzx-manager/src/main/java/cn/bunny/service/impl/AsyncOperLogServiceImpl.java
new file mode 100644
index 0000000..03db5bc
--- /dev/null
+++ b/spzx-manager/src/main/java/cn/bunny/service/impl/AsyncOperLogServiceImpl.java
@@ -0,0 +1,20 @@
+package cn.bunny.service.impl;
+
+import cn.bunny.common.spzx.model.entity.system.SysOperLog;
+import cn.bunny.log.service.AsyncOperLogService;
+import cn.bunny.mapper.SysOperLogMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AsyncOperLogServiceImpl implements AsyncOperLogService {
+ @Autowired
+ private SysOperLogMapper sysOperLogMapper;
+
+
+ // 保存日志数据
+ @Override
+ public void saveSysOperLog(SysOperLog sysOperLog) {
+ sysOperLogMapper.insert(sysOperLog);
+ }
+}
diff --git a/spzx-manager/src/main/resources/mapper/log/SysOperLogMapper.xml b/spzx-manager/src/main/resources/mapper/log/SysOperLogMapper.xml
new file mode 100644
index 0000000..acecd09
--- /dev/null
+++ b/spzx-manager/src/main/resources/mapper/log/SysOperLogMapper.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+ insert into sys_oper_log (
+ id,
+ title,
+ method,
+ request_method,
+ operator_type,
+ oper_name,
+ oper_url,
+ oper_ip,
+ oper_param,
+ json_result,
+ status,
+ error_msg
+ ) values (
+ #{id},
+ #{title},
+ #{method},
+ #{requestMethod},
+ #{operatorType},
+ #{operName},
+ #{operUrl},
+ #{operIp},
+ #{operParam},
+ #{jsonResult},
+ #{status},
+ #{errorMsg}
+ )
+
+