mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
feat: 操作日志模块(代码+SQL)
- 新增 @OperLog 注解,标记需记录的方法 - 新增 OperLogAspect AOP 切面,自动记录操作日志 - 新增 sys_oper_log 表结构 - 支持异步记录,不阻塞主流程 - application.yml 启用 @EnableAsync
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
## 阶段四:功能补充
|
## 阶段四:功能补充
|
||||||
|
|
||||||
- [ ] 4.1 公司概览 Dashboard 页面(KPI 卡片:销售额/单量/ROI/环比增长)
|
- [x] 4.1 公司概览 Dashboard 页面 ✅ 已存在,添加导出按钮完成 2026-03-26
|
||||||
- [ ] 4.2 操作日志表 + AOP 记录(谁在什么时间改了啥)
|
- [ ] 4.2 操作日志表 + AOP 记录(谁在什么时间改了啥)
|
||||||
- [ ] 4.3 店铺月目标管理页面完善(前端入口 + CRUD)
|
- [ ] 4.3 店铺月目标管理页面完善(前端入口 + CRUD)
|
||||||
- [ ] 4.4 前端各模块入口检查(config、order-status 等是否有遗漏)
|
- [ ] 4.4 前端各模块入口检查(config、order-status 等是否有遗漏)
|
||||||
@@ -45,9 +45,9 @@
|
|||||||
## 阶段五:基础设施
|
## 阶段五:基础设施
|
||||||
|
|
||||||
- [x] 5.1 Redis 超时配置修复(timeout vs leftPop 等待时间对齐) ✅ 2026-03-26 注释已修正
|
- [x] 5.1 Redis 超时配置修复(timeout vs leftPop 等待时间对齐) ✅ 2026-03-26 注释已修正
|
||||||
- [ ] 5.2 后端 README 完善(启动方式、环境变量、依赖说明)
|
- [x] 5.2 后端 README 完善(启动方式、环境变量、依赖说明)✅ 2026-03-26
|
||||||
- [ ] 5.3 前端 README 完善
|
- [x] 5.3 前端 README 完善 ✅ 2026-03-26
|
||||||
- [ ] 5.4 制定 MySQL 数据备份策略
|
- [x] 5.4 制定 MySQL 数据备份策略 ✅ 2026-03-26 scripts/backup.sh
|
||||||
- [ ] 5.5 后端单元测试(重点:盈亏/ROI/税费计算逻辑)
|
- [ ] 5.5 后端单元测试(重点:盈亏/ROI/税费计算逻辑)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+74
-164
@@ -1,179 +1,89 @@
|
|||||||
# AH-GF-Backend
|
# ecom-dmb-backend
|
||||||
|
|
||||||
AH-GF-Backend 是一个基于 Spring Boot 3.x + MyBatis Plus + Spring Security + JWT 的后端服务项目。
|
电商 DMB 后端服务
|
||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
|
|
||||||
- **Spring Boot 3.2.3** - 主框架
|
- Java 17 + Spring Boot 3.2
|
||||||
- **MyBatis Plus 3.5.5** - ORM框架
|
- MyBatis-Plus + MySQL
|
||||||
- **Spring Security** - 安全框架
|
- Redis(消息队列 + 缓存)
|
||||||
- **JWT** - 身份认证
|
- JWT 认证(HS512)
|
||||||
- **MySQL** - 数据库
|
- Knife4j API 文档
|
||||||
- **Knife4j** - API文档
|
- Lombok + MapStruct
|
||||||
- **Lombok** - 代码简化
|
|
||||||
- **Maven** - 构建工具
|
## 环境要求
|
||||||
|
|
||||||
|
- JDK 17+
|
||||||
|
- MySQL 8.0+
|
||||||
|
- Redis 6.0+
|
||||||
|
- Maven 3.9+
|
||||||
|
|
||||||
|
## 快速启动
|
||||||
|
|
||||||
|
### 1. 配置环境变量(生产环境必须)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export DB_URL="jdbc:mysql://<host>:3306/ecom_dmb_dev?characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true"
|
||||||
|
export DB_USERNAME="ecom_dmb_dev"
|
||||||
|
export DB_PASSWORD="<your-db-password>"
|
||||||
|
export REDIS_HOST="<your-redis-host>"
|
||||||
|
export REDIS_PORT="6379"
|
||||||
|
export REDIS_PASSWORD="<your-redis-password>"
|
||||||
|
export JWT_SECRET="<your-64-byte-secret-key>"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd ecom-dmb-backend
|
||||||
|
./mvnw spring-boot:run
|
||||||
|
```
|
||||||
|
|
||||||
|
或指定端口:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./mvnw spring-boot:run -Dspring-boot.run.arguments="--server.port=8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 接口文档
|
||||||
|
|
||||||
|
启动后访问:http://localhost:8080/doc.html
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
src/main/java/top/xyquan/ahgfbackend/
|
ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/
|
||||||
├── AhGfBackendApplication.java # 启动类
|
├── common/ # 通用组件(异常、响应、注解、过滤器)
|
||||||
├── common/ # 公共模块
|
├── modules/
|
||||||
│ ├── exception/ # 异常处理
|
│ ├── ecom/ # 电商核心模块
|
||||||
│ ├── model/ # 公共模型
|
│ │ ├── overview/ # 概览统计(含导出)
|
||||||
│ └── response/ # 响应封装
|
│ │ ├── order/ # 订单管理
|
||||||
├── config/ # 配置类
|
│ │ ├── product/ # 商品管理
|
||||||
├── modules/ # 业务模块
|
│ │ ├── shop/ # 店铺管理
|
||||||
│ ├── sys/ # 系统模块
|
│ │ ├── promotion/ # 推广费管理
|
||||||
│ │ ├── controller/ # 控制器
|
│ │ ├── Brushorder/ # 刷单管理
|
||||||
│ │ ├── mapper/ # 数据访问层
|
│ │ └── importtask/ # 导入任务(Redis 队列)
|
||||||
│ │ ├── model/ # 数据模型
|
│ └── sys/ # 系统模块(用户、菜单、权限)
|
||||||
│ │ │ ├── dto/ # 数据传输对象
|
└── utils/ # 工具类
|
||||||
│ │ │ ├── po/ # 持久化对象
|
|
||||||
│ │ │ └── vo/ # 视图对象
|
|
||||||
│ │ └── service/ # 业务逻辑层
|
|
||||||
│ └── org/ # 组织模块
|
|
||||||
└── utils/ # 工具类
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 功能特性
|
## 核心接口
|
||||||
|
|
||||||
### 用户认证模块
|
| 模块 | 路径 | 说明 |
|
||||||
|
|------|------|------|
|
||||||
|
| 公司概览 | POST /ec/company-overview/statistics | 全店铺汇总统计 |
|
||||||
|
| 公司概览导出 | POST /ec/company-overview/export | Excel 导出 |
|
||||||
|
| 店铺概览 | POST /ec/shop/overview-statistics | 单店铺统计 |
|
||||||
|
| 店铺导出 | POST /ec/shop/export-overview | Excel 导出 |
|
||||||
|
| 订单 | /ec/order/* | CRUD |
|
||||||
|
| 推广费 | /ec/promotion-fee/* | CRUD |
|
||||||
|
| 刷单 | /ec/brush-order/* | CRUD |
|
||||||
|
| 商品 | /ec/product/* | CRUD |
|
||||||
|
|
||||||
1. **用户注册**
|
## 数据库
|
||||||
- 支持通过登录账号或手机号码注册
|
|
||||||
- 密码加密存储
|
|
||||||
- 自动生成JWT令牌
|
|
||||||
|
|
||||||
2. **用户登录**
|
连接信息通过环境变量配置,参考 application.yml 中的 `DB_*` 前缀。
|
||||||
- 支持通过登录账号或手机号码登录
|
|
||||||
- 密码验证
|
|
||||||
- 返回JWT令牌和用户信息
|
|
||||||
|
|
||||||
3. **安全特性**
|
## 数据备份
|
||||||
- 密码BCrypt加密
|
|
||||||
- JWT令牌认证
|
|
||||||
- 全局异常处理
|
|
||||||
- 参数验证
|
|
||||||
|
|
||||||
## API接口
|
参见项目根目录 `scripts/backup.sh`
|
||||||
|
|
||||||
### 认证接口
|
|
||||||
|
|
||||||
#### 用户注册
|
|
||||||
- **URL**: `POST /api/auth/register`
|
|
||||||
- **请求体**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"loginCode": "用户名",
|
|
||||||
"phone": "手机号码",
|
|
||||||
"password": "密码"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- **说明**: loginCode和phone至少填写一个
|
|
||||||
|
|
||||||
#### 用户登录
|
|
||||||
- **URL**: `POST /api/auth/login`
|
|
||||||
- **请求体**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"account": "登录账号或手机号码",
|
|
||||||
"password": "密码"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 数据库设计
|
|
||||||
|
|
||||||
### sys_user 表
|
|
||||||
|
|
||||||
用户表包含以下主要字段:
|
|
||||||
- `id`: 用户编号
|
|
||||||
- `login_code`: 登录账号
|
|
||||||
- `phone`: 手机号码
|
|
||||||
- `password`: 登录密码(加密存储)
|
|
||||||
- `real_name`: 用户名称
|
|
||||||
- `role`: 用户角色
|
|
||||||
- `status`: 用户状态
|
|
||||||
- `create_time`: 创建时间
|
|
||||||
- `update_time`: 更新时间
|
|
||||||
|
|
||||||
## 配置说明
|
|
||||||
|
|
||||||
### 数据库配置
|
|
||||||
在 `application.yml` 中配置数据库连接信息:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
url: jdbc:mysql://localhost:3306/your_database
|
|
||||||
username: your_username
|
|
||||||
password: your_password
|
|
||||||
```
|
|
||||||
|
|
||||||
### JWT配置
|
|
||||||
```yaml
|
|
||||||
jwt:
|
|
||||||
secret: your-secret-key
|
|
||||||
expiration: 86400
|
|
||||||
```
|
|
||||||
|
|
||||||
## 启动项目
|
|
||||||
|
|
||||||
1. **克隆项目**
|
|
||||||
```bash
|
|
||||||
git clone <repository-url>
|
|
||||||
cd ah-gf-backend
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **配置数据库**
|
|
||||||
- 创建数据库
|
|
||||||
- 执行SQL脚本创建表
|
|
||||||
- 修改 `application.yml` 中的数据库配置
|
|
||||||
|
|
||||||
3. **启动项目**
|
|
||||||
```bash
|
|
||||||
mvn spring-boot:run
|
|
||||||
```
|
|
||||||
|
|
||||||
4. **访问API文档**
|
|
||||||
- 浏览器访问: `http://localhost:8080/doc.html`
|
|
||||||
|
|
||||||
## 开发规范
|
|
||||||
|
|
||||||
1. **代码规范**
|
|
||||||
- 遵循阿里巴巴Java开发手册
|
|
||||||
- 使用Lombok简化代码
|
|
||||||
- 统一异常处理
|
|
||||||
|
|
||||||
2. **架构设计**
|
|
||||||
- 模块化设计
|
|
||||||
- 分层架构(Controller -> Service -> Mapper)
|
|
||||||
- 单一职责原则
|
|
||||||
|
|
||||||
3. **安全规范**
|
|
||||||
- 密码加密存储
|
|
||||||
- JWT令牌认证
|
|
||||||
- 参数验证
|
|
||||||
|
|
||||||
## 测试
|
|
||||||
|
|
||||||
运行测试用例:
|
|
||||||
```bash
|
|
||||||
mvn test
|
|
||||||
```
|
|
||||||
|
|
||||||
## 部署
|
|
||||||
|
|
||||||
1. **打包**
|
|
||||||
```bash
|
|
||||||
mvn clean package
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **运行**
|
|
||||||
```bash
|
|
||||||
java -jar target/ah-gf-backend-0.0.1-SNAPSHOT.jar
|
|
||||||
```
|
|
||||||
|
|
||||||
## 许可证
|
|
||||||
|
|
||||||
MIT License
|
|
||||||
|
|||||||
+2
@@ -3,8 +3,10 @@ package top.xyquan.ecomdmbbackend;
|
|||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableAsync
|
||||||
@MapperScan({
|
@MapperScan({
|
||||||
"top.xyquan.ecomdmbbackend.modules.*.mapper",
|
"top.xyquan.ecomdmbbackend.modules.*.mapper",
|
||||||
"top.xyquan.ecomdmbbackend.modules.*.*.mapper"
|
"top.xyquan.ecomdmbbackend.modules.*.*.mapper"
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志注解
|
||||||
|
* 标注在 Controller 方法上,自动记录操作日志
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface OperLog {
|
||||||
|
|
||||||
|
/** 模块名称,如"店铺管理"、"订单管理" */
|
||||||
|
String module() default "";
|
||||||
|
|
||||||
|
/** 操作类型 */
|
||||||
|
OperType type() default OperType.QUERY;
|
||||||
|
|
||||||
|
/** 操作描述,如"创建店铺"、"更新订单" */
|
||||||
|
String description() default "";
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.annotation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作类型枚举
|
||||||
|
*/
|
||||||
|
public enum OperType {
|
||||||
|
QUERY("查询"),
|
||||||
|
CREATE("新增"),
|
||||||
|
UPDATE("更新"),
|
||||||
|
DELETE("删除"),
|
||||||
|
EXPORT("导出"),
|
||||||
|
IMPORT("导入"),
|
||||||
|
OTHER("其他");
|
||||||
|
|
||||||
|
private final String label;
|
||||||
|
|
||||||
|
OperType(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
}
|
||||||
+178
@@ -0,0 +1,178 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.aspect;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.annotation.OperLog;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.model.po.SysOperLogPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.service.SysOperLogService;
|
||||||
|
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志 AOP 切面
|
||||||
|
* 自动拦截标注了 @OperLog 的 Controller 方法,记录操作日志
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class OperLogAspect {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(OperLogAspect.class);
|
||||||
|
private static final int MAX_PARAMS_LEN = 2000;
|
||||||
|
|
||||||
|
private final SysOperLogService sysOperLogService;
|
||||||
|
private final CurrentUserContext currentUserContext;
|
||||||
|
|
||||||
|
public OperLogAspect(SysOperLogService sysOperLogService, CurrentUserContext currentUserContext) {
|
||||||
|
this.sysOperLogService = sysOperLogService;
|
||||||
|
this.currentUserContext = currentUserContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("@annotation(top.xyquan.ecomdmbbackend.modules.sys.operlog.annotation.OperLog)")
|
||||||
|
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// 获取注解
|
||||||
|
MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
OperLog operLog = method.getAnnotation(OperLog.class);
|
||||||
|
|
||||||
|
// 获取请求信息
|
||||||
|
HttpServletRequest request = getRequest();
|
||||||
|
String ip = request != null ? getIpAddress(request) : "unknown";
|
||||||
|
String url = request != null ? request.getRequestURI() : "";
|
||||||
|
String methodName = point.getTarget().getClass().getName() + "." + method.getName();
|
||||||
|
|
||||||
|
// 获取请求参数
|
||||||
|
String params = getParams(point);
|
||||||
|
|
||||||
|
// 执行目标方法
|
||||||
|
Object result = null;
|
||||||
|
String errorMsg = null;
|
||||||
|
String resultStatus = "success";
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = point.proceed();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
resultStatus = "fail";
|
||||||
|
errorMsg = e.getMessage();
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
long duration = System.currentTimeMillis() - startTime;
|
||||||
|
|
||||||
|
// 异步记录日志
|
||||||
|
try {
|
||||||
|
SysOperLogPO logPO = new SysOperLogPO();
|
||||||
|
logPO.setCompanyId(getCompanyIdSafely());
|
||||||
|
logPO.setUserId(getUserIdSafely());
|
||||||
|
logPO.setUsername(getUsernameSafely());
|
||||||
|
logPO.setModule(operLog.module());
|
||||||
|
logPO.setOperType(operLog.type().getLabel());
|
||||||
|
logPO.setDescription(operLog.description());
|
||||||
|
logPO.setMethod(methodName);
|
||||||
|
logPO.setUrl(url);
|
||||||
|
logPO.setParams(params.length() > MAX_PARAMS_LEN ? params.substring(0, MAX_PARAMS_LEN) : params);
|
||||||
|
logPO.setDuration(duration);
|
||||||
|
logPO.setIp(ip);
|
||||||
|
logPO.setResult(resultStatus);
|
||||||
|
logPO.setErrorMsg(errorMsg != null && errorMsg.length() > 500 ? errorMsg.substring(0, 500) : errorMsg);
|
||||||
|
logPO.setOperateTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
sysOperLogService.saveLog(logPO);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("保存操作日志失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpServletRequest getRequest() {
|
||||||
|
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
return attrs != null ? attrs.getRequest() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getCompanyIdSafely() {
|
||||||
|
try {
|
||||||
|
return currentUserContext.getCurrentCompanyId();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long getUserIdSafely() {
|
||||||
|
try {
|
||||||
|
return currentUserContext.getCurrentUserId();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUsernameSafely() {
|
||||||
|
try {
|
||||||
|
return String.valueOf(currentUserContext.getCurrentUserId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getParams(ProceedingJoinPoint point) {
|
||||||
|
try {
|
||||||
|
Object[] args = point.getArgs();
|
||||||
|
if (args == null || args.length == 0) return "";
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Object arg : args) {
|
||||||
|
if (arg == null) continue;
|
||||||
|
// 跳过 HttpServletRequest/Response 等非业务参数
|
||||||
|
String className = arg.getClass().getName();
|
||||||
|
if (className.startsWith("jakarta.servlet") || className.startsWith("javax.servlet")) continue;
|
||||||
|
if (arg instanceof org.springframework.web.multipart.MultipartFile) continue;
|
||||||
|
try {
|
||||||
|
sb.append(",").append(arg.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
sb.append(",[unserializable]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.length() > 0 ? sb.substring(1) : "";
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getIpAddress(HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
String[] headers = {
|
||||||
|
"X-Forwarded-For",
|
||||||
|
"Proxy-Client-IP",
|
||||||
|
"WL-Proxy-Client-IP",
|
||||||
|
"HTTP_X_FORWARDED_FOR",
|
||||||
|
"HTTP_X_FORWARDED",
|
||||||
|
"HTTP_X_CLUSTER_CLIENT_IP",
|
||||||
|
"HTTP_CLIENT_IP",
|
||||||
|
"HTTP_FORWARDED_FOR",
|
||||||
|
"HTTP_FORWARDED",
|
||||||
|
"HTTP_VIA",
|
||||||
|
"REMOTE_ADDR"
|
||||||
|
};
|
||||||
|
for (String header : headers) {
|
||||||
|
String ip = request.getHeader(header);
|
||||||
|
if (ip != null && !ip.isEmpty() && !"unknown".equalsIgnoreCase(ip)) {
|
||||||
|
return ip.split(",")[0].trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return request.getRemoteAddr();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.model.po.SysOperLogPO;
|
||||||
|
|
||||||
|
public interface SysOperLogMapper extends BaseMapper<SysOperLogPO> {
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志实体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("sys_oper_log")
|
||||||
|
public class SysOperLogPO {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 公司ID */
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
/** 用户ID */
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/** 用户名 */
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/** 模块名称 */
|
||||||
|
private String module;
|
||||||
|
|
||||||
|
/** 操作类型 */
|
||||||
|
private String operType;
|
||||||
|
|
||||||
|
/** 操作描述 */
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/** 请求方法 */
|
||||||
|
private String method;
|
||||||
|
|
||||||
|
/** 请求路径 */
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/** 请求参数(JSON 截断) */
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
/** 执行时长(毫秒) */
|
||||||
|
private Long duration;
|
||||||
|
|
||||||
|
/** IP 地址 */
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/** 操作结果:success / fail */
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
/** 错误信息 */
|
||||||
|
private String errorMsg;
|
||||||
|
|
||||||
|
/** 操作时间 */
|
||||||
|
private LocalDateTime operateTime;
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.model.po.SysOperLogPO;
|
||||||
|
|
||||||
|
public interface SysOperLogService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存操作日志
|
||||||
|
*/
|
||||||
|
void saveLog(SysOperLogPO logPO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询日志
|
||||||
|
*/
|
||||||
|
Page<SysOperLogPO> pageQuery(Long companyId, int page, int size, String module, String operType);
|
||||||
|
}
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.sys.operlog.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.mapper.SysOperLogMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.model.po.SysOperLogPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.sys.operlog.service.SysOperLogService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SysOperLogServiceImpl implements SysOperLogService {
|
||||||
|
|
||||||
|
private final SysOperLogMapper sysOperLogMapper;
|
||||||
|
|
||||||
|
public SysOperLogServiceImpl(SysOperLogMapper sysOperLogMapper) {
|
||||||
|
this.sysOperLogMapper = sysOperLogMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Async
|
||||||
|
public void saveLog(SysOperLogPO logPO) {
|
||||||
|
sysOperLogMapper.insert(logPO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SysOperLogPO> pageQuery(Long companyId, int page, int size, String module, String operType) {
|
||||||
|
LambdaQueryWrapper<SysOperLogPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(SysOperLogPO::getCompanyId, companyId)
|
||||||
|
.orderByDesc(SysOperLogPO::getOperateTime);
|
||||||
|
|
||||||
|
if (module != null && !module.isBlank()) {
|
||||||
|
wrapper.like(SysOperLogPO::getModule, module);
|
||||||
|
}
|
||||||
|
if (operType != null && !operType.isBlank()) {
|
||||||
|
wrapper.eq(SysOperLogPO::getOperType, operType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sysOperLogMapper.selectPage(new Page<>(page, size), wrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
-- 操作日志表
|
||||||
|
CREATE TABLE IF NOT EXISTS `sys_oper_log` (
|
||||||
|
`id` BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
|
||||||
|
`company_id` BIGINT DEFAULT NULL COMMENT '公司ID',
|
||||||
|
`user_id` BIGINT DEFAULT NULL COMMENT '用户ID',
|
||||||
|
`username` VARCHAR(100) DEFAULT NULL COMMENT '用户名',
|
||||||
|
`module` VARCHAR(100) DEFAULT NULL COMMENT '模块名称',
|
||||||
|
`oper_type` VARCHAR(20) DEFAULT NULL COMMENT '操作类型',
|
||||||
|
`description` VARCHAR(500) DEFAULT NULL COMMENT '操作描述',
|
||||||
|
`method` VARCHAR(500) DEFAULT NULL COMMENT '请求方法',
|
||||||
|
`url` VARCHAR(500) DEFAULT NULL COMMENT '请求路径',
|
||||||
|
`params` TEXT COMMENT '请求参数',
|
||||||
|
`duration` BIGINT DEFAULT NULL COMMENT '执行时长(ms)',
|
||||||
|
`ip` VARCHAR(50) DEFAULT NULL COMMENT 'IP地址',
|
||||||
|
`result` VARCHAR(20) DEFAULT NULL COMMENT '操作结果(success/fail)',
|
||||||
|
`error_msg` VARCHAR(1000) DEFAULT NULL COMMENT '错误信息',
|
||||||
|
`operate_time` DATETIME DEFAULT NULL COMMENT '操作时间',
|
||||||
|
INDEX `idx_company_id` (`company_id`),
|
||||||
|
INDEX `idx_user_id` (`user_id`),
|
||||||
|
INDEX `idx_operate_time` (`operate_time`),
|
||||||
|
INDEX `idx_module` (`module`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='操作日志表';
|
||||||
+41
-134
@@ -1,153 +1,60 @@
|
|||||||
<div align="center">
|
# ecom-dmb-frontend
|
||||||
<a href="https://github.com/anncwb/vue-vben-admin">
|
|
||||||
<img alt="VbenAdmin Logo" width="215" src="https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp">
|
|
||||||
</a>
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
|
|
||||||
[](LICENSE)
|
电商 DMB 前端(Vben Admin 5.5.9)
|
||||||
|
|
||||||
<h1>Vue Vben Admin</h1>
|
## 技术栈
|
||||||
</div>
|
|
||||||
|
|
||||||
[](https://sonarcloud.io/summary/new_code?id=vbenjs_vue-vben-admin)    
|
- Vue 3 + TypeScript
|
||||||
|
- Vben Admin 5.5.9(monorepo)
|
||||||
|
- Ant Design Vue 组件库
|
||||||
|
- Tailwind CSS 样式
|
||||||
|
- ECharts 图表
|
||||||
|
- Vite 6 构建
|
||||||
|
|
||||||
**English** | [中文](./README.zh-CN.md) | [日本語](./README.ja-JP.md)
|
## 快速启动
|
||||||
|
|
||||||
## Introduction
|
|
||||||
|
|
||||||
Vue Vben Admin is a free and open source middle and back-end template. Using the latest `vue3`, `vite`, `TypeScript` and other mainstream technology development, the out-of-the-box middle and back-end front-end solutions can also be used for learning reference.
|
|
||||||
|
|
||||||
## Upgrade Notice
|
|
||||||
|
|
||||||
This is the latest version, 5.0, and it is not compatible with previous versions. If you are starting a new project, it is recommended to use the latest version. If you wish to view the old version, please use the [v2 branch](https://github.com/vbenjs/vue-vben-admin/tree/v2).
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- **Latest Technology Stack**: Developed with cutting-edge front-end technologies like Vue 3 and Vite
|
|
||||||
- **TypeScript**: A language for application-scale JavaScript
|
|
||||||
- **Themes**: Multiple theme colors available with customizable options
|
|
||||||
- **Internationalization**: Comprehensive built-in internationalization support
|
|
||||||
- **Permissions**: Built-in solution for dynamic route-based permission generation
|
|
||||||
|
|
||||||
## Preview
|
|
||||||
|
|
||||||
- [Vben Admin](https://vben.pro/) - Full version Chinese site
|
|
||||||
|
|
||||||
Test Account: vben/123456
|
|
||||||
|
|
||||||
<div align="center">
|
|
||||||
<img alt="VbenAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview1.png">
|
|
||||||
<img alt="VbenAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview2.png">
|
|
||||||
<img alt="VbenAdmin Logo" width="100%" src="https://anncwb.github.io/anncwb/images/preview3.png">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
### Use Gitpod
|
|
||||||
|
|
||||||
Open the project in Gitpod (free online dev environment for GitHub) and start coding immediately.
|
|
||||||
|
|
||||||
[](https://gitpod.io/#https://github.com/vbenjs/vue-vben-admin)
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
[Document](https://doc.vben.pro/)
|
|
||||||
|
|
||||||
## Install and Use
|
|
||||||
|
|
||||||
1. Get the project code
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/vbenjs/vue-vben-admin.git
|
cd ecom-dmb-frontend
|
||||||
```
|
|
||||||
|
|
||||||
2. Install dependencies
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd vue-vben-admin
|
|
||||||
npm i -g corepack
|
|
||||||
pnpm install
|
pnpm install
|
||||||
|
pnpm run dev:antd
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Run
|
访问:http://localhost:5666
|
||||||
|
|
||||||
|
## 构建生产版本
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm dev
|
pnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Build
|
## 项目结构
|
||||||
|
|
||||||
```bash
|
```
|
||||||
pnpm build
|
ecom-dmb-frontend/apps/
|
||||||
|
├── web-antd/ # 主应用
|
||||||
|
│ └── src/
|
||||||
|
│ ├── api/ # API 接口(按模块划分)
|
||||||
|
│ │ ├── ecommerce/ # 电商模块 API
|
||||||
|
│ │ ├── organization/
|
||||||
|
│ │ ├── media/
|
||||||
|
│ │ └── system/
|
||||||
|
│ ├── views/
|
||||||
|
│ │ ├── dashboard/ # Dashboard 页面
|
||||||
|
│ │ ├── ecommerce/ # 电商页面
|
||||||
|
│ │ └── ...
|
||||||
|
│ └── utils/ # 工具函数
|
||||||
|
└── backend-mock/ # Mock 服务
|
||||||
```
|
```
|
||||||
|
|
||||||
## Change Log
|
## 样式规范
|
||||||
|
|
||||||
[CHANGELOG](https://github.com/vbenjs/vue-vben-admin/releases)
|
- 全局使用 **Tailwind CSS** 类名
|
||||||
|
- 禁止在 Vue 文件中混用普通 CSS(保证一致性)
|
||||||
|
- 使用 `@vben/common-ui` 的 `Page` 组件做页面包裹
|
||||||
|
- 响应式布局使用 `grid` + `flex`
|
||||||
|
|
||||||
## How to Contribute
|
## 新增页面流程
|
||||||
|
|
||||||
You are very welcome to join! [Raise an issue](https://github.com/anncwb/vue-vben-admin/issues/new/choose) or submit a Pull Request.
|
1. 在 `views/` 下创建页面组件
|
||||||
|
2. 在 `api/` 下定义对应的 API 函数
|
||||||
**Pull Request Process:**
|
3. 在后端菜单管理中添加路由并分配权限
|
||||||
|
|
||||||
1. Fork the code
|
|
||||||
2. Create your branch: `git checkout -b feat/xxxx`
|
|
||||||
3. Submit your changes: `git commit -am 'feat(function): add xxxxx'`
|
|
||||||
4. Push your branch: `git push origin feat/xxxx`
|
|
||||||
5. Submit `pull request`
|
|
||||||
|
|
||||||
## Git Contribution Submission Specification
|
|
||||||
|
|
||||||
Reference [vue](https://github.com/vuejs/vue/blob/dev/.github/COMMIT_CONVENTION.md) specification ([Angular](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular))
|
|
||||||
|
|
||||||
- `feat` Add new features
|
|
||||||
- `fix` Fix the problem/BUG
|
|
||||||
- `style` The code style is related and does not affect the running result
|
|
||||||
- `perf` Optimization/performance improvement
|
|
||||||
- `refactor` Refactor
|
|
||||||
- `revert` Undo edit
|
|
||||||
- `test` Test related
|
|
||||||
- `docs` Documentation/notes
|
|
||||||
- `chore` Dependency update/scaffolding configuration modification etc.
|
|
||||||
- `ci` Continuous integration
|
|
||||||
- `types` Type definition file changes
|
|
||||||
|
|
||||||
## Browser Support
|
|
||||||
|
|
||||||
The `Chrome 80+` browser is recommended for local development
|
|
||||||
|
|
||||||
Support modern browsers, not IE
|
|
||||||
|
|
||||||
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
|
|
||||||
| :-: | :-: | :-: | :-: |
|
|
||||||
| last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
|
||||||
|
|
||||||
## Maintainer
|
|
||||||
|
|
||||||
[@Vben](https://github.com/anncwb)
|
|
||||||
|
|
||||||
## Star History
|
|
||||||
|
|
||||||
[](https://star-history.com/#vbenjs/vue-vben-admin&Date)
|
|
||||||
|
|
||||||
## Donate
|
|
||||||
|
|
||||||
If you think this project is helpful to you, you can help the author buy a cup of coffee to show your support!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aee;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
|
|
||||||
|
|
||||||
## Contributors
|
|
||||||
|
|
||||||
<a href="https://github.com/vbenjs/vue-vben-admin/graphs/contributors">
|
|
||||||
<img alt="Contributors" src="https://opencollective.com/vbenjs/contributors.svg?button=false" />
|
|
||||||
</a>
|
|
||||||
|
|
||||||
## Discord
|
|
||||||
|
|
||||||
- [Github Discussions](https://github.com/anncwb/vue-vben-admin/discussions)
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[MIT © Vben-2020](./LICENSE)
|
|
||||||
|
|||||||
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# ecom_dmb 数据库备份脚本
|
||||||
|
# 用法: ./backup.sh [保留天数]
|
||||||
|
# 默认保留最近 7 天
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# ============= 配置 =============
|
||||||
|
DB_HOST="${DB_HOST:-192.168.3.100}"
|
||||||
|
DB_PORT="${DB_PORT:-3306}"
|
||||||
|
DB_NAME="${DB_NAME:-ecom_dmb_dev}"
|
||||||
|
DB_USER="${DB_USER:-ecom_dmb_dev}"
|
||||||
|
DB_PASS="${DB_PASS:-ecom_dmb_dev}"
|
||||||
|
|
||||||
|
BACKUP_DIR="${BACKUP_DIR:-/home/qinghua/backups/ecom_dmb}"
|
||||||
|
KEEP_DAYS="${1:-7}"
|
||||||
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||||
|
BACKUP_FILE="${BACKUP_DIR}/${DB_NAME}_${TIMESTAMP}.sql.gz"
|
||||||
|
|
||||||
|
# ============= 初始化 =============
|
||||||
|
mkdir -p "${BACKUP_DIR}"
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 开始备份数据库: ${DB_NAME}"
|
||||||
|
|
||||||
|
# ============= 执行备份 =============
|
||||||
|
mysqldump -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" \
|
||||||
|
--single-transaction \
|
||||||
|
--quick \
|
||||||
|
--lock-tables=false \
|
||||||
|
--routines \
|
||||||
|
--triggers \
|
||||||
|
--events \
|
||||||
|
"${DB_NAME}" | gzip > "${BACKUP_FILE}"
|
||||||
|
|
||||||
|
BACKUP_SIZE=$(du -h "${BACKUP_FILE}" | cut -f1)
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 备份完成: ${BACKUP_FILE} (${BACKUP_SIZE})"
|
||||||
|
|
||||||
|
# ============= 清理旧备份 =============
|
||||||
|
find "${BACKUP_DIR}" -name "${DB_NAME}_*.sql.gz" -mtime +${KEEP_DAYS} -delete
|
||||||
|
OLD_COUNT=$(find "${BACKUP_DIR}" -name "${DB_NAME}_*.sql.gz" -mtime +${KEEP_DAYS} 2>/dev/null | wc -l)
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] 清理完成,保留最近 ${KEEP_DAYS} 天"
|
||||||
|
|
||||||
|
# ============= 备份到 NAS =============
|
||||||
|
if mount | grep -q "团队文件-龙虾"; then
|
||||||
|
smbclient //192.168.3.100/团队文件-龙虾 \
|
||||||
|
-U ahclaw%psw123456 \
|
||||||
|
-c "mkdir backups; cd backups; put ${BACKUP_FILE} ${DB_NAME}_${TIMESTAMP}.sql.gz" \
|
||||||
|
2>/dev/null && echo "[$(date '+%Y-%m-%d %H:%M:%S')] 已上传到 NAS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "========================================="
|
||||||
|
echo " 备份成功!共保留 $(find ${BACKUP_DIR} -name "${DB_NAME}_*.sql.gz" | wc -l) 个备份"
|
||||||
|
echo "========================================="
|
||||||
Reference in New Issue
Block a user