mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
初始化项目
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
@@ -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/
|
||||
@@ -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
|
||||
@@ -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 <repository-url>
|
||||
cd ah-gf-backend
|
||||
```
|
||||
|
||||
2. **配置数据库**
|
||||
- 创建数据库
|
||||
- 执行SQL脚本创建表
|
||||
- 修改 `application.yml` 中的数据库配置
|
||||
|
||||
3. **启动项目**
|
||||
```bash
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
4. **访问API文档**
|
||||
- 浏览器访问: `http://localhost:8080/doc.html`
|
||||
|
||||
## 开发规范
|
||||
|
||||
1. **代码规范**
|
||||
- 遵循阿里巴巴Java开发手册
|
||||
- 使用Lombok简化代码
|
||||
- 统一异常处理
|
||||
|
||||
2. **架构设计**
|
||||
- 模块化设计
|
||||
- 分层架构(Controller -> Service -> Mapper)
|
||||
- 单一职责原则
|
||||
|
||||
3. **安全规范**
|
||||
- 密码加密存储
|
||||
- JWT令牌认证
|
||||
- 参数验证
|
||||
|
||||
## 测试
|
||||
|
||||
运行测试用例:
|
||||
```bash
|
||||
mvn test
|
||||
```
|
||||
|
||||
## 部署
|
||||
|
||||
1. **打包**
|
||||
```bash
|
||||
mvn clean package
|
||||
```
|
||||
|
||||
2. **运行**
|
||||
```bash
|
||||
java -jar target/ah-gf-backend-0.0.1-SNAPSHOT.jar
|
||||
```
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT License
|
||||
@@ -0,0 +1,188 @@
|
||||
# CurrentUserContext 使用说明
|
||||
|
||||
## 概述
|
||||
|
||||
`CurrentUserContext` 是一个更安全的当前用户信息获取工具类,用于替代原有的 `SecurityUtils` 静态方法。它提供了更好的线程安全性和错误处理机制。
|
||||
|
||||
## 主要优势
|
||||
|
||||
### 1. 线程安全性
|
||||
- 使用依赖注入管理 `JwtUtils` 实例,避免每次创建新实例
|
||||
- 基于 Spring Security 的 `SecurityContextHolder`,天然线程安全
|
||||
- 每个HTTP请求在独立线程中处理,用户信息完全隔离
|
||||
|
||||
### 2. 更好的错误处理
|
||||
- 提供明确的异常信息
|
||||
- 统一的错误处理机制
|
||||
- 更好的调试体验
|
||||
|
||||
### 3. 依赖注入
|
||||
- 符合Spring最佳实践
|
||||
- 便于单元测试
|
||||
- 更好的可维护性
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 在服务类中注入
|
||||
|
||||
```java
|
||||
@Service
|
||||
public class YourServiceImpl extends ServiceImpl<YourMapper, YourPO> 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<DepartmentVO> getDepartmentPage(PageQueryDTO pageQueryDTO, DepartmentFilterDTO queryDTO) {
|
||||
// 强制添加公司ID过滤条件
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
LambdaQueryWrapper<DepartmentPO> 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` 提供了更安全、更易用的用户信息获取方式,是企业级应用中处理多租户数据隔离的最佳实践。
|
||||
@@ -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
|
||||
<!-- Spring AOP -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 2. 注解使用示例
|
||||
|
||||
#### 角色权限控制
|
||||
```java
|
||||
@RequireRole(description = "创建公司", allowUser = false)
|
||||
@PostMapping("/create")
|
||||
public ApiResponse<CompanyVO> createCompany(@Valid @RequestBody CreateCompanyDTO dto) {
|
||||
// 业务逻辑
|
||||
}
|
||||
```
|
||||
|
||||
#### 细粒度权限控制
|
||||
```java
|
||||
@RequirePermission(value = "company:delete", description = "删除公司")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> 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<Result> method() {
|
||||
// 业务逻辑
|
||||
}
|
||||
```
|
||||
|
||||
#### 细粒度权限控制
|
||||
```java
|
||||
@RequirePermission(value = "module:action", description = "操作描述")
|
||||
@PostMapping("/api/endpoint")
|
||||
public ApiResponse<Result> method() {
|
||||
// 业务逻辑
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 在代码中进行权限检查
|
||||
|
||||
```java
|
||||
// 检查是否有指定权限
|
||||
if (PermissionUtils.hasPermission("user:create")) {
|
||||
// 执行创建用户逻辑
|
||||
}
|
||||
|
||||
// 检查是否有指定角色
|
||||
if (PermissionUtils.isSuper()) {
|
||||
// 超级管理员逻辑
|
||||
}
|
||||
|
||||
// 获取当前用户角色
|
||||
String role = PermissionUtils.getCurrentRole();
|
||||
```
|
||||
|
||||
## 扩展建议
|
||||
|
||||
### 1. 权限缓存
|
||||
为了提高性能,建议对权限信息进行缓存:
|
||||
```java
|
||||
@Cacheable(value = "permissions", key = "#positionId")
|
||||
public List<String> 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. **权限同步**:支持权限的实时同步
|
||||
@@ -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<CompanyVO> createCompany(@Valid @RequestBody CreateCompanyDTO createCompanyDTO) {
|
||||
// 业务逻辑
|
||||
}
|
||||
```
|
||||
|
||||
**注解参数说明:**
|
||||
- `value`:允许的角色列表(可选)
|
||||
- `description`:权限描述
|
||||
- `allowSuper`:是否允许超级管理员访问(默认true)
|
||||
- `allowCompany`:是否允许公司管理员访问(默认true)
|
||||
- `allowUser`:是否允许普通用户访问(默认false)
|
||||
|
||||
#### @RequirePermission 注解
|
||||
|
||||
用于细粒度的权限控制,基于权限码进行验证:
|
||||
|
||||
```java
|
||||
@RequirePermission(value = "company:create", description = "创建公司")
|
||||
@PostMapping("/create")
|
||||
public ApiResponse<CompanyVO> 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<CompanyVO> createCompany(@Valid @RequestBody CreateCompanyDTO dto) {
|
||||
// 业务逻辑
|
||||
}
|
||||
|
||||
// 允许所有角色访问
|
||||
@RequireRole(description = "查询公司列表", allowUser = true)
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<CompanyVO>> getCompanyPage(@Valid @RequestBody PageQueryDTO<CompanyFilterDTO> pageQuery) {
|
||||
// 业务逻辑
|
||||
}
|
||||
|
||||
// 使用细粒度权限控制
|
||||
@RequirePermission(value = "company:delete", description = "删除公司")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> 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. **安全测试**:测试权限绕过的可能性
|
||||
Vendored
+259
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -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 "$@"
|
||||
Vendored
+149
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
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"
|
||||
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>top.xyquan</groupId>
|
||||
<artifactId>ecom-dmb-backend</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>ah-gf-backend</name>
|
||||
<description>ah-gf-backend</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<mybatis-plus.version>3.5.5</mybatis-plus.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!--Spring Boot Web启动器-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis Plus 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
<!--MySQL数据库连接器-->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!--Lombok库-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- knife4j-openapi3 -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
<!-- Spring Security -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<!--JJWT库的API模块-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.11.5</version>
|
||||
</dependency>
|
||||
<!--JJWT库的实现模块-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!--JJWT库的Jackson模块-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!--Spring Boot测试启动器-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Jakarta Validation -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<!-- Spring AOP -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!-- AspectJ -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
<mirrors>
|
||||
<!-- 阿里云镜像 -->
|
||||
<mirror>
|
||||
<id>aliyunmaven</id>
|
||||
<mirrorOf>central</mirrorOf>
|
||||
<name>阿里云公共仓库</name>
|
||||
<url>https://maven.aliyun.com/repository/central</url>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+40
@@ -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;
|
||||
}
|
||||
+40
@@ -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;
|
||||
}
|
||||
+78
@@ -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();
|
||||
}
|
||||
}
|
||||
+76
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
+31
@@ -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")));
|
||||
}
|
||||
}
|
||||
+47
@@ -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());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+51
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
+23
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
+102
@@ -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<String> handleBusinessException(BusinessException e) {
|
||||
return ApiResponse.fail(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理运行时异常
|
||||
*/
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public ApiResponse<String> handleRuntimeException(RuntimeException e) {
|
||||
return ApiResponse.fail(e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理参数验证异常
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public ApiResponse<String> 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<String> 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<String> handleAuthenticationException(AuthenticationException e) {
|
||||
return ApiResponse.fail("认证失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理权限异常
|
||||
*/
|
||||
@ExceptionHandler(AccessDeniedException.class)
|
||||
@ResponseStatus(HttpStatus.FORBIDDEN)
|
||||
public ApiResponse<String> handleAccessDeniedException(AccessDeniedException e) {
|
||||
return ApiResponse.fail("权限不足: " + e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理404异常
|
||||
*/
|
||||
@ExceptionHandler(NoHandlerFoundException.class)
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public ApiResponse<String> handleNoHandlerFoundException(NoHandlerFoundException e) {
|
||||
return ApiResponse.fail("请求的资源不存在: " + e.getRequestURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理其他异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
public ApiResponse<String> handleException(Exception e) {
|
||||
// 记录详细错误信息到日志
|
||||
e.printStackTrace();
|
||||
return ApiResponse.fail("系统内部错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
+76
@@ -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;
|
||||
}
|
||||
}
|
||||
+26
@@ -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<T> {
|
||||
|
||||
//页码,从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;
|
||||
}
|
||||
+37
@@ -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<T> implements Serializable {
|
||||
private List<T> list; // 当前页数据
|
||||
private Long total; // 总条数
|
||||
private Integer page; // 当前页码
|
||||
private Integer pageSize; // 每页条数
|
||||
private Integer totalPages; // 总页数
|
||||
private Boolean hasNextPage; // 是否有下一页
|
||||
private Boolean hasPrevPage; // 是否有上一页
|
||||
|
||||
// 构造函数
|
||||
public PageResultVO(List<T> 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 <T> PageResultVO<T> create(List<T> list, Long total, Integer page, Integer pageSize) {
|
||||
return new PageResultVO<>(list, total, page, pageSize);
|
||||
}
|
||||
}
|
||||
+34
@@ -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<T> {
|
||||
private int code;
|
||||
private String message;
|
||||
private T data;
|
||||
|
||||
public static <T> ApiResponse<T> success(T data) {
|
||||
return new ApiResponse<>(0, "操作成功", data);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> success(String message, T data) {
|
||||
return new ApiResponse<>(0, message, data);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> success() {
|
||||
return new ApiResponse<>(0, "操作成功", null);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> fail(String message) {
|
||||
return new ApiResponse<>(1, message, null);
|
||||
}
|
||||
|
||||
public static <T> ApiResponse<T> fail(int code, String message) {
|
||||
return new ApiResponse<>(code, message, null);
|
||||
}
|
||||
}
|
||||
+102
@@ -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<MediaFileVO> 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<List<MediaFileVO>> batchUploadFiles(
|
||||
@RequestParam("files") List<MultipartFile> 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<MediaFileDTO> 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<MediaFileVO> mediaFileVOList = mediaFileService.batchUploadFiles(mediaFileDTOList);
|
||||
return ApiResponse.success(mediaFileVOList);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新文件信息", description = "更新文件的元数据信息")
|
||||
@PutMapping("/update")
|
||||
public ApiResponse<MediaFileVO> updateFile(@Valid @RequestBody MediaFileDTO mediaFileDTO) {
|
||||
MediaFileVO mediaFileVO = mediaFileService.updateFile(mediaFileDTO);
|
||||
return ApiResponse.success(mediaFileVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除文件", description = "删除指定文件")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> deleteFile(
|
||||
@Parameter(description = "文件ID") @PathVariable Long id) {
|
||||
mediaFileService.deleteFile(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
+112
@@ -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<MediaImageVO> 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<List<MediaImageVO>> batchUploadImages(
|
||||
@RequestParam("files") List<MultipartFile> 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<MediaImageDTO> 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<MediaImageVO> mediaImageVOList = mediaImageService.batchUploadImages(mediaImageDTOList);
|
||||
return ApiResponse.success(mediaImageVOList);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新图片信息", description = "更新图片的元数据信息")
|
||||
@PutMapping("/update")
|
||||
public ApiResponse<MediaImageVO> updateImage(@Valid @RequestBody MediaImageDTO mediaImageDTO) {
|
||||
MediaImageVO mediaImageVO = mediaImageService.updateImage(mediaImageDTO);
|
||||
return ApiResponse.success(mediaImageVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除图片", description = "删除指定图片")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ApiResponse<Void> deleteImage(
|
||||
@Parameter(description = "图片ID") @PathVariable Long id) {
|
||||
mediaImageService.deleteImage(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
+12
@@ -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<MediaFilePO> {
|
||||
}
|
||||
+12
@@ -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<MediaImagePO> {
|
||||
}
|
||||
+43
@@ -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;
|
||||
}
|
||||
+42
@@ -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;
|
||||
}
|
||||
+70
@@ -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;
|
||||
}
|
||||
+70
@@ -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;
|
||||
}
|
||||
+57
@@ -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;
|
||||
}
|
||||
+57
@@ -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;
|
||||
}
|
||||
+32
@@ -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<MediaFileVO> batchUploadFiles(List<MediaFileDTO> mediaFileDTOList);
|
||||
|
||||
/**
|
||||
* 更新文件信息
|
||||
*/
|
||||
MediaFileVO updateFile(MediaFileDTO mediaFileDTO);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
void deleteFile(Long id);
|
||||
}
|
||||
+32
@@ -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<MediaImageVO> batchUploadImages(List<MediaImageDTO> mediaImageDTOList);
|
||||
|
||||
/**
|
||||
* 更新图片信息
|
||||
*/
|
||||
MediaImageVO updateImage(MediaImageDTO mediaImageDTO);
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
*/
|
||||
void deleteImage(Long id);
|
||||
}
|
||||
+151
@@ -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<MediaFileMapper, MediaFilePO>
|
||||
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<MediaFileVO> batchUploadFiles(List<MediaFileDTO> mediaFileDTOList) {
|
||||
if (mediaFileDTOList == null || mediaFileDTOList.isEmpty()) {
|
||||
throw new BusinessException("文件列表不能为空");
|
||||
}
|
||||
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 批量创建文件记录
|
||||
List<MediaFilePO> 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;
|
||||
}
|
||||
}
|
||||
+166
@@ -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<MediaImageMapper, MediaImagePO>
|
||||
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<MediaImageVO> batchUploadImages(List<MediaImageDTO> mediaImageDTOList) {
|
||||
if (mediaImageDTOList == null || mediaImageDTOList.isEmpty()) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
}
|
||||
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 批量创建图片记录
|
||||
List<MediaImagePO> 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;
|
||||
}
|
||||
}
|
||||
+66
@@ -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<CompanyVO> 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<CompanyVO> 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<Void> deleteCompany(
|
||||
@Parameter(description = "公司ID") @PathVariable Long id) {
|
||||
companyService.deleteCompany(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询公司列表", description = "分页查询公司列表,支持多种过滤条件")
|
||||
@PostMapping("/page")
|
||||
@RequireRole(description = "查询公司列表", allowUser = true)
|
||||
public ApiResponse<PageResultVO<CompanyVO>> getCompanyPage(
|
||||
@Valid @RequestBody PageQueryDTO<CompanyFilterDTO> pageQuery) {
|
||||
PageResultVO<CompanyVO> pageResult = companyService.getCompanyPage(pageQuery);
|
||||
return ApiResponse.success(pageResult);
|
||||
}
|
||||
}
|
||||
+76
@@ -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<CompanyMenuVO> 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<CompanyMenuVO> 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<Void> 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<List<CompanyMenuVO>> batchCreateCompanyMenu(
|
||||
@Parameter(description = "公司ID") @PathVariable Long id,
|
||||
@Parameter(description = "菜单ID列表") @RequestBody List<Long> menuIds) {
|
||||
List<CompanyMenuVO> result = companyMenuService.batchCreateCompanyMenu(id, menuIds);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除公司菜单", description = "批量删除公司菜单权限关联")
|
||||
@DeleteMapping("/batch-delete/{id}")
|
||||
@RequireRole(description = "批量删除公司菜单", allowUser = false)
|
||||
public ApiResponse<Void> batchDeleteCompanyMenu(
|
||||
@Parameter(description = "公司ID") @PathVariable Long id,
|
||||
@Parameter(description = "菜单ID列表") @RequestBody List<Long> menuIds) {
|
||||
companyMenuService.batchDeleteCompanyMenu(id, menuIds);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
+66
@@ -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<DepartmentVO> 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<DepartmentVO> 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<Void> deleteDepartment(
|
||||
@Parameter(description = "部门ID") @PathVariable Long id) {
|
||||
departmentService.deleteDepartment(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取部门列表", description = "分页获取部门列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
@RequireRole(description = "查询部门列表", allowUser = true)
|
||||
public ApiResponse<PageResultVO<DepartmentVO>> getDepartmentPage(
|
||||
@Valid @RequestBody PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<DepartmentVO> result = departmentService.getDepartmentPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+66
@@ -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<PositionVO> 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<PositionVO> 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<Void> deletePosition(
|
||||
@Parameter(description = "岗位ID") @PathVariable Long id) {
|
||||
positionService.deletePosition(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取岗位列表", description = "分页获取岗位列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
@RequireRole(description = "查询岗位列表", allowUser = true)
|
||||
public ApiResponse<PageResultVO<PositionVO>> getPositionPage(
|
||||
@Valid @RequestBody PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PositionVO> result = positionService.getPositionPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+12
@@ -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<CompanyPO> {
|
||||
}
|
||||
+12
@@ -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<CompanyMenuPO> {
|
||||
}
|
||||
+12
@@ -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<DepartmentPO> {
|
||||
}
|
||||
+32
@@ -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<PositionCompanyMenuPO> {
|
||||
|
||||
/**
|
||||
* 根据岗位ID查询菜单权限列表
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @return 菜单权限列表
|
||||
*/
|
||||
List<PositionMenuVO> selectMenusByPositionId(@Param("positionId") Long positionId);
|
||||
|
||||
/**
|
||||
* 根据岗位ID列表查询菜单权限列表
|
||||
*
|
||||
* @param positionIds 岗位ID列表
|
||||
* @return 菜单权限列表
|
||||
*/
|
||||
List<PositionMenuVO> selectMenusByPositionIds(@Param("positionIds") List<Long> positionIds);
|
||||
}
|
||||
+12
@@ -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<PositionPO> {
|
||||
}
|
||||
+70
@@ -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;
|
||||
}
|
||||
+48
@@ -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;
|
||||
}
|
||||
+64
@@ -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;
|
||||
}
|
||||
+64
@@ -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;
|
||||
}
|
||||
+30
@@ -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<Long> menuIds;
|
||||
}
|
||||
+69
@@ -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;
|
||||
}
|
||||
+63
@@ -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;
|
||||
}
|
||||
+63
@@ -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;
|
||||
}
|
||||
+38
@@ -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;
|
||||
}
|
||||
+52
@@ -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;
|
||||
}
|
||||
+30
@@ -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;
|
||||
}
|
||||
+38
@@ -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;
|
||||
}
|
||||
+30
@@ -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<Long> companyMenuIds;
|
||||
}
|
||||
+44
@@ -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;
|
||||
}
|
||||
+58
@@ -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;
|
||||
}
|
||||
+24
@@ -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;
|
||||
}
|
||||
+44
@@ -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;
|
||||
}
|
||||
+94
@@ -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;
|
||||
}
|
||||
+100
@@ -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;
|
||||
}
|
||||
+76
@@ -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;
|
||||
}
|
||||
+46
@@ -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;
|
||||
}
|
||||
+70
@@ -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;
|
||||
}
|
||||
+69
@@ -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<MenuVO> menus;
|
||||
}
|
||||
+92
@@ -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;
|
||||
}
|
||||
+80
@@ -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<DepartmentVO> children;
|
||||
}
|
||||
+47
@@ -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;
|
||||
}
|
||||
+68
@@ -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;
|
||||
}
|
||||
+55
@@ -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<CompanyMenuPO> {
|
||||
|
||||
/**
|
||||
* 创建公司菜单
|
||||
*
|
||||
* @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<CompanyMenuVO> batchCreateCompanyMenu(Long companyId, List<Long> menuIds);
|
||||
|
||||
/**
|
||||
* 批量删除公司菜单
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param menuIds 菜单ID列表
|
||||
*/
|
||||
void batchDeleteCompanyMenu(Long companyId, List<Long> menuIds);
|
||||
}
|
||||
+47
@@ -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<CompanyPO> {
|
||||
|
||||
/**
|
||||
* 创建公司
|
||||
*
|
||||
* @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<CompanyVO> getCompanyPage(PageQueryDTO<CompanyFilterDTO> pageQuery);
|
||||
}
|
||||
+48
@@ -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<DepartmentPO> {
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*
|
||||
* @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<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO);
|
||||
}
|
||||
+52
@@ -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<PositionMenuVO> getMenusByPositionId(Long positionId);
|
||||
|
||||
/**
|
||||
* 根据岗位ID列表查询菜单权限列表
|
||||
*
|
||||
* @param positionIds 岗位ID列表
|
||||
* @return 菜单权限列表
|
||||
*/
|
||||
List<PositionMenuVO> getMenusByPositionIds(List<Long> positionIds);
|
||||
|
||||
/**
|
||||
* 检查岗位是否有指定菜单权限
|
||||
*
|
||||
* @param positionId 岗位ID
|
||||
* @param companyMenuId 公司菜单权限ID
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPositionMenu(Long positionId, Long companyMenuId);
|
||||
}
|
||||
+48
@@ -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<PositionPO> {
|
||||
|
||||
/**
|
||||
* 创建岗位
|
||||
*
|
||||
* @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<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO);
|
||||
}
|
||||
+183
@@ -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<CompanyMenuMapper, CompanyMenuPO>
|
||||
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<CompanyMenuPO> 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<CompanyMenuPO> 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<CompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CompanyMenuPO::getParentId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("存在子菜单,无法删除");
|
||||
}
|
||||
|
||||
// 删除公司菜单
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<CompanyMenuVO> batchCreateCompanyMenu(Long companyId, List<Long> menuIds) {
|
||||
List<CompanyMenuVO> 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<Long> menuIds) {
|
||||
LambdaQueryWrapper<CompanyMenuPO> 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;
|
||||
}
|
||||
}
|
||||
+164
@@ -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<CompanyMapper, CompanyPO> implements CompanyService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public CompanyServiceImpl(CurrentUserContext currentUserContext) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyVO createCompany(CreateCompanyDTO createCompanyDTO) {
|
||||
// 检查公司名称是否重复
|
||||
LambdaQueryWrapper<CompanyPO> 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<CompanyPO> 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<CompanyVO> getCompanyPage(PageQueryDTO<CompanyFilterDTO> pageQuery) {
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<CompanyPO> 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<CompanyPO> page = new Page<>(pageQuery.getPage(), pageQuery.getPageSize());
|
||||
IPage<CompanyPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<CompanyVO> 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;
|
||||
}
|
||||
}
|
||||
+191
@@ -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<DepartmentMapper, DepartmentPO> 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<DepartmentPO> 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<DepartmentPO> 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<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DepartmentPO::getParentId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("存在子部门,无法删除");
|
||||
}
|
||||
|
||||
// 删除部门
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<DepartmentPO> 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<DepartmentPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<DepartmentPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<DepartmentVO> records = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.toList();
|
||||
PageResultVO<DepartmentVO> 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;
|
||||
}
|
||||
}
|
||||
+91
@@ -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<Long> companyMenuIds = batchAssignDTO.getCompanyMenuIds();
|
||||
|
||||
// 先删除该岗位的所有菜单权限
|
||||
LambdaQueryWrapper<PositionCompanyMenuPO> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(PositionCompanyMenuPO::getPositionId, positionId);
|
||||
positionCompanyMenuMapper.delete(deleteWrapper);
|
||||
|
||||
// 批量插入新的菜单权限
|
||||
List<PositionCompanyMenuPO> 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<PositionCompanyMenuPO> 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<PositionMenuVO> getMenusByPositionId(Long positionId) {
|
||||
return positionCompanyMenuMapper.selectMenusByPositionId(positionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PositionMenuVO> getMenusByPositionIds(List<Long> positionIds) {
|
||||
if (positionIds == null || positionIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return positionCompanyMenuMapper.selectMenusByPositionIds(positionIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPositionMenu(Long positionId, Long companyMenuId) {
|
||||
LambdaQueryWrapper<PositionCompanyMenuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PositionCompanyMenuPO::getPositionId, positionId)
|
||||
.eq(PositionCompanyMenuPO::getCompanyMenuId, companyMenuId);
|
||||
|
||||
return positionCompanyMenuMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
}
|
||||
+181
@@ -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<PositionMapper, PositionPO> 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<PositionPO> 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<PositionPO> 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<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<PositionPO> 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<PositionPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<PositionPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<PositionVO> records = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.toList();
|
||||
PageResultVO<PositionVO> 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;
|
||||
}
|
||||
}
|
||||
+62
@@ -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<PlanVO> createPlan(@Valid @RequestBody CreatePlanDTO createPlanDTO) {
|
||||
PlanVO planVO = planService.createPlan(createPlanDTO);
|
||||
return ApiResponse.success(planVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新套餐", description = "更新现有套餐信息")
|
||||
@PutMapping("/update/{planId}")
|
||||
public ApiResponse<PlanVO> 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<Void> deletePlan(
|
||||
@Parameter(description = "套餐ID") @PathVariable Long planId) {
|
||||
planService.deletePlan(planId);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取套餐列表", description = "分页获取套餐列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<PlanListVO>> getPlanPage(
|
||||
@Valid @RequestBody PageQueryDTO<PlanFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PlanListVO> result = planService.getPlanPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+62
@@ -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<PlanPricingVO> createPlanPricing(@Valid @RequestBody CreatePlanPricingDTO createPlanPricingDTO) {
|
||||
PlanPricingVO planPricingVO = planPricingService.createPlanPricing(createPlanPricingDTO);
|
||||
return ApiResponse.success(planPricingVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新定价", description = "更新现有定价信息")
|
||||
@PutMapping("/update/{id}")
|
||||
public ApiResponse<PlanPricingVO> 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<Void> deletePlanPricing(
|
||||
@Parameter(description = "定价ID") @PathVariable Long id) {
|
||||
planPricingService.deletePlanPricing(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取定价列表", description = "分页获取定价列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<PlanPricingListVO>> getPlanPricingPage(
|
||||
@Valid @RequestBody PageQueryDTO<PlanPricingFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PlanPricingListVO> result = planPricingService.getPlanPricingPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+64
@@ -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<SubscriptionVO> createSubscription(
|
||||
@Valid @RequestBody CreateSubscriptionDTO createSubscriptionDTO) {
|
||||
SubscriptionVO subscriptionVO = subscriptionService.createSubscription(createSubscriptionDTO);
|
||||
return ApiResponse.success(subscriptionVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订阅", description = "更新现有订阅信息")
|
||||
@PutMapping("/update/{id}")
|
||||
public ApiResponse<SubscriptionVO> 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<Void> deleteSubscription(
|
||||
@Parameter(description = "订阅ID") @PathVariable Long id) {
|
||||
subscriptionService.deleteSubscription(id);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取订阅列表", description = "分页获取订阅列表,支持条件过滤")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<SubscriptionListVO>> getSubscriptionPage(
|
||||
@Valid @RequestBody PageQueryDTO<SubscriptionFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<SubscriptionListVO> result = subscriptionService.getSubscriptionPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
}
|
||||
+12
@@ -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<PlanPO> {
|
||||
}
|
||||
+12
@@ -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<PlanPricingPO> {
|
||||
}
|
||||
+12
@@ -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<SubscriptionPO> {
|
||||
}
|
||||
+44
@@ -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;
|
||||
}
|
||||
+25
@@ -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;
|
||||
}
|
||||
+44
@@ -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;
|
||||
}
|
||||
+40
@@ -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;
|
||||
}
|
||||
+37
@@ -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;
|
||||
}
|
||||
+46
@@ -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;
|
||||
}
|
||||
+68
@@ -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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user