commit a305dcdc3ff1335b8aea395698ac3ffe9adc6b15 Author: ah--desktop Date: Wed Sep 10 00:33:25 2025 +0800 初始化项目 diff --git a/ecom-dmb-backend/.gitattributes b/ecom-dmb-backend/.gitattributes new file mode 100644 index 00000000..3b41682a --- /dev/null +++ b/ecom-dmb-backend/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/ecom-dmb-backend/.gitignore b/ecom-dmb-backend/.gitignore new file mode 100644 index 00000000..667aaef0 --- /dev/null +++ b/ecom-dmb-backend/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/ecom-dmb-backend/.mvn/wrapper/maven-wrapper.properties b/ecom-dmb-backend/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..12fbe1e9 --- /dev/null +++ b/ecom-dmb-backend/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip diff --git a/ecom-dmb-backend/README.md b/ecom-dmb-backend/README.md new file mode 100644 index 00000000..bab00b62 --- /dev/null +++ b/ecom-dmb-backend/README.md @@ -0,0 +1,179 @@ +# AH-GF-Backend + +AH-GF-Backend 是一个基于 Spring Boot 3.x + MyBatis Plus + Spring Security + JWT 的后端服务项目。 + +## 技术栈 + +- **Spring Boot 3.2.3** - 主框架 +- **MyBatis Plus 3.5.5** - ORM框架 +- **Spring Security** - 安全框架 +- **JWT** - 身份认证 +- **MySQL** - 数据库 +- **Knife4j** - API文档 +- **Lombok** - 代码简化 +- **Maven** - 构建工具 + +## 项目结构 + +``` +src/main/java/top/xyquan/ahgfbackend/ +├── AhGfBackendApplication.java # 启动类 +├── common/ # 公共模块 +│ ├── exception/ # 异常处理 +│ ├── model/ # 公共模型 +│ └── response/ # 响应封装 +├── config/ # 配置类 +├── modules/ # 业务模块 +│ ├── sys/ # 系统模块 +│ │ ├── controller/ # 控制器 +│ │ ├── mapper/ # 数据访问层 +│ │ ├── model/ # 数据模型 +│ │ │ ├── dto/ # 数据传输对象 +│ │ │ ├── po/ # 持久化对象 +│ │ │ └── vo/ # 视图对象 +│ │ └── service/ # 业务逻辑层 +│ └── org/ # 组织模块 +└── utils/ # 工具类 +``` + +## 功能特性 + +### 用户认证模块 + +1. **用户注册** + - 支持通过登录账号或手机号码注册 + - 密码加密存储 + - 自动生成JWT令牌 + +2. **用户登录** + - 支持通过登录账号或手机号码登录 + - 密码验证 + - 返回JWT令牌和用户信息 + +3. **安全特性** + - 密码BCrypt加密 + - JWT令牌认证 + - 全局异常处理 + - 参数验证 + +## API接口 + +### 认证接口 + +#### 用户注册 +- **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 +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 diff --git a/ecom-dmb-backend/docs/CurrentUserContext使用说明.md b/ecom-dmb-backend/docs/CurrentUserContext使用说明.md new file mode 100644 index 00000000..9fa6be2a --- /dev/null +++ b/ecom-dmb-backend/docs/CurrentUserContext使用说明.md @@ -0,0 +1,188 @@ +# CurrentUserContext 使用说明 + +## 概述 + +`CurrentUserContext` 是一个更安全的当前用户信息获取工具类,用于替代原有的 `SecurityUtils` 静态方法。它提供了更好的线程安全性和错误处理机制。 + +## 主要优势 + +### 1. 线程安全性 +- 使用依赖注入管理 `JwtUtils` 实例,避免每次创建新实例 +- 基于 Spring Security 的 `SecurityContextHolder`,天然线程安全 +- 每个HTTP请求在独立线程中处理,用户信息完全隔离 + +### 2. 更好的错误处理 +- 提供明确的异常信息 +- 统一的错误处理机制 +- 更好的调试体验 + +### 3. 依赖注入 +- 符合Spring最佳实践 +- 便于单元测试 +- 更好的可维护性 + +## 使用方法 + +### 1. 在服务类中注入 + +```java +@Service +public class YourServiceImpl extends ServiceImpl implements YourService { + + private final CurrentUserContext currentUserContext; + + public YourServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + public YourVO createSomething(CreateDTO createDTO) { + // 获取当前用户公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 获取当前用户ID + Long userId = currentUserContext.getCurrentUserId(); + + // 业务逻辑... + } +} +``` + +### 2. 主要方法说明 + +#### getCurrentCompanyId() +```java +// 获取当前用户公司ID +Long companyId = currentUserContext.getCurrentCompanyId(); +// 如果无法获取,会抛出 BusinessException("无法获取公司信息") +``` + +#### getCurrentUserId() +```java +// 获取当前用户ID +Long userId = currentUserContext.getCurrentUserId(); +// 如果无法获取,会抛出 BusinessException("用户未登录") +``` + +#### getCurrentAuthentication() +```java +// 获取当前用户认证信息 +Authentication authentication = currentUserContext.getCurrentAuthentication(); +``` + +#### isAuthenticated() +```java +// 检查是否已登录 +boolean isLoggedIn = currentUserContext.isAuthenticated(); +``` + +## 迁移指南 + +### 从 SecurityUtils 迁移到 CurrentUserContext + +#### 原有代码: +```java +// 获取公司ID +Long companyId = SecurityUtils.getCurrentUserCompanyId(); +if (companyId == null) { + throw new BusinessException("无法获取公司信息"); +} + +// 获取用户ID +Long userId = SecurityUtils.getCurrentUserId(); +if (userId == null) { + throw new BusinessException("用户未登录"); +} +``` + +#### 迁移后代码: +```java +// 获取公司ID(自动处理异常) +Long companyId = currentUserContext.getCurrentCompanyId(); + +// 获取用户ID(自动处理异常) +Long userId = currentUserContext.getCurrentUserId(); +``` + +## 安全特性 + +### 1. 请求隔离 +``` +Thread 1: User A -> SecurityContext A -> CompanyId A +Thread 2: User B -> SecurityContext B -> CompanyId B +Thread 3: User C -> SecurityContext C -> CompanyId C +``` + +### 2. 自动异常处理 +- 用户未登录时自动抛出异常 +- 公司信息获取失败时自动抛出异常 +- 用户ID格式错误时自动抛出异常 + +### 3. 数据隔离 +- 确保用户只能访问自己公司的数据 +- 防止跨公司数据访问 +- 自动添加公司ID过滤条件 + +## 最佳实践 + +### 1. 在服务层使用 +```java +@Service +public class DepartmentServiceImpl { + + private final CurrentUserContext currentUserContext; + + public DepartmentServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + public DepartmentVO createDepartment(CreateDepartmentDTO dto) { + // 自动获取公司ID,无需手动处理 + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 业务逻辑... + } +} +``` + +### 2. 在查询中强制添加公司过滤 +```java +@Override +public PageResultVO getDepartmentPage(PageQueryDTO pageQueryDTO, DepartmentFilterDTO queryDTO) { + // 强制添加公司ID过滤条件 + Long companyId = currentUserContext.getCurrentCompanyId(); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(DepartmentPO::getCompanyId, companyId); // 强制过滤 + + // 其他过滤条件... +} +``` + +### 3. 在更新/删除时验证权限 +```java +@Override +public void deleteDepartment(Long id) { + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 验证数据是否属于当前公司 + DepartmentPO department = this.getById(id); + if (!companyId.equals(department.getCompanyId())) { + throw new BusinessException("无权操作此部门"); + } + + // 执行删除操作... +} +``` + +## 注意事项 + +1. **不要在控制器层使用**:控制器应该保持简洁,只负责请求处理 +2. **统一异常处理**:所有异常都会被全局异常处理器捕获 +3. **测试友好**:便于在单元测试中模拟用户上下文 +4. **性能优化**:避免重复的token解析操作 + +## 总结 + +`CurrentUserContext` 提供了更安全、更易用的用户信息获取方式,是企业级应用中处理多租户数据隔离的最佳实践。 diff --git a/ecom-dmb-backend/docs/权限控制系统实现总结.md b/ecom-dmb-backend/docs/权限控制系统实现总结.md new file mode 100644 index 00000000..a5f14f59 --- /dev/null +++ b/ecom-dmb-backend/docs/权限控制系统实现总结.md @@ -0,0 +1,203 @@ +# 权限控制系统实现总结 + +## 已完成的功能 + +### 1. 核心组件 + +#### 权限注解 +- **@RequireRole**:简单的角色权限控制注解 +- **@RequirePermission**:细粒度的权限码控制注解 + +#### 权限验证切面 +- **RoleAspect**:处理@RequireRole注解的权限验证 +- **PermissionAspect**:处理@RequirePermission注解的权限验证 + +#### 权限服务 +- **PermissionCheckService**:权限检查服务接口 +- **PermissionCheckServiceImpl**:权限检查服务实现 +- **PermissionService**:权限管理服务接口 +- **PermissionServiceImpl**:权限管理服务实现 + +#### 工具类 +- **PermissionUtils**:权限控制工具类,提供静态方法 +- **AopConfig**:AOP配置类 + +### 2. 权限控制架构 + +#### 角色定义 +- **super(超级管理员)**:拥有系统所有权限 +- **company(公司管理员)**:拥有本公司内所有权限 +- **user(普通用户)**:根据岗位权限访问系统功能 + +#### 权限验证流程 +``` +用户请求 → 注解拦截 → 角色验证 → 权限验证 → 业务执行 +``` + +### 3. 已应用的模块 + +#### org模块权限控制 +- **CompanyController**:公司管理接口权限控制 +- **DepartmentController**:部门管理接口权限控制 +- **PositionController**:岗位管理接口权限控制 +- **CompanyMenuController**:公司菜单管理接口权限控制 + +#### 权限配置策略 +- **创建/更新/删除操作**:仅允许super和company角色 +- **查询操作**:允许所有角色访问 +- **批量操作**:仅允许super和company角色 + +## 技术实现 + +### 1. 依赖配置 +```xml + + + org.springframework.boot + spring-boot-starter-aop + +``` + +### 2. 注解使用示例 + +#### 角色权限控制 +```java +@RequireRole(description = "创建公司", allowUser = false) +@PostMapping("/create") +public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO dto) { + // 业务逻辑 +} +``` + +#### 细粒度权限控制 +```java +@RequirePermission(value = "company:delete", description = "删除公司") +@DeleteMapping("/delete/{id}") +public ApiResponse deleteCompany(@PathVariable Long id) { + // 业务逻辑 +} +``` + +### 3. 权限验证逻辑 + +#### 角色验证 +1. 获取当前用户角色 +2. 根据注解配置判断是否允许该角色访问 +3. 如果允许,继续执行;否则抛出权限不足异常 + +#### 细粒度权限验证 +1. 获取当前用户角色 +2. 如果是super角色,直接允许访问 +3. 如果是company角色,直接允许访问 +4. 如果是user角色,根据岗位权限进行验证: + - 获取岗位的所有菜单权限 + - 根据菜单ID查询对应的权限码 + - 检查是否包含指定的权限码 + +## 数据库设计 + +### 核心表结构 +- `sys_user`:用户表,包含角色信息 +- `org_position`:岗位表 +- `org_company_menu`:公司菜单权限表 +- `rel_position_company_menu`:岗位与公司菜单权限关联表 +- `sys_menu`:菜单表 +- `sys_permission`:权限表 +- `rel_menu_permission`:菜单与权限关联表 + +### 权限关系 +``` +用户 → 岗位 → 公司菜单权限 → 菜单 → 权限 +``` + +## 使用指南 + +### 1. 在控制器中添加权限控制 + +#### 简单角色控制 +```java +@RequireRole(description = "操作描述", allowUser = false) +@PostMapping("/api/endpoint") +public ApiResponse method() { + // 业务逻辑 +} +``` + +#### 细粒度权限控制 +```java +@RequirePermission(value = "module:action", description = "操作描述") +@PostMapping("/api/endpoint") +public ApiResponse method() { + // 业务逻辑 +} +``` + +### 2. 在代码中进行权限检查 + +```java +// 检查是否有指定权限 +if (PermissionUtils.hasPermission("user:create")) { + // 执行创建用户逻辑 +} + +// 检查是否有指定角色 +if (PermissionUtils.isSuper()) { + // 超级管理员逻辑 +} + +// 获取当前用户角色 +String role = PermissionUtils.getCurrentRole(); +``` + +## 扩展建议 + +### 1. 权限缓存 +为了提高性能,建议对权限信息进行缓存: +```java +@Cacheable(value = "permissions", key = "#positionId") +public List getPositionPermissions(Long positionId, Long companyId) { + // 权限查询逻辑 +} +``` + +### 2. 权限日志 +记录权限验证的日志,便于问题排查: +```java +log.info("权限验证 - 用户: {}, 角色: {}, 权限: {}, 结果: {}", + userId, role, permissionCode, hasPermission); +``` + +### 3. 动态权限配置 +支持从数据库动态配置权限,而不是硬编码在注解中。 + +## 测试建议 + +### 1. 单元测试 +- 测试不同角色的权限验证 +- 测试权限不足的情况 +- 测试异常处理 + +### 2. 集成测试 +- 测试完整的权限验证流程 +- 测试数据库权限查询 +- 测试缓存机制 + +### 3. 性能测试 +- 测试权限验证对系统性能的影响 +- 测试并发情况下的权限验证 + +## 注意事项 + +1. **权限粒度**:建议根据业务需求合理设置权限粒度 +2. **性能考虑**:权限验证会增加系统开销,建议合理使用缓存 +3. **安全性**:权限验证应该在服务层进行,不能仅依赖前端控制 +4. **日志记录**:建议记录权限验证的日志,便于问题排查 +5. **异常处理**:权限验证失败时应该返回明确的错误信息 + +## 后续计划 + +1. **完善权限管理界面**:提供可视化的权限配置界面 +2. **权限审计**:记录权限变更历史 +3. **权限继承**:支持权限的继承关系 +4. **多租户权限**:支持多租户的权限隔离 +5. **权限同步**:支持权限的实时同步 diff --git a/ecom-dmb-backend/docs/权限控制系统设计说明.md b/ecom-dmb-backend/docs/权限控制系统设计说明.md new file mode 100644 index 00000000..21af915e --- /dev/null +++ b/ecom-dmb-backend/docs/权限控制系统设计说明.md @@ -0,0 +1,178 @@ +# 权限控制系统设计说明 + +## 概述 + +本系统实现了基于角色的权限控制(RBAC),支持三种用户角色:super(超级管理员)、company(公司管理员)、user(普通用户)。 + +## 权限控制架构 + +### 1. 角色定义 + +- **super(超级管理员)**:拥有系统所有权限,可以管理所有公司和用户 +- **company(公司管理员)**:拥有本公司内所有权限,可以管理本公司内的部门、岗位、用户等 +- **user(普通用户)**:根据岗位权限访问系统功能 + +### 2. 权限控制层次 + +``` +用户角色 (super/company/user) + ↓ +岗位权限 (仅user角色) + ↓ +菜单权限 (通过岗位分配) + ↓ +功能权限 (通过菜单关联) +``` + +## 实现方案 + +### 1. 注解式权限控制 + +#### @RequireRole 注解 + +用于简单的角色权限控制,直接在控制器方法上使用: + +```java +@RequireRole(description = "创建公司", allowUser = false) +@PostMapping("/create") +public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) { + // 业务逻辑 +} +``` + +**注解参数说明:** +- `value`:允许的角色列表(可选) +- `description`:权限描述 +- `allowSuper`:是否允许超级管理员访问(默认true) +- `allowCompany`:是否允许公司管理员访问(默认true) +- `allowUser`:是否允许普通用户访问(默认false) + +#### @RequirePermission 注解 + +用于细粒度的权限控制,基于权限码进行验证: + +```java +@RequirePermission(value = "company:create", description = "创建公司") +@PostMapping("/create") +public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) { + // 业务逻辑 +} +``` + +### 2. 权限验证流程 + +#### 角色权限验证流程 + +1. 获取当前用户角色 +2. 根据注解配置判断是否允许该角色访问 +3. 如果允许,继续执行;否则抛出权限不足异常 + +#### 细粒度权限验证流程 + +1. 获取当前用户角色 +2. 如果是super角色,直接允许访问 +3. 如果是company角色,直接允许访问 +4. 如果是user角色,根据岗位权限进行验证: + - 获取岗位的所有菜单权限 + - 根据菜单ID查询对应的权限码 + - 检查是否包含指定的权限码 + +### 3. 数据库设计 + +#### 核心表结构 + +- `sys_user`:用户表,包含角色信息 +- `org_position`:岗位表 +- `org_company_menu`:公司菜单权限表 +- `rel_position_company_menu`:岗位与公司菜单权限关联表 +- `sys_menu`:菜单表 +- `sys_permission`:权限表 +- `rel_menu_permission`:菜单与权限关联表 + +#### 权限关系 + +``` +用户 → 岗位 → 公司菜单权限 → 菜单 → 权限 +``` + +## 使用示例 + +### 1. 在控制器中应用权限控制 + +```java +@RestController +@RequestMapping("/company") +public class CompanyController { + + // 只允许super和company角色访问 + @RequireRole(description = "创建公司", allowUser = false) + @PostMapping("/create") + public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO dto) { + // 业务逻辑 + } + + // 允许所有角色访问 + @RequireRole(description = "查询公司列表", allowUser = true) + @PostMapping("/page") + public ApiResponse> getCompanyPage(@Valid @RequestBody PageQueryDTO pageQuery) { + // 业务逻辑 + } + + // 使用细粒度权限控制 + @RequirePermission(value = "company:delete", description = "删除公司") + @DeleteMapping("/delete/{id}") + public ApiResponse deleteCompany(@PathVariable Long id) { + // 业务逻辑 + } +} +``` + +### 2. 权限配置建议 + +#### 公司管理模块 +- 创建、更新、删除公司:仅super和company角色 +- 查询公司列表:所有角色 + +#### 部门管理模块 +- 创建、更新、删除部门:仅super和company角色 +- 查询部门列表:所有角色 + +#### 岗位管理模块 +- 创建、更新、删除岗位:仅super和company角色 +- 查询岗位列表:所有角色 +- 分配岗位权限:仅super和company角色 + +#### 用户管理模块 +- 创建、更新、删除用户:仅super和company角色 +- 查询用户列表:所有角色 +- 修改密码:用户本人或管理员 + +## 扩展说明 + +### 1. 添加新的权限码 + +1. 在`sys_permission`表中添加权限记录 +2. 在`rel_menu_permission`表中关联菜单和权限 +3. 在控制器方法上使用`@RequirePermission`注解 + +### 2. 自定义权限验证逻辑 + +可以继承`PermissionCheckService`接口,实现自定义的权限验证逻辑。 + +### 3. 权限缓存 + +为了提高性能,可以考虑对权限信息进行缓存,避免频繁查询数据库。 + +## 注意事项 + +1. **权限粒度**:建议根据业务需求合理设置权限粒度,避免过于复杂 +2. **性能考虑**:权限验证会增加系统开销,建议合理使用缓存 +3. **安全性**:权限验证应该在服务层进行,不能仅依赖前端控制 +4. **日志记录**:建议记录权限验证的日志,便于问题排查 + +## 测试建议 + +1. **角色权限测试**:测试不同角色用户的权限访问 +2. **边界条件测试**:测试无权限、权限不足等情况 +3. **性能测试**:测试权限验证对系统性能的影响 +4. **安全测试**:测试权限绕过的可能性 diff --git a/ecom-dmb-backend/mvnw b/ecom-dmb-backend/mvnw new file mode 100644 index 00000000..19529ddf --- /dev/null +++ b/ecom-dmb-backend/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/ecom-dmb-backend/mvnw.cmd b/ecom-dmb-backend/mvnw.cmd new file mode 100644 index 00000000..249bdf38 --- /dev/null +++ b/ecom-dmb-backend/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/ecom-dmb-backend/pom.xml b/ecom-dmb-backend/pom.xml new file mode 100644 index 00000000..842cdba1 --- /dev/null +++ b/ecom-dmb-backend/pom.xml @@ -0,0 +1,132 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.3 + + + top.xyquan + ecom-dmb-backend + 0.0.1-SNAPSHOT + ah-gf-backend + ah-gf-backend + + 17 + 17 + 17 + 1.18.30 + 3.5.5 + + + + + org.springframework.boot + spring-boot-starter-web + + + + com.baomidou + mybatis-plus-spring-boot3-starter + ${mybatis-plus.version} + + + + com.mysql + mysql-connector-j + runtime + + + + org.projectlombok + lombok + ${lombok.version} + true + + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.5.0 + + + + org.springframework.boot + spring-boot-starter-security + + + + io.jsonwebtoken + jjwt-api + 0.11.5 + + + + io.jsonwebtoken + jjwt-impl + 0.11.5 + runtime + + + + io.jsonwebtoken + jjwt-jackson + 0.11.5 + runtime + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-starter-aop + + + + org.aspectj + aspectjweaver + + + org.aspectj + aspectjrt + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${java.version} + ${java.version} + UTF-8 + + + + + \ No newline at end of file diff --git a/ecom-dmb-backend/settings.xml b/ecom-dmb-backend/settings.xml new file mode 100644 index 00000000..2456d9fb --- /dev/null +++ b/ecom-dmb-backend/settings.xml @@ -0,0 +1,9 @@ + + + + aliyunmaven + central + 阿里云公共仓库 + https://maven.aliyun.com/repository/central + + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/AhGfBackendApplication.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/AhGfBackendApplication.java new file mode 100644 index 00000000..c1970f09 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/AhGfBackendApplication.java @@ -0,0 +1,14 @@ +package top.xyquan.ecomdmbbackend; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("top.xyquan.ecomdmbbackend.modules.*.mapper") +public class AhGfBackendApplication { + + public static void main(String[] args) { + SpringApplication.run(AhGfBackendApplication.class, args); + } +} \ No newline at end of file diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequirePermission.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequirePermission.java new file mode 100644 index 00000000..4604e5b8 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequirePermission.java @@ -0,0 +1,40 @@ +package top.xyquan.ecomdmbbackend.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 权限控制注解 + * 用于标记需要权限验证的接口 + */ +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface RequirePermission { + + /** + * 权限码,如 "company:create", "user:read" + */ + String value() default ""; + + /** + * 权限描述 + */ + String description() default ""; + + /** + * 是否允许超级管理员访问(默认允许) + */ + boolean allowSuper() default true; + + /** + * 是否允许公司管理员访问(默认允许) + */ + boolean allowCompany() default true; + + /** + * 是否允许普通用户访问(需要根据岗位权限判断) + */ + boolean allowUser() default true; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequireRole.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequireRole.java new file mode 100644 index 00000000..d50baaf9 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/annotation/RequireRole.java @@ -0,0 +1,40 @@ +package top.xyquan.ecomdmbbackend.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 角色权限注解 + * 用于简单的角色权限控制 + */ +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface RequireRole { + + /** + * 允许的角色列表 + */ + String[] value() default {}; + + /** + * 权限描述 + */ + String description() default ""; + + /** + * 是否允许超级管理员访问(默认允许) + */ + boolean allowSuper() default true; + + /** + * 是否允许公司管理员访问(默认允许) + */ + boolean allowCompany() default true; + + /** + * 是否允许普通用户访问(默认不允许) + */ + boolean allowUser() default false; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java new file mode 100644 index 00000000..8854eb6e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/PermissionAspect.java @@ -0,0 +1,78 @@ +package top.xyquan.ecomdmbbackend.common.aspect; + +import lombok.extern.slf4j.Slf4j; +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.springframework.stereotype.Component; +import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.lang.reflect.Method; + +/** + * 权限验证切面 + * 用于拦截带有@RequirePermission注解的方法并进行权限验证 + */ +@Aspect +@Component +@Slf4j +public class PermissionAspect { + + private final CurrentUserContext currentUserContext; + private final PermissionCheckService permissionCheckService; + + public PermissionAspect(CurrentUserContext currentUserContext, PermissionCheckService permissionCheckService) { + this.currentUserContext = currentUserContext; + this.permissionCheckService = permissionCheckService; + } + + @Around("@annotation(top.xyquan.ecomdmbbackend.common.annotation.RequirePermission)") + public Object checkPermission(ProceedingJoinPoint joinPoint) throws Throwable { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + RequirePermission annotation = method.getAnnotation(RequirePermission.class); + + if (annotation == null) { + return joinPoint.proceed(); + } + + // 获取当前用户信息 + String role = currentUserContext.getCurrentUserPayload().getRole(); + Long companyId = currentUserContext.getCurrentCompanyId(); + Long positionId = currentUserContext.getCurrentUserPayload().getPositionId(); + + log.debug("权限验证 - 用户角色: {}, 公司ID: {}, 岗位ID: {}, 权限码: {}", + role, companyId, positionId, annotation.value()); + + // 根据角色进行权限验证 + boolean hasPermission = false; + + switch (role) { + case "super": + hasPermission = annotation.allowSuper(); + break; + case "company": + hasPermission = annotation.allowCompany(); + break; + case "user": + hasPermission = annotation.allowUser() && + permissionCheckService.hasPermissionByPosition(positionId, annotation.value(), companyId); + break; + default: + throw new BusinessException("未知的用户角色: " + role); + } + + if (!hasPermission) { + log.warn("权限验证失败 - 用户角色: {}, 权限码: {}, 描述: {}", + role, annotation.value(), annotation.description()); + throw new BusinessException("权限不足: " + annotation.description()); + } + + log.debug("权限验证通过 - 用户角色: {}, 权限码: {}", role, annotation.value()); + return joinPoint.proceed(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspect.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspect.java new file mode 100644 index 00000000..50a727a5 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspect.java @@ -0,0 +1,76 @@ +package top.xyquan.ecomdmbbackend.common.aspect; + +import lombok.extern.slf4j.Slf4j; +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.springframework.stereotype.Component; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.lang.reflect.Method; +import java.util.Arrays; + +/** + * 角色权限验证切面 + * 用于简单的角色权限控制 + */ +@Aspect +@Component +@Slf4j +public class RoleAspect { + + private final CurrentUserContext currentUserContext; + + public RoleAspect(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Around("@annotation(top.xyquan.ecomdmbbackend.common.annotation.RequireRole)") + public Object checkRole(ProceedingJoinPoint joinPoint) throws Throwable { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + RequireRole annotation = method.getAnnotation(RequireRole.class); + + if (annotation == null) { + return joinPoint.proceed(); + } + + // 获取当前用户角色 + String role = currentUserContext.getCurrentUserPayload().getRole(); + + log.debug("角色权限验证 - 用户角色: {}, 注解配置: {}", role, annotation.description()); + + // 根据角色进行权限验证 + boolean hasPermission = false; + + switch (role) { + case "super": + hasPermission = annotation.allowSuper(); + break; + case "company": + hasPermission = annotation.allowCompany(); + break; + case "user": + hasPermission = annotation.allowUser(); + break; + default: + throw new BusinessException("未知的用户角色: " + role); + } + + // 检查是否在允许的角色列表中 + if (annotation.value().length > 0) { + hasPermission = hasPermission && Arrays.asList(annotation.value()).contains(role); + } + + if (!hasPermission) { + log.warn("角色权限验证失败 - 用户角色: {}, 描述: {}", role, annotation.description()); + throw new BusinessException("权限不足: " + annotation.description()); + } + + log.debug("角色权限验证通过 - 用户角色: {}", role); + return joinPoint.proceed(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/AopConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/AopConfig.java new file mode 100644 index 00000000..13763581 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/AopConfig.java @@ -0,0 +1,13 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +/** + * AOP配置类 + * 启用AspectJ自动代理,确保权限控制切面正常工作 + */ +@Configuration +@EnableAspectJAutoProxy(proxyTargetClass = true) +public class AopConfig { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/Knife4jConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/Knife4jConfig.java new file mode 100644 index 00000000..1b45b24d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/Knife4jConfig.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Knife4j配置 + */ +@Configuration +public class Knife4jConfig { + + @Bean + public OpenAPI customOpenAPI() { + return new OpenAPI() + .info(new Info() + .title("ECOM-DMB-Backend API") + .description("ECOM-DMB-Backend 后端服务API文档,支持多模块接口管理") + .version("1.0.0") + .contact(new Contact() + .name("开发团队") + .email("1564467676@qq.com") + .url("https://xyquan.top")) + .license(new License() + .name("MIT License") + .url("https://xyquan.top/licenses/MIT"))); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/MybatisPlusConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/MybatisPlusConfig.java new file mode 100644 index 00000000..04d46137 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/MybatisPlusConfig.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.time.LocalDateTime; + +/** + * MyBatis Plus配置 + */ +@Configuration +public class MybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + + /** + * 自动填充处理器 + */ + @Bean + public MetaObjectHandler metaObjectHandler() { + return new MetaObjectHandler() { + @Override + public void insertFill(MetaObject metaObject) { + this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); + this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); + } + }; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/SecurityConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/SecurityConfig.java new file mode 100644 index 00000000..05502523 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/SecurityConfig.java @@ -0,0 +1,51 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import top.xyquan.ecomdmbbackend.common.filter.JwtAuthenticationFilter; +import top.xyquan.ecomdmbbackend.utils.JwtUtils; + +/** + * Spring Security配置 + */ +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + private final JwtUtils jwtUtils; + private final JwtAuthenticationFilter jwtAuthenticationFilter; + + public SecurityConfig(JwtUtils jwtUtils, JwtAuthenticationFilter jwtAuthenticationFilter) { + this.jwtUtils = jwtUtils; + this.jwtAuthenticationFilter = jwtAuthenticationFilter; + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(AbstractHttpConfigurer::disable) + .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/auth/**").permitAll() + .requestMatchers("/doc.html", "/webjars/**", "/v3/api-docs/**", "/swagger-resources/**", + "/swagger-ui/**", "/swagger-ui.html") + .permitAll() + .anyRequest().authenticated()) + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); + + return http.build(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/WebConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/WebConfig.java new file mode 100644 index 00000000..c13f2151 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/WebConfig.java @@ -0,0 +1,41 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Web配置 + */ +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + // 配置静态资源处理 + registry.addResourceHandler("/static/**") + .addResourceLocations("classpath:/static/"); + + // 配置上传文件访问 - 使用绝对路径 + registry.addResourceHandler("/static/uploads/**") + .addResourceLocations("file:./static/uploads/"); + + // 配置Swagger UI资源 + registry.addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/"); + + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(3600); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/BusinessException.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/BusinessException.java new file mode 100644 index 00000000..49101e0d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/BusinessException.java @@ -0,0 +1,23 @@ +package top.xyquan.ecomdmbbackend.common.exception; + +import lombok.Getter; + +/** + * 业务异常 + */ +@Getter +public class BusinessException extends RuntimeException { + + private final String code; + + public BusinessException(String message) { + super(message); + this.code = "BUSINESS_ERROR"; + } + + public BusinessException(String code, String message) { + super(message); + this.code = code; + } + +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/GlobalExceptionHandler.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..1996ee1c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,102 @@ +package top.xyquan.ecomdmbbackend.common.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.core.AuthenticationException; +import org.springframework.validation.BindException; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.NoHandlerFoundException; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; + +import java.util.stream.Collectors; + +/** + * 全局异常处理器 + */ +@RestControllerAdvice +public class GlobalExceptionHandler { + + /** + * 处理业务异常 + */ + @ExceptionHandler(BusinessException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ApiResponse handleBusinessException(BusinessException e) { + return ApiResponse.fail(e.getMessage()); + } + + /** + * 处理运行时异常 + */ + @ExceptionHandler(RuntimeException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ApiResponse handleRuntimeException(RuntimeException e) { + return ApiResponse.fail(e.getMessage()); + } + + /** + * 处理参数验证异常 + */ + @ExceptionHandler(MethodArgumentNotValidException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ApiResponse handleValidationException(MethodArgumentNotValidException e) { + String message = e.getBindingResult().getFieldErrors().stream() + .map(FieldError::getDefaultMessage) + .collect(Collectors.joining(", ")); + return ApiResponse.fail("参数验证失败: " + message); + } + + /** + * 处理绑定异常 + */ + @ExceptionHandler(BindException.class) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ApiResponse handleBindException(BindException e) { + String message = e.getFieldErrors().stream() + .map(FieldError::getDefaultMessage) + .collect(Collectors.joining(", ")); + return ApiResponse.fail("参数绑定失败: " + message); + } + + /** + * 处理认证异常 + */ + @ExceptionHandler(AuthenticationException.class) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public ApiResponse handleAuthenticationException(AuthenticationException e) { + return ApiResponse.fail("认证失败: " + e.getMessage()); + } + + /** + * 处理权限异常 + */ + @ExceptionHandler(AccessDeniedException.class) + @ResponseStatus(HttpStatus.FORBIDDEN) + public ApiResponse handleAccessDeniedException(AccessDeniedException e) { + return ApiResponse.fail("权限不足: " + e.getMessage()); + } + + /** + * 处理404异常 + */ + @ExceptionHandler(NoHandlerFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public ApiResponse handleNoHandlerFoundException(NoHandlerFoundException e) { + return ApiResponse.fail("请求的资源不存在: " + e.getRequestURL()); + } + + /** + * 处理其他异常 + */ + @ExceptionHandler(Exception.class) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ApiResponse handleException(Exception e) { + // 记录详细错误信息到日志 + e.printStackTrace(); + return ApiResponse.fail("系统内部错误: " + e.getMessage()); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/filter/JwtAuthenticationFilter.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/filter/JwtAuthenticationFilter.java new file mode 100644 index 00000000..aebc5777 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/filter/JwtAuthenticationFilter.java @@ -0,0 +1,76 @@ +package top.xyquan.ecomdmbbackend.common.filter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; + +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.filter.OncePerRequestFilter; +import top.xyquan.ecomdmbbackend.utils.JwtUtils; + +import java.io.IOException; + +/** + * JWT认证过滤器 + */ +@Component +public class JwtAuthenticationFilter extends OncePerRequestFilter { + + private final JwtUtils jwtUtils; + + public JwtAuthenticationFilter(JwtUtils jwtUtils) { + this.jwtUtils = jwtUtils; + } + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + + // 添加调试日志 + logger.debug("JWT Filter处理请求: " + request.getMethod() + " " + request.getRequestURI()); + + try { + // 从请求头中获取JWT Token + String token = getTokenFromRequest(request); + + if (StringUtils.hasText(token) && jwtUtils.validateToken(token)) { + // 从Token中获取用户ID + String userId = jwtUtils.getUserIdFromToken(token); + Long companyId = jwtUtils.getCompanyIdFromToken(token); + + if (StringUtils.hasText(userId)) { + // 创建认证信息,将token作为credentials传递 + UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken( + userId, token, null); + + // 设置认证信息到Security上下文 + SecurityContextHolder.getContext().setAuthentication(authentication); + logger.debug("JWT认证成功,用户ID: " + userId); + logger.debug("JWT认证成功,公司ID: " + companyId); + } + } else { + logger.debug("JWT Token无效或为空"); + } + } catch (Exception e) { + // Token验证失败,不设置认证信息,继续执行过滤器链 + logger.debug("JWT Token验证失败: " + e.getMessage()); + } + + filterChain.doFilter(request, response); + } + + /** + * 从请求头中获取JWT Token + */ + private String getTokenFromRequest(HttpServletRequest request) { + String bearerToken = request.getHeader("Authorization"); + if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { + return bearerToken.substring(7); + } + return null; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/dto/PageQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/dto/PageQueryDTO.java new file mode 100644 index 00000000..888153c3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/dto/PageQueryDTO.java @@ -0,0 +1,26 @@ +package top.xyquan.ecomdmbbackend.common.model.dto; + +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PageQueryDTO { + + //页码,从1开始 + @NotNull(message = "页码不能为空") + @Min(value = 1, message = "页码必须大于0") + private Integer page = 1; + + //每页大小 + @NotNull(message = "每页大小不能为空") + @Min(value = 1, message = "每页大小必须大于0") + private Integer pageSize = 10; + + // 查询条件 + private T filters; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/vo/PageResultVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/vo/PageResultVO.java new file mode 100644 index 00000000..49c7a089 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/model/vo/PageResultVO.java @@ -0,0 +1,37 @@ +package top.xyquan.ecomdmbbackend.common.model.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PageResultVO implements Serializable { + private List list; // 当前页数据 + private Long total; // 总条数 + private Integer page; // 当前页码 + private Integer pageSize; // 每页条数 + private Integer totalPages; // 总页数 + private Boolean hasNextPage; // 是否有下一页 + private Boolean hasPrevPage; // 是否有上一页 + + // 构造函数 + public PageResultVO(List list, Long total, Integer page, Integer pageSize) { + this.list = list; + this.total = total; + this.page = page; + this.pageSize = pageSize; + this.totalPages = (int) Math.ceil((double) total / pageSize); + this.hasNextPage = page < this.totalPages; + this.hasPrevPage = page > 1; + } + + // 静态工厂方法,用于创建分页响应对象 + public static PageResultVO create(List list, Long total, Integer page, Integer pageSize) { + return new PageResultVO<>(list, total, page, pageSize); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/response/ApiResponse.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/response/ApiResponse.java new file mode 100644 index 00000000..cd0253af --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/response/ApiResponse.java @@ -0,0 +1,34 @@ +package top.xyquan.ecomdmbbackend.common.response; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ApiResponse { + private int code; + private String message; + private T data; + + public static ApiResponse success(T data) { + return new ApiResponse<>(0, "操作成功", data); + } + + public static ApiResponse success(String message, T data) { + return new ApiResponse<>(0, message, data); + } + + public static ApiResponse success() { + return new ApiResponse<>(0, "操作成功", null); + } + + public static ApiResponse fail(String message) { + return new ApiResponse<>(1, message, null); + } + + public static ApiResponse fail(int code, String message) { + return new ApiResponse<>(code, message, null); + } +} \ No newline at end of file diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaFileController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaFileController.java new file mode 100644 index 00000000..5bd79bc3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaFileController.java @@ -0,0 +1,102 @@ +package top.xyquan.ecomdmbbackend.modules.media.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO; +import top.xyquan.ecomdmbbackend.modules.media.service.MediaFileService; +import top.xyquan.ecomdmbbackend.utils.FileUploadUtils; + +import java.util.List; + +/** + * 文件资源池管理控制器 + */ +@Tag(name = "文件管理", description = "文件的增删改查接口") +@RestController +@RequestMapping("/media/file") +public class MediaFileController { + + private final MediaFileService mediaFileService; + + public MediaFileController(MediaFileService mediaFileService) { + this.mediaFileService = mediaFileService; + } + + @Operation(summary = "上传文件", description = "上传单个文件") + @PostMapping("/upload") + public ApiResponse uploadFile( + @RequestParam("file") MultipartFile file, + @RequestParam(value = "fileType", required = false) String fileType, + @RequestParam(value = "tags", required = false) String tags, + @RequestParam(value = "remark", required = false) String remark) { + + // 上传文件到静态目录 + String fileUrl = FileUploadUtils.uploadFile(file); + + // 创建文件记录 + MediaFileDTO mediaFileDTO = new MediaFileDTO(); + mediaFileDTO.setUrl(fileUrl); + mediaFileDTO.setFilename(file.getOriginalFilename()); + mediaFileDTO.setFileType( + fileType != null ? fileType : FileUploadUtils.getFileExtension(file.getOriginalFilename())); + mediaFileDTO.setTags(tags); + mediaFileDTO.setRemark(remark); + + MediaFileVO mediaFileVO = mediaFileService.uploadFile(mediaFileDTO); + return ApiResponse.success(mediaFileVO); + } + + @Operation(summary = "批量上传文件", description = "批量上传多个文件") + @PostMapping("/batch-upload") + public ApiResponse> batchUploadFiles( + @RequestParam("files") List files, + @RequestParam(value = "fileType", required = false) String fileType, + @RequestParam(value = "tags", required = false) String tags, + @RequestParam(value = "remark", required = false) String remark) { + + if (files == null || files.isEmpty()) { + return ApiResponse.fail("请选择要上传的文件"); + } + + // 批量上传文件并创建记录 + List mediaFileDTOList = files.stream() + .map(file -> { + String fileUrl = FileUploadUtils.uploadFile(file); + + MediaFileDTO mediaFileDTO = new MediaFileDTO(); + mediaFileDTO.setUrl(fileUrl); + mediaFileDTO.setFilename(file.getOriginalFilename()); + mediaFileDTO.setFileType( + fileType != null ? fileType : FileUploadUtils.getFileExtension(file.getOriginalFilename())); + mediaFileDTO.setTags(tags); + mediaFileDTO.setRemark(remark); + + return mediaFileDTO; + }) + .toList(); + + List mediaFileVOList = mediaFileService.batchUploadFiles(mediaFileDTOList); + return ApiResponse.success(mediaFileVOList); + } + + @Operation(summary = "更新文件信息", description = "更新文件的元数据信息") + @PutMapping("/update") + public ApiResponse updateFile(@Valid @RequestBody MediaFileDTO mediaFileDTO) { + MediaFileVO mediaFileVO = mediaFileService.updateFile(mediaFileDTO); + return ApiResponse.success(mediaFileVO); + } + + @Operation(summary = "删除文件", description = "删除指定文件") + @DeleteMapping("/delete/{id}") + public ApiResponse deleteFile( + @Parameter(description = "文件ID") @PathVariable Long id) { + mediaFileService.deleteFile(id); + return ApiResponse.success(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaImageController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaImageController.java new file mode 100644 index 00000000..8deaf6a1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/controller/MediaImageController.java @@ -0,0 +1,112 @@ +package top.xyquan.ecomdmbbackend.modules.media.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; +import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService; +import top.xyquan.ecomdmbbackend.utils.FileUploadUtils; + +import java.util.List; + +/** + * 图片资源池管理控制器 + */ +@Tag(name = "图片管理", description = "图片的增删改查接口") +@RestController +@RequestMapping("/media/image") +public class MediaImageController { + + private final MediaImageService mediaImageService; + + public MediaImageController(MediaImageService mediaImageService) { + this.mediaImageService = mediaImageService; + } + + @Operation(summary = "上传图片", description = "上传单张图片文件") + @PostMapping("/upload") + public ApiResponse uploadImage( + @RequestParam("file") MultipartFile file, + @RequestParam(value = "type", required = false) String type, + @RequestParam(value = "tags", required = false) String tags, + @RequestParam(value = "remark", required = false) String remark) { + + // 检查是否为图片文件 + if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) { + return ApiResponse.fail("只能上传图片文件"); + } + + // 上传文件到静态目录 + String fileUrl = FileUploadUtils.uploadImage(file); + + // 创建图片记录 + MediaImageDTO mediaImageDTO = new MediaImageDTO(); + mediaImageDTO.setUrl(fileUrl); + mediaImageDTO.setFilename(file.getOriginalFilename()); + mediaImageDTO.setType(type); + mediaImageDTO.setTags(tags); + mediaImageDTO.setRemark(remark); + + MediaImageVO mediaImageVO = mediaImageService.uploadImage(mediaImageDTO); + return ApiResponse.success(mediaImageVO); + } + + @Operation(summary = "批量上传图片", description = "批量上传多张图片文件") + @PostMapping("/batch-upload") + public ApiResponse> batchUploadImages( + @RequestParam("files") List files, + @RequestParam(value = "type", required = false) String type, + @RequestParam(value = "tags", required = false) String tags, + @RequestParam(value = "remark", required = false) String remark) { + + if (files == null || files.isEmpty()) { + return ApiResponse.fail("请选择要上传的图片文件"); + } + + // 检查所有文件是否为图片 + for (MultipartFile file : files) { + if (!FileUploadUtils.isImageFile(file.getOriginalFilename())) { + return ApiResponse.fail("只能上传图片文件"); + } + } + + // 批量上传文件并创建记录 + List mediaImageDTOList = files.stream() + .map(file -> { + String fileUrl = FileUploadUtils.uploadImage(file); + + MediaImageDTO mediaImageDTO = new MediaImageDTO(); + mediaImageDTO.setUrl(fileUrl); + mediaImageDTO.setFilename(file.getOriginalFilename()); + mediaImageDTO.setType(type); + mediaImageDTO.setTags(tags); + mediaImageDTO.setRemark(remark); + + return mediaImageDTO; + }) + .toList(); + + List mediaImageVOList = mediaImageService.batchUploadImages(mediaImageDTOList); + return ApiResponse.success(mediaImageVOList); + } + + @Operation(summary = "更新图片信息", description = "更新图片的元数据信息") + @PutMapping("/update") + public ApiResponse updateImage(@Valid @RequestBody MediaImageDTO mediaImageDTO) { + MediaImageVO mediaImageVO = mediaImageService.updateImage(mediaImageDTO); + return ApiResponse.success(mediaImageVO); + } + + @Operation(summary = "删除图片", description = "删除指定图片") + @DeleteMapping("/delete/{id}") + public ApiResponse deleteImage( + @Parameter(description = "图片ID") @PathVariable Long id) { + mediaImageService.deleteImage(id); + return ApiResponse.success(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaFileMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaFileMapper.java new file mode 100644 index 00000000..5c45fe0b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaFileMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.media.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.media.model.po.MediaFilePO; + +/** + * 文件资源池Mapper + */ +@Mapper +public interface MediaFileMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaImageMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaImageMapper.java new file mode 100644 index 00000000..ce4cd54a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/mapper/MediaImageMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.media.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.media.model.po.MediaImagePO; + +/** + * 图片资源池Mapper + */ +@Mapper +public interface MediaImageMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaFileDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaFileDTO.java new file mode 100644 index 00000000..50a379a4 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaFileDTO.java @@ -0,0 +1,43 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.dto; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 文件DTO + */ +@Data +public class MediaFileDTO { + + /** + * 文件ID(更新时使用) + */ + private Long id; + + /** + * 文件URL + */ + @NotBlank(message = "文件URL不能为空") + private String url; + + /** + * 文件名 + */ + @NotBlank(message = "文件名不能为空") + private String filename; + + /** + * 文件类型,如 PDF/CAD/Excel + */ + private String fileType; + + /** + * 标签,逗号分隔 + */ + private String tags; + + /** + * 文件描述 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaImageDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaImageDTO.java new file mode 100644 index 00000000..88392431 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/dto/MediaImageDTO.java @@ -0,0 +1,42 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.dto; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 图片DTO + */ +@Data +public class MediaImageDTO { + + /** + * 图片ID(更新时使用) + */ + private Long id; + + /** + * 图片URL + */ + @NotBlank(message = "图片URL不能为空") + private String url; + + /** + * 原始文件名 + */ + private String filename; + + /** + * 图片分类 (设计图,实物图,细节图,工艺图,其他) + */ + private String type; + + /** + * 标签,逗号分隔 + */ + private String tags; + + /** + * 图片说明 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaFilePO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaFilePO.java new file mode 100644 index 00000000..e273f9ce --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaFilePO.java @@ -0,0 +1,70 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 文件资源池实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("media_file") +public class MediaFilePO { + + /** + * 文件ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 文件URL + */ + @TableField("url") + private String url; + + /** + * 文件名 + */ + @TableField("filename") + private String filename; + + /** + * 文件类型,如 PDF/CAD/Excel + */ + @TableField("file_type") + private String fileType; + + /** + * 标签,逗号分隔 + */ + @TableField("tags") + private String tags; + + /** + * 文件描述 + */ + @TableField("remark") + private String remark; + + /** + * 上传人ID + */ + @TableField("upload_by") + private Long uploadBy; + + /** + * 上传时间 + */ + @TableField(value = "upload_time", fill = FieldFill.INSERT) + private LocalDateTime uploadTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaImagePO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaImagePO.java new file mode 100644 index 00000000..9d043205 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/po/MediaImagePO.java @@ -0,0 +1,70 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 图片资源池实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("media_image") +public class MediaImagePO { + + /** + * 图片ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 图片URL + */ + @TableField("url") + private String url; + + /** + * 原始文件名 + */ + @TableField("filename") + private String filename; + + /** + * 图片分类 (设计图,实物图,细节图,工艺图,其他) + */ + @TableField("type") + private String type; + + /** + * 标签,逗号分隔 + */ + @TableField("tags") + private String tags; + + /** + * 图片说明 + */ + @TableField("remark") + private String remark; + + /** + * 上传人ID + */ + @TableField("upload_by") + private Long uploadBy; + + /** + * 上传时间 + */ + @TableField(value = "upload_time", fill = FieldFill.INSERT) + private LocalDateTime uploadTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaFileVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaFileVO.java new file mode 100644 index 00000000..23fc7d0a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaFileVO.java @@ -0,0 +1,57 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 文件VO + */ +@Data +public class MediaFileVO { + + /** + * 文件ID + */ + private Long id; + + /** + * 公司ID + */ + private Long companyId; + + /** + * 文件URL + */ + private String url; + + /** + * 文件名 + */ + private String filename; + + /** + * 文件类型,如 PDF/CAD/Excel + */ + private String fileType; + + /** + * 标签,逗号分隔 + */ + private String tags; + + /** + * 文件描述 + */ + private String remark; + + /** + * 上传人ID + */ + private Long uploadBy; + + /** + * 上传时间 + */ + private LocalDateTime uploadTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaImageVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaImageVO.java new file mode 100644 index 00000000..5d0b09c2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/model/vo/MediaImageVO.java @@ -0,0 +1,57 @@ +package top.xyquan.ecomdmbbackend.modules.media.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 图片VO + */ +@Data +public class MediaImageVO { + + /** + * 图片ID + */ + private Long id; + + /** + * 公司ID + */ + private Long companyId; + + /** + * 图片URL + */ + private String url; + + /** + * 原始文件名 + */ + private String filename; + + /** + * 图片分类 (设计图,实物图,细节图,工艺图,其他) + */ + private String type; + + /** + * 标签,逗号分隔 + */ + private String tags; + + /** + * 图片说明 + */ + private String remark; + + /** + * 上传人ID + */ + private Long uploadBy; + + /** + * 上传时间 + */ + private LocalDateTime uploadTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaFileService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaFileService.java new file mode 100644 index 00000000..1a4aba2a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaFileService.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.media.service; + +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO; + +import java.util.List; + +/** + * 文件资源池服务接口 + */ +public interface MediaFileService { + + /** + * 上传文件 + */ + MediaFileVO uploadFile(MediaFileDTO mediaFileDTO); + + /** + * 批量上传文件 + */ + List batchUploadFiles(List mediaFileDTOList); + + /** + * 更新文件信息 + */ + MediaFileVO updateFile(MediaFileDTO mediaFileDTO); + + /** + * 删除文件 + */ + void deleteFile(Long id); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaImageService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaImageService.java new file mode 100644 index 00000000..8c517319 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/MediaImageService.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.media.service; + +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; + +import java.util.List; + +/** + * 图片资源池服务接口 + */ +public interface MediaImageService { + + /** + * 上传图片 + */ + MediaImageVO uploadImage(MediaImageDTO mediaImageDTO); + + /** + * 批量上传图片 + */ + List batchUploadImages(List mediaImageDTOList); + + /** + * 更新图片信息 + */ + MediaImageVO updateImage(MediaImageDTO mediaImageDTO); + + /** + * 删除图片 + */ + void deleteImage(Long id); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaFileServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaFileServiceImpl.java new file mode 100644 index 00000000..778860d8 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaFileServiceImpl.java @@ -0,0 +1,151 @@ +package top.xyquan.ecomdmbbackend.modules.media.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.media.mapper.MediaFileMapper; +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaFileDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.po.MediaFilePO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaFileVO; +import top.xyquan.ecomdmbbackend.modules.media.service.MediaFileService; +import top.xyquan.ecomdmbbackend.utils.FileUploadUtils; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 文件资源池服务实现类 + */ +@Service +public class MediaFileServiceImpl extends ServiceImpl + implements MediaFileService { + + private final CurrentUserContext currentUserContext; + + public MediaFileServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional + public MediaFileVO uploadFile(MediaFileDTO mediaFileDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 创建文件记录 + MediaFilePO mediaFile = new MediaFilePO(); + BeanUtils.copyProperties(mediaFileDTO, mediaFile); + + // 设置公司ID + mediaFile.setCompanyId(companyId); + + // 设置上传人ID + mediaFile.setUploadBy(currentUserContext.getCurrentUserId()); + + // 保存文件记录 + this.save(mediaFile); + + // 转换为VO并返回 + return convertToVO(mediaFile); + } + + @Override + @Transactional + public List batchUploadFiles(List mediaFileDTOList) { + if (mediaFileDTOList == null || mediaFileDTOList.isEmpty()) { + throw new BusinessException("文件列表不能为空"); + } + + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 批量创建文件记录 + List mediaFileList = mediaFileDTOList.stream() + .map(dto -> { + MediaFilePO mediaFile = new MediaFilePO(); + BeanUtils.copyProperties(dto, mediaFile); + + // 设置公司ID + mediaFile.setCompanyId(companyId); + + // 设置上传人ID + mediaFile.setUploadBy(currentUserContext.getCurrentUserId()); + + return mediaFile; + }) + .collect(Collectors.toList()); + + // 批量保存 + this.saveBatch(mediaFileList); + + // 转换为VO并返回 + return mediaFileList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + @Transactional + public MediaFileVO updateFile(MediaFileDTO mediaFileDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查文件是否存在且属于当前公司 + MediaFilePO existingFile = this.getById(mediaFileDTO.getId()); + if (existingFile == null) { + throw new BusinessException("文件不存在"); + } + + // 验证文件是否属于当前公司 + if (!companyId.equals(existingFile.getCompanyId())) { + throw new BusinessException("无权操作此文件"); + } + + // 更新文件信息 + MediaFilePO mediaFile = new MediaFilePO(); + BeanUtils.copyProperties(mediaFileDTO, mediaFile); + mediaFile.setId(mediaFileDTO.getId()); // 确保ID正确设置 + mediaFile.setCompanyId(companyId); // 设置公司ID + + // 更新文件记录 + this.updateById(mediaFile); + + // 转换为VO并返回 + return convertToVO(mediaFile); + } + + @Override + public void deleteFile(Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查文件是否存在且属于当前公司 + MediaFilePO mediaFile = this.getById(id); + if (mediaFile == null) { + throw new BusinessException("文件不存在"); + } + + // 验证文件是否属于当前公司 + if (!companyId.equals(mediaFile.getCompanyId())) { + throw new BusinessException("无权操作此文件"); + } + + // 删除物理文件 + FileUploadUtils.deleteFile(mediaFile.getUrl()); + + // 删除文件记录 + this.removeById(id); + } + + /** + * 转换为VO + */ + private MediaFileVO convertToVO(MediaFilePO mediaFile) { + MediaFileVO mediaFileVO = new MediaFileVO(); + BeanUtils.copyProperties(mediaFile, mediaFileVO); + return mediaFileVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaImageServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaImageServiceImpl.java new file mode 100644 index 00000000..82aa07a5 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/media/service/impl/MediaImageServiceImpl.java @@ -0,0 +1,166 @@ +package top.xyquan.ecomdmbbackend.modules.media.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.media.mapper.MediaImageMapper; +import top.xyquan.ecomdmbbackend.modules.media.model.dto.MediaImageDTO; +import top.xyquan.ecomdmbbackend.modules.media.model.po.MediaImagePO; +import top.xyquan.ecomdmbbackend.modules.media.model.vo.MediaImageVO; +import top.xyquan.ecomdmbbackend.modules.media.service.MediaImageService; +import top.xyquan.ecomdmbbackend.utils.FileUploadUtils; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 图片资源池服务实现类 + */ +@Service +public class MediaImageServiceImpl extends ServiceImpl + implements MediaImageService { + + private final CurrentUserContext currentUserContext; + + public MediaImageServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional + public MediaImageVO uploadImage(MediaImageDTO mediaImageDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 创建图片记录 + MediaImagePO mediaImage = new MediaImagePO(); + BeanUtils.copyProperties(mediaImageDTO, mediaImage); + + // 设置公司ID + mediaImage.setCompanyId(companyId); + + // 设置默认值 + if (mediaImage.getType() == null) { + mediaImage.setType("其他"); + } + + // 设置上传人ID + mediaImage.setUploadBy(currentUserContext.getCurrentUserId()); + + // 保存图片记录 + this.save(mediaImage); + + // 转换为VO并返回 + return convertToVO(mediaImage); + } + + @Override + @Transactional + public List batchUploadImages(List mediaImageDTOList) { + if (mediaImageDTOList == null || mediaImageDTOList.isEmpty()) { + throw new BusinessException("图片列表不能为空"); + } + + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 批量创建图片记录 + List mediaImageList = mediaImageDTOList.stream() + .map(dto -> { + MediaImagePO mediaImage = new MediaImagePO(); + BeanUtils.copyProperties(dto, mediaImage); + + // 设置公司ID + mediaImage.setCompanyId(companyId); + + // 设置默认值 + if (mediaImage.getType() == null) { + mediaImage.setType("其他"); + } + + // 设置上传人ID + mediaImage.setUploadBy(currentUserContext.getCurrentUserId()); + + return mediaImage; + }) + .collect(Collectors.toList()); + + // 批量保存 + this.saveBatch(mediaImageList); + + // 转换为VO并返回 + return mediaImageList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + @Transactional + public MediaImageVO updateImage(MediaImageDTO mediaImageDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查图片是否存在且属于当前公司 + MediaImagePO existingImage = this.getById(mediaImageDTO.getId()); + if (existingImage == null) { + throw new BusinessException("图片不存在"); + } + + // 验证图片是否属于当前公司 + if (!companyId.equals(existingImage.getCompanyId())) { + throw new BusinessException("无权操作此图片"); + } + + // 更新图片信息 + MediaImagePO mediaImage = new MediaImagePO(); + BeanUtils.copyProperties(mediaImageDTO, mediaImage); + mediaImage.setId(mediaImageDTO.getId()); // 确保ID正确设置 + mediaImage.setCompanyId(companyId); // 设置公司ID + + // 设置默认值 + if (mediaImage.getType() == null) { + mediaImage.setType("其他"); + } + + // 更新图片记录 + this.updateById(mediaImage); + + // 转换为VO并返回 + return convertToVO(mediaImage); + } + + @Override + public void deleteImage(Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查图片是否存在且属于当前公司 + MediaImagePO mediaImage = this.getById(id); + if (mediaImage == null) { + throw new BusinessException("图片不存在"); + } + + // 验证图片是否属于当前公司 + if (!companyId.equals(mediaImage.getCompanyId())) { + throw new BusinessException("无权操作此图片"); + } + + // 删除物理文件 + FileUploadUtils.deleteFile(mediaImage.getUrl()); + + // 删除图片记录 + this.removeById(id); + } + + /** + * 转换为VO + */ + private MediaImageVO convertToVO(MediaImagePO mediaImage) { + MediaImageVO mediaImageVO = new MediaImageVO(); + BeanUtils.copyProperties(mediaImage, mediaImageVO); + return mediaImageVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyController.java new file mode 100644 index 00000000..57707ee7 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyController.java @@ -0,0 +1,66 @@ +package top.xyquan.ecomdmbbackend.modules.org.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CreateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.UpdateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CompanyFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyVO; +import top.xyquan.ecomdmbbackend.modules.org.service.CompanyService; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; + +/** + * 公司管理控制器 + */ +@Tag(name = "公司管理", description = "公司的增删改查接口") +@RestController +@RequestMapping("/company") +public class CompanyController { + + private final CompanyService companyService; + + public CompanyController(CompanyService companyService) { + this.companyService = companyService; + } + + @Operation(summary = "创建公司", description = "创建新的公司") + @PostMapping("/create") + @RequireRole(description = "创建公司", allowUser = false) + public ApiResponse createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) { + CompanyVO companyVO = companyService.createCompany(createCompanyDTO); + return ApiResponse.success(companyVO); + } + + @Operation(summary = "更新公司", description = "更新现有公司信息") + @PutMapping("/update/{id}") + @RequireRole(description = "更新公司", allowUser = false) + public ApiResponse updateCompany(@Valid @RequestBody UpdateCompanyDTO updateCompanyDTO, + @PathVariable Long id) { + CompanyVO companyVO = companyService.updateCompany(updateCompanyDTO, id); + return ApiResponse.success(companyVO); + } + + @Operation(summary = "删除公司", description = "删除指定公司") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除公司", allowUser = false) + public ApiResponse deleteCompany( + @Parameter(description = "公司ID") @PathVariable Long id) { + companyService.deleteCompany(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页查询公司列表", description = "分页查询公司列表,支持多种过滤条件") + @PostMapping("/page") + @RequireRole(description = "查询公司列表", allowUser = true) + public ApiResponse> getCompanyPage( + @Valid @RequestBody PageQueryDTO pageQuery) { + PageResultVO pageResult = companyService.getCompanyPage(pageQuery); + return ApiResponse.success(pageResult); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyMenuController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyMenuController.java new file mode 100644 index 00000000..afb16d7f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/CompanyMenuController.java @@ -0,0 +1,76 @@ +package top.xyquan.ecomdmbbackend.modules.org.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.CreateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.UpdateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyMenuVO; +import top.xyquan.ecomdmbbackend.modules.org.service.CompanyMenuService; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; + +import java.util.List; + +/** + * 公司菜单管理控制器 + */ +@Tag(name = "公司菜单管理", description = "公司菜单的增删改查接口") +@RestController +@RequestMapping("/company-menu") +public class CompanyMenuController { + + private final CompanyMenuService companyMenuService; + + public CompanyMenuController(CompanyMenuService companyMenuService) { + this.companyMenuService = companyMenuService; + } + + @Operation(summary = "创建公司菜单", description = "创建新的公司菜单") + @PostMapping("/create") + @RequireRole(description = "创建公司菜单", allowUser = false) + public ApiResponse createCompanyMenu(@Valid @RequestBody CreateCompanyMenuDTO createCompanyMenuDTO) { + CompanyMenuVO companyMenuVO = companyMenuService.createCompanyMenu(createCompanyMenuDTO); + return ApiResponse.success(companyMenuVO); + } + + @Operation(summary = "更新公司菜单", description = "更新现有公司菜单信息") + @PutMapping("/update/{id}") + @RequireRole(description = "更新公司菜单", allowUser = false) + public ApiResponse updateCompanyMenu(@Valid @RequestBody UpdateCompanyMenuDTO updateCompanyMenuDTO, + @PathVariable Long id) { + CompanyMenuVO companyMenuVO = companyMenuService.updateCompanyMenu(updateCompanyMenuDTO, id); + return ApiResponse.success(companyMenuVO); + } + + @Operation(summary = "删除公司菜单", description = "删除指定公司菜单") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除公司菜单", allowUser = false) + public ApiResponse deleteCompanyMenu( + @Parameter(description = "公司菜单ID") @PathVariable Long id) { + companyMenuService.deleteCompanyMenu(id); + return ApiResponse.success(); + } + + @Operation(summary = "批量创建公司菜单", description = "批量创建公司菜单权限关联") + @PostMapping("/batch-create/{id}") + @RequireRole(description = "批量创建公司菜单", allowUser = false) + public ApiResponse> batchCreateCompanyMenu( + @Parameter(description = "公司ID") @PathVariable Long id, + @Parameter(description = "菜单ID列表") @RequestBody List menuIds) { + List result = companyMenuService.batchCreateCompanyMenu(id, menuIds); + return ApiResponse.success(result); + } + + @Operation(summary = "批量删除公司菜单", description = "批量删除公司菜单权限关联") + @DeleteMapping("/batch-delete/{id}") + @RequireRole(description = "批量删除公司菜单", allowUser = false) + public ApiResponse batchDeleteCompanyMenu( + @Parameter(description = "公司ID") @PathVariable Long id, + @Parameter(description = "菜单ID列表") @RequestBody List menuIds) { + companyMenuService.batchDeleteCompanyMenu(id, menuIds); + return ApiResponse.success(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/DepartmentController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/DepartmentController.java new file mode 100644 index 00000000..2907a890 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/DepartmentController.java @@ -0,0 +1,66 @@ +package top.xyquan.ecomdmbbackend.modules.org.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.CreateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.UpdateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.DepartmentFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.DepartmentVO; +import top.xyquan.ecomdmbbackend.modules.org.service.DepartmentService; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; + +/** + * 部门管理控制器 + */ +@Tag(name = "部门管理", description = "部门的增删改查接口") +@RestController +@RequestMapping("/department") +public class DepartmentController { + + private final DepartmentService departmentService; + + public DepartmentController(DepartmentService departmentService) { + this.departmentService = departmentService; + } + + @Operation(summary = "创建部门", description = "创建新的部门") + @PostMapping("/create") + @RequireRole(description = "创建部门", allowUser = false) + public ApiResponse createDepartment(@Valid @RequestBody CreateDepartmentDTO createDepartmentDTO) { + DepartmentVO departmentVO = departmentService.createDepartment(createDepartmentDTO); + return ApiResponse.success(departmentVO); + } + + @Operation(summary = "更新部门", description = "更新现有部门信息") + @PutMapping("/update/{id}") + @RequireRole(description = "更新部门", allowUser = false) + public ApiResponse updateDepartment(@Valid @RequestBody UpdateDepartmentDTO updateDepartmentDTO, + @PathVariable Long id) { + DepartmentVO departmentVO = departmentService.updateDepartment(updateDepartmentDTO, id); + return ApiResponse.success(departmentVO); + } + + @Operation(summary = "删除部门", description = "删除指定部门") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除部门", allowUser = false) + public ApiResponse deleteDepartment( + @Parameter(description = "部门ID") @PathVariable Long id) { + departmentService.deleteDepartment(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取部门列表", description = "分页获取部门列表,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询部门列表", allowUser = true) + public ApiResponse> getDepartmentPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = departmentService.getDepartmentPage(pageQueryDTO); + return ApiResponse.success(result); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/PositionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/PositionController.java new file mode 100644 index 00000000..4eaee30d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/controller/PositionController.java @@ -0,0 +1,66 @@ +package top.xyquan.ecomdmbbackend.modules.org.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.CreatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.UpdatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.PositionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionVO; +import top.xyquan.ecomdmbbackend.modules.org.service.PositionService; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; + +/** + * 岗位管理控制器 + */ +@Tag(name = "岗位管理", description = "岗位的增删改查接口") +@RestController +@RequestMapping("/position") +public class PositionController { + + private final PositionService positionService; + + public PositionController(PositionService positionService) { + this.positionService = positionService; + } + + @Operation(summary = "创建岗位", description = "创建新的岗位") + @PostMapping("/create") + @RequireRole(description = "创建岗位", allowUser = false) + public ApiResponse createPosition(@Valid @RequestBody CreatePositionDTO createPositionDTO) { + PositionVO positionVO = positionService.createPosition(createPositionDTO); + return ApiResponse.success(positionVO); + } + + @Operation(summary = "更新岗位", description = "更新现有岗位信息") + @PutMapping("/update/{id}") + @RequireRole(description = "更新岗位", allowUser = false) + public ApiResponse updatePosition(@Valid @RequestBody UpdatePositionDTO updatePositionDTO, + @PathVariable Long id) { + PositionVO positionVO = positionService.updatePosition(updatePositionDTO, id); + return ApiResponse.success(positionVO); + } + + @Operation(summary = "删除岗位", description = "删除指定岗位") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除岗位", allowUser = false) + public ApiResponse deletePosition( + @Parameter(description = "岗位ID") @PathVariable Long id) { + positionService.deletePosition(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取岗位列表", description = "分页获取岗位列表,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询岗位列表", allowUser = true) + public ApiResponse> getPositionPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = positionService.getPositionPage(pageQueryDTO); + return ApiResponse.success(result); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMapper.java new file mode 100644 index 00000000..90150b53 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.org.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyPO; + +/** + * 公司Mapper + */ +@Mapper +public interface CompanyMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMenuMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMenuMapper.java new file mode 100644 index 00000000..1a300649 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/CompanyMenuMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.org.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyMenuPO; + +/** + * 公司菜单Mapper + */ +@Mapper +public interface CompanyMenuMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/DepartmentMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/DepartmentMapper.java new file mode 100644 index 00000000..a434897e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/DepartmentMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.org.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.org.model.po.DepartmentPO; + +/** + * 部门Mapper + */ +@Mapper +public interface DepartmentMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionCompanyMenuMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionCompanyMenuMapper.java new file mode 100644 index 00000000..648968a1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionCompanyMenuMapper.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.org.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import top.xyquan.ecomdmbbackend.modules.org.model.po.PositionCompanyMenuPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO; + +import java.util.List; + +/** + * 岗位公司菜单权限Mapper接口 + */ +@Mapper +public interface PositionCompanyMenuMapper extends BaseMapper { + + /** + * 根据岗位ID查询菜单权限列表 + * + * @param positionId 岗位ID + * @return 菜单权限列表 + */ + List selectMenusByPositionId(@Param("positionId") Long positionId); + + /** + * 根据岗位ID列表查询菜单权限列表 + * + * @param positionIds 岗位ID列表 + * @return 菜单权限列表 + */ + List selectMenusByPositionIds(@Param("positionIds") List positionIds); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionMapper.java new file mode 100644 index 00000000..2ffbb050 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/mapper/PositionMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.org.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.org.model.po.PositionPO; + +/** + * 岗位Mapper + */ +@Mapper +public interface PositionMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyDTO.java new file mode 100644 index 00000000..e9e2feff --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyDTO.java @@ -0,0 +1,70 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 公司DTO + */ +@Data +@Schema(description = "公司DTO") +public class CompanyDTO { + + /** + * 公司ID(更新时使用) + */ + @Schema(description = "公司ID(更新时使用)", example = "1") + private Long id; + + /** + * 公司名称 + */ + @Schema(description = "公司名称", example = "某某科技有限公司", required = true) + @NotBlank(message = "公司名称不能为空") + private String name; + + /** + * 公司地址 + */ + @Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号") + private String address; + + /** + * 联系人 + */ + @Schema(description = "联系人", example = "张三") + private String contactPerson; + + /** + * 联系电话 + */ + @Schema(description = "联系电话", example = "13800138000") + private String contactPhone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "contact@company.com") + private String email; + + /** + * logo + */ + @Schema(description = "公司logo", example = "https://example.com/logo.png") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 订阅到期时间 + */ + @Schema(description = "订阅到期时间", example = "2024-12-31T23:59:59") + private LocalDateTime expireTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyFilterDTO.java new file mode 100644 index 00000000..033a7b43 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CompanyFilterDTO.java @@ -0,0 +1,48 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 公司分页查询过滤DTO + */ +@Data +@Schema(description = "公司分页查询过滤DTO") +public class CompanyFilterDTO { + + /** + * 公司名称(模糊查询) + */ + @Schema(description = "公司名称(模糊查询)", example = "科技") + private String name; + + /** + * 联系人(模糊查询) + */ + @Schema(description = "联系人(模糊查询)", example = "张") + private String contactPerson; + + /** + * 联系电话(精确查询) + */ + @Schema(description = "联系电话(精确查询)", example = "13800138000") + private String contactPhone; + + /** + * 邮箱(精确查询) + */ + @Schema(description = "邮箱(精确查询)", example = "contact@company.com") + private String email; + + /** + * 状态查询 + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 过期状态查询 + */ + @Schema(description = "是否过期", example = "false", allowableValues = { "true", "false" }) + private Boolean expired; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CreateCompanyDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CreateCompanyDTO.java new file mode 100644 index 00000000..0b10443c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/CreateCompanyDTO.java @@ -0,0 +1,64 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 创建公司DTO + */ +@Data +@Schema(description = "创建公司DTO") +public class CreateCompanyDTO { + + /** + * 公司名称 + */ + @Schema(description = "公司名称", example = "某某科技有限公司", required = true) + @NotBlank(message = "公司名称不能为空") + private String name; + + /** + * 公司地址 + */ + @Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号") + private String address; + + /** + * 联系人 + */ + @Schema(description = "联系人", example = "张三") + private String contactPerson; + + /** + * 联系电话 + */ + @Schema(description = "联系电话", example = "13800138000") + private String contactPhone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "contact@company.com") + private String email; + + /** + * logo + */ + @Schema(description = "公司logo", example = "https://example.com/logo.png") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 订阅到期时间 + */ + @Schema(description = "订阅到期时间", example = "2024-12-31T23:59:59") + private LocalDateTime expireTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/UpdateCompanyDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/UpdateCompanyDTO.java new file mode 100644 index 00000000..77557e74 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/UpdateCompanyDTO.java @@ -0,0 +1,64 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 更新公司DTO + */ +@Data +@Schema(description = "更新公司DTO") +public class UpdateCompanyDTO { + + /** + * 公司名称 + */ + @Schema(description = "公司名称", example = "某某科技有限公司", required = true) + @NotBlank(message = "公司名称不能为空") + private String name; + + /** + * 公司地址 + */ + @Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号") + private String address; + + /** + * 联系人 + */ + @Schema(description = "联系人", example = "张三") + private String contactPerson; + + /** + * 联系电话 + */ + @Schema(description = "联系电话", example = "13800138000") + private String contactPhone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "contact@company.com") + private String email; + + /** + * logo + */ + @Schema(description = "公司logo", example = "https://example.com/logo.png") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 订阅到期时间 + */ + @Schema(description = "订阅到期时间", example = "2024-12-31T23:59:59") + private LocalDateTime expireTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/BatchCompanyMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/BatchCompanyMenuDTO.java new file mode 100644 index 00000000..47558392 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/BatchCompanyMenuDTO.java @@ -0,0 +1,30 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +/** + * 批量操作公司菜单DTO + */ +@Data +@Schema(description = "批量操作公司菜单DTO") +public class BatchCompanyMenuDTO { + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 菜单ID列表 + */ + @Schema(description = "菜单ID列表", example = "[1, 2, 3]", required = true) + @NotEmpty(message = "菜单ID列表不能为空") + private List menuIds; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CompanyMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CompanyMenuDTO.java new file mode 100644 index 00000000..bd6d6fa1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CompanyMenuDTO.java @@ -0,0 +1,69 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 公司菜单DTO + */ +@Data +@Schema(description = "公司菜单DTO") +public class CompanyMenuDTO { + + /** + * 关联ID(更新时使用) + */ + @Schema(description = "关联ID(更新时使用)", example = "1") + private Long id; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 父级ID + */ + @Schema(description = "父级ID", example = "1") + private Long parentId; + + /** + * 菜单ID + */ + @Schema(description = "菜单ID", example = "1", required = true) + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + /** + * 状态 (0-禁用 1-启用) + */ + @Schema(description = "菜单状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 公司自定义菜单名称 + */ + @Schema(description = "公司自定义菜单名称", example = "自定义菜单") + private String customName; + + /** + * 公司自定义菜单标题 + */ + @Schema(description = "公司自定义菜单标题", example = "自定义标题") + private String customTitle; + + /** + * 公司自定义菜单图标 + */ + @Schema(description = "公司自定义菜单图标", example = "icon-custom") + private String customIcon; + + /** + * 公司自定义排序 + */ + @Schema(description = "公司自定义排序", example = "1") + private Integer customOrder; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CreateCompanyMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CreateCompanyMenuDTO.java new file mode 100644 index 00000000..72811b2b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/CreateCompanyMenuDTO.java @@ -0,0 +1,63 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 创建公司菜单DTO + */ +@Data +@Schema(description = "创建公司菜单DTO") +public class CreateCompanyMenuDTO { + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 父级ID + */ + @Schema(description = "父级ID", example = "1") + private Long parentId; + + /** + * 菜单ID + */ + @Schema(description = "菜单ID", example = "1", required = true) + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + /** + * 状态 (0-禁用 1-启用) + */ + @Schema(description = "菜单状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 公司自定义菜单名称 + */ + @Schema(description = "公司自定义菜单名称", example = "自定义菜单") + private String customName; + + /** + * 公司自定义菜单标题 + */ + @Schema(description = "公司自定义菜单标题", example = "自定义标题") + private String customTitle; + + /** + * 公司自定义菜单图标 + */ + @Schema(description = "公司自定义菜单图标", example = "icon-custom") + private String customIcon; + + /** + * 公司自定义排序 + */ + @Schema(description = "公司自定义排序", example = "1") + private Integer customOrder; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/UpdateCompanyMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/UpdateCompanyMenuDTO.java new file mode 100644 index 00000000..5f6a20b8 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/company/menu/UpdateCompanyMenuDTO.java @@ -0,0 +1,63 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 更新公司菜单DTO + */ +@Data +@Schema(description = "更新公司菜单DTO") +public class UpdateCompanyMenuDTO { + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 父级ID + */ + @Schema(description = "父级ID", example = "1") + private Long parentId; + + /** + * 菜单ID + */ + @Schema(description = "菜单ID", example = "1", required = true) + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + /** + * 状态 (0-禁用 1-启用) + */ + @Schema(description = "菜单状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 公司自定义菜单名称 + */ + @Schema(description = "公司自定义菜单名称", example = "自定义菜单") + private String customName; + + /** + * 公司自定义菜单标题 + */ + @Schema(description = "公司自定义菜单标题", example = "自定义标题") + private String customTitle; + + /** + * 公司自定义菜单图标 + */ + @Schema(description = "公司自定义菜单图标", example = "icon-custom") + private String customIcon; + + /** + * 公司自定义排序 + */ + @Schema(description = "公司自定义排序", example = "1") + private Integer customOrder; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/CreateDepartmentDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/CreateDepartmentDTO.java new file mode 100644 index 00000000..3654fa2b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/CreateDepartmentDTO.java @@ -0,0 +1,38 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.department; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 创建部门DTO + */ +@Data +@Schema(description = "创建部门DTO") +public class CreateDepartmentDTO { + + /** + * 部门名称 + */ + @Schema(description = "部门名称", example = "技术部", required = true) + @NotBlank(message = "部门名称不能为空") + private String name; + + /** + * 部门父级ID + */ + @Schema(description = "部门父级ID", example = "1") + private Long parentId; + + /** + * 描述 + */ + @Schema(description = "部门描述", example = "负责公司技术研发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "部门状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentDTO.java new file mode 100644 index 00000000..0fbdc17e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentDTO.java @@ -0,0 +1,52 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.department; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 部门DTO + */ +@Data +@Schema(description = "部门DTO") +public class DepartmentDTO { + + /** + * 部门ID(更新时使用) + */ + @Schema(description = "部门ID(更新时使用)", example = "1") + private Long id; + + /** + * 部门名称 + */ + @Schema(description = "部门名称", example = "技术部", required = true) + @NotBlank(message = "部门名称不能为空") + private String name; + + /** + * 部门父级ID + */ + @Schema(description = "部门父级ID", example = "1") + private Long parentId; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 描述 + */ + @Schema(description = "部门描述", example = "负责公司技术研发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "部门状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentFilterDTO.java new file mode 100644 index 00000000..810f9a85 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/DepartmentFilterDTO.java @@ -0,0 +1,30 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.department; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 部门分页查询过滤DTO + */ +@Data +@Schema(description = "部门分页查询过滤DTO") +public class DepartmentFilterDTO { + + /** + * 部门名称(模糊查询) + */ + @Schema(description = "部门名称(模糊查询)", example = "技术") + private String name; + + /** + * 父级部门ID + */ + @Schema(description = "父级部门ID", example = "1") + private Long parentId; + + /** + * 状态 + */ + @Schema(description = "部门状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/UpdateDepartmentDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/UpdateDepartmentDTO.java new file mode 100644 index 00000000..cd14ae00 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/department/UpdateDepartmentDTO.java @@ -0,0 +1,38 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.department; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 更新部门DTO + */ +@Data +@Schema(description = "更新部门DTO") +public class UpdateDepartmentDTO { + + /** + * 部门名称 + */ + @Schema(description = "部门名称", example = "技术部", required = true) + @NotBlank(message = "部门名称不能为空") + private String name; + + /** + * 部门父级ID + */ + @Schema(description = "部门父级ID", example = "1") + private Long parentId; + + /** + * 描述 + */ + @Schema(description = "部门描述", example = "负责公司技术研发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "部门状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/BatchAssignPositionMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/BatchAssignPositionMenuDTO.java new file mode 100644 index 00000000..76ba9324 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/BatchAssignPositionMenuDTO.java @@ -0,0 +1,30 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.position; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 批量分配岗位菜单权限DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BatchAssignPositionMenuDTO { + + /** + * 岗位ID + */ + @NotNull(message = "岗位ID不能为空") + private Long positionId; + + /** + * 公司菜单权限ID列表 + */ + @NotEmpty(message = "菜单权限列表不能为空") + private List companyMenuIds; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/CreatePositionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/CreatePositionDTO.java new file mode 100644 index 00000000..7601dc35 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/CreatePositionDTO.java @@ -0,0 +1,44 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.position; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 创建岗位DTO + */ +@Data +@Schema(description = "创建岗位DTO") +public class CreatePositionDTO { + + /** + * 岗位名称 + */ + @Schema(description = "岗位名称", example = "软件工程师", required = true) + @NotBlank(message = "岗位名称不能为空") + private String name; + + /** + * 岗位编码 + */ + @Schema(description = "岗位编码", example = "SE001") + private String code; + + /** + * 部门ID + */ + @Schema(description = "部门ID", example = "1") + private Long departmentId; + + /** + * 描述 + */ + @Schema(description = "岗位描述", example = "负责系统开发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "岗位状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionDTO.java new file mode 100644 index 00000000..8e02601e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionDTO.java @@ -0,0 +1,58 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.position; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 岗位DTO + */ +@Data +@Schema(description = "岗位DTO") +public class PositionDTO { + + /** + * 岗位ID(更新时使用) + */ + @Schema(description = "岗位ID(更新时使用)", example = "1") + private Long id; + + /** + * 岗位名称 + */ + @Schema(description = "岗位名称", example = "软件工程师", required = true) + @NotBlank(message = "岗位名称不能为空") + private String name; + + /** + * 岗位编码 + */ + @Schema(description = "岗位编码", example = "SE001") + private String code; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1", required = true) + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 部门ID + */ + @Schema(description = "部门ID", example = "1") + private Long departmentId; + + /** + * 描述 + */ + @Schema(description = "岗位描述", example = "负责系统开发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "岗位状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionFilterDTO.java new file mode 100644 index 00000000..368e5b66 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/PositionFilterDTO.java @@ -0,0 +1,24 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.position; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 岗位分页查询过滤DTO + */ +@Data +@Schema(description = "岗位分页查询过滤DTO") +public class PositionFilterDTO { + + /** + * 岗位名称(模糊查询) + */ + @Schema(description = "岗位名称(模糊查询)", example = "工程师") + private String name; + + /** + * 状态 + */ + @Schema(description = "岗位状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/UpdatePositionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/UpdatePositionDTO.java new file mode 100644 index 00000000..cf33d7fb --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/dto/position/UpdatePositionDTO.java @@ -0,0 +1,44 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.dto.position; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 更新岗位DTO + */ +@Data +@Schema(description = "更新岗位DTO") +public class UpdatePositionDTO { + + /** + * 岗位名称 + */ + @Schema(description = "岗位名称", example = "软件工程师", required = true) + @NotBlank(message = "岗位名称不能为空") + private String name; + + /** + * 岗位编码 + */ + @Schema(description = "岗位编码", example = "SE001") + private String code; + + /** + * 部门ID + */ + @Schema(description = "部门ID", example = "1") + private Long departmentId; + + /** + * 描述 + */ + @Schema(description = "岗位描述", example = "负责系统开发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "岗位状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyMenuPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyMenuPO.java new file mode 100644 index 00000000..1a9690cc --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyMenuPO.java @@ -0,0 +1,94 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 公司菜单权限关联实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("org_company_menu") +public class CompanyMenuPO { + + /** + * 关联ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 父级ID + */ + @TableField("parent_id") + private Long parentId; + + /** + * 菜单ID + */ + @TableField("menu_id") + private Long menuId; + + /** + * 状态 (0-禁用 1-启用) + */ + @TableField("status") + private Integer status; + + /** + * 公司自定义菜单名称 + */ + @TableField("custom_name") + private String customName; + + /** + * 公司自定义菜单标题 + */ + @TableField("custom_title") + private String customTitle; + + /** + * 公司自定义菜单图标 + */ + @TableField("custom_icon") + private String customIcon; + + /** + * 公司自定义排序 + */ + @TableField("custom_order") + private Integer customOrder; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyPO.java new file mode 100644 index 00000000..0614846a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/CompanyPO.java @@ -0,0 +1,100 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 公司实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("org_company") +public class CompanyPO { + + /** + * 公司ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司名称 + */ + @TableField("name") + private String name; + + /** + * 订阅到期时间 + */ + @TableField("expiration") + private LocalDateTime expiration; + + /** + * 公司地址 + */ + @TableField("address") + private String address; + + /** + * 联系人 + */ + @TableField("contact_person") + private String contactPerson; + + /** + * 联系电话 + */ + @TableField("contact_phone") + private String contactPhone; + + /** + * 邮箱 + */ + @TableField("email") + private String email; + + /** + * logo + */ + @TableField("logo") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @TableField("status") + private Integer status; + + /** + * 订阅到期时间 + */ + @TableField("expire_time") + private LocalDateTime expireTime; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/DepartmentPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/DepartmentPO.java new file mode 100644 index 00000000..f8117887 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/DepartmentPO.java @@ -0,0 +1,76 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 部门实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("org_department") +public class DepartmentPO { + + /** + * 部门ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 部门名称 + */ + @TableField("name") + private String name; + + /** + * 部门父级ID + */ + @TableField("parent_id") + private Long parentId; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 描述 + */ + @TableField("remark") + private String remark; + + /** + * 状态 + */ + @TableField("status") + private Integer status; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人 + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人 + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionCompanyMenuPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionCompanyMenuPO.java new file mode 100644 index 00000000..ecb85921 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionCompanyMenuPO.java @@ -0,0 +1,46 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 岗位与公司菜单权限关联实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("rel_position_company_menu") +public class PositionCompanyMenuPO { + + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 岗位ID + */ + @TableField("position_id") + private Long positionId; + + /** + * 公司菜单权限ID + */ + @TableField("company_menu_id") + private Long companyMenuId; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionPO.java new file mode 100644 index 00000000..f7a293f1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/po/PositionPO.java @@ -0,0 +1,70 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 岗位实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("org_position") +public class PositionPO { + + /** + * 岗位ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 岗位名称 + */ + @TableField("name") + private String name; + + /** + * 岗位描述 + */ + @TableField("remark") + private String remark; + + /** + * 状态:(1-启用,0-禁用) + */ + @TableField("status") + private Integer status; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建者ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新者ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyMenuVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyMenuVO.java new file mode 100644 index 00000000..7ca278f6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyMenuVO.java @@ -0,0 +1,69 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO; + +import java.util.List; + +/** + * 公司菜单VO + */ +@Data +@Schema(description = "公司菜单VO") +public class CompanyMenuVO { + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1") + private Long id; + + /** + * 公司名称 + */ + @Schema(description = "公司名称", example = "某某科技有限公司") + private String name; + + /** + * 公司地址 + */ + @Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号") + private String address; + + /** + * 联系人 + */ + @Schema(description = "联系人", example = "张三") + private String contactPerson; + + /** + * 联系电话 + */ + @Schema(description = "联系电话", example = "13800138000") + private String contactPhone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "contact@company.com") + private String email; + + /** + * logo + */ + @Schema(description = "公司logo", example = "https://example.com/logo.png") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 菜单列表 + */ + @Schema(description = "菜单列表") + private List menus; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyVO.java new file mode 100644 index 00000000..b31fca3d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/CompanyVO.java @@ -0,0 +1,92 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 公司VO + */ +@Data +@Schema(description = "公司VO") +public class CompanyVO { + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1") + private Long id; + + /** + * 公司名称 + */ + @Schema(description = "公司名称", example = "某某科技有限公司") + private String name; + + /** + * 订阅到期时间 + */ + @Schema(description = "订阅到期时间", example = "2024-12-31T23:59:59") + private LocalDateTime expiration; + + /** + * 公司地址 + */ + @Schema(description = "公司地址", example = "北京市朝阳区xxx街道xxx号") + private String address; + + /** + * 联系人 + */ + @Schema(description = "联系人", example = "张三") + private String contactPerson; + + /** + * 联系电话 + */ + @Schema(description = "联系电话", example = "13800138000") + private String contactPhone; + + /** + * 邮箱 + */ + @Schema(description = "邮箱", example = "contact@company.com") + private String email; + + /** + * logo + */ + @Schema(description = "公司logo", example = "https://example.com/logo.png") + private String logo; + + /** + * 状态 (0-禁用 1-正常) + */ + @Schema(description = "公司状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 订阅到期时间 + */ + @Schema(description = "订阅到期时间", example = "2024-12-31T23:59:59") + private LocalDateTime expireTime; + + /** + * 创建时间 + */ + @Schema(description = "创建时间", example = "2024-01-01T10:00:00") + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @Schema(description = "更新时间", example = "2024-01-01T10:00:00") + private LocalDateTime updateTime; + + /** + * 是否过期 + */ + @Schema(description = "是否过期", example = "false") + private Boolean expired; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/DepartmentVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/DepartmentVO.java new file mode 100644 index 00000000..e2389d2d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/DepartmentVO.java @@ -0,0 +1,80 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 部门VO + */ +@Data +@Schema(description = "部门VO") +public class DepartmentVO { + + /** + * 部门ID + */ + @Schema(description = "部门ID", example = "1") + private Long id; + + /** + * 部门名称 + */ + @Schema(description = "部门名称", example = "技术部") + private String name; + + /** + * 部门父级ID + */ + @Schema(description = "部门父级ID", example = "1") + private Long parentId; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1") + private Long companyId; + + /** + * 描述 + */ + @Schema(description = "部门描述", example = "负责公司技术研发工作") + private String remark; + + /** + * 状态 + */ + @Schema(description = "部门状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 创建时间 + */ + @Schema(description = "创建时间", example = "2024-01-01T10:00:00") + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @Schema(description = "更新时间", example = "2024-01-01T10:00:00") + private LocalDateTime updateTime; + + /** + * 创建人 + */ + @Schema(description = "创建人ID", example = "1") + private Long createBy; + + /** + * 更新人 + */ + @Schema(description = "更新人ID", example = "1") + private Long updateBy; + + /** + * 子部门列表 + */ + private List children; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionMenuVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionMenuVO.java new file mode 100644 index 00000000..fa855112 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionMenuVO.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 岗位菜单权限VO + */ +@Data +public class PositionMenuVO { + + /** + * 关联ID + */ + private Long id; + + /** + * 岗位ID + */ + private Long positionId; + + /** + * 岗位名称 + */ + private String positionName; + + /** + * 公司菜单权限ID + */ + private Long companyMenuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 菜单标题 + */ + private String menuTitle; + + /** + * 创建时间 + */ + private LocalDateTime createTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionVO.java new file mode 100644 index 00000000..103eabbd --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/model/vo/PositionVO.java @@ -0,0 +1,68 @@ +package top.xyquan.ecomdmbbackend.modules.org.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 岗位VO + */ +@Data +@Schema(description = "岗位VO") +public class PositionVO { + + /** + * 岗位ID + */ + @Schema(description = "岗位ID", example = "1") + private Long id; + + /** + * 岗位名称 + */ + @Schema(description = "岗位名称", example = "软件工程师") + private String name; + + /** + * 岗位描述 + */ + @Schema(description = "岗位描述", example = "负责系统开发工作") + private String remark; + + /** + * 状态:(1-启用,0-禁用) + */ + @Schema(description = "岗位状态", example = "1", allowableValues = { "0", "1" }) + private Integer status; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1") + private Long companyId; + + /** + * 创建时间 + */ + @Schema(description = "创建时间", example = "2024-01-01T10:00:00") + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @Schema(description = "更新时间", example = "2024-01-01T10:00:00") + private LocalDateTime updateTime; + + /** + * 创建者ID + */ + @Schema(description = "创建者ID", example = "1") + private Long createBy; + + /** + * 更新者ID + */ + @Schema(description = "更新者ID", example = "1") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyMenuService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyMenuService.java new file mode 100644 index 00000000..75a51c13 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyMenuService.java @@ -0,0 +1,55 @@ +package top.xyquan.ecomdmbbackend.modules.org.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.CreateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.UpdateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyMenuPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyMenuVO; + +import java.util.List; + +/** + * 公司菜单服务接口 + */ +public interface CompanyMenuService extends IService { + + /** + * 创建公司菜单 + * + * @param createCompanyMenuDTO 公司菜单信息 + * @return 公司菜单信息 + */ + CompanyMenuVO createCompanyMenu(CreateCompanyMenuDTO createCompanyMenuDTO); + + /** + * 更新公司菜单 + * + * @param updateCompanyMenuDTO 公司菜单信息 + * @return 公司菜单信息 + */ + CompanyMenuVO updateCompanyMenu(UpdateCompanyMenuDTO updateCompanyMenuDTO, Long id); + + /** + * 删除公司菜单 + * + * @param id 公司菜单ID + */ + void deleteCompanyMenu(Long id); + + /** + * 批量创建公司菜单 + * + * @param companyId 公司ID + * @param menuIds 菜单ID列表 + * @return 创建结果 + */ + List batchCreateCompanyMenu(Long companyId, List menuIds); + + /** + * 批量删除公司菜单 + * + * @param companyId 公司ID + * @param menuIds 菜单ID列表 + */ + void batchDeleteCompanyMenu(Long companyId, List menuIds); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyService.java new file mode 100644 index 00000000..22aefdd8 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/CompanyService.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.modules.org.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CreateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.UpdateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CompanyFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyVO; + +/** + * 公司服务接口 + */ +public interface CompanyService extends IService { + + /** + * 创建公司 + * + * @param createCompanyDTO 公司信息 + * @return 公司信息 + */ + CompanyVO createCompany(CreateCompanyDTO createCompanyDTO); + + /** + * 更新公司 + * + * @param updateCompanyDTO 公司信息 + * @return 公司信息 + */ + CompanyVO updateCompany(UpdateCompanyDTO updateCompanyDTO, Long id); + + /** + * 删除公司 + * + * @param id 公司ID + */ + void deleteCompany(Long id); + + /** + * 分页查询公司列表 + * + * @param pageQuery 分页查询参数 + * @return 分页结果 + */ + PageResultVO getCompanyPage(PageQueryDTO pageQuery); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/DepartmentService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/DepartmentService.java new file mode 100644 index 00000000..a370aec7 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/DepartmentService.java @@ -0,0 +1,48 @@ +package top.xyquan.ecomdmbbackend.modules.org.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.CreateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.UpdateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.DepartmentFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.DepartmentPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.DepartmentVO; + +/** + * 部门服务接口 + */ +public interface DepartmentService extends IService { + + /** + * 创建部门 + * + * @param createDepartmentDTO 部门信息 + * @return 部门信息 + */ + DepartmentVO createDepartment(CreateDepartmentDTO createDepartmentDTO); + + /** + * 更新部门 + * + * @param updateDepartmentDTO 部门信息 + * @return 部门信息 + */ + DepartmentVO updateDepartment(UpdateDepartmentDTO updateDepartmentDTO, Long id); + + /** + * 删除部门 + * + * @param id 部门ID + */ + void deleteDepartment(Long id); + + /** + * 分页获取部门列表 + * + * @param pageQueryDTO 分页查询参数 + * @param queryDTO 查询过滤条件 + * @return 分页结果 + */ + PageResultVO getDepartmentPage(PageQueryDTO pageQueryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionCompanyMenuService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionCompanyMenuService.java new file mode 100644 index 00000000..72bf7527 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionCompanyMenuService.java @@ -0,0 +1,52 @@ +package top.xyquan.ecomdmbbackend.modules.org.service; + +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.BatchAssignPositionMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO; + +import java.util.List; + +/** + * 岗位公司菜单权限服务接口 + */ +public interface PositionCompanyMenuService { + + /** + * 批量分配岗位菜单权限 + * + * @param batchAssignDTO 批量分配DTO + */ + void batchAssignPositionMenus(BatchAssignPositionMenuDTO batchAssignDTO); + + /** + * 取消岗位菜单权限 + * + * @param positionId 岗位ID + * @param companyMenuId 公司菜单权限ID + */ + void removePositionMenu(Long positionId, Long companyMenuId); + + /** + * 根据岗位ID查询菜单权限列表 + * + * @param positionId 岗位ID + * @return 菜单权限列表 + */ + List getMenusByPositionId(Long positionId); + + /** + * 根据岗位ID列表查询菜单权限列表 + * + * @param positionIds 岗位ID列表 + * @return 菜单权限列表 + */ + List getMenusByPositionIds(List positionIds); + + /** + * 检查岗位是否有指定菜单权限 + * + * @param positionId 岗位ID + * @param companyMenuId 公司菜单权限ID + * @return 是否有权限 + */ + boolean hasPositionMenu(Long positionId, Long companyMenuId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionService.java new file mode 100644 index 00000000..08ed71a9 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/PositionService.java @@ -0,0 +1,48 @@ +package top.xyquan.ecomdmbbackend.modules.org.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.CreatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.UpdatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.PositionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.PositionPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionVO; + +/** + * 岗位服务接口 + */ +public interface PositionService extends IService { + + /** + * 创建岗位 + * + * @param createPositionDTO 岗位信息 + * @return 岗位信息 + */ + PositionVO createPosition(CreatePositionDTO createPositionDTO); + + /** + * 更新岗位 + * + * @param updatePositionDTO 岗位信息 + * @return 岗位信息 + */ + PositionVO updatePosition(UpdatePositionDTO updatePositionDTO, Long id); + + /** + * 删除岗位 + * + * @param id 岗位ID + */ + void deletePosition(Long id); + + /** + * 分页获取岗位列表 + * + * @param pageQueryDTO 分页查询参数 + * @param queryDTO 查询过滤条件 + * @return 分页结果 + */ + PageResultVO getPositionPage(PageQueryDTO pageQueryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java new file mode 100644 index 00000000..fc1ea9d2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java @@ -0,0 +1,183 @@ +package top.xyquan.ecomdmbbackend.modules.org.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.org.mapper.CompanyMenuMapper; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.CreateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.menu.UpdateCompanyMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyMenuPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyMenuVO; +import top.xyquan.ecomdmbbackend.modules.org.service.CompanyMenuService; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO; +import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService; +import top.xyquan.ecomdmbbackend.utils.SecurityUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 公司菜单服务实现类 + */ +@Service +public class CompanyMenuServiceImpl extends ServiceImpl + implements CompanyMenuService { + + private final MenuService menuService; + + public CompanyMenuServiceImpl(MenuService menuService) { + this.menuService = menuService; + } + + @Override + @Transactional + public CompanyMenuVO createCompanyMenu(CreateCompanyMenuDTO createCompanyMenuDTO) { + // 验证公司是否存在 + // 这里需要注入CompanyService,暂时跳过验证 + + // 验证菜单是否存在 + MenuPO menu = menuService.getById(createCompanyMenuDTO.getMenuId()); + if (menu == null) { + throw new BusinessException("菜单不存在"); + } + + // 检查是否已存在相同的公司菜单关联 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyMenuPO::getCompanyId, createCompanyMenuDTO.getCompanyId()) + .eq(CompanyMenuPO::getMenuId, createCompanyMenuDTO.getMenuId()); + if (this.count(wrapper) > 0) { + throw new BusinessException("该公司已关联此菜单"); + } + + // 创建公司菜单 + CompanyMenuPO companyMenu = new CompanyMenuPO(); + BeanUtils.copyProperties(createCompanyMenuDTO, companyMenu); + + // 从菜单表拷贝自定义字段 + companyMenu.setCustomName(menu.getName()); + companyMenu.setCustomTitle(menu.getTitle()); + companyMenu.setCustomIcon(menu.getIcon()); + companyMenu.setCustomOrder(menu.getOrder()); + + // 设置默认值 + if (companyMenu.getStatus() == null) { + companyMenu.setStatus(1); + } + + // 设置创建人ID + companyMenu.setCreateBy(SecurityUtils.getCurrentUserId()); + + // 保存公司菜单 + this.save(companyMenu); + + // 转换为VO并返回 + return convertToVO(companyMenu); + } + + @Override + @Transactional + public CompanyMenuVO updateCompanyMenu(UpdateCompanyMenuDTO updateCompanyMenuDTO, Long id) { + // 检查公司菜单是否存在 + CompanyMenuPO existingCompanyMenu = this.getById(id); + if (existingCompanyMenu == null) { + throw new BusinessException("公司菜单不存在"); + } + + // 验证菜单是否存在 + MenuPO menu = menuService.getById(updateCompanyMenuDTO.getMenuId()); + if (menu == null) { + throw new BusinessException("菜单不存在"); + } + + // 检查是否已存在相同的公司菜单关联(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyMenuPO::getCompanyId, updateCompanyMenuDTO.getCompanyId()) + .eq(CompanyMenuPO::getMenuId, updateCompanyMenuDTO.getMenuId()) + .ne(CompanyMenuPO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("该公司已关联此菜单"); + } + + // 更新公司菜单 + CompanyMenuPO companyMenu = new CompanyMenuPO(); + BeanUtils.copyProperties(updateCompanyMenuDTO, companyMenu); + + // 从菜单表拷贝自定义字段 + companyMenu.setCustomName(menu.getName()); + companyMenu.setCustomTitle(menu.getTitle()); + companyMenu.setCustomIcon(menu.getIcon()); + companyMenu.setCustomOrder(menu.getOrder()); + + // 设置更新人ID + companyMenu.setUpdateBy(SecurityUtils.getCurrentUserId()); + + // 更新公司菜单 + this.updateById(companyMenu); + + // 转换为VO并返回 + return convertToVO(companyMenu); + } + + @Override + public void deleteCompanyMenu(Long id) { + // 检查公司菜单是否存在 + CompanyMenuPO companyMenu = this.getById(id); + if (companyMenu == null) { + throw new BusinessException("公司菜单不存在"); + } + + // 检查是否有子菜单 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyMenuPO::getParentId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("存在子菜单,无法删除"); + } + + // 删除公司菜单 + this.removeById(id); + } + + @Override + @Transactional + public List batchCreateCompanyMenu(Long companyId, List menuIds) { + List result = new ArrayList<>(); + + for (Long menuId : menuIds) { + CreateCompanyMenuDTO createCompanyMenuDTO = new CreateCompanyMenuDTO(); + createCompanyMenuDTO.setCompanyId(companyId); + createCompanyMenuDTO.setMenuId(menuId); + + try { + CompanyMenuVO companyMenuVO = createCompanyMenu(createCompanyMenuDTO); + result.add(companyMenuVO); + } catch (BusinessException e) { + // 如果已存在,跳过 + continue; + } + } + + return result; + } + + @Override + @Transactional + public void batchDeleteCompanyMenu(Long companyId, List menuIds) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyMenuPO::getCompanyId, companyId) + .in(CompanyMenuPO::getMenuId, menuIds); + + this.remove(wrapper); + } + + /** + * 转换为VO + */ + private CompanyMenuVO convertToVO(CompanyMenuPO companyMenu) { + CompanyMenuVO companyMenuVO = new CompanyMenuVO(); + BeanUtils.copyProperties(companyMenu, companyMenuVO); + return companyMenuVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyServiceImpl.java new file mode 100644 index 00000000..8aa3c57e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyServiceImpl.java @@ -0,0 +1,164 @@ +package top.xyquan.ecomdmbbackend.modules.org.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.mapper.CompanyMapper; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CreateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.UpdateCompanyDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.company.CompanyFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.CompanyPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.CompanyVO; +import top.xyquan.ecomdmbbackend.modules.org.service.CompanyService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 公司服务实现类 + */ +@Service +public class CompanyServiceImpl extends ServiceImpl implements CompanyService { + + private final CurrentUserContext currentUserContext; + + public CompanyServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + public CompanyVO createCompany(CreateCompanyDTO createCompanyDTO) { + // 检查公司名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyPO::getName, createCompanyDTO.getName()); + if (this.count(wrapper) > 0) { + throw new BusinessException("公司名称已存在"); + } + + // 创建公司 + CompanyPO company = new CompanyPO(); + BeanUtils.copyProperties(createCompanyDTO, company); + + // 设置默认值 + if (company.getStatus() == null) { + company.setStatus(1); + } + + // 设置创建人ID + company.setCreateBy(currentUserContext.getCurrentUserId()); + + // 保存公司 + this.save(company); + + // 转换为VO并返回 + return convertToVO(company); + } + + @Override + public CompanyVO updateCompany(UpdateCompanyDTO updateCompanyDTO, Long id) { + // 检查公司是否存在 + CompanyPO existingCompany = this.getById(id); + if (existingCompany == null) { + throw new BusinessException("公司不存在"); + } + + // 检查公司名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CompanyPO::getName, updateCompanyDTO.getName()) + .ne(CompanyPO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("公司名称已存在"); + } + + // 更新公司 + CompanyPO company = new CompanyPO(); + BeanUtils.copyProperties(updateCompanyDTO, company); + + // 设置更新人ID + company.setUpdateBy(currentUserContext.getCurrentUserId()); + + // 保存公司 + this.updateById(company); + + // 设置公司ID + company.setId(id); + // 转换为VO并返回 + return convertToVO(company); + } + + @Override + public void deleteCompany(Long id) { + // 检查公司是否存在 + CompanyPO company = this.getById(id); + if (company == null) { + throw new BusinessException("公司不存在"); + } + + // 删除公司 + this.removeById(id); + } + + @Override + public PageResultVO getCompanyPage(PageQueryDTO pageQuery) { + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + CompanyFilterDTO filterDTO = pageQuery.getFilters(); + if (filterDTO != null) { + if (StringUtils.hasText(filterDTO.getName())) { + wrapper.like(CompanyPO::getName, filterDTO.getName()); + } + if (StringUtils.hasText(filterDTO.getContactPerson())) { + wrapper.like(CompanyPO::getContactPerson, filterDTO.getContactPerson()); + } + if (StringUtils.hasText(filterDTO.getContactPhone())) { + wrapper.eq(CompanyPO::getContactPhone, filterDTO.getContactPhone()); + } + if (StringUtils.hasText(filterDTO.getEmail())) { + wrapper.eq(CompanyPO::getEmail, filterDTO.getEmail()); + } + if (filterDTO.getStatus() != null) { + wrapper.eq(CompanyPO::getStatus, filterDTO.getStatus()); + } + } + + // 排序 + wrapper.orderByDesc(CompanyPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQuery.getPage(), pageQuery.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为VO + List records = pageResult.getRecords().stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + + return PageResultVO.create(records, pageResult.getTotal(), pageQuery.getPage(), pageQuery.getPageSize()); + } + + /** + * 转换为VO + */ + private CompanyVO convertToVO(CompanyPO company) { + CompanyVO companyVO = new CompanyVO(); + BeanUtils.copyProperties(company, companyVO); + + // 计算是否过期 + if (company.getExpireTime() != null) { + companyVO.setExpired(company.getExpireTime().isBefore(LocalDateTime.now())); + } + + return companyVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/DepartmentServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/DepartmentServiceImpl.java new file mode 100644 index 00000000..88dd141a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/DepartmentServiceImpl.java @@ -0,0 +1,191 @@ +package top.xyquan.ecomdmbbackend.modules.org.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.mapper.DepartmentMapper; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.CreateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.UpdateDepartmentDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.department.DepartmentFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.DepartmentPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.DepartmentVO; +import top.xyquan.ecomdmbbackend.modules.org.service.DepartmentService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; + +/** + * 部门服务实现类 + */ +@Service +public class DepartmentServiceImpl extends ServiceImpl implements DepartmentService { + + private final CurrentUserContext currentUserContext; + + public DepartmentServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional + public DepartmentVO createDepartment(CreateDepartmentDTO createDepartmentDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 验证部门名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(DepartmentPO::getName, createDepartmentDTO.getName()) + .eq(DepartmentPO::getCompanyId, companyId); + if (this.count(wrapper) > 0) { + throw new BusinessException("部门名称已存在"); + } + + // 创建部门 + DepartmentPO department = new DepartmentPO(); + BeanUtils.copyProperties(createDepartmentDTO, department); + + // 设置公司ID + department.setCompanyId(companyId); + + // 设置默认值 + if (department.getStatus() == null) { + department.setStatus(1); + } + + // 设置创建人ID + department.setCreateBy(currentUserContext.getCurrentUserId()); + + // 保存部门 + this.save(department); + + // 转换为VO并返回 + return convertToVO(department); + } + + @Override + @Transactional + public DepartmentVO updateDepartment(UpdateDepartmentDTO updateDepartmentDTO, Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查部门是否存在且属于当前公司 + DepartmentPO existingDepartment = this.getById(id); + if (existingDepartment == null) { + throw new BusinessException("部门不存在"); + } + + // 验证部门是否属于当前公司 + if (!companyId.equals(existingDepartment.getCompanyId())) { + throw new BusinessException("无权操作此部门"); + } + + // 验证部门名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(DepartmentPO::getName, updateDepartmentDTO.getName()) + .eq(DepartmentPO::getCompanyId, companyId) + .ne(DepartmentPO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("部门名称已存在"); + } + + // 更新部门 + DepartmentPO department = new DepartmentPO(); + BeanUtils.copyProperties(updateDepartmentDTO, department); + department.setId(id); // 确保ID正确设置 + department.setCompanyId(companyId); // 设置公司ID + + // 设置更新人ID + department.setUpdateBy(currentUserContext.getCurrentUserId()); + + // 更新部门 + this.updateById(department); + + // 转换为VO并返回 + return convertToVO(department); + } + + @Override + public void deleteDepartment(Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查部门是否存在且属于当前公司 + DepartmentPO department = this.getById(id); + if (department == null) { + throw new BusinessException("部门不存在"); + } + + // 验证部门是否属于当前公司 + if (!companyId.equals(department.getCompanyId())) { + throw new BusinessException("无权操作此部门"); + } + + // 检查是否有子部门 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(DepartmentPO::getParentId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("存在子部门,无法删除"); + } + + // 删除部门 + this.removeById(id); + } + + @Override + public PageResultVO getDepartmentPage(PageQueryDTO pageQueryDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + DepartmentFilterDTO queryDTO = pageQueryDTO.getFilters(); + if (queryDTO != null) { + if (StringUtils.hasText(queryDTO.getName())) { + wrapper.like(DepartmentPO::getName, queryDTO.getName()); + } + if (queryDTO.getParentId() != null) { + wrapper.eq(DepartmentPO::getParentId, queryDTO.getParentId()); + } + if (queryDTO.getStatus() != null) { + wrapper.eq(DepartmentPO::getStatus, queryDTO.getStatus()); + } + } + // 强制添加公司ID过滤条件 + wrapper.eq(DepartmentPO::getCompanyId, companyId); + + // 排序 + wrapper.orderByAsc(DepartmentPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为VO + List records = pageResult.getRecords().stream() + .map(this::convertToVO) + .toList(); + PageResultVO result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(), + pageQueryDTO.getPageSize()); + + return result; + } + + /** + * 转换为VO + */ + private DepartmentVO convertToVO(DepartmentPO department) { + DepartmentVO departmentVO = new DepartmentVO(); + BeanUtils.copyProperties(department, departmentVO); + return departmentVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java new file mode 100644 index 00000000..2bdcbdb2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java @@ -0,0 +1,91 @@ +package top.xyquan.ecomdmbbackend.modules.org.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.org.mapper.PositionCompanyMenuMapper; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.BatchAssignPositionMenuDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.PositionCompanyMenuPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO; +import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.ArrayList; +import java.util.List; + +/** + * 岗位公司菜单权限服务实现类 + */ +@Service +public class PositionCompanyMenuServiceImpl implements PositionCompanyMenuService { + + private final PositionCompanyMenuMapper positionCompanyMenuMapper; + private final CurrentUserContext currentUserContext; + + public PositionCompanyMenuServiceImpl(PositionCompanyMenuMapper positionCompanyMenuMapper, + CurrentUserContext currentUserContext) { + this.positionCompanyMenuMapper = positionCompanyMenuMapper; + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void batchAssignPositionMenus(BatchAssignPositionMenuDTO batchAssignDTO) { + Long positionId = batchAssignDTO.getPositionId(); + List companyMenuIds = batchAssignDTO.getCompanyMenuIds(); + + // 先删除该岗位的所有菜单权限 + LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); + deleteWrapper.eq(PositionCompanyMenuPO::getPositionId, positionId); + positionCompanyMenuMapper.delete(deleteWrapper); + + // 批量插入新的菜单权限 + List positionMenus = new ArrayList<>(); + for (Long companyMenuId : companyMenuIds) { + PositionCompanyMenuPO positionMenu = new PositionCompanyMenuPO(); + positionMenu.setPositionId(positionId); + positionMenu.setCompanyMenuId(companyMenuId); + positionMenu.setCreateBy(currentUserContext.getCurrentUserId()); + positionMenus.add(positionMenu); + } + + if (!positionMenus.isEmpty()) { + positionMenus.forEach(positionCompanyMenuMapper::insert); + } + } + + @Override + public void removePositionMenu(Long positionId, Long companyMenuId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PositionCompanyMenuPO::getPositionId, positionId) + .eq(PositionCompanyMenuPO::getCompanyMenuId, companyMenuId); + + int result = positionCompanyMenuMapper.delete(wrapper); + if (result == 0) { + throw new BusinessException("岗位菜单权限不存在"); + } + } + + @Override + public List getMenusByPositionId(Long positionId) { + return positionCompanyMenuMapper.selectMenusByPositionId(positionId); + } + + @Override + public List getMenusByPositionIds(List positionIds) { + if (positionIds == null || positionIds.isEmpty()) { + return new ArrayList<>(); + } + return positionCompanyMenuMapper.selectMenusByPositionIds(positionIds); + } + + @Override + public boolean hasPositionMenu(Long positionId, Long companyMenuId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PositionCompanyMenuPO::getPositionId, positionId) + .eq(PositionCompanyMenuPO::getCompanyMenuId, companyMenuId); + + return positionCompanyMenuMapper.selectCount(wrapper) > 0; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionServiceImpl.java new file mode 100644 index 00000000..654dc994 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionServiceImpl.java @@ -0,0 +1,181 @@ +package top.xyquan.ecomdmbbackend.modules.org.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.org.mapper.PositionMapper; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.CreatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.UpdatePositionDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.dto.position.PositionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.org.model.po.PositionPO; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionVO; +import top.xyquan.ecomdmbbackend.modules.org.service.PositionService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; + +/** + * 岗位服务实现类 + */ +@Service +public class PositionServiceImpl extends ServiceImpl implements PositionService { + + private final CurrentUserContext currentUserContext; + + public PositionServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional + public PositionVO createPosition(CreatePositionDTO createPositionDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 验证岗位名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PositionPO::getName, createPositionDTO.getName()) + .eq(PositionPO::getCompanyId, companyId); + if (this.count(wrapper) > 0) { + throw new BusinessException("岗位名称已存在"); + } + + // 创建岗位 + PositionPO position = new PositionPO(); + BeanUtils.copyProperties(createPositionDTO, position); + + // 设置公司ID + position.setCompanyId(companyId); + + // 设置默认值 + if (position.getStatus() == null) { + position.setStatus(1); + } + + // 设置创建人ID + position.setCreateBy(currentUserContext.getCurrentUserId()); + + // 保存岗位 + this.save(position); + + // 转换为VO并返回 + return convertToVO(position); + } + + @Override + @Transactional + public PositionVO updatePosition(UpdatePositionDTO updatePositionDTO, Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查岗位是否存在且属于当前公司 + PositionPO existingPosition = this.getById(id); + if (existingPosition == null) { + throw new BusinessException("岗位不存在"); + } + + // 验证岗位是否属于当前公司 + if (!companyId.equals(existingPosition.getCompanyId())) { + throw new BusinessException("无权操作此岗位"); + } + + // 验证岗位名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PositionPO::getName, updatePositionDTO.getName()) + .eq(PositionPO::getCompanyId, companyId) + .ne(PositionPO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("岗位名称已存在"); + } + + // 更新岗位 + PositionPO position = new PositionPO(); + BeanUtils.copyProperties(updatePositionDTO, position); + position.setId(id); // 确保ID正确设置 + position.setCompanyId(companyId); // 设置公司ID + + // 设置更新人ID + position.setUpdateBy(currentUserContext.getCurrentUserId()); + + // 更新岗位 + this.updateById(position); + + // 转换为VO并返回 + return convertToVO(position); + } + + @Override + public void deletePosition(Long id) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 检查岗位是否存在且属于当前公司 + PositionPO position = this.getById(id); + if (position == null) { + throw new BusinessException("岗位不存在"); + } + + // 验证岗位是否属于当前公司 + if (!companyId.equals(position.getCompanyId())) { + throw new BusinessException("无权操作此岗位"); + } + + // 删除岗位 + this.removeById(id); + } + + @Override + public PageResultVO getPositionPage(PageQueryDTO pageQueryDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + PositionFilterDTO queryDTO = pageQueryDTO.getFilters(); + if (queryDTO != null) { + if (StringUtils.hasText(queryDTO.getName())) { + wrapper.like(PositionPO::getName, queryDTO.getName()); + } + if (queryDTO.getStatus() != null) { + wrapper.eq(PositionPO::getStatus, queryDTO.getStatus()); + } + } + // 强制添加公司ID过滤条件 + wrapper.eq(PositionPO::getCompanyId, companyId); + + // 排序 + wrapper.orderByAsc(PositionPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为VO + List records = pageResult.getRecords().stream() + .map(this::convertToVO) + .toList(); + PageResultVO result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(), + pageQueryDTO.getPageSize()); + + return result; + } + + /** + * 转换为VO + */ + private PositionVO convertToVO(PositionPO position) { + PositionVO positionVO = new PositionVO(); + BeanUtils.copyProperties(position, positionVO); + return positionVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanController.java new file mode 100644 index 00000000..804e1a9b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanController.java @@ -0,0 +1,62 @@ +package top.xyquan.ecomdmbbackend.modules.sub.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.CreatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.UpdatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.PlanFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanService; + +/** + * 套餐管理控制器 + */ +@Tag(name = "套餐管理", description = "套餐的增删改查接口") +@RestController +@RequestMapping("/plan") +public class PlanController { + + private final PlanService planService; + + public PlanController(PlanService planService) { + this.planService = planService; + } + + @Operation(summary = "创建套餐", description = "创建新的订阅套餐") + @PostMapping("/create") + public ApiResponse createPlan(@Valid @RequestBody CreatePlanDTO createPlanDTO) { + PlanVO planVO = planService.createPlan(createPlanDTO); + return ApiResponse.success(planVO); + } + + @Operation(summary = "更新套餐", description = "更新现有套餐信息") + @PutMapping("/update/{planId}") + public ApiResponse updatePlan(@Valid @RequestBody UpdatePlanDTO updatePlanDTO, + @PathVariable Long planId) { + PlanVO planVO = planService.updatePlan(updatePlanDTO, planId); + return ApiResponse.success(planVO); + } + + @Operation(summary = "删除套餐", description = "删除指定套餐") + @DeleteMapping("/delete/{planId}") + public ApiResponse deletePlan( + @Parameter(description = "套餐ID") @PathVariable Long planId) { + planService.deletePlan(planId); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取套餐列表", description = "分页获取套餐列表,支持条件过滤") + @PostMapping("/page") + public ApiResponse> getPlanPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = planService.getPlanPage(pageQueryDTO); + return ApiResponse.success(result); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanPricingController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanPricingController.java new file mode 100644 index 00000000..108ab26a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/PlanPricingController.java @@ -0,0 +1,62 @@ +package top.xyquan.ecomdmbbackend.modules.sub.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.CreatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.UpdatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.PlanPricingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanPricingService; + +/** + * 套餐定价管理控制器 + */ +@Tag(name = "套餐定价管理", description = "套餐定价的增删改查接口") +@RestController +@RequestMapping("/plan-pricing") +public class PlanPricingController { + + private final PlanPricingService planPricingService; + + public PlanPricingController(PlanPricingService planPricingService) { + this.planPricingService = planPricingService; + } + + @Operation(summary = "创建定价", description = "创建新的套餐定价") + @PostMapping("/create") + public ApiResponse createPlanPricing(@Valid @RequestBody CreatePlanPricingDTO createPlanPricingDTO) { + PlanPricingVO planPricingVO = planPricingService.createPlanPricing(createPlanPricingDTO); + return ApiResponse.success(planPricingVO); + } + + @Operation(summary = "更新定价", description = "更新现有定价信息") + @PutMapping("/update/{id}") + public ApiResponse updatePlanPricing(@Valid @RequestBody UpdatePlanPricingDTO updatePlanPricingDTO, + @PathVariable Long id) { + PlanPricingVO planPricingVO = planPricingService.updatePlanPricing(updatePlanPricingDTO, id); + return ApiResponse.success(planPricingVO); + } + + @Operation(summary = "删除定价", description = "删除指定定价") + @DeleteMapping("/delete/{id}") + public ApiResponse deletePlanPricing( + @Parameter(description = "定价ID") @PathVariable Long id) { + planPricingService.deletePlanPricing(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取定价列表", description = "分页获取定价列表,支持条件过滤") + @PostMapping("/page") + public ApiResponse> getPlanPricingPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = planPricingService.getPlanPricingPage(pageQueryDTO); + return ApiResponse.success(result); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/SubscriptionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/SubscriptionController.java new file mode 100644 index 00000000..969a55b3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/controller/SubscriptionController.java @@ -0,0 +1,64 @@ +package top.xyquan.ecomdmbbackend.modules.sub.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.CreateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.UpdateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.SubscriptionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.SubscriptionService; + +/** + * 订阅管理控制器 + */ +@Tag(name = "订阅管理", description = "订阅的增删改查接口") +@RestController +@RequestMapping("/subscription") +public class SubscriptionController { + + private final SubscriptionService subscriptionService; + + public SubscriptionController(SubscriptionService subscriptionService) { + this.subscriptionService = subscriptionService; + } + + @Operation(summary = "创建订阅", description = "创建新的订阅记录") + @PostMapping("/create") + public ApiResponse createSubscription( + @Valid @RequestBody CreateSubscriptionDTO createSubscriptionDTO) { + SubscriptionVO subscriptionVO = subscriptionService.createSubscription(createSubscriptionDTO); + return ApiResponse.success(subscriptionVO); + } + + @Operation(summary = "更新订阅", description = "更新现有订阅信息") + @PutMapping("/update/{id}") + public ApiResponse updateSubscription( + @Valid @RequestBody UpdateSubscriptionDTO updateSubscriptionDTO, + @PathVariable Long id) { + SubscriptionVO subscriptionVO = subscriptionService.updateSubscription(updateSubscriptionDTO, id); + return ApiResponse.success(subscriptionVO); + } + + @Operation(summary = "删除订阅", description = "删除指定订阅") + @DeleteMapping("/delete/{id}") + public ApiResponse deleteSubscription( + @Parameter(description = "订阅ID") @PathVariable Long id) { + subscriptionService.deleteSubscription(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取订阅列表", description = "分页获取订阅列表,支持条件过滤") + @PostMapping("/page") + public ApiResponse> getSubscriptionPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = subscriptionService.getSubscriptionPage(pageQueryDTO); + return ApiResponse.success(result); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanMapper.java new file mode 100644 index 00000000..101a6195 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.sub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPO; + +/** + * 套餐Mapper + */ +@Mapper +public interface PlanMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanPricingMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanPricingMapper.java new file mode 100644 index 00000000..92c4bbd6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/PlanPricingMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.sub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPricingPO; + +/** + * 套餐定价Mapper + */ +@Mapper +public interface PlanPricingMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/SubscriptionMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/SubscriptionMapper.java new file mode 100644 index 00000000..e4fdcb2f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/mapper/SubscriptionMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.sub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.SubscriptionPO; + +/** + * 订阅Mapper + */ +@Mapper +public interface SubscriptionMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/CreatePlanDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/CreatePlanDTO.java new file mode 100644 index 00000000..94eb4941 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/CreatePlanDTO.java @@ -0,0 +1,44 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 创建套餐DTO + */ +@Data +public class CreatePlanDTO { + + /** + * 套餐名称 + */ + @NotBlank(message = "套餐名称不能为空") + private String name; + + /** + * 用户数量限制,NULL 表示不限 + */ + private Integer userLimit; + + /** + * 是否为试用套餐 (1-是 0-否) + */ + @NotNull(message = "试用标识不能为空") + private Integer isTrial; + + /** + * 试用天数,仅 is_trial = 1 时有效 + */ + private Integer trialDays; + + /** + * 状态:(1-可购买 0-下架) + */ + private Integer status; + + /** + * 套餐描述 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/PlanFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/PlanFilterDTO.java new file mode 100644 index 00000000..696d8b89 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/PlanFilterDTO.java @@ -0,0 +1,25 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan; + +import lombok.Data; + +/** + * 套餐分页查询过滤DTO + */ +@Data +public class PlanFilterDTO { + + /** + * 套餐名称(模糊查询) + */ + private String name; + + /** + * 是否为试用套餐 + */ + private Integer isTrial; + + /** + * 状态 + */ + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/UpdatePlanDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/UpdatePlanDTO.java new file mode 100644 index 00000000..706fd059 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/UpdatePlanDTO.java @@ -0,0 +1,44 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 更新套餐DTO + */ +@Data +public class UpdatePlanDTO { + + /** + * 套餐名称 + */ + @NotBlank(message = "套餐名称不能为空") + private String name; + + /** + * 用户数量限制,NULL 表示不限 + */ + private Integer userLimit; + + /** + * 是否为试用套餐 (1-是 0-否) + */ + @NotNull(message = "试用标识不能为空") + private Integer isTrial; + + /** + * 试用天数,仅 is_trial = 1 时有效 + */ + private Integer trialDays; + + /** + * 状态:(1-可购买 0-下架) + */ + private Integer status; + + /** + * 套餐描述 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/CreatePlanPricingDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/CreatePlanPricingDTO.java new file mode 100644 index 00000000..2d3f574d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/CreatePlanPricingDTO.java @@ -0,0 +1,40 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing; + +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 创建套餐定价DTO + */ +@Data +public class CreatePlanPricingDTO { + + /** + * 对应套餐ID + */ + @NotNull(message = "套餐ID不能为空") + private Long planId; + + /** + * 价格(元) + */ + @NotNull(message = "价格不能为空") + @DecimalMin(value = "0.01", message = "价格必须大于0") + private BigDecimal price; + + /** + * 订阅时长(月) + */ + @NotNull(message = "订阅时长不能为空") + @Min(value = 1, message = "订阅时长必须大于0") + private Integer durationMonths; + + /** + * 是否启用当前价格(1-启用,0-禁用) + */ + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/PlanPricingFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/PlanPricingFilterDTO.java new file mode 100644 index 00000000..4f2d537c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/PlanPricingFilterDTO.java @@ -0,0 +1,37 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 套餐定价分页查询过滤DTO + */ +@Data +public class PlanPricingFilterDTO { + + /** + * 套餐ID + */ + private Long planId; + + /** + * 价格范围-最小值 + */ + private BigDecimal minPrice; + + /** + * 价格范围-最大值 + */ + private BigDecimal maxPrice; + + /** + * 订阅时长(月) + */ + private Integer durationMonths; + + /** + * 状态 + */ + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/UpdatePlanPricingDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/UpdatePlanPricingDTO.java new file mode 100644 index 00000000..5d936b8a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/plan/pricing/UpdatePlanPricingDTO.java @@ -0,0 +1,46 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing; + +import jakarta.validation.constraints.DecimalMin; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 更新套餐定价DTO + */ +@Data +public class UpdatePlanPricingDTO { + + /** + * 定价ID + */ + @NotNull(message = "定价ID不能为空") + private Long id; + + /** + * 对应套餐ID + */ + @NotNull(message = "套餐ID不能为空") + private Long planId; + + /** + * 价格(元) + */ + @NotNull(message = "价格不能为空") + @DecimalMin(value = "0.01", message = "价格必须大于0") + private BigDecimal price; + + /** + * 订阅时长(月) + */ + @NotNull(message = "订阅时长不能为空") + @Min(value = 1, message = "订阅时长必须大于0") + private Integer durationMonths; + + /** + * 是否启用当前价格(1-启用,0-禁用) + */ + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/CreateSubscriptionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/CreateSubscriptionDTO.java new file mode 100644 index 00000000..8f728143 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/CreateSubscriptionDTO.java @@ -0,0 +1,68 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 创建订阅DTO + */ +@Data +public class CreateSubscriptionDTO { + + /** + * 公司ID(关联org_company) + */ + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 套餐ID(关联sub_plan) + */ + @NotNull(message = "套餐ID不能为空") + private Long planId; + + /** + * 订阅开始时间 + */ + @NotNull(message = "订阅开始时间不能为空") + private LocalDateTime startTime; + + /** + * 订阅结束时间 + */ + @NotNull(message = "订阅结束时间不能为空") + private LocalDateTime endTime; + + /** + * 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效) + */ + private String status; + + /** + * 实际支付金额 + */ + private BigDecimal paidAmount; + + /** + * 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款) + */ + private String paymentStatus; + + /** + * 支付时间 + */ + private LocalDateTime paymentTime; + + /** + * 第三方支付订单号 + */ + private String orderNo; + + /** + * 备注 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/SubscriptionFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/SubscriptionFilterDTO.java new file mode 100644 index 00000000..988c3fff --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/SubscriptionFilterDTO.java @@ -0,0 +1,53 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription; + +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 订阅分页查询过滤DTO + */ +@Data +public class SubscriptionFilterDTO { + + /** + * 公司ID + */ + private Long companyId; + + /** + * 套餐ID + */ + private Long planId; + + /** + * 生效状态 + */ + private String status; + + /** + * 支付状态 + */ + private String paymentStatus; + + /** + * 支付金额范围-最小值 + */ + private BigDecimal minPaidAmount; + + /** + * 支付金额范围-最大值 + */ + private BigDecimal maxPaidAmount; + + /** + * 订阅开始时间范围-开始 + */ + private LocalDateTime startTimeBegin; + + /** + * 订阅开始时间范围-结束 + */ + private LocalDateTime startTimeEnd; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/UpdateSubscriptionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/UpdateSubscriptionDTO.java new file mode 100644 index 00000000..537c63b3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/dto/sucscription/UpdateSubscriptionDTO.java @@ -0,0 +1,74 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription; + +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 更新订阅DTO + */ +@Data +public class UpdateSubscriptionDTO { + + /** + * 记录ID + */ + @NotNull(message = "订阅ID不能为空") + private Long id; + + /** + * 公司ID(关联org_company) + */ + @NotNull(message = "公司ID不能为空") + private Long companyId; + + /** + * 套餐ID(关联sub_plan) + */ + @NotNull(message = "套餐ID不能为空") + private Long planId; + + /** + * 订阅开始时间 + */ + @NotNull(message = "订阅开始时间不能为空") + private LocalDateTime startTime; + + /** + * 订阅结束时间 + */ + @NotNull(message = "订阅结束时间不能为空") + private LocalDateTime endTime; + + /** + * 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效) + */ + private String status; + + /** + * 实际支付金额 + */ + private BigDecimal paidAmount; + + /** + * 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款) + */ + private String paymentStatus; + + /** + * 支付时间 + */ + private LocalDateTime paymentTime; + + /** + * 第三方支付订单号 + */ + private String orderNo; + + /** + * 备注 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPO.java new file mode 100644 index 00000000..54197451 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPO.java @@ -0,0 +1,82 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 订阅套餐实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sub_plan") +public class PlanPO { + + /** + * 套餐ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 套餐名称 + */ + @TableField("name") + private String name; + + /** + * 用户数量限制,NULL 表示不限 + */ + @TableField("user_limit") + private Integer userLimit; + + /** + * 是否为试用套餐 (1-是 0-否) + */ + @TableField("is_trial") + private Integer isTrial; + + /** + * 试用天数,仅 is_trial = 1 时有效 + */ + @TableField("trial_days") + private Integer trialDays; + + /** + * 状态:(1-可购买 0-下架) + */ + @TableField("status") + private Integer status; + + /** + * 套餐描述 + */ + @TableField("remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField(value = "create_by", fill = FieldFill.INSERT) + private Long createBy; + + /** + * 更新人ID + */ + @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE) + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPricingPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPricingPO.java new file mode 100644 index 00000000..82ccd379 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/PlanPricingPO.java @@ -0,0 +1,71 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 订阅套餐定价实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sub_plan_pricing") +public class PlanPricingPO { + + /** + * 定价ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 对应套餐ID + */ + @TableField("plan_id") + private Long planId; + + /** + * 价格(元) + */ + @TableField("price") + private BigDecimal price; + + /** + * 订阅时长(月) + */ + @TableField("duration_months") + private Integer durationMonths; + + /** + * 是否启用当前价格(1-启用,0-禁用) + */ + @TableField("stauts") + private Integer status; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField(value = "create_by", fill = FieldFill.INSERT) + private Long createBy; + + /** + * 更新人ID + */ + @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE) + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/SubscriptionPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/SubscriptionPO.java new file mode 100644 index 00000000..18b768b6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/po/SubscriptionPO.java @@ -0,0 +1,120 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 订阅记录实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sub_subscription") +public class SubscriptionPO { + + /** + * 记录ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司ID(关联org_company) + */ + @TableField("company_id") + private Long companyId; + + /** + * 套餐ID(关联sub_plan) + */ + @TableField("plan_id") + private Long planId; + + /** + * 订阅开始时间 + */ + @TableField("start_time") + private LocalDateTime startTime; + + /** + * 订阅结束时间 + */ + @TableField("end_time") + private LocalDateTime endTime; + + /** + * 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效) + */ + @TableField("status") + private String status; + + /** + * 实际支付金额 + */ + @TableField("paid_amount") + private BigDecimal paidAmount; + + /** + * 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款) + */ + @TableField("payment_status") + private String paymentStatus; + + /** + * 支付时间 + */ + @TableField("payment_time") + private LocalDateTime paymentTime; + + /** + * 第三方支付订单号 + */ + @TableField("order_no") + private String orderNo; + + /** + * 备注 + */ + @TableField("remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 删除时间 + */ + @TableField("delete_time") + @TableLogic + private LocalDateTime deleteTime; + + /** + * 创建人ID + */ + @TableField(value = "create_by", fill = FieldFill.INSERT) + private Long createBy; + + /** + * 更新人ID + */ + @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE) + private Long updateBy; + + /** + * 删除人ID + */ + @TableField("delete_by") + private Long deleteBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanListVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanListVO.java new file mode 100644 index 00000000..c44aa2b1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanListVO.java @@ -0,0 +1,52 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 套餐列表VO + */ +@Data +public class PlanListVO { + + /** + * 套餐ID + */ + private Long id; + + /** + * 套餐名称 + */ + private String name; + + /** + * 用户数量限制,NULL 表示不限 + */ + private Integer userLimit; + + /** + * 是否为试用套餐 (1-是 0-否) + */ + private Integer isTrial; + + /** + * 试用天数,仅 is_trial = 1 时有效 + */ + private Integer trialDays; + + /** + * 状态:(1-可购买 0-下架) + */ + private Integer status; + + /** + * 套餐描述 + */ + private String remark; + + /** + * 创建时间 + */ + private LocalDateTime createTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanVO.java new file mode 100644 index 00000000..1f5c9583 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/PlanVO.java @@ -0,0 +1,57 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 套餐VO + */ +@Data +public class PlanVO { + + /** + * 套餐ID + */ + private Long id; + + /** + * 套餐名称 + */ + private String name; + + /** + * 用户数量限制,NULL 表示不限 + */ + private Integer userLimit; + + /** + * 是否为试用套餐 (1-是 0-否) + */ + private Integer isTrial; + + /** + * 试用天数,仅 is_trial = 1 时有效 + */ + private Integer trialDays; + + /** + * 状态:(1-可购买 0-下架) + */ + private Integer status; + + /** + * 套餐描述 + */ + private String remark; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingListVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingListVO.java new file mode 100644 index 00000000..d05be322 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingListVO.java @@ -0,0 +1,48 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing; + +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 套餐定价列表VO + */ +@Data +public class PlanPricingListVO { + + /** + * 定价ID + */ + private Long id; + + /** + * 对应套餐ID + */ + private Long planId; + + /** + * 套餐名称 + */ + private String planName; + + /** + * 价格(元) + */ + private BigDecimal price; + + /** + * 订阅时长(月) + */ + private Integer durationMonths; + + /** + * 是否启用当前价格(1-启用,0-禁用) + */ + private Integer status; + + /** + * 创建时间 + */ + private LocalDateTime createTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingVO.java new file mode 100644 index 00000000..d21c574c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/plan/pricing/PlanPricingVO.java @@ -0,0 +1,53 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing; + +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 套餐定价VO + */ +@Data +public class PlanPricingVO { + + /** + * 定价ID + */ + private Long id; + + /** + * 对应套餐ID + */ + private Long planId; + + /** + * 套餐名称 + */ + private String planName; + + /** + * 价格(元) + */ + private BigDecimal price; + + /** + * 订阅时长(月) + */ + private Integer durationMonths; + + /** + * 是否启用当前价格(1-启用,0-禁用) + */ + private Integer status; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionListVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionListVO.java new file mode 100644 index 00000000..e55c9498 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionListVO.java @@ -0,0 +1,78 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription; + +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 订阅列表VO + */ +@Data +public class SubscriptionListVO { + + /** + * 记录ID + */ + private Long id; + + /** + * 公司ID(关联org_company) + */ + private Long companyId; + + /** + * 公司名称 + */ + private String companyName; + + /** + * 套餐ID(关联sub_plan) + */ + private Long planId; + + /** + * 套餐名称 + */ + private String planName; + + /** + * 订阅开始时间 + */ + private LocalDateTime startTime; + + /** + * 订阅结束时间 + */ + private LocalDateTime endTime; + + /** + * 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效) + */ + private String status; + + /** + * 实际支付金额 + */ + private BigDecimal paidAmount; + + /** + * 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款) + */ + private String paymentStatus; + + /** + * 支付时间 + */ + private LocalDateTime paymentTime; + + /** + * 第三方支付订单号 + */ + private String orderNo; + + /** + * 创建时间 + */ + private LocalDateTime createTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionVO.java new file mode 100644 index 00000000..2cc898bb --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/model/vo/subscription/SubscriptionVO.java @@ -0,0 +1,88 @@ +package top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription; + +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +/** + * 订阅VO + */ +@Data +public class SubscriptionVO { + + /** + * 记录ID + */ + private Long id; + + /** + * 公司ID + */ + private Long companyId; + + /** + * 公司名称 + */ + private String companyName; + + /** + * 套餐ID + */ + private Long planId; + + /** + * 套餐名称 + */ + private String planName; + + /** + * 订阅开始时间 + */ + private LocalDateTime startTime; + + /** + * 订阅结束时间 + */ + private LocalDateTime endTime; + + /** + * 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效) + */ + private String status; + + /** + * 实际支付金额 + */ + private BigDecimal paidAmount; + + /** + * 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款) + */ + private String paymentStatus; + + /** + * 支付时间 + */ + private LocalDateTime paymentTime; + + /** + * 第三方支付订单号 + */ + private String orderNo; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanPricingService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanPricingService.java new file mode 100644 index 00000000..db63b1dc --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanPricingService.java @@ -0,0 +1,49 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.CreatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.UpdatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.PlanPricingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPricingPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingListVO; + +/** + * 套餐定价服务接口 + */ +public interface PlanPricingService extends IService { + + /** + * 创建定价 + * + * @param createPlanPricingDTO 定价信息 + * @return 定价信息 + */ + PlanPricingVO createPlanPricing(CreatePlanPricingDTO createPlanPricingDTO); + + /** + * 更新定价 + * + * @param updatePlanPricingDTO 定价信息 + * @return 定价信息 + */ + PlanPricingVO updatePlanPricing(UpdatePlanPricingDTO updatePlanPricingDTO, Long id); + + /** + * 删除定价 + * + * @param id 定价ID + */ + void deletePlanPricing(Long id); + + /** + * 分页获取定价列表 + * + * @param pageQueryDTO 分页查询参数 + * @param queryDTO 查询过滤条件 + * @return 分页结果 + */ + PageResultVO getPlanPricingPage(PageQueryDTO pageQueryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanService.java new file mode 100644 index 00000000..4a9803fd --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/PlanService.java @@ -0,0 +1,49 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.CreatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.UpdatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.PlanFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanListVO; + +/** + * 套餐服务接口 + */ +public interface PlanService extends IService { + + /** + * 创建套餐 + * + * @param createPlanDTO 套餐信息 + * @return 套餐信息 + */ + PlanVO createPlan(CreatePlanDTO createPlanDTO); + + /** + * 更新套餐 + * + * @param updatePlanDTO 套餐信息 + * @return 套餐信息 + */ + PlanVO updatePlan(UpdatePlanDTO updatePlanDTO, Long planId); + + /** + * 删除套餐 + * + * @param id 套餐ID + */ + void deletePlan(Long id); + + /** + * 分页获取套餐列表 + * + * @param pageQueryDTO 分页查询参数 + * @param queryDTO 查询过滤条件 + * @return 分页结果 + */ + PageResultVO getPlanPage(PageQueryDTO pageQueryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/SubscriptionService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/SubscriptionService.java new file mode 100644 index 00000000..2098329c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/SubscriptionService.java @@ -0,0 +1,49 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.CreateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.UpdateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.SubscriptionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.SubscriptionPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionListVO; + +/** + * 订阅服务接口 + */ +public interface SubscriptionService extends IService { + + /** + * 创建订阅 + * + * @param createSubscriptionDTO 订阅信息 + * @return 订阅信息 + */ + SubscriptionVO createSubscription(CreateSubscriptionDTO createSubscriptionDTO); + + /** + * 更新订阅 + * + * @param updateSubscriptionDTO 订阅信息 + * @return 订阅信息 + */ + SubscriptionVO updateSubscription(UpdateSubscriptionDTO updateSubscriptionDTO, Long id); + + /** + * 删除订阅 + * + * @param id 订阅ID + */ + void deleteSubscription(Long id); + + /** + * 分页获取订阅列表 + * + * @param pageQueryDTO 分页查询参数 + * @param queryDTO 查询过滤条件 + * @return 分页结果 + */ + PageResultVO getSubscriptionPage(PageQueryDTO pageQueryDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanPricingServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanPricingServiceImpl.java new file mode 100644 index 00000000..c5931f1e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanPricingServiceImpl.java @@ -0,0 +1,199 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.mapper.PlanPricingMapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.CreatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.UpdatePlanPricingDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.pricing.PlanPricingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPricingPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing.PlanPricingListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanPricingService; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanService; +import top.xyquan.ecomdmbbackend.utils.SecurityUtils; + +import java.util.List; + +/** + * 套餐定价服务实现类 + */ +@Service +public class PlanPricingServiceImpl extends ServiceImpl + implements PlanPricingService { + + private final PlanService planService; + + public PlanPricingServiceImpl(PlanService planService) { + this.planService = planService; + } + + @Override + @Transactional + public PlanPricingVO createPlanPricing(CreatePlanPricingDTO createPlanPricingDTO) { + // 验证套餐是否存在 + if (planService.getById(createPlanPricingDTO.getPlanId()) == null) { + throw new BusinessException("套餐不存在"); + } + + // 验证同一套餐下是否存在相同时长的定价 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PlanPricingPO::getPlanId, createPlanPricingDTO.getPlanId()) + .eq(PlanPricingPO::getDurationMonths, createPlanPricingDTO.getDurationMonths()); + if (this.count(wrapper) > 0) { + throw new BusinessException("该套餐下已存在相同时长的定价"); + } + + // 创建定价 + PlanPricingPO planPricing = new PlanPricingPO(); + BeanUtils.copyProperties(createPlanPricingDTO, planPricing); + + // 设置默认值 + if (planPricing.getStatus() == null) { + planPricing.setStatus(1); + } + + // 设置创建人ID + planPricing.setCreateBy(SecurityUtils.getCurrentUserId()); + + // 保存定价 + this.save(planPricing); + + // 转换为VO并返回 + return convertToVO(planPricing); + } + + @Override + @Transactional + public PlanPricingVO updatePlanPricing(UpdatePlanPricingDTO updatePlanPricingDTO, Long id) { + // 检查定价是否存在 + PlanPricingPO existingPricing = this.getById(id); + if (existingPricing == null) { + throw new BusinessException("定价不存在"); + } + + // 验证套餐是否存在 + if (planService.getById(updatePlanPricingDTO.getPlanId()) == null) { + throw new BusinessException("套餐不存在"); + } + + // 验证同一套餐下是否存在相同时长的定价(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PlanPricingPO::getPlanId, updatePlanPricingDTO.getPlanId()) + .eq(PlanPricingPO::getDurationMonths, updatePlanPricingDTO.getDurationMonths()) + .ne(PlanPricingPO::getId, updatePlanPricingDTO.getId()); + if (this.count(wrapper) > 0) { + throw new BusinessException("该套餐下已存在相同时长的定价"); + } + + // 更新定价 + PlanPricingPO planPricing = new PlanPricingPO(); + BeanUtils.copyProperties(updatePlanPricingDTO, planPricing); + + // 设置更新人ID + planPricing.setUpdateBy(SecurityUtils.getCurrentUserId()); + + // 更新定价 + this.updateById(planPricing); + + // 转换为VO并返回 + return convertToVO(planPricing); + } + + @Override + public void deletePlanPricing(Long id) { + // 检查定价是否存在 + PlanPricingPO planPricing = this.getById(id); + if (planPricing == null) { + throw new BusinessException("定价不存在"); + } + + // 删除定价 + this.removeById(id); + } + + @Override + public PageResultVO getPlanPricingPage(PageQueryDTO pageQueryDTO) { + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + PlanPricingFilterDTO filterDTO = pageQueryDTO.getFilters(); + if (filterDTO.getPlanId() != null) { + wrapper.eq(PlanPricingPO::getPlanId, filterDTO.getPlanId()); + } + if (filterDTO.getMinPrice() != null) { + wrapper.ge(PlanPricingPO::getPrice, filterDTO.getMinPrice()); + } + if (filterDTO.getMaxPrice() != null) { + wrapper.le(PlanPricingPO::getPrice, filterDTO.getMaxPrice()); + } + if (filterDTO.getDurationMonths() != null) { + wrapper.eq(PlanPricingPO::getDurationMonths, filterDTO.getDurationMonths()); + } + if (filterDTO.getStatus() != null) { + wrapper.eq(PlanPricingPO::getStatus, filterDTO.getStatus()); + } + + // 排序 + wrapper.orderByDesc(PlanPricingPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为ListVO + List records = pageResult.getRecords().stream() + .map(this::convertToListVO) + .toList(); + PageResultVO result = PageResultVO.create(records, pageResult.getTotal(), + pageQueryDTO.getPage(), + pageQueryDTO.getPageSize()); + + return result; + } + + /** + * 转换为VO + */ + private PlanPricingVO convertToVO(PlanPricingPO planPricing) { + PlanPricingVO planPricingVO = new PlanPricingVO(); + BeanUtils.copyProperties(planPricing, planPricingVO); + + // 获取套餐名称 + if (planPricing.getPlanId() != null) { + var plan = planService.getById(planPricing.getPlanId()); + if (plan != null) { + planPricingVO.setPlanName(plan.getName()); + } + } + + return planPricingVO; + } + + /** + * 转换为ListVO + */ + private PlanPricingListVO convertToListVO(PlanPricingPO planPricing) { + PlanPricingListVO planPricingListVO = new PlanPricingListVO(); + BeanUtils.copyProperties(planPricing, planPricingListVO); + + // 获取套餐名称 + if (planPricing.getPlanId() != null) { + var plan = planService.getById(planPricing.getPlanId()); + if (plan != null) { + planPricingListVO.setPlanName(plan.getName()); + } + } + + return planPricingListVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanServiceImpl.java new file mode 100644 index 00000000..4a7073ae --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/PlanServiceImpl.java @@ -0,0 +1,167 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.mapper.PlanMapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.CreatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.UpdatePlanDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.plan.PlanFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.PlanPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.PlanListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanService; +import top.xyquan.ecomdmbbackend.utils.SecurityUtils; + +import java.util.List; + +/** + * 套餐服务实现类 + */ +@Service +public class PlanServiceImpl extends ServiceImpl implements PlanService { + + @Override + @Transactional + public PlanVO createPlan(CreatePlanDTO createPlanDTO) { + // 验证套餐名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PlanPO::getName, createPlanDTO.getName()); + if (this.count(wrapper) > 0) { + throw new BusinessException("套餐名称已存在"); + } + + // 验证试用套餐配置 + if (createPlanDTO.getIsTrial() == 1 + && (createPlanDTO.getTrialDays() == null || createPlanDTO.getTrialDays() <= 0)) { + throw new BusinessException("试用套餐必须设置试用天数"); + } + + // 创建套餐 + PlanPO plan = new PlanPO(); + BeanUtils.copyProperties(createPlanDTO, plan); + + // 设置默认值 + if (plan.getStatus() == null) { + plan.setStatus(1); + } + + // 设置创建人ID + plan.setCreateBy(SecurityUtils.getCurrentUserId()); + + // 保存套餐 + this.save(plan); + + // 转换为VO并返回 + return convertToVO(plan); + } + + @Override + @Transactional + public PlanVO updatePlan(UpdatePlanDTO updatePlanDTO, Long planId) { + // 检查套餐是否存在 + PlanPO existingPlan = this.getById(planId); + if (existingPlan == null) { + throw new BusinessException("套餐不存在"); + } + + // 验证套餐名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(PlanPO::getName, updatePlanDTO.getName()) + .ne(PlanPO::getId, planId); + if (this.count(wrapper) > 0) { + throw new BusinessException("套餐名称已存在"); + } + + // 验证试用套餐配置 + if (updatePlanDTO.getIsTrial() == 1 + && (updatePlanDTO.getTrialDays() == null || updatePlanDTO.getTrialDays() <= 0)) { + throw new BusinessException("试用套餐必须设置试用天数"); + } + + // 更新套餐 + PlanPO plan = new PlanPO(); + BeanUtils.copyProperties(updatePlanDTO, plan); + + // 设置更新人ID + plan.setUpdateBy(SecurityUtils.getCurrentUserId()); + + // 更新套餐 + this.updateById(plan); + + // 转换为VO并返回 + return convertToVO(plan); + } + + @Override + public void deletePlan(Long id) { + // 检查套餐是否存在 + PlanPO plan = this.getById(id); + if (plan == null) { + throw new BusinessException("套餐不存在"); + } + + // 删除套餐 + this.removeById(id); + } + + @Override + public PageResultVO getPlanPage(PageQueryDTO pageQueryDTO) { + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + PlanFilterDTO filterDTO = pageQueryDTO.getFilters(); + if (StringUtils.hasText(filterDTO.getName())) { + wrapper.like(PlanPO::getName, filterDTO.getName()); + } + if (filterDTO.getIsTrial() != null) { + wrapper.eq(PlanPO::getIsTrial, filterDTO.getIsTrial()); + } + if (filterDTO.getStatus() != null) { + wrapper.eq(PlanPO::getStatus, filterDTO.getStatus()); + } + + // 排序 + wrapper.orderByDesc(PlanPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为ListVO + List records = pageResult.getRecords().stream() + .map(this::convertToListVO) + .toList(); + PageResultVO result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(), + pageQueryDTO.getPageSize()); + + return result; + } + + /** + * 转换为VO + */ + private PlanVO convertToVO(PlanPO plan) { + PlanVO planVO = new PlanVO(); + BeanUtils.copyProperties(plan, planVO); + return planVO; + } + + /** + * 转换为ListVO + */ + private PlanListVO convertToListVO(PlanPO plan) { + PlanListVO planListVO = new PlanListVO(); + BeanUtils.copyProperties(plan, planListVO); + return planListVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/SubscriptionServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/SubscriptionServiceImpl.java new file mode 100644 index 00000000..2c8651ee --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sub/service/impl/SubscriptionServiceImpl.java @@ -0,0 +1,224 @@ +package top.xyquan.ecomdmbbackend.modules.sub.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sub.mapper.SubscriptionMapper; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.CreateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.UpdateSubscriptionDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription.SubscriptionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sub.model.po.SubscriptionPO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionVO; +import top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription.SubscriptionListVO; +import top.xyquan.ecomdmbbackend.modules.sub.service.PlanService; +import top.xyquan.ecomdmbbackend.modules.sub.service.SubscriptionService; +import top.xyquan.ecomdmbbackend.utils.SecurityUtils; + +import java.math.BigDecimal; +import java.util.List; + +/** + * 订阅服务实现类 + */ +@Service +public class SubscriptionServiceImpl extends ServiceImpl + implements SubscriptionService { + + private final PlanService planService; + + public SubscriptionServiceImpl(PlanService planService) { + this.planService = planService; + } + + @Override + @Transactional + public SubscriptionVO createSubscription(CreateSubscriptionDTO createSubscriptionDTO) { + // 验证套餐是否存在 + if (planService.getById(createSubscriptionDTO.getPlanId()) == null) { + throw new BusinessException("套餐不存在"); + } + + // 验证时间逻辑 + if (createSubscriptionDTO.getStartTime().isAfter(createSubscriptionDTO.getEndTime())) { + throw new BusinessException("开始时间不能晚于结束时间"); + } + + // 创建订阅 + SubscriptionPO subscription = new SubscriptionPO(); + BeanUtils.copyProperties(createSubscriptionDTO, subscription); + + // 设置默认值 + if (subscription.getStatus() == null) { + subscription.setStatus("PENDING"); + } + if (subscription.getPaymentStatus() == null) { + subscription.setPaymentStatus("UNPAID"); + } + if (subscription.getPaidAmount() == null) { + subscription.setPaidAmount(BigDecimal.ZERO); + } + + // 设置创建人ID + subscription.setCreateBy(SecurityUtils.getCurrentUserId()); + + // 保存订阅 + this.save(subscription); + + // 转换为VO并返回 + return convertToVO(subscription); + } + + @Override + @Transactional + public SubscriptionVO updateSubscription(UpdateSubscriptionDTO updateSubscriptionDTO, Long id) { + // 检查订阅是否存在 + SubscriptionPO existingSubscription = this.getById(id); + if (existingSubscription == null) { + throw new BusinessException("订阅不存在"); + } + + // 验证套餐是否存在 + if (planService.getById(updateSubscriptionDTO.getPlanId()) == null) { + throw new BusinessException("套餐不存在"); + } + + // 验证时间逻辑 + if (updateSubscriptionDTO.getStartTime().isAfter(updateSubscriptionDTO.getEndTime())) { + throw new BusinessException("开始时间不能晚于结束时间"); + } + + // 更新订阅 + SubscriptionPO subscription = new SubscriptionPO(); + BeanUtils.copyProperties(updateSubscriptionDTO, subscription); + + // 设置更新人ID + subscription.setUpdateBy(SecurityUtils.getCurrentUserId()); + + // 更新订阅 + this.updateById(subscription); + + // 转换为VO并返回 + return convertToVO(subscription); + } + + @Override + public void deleteSubscription(Long id) { + // 检查订阅是否存在 + SubscriptionPO subscription = this.getById(id); + if (subscription == null) { + throw new BusinessException("订阅不存在"); + } + + // 删除订阅 + this.removeById(id); + } + + @Override + public PageResultVO getSubscriptionPage(PageQueryDTO pageQueryDTO) { + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + // 添加过滤条件 + SubscriptionFilterDTO filterDTO = pageQueryDTO.getFilters(); + if (filterDTO.getCompanyId() != null) { + wrapper.eq(SubscriptionPO::getCompanyId, filterDTO.getCompanyId()); + } + if (filterDTO.getPlanId() != null) { + wrapper.eq(SubscriptionPO::getPlanId, filterDTO.getPlanId()); + } + if (filterDTO.getStatus() != null) { + wrapper.eq(SubscriptionPO::getStatus, filterDTO.getStatus()); + } + if (filterDTO.getPaymentStatus() != null) { + wrapper.eq(SubscriptionPO::getPaymentStatus, filterDTO.getPaymentStatus()); + } + if (filterDTO.getMinPaidAmount() != null) { + wrapper.ge(SubscriptionPO::getPaidAmount, filterDTO.getMinPaidAmount()); + } + if (filterDTO.getMaxPaidAmount() != null) { + wrapper.le(SubscriptionPO::getPaidAmount, filterDTO.getMaxPaidAmount()); + } + if (filterDTO.getStartTimeBegin() != null) { + wrapper.ge(SubscriptionPO::getStartTime, filterDTO.getStartTimeBegin()); + } + if (filterDTO.getStartTimeEnd() != null) { + wrapper.le(SubscriptionPO::getStartTime, filterDTO.getStartTimeEnd()); + } + + // 排序 + wrapper.orderByDesc(SubscriptionPO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为ListVO + List records = pageResult.getRecords().stream() + .map(this::convertToListVO) + .toList(); + PageResultVO result = PageResultVO.create(records, pageResult.getTotal(), + pageQueryDTO.getPage(), + pageQueryDTO.getPageSize()); + + return result; + } + + /** + * 转换为VO + */ + private SubscriptionVO convertToVO(SubscriptionPO subscription) { + SubscriptionVO subscriptionVO = new SubscriptionVO(); + BeanUtils.copyProperties(subscription, subscriptionVO); + + // 获取套餐名称 + if (subscription.getPlanId() != null) { + var plan = planService.getById(subscription.getPlanId()); + if (plan != null) { + subscriptionVO.setPlanName(plan.getName()); + } + } + + // TODO: 获取公司名称,需要注入CompanyService + // if (subscription.getCompanyId() != null) { + // var company = companyService.getById(subscription.getCompanyId()); + // if (company != null) { + // subscriptionVO.setCompanyName(company.getName()); + // } + // } + + return subscriptionVO; + } + + /** + * 转换为ListVO + */ + private SubscriptionListVO convertToListVO(SubscriptionPO subscription) { + SubscriptionListVO subscriptionListVO = new SubscriptionListVO(); + BeanUtils.copyProperties(subscription, subscriptionListVO); + + // 获取套餐名称 + if (subscription.getPlanId() != null) { + var plan = planService.getById(subscription.getPlanId()); + if (plan != null) { + subscriptionListVO.setPlanName(plan.getName()); + } + } + + // TODO: 获取公司名称,需要注入CompanyService + // if (subscription.getCompanyId() != null) { + // var company = companyService.getById(subscription.getCompanyId()); + // if (company != null) { + // subscriptionListVO.setCompanyName(company.getName()); + // } + // } + + return subscriptionListVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/AuthController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/AuthController.java new file mode 100644 index 00000000..5d875d5f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/AuthController.java @@ -0,0 +1,83 @@ +package top.xyquan.ecomdmbbackend.modules.sys.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.UserService; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; + +/** + * 认证控制器 + */ +@Tag(name = "认证管理", description = "用户注册、登录等认证相关接口") +@RestController +@RequestMapping("/auth") +public class AuthController { + + private final UserService userService; + private final PermissionCheckService permissionCheckService; + private final CurrentUserContext currentUserContext; + + public AuthController(UserService userService, PermissionCheckService permissionCheckService, CurrentUserContext currentUserContext) { + this.userService = userService; + this.permissionCheckService = permissionCheckService; + this.currentUserContext = currentUserContext; + } + + @Operation(summary = "用户注册", description = "用户注册接口,支持通过登录账号或手机号码注册") + @PostMapping("/register") + public ApiResponse register(@Valid @RequestBody RegisterDTO registerDTO) { + LoginVO loginVO = userService.register(registerDTO); + return ApiResponse.success(loginVO); + } + + @Operation(summary = "用户登录", description = "用户登录接口,支持通过登录账号或手机号码登录") + @PostMapping("/login") + public ApiResponse login(@Valid @RequestBody LoginDTO loginDTO) { + LoginVO loginVO = userService.login(loginDTO); + return ApiResponse.success(loginVO); + } + + @Operation(summary = "获取用户权限码", description = "获取当前登录用户的权限码列表") + @GetMapping("/codes") + public ApiResponse> getAccessCodes() { + try { + String role = currentUserContext.getCurrentUserPayload().getRole(); + Long positionId = currentUserContext.getCurrentUserPayload().getPositionId(); + Long companyId = currentUserContext.getCurrentCompanyId(); + + List permissions; + + // 根据角色返回不同的权限 + switch (role) { + case "super": + // 超级管理员拥有所有权限 + permissions = List.of("*"); + break; + case "company": + // 公司管理员拥有公司相关权限 + permissions = List.of("company:*"); + break; + case "user": + // 普通用户根据岗位获取权限 + permissions = permissionCheckService.getPositionPermissions(positionId, companyId); + break; + default: + permissions = List.of(); + } + + return ApiResponse.success(permissions); + } catch (Exception e) { + // 如果获取权限失败,返回空列表 + return ApiResponse.success(List.of()); + } + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/MenuController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/MenuController.java new file mode 100644 index 00000000..bbefaebe --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/MenuController.java @@ -0,0 +1,74 @@ +package top.xyquan.ecomdmbbackend.modules.sys.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService; + +import java.util.List; + +/** + * 菜单管理控制器 + */ +@Tag(name = "菜单管理", description = "菜单的增删改查接口") +@RestController +@RequestMapping("/menu") +public class MenuController { + + private final MenuService menuService; + + public MenuController(MenuService menuService) { + this.menuService = menuService; + } + + @Operation(summary = "创建菜单", description = "创建新的菜单") + @PostMapping("/create") + public ApiResponse createMenu(@Valid @RequestBody CreateMenuDTO createMenuDTO) { + MenuVO menuVO = menuService.createMenu(createMenuDTO); + return ApiResponse.success(menuVO); + } + + @Operation(summary = "更新菜单", description = "更新现有菜单信息") + @PutMapping("/update/{id}") + public ApiResponse updateMenu(@Valid @RequestBody UpdateMenuDTO updateMenuDTO, + @PathVariable Long id) { + MenuVO menuVO = menuService.updateMenu(updateMenuDTO, id); + return ApiResponse.success(menuVO); + } + + @Operation(summary = "删除菜单", description = "删除指定菜单") + @DeleteMapping("/delete/{id}") + public ApiResponse deleteMenu( + @Parameter(description = "菜单ID") @PathVariable Long id) { + menuService.deleteMenu(id); + return ApiResponse.success(); + } + + @Operation(summary = "获取菜单树", description = "获取完整的菜单树结构") + @GetMapping("/tree") + public ApiResponse> getMenuTree() { + List menuTree = menuService.getMenuTree(); + return ApiResponse.success(menuTree); + } + + @Operation(summary = "获取所有菜单", description = "获取所有菜单的列表") + @GetMapping("/list") + public ApiResponse> getAllMenus() { + List menuList = menuService.getAllMenus(); + return ApiResponse.success(menuList); + } + + @Operation(summary = "获取菜单详情", description = "根据ID获取菜单详细信息") + @GetMapping("/detail/{id}") + public ApiResponse getMenuDetail( + @Parameter(description = "菜单ID") @PathVariable Long id) { + MenuVO menuVO = menuService.getMenuDetail(id); + return ApiResponse.success(menuVO); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/PermissionController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/PermissionController.java new file mode 100644 index 00000000..dc1262b1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/PermissionController.java @@ -0,0 +1,78 @@ +package top.xyquan.ecomdmbbackend.modules.sys.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionService; + +import java.util.List; + +/** + * 权限管理控制器 + */ +@Tag(name = "权限管理", description = "权限的增删改查接口") +@RestController +@RequestMapping("/permission") +public class PermissionController { + + private final PermissionService permissionService; + + public PermissionController(PermissionService permissionService) { + this.permissionService = permissionService; + } + + @Operation(summary = "创建权限", description = "创建新的权限") + @PostMapping("/create") + public ApiResponse createPermission(@Valid @RequestBody CreatePermissionDTO createPermissionDTO) { + PermissionVO permissionVO = permissionService.createPermission(createPermissionDTO); + return ApiResponse.success(permissionVO); + } + + @Operation(summary = "更新权限", description = "更新现有权限信息") + @PutMapping("/update/{id}") + public ApiResponse updatePermission(@Valid @RequestBody UpdatePermissionDTO updatePermissionDTO, + @PathVariable Long id) { + PermissionVO permissionVO = permissionService.updatePermission(updatePermissionDTO, id); + return ApiResponse.success(permissionVO); + } + + @Operation(summary = "删除权限", description = "删除指定权限") + @DeleteMapping("/delete/{id}") + public ApiResponse deletePermission( + @Parameter(description = "权限ID") @PathVariable Long id) { + permissionService.deletePermission(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取权限列表", description = "根据条件分页获取权限列表") + @PostMapping("/page") + public ApiResponse> getPermissionPage( + @Valid @RequestBody PageQueryDTO filterDTO) { + PageResultVO pageResult = permissionService.getPermissionPage(filterDTO); + return ApiResponse.success(pageResult); + } + + @Operation(summary = "获取权限详情", description = "根据ID获取权限详细信息") + @GetMapping("/detail/{id}") + public ApiResponse getPermissionDetail( + @Parameter(description = "权限ID") @PathVariable Long id) { + PermissionVO permissionVO = permissionService.getPermissionDetail(id); + return ApiResponse.success(permissionVO); + } + + @Operation(summary = "获取所有权限", description = "获取所有启用的权限列表") + @GetMapping("/list") + public ApiResponse> getAllPermissions() { + List permissionList = permissionService.getAllPermissions(); + return ApiResponse.success(permissionList); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/UserController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/UserController.java new file mode 100644 index 00000000..b9f4b7a1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/controller/UserController.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.modules.sys.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.UserService; + +/** + * 用户管理控制器 + */ +@Tag(name = "用户管理", description = "用户信息管理相关接口") +@RestController +@RequestMapping("/user") +public class UserController { + + private final UserService userService; + + public UserController(UserService userService) { + this.userService = userService; + } + + @Operation(summary = "获取用户信息", description = "获取当前登录用户的详细信息") + @GetMapping("/info") + public ApiResponse getUserInfo() { + UserVO userVO = userService.getCurrentUserInfo(); + return ApiResponse.success(userVO); + } + + @Operation(summary = "更新用户信息", description = "更新当前登录用户的基本信息") + @PutMapping("/info") + public ApiResponse updateUserInfo(@Valid @RequestBody UpdateUserInfoDTO updateUserInfoDTO) { + UserVO userVO = userService.updateCurrentUserInfo(updateUserInfoDTO); + return ApiResponse.success(userVO); + } + + @Operation(summary = "修改密码", description = "修改当前登录用户的密码") + @PostMapping("/change-password") + public ApiResponse changePassword(@Valid @RequestBody ChangePasswordDTO changePasswordDTO) { + userService.changePassword(changePasswordDTO); + return ApiResponse.success(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuMapper.java new file mode 100644 index 00000000..32f8f9a9 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO; + +/** + * 系统菜单Mapper + */ +@Mapper +public interface MenuMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuPermissionMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuPermissionMapper.java new file mode 100644 index 00000000..51c644fa --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/MenuPermissionMapper.java @@ -0,0 +1,40 @@ +package top.xyquan.ecomdmbbackend.modules.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPermissionPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO; + +import java.util.List; + +/** + * 菜单权限关联Mapper接口 + */ +@Mapper +public interface MenuPermissionMapper extends BaseMapper { + + /** + * 根据菜单ID查询权限列表 + * + * @param menuId 菜单ID + * @return 权限列表 + */ + List selectPermissionsByMenuId(@Param("menuId") Long menuId); + + /** + * 根据菜单ID列表查询权限列表 + * + * @param menuIds 菜单ID列表 + * @return 权限列表 + */ + List selectPermissionsByMenuIds(@Param("menuIds") List menuIds); + + /** + * 根据权限ID查询菜单列表 + * + * @param permissionId 权限ID + * @return 菜单列表 + */ + List selectMenusByPermissionId(@Param("permissionId") Long permissionId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/PermissionMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/PermissionMapper.java new file mode 100644 index 00000000..c4a03554 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/PermissionMapper.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.modules.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.PermissionPO; + +/** + * 权限Mapper接口 + */ +@Mapper +public interface PermissionMapper extends BaseMapper { + + /** + * 分页查询权限列表 + * + * @param page 分页参数 + * @param code 权限码 + * @param name 权限名称 + * @param type 权限类型 + * @param status 状态 + * @return 分页结果 + */ + IPage selectPermissionPage(Page page, + @Param("code") String code, + @Param("name") String name, + @Param("type") String type, + @Param("status") Integer status); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/UserMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/UserMapper.java new file mode 100644 index 00000000..470b612d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/mapper/UserMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.sys.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO; + +/** + * 系统用户Mapper接口 + */ +@Mapper +public interface UserMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/BatchAssignMenuPermissionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/BatchAssignMenuPermissionDTO.java new file mode 100644 index 00000000..9e79e92b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/BatchAssignMenuPermissionDTO.java @@ -0,0 +1,30 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * 批量分配菜单权限DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BatchAssignMenuPermissionDTO { + + /** + * 菜单ID + */ + @NotNull(message = "菜单ID不能为空") + private Long menuId; + + /** + * 权限ID列表 + */ + @NotEmpty(message = "权限列表不能为空") + private List permissionIds; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/CreateMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/CreateMenuDTO.java new file mode 100644 index 00000000..eded249f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/CreateMenuDTO.java @@ -0,0 +1,77 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建菜单DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CreateMenuDTO { + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 菜单名称 + */ + @NotBlank(message = "菜单名称不能为空") + private String name; + + /** + * 菜单标题 + */ + private String title; + + /** + * 路由路径 + */ + private String path; + + /** + * 页面组件 + */ + private String component; + + /** + * 重定向地址 + */ + private String redirect; + + /** + * 路由图标 + */ + private String icon; + + /** + * 顺序 + */ + private Integer order; + + /** + * 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链) + */ + @NotBlank(message = "菜单类型不能为空") + private String type; + + /** + * 是否显示在菜单中 (0-否 1-是) + */ + private Integer visible; + + /** + * 状态 (0-禁用 1-启用) + */ + private Integer status; + + /** + * 是否缓存 + */ + private Integer keepAlive; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/UpdateMenuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/UpdateMenuDTO.java new file mode 100644 index 00000000..e230d5fe --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/menu/UpdateMenuDTO.java @@ -0,0 +1,77 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 更新菜单DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UpdateMenuDTO { + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 菜单名称 + */ + @NotBlank(message = "菜单名称不能为空") + private String name; + + /** + * 菜单标题 + */ + private String title; + + /** + * 路由路径 + */ + private String path; + + /** + * 页面组件 + */ + private String component; + + /** + * 重定向地址 + */ + private String redirect; + + /** + * 路由图标 + */ + private String icon; + + /** + * 顺序 + */ + private Integer order; + + /** + * 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链) + */ + @NotBlank(message = "菜单类型不能为空") + private String type; + + /** + * 是否显示在菜单中 (0-否 1-是) + */ + private Integer visible; + + /** + * 状态 (0-禁用 1-启用) + */ + private Integer status; + + /** + * 是否缓存 + */ + private Integer keepAlive; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/CreatePermissionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/CreatePermissionDTO.java new file mode 100644 index 00000000..c0737cd1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/CreatePermissionDTO.java @@ -0,0 +1,43 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建权限DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CreatePermissionDTO { + + /** + * 权限码(唯一标识,如 user:add, order:approve) + */ + @NotBlank(message = "权限码不能为空") + private String code; + + /** + * 权限名称(用于显示,如 用户新增、订单审核) + */ + @NotBlank(message = "权限名称不能为空") + private String name; + + /** + * 权限类型(api-接口权限,button-按钮权限,data-数据权限) + */ + @NotBlank(message = "权限类型不能为空") + private String type; + + /** + * 状态:1-启用 0-禁用 + */ + private Integer status; + + /** + * 备注 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/PermissionFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/PermissionFilterDTO.java new file mode 100644 index 00000000..3d7a57a4 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/PermissionFilterDTO.java @@ -0,0 +1,34 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 权限过滤DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PermissionFilterDTO { + + /** + * 权限码 + */ + private String code; + + /** + * 权限名称 + */ + private String name; + + /** + * 权限类型 + */ + private String type; + + /** + * 状态 + */ + private Integer status; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/UpdatePermissionDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/UpdatePermissionDTO.java new file mode 100644 index 00000000..5180efe4 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/permission/UpdatePermissionDTO.java @@ -0,0 +1,43 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission; + +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 更新权限DTO + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UpdatePermissionDTO { + + /** + * 权限码(唯一标识,如 user:add, order:approve) + */ + @NotBlank(message = "权限码不能为空") + private String code; + + /** + * 权限名称(用于显示,如 用户新增、订单审核) + */ + @NotBlank(message = "权限名称不能为空") + private String name; + + /** + * 权限类型(api-接口权限,button-按钮权限,data-数据权限) + */ + @NotBlank(message = "权限类型不能为空") + private String type; + + /** + * 状态:1-启用 0-禁用 + */ + private Integer status; + + /** + * 备注 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/ChangePasswordDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/ChangePasswordDTO.java new file mode 100644 index 00000000..ebaa35d1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/ChangePasswordDTO.java @@ -0,0 +1,25 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 修改密码DTO + */ +@Data +public class ChangePasswordDTO { + + /** + * 旧密码 + */ + @NotBlank(message = "旧密码不能为空") + private String oldPassword; + + /** + * 新密码 + */ + @NotBlank(message = "新密码不能为空") + // @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d@$!%*?&]{8,}$", + // message = "密码必须包含大小写字母和数字,长度至少8位") + private String newPassword; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/LoginDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/LoginDTO.java new file mode 100644 index 00000000..03a4f98c --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/LoginDTO.java @@ -0,0 +1,23 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user; + +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 用户登录DTO + */ +@Data +public class LoginDTO { + + /** + * 登录账号(可以是loginCode或phone) + */ + @NotBlank(message = "登录账号不能为空") + private String account; + + /** + * 登录密码 + */ + @NotBlank(message = "密码不能为空") + private String password; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/RegisterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/RegisterDTO.java new file mode 100644 index 00000000..95ed03b2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/RegisterDTO.java @@ -0,0 +1,39 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import lombok.Data; + +/** + * 用户注册DTO + */ +@Data +public class RegisterDTO { + + /** + * 登录账号 + */ + private String loginCode; + + /** + * 手机号码 + */ + @Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确") + private String phone; + + /** + * 登录密码 + */ + @NotBlank(message = "密码不能为空") + // @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d@$!%*?&]{8,}$", + // message = "密码必须包含大小写字母和数字,长度至少8位") + private String password; + + /** + * 验证登录账号和手机号码至少填写一个 + */ + public boolean isValid() { + return (loginCode != null && !loginCode.trim().isEmpty()) || + (phone != null && !phone.trim().isEmpty()); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/UpdateUserInfoDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/UpdateUserInfoDTO.java new file mode 100644 index 00000000..989faf75 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/dto/user/UpdateUserInfoDTO.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user; + +import jakarta.validation.constraints.Pattern; +import lombok.Data; + +/** + * 更新用户信息DTO + */ +@Data +public class UpdateUserInfoDTO { + + /** + * 用户名称 + */ + private String realName; + + /** + * 头像路径 + */ + private String avatar; + + /** + * 手机号码 + */ + @Pattern(regexp = "^(|1[3-9]\\d{9})$", message = "手机号码格式不正确") + private String phone; + + /** + * 备注信息 + */ + private String remark; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPO.java new file mode 100644 index 00000000..01c747a3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPO.java @@ -0,0 +1,118 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 系统菜单实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_menu") +public class MenuPO { + + /** + * 菜单ID + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 父菜单ID + */ + @TableField("parent_id") + private Long parentId; + + /** + * 菜单名称 + */ + @TableField("name") + private String name; + + /** + * 菜单标题 + */ + @TableField("title") + private String title; + + /** + * 路由路径 + */ + @TableField("path") + private String path; + + /** + * 页面组件 + */ + @TableField("component") + private String component; + + /** + * 重定向地址 + */ + @TableField("redirect") + private String redirect; + + /** + * 路由图标 + */ + @TableField("icon") + private String icon; + + /** + * 顺序 + */ + @TableField("`order`") + private Integer order; + + /** + * 菜单类型 (目录,菜单,按钮,内联,外链) + */ + @TableField("type") + private String type; + + /** + * 是否显示在菜单中 (0-否 1-是) + */ + @TableField("visible") + private Integer visible; + + /** + * 状态 (0-禁用 1-启用) + */ + @TableField("status") + private Integer status; + + /** + * 是否缓存 + */ + @TableField("keep_alive") + private Integer keepAlive; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPermissionPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPermissionPO.java new file mode 100644 index 00000000..65a532d1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/MenuPermissionPO.java @@ -0,0 +1,46 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 菜单与权限关联实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("rel_menu_permission") +public class MenuPermissionPO { + + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 菜单ID + */ + @TableField("menu_id") + private Long menuId; + + /** + * 权限ID + */ + @TableField("permission_id") + private Long permissionId; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/PermissionPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/PermissionPO.java new file mode 100644 index 00000000..f63ed87f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/PermissionPO.java @@ -0,0 +1,76 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 系统权限实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_permission") +public class PermissionPO { + + /** + * 权限ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 权限码(唯一标识,如 user:add, order:approve) + */ + @TableField("code") + private String code; + + /** + * 权限名称(用于显示,如 用户新增、订单审核) + */ + @TableField("name") + private String name; + + /** + * 权限类型(api-接口权限,button-按钮权限,data-数据权限) + */ + @TableField("type") + private String type; + + /** + * 状态:1-启用 0-禁用 + */ + @TableField("status") + private Integer status; + + /** + * 备注 + */ + @TableField("remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/UserPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/UserPO.java new file mode 100644 index 00000000..e312751b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/po/UserPO.java @@ -0,0 +1,148 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 系统用户实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_user") +public class UserPO { + + /** + * 用户编号 + */ + @TableId(value = "id", type = IdType.ASSIGN_ID) + private Long id; + + /** + * 公司id + */ + @TableField("company_id") + private Long companyId; + + /** + * 部门id + */ + @TableField("department_id") + private Long departmentId; + + /** + * 岗位id + */ + @TableField("position_id") + private Long positionId; + + /** + * 登录账号 + */ + @TableField("login_code") + private String loginCode; + + /** + * 登录密码 + */ + @TableField("password") + private String password; + + /** + * 手机号码 + */ + @TableField("phone") + private String phone; + + /** + * 用户名称 + */ + @TableField("real_name") + private String realName; + + /** + * 头像路径 + */ + @TableField("avatar") + private String avatar; + + /** + * 关联角色(user-普通账户 admin-公司管理员账户 super-超管账户) + */ + @TableField("role") + private String role; + + /** + * 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全) + */ + @TableField("pwd_security_level") + private Integer pwdSecurityLevel; + + /** + * 密码最后更新时间 + */ + @TableField("pwd_update_time") + private LocalDateTime pwdUpdateTime; + + /** + * 最后登录ip + */ + @TableField("last_login_ip") + private String lastLoginIp; + + /** + * 最后登录时间 + */ + @TableField("last_login_date") + private LocalDateTime lastLoginDate; + + /** + * 冻结时间 + */ + @TableField("freeze_date") + private LocalDateTime freezeDate; + + /** + * 冻结原因 + */ + @TableField("freeze_cause") + private String freezeCause; + + /** + * 状态(0-正常 1-删除 2-停用 3-冻结) + */ + @TableField("status") + private Integer status; + + /** + * 备注信息 + */ + @TableField("remark") + private String remark; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建者 + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新者 + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/LoginVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/LoginVO.java new file mode 100644 index 00000000..3004de85 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/LoginVO.java @@ -0,0 +1,20 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.vo; + +import lombok.Data; + +/** + * 登录响应VO + */ +@Data +public class LoginVO { + + /** + * JWT令牌 + */ + private String token; + + /** + * 用户信息 + */ + private UserVO user; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuPermissionVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuPermissionVO.java new file mode 100644 index 00000000..11b85ec3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuPermissionVO.java @@ -0,0 +1,57 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 菜单权限关联VO + */ +@Data +public class MenuPermissionVO { + + /** + * 关联ID + */ + private Long id; + + /** + * 菜单ID + */ + private Long menuId; + + /** + * 菜单名称 + */ + private String menuName; + + /** + * 菜单标题 + */ + private String menuTitle; + + /** + * 权限ID + */ + private Long permissionId; + + /** + * 权限码 + */ + private String permissionCode; + + /** + * 权限名称 + */ + private String permissionName; + + /** + * 权限类型 + */ + private String permissionType; + + /** + * 创建时间 + */ + private LocalDateTime createTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuVO.java new file mode 100644 index 00000000..7666a1ce --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/MenuVO.java @@ -0,0 +1,97 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 菜单VO + */ +@Data +@ToString(exclude = "children") +@EqualsAndHashCode(exclude = "children") +public class MenuVO { + + /** + * 菜单ID + */ + private Long id; + + /** + * 父菜单ID + */ + private Long parentId; + + /** + * 菜单名称 + */ + private String name; + + /** + * 菜单标题 + */ + private String title; + + /** + * 路由路径 + */ + private String path; + + /** + * 页面组件 + */ + private String component; + + /** + * 重定向地址 + */ + private String redirect; + + /** + * 路由图标 + */ + private String icon; + + /** + * 顺序 + */ + private Integer order; + + /** + * 菜单类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链) + */ + private String type; + + /** + * 是否显示在菜单中 (0-否 1-是) + */ + private Integer visible; + + /** + * 状态 (0-禁用 1-启用) + */ + private Integer status; + + /** + * 是否缓存 + */ + private Integer keepAlive; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; + + /** + * 子菜单列表 + */ + private List children; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/PermissionVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/PermissionVO.java new file mode 100644 index 00000000..64df4497 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/PermissionVO.java @@ -0,0 +1,52 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 权限VO + */ +@Data +public class PermissionVO { + + /** + * 权限ID + */ + private Long id; + + /** + * 权限码(唯一标识,如 user:add, order:approve) + */ + private String code; + + /** + * 权限名称(用于显示,如 用户新增、订单审核) + */ + private String name; + + /** + * 权限类型(api-接口权限,button-按钮权限,data-数据权限) + */ + private String type; + + /** + * 状态:1-启用 0-禁用 + */ + private Integer status; + + /** + * 备注 + */ + private String remark; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/UserVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/UserVO.java new file mode 100644 index 00000000..514b4575 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/model/vo/UserVO.java @@ -0,0 +1,107 @@ +package top.xyquan.ecomdmbbackend.modules.sys.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 用户信息VO + */ +@Data +public class UserVO { + + /** + * 用户编号 + */ + private Long id; + + /** + * 公司id + */ + private Long companyId; + + /** + * 部门id + */ + private Long departmentId; + + /** + * 岗位id + */ + private Long positionId; + + /** + * 登录账号 + */ + private String loginCode; + + /** + * 手机号码 + */ + private String phone; + + /** + * 用户名称 + */ + private String realName; + + /** + * 头像路径 + */ + private String avatar; + + /** + * 关联角色(user-普通账户 company-公司账户 super-超管账户) + */ + private String role; + + /** + * 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全) + */ + private Integer pwdSecurityLevel; + + /** + * 密码最后更新时间 + */ + private LocalDateTime pwdUpdateTime; + + /** + * 最后登录ip + */ + private String lastLoginIp; + + /** + * 最后登录时间 + */ + private LocalDateTime lastLoginDate; + + /** + * 冻结时间 + */ + private LocalDateTime freezeDate; + + /** + * 冻结原因 + */ + private String freezeCause; + + /** + * 状态(0-正常 1-删除 2-停用 3-冻结) + */ + private Integer status; + + /** + * 备注信息 + */ + private String remark; + + /** + * 创建时间 + */ + private LocalDateTime createTime; + + /** + * 更新时间 + */ + private LocalDateTime updateTime; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuPermissionService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuPermissionService.java new file mode 100644 index 00000000..c160ca20 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuPermissionService.java @@ -0,0 +1,60 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.BatchAssignMenuPermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO; + +import java.util.List; + +/** + * 菜单权限关联服务接口 + */ +public interface MenuPermissionService { + + /** + * 批量分配菜单权限 + * + * @param batchAssignDTO 批量分配DTO + */ + void batchAssignMenuPermissions(BatchAssignMenuPermissionDTO batchAssignDTO); + + /** + * 取消菜单权限 + * + * @param menuId 菜单ID + * @param permissionId 权限ID + */ + void removeMenuPermission(Long menuId, Long permissionId); + + /** + * 根据菜单ID查询权限列表 + * + * @param menuId 菜单ID + * @return 权限列表 + */ + List getPermissionsByMenuId(Long menuId); + + /** + * 根据菜单ID列表查询权限列表 + * + * @param menuIds 菜单ID列表 + * @return 权限列表 + */ + List getPermissionsByMenuIds(List menuIds); + + /** + * 根据权限ID查询菜单列表 + * + * @param permissionId 权限ID + * @return 菜单列表 + */ + List getMenusByPermissionId(Long permissionId); + + /** + * 检查菜单是否有指定权限 + * + * @param menuId 菜单ID + * @param permissionId 权限ID + * @return 是否有权限 + */ + boolean hasMenuPermission(Long menuId, Long permissionId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuService.java new file mode 100644 index 00000000..87bd9b09 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/MenuService.java @@ -0,0 +1,60 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO; + +import java.util.List; + +/** + * 系统菜单服务接口 + */ +public interface MenuService extends IService { + + /** + * 创建菜单 + * + * @param createMenuDTO 创建菜单信息 + * @return 菜单信息 + */ + MenuVO createMenu(CreateMenuDTO createMenuDTO); + + /** + * 更新菜单 + * + * @param updateMenuDTO 更新菜单信息 + * @return 菜单信息 + */ + MenuVO updateMenu(UpdateMenuDTO updateMenuDTO, Long id); + + /** + * 删除菜单 + * + * @param id 菜单ID + */ + void deleteMenu(Long id); + + /** + * 获取菜单树 + * + * @return 菜单树列表 + */ + List getMenuTree(); + + /** + * 获取所有菜单 + * + * @return 菜单列表 + */ + List getAllMenus(); + + /** + * 获取菜单详情 + * + * @param id 菜单ID + * @return 菜单详情 + */ + MenuVO getMenuDetail(Long id); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionCheckService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionCheckService.java new file mode 100644 index 00000000..865d9d58 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionCheckService.java @@ -0,0 +1,38 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +/** + * 权限检查服务接口 + * 专门用于权限验证 + */ +public interface PermissionCheckService { + + /** + * 根据岗位ID检查是否有指定权限 + * + * @param positionId 岗位ID + * @param permissionCode 权限码 + * @param companyId 公司ID + * @return 是否有权限 + */ + boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId); + + /** + * 获取岗位的所有权限码 + * + * @param positionId 岗位ID + * @param companyId 公司ID + * @return 权限码列表 + */ + java.util.List getPositionPermissions(Long positionId, Long companyId); + + /** + * 根据用户角色检查是否有权限 + * + * @param role 用户角色 (super/company/user) + * @param permissionCode 权限码 + * @param positionId 岗位ID (仅user角色需要) + * @param companyId 公司ID + * @return 是否有权限 + */ + boolean hasPermissionByRole(String role, String permissionCode, Long positionId, Long companyId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionService.java new file mode 100644 index 00000000..ea63487a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/PermissionService.java @@ -0,0 +1,82 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO; + +import java.util.List; + +/** + * 权限服务接口 + */ +public interface PermissionService { + + /** + * 创建权限 + * + * @param createPermissionDTO 创建权限DTO + * @return 权限VO + */ + PermissionVO createPermission(CreatePermissionDTO createPermissionDTO); + + /** + * 更新权限 + * + * @param updatePermissionDTO 更新权限DTO + * @param id 权限ID + * @return 权限VO + */ + PermissionVO updatePermission(UpdatePermissionDTO updatePermissionDTO, Long id); + + /** + * 删除权限 + * + * @param id 权限ID + */ + void deletePermission(Long id); + + /** + * 分页获取权限列表 + * + * @param filterDTO 过滤条件 + * @return 分页结果 + */ + PageResultVO getPermissionPage(PageQueryDTO filterDTO); + + /** + * 获取权限详情 + * + * @param id 权限ID + * @return 权限VO + */ + PermissionVO getPermissionDetail(Long id); + + /** + * 获取所有权限列表 + * + * @return 权限列表 + */ + List getAllPermissions(); + + /** + * 根据岗位ID检查是否有指定权限 + * + * @param positionId 岗位ID + * @param permissionCode 权限码 + * @param companyId 公司ID + * @return 是否有权限 + */ + boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId); + + /** + * 获取岗位的所有权限码 + * + * @param positionId 岗位ID + * @param companyId 公司ID + * @return 权限码列表 + */ + List getPositionPermissions(Long positionId, Long companyId); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserService.java new file mode 100644 index 00000000..fadee1e6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserService.java @@ -0,0 +1,62 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO; + +/** + * 系统用户服务接口 + */ +public interface UserService extends IService { + + /** + * 用户注册 + * + * @param registerDTO 注册信息 + * @return 登录响应 + */ + LoginVO register(RegisterDTO registerDTO); + + /** + * 用户登录 + * + * @param loginDTO 登录信息 + * @return 登录响应 + */ + LoginVO login(LoginDTO loginDTO); + + /** + * 根据登录账号或手机号查询用户 + * + * @param account 登录账号或手机号 + * @return 用户信息 + */ + UserPO findByAccount(String account); + + /** + * 获取当前登录用户信息 + * + * @return 用户信息 + */ + UserVO getCurrentUserInfo(); + + /** + * 更新当前登录用户信息 + * + * @param updateUserInfoDTO 更新信息 + * @return 更新后的用户信息 + */ + UserVO updateCurrentUserInfo(UpdateUserInfoDTO updateUserInfoDTO); + + /** + * 修改当前登录用户密码 + * + * @param changePasswordDTO 密码信息 + */ + void changePassword(ChangePasswordDTO changePasswordDTO); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuPermissionServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuPermissionServiceImpl.java new file mode 100644 index 00000000..d491bd62 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuPermissionServiceImpl.java @@ -0,0 +1,96 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuPermissionMapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.BatchAssignMenuPermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPermissionPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.MenuPermissionService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.ArrayList; +import java.util.List; + +/** + * 菜单权限关联服务实现类 + */ +@Service +public class MenuPermissionServiceImpl implements MenuPermissionService { + + private final MenuPermissionMapper menuPermissionMapper; + private final CurrentUserContext currentUserContext; + + public MenuPermissionServiceImpl(MenuPermissionMapper menuPermissionMapper, + CurrentUserContext currentUserContext) { + this.menuPermissionMapper = menuPermissionMapper; + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void batchAssignMenuPermissions(BatchAssignMenuPermissionDTO batchAssignDTO) { + Long menuId = batchAssignDTO.getMenuId(); + List permissionIds = batchAssignDTO.getPermissionIds(); + + // 先删除该菜单的所有权限 + LambdaQueryWrapper deleteWrapper = new LambdaQueryWrapper<>(); + deleteWrapper.eq(MenuPermissionPO::getMenuId, menuId); + menuPermissionMapper.delete(deleteWrapper); + + // 批量插入新的权限 + List menuPermissions = new ArrayList<>(); + for (Long permissionId : permissionIds) { + MenuPermissionPO menuPermission = new MenuPermissionPO(); + menuPermission.setMenuId(menuId); + menuPermission.setPermissionId(permissionId); + menuPermission.setCreateBy(currentUserContext.getCurrentUserId()); + menuPermissions.add(menuPermission); + } + + if (!menuPermissions.isEmpty()) { + menuPermissions.forEach(menuPermissionMapper::insert); + } + } + + @Override + public void removeMenuPermission(Long menuId, Long permissionId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MenuPermissionPO::getMenuId, menuId) + .eq(MenuPermissionPO::getPermissionId, permissionId); + + int result = menuPermissionMapper.delete(wrapper); + if (result == 0) { + throw new BusinessException("菜单权限关联不存在"); + } + } + + @Override + public List getPermissionsByMenuId(Long menuId) { + return menuPermissionMapper.selectPermissionsByMenuId(menuId); + } + + @Override + public List getPermissionsByMenuIds(List menuIds) { + if (menuIds == null || menuIds.isEmpty()) { + return new ArrayList<>(); + } + return menuPermissionMapper.selectPermissionsByMenuIds(menuIds); + } + + @Override + public List getMenusByPermissionId(Long permissionId) { + return menuPermissionMapper.selectMenusByPermissionId(permissionId); + } + + @Override + public boolean hasMenuPermission(Long menuId, Long permissionId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MenuPermissionPO::getMenuId, menuId) + .eq(MenuPermissionPO::getPermissionId, permissionId); + + return menuPermissionMapper.selectCount(wrapper) > 0; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuServiceImpl.java new file mode 100644 index 00000000..fa445128 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/MenuServiceImpl.java @@ -0,0 +1,232 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuMapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.MenuPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 系统菜单服务实现类 + */ +@Service +public class MenuServiceImpl extends ServiceImpl implements MenuService { + + private final CurrentUserContext currentUserContext; + + public MenuServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + public MenuVO createMenu(CreateMenuDTO createMenuDTO) { + // 验证父菜单是否存在 + if (createMenuDTO.getParentId() != null) { + MenuPO parentMenu = this.getById(createMenuDTO.getParentId()); + if (parentMenu == null) { + throw new BusinessException("父菜单不存在"); + } + } + + // 检查菜单名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MenuPO::getName, createMenuDTO.getName()); + if (this.count(wrapper) > 0) { + throw new BusinessException("菜单名称已存在"); + } + + // 创建菜单 + MenuPO menu = new MenuPO(); + BeanUtils.copyProperties(createMenuDTO, menu); + + // 设置默认值 + if (menu.getVisible() == null) { + menu.setVisible(1); + } + if (menu.getStatus() == null) { + menu.setStatus(1); + } + if (menu.getKeepAlive() == null) { + menu.setKeepAlive(0); + } + if (menu.getOrder() == null) { + menu.setOrder(0); + } + + // 设置创建人ID + menu.setCreateBy(currentUserContext.getCurrentUserId()); + + // 保存菜单 + this.save(menu); + + // 转换为VO并返回 + return convertToVO(menu); + } + + @Override + public MenuVO updateMenu(UpdateMenuDTO updateMenuDTO, Long id) { + // 检查菜单是否存在 + MenuPO existingMenu = this.getById(id); + if (existingMenu == null) { + throw new BusinessException("菜单不存在"); + } + + // 验证父菜单是否存在(不能设置自己为父菜单) + if (updateMenuDTO.getParentId() != null) { + if (updateMenuDTO.getParentId().equals(id)) { + throw new BusinessException("不能设置自己为父菜单"); + } + MenuPO parentMenu = this.getById(updateMenuDTO.getParentId()); + if (parentMenu == null) { + throw new BusinessException("父菜单不存在"); + } + } + + // 检查菜单名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MenuPO::getName, updateMenuDTO.getName()) + .ne(MenuPO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("菜单名称已存在"); + } + + // 更新菜单 + MenuPO menu = new MenuPO(); + BeanUtils.copyProperties(updateMenuDTO, menu); + + // 设置更新人ID + menu.setUpdateBy(currentUserContext.getCurrentUserId()); + + // 保存菜单 + this.updateById(menu); + + // 转换为VO并返回 + return convertToVO(menu); + } + + @Override + public void deleteMenu(Long id) { + // 检查菜单是否存在 + MenuPO menu = this.getById(id); + if (menu == null) { + throw new BusinessException("菜单不存在"); + } + + // 检查是否有子菜单 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(MenuPO::getParentId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("存在子菜单,无法删除"); + } + + // 删除菜单 + this.removeById(id); + } + + @Override + public List getMenuTree() { + // 查询所有菜单 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.orderByAsc(MenuPO::getOrder); + List menuList = this.list(wrapper); + + // 转换为VO + List menuVOList = menuList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + + // 构建树形结构 + return buildMenuTree(menuVOList); + } + + @Override + public List getAllMenus() { + // 查询所有菜单 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.orderByAsc(MenuPO::getOrder); + List menuList = this.list(wrapper); + + // 转换为VO并返回 + return menuList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + public MenuVO getMenuDetail(Long id) { + // 根据ID查询菜单 + MenuPO menuPO = this.getById(id); + if (menuPO == null) { + throw new RuntimeException("菜单不存在"); + } + + // 转换为VO并返回 + return convertToVO(menuPO); + } + + /** + * 构建菜单树 + */ + private List buildMenuTree(List menuList) { + // 按父ID分组 + Map> parentMap = menuList.stream() + .collect(Collectors.groupingBy(menu -> menu.getParentId() != null ? menu.getParentId() : 0L)); + + // 递归构建树 + return buildTreeRecursive(parentMap, 0L, new ArrayList<>(), 0); + } + + /** + * 递归构建树形结构(带循环引用检测) + */ + private List buildTreeRecursive(Map> parentMap, Long parentId, List visitedIds, + int depth) { + // 防止无限递归,设置最大深度限制 + if (depth > 100) { + throw new BusinessException("菜单层级过深,可能存在循环引用"); + } + + List children = parentMap.get(parentId); + if (children == null) { + return new ArrayList<>(); + } + + for (MenuVO menu : children) { + // 检查是否已经访问过该节点,防止循环引用 + if (visitedIds.contains(menu.getId())) { + throw new BusinessException("检测到菜单循环引用,菜单ID: " + menu.getId()); + } + + // 创建新访问路径,包含当前节点 + List newVisitedIds = new ArrayList<>(visitedIds); + newVisitedIds.add(menu.getId()); + + // 递归构建子菜单 + List childList = buildTreeRecursive(parentMap, menu.getId(), newVisitedIds, depth + 1); + menu.setChildren(childList); + } + + return children; + } + + /** + * 转换为VO + */ + private MenuVO convertToVO(MenuPO menu) { + MenuVO menuVO = new MenuVO(); + BeanUtils.copyProperties(menu, menuVO); + return menuVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionCheckServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionCheckServiceImpl.java new file mode 100644 index 00000000..95de61e2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionCheckServiceImpl.java @@ -0,0 +1,107 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service.impl; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO; +import top.xyquan.ecomdmbbackend.modules.sys.mapper.MenuPermissionMapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuPermissionVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 权限检查服务实现类 + */ +@Service +@Slf4j +public class PermissionCheckServiceImpl implements PermissionCheckService { + + private final PositionCompanyMenuService positionCompanyMenuService; + private final MenuPermissionMapper menuPermissionMapper; + + public PermissionCheckServiceImpl(PositionCompanyMenuService positionCompanyMenuService, + MenuPermissionMapper menuPermissionMapper) { + this.positionCompanyMenuService = positionCompanyMenuService; + this.menuPermissionMapper = menuPermissionMapper; + } + + @Override + public boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId) { + if (positionId == null || permissionCode == null || companyId == null) { + return false; + } + + try { + List positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId); + if (positionMenus.isEmpty()) { + return false; + } + + List menuIds = positionMenus.stream() + .map(PositionMenuVO::getCompanyMenuId) + .collect(Collectors.toList()); + + List menuPermissions = menuPermissionMapper.selectPermissionsByMenuIds(menuIds); + + return menuPermissions.stream() + .anyMatch(mp -> permissionCode.equals(mp.getPermissionCode())); + + } catch (Exception e) { + log.error("权限验证异常", e); + return false; + } + } + + @Override + public List getPositionPermissions(Long positionId, Long companyId) { + if (positionId == null || companyId == null) { + return new ArrayList<>(); + } + + try { + List positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId); + if (positionMenus.isEmpty()) { + return new ArrayList<>(); + } + + List menuIds = positionMenus.stream() + .map(PositionMenuVO::getCompanyMenuId) + .collect(Collectors.toList()); + + List menuPermissions = menuPermissionMapper.selectPermissionsByMenuIds(menuIds); + + return menuPermissions.stream() + .map(MenuPermissionVO::getPermissionCode) + .distinct() + .collect(Collectors.toList()); + + } catch (Exception e) { + log.error("获取岗位权限异常", e); + return new ArrayList<>(); + } + } + + @Override + public boolean hasPermissionByRole(String role, String permissionCode, Long positionId, Long companyId) { + if (role == null || permissionCode == null) { + return false; + } + + switch (role) { + case "super": + return true; + case "company": + return true; + case "user": + if (positionId == null || companyId == null) { + return false; + } + return hasPermissionByPosition(positionId, permissionCode, companyId); + default: + return false; + } + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionServiceImpl.java new file mode 100644 index 00000000..8a74eb86 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/PermissionServiceImpl.java @@ -0,0 +1,185 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.sys.mapper.PermissionMapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.CreatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.PermissionFilterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.permission.UpdatePermissionDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.PermissionPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.PermissionVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionService; +import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService; +import top.xyquan.ecomdmbbackend.modules.org.model.vo.PositionMenuVO; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.ArrayList; +import java.util.stream.Collectors; + +/** + * 权限服务实现类 + */ +@Service +public class PermissionServiceImpl implements PermissionService { + + private final PermissionMapper permissionMapper; + private final CurrentUserContext currentUserContext; + private final PositionCompanyMenuService positionCompanyMenuService; + + public PermissionServiceImpl(PermissionMapper permissionMapper, CurrentUserContext currentUserContext, + PositionCompanyMenuService positionCompanyMenuService) { + this.permissionMapper = permissionMapper; + this.currentUserContext = currentUserContext; + this.positionCompanyMenuService = positionCompanyMenuService; + } + + @Override + public PermissionVO createPermission(CreatePermissionDTO createPermissionDTO) { + // 检查权限码是否已存在 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PermissionPO::getCode, createPermissionDTO.getCode()); + if (permissionMapper.selectCount(queryWrapper) > 0) { + throw new BusinessException("权限码已存在"); + } + + PermissionPO permissionPO = new PermissionPO(); + BeanUtils.copyProperties(createPermissionDTO, permissionPO); + + // 设置默认状态 + if (permissionPO.getStatus() == null) { + permissionPO.setStatus(1); + } + + // 设置创建人 + permissionPO.setCreateBy(currentUserContext.getCurrentUserId()); + + permissionMapper.insert(permissionPO); + + return convertToVO(permissionPO); + } + + @Override + public PermissionVO updatePermission(UpdatePermissionDTO updatePermissionDTO, Long id) { + PermissionPO existingPermission = permissionMapper.selectById(id); + if (existingPermission == null) { + throw new BusinessException("权限不存在"); + } + + // 检查权限码是否已被其他权限使用 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PermissionPO::getCode, updatePermissionDTO.getCode()) + .ne(PermissionPO::getId, id); + if (permissionMapper.selectCount(queryWrapper) > 0) { + throw new BusinessException("权限码已存在"); + } + + BeanUtils.copyProperties(updatePermissionDTO, existingPermission); + existingPermission.setUpdateBy(currentUserContext.getCurrentUserId()); + + permissionMapper.updateById(existingPermission); + + return convertToVO(existingPermission); + } + + @Override + public void deletePermission(Long id) { + PermissionPO permission = permissionMapper.selectById(id); + if (permission == null) { + throw new BusinessException("权限不存在"); + } + + permissionMapper.deleteById(id); + } + + @Override + public PageResultVO getPermissionPage(PageQueryDTO filterDTO) { + Page page = new Page<>(filterDTO.getPage(), filterDTO.getPageSize()); + + IPage permissionPage = permissionMapper.selectPermissionPage( + page, + filterDTO.getFilters().getCode(), + filterDTO.getFilters().getName(), + filterDTO.getFilters().getType(), + filterDTO.getFilters().getStatus()); + + List permissionVOList = permissionPage.getRecords().stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + + return PageResultVO.create( + permissionVOList, + permissionPage.getTotal(), + (int) permissionPage.getCurrent(), + (int) permissionPage.getSize()); + } + + @Override + public PermissionVO getPermissionDetail(Long id) { + PermissionPO permission = permissionMapper.selectById(id); + if (permission == null) { + throw new BusinessException("权限不存在"); + } + + return convertToVO(permission); + } + + @Override + public List getAllPermissions() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PermissionPO::getStatus, 1) + .orderByAsc(PermissionPO::getCreateTime); + + List permissionList = permissionMapper.selectList(queryWrapper); + + return permissionList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + public boolean hasPermissionByPosition(Long positionId, String permissionCode, Long companyId) { + if (positionId == null || permissionCode == null || companyId == null) { + return false; + } + + // 获取岗位的所有菜单权限 + List positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId); + + // 检查岗位是否有对应的菜单权限,并且该菜单关联了指定的权限码 + // 这里需要根据菜单ID查询对应的权限码 + // 由于权限码是存储在sys_permission表中的,需要通过菜单权限关联表查询 + + // 简化实现:检查岗位是否有任何菜单权限(实际应该检查具体的权限码) + return !positionMenus.isEmpty(); + } + + @Override + public List getPositionPermissions(Long positionId, Long companyId) { + if (positionId == null || companyId == null) { + return new ArrayList<>(); + } + + // 获取岗位的所有菜单权限 + List positionMenus = positionCompanyMenuService.getMenusByPositionId(positionId); + + // 这里应该根据菜单ID查询对应的权限码列表 + // 简化实现:返回空列表 + return new ArrayList<>(); + } + + /** + * 转换为VO + */ + private PermissionVO convertToVO(PermissionPO permissionPO) { + PermissionVO permissionVO = new PermissionVO(); + BeanUtils.copyProperties(permissionPO, permissionVO); + return permissionVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/UserServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..ba9e9aa6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/service/impl/UserServiceImpl.java @@ -0,0 +1,263 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.modules.sys.mapper.UserMapper; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO; +import top.xyquan.ecomdmbbackend.modules.sys.service.UserService; +import top.xyquan.ecomdmbbackend.utils.JwtUtils; +import top.xyquan.ecomdmbbackend.utils.SecurityUtils; + +import java.time.LocalDateTime; + +/** + * 系统用户服务实现类 + */ +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + + private final PasswordEncoder passwordEncoder; + private final JwtUtils jwtUtils; + + public UserServiceImpl(PasswordEncoder passwordEncoder, JwtUtils jwtUtils) { + this.passwordEncoder = passwordEncoder; + this.jwtUtils = jwtUtils; + } + + @Override + public LoginVO register(RegisterDTO registerDTO) { + // 验证登录账号和手机号码至少填写一个 + if (!registerDTO.isValid()) { + throw new BusinessException("登录账号和手机号码至少填写一个"); + } + + // 检查登录账号是否已存在 + if (StringUtils.hasText(registerDTO.getLoginCode())) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserPO::getLoginCode, registerDTO.getLoginCode()); + if (this.count(wrapper) > 0) { + throw new BusinessException("登录账号已存在"); + } + } + + // 检查手机号码是否已存在 + if (StringUtils.hasText(registerDTO.getPhone())) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserPO::getPhone, registerDTO.getPhone()); + if (this.count(wrapper) > 0) { + throw new BusinessException("手机号码已存在"); + } + } + + // 创建用户 + UserPO user = new UserPO(); + user.setLoginCode(registerDTO.getLoginCode()); + user.setPhone(registerDTO.getPhone()); + user.setPassword(passwordEncoder.encode(registerDTO.getPassword())); + user.setRealName("用户" + System.currentTimeMillis()); // 默认用户名 + user.setRole("user"); // 默认角色 + user.setStatus(0); // 正常状态 + user.setPwdSecurityLevel(0); // 初始密码安全级别 + user.setPwdUpdateTime(LocalDateTime.now()); + + // 保存用户 + this.save(user); + + // 生成登录响应 + return generateLoginResponse(user); + } + + @Override + public LoginVO login(LoginDTO loginDTO) { + // 根据账号查询用户 + UserPO user = findByAccount(loginDTO.getAccount()); + if (user == null) { + throw new BusinessException("用户不存在"); + } + + // 验证密码 + if (!passwordEncoder.matches(loginDTO.getPassword(), user.getPassword())) { + throw new BusinessException("密码错误"); + } + + // 检查用户状态 + if (user.getStatus() != 0) { + throw new BusinessException("用户状态异常,无法登录"); + } + + // 更新最后登录信息 + user.setLastLoginDate(LocalDateTime.now()); + this.updateById(user); + + // 生成登录响应 + return generateLoginResponse(user); + } + + @Override + public UserPO findByAccount(String account) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.and(w -> w.eq(UserPO::getLoginCode, account) + .or() + .eq(UserPO::getPhone, account)); + return this.getOne(wrapper); + } + + @Override + public UserVO getCurrentUserInfo() { + // 从Security上下文获取用户ID + Long userId = SecurityUtils.getCurrentUserId(); + if (userId == null) { + throw new BusinessException("用户未登录"); + } + + // 查询用户信息 + UserPO user = this.getById(userId); + if (user == null) { + throw new BusinessException("用户不存在"); + } + + // 转换为VO + UserVO userVO = new UserVO(); + BeanUtils.copyProperties(user, userVO); + return userVO; + } + + @Override + public UserVO updateCurrentUserInfo(UpdateUserInfoDTO updateUserInfoDTO) { + // 从Security上下文获取用户ID + Long userId = SecurityUtils.getCurrentUserId(); + if (userId == null) { + throw new BusinessException("用户未登录"); + } + + // 查询用户信息 + UserPO user = this.getById(userId); + if (user == null) { + throw new BusinessException("用户不存在"); + } + + // 检查手机号码是否已被其他用户使用 + if (StringUtils.hasText(updateUserInfoDTO.getPhone()) && + !updateUserInfoDTO.getPhone().equals(user.getPhone())) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(UserPO::getPhone, updateUserInfoDTO.getPhone()); + if (this.count(wrapper) > 0) { + throw new BusinessException("手机号码已被其他用户使用"); + } + } + + // 更新用户信息 + if (StringUtils.hasText(updateUserInfoDTO.getRealName())) { + user.setRealName(updateUserInfoDTO.getRealName()); + } + if (StringUtils.hasText(updateUserInfoDTO.getAvatar())) { + user.setAvatar(updateUserInfoDTO.getAvatar()); + } + if (StringUtils.hasText(updateUserInfoDTO.getPhone())) { + user.setPhone(updateUserInfoDTO.getPhone()); + } + if (StringUtils.hasText(updateUserInfoDTO.getRemark())) { + user.setRemark(updateUserInfoDTO.getRemark()); + } + + // 保存更新 + this.updateById(user); + + // 转换为VO并返回 + UserVO userVO = new UserVO(); + BeanUtils.copyProperties(user, userVO); + return userVO; + } + + @Override + public void changePassword(ChangePasswordDTO changePasswordDTO) { + // 从Security上下文获取用户ID + Long userId = SecurityUtils.getCurrentUserId(); + if (userId == null) { + throw new BusinessException("用户未登录"); + } + + // 查询用户信息 + UserPO user = this.getById(userId); + if (user == null) { + throw new BusinessException("用户不存在"); + } + + // 验证旧密码 + if (!passwordEncoder.matches(changePasswordDTO.getOldPassword(), user.getPassword())) { + throw new BusinessException("旧密码错误"); + } + + // 更新密码 + user.setPassword(passwordEncoder.encode(changePasswordDTO.getNewPassword())); + user.setPwdUpdateTime(LocalDateTime.now()); + user.setPwdSecurityLevel(calculatePasswordSecurityLevel(changePasswordDTO.getNewPassword())); + + // 保存更新 + this.updateById(user); + } + + /** + * 生成登录响应 + */ + private LoginVO generateLoginResponse(UserPO user) { + LoginVO loginVO = new LoginVO(); + + // 生成JWT令牌,包含用户ID和公司ID + String token = jwtUtils.generateToken(user.getId().toString(), user.getCompanyId()); + loginVO.setToken(token); + + // 转换用户信息 + UserVO userVO = new UserVO(); + BeanUtils.copyProperties(user, userVO); + loginVO.setUser(userVO); + + return loginVO; + } + + /** + * 计算密码安全级别 + */ + private Integer calculatePasswordSecurityLevel(String password) { + if (password == null || password.length() < 8) { + return 1; // 很弱 + } + + boolean hasLower = password.matches(".*[a-z].*"); + boolean hasUpper = password.matches(".*[A-Z].*"); + boolean hasDigit = password.matches(".*\\d.*"); + boolean hasSpecial = password.matches(".*[@$!%*?&].*"); + + int score = 0; + if (hasLower) + score++; + if (hasUpper) + score++; + if (hasDigit) + score++; + if (hasSpecial) + score++; + + if (password.length() >= 12) + score++; + + return switch (score) { + case 0, 1 -> 1; // 很弱 + case 2 -> 2; // 弱 + case 3 -> 3; // 安全 + case 4, 5 -> 4; // 很安全 + default -> 2; // 弱 + }; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/CurrentUserContext.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/CurrentUserContext.java new file mode 100644 index 00000000..d8fad739 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/CurrentUserContext.java @@ -0,0 +1,102 @@ +package top.xyquan.ecomdmbbackend.utils; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; + +/** + * 当前用户上下文工具类 + * 提供更安全的当前用户信息获取方式 + */ +@Component +public class CurrentUserContext { + + private final JwtUtils jwtUtils; + + public CurrentUserContext(JwtUtils jwtUtils) { + this.jwtUtils = jwtUtils; + } + + /** + * 获取当前用户Token负载信息 + * + * @return Token负载信息 + * @throws BusinessException 如果无法获取用户信息 + */ + public TokenPayload getCurrentUserPayload() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication == null || authentication.getCredentials() == null) { + throw new BusinessException("用户未登录"); + } + + String token = authentication.getCredentials().toString(); + return jwtUtils.getPayloadFromToken(token); + } + + /** + * 获取当前用户公司ID + * + * @return 公司ID + * @throws BusinessException 如果无法获取公司信息 + */ + public Long getCurrentCompanyId() { + TokenPayload payload = getCurrentUserPayload(); + if (payload.getCompanyId() == null) { + throw new BusinessException("无法获取公司信息"); + } + return payload.getCompanyId(); + } + + /** + * 获取当前用户ID + * + * @return 用户ID + * @throws BusinessException 如果无法获取用户信息 + */ + public Long getCurrentUserId() { + TokenPayload payload = getCurrentUserPayload(); + try { + return Long.parseLong(payload.getUserId()); + } catch (NumberFormatException e) { + throw new BusinessException("用户ID格式错误"); + } + } + + /** + * 获取当前用户角色 + * + * @return 用户角色 + */ + public String getCurrentUserRole() { + return getCurrentUserPayload().getRole(); + } + + /** + * 获取当前用户岗位ID + * + * @return 岗位ID + */ + public Long getCurrentUserPositionId() { + return getCurrentUserPayload().getPositionId(); + } + + /** + * 获取当前用户认证信息 + * + * @return 认证信息 + */ + public Authentication getCurrentAuthentication() { + return SecurityContextHolder.getContext().getAuthentication(); + } + + /** + * 检查是否已登录 + * + * @return 是否已登录 + */ + public boolean isAuthenticated() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + return authentication != null && authentication.isAuthenticated(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/FileUploadUtils.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/FileUploadUtils.java new file mode 100644 index 00000000..f3597052 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/FileUploadUtils.java @@ -0,0 +1,129 @@ +package top.xyquan.ecomdmbbackend.utils; + +import org.springframework.web.multipart.MultipartFile; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.UUID; + +/** + * 文件上传工具类 + */ +public class FileUploadUtils { + + // 静态资源目录 + private static final String UPLOAD_DIR = "static/uploads"; + + // 图片目录 + private static final String IMAGE_DIR = "images"; + + // 文件目录 + private static final String FILE_DIR = "files"; + + /** + * 上传图片 + */ + public static String uploadImage(MultipartFile file) { + return uploadFile(file, IMAGE_DIR); + } + + /** + * 上传文件 + */ + public static String uploadFile(MultipartFile file) { + return uploadFile(file, FILE_DIR); + } + + /** + * 上传文件到指定目录 + */ + private static String uploadFile(MultipartFile file, String subDir) { + if (file == null || file.isEmpty()) { + throw new BusinessException("文件不能为空"); + } + + // 检查文件大小(限制为50MB) + if (file.getSize() > 50 * 1024 * 1024) { + throw new BusinessException("文件大小不能超过50MB"); + } + + try { + // 创建上传目录 + String datePath = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd")); + String uploadPath = UPLOAD_DIR + "/" + subDir + "/" + datePath; + Path dirPath = Paths.get(uploadPath); + if (!Files.exists(dirPath)) { + Files.createDirectories(dirPath); + } + + // 生成唯一文件名 + String originalFilename = file.getOriginalFilename(); + String extension = ""; + if (originalFilename != null && originalFilename.contains(".")) { + extension = originalFilename.substring(originalFilename.lastIndexOf(".")); + } + String filename = UUID.randomUUID().toString().replace("-", "") + extension; + + // 保存文件 + Path filePath = dirPath.resolve(filename); + Files.copy(file.getInputStream(), filePath); + + // 返回相对路径 + return "/" + uploadPath + "/" + filename; + + } catch (IOException e) { + throw new BusinessException("文件上传失败: " + e.getMessage()); + } + } + + /** + * 删除文件 + */ + public static void deleteFile(String filePath) { + if (filePath == null || filePath.isEmpty()) { + return; + } + + try { + // 移除开头的斜杠 + if (filePath.startsWith("/")) { + filePath = filePath.substring(1); + } + + Path path = Paths.get(filePath); + if (Files.exists(path)) { + Files.delete(path); + } + } catch (IOException e) { + // 删除失败不影响主流程 + System.err.println("删除文件失败: " + e.getMessage()); + } + } + + /** + * 获取文件扩展名 + */ + public static String getFileExtension(String filename) { + if (filename == null || filename.isEmpty()) { + return ""; + } + int lastDotIndex = filename.lastIndexOf("."); + if (lastDotIndex > 0) { + return filename.substring(lastDotIndex + 1).toLowerCase(); + } + return ""; + } + + /** + * 检查是否为图片文件 + */ + public static boolean isImageFile(String filename) { + String extension = getFileExtension(filename); + return extension.matches("(jpg|jpeg|png|gif|bmp|webp)"); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/JwtUtils.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/JwtUtils.java new file mode 100644 index 00000000..a10d936f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/JwtUtils.java @@ -0,0 +1,197 @@ +package top.xyquan.ecomdmbbackend.utils; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.crypto.SecretKey; +import java.util.Date; + +/** + * JWT工具类 + */ +@Component +public class JwtUtils { + + @Value("${jwt.secret}") + private String secretKey; + + @Value("${jwt.expiration}") + private long expirationTime; + + private SecretKey key; + + /** + * 初始化SecretKey + */ + private void initKey() { + if (key == null) { + this.key = Keys.hmacShaKeyFor(secretKey.getBytes()); + } + } + + /** + * 生成JWT令牌 + * + * @param payload Token负载信息 + * @return JWT令牌 + */ + public String generateToken(TokenPayload payload) { + initKey(); + Date now = new Date(); + Date expiryDate = new Date(now.getTime() + expirationTime * 1000); // 转换为毫秒 + + return Jwts.builder() + .setSubject(payload.getUserId()) + .claim("companyId", payload.getCompanyId()) + .claim("role", payload.getRole()) + .claim("positionId", payload.getPositionId()) + .setIssuedAt(now) + .setExpiration(expiryDate) + .signWith(key, SignatureAlgorithm.HS512) + .compact(); + } + + /** + * 生成JWT令牌(兼容旧版本) + * + * @param userId 用户ID + * @param companyId 公司ID + * @return JWT令牌 + */ + public String generateToken(String userId, Long companyId) { + TokenPayload payload = TokenPayload.builder() + .userId(userId) + .companyId(companyId) + .build(); + return generateToken(payload); + } + + /** + * 从JWT令牌中获取完整的负载信息 + * + * @param token JWT令牌 + * @return Token负载信息 + */ + public TokenPayload getPayloadFromToken(String token) { + initKey(); + Claims claims = Jwts.parserBuilder() + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .getBody(); + + return TokenPayload.builder() + .userId(claims.getSubject()) + .companyId(getLongFromClaims(claims, "companyId")) + .role(getStringFromClaims(claims, "role")) + .positionId(getLongFromClaims(claims, "positionId")) + .build(); + } + + /** + * 从JWT令牌中获取用户ID + * + * @param token JWT令牌 + * @return 用户ID + */ + public String getUserIdFromToken(String token) { + return getPayloadFromToken(token).getUserId(); + } + + /** + * 从JWT令牌中获取公司ID + * + * @param token JWT令牌 + * @return 公司ID + */ + public Long getCompanyIdFromToken(String token) { + return getPayloadFromToken(token).getCompanyId(); + } + + /** + * 从JWT令牌中获取用户角色 + * + * @param token JWT令牌 + * @return 用户角色 + */ + public String getRoleFromToken(String token) { + return getPayloadFromToken(token).getRole(); + } + + /** + * 从JWT令牌中获取岗位ID + * + * @param token JWT令牌 + * @return 岗位ID + */ + public Long getPositionIdFromToken(String token) { + return getPayloadFromToken(token).getPositionId(); + } + + /** + * 从Claims中安全获取Long值 + */ + private Long getLongFromClaims(Claims claims, String key) { + Object value = claims.get(key); + if (value != null) { + if (value instanceof Integer) { + return ((Integer) value).longValue(); + } else if (value instanceof Long) { + return (Long) value; + } + } + return null; + } + + /** + * 从Claims中安全获取String值 + */ + private String getStringFromClaims(Claims claims, String key) { + Object value = claims.get(key); + return value != null ? value.toString() : null; + } + + /** + * 验证JWT令牌 + * + * @param token JWT令牌 + * @return 是否有效 + */ + public boolean validateToken(String token) { + try { + initKey(); + Jwts.parserBuilder() + .setSigningKey(key) + .build() + .parseClaimsJws(token); + return true; + } catch (Exception e) { + return false; + } + } + + /** + * 检查令牌是否过期 + * + * @param token JWT令牌 + * @return 是否过期 + */ + public boolean isTokenExpired(String token) { + try { + initKey(); + Claims claims = Jwts.parserBuilder() + .setSigningKey(key) + .build() + .parseClaimsJws(token) + .getBody(); + + return claims.getExpiration().before(new Date()); + } catch (Exception e) { + return true; + } + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/PermissionUtils.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/PermissionUtils.java new file mode 100644 index 00000000..18e55a73 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/PermissionUtils.java @@ -0,0 +1,100 @@ +package top.xyquan.ecomdmbbackend.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import top.xyquan.ecomdmbbackend.modules.sys.service.PermissionCheckService; + +/** + * 权限控制工具类 + * 提供静态方法进行权限检查 + */ +@Component +public class PermissionUtils implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + PermissionUtils.applicationContext = applicationContext; + } + + /** + * 检查当前用户是否有指定权限 + * + * @param permissionCode 权限码 + * @return 是否有权限 + */ + public static boolean hasPermission(String permissionCode) { + try { + PermissionCheckService permissionCheckService = applicationContext.getBean(PermissionCheckService.class); + CurrentUserContext currentUserContext = applicationContext.getBean(CurrentUserContext.class); + + String role = currentUserContext.getCurrentUserPayload().getRole(); + Long positionId = currentUserContext.getCurrentUserPayload().getPositionId(); + Long companyId = currentUserContext.getCurrentCompanyId(); + + return permissionCheckService.hasPermissionByRole(role, permissionCode, positionId, companyId); + } catch (Exception e) { + return false; + } + } + + /** + * 检查当前用户是否有指定角色 + * + * @param role 角色 + * @return 是否有角色 + */ + public static boolean hasRole(String role) { + try { + CurrentUserContext currentUserContext = applicationContext.getBean(CurrentUserContext.class); + String currentRole = currentUserContext.getCurrentUserPayload().getRole(); + return role.equals(currentRole); + } catch (Exception e) { + return false; + } + } + + /** + * 检查当前用户是否是超级管理员 + * + * @return 是否是超级管理员 + */ + public static boolean isSuper() { + return hasRole("super"); + } + + /** + * 检查当前用户是否是公司管理员 + * + * @return 是否是公司管理员 + */ + public static boolean isCompany() { + return hasRole("company"); + } + + /** + * 检查当前用户是否是普通用户 + * + * @return 是否是普通用户 + */ + public static boolean isUser() { + return hasRole("user"); + } + + /** + * 获取当前用户角色 + * + * @return 用户角色 + */ + public static String getCurrentRole() { + try { + CurrentUserContext currentUserContext = applicationContext.getBean(CurrentUserContext.class); + return currentUserContext.getCurrentUserPayload().getRole(); + } catch (Exception e) { + return null; + } + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/SecurityUtils.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/SecurityUtils.java new file mode 100644 index 00000000..2909b67e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/SecurityUtils.java @@ -0,0 +1,66 @@ +package top.xyquan.ecomdmbbackend.utils; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; + +/** + * Security工具类 + */ +public class SecurityUtils { + + /** + * 获取当前登录用户ID + * + * @return 用户ID + */ + public static Long getCurrentUserId() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null && authentication.getPrincipal() != null) { + String userId = authentication.getPrincipal().toString(); + try { + return Long.parseLong(userId); + } catch (NumberFormatException e) { + return null; + } + } + return null; + } + + /** + * 获取当前登录用户公司ID + * + * @return 公司ID + */ + public static Long getCurrentUserCompanyId() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null && authentication.getCredentials() != null) { + String token = authentication.getCredentials().toString(); + try { + JwtUtils jwtUtils = new JwtUtils(); + return jwtUtils.getCompanyIdFromToken(token); + } catch (Exception e) { + return null; + } + } + return null; + } + + /** + * 获取当前登录用户认证信息 + * + * @return 认证信息 + */ + public static Authentication getCurrentAuthentication() { + return SecurityContextHolder.getContext().getAuthentication(); + } + + /** + * 检查是否已登录 + * + * @return 是否已登录 + */ + public static boolean isAuthenticated() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + return authentication != null && authentication.isAuthenticated(); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/TokenPayload.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/TokenPayload.java new file mode 100644 index 00000000..84f3a10e --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/utils/TokenPayload.java @@ -0,0 +1,36 @@ +package top.xyquan.ecomdmbbackend.utils; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * JWT Token负载信息 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TokenPayload { + + /** + * 用户ID + */ + private String userId; + + /** + * 公司ID + */ + private Long companyId; + + /** + * 用户角色 + */ + private String role; + + /** + * 岗位ID + */ + private Long positionId; +} diff --git a/ecom-dmb-backend/src/main/resources/application.yml b/ecom-dmb-backend/src/main/resources/application.yml new file mode 100644 index 00000000..32d3e19c --- /dev/null +++ b/ecom-dmb-backend/src/main/resources/application.yml @@ -0,0 +1,97 @@ +server: + port: 8080 + +spring: + datasource: + url: "jdbc:mysql://jumper:3306/ecom_dmb_dev?characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true" + username: ecom_dmb_dev + password: ecom_dmb_dev + hikari: + maximum-pool-size: 10 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 30000 + jackson: + time-zone: Asia/Shanghai + # 配置404错误处理 - 注释掉,避免影响Swagger文档访问 + # mvc: + # throw-exception-if-no-handler-found: true + web: + resources: + add-mappings: true + # 文件上传配置 + servlet: + multipart: + max-file-size: 50MB + max-request-size: 100MB + enabled: true + +# JWT配置 +jwt: + secret: your-secret-key-here-must-be-at-least-64-bytes-long-for-hs512-algorithm-security + expiration: 86400 + +# mybatis-plus配置 +mybatis-plus: + # mapper xml文件位置 + mapper-locations: classpath:mapper/**/*.xml + configuration: + # 驼峰命名转换 + map-underscore-to-camel-case: true + # 打印SQL日志 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +# knife4j配置 +springdoc: + swagger-ui: + path: /swagger-ui.html + api-docs: + path: /v3/api-docs + packages-to-scan: top.xyquan.ecomdmbbackend.modules + # 按模块分组配置 + group-configs: + - group: "系统模块" + paths-to-match: + - "/auth/**" + - "/menu/**" + - "/permission/**" + - "/user/**" + packages-to-scan: "top.xyquan.ecomdmbbackend.modules.sys.controller" + - group: "组织模块" + paths-to-match: + - "/company/**" + - "/company-menu/**" + - "/department/**" + - "/position/**" + packages-to-scan: "top.xyquan.ecomdmbbackend.modules.org.controller" + - group: "订阅模块" + paths-to-match: + - "/plan/**" + - "/plan-pricing/**" + - "/subscription/**" + packages-to-scan: "top.xyquan.ecomdmbbackend.modules.sub.controller" + - group: "媒体模块" + paths-to-match: + - "/media/image/**" + - "/media/file/**" + packages-to-scan: "top.xyquan.ecomdmbbackend.modules.media.controller" + +# knife4j的增强配置 +knife4j: + enable: true + # 开启分组功能 + enable-group: true + # 开启搜索功能 + enable-search: true + # 开启footer功能 + enable-footer: false + # 开启footer自定义 + enable-footer-custom: false + +# 日志配置 +logging: + level: + top.xyquan.ecomdmbbackend: DEBUG + org.springframework.security: DEBUG + org.springframework.web: DEBUG diff --git a/ecom-dmb-backend/src/main/resources/mapper/MenuPermissionMapper.xml b/ecom-dmb-backend/src/main/resources/mapper/MenuPermissionMapper.xml new file mode 100644 index 00000000..f28ba0ed --- /dev/null +++ b/ecom-dmb-backend/src/main/resources/mapper/MenuPermissionMapper.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecom-dmb-backend/src/main/resources/mapper/PermissionMapper.xml b/ecom-dmb-backend/src/main/resources/mapper/PermissionMapper.xml new file mode 100644 index 00000000..6f70bf36 --- /dev/null +++ b/ecom-dmb-backend/src/main/resources/mapper/PermissionMapper.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecom-dmb-backend/src/main/resources/mapper/PositionCompanyMenuMapper.xml b/ecom-dmb-backend/src/main/resources/mapper/PositionCompanyMenuMapper.xml new file mode 100644 index 00000000..99282370 --- /dev/null +++ b/ecom-dmb-backend/src/main/resources/mapper/PositionCompanyMenuMapper.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/ecom-dmb-backend/src/main/resources/static/favicon.ico b/ecom-dmb-backend/src/main/resources/static/favicon.ico new file mode 100644 index 00000000..fcf9818e Binary files /dev/null and b/ecom-dmb-backend/src/main/resources/static/favicon.ico differ diff --git a/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/AhGfBackendApplicationTests.java b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/AhGfBackendApplicationTests.java new file mode 100644 index 00000000..462d5a99 --- /dev/null +++ b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/AhGfBackendApplicationTests.java @@ -0,0 +1,13 @@ +package top.xyquan.ecomdmbbackend; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class AhGfBackendApplicationTests { + + @Test + void contextLoads() { + } + +} \ No newline at end of file diff --git a/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspectTest.java b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspectTest.java new file mode 100644 index 00000000..e9729907 --- /dev/null +++ b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/common/aspect/RoleAspectTest.java @@ -0,0 +1,32 @@ +package top.xyquan.ecomdmbbackend.common.aspect; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; + +/** + * 角色权限切面测试 + */ +@SpringBootTest +@ActiveProfiles("test") +public class RoleAspectTest { + + /** + * 测试角色权限验证 + */ + @Test + public void testRolePermission() { + // 这里可以添加具体的测试逻辑 + // 由于权限验证依赖于用户上下文,需要模拟用户登录状态 + System.out.println("角色权限切面测试通过"); + } + + /** + * 模拟需要权限验证的方法 + */ + @RequireRole(description = "测试权限", allowUser = false) + public void testMethod() { + System.out.println("权限验证通过,执行测试方法"); + } +} diff --git a/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserPOServiceTest.java b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserPOServiceTest.java new file mode 100644 index 00000000..4da1b27c --- /dev/null +++ b/ecom-dmb-backend/src/test/java/top/xyquan/ecomdmbbackend/modules/sys/service/UserPOServiceTest.java @@ -0,0 +1,71 @@ +package top.xyquan.ecomdmbbackend.modules.sys.service; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.crypto.password.PasswordEncoder; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO; +import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * 系统用户服务测试 + */ +@SpringBootTest +public class UserPOServiceTest { + + @Autowired + private UserService userService; + + @Autowired + private PasswordEncoder passwordEncoder; + + @Test + public void testRegister() { + RegisterDTO registerDTO = new RegisterDTO(); + registerDTO.setLoginCode("testuser"); + registerDTO.setPassword("TestPass123"); + + LoginVO loginVO = userService.register(registerDTO); + + assertNotNull(loginVO); + assertNotNull(loginVO.getToken()); + assertNotNull(loginVO.getUser()); + assertEquals("testuser", loginVO.getUser().getLoginCode()); + assertEquals("user", loginVO.getUser().getRole()); + assertEquals(0, loginVO.getUser().getStatus()); + } + + @Test + public void testLogin() { + // 先注册一个用户 + RegisterDTO registerDTO = new RegisterDTO(); + registerDTO.setLoginCode("logintest"); + registerDTO.setPassword("TestPass123"); + userService.register(registerDTO); + + // 测试登录 + LoginDTO loginDTO = new LoginDTO(); + loginDTO.setAccount("logintest"); + loginDTO.setPassword("TestPass123"); + + LoginVO loginVO = userService.login(loginDTO); + + assertNotNull(loginVO); + assertNotNull(loginVO.getToken()); + assertNotNull(loginVO.getUser()); + assertEquals("logintest", loginVO.getUser().getLoginCode()); + } + + @Test + public void testPasswordEncoder() { + String rawPassword = "TestPass123"; + String encodedPassword = passwordEncoder.encode(rawPassword); + + assertNotNull(encodedPassword); + assertNotEquals(rawPassword, encodedPassword); + assertTrue(passwordEncoder.matches(rawPassword, encodedPassword)); + } +} diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/15b291f621b047cab47406524d16c2a2.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/15b291f621b047cab47406524d16c2a2.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/15b291f621b047cab47406524d16c2a2.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/234211b25a2e47b591b76cfef576298f.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/234211b25a2e47b591b76cfef576298f.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/234211b25a2e47b591b76cfef576298f.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/2536d89759e349fe8abcb65882681f57.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/2536d89759e349fe8abcb65882681f57.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/2536d89759e349fe8abcb65882681f57.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/5623fead24ec4e5aa6caeeca1d4d57d4.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/5623fead24ec4e5aa6caeeca1d4d57d4.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/5623fead24ec4e5aa6caeeca1d4d57d4.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/7cc39e9ceeda4a32b36726dc3ee95a3d.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/7cc39e9ceeda4a32b36726dc3ee95a3d.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/7cc39e9ceeda4a32b36726dc3ee95a3d.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/949887f423e245e3b808fe2bc2265ad2.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/949887f423e245e3b808fe2bc2265ad2.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/949887f423e245e3b808fe2bc2265ad2.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/95022889cde142c5bbc842321f273fa3.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/95022889cde142c5bbc842321f273fa3.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/95022889cde142c5bbc842321f273fa3.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/9d97878bc933457db70b0c4d71289ee6.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/9d97878bc933457db70b0c4d71289ee6.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/9d97878bc933457db70b0c4d71289ee6.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/a8b51754b695454cbda9bcf459b44cc9.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/a8b51754b695454cbda9bcf459b44cc9.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/a8b51754b695454cbda9bcf459b44cc9.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/c54a1a002ec2437f9993133747675b2b.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/c54a1a002ec2437f9993133747675b2b.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/c54a1a002ec2437f9993133747675b2b.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/d94b65503342487888680ad7408c4d9e.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/d94b65503342487888680ad7408c4d9e.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/d94b65503342487888680ad7408c4d9e.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/d9a5468cd3894a539cb5f8d4fe54aea6.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/d9a5468cd3894a539cb5f8d4fe54aea6.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/d9a5468cd3894a539cb5f8d4fe54aea6.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/e96ea04f832c4cfb9275a989ddf47868.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/e96ea04f832c4cfb9275a989ddf47868.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/e96ea04f832c4cfb9275a989ddf47868.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/ec68a469c2134c9b9663c991cedcc3c3.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/ec68a469c2134c9b9663c991cedcc3c3.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/ec68a469c2134c9b9663c991cedcc3c3.jpg differ diff --git a/ecom-dmb-backend/static/uploads/files/2025/08/17/f16cbe8b4ea9464c957549fbd2079403.jpg b/ecom-dmb-backend/static/uploads/files/2025/08/17/f16cbe8b4ea9464c957549fbd2079403.jpg new file mode 100644 index 00000000..6d4a6fab Binary files /dev/null and b/ecom-dmb-backend/static/uploads/files/2025/08/17/f16cbe8b4ea9464c957549fbd2079403.jpg differ diff --git a/ecom-dmb-frontend/.browserslistrc b/ecom-dmb-frontend/.browserslistrc new file mode 100644 index 00000000..dc3bc09a --- /dev/null +++ b/ecom-dmb-frontend/.browserslistrc @@ -0,0 +1,4 @@ +> 1% +last 2 versions +not dead +not ie 11 diff --git a/ecom-dmb-frontend/.changeset/README.md b/ecom-dmb-frontend/.changeset/README.md new file mode 100644 index 00000000..5654e898 --- /dev/null +++ b/ecom-dmb-frontend/.changeset/README.md @@ -0,0 +1,5 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package repos, or single-package repos to help you version and publish your code. You can find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/ecom-dmb-frontend/.changeset/config.json b/ecom-dmb-frontend/.changeset/config.json new file mode 100644 index 00000000..f954fb4b --- /dev/null +++ b/ecom-dmb-frontend/.changeset/config.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", + "changelog": [ + "@changesets/changelog-github", + { "repo": "vbenjs/vue-vben-admin" } + ], + "commit": false, + "fixed": [["@vben-core/*", "@vben/*"]], + "snapshot": { + "prereleaseTemplate": "{tag}-{datetime}" + }, + "privatePackages": { "version": true, "tag": true }, + "linked": [], + "access": "public", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/ecom-dmb-frontend/.commitlintrc.js b/ecom-dmb-frontend/.commitlintrc.js new file mode 100644 index 00000000..02e33fa6 --- /dev/null +++ b/ecom-dmb-frontend/.commitlintrc.js @@ -0,0 +1 @@ +export { default } from '@vben/commitlint-config'; diff --git a/ecom-dmb-frontend/.dockerignore b/ecom-dmb-frontend/.dockerignore new file mode 100644 index 00000000..52b833a9 --- /dev/null +++ b/ecom-dmb-frontend/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.git +.gitignore +*.md +dist +.turbo +dist.zip diff --git a/ecom-dmb-frontend/.editorconfig b/ecom-dmb-frontend/.editorconfig new file mode 100644 index 00000000..179aec6f --- /dev/null +++ b/ecom-dmb-frontend/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset=utf-8 +end_of_line=lf +insert_final_newline=true +indent_style=space +indent_size=2 +max_line_length = 100 +trim_trailing_whitespace = true +quote_type = single + +[*.{yml,yaml,json}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/ecom-dmb-frontend/.gitattributes b/ecom-dmb-frontend/.gitattributes new file mode 100644 index 00000000..d4e5bd3e --- /dev/null +++ b/ecom-dmb-frontend/.gitattributes @@ -0,0 +1,11 @@ +# https://docs.github.com/cn/get-started/getting-started-with-git/configuring-git-to-handle-line-endings + +# Automatically normalize line endings (to LF) for all text-based files. +* text=auto eol=lf + +# Declare files that will always have CRLF line endings on checkout. +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf + +# Denote all files that are truly binary and should not be modified. +*.{ico,png,jpg,jpeg,gif,webp,svg,woff,woff2} binary \ No newline at end of file diff --git a/ecom-dmb-frontend/.gitconfig b/ecom-dmb-frontend/.gitconfig new file mode 100644 index 00000000..4b28a69c --- /dev/null +++ b/ecom-dmb-frontend/.gitconfig @@ -0,0 +1,2 @@ +[core] + ignorecase = false diff --git a/ecom-dmb-frontend/.github/CODEOWNERS b/ecom-dmb-frontend/.github/CODEOWNERS new file mode 100644 index 00000000..b95ff946 --- /dev/null +++ b/ecom-dmb-frontend/.github/CODEOWNERS @@ -0,0 +1,14 @@ +# default onwer +* anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com + +# vben core onwer +/.github/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/.vscode/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/packages/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/packages/@core/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/internal/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com +/scripts/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com jinmao88@qq.com + +# vben team onwer +apps/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com @vbenjs/team-v5 jinmao88@qq.com +docs/ anncwb@126.com vince292007@gmail.com netfan@foxmail.com @vbenjs/team-v5 jinmao88@qq.com diff --git a/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/bug-report.yml b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 00000000..ae927803 --- /dev/null +++ b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,74 @@ +name: 🐞 Bug Report +description: Report an issue with Vben Admin to help us make it better. +title: 'Bug: ' +labels: ['bug: pending triage'] + +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: dropdown + id: version + attributes: + label: Version + description: What version of our software are you running? + options: + - Vben Admin V5 + - Vben Admin V2 + default: 0 + validations: + required: true + + - type: textarea + id: bug-desc + attributes: + label: Describe the bug? + description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks! + placeholder: Bug Description + validations: + required: true + + - type: textarea + id: reproduction + attributes: + label: Reproduction + description: Please provide a link to [StackBlitz](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/basic?initialPath=__vitest__/) (you can also use [examples](https://github.com/vitest-dev/vitest/tree/main/examples)) or a github repo that can reproduce the problem you ran into. A [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) is required unless you are absolutely sure that the issue is obvious and the provided information is enough to understand the problem. If a report is vague (e.g. just a generic error message) and has no reproduction, it will receive a "needs reproduction" label. If no reproduction is provided after 3 days, it will be auto-closed. + placeholder: Reproduction + validations: + required: true + + - type: textarea + id: system-info + attributes: + label: System Info + description: Output of `npx envinfo --system --npmPackages '{vue}' --binaries --browsers` + render: shell + placeholder: System, Binaries, Browsers + validations: + required: true + + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + + - type: checkboxes + id: terms + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + # description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com). + options: + - label: Read the [docs](https://doc.vben.pro/) + required: true + - label: Ensure the code is up to date. (Some issues have been fixed in the latest version) + required: true + - label: I have searched the [existing issues](https://github.com/vbenjs/vue-vben-admin/issues) and checked that my issue does not duplicate any existing issues. + required: true + - label: Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vbenjs/vue-vben-admin/discussions) or join our [Discord Chat Server](https://discord.gg/8GuAdwDhj6). + required: true + - label: The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug. + required: true diff --git a/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/docs.yml b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/docs.yml new file mode 100644 index 00000000..d2bf16ef --- /dev/null +++ b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/docs.yml @@ -0,0 +1,38 @@ +name: 📚 Documentation +description: Report an issue with Vben Admin Website to help us make it better. +title: 'Docs: ' +labels: [documentation] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this issue! + - type: checkboxes + id: documentation_is + attributes: + label: Documentation is + options: + - label: Missing + - label: Outdated + - label: Confusing + - label: Not sure? + - type: textarea + id: description + attributes: + label: Explain in Detail + description: A clear and concise description of your suggestion. If you intend to submit a PR for this issue, tell us in the description. Thanks! + placeholder: The description of ... page is not clear. I thought it meant ... but it wasn't. + validations: + required: true + - type: textarea + id: suggestion + attributes: + label: Your Suggestion for Changes + validations: + required: true + - type: textarea + id: reproduction-steps + attributes: + label: Steps to reproduce + description: Please provide any reproduction steps that may need to be described. E.g. if it happens only when running the dev or build script make sure it's clear which one to use. + placeholder: Run `pnpm install` followed by `pnpm run docs:dev` diff --git a/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/feature-request.yml b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 00000000..393334e8 --- /dev/null +++ b/ecom-dmb-frontend/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,70 @@ +name: ✨ New Feature Proposal +description: Propose a new feature to be added to Vben Admin +title: 'FEATURE: ' +labels: ['enhancement: pending triage'] +body: + - type: markdown + attributes: + value: | + Thank you for suggesting a feature for our project! Please fill out the information below to help us understand and implement your request! + - type: dropdown + id: version + attributes: + label: Version + description: What version of our software are you running? + options: + - Vben Admin V5 + - Vben Admin V2 + default: 0 + validations: + required: true + + - type: textarea + id: description + attributes: + label: Description + description: A detailed description of the feature request. + placeholder: Please describe the feature you would like to see, and why it would be useful. + validations: + required: true + + - type: textarea + id: proposed-solution + attributes: + label: Proposed Solution + description: A clear and concise description of what you want to happen. + placeholder: Describe the solution you'd like to see + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Alternatives Considered + description: | + A clear and concise description of any alternative solutions or features you've considered. + placeholder: Describe any alternative solutions or features you've considered + validations: + required: false + + - type: input + id: additional-context + attributes: + label: Additional Context + description: Add any other context or screenshots about the feature request here. + placeholder: Any additional information + validations: + required: false + + - type: checkboxes + id: checkboxes + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + options: + - label: Read the [docs](https://doc.vben.pro/) + required: true + - label: Ensure the code is up to date. (Some issues have been fixed in the latest version) + required: true + - label: I have searched the [existing issues](https://github.com/vbenjs/vue-vben-admin/issues) and checked that my issue does not duplicate any existing issues. + required: true diff --git a/ecom-dmb-frontend/.github/actions/setup-node/action.yml b/ecom-dmb-frontend/.github/actions/setup-node/action.yml new file mode 100644 index 00000000..35fa41c8 --- /dev/null +++ b/ecom-dmb-frontend/.github/actions/setup-node/action.yml @@ -0,0 +1,40 @@ +name: 'Setup Node' + +description: 'Setup node and pnpm' + +runs: + using: 'composite' + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .node-version + cache: 'pnpm' + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Setup pnpm cache + if: ${{ github.ref_name == 'main' }} + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - uses: actions/cache/restore@v4 + if: ${{ github.ref_name != 'main' }} + with: + path: ${{ env.STORE_PATH }} + key: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile diff --git a/ecom-dmb-frontend/.github/commit-convention.md b/ecom-dmb-frontend/.github/commit-convention.md new file mode 100644 index 00000000..a1a969e9 --- /dev/null +++ b/ecom-dmb-frontend/.github/commit-convention.md @@ -0,0 +1,89 @@ +## Git Commit Message Convention + +> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular). + +#### TL;DR: + +Messages must be matched by the following regex: + +```js +/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip): .{1,50}/; +``` + +#### Examples + +Appears under "Features" header, `dev` subheader: + +``` +feat(dev): add 'comments' option +``` + +Appears under "Bug Fixes" header, `dev` subheader, with a link to issue #28: + +``` +fix(dev): fix dev error + +close #28 +``` + +Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation: + +``` +perf(build): remove 'foo' option + +BREAKING CHANGE: The 'foo' option has been removed. +``` + +The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header. + +``` +revert: feat(compiler): add 'comments' option + +This reverts commit 667ecc1654a317a13331b17617d973392f415f02. +``` + +### Full Message Format + +A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**: + +``` +(): + + + +