初始化项目

This commit is contained in:
ah--desktop
2025-09-10 00:33:25 +08:00
commit a305dcdc3f
1406 changed files with 114976 additions and 0 deletions
@@ -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);
}
}
@@ -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;
}
@@ -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;
}
@@ -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();
}
}
@@ -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 {
}
@@ -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")));
}
}
@@ -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());
}
};
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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());
}
}
@@ -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;
}
}
@@ -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;
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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> {
}
@@ -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> {
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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> {
}
@@ -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> {
}
@@ -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> {
}
@@ -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);
}
@@ -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> {
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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> {
}
@@ -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> {
}
@@ -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> {
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -0,0 +1,53 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 订阅分页查询过滤DTO
*/
@Data
public class SubscriptionFilterDTO {
/**
* 公司ID
*/
private Long companyId;
/**
* 套餐ID
*/
private Long planId;
/**
* 生效状态
*/
private String status;
/**
* 支付状态
*/
private String paymentStatus;
/**
* 支付金额范围-最小值
*/
private BigDecimal minPaidAmount;
/**
* 支付金额范围-最大值
*/
private BigDecimal maxPaidAmount;
/**
* 订阅开始时间范围-开始
*/
private LocalDateTime startTimeBegin;
/**
* 订阅开始时间范围-结束
*/
private LocalDateTime startTimeEnd;
}
@@ -0,0 +1,74 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.dto.sucscription;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 更新订阅DTO
*/
@Data
public class UpdateSubscriptionDTO {
/**
* 记录ID
*/
@NotNull(message = "订阅ID不能为空")
private Long id;
/**
* 公司ID(关联org_company)
*/
@NotNull(message = "公司ID不能为空")
private Long companyId;
/**
* 套餐ID(关联sub_plan)
*/
@NotNull(message = "套餐ID不能为空")
private Long planId;
/**
* 订阅开始时间
*/
@NotNull(message = "订阅开始时间不能为空")
private LocalDateTime startTime;
/**
* 订阅结束时间
*/
@NotNull(message = "订阅结束时间不能为空")
private LocalDateTime endTime;
/**
* 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效)
*/
private String status;
/**
* 实际支付金额
*/
private BigDecimal paidAmount;
/**
* 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款)
*/
private String paymentStatus;
/**
* 支付时间
*/
private LocalDateTime paymentTime;
/**
* 第三方支付订单号
*/
private String orderNo;
/**
* 备注
*/
private String remark;
}
@@ -0,0 +1,82 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 订阅套餐实体
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sub_plan")
public class PlanPO {
/**
* 套餐ID
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
/**
* 套餐名称
*/
@TableField("name")
private String name;
/**
* 用户数量限制,NULL 表示不限
*/
@TableField("user_limit")
private Integer userLimit;
/**
* 是否为试用套餐 (1-是 0-否)
*/
@TableField("is_trial")
private Integer isTrial;
/**
* 试用天数,仅 is_trial = 1 时有效
*/
@TableField("trial_days")
private Integer trialDays;
/**
* 状态:(1-可购买 0-下架)
*/
@TableField("status")
private Integer status;
/**
* 套餐描述
*/
@TableField("remark")
private String remark;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人ID
*/
@TableField(value = "create_by", fill = FieldFill.INSERT)
private Long createBy;
/**
* 更新人ID
*/
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
private Long updateBy;
}
@@ -0,0 +1,71 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 订阅套餐定价实体
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sub_plan_pricing")
public class PlanPricingPO {
/**
* 定价ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 对应套餐ID
*/
@TableField("plan_id")
private Long planId;
/**
* 价格(元)
*/
@TableField("price")
private BigDecimal price;
/**
* 订阅时长(月)
*/
@TableField("duration_months")
private Integer durationMonths;
/**
* 是否启用当前价格(1-启用,0-禁用)
*/
@TableField("stauts")
private Integer status;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 创建人ID
*/
@TableField(value = "create_by", fill = FieldFill.INSERT)
private Long createBy;
/**
* 更新人ID
*/
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
private Long updateBy;
}
@@ -0,0 +1,120 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.po;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 订阅记录实体
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sub_subscription")
public class SubscriptionPO {
/**
* 记录ID
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
/**
* 公司ID(关联org_company)
*/
@TableField("company_id")
private Long companyId;
/**
* 套餐ID(关联sub_plan)
*/
@TableField("plan_id")
private Long planId;
/**
* 订阅开始时间
*/
@TableField("start_time")
private LocalDateTime startTime;
/**
* 订阅结束时间
*/
@TableField("end_time")
private LocalDateTime endTime;
/**
* 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效)
*/
@TableField("status")
private String status;
/**
* 实际支付金额
*/
@TableField("paid_amount")
private BigDecimal paidAmount;
/**
* 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款)
*/
@TableField("payment_status")
private String paymentStatus;
/**
* 支付时间
*/
@TableField("payment_time")
private LocalDateTime paymentTime;
/**
* 第三方支付订单号
*/
@TableField("order_no")
private String orderNo;
/**
* 备注
*/
@TableField("remark")
private String remark;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 删除时间
*/
@TableField("delete_time")
@TableLogic
private LocalDateTime deleteTime;
/**
* 创建人ID
*/
@TableField(value = "create_by", fill = FieldFill.INSERT)
private Long createBy;
/**
* 更新人ID
*/
@TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
private Long updateBy;
/**
* 删除人ID
*/
@TableField("delete_by")
private Long deleteBy;
}
@@ -0,0 +1,52 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 套餐列表VO
*/
@Data
public class PlanListVO {
/**
* 套餐ID
*/
private Long id;
/**
* 套餐名称
*/
private String name;
/**
* 用户数量限制,NULL 表示不限
*/
private Integer userLimit;
/**
* 是否为试用套餐 (1-是 0-否)
*/
private Integer isTrial;
/**
* 试用天数,仅 is_trial = 1 时有效
*/
private Integer trialDays;
/**
* 状态:(1-可购买 0-下架)
*/
private Integer status;
/**
* 套餐描述
*/
private String remark;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
@@ -0,0 +1,57 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 套餐VO
*/
@Data
public class PlanVO {
/**
* 套餐ID
*/
private Long id;
/**
* 套餐名称
*/
private String name;
/**
* 用户数量限制,NULL 表示不限
*/
private Integer userLimit;
/**
* 是否为试用套餐 (1-是 0-否)
*/
private Integer isTrial;
/**
* 试用天数,仅 is_trial = 1 时有效
*/
private Integer trialDays;
/**
* 状态:(1-可购买 0-下架)
*/
private Integer status;
/**
* 套餐描述
*/
private String remark;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}
@@ -0,0 +1,48 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 套餐定价列表VO
*/
@Data
public class PlanPricingListVO {
/**
* 定价ID
*/
private Long id;
/**
* 对应套餐ID
*/
private Long planId;
/**
* 套餐名称
*/
private String planName;
/**
* 价格(元)
*/
private BigDecimal price;
/**
* 订阅时长(月)
*/
private Integer durationMonths;
/**
* 是否启用当前价格(1-启用,0-禁用)
*/
private Integer status;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
@@ -0,0 +1,53 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.plan.pricing;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 套餐定价VO
*/
@Data
public class PlanPricingVO {
/**
* 定价ID
*/
private Long id;
/**
* 对应套餐ID
*/
private Long planId;
/**
* 套餐名称
*/
private String planName;
/**
* 价格(元)
*/
private BigDecimal price;
/**
* 订阅时长(月)
*/
private Integer durationMonths;
/**
* 是否启用当前价格(1-启用,0-禁用)
*/
private Integer status;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}
@@ -0,0 +1,78 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 订阅列表VO
*/
@Data
public class SubscriptionListVO {
/**
* 记录ID
*/
private Long id;
/**
* 公司ID(关联org_company)
*/
private Long companyId;
/**
* 公司名称
*/
private String companyName;
/**
* 套餐ID(关联sub_plan)
*/
private Long planId;
/**
* 套餐名称
*/
private String planName;
/**
* 订阅开始时间
*/
private LocalDateTime startTime;
/**
* 订阅结束时间
*/
private LocalDateTime endTime;
/**
* 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效)
*/
private String status;
/**
* 实际支付金额
*/
private BigDecimal paidAmount;
/**
* 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款)
*/
private String paymentStatus;
/**
* 支付时间
*/
private LocalDateTime paymentTime;
/**
* 第三方支付订单号
*/
private String orderNo;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
@@ -0,0 +1,88 @@
package top.xyquan.ecomdmbbackend.modules.sub.model.vo.subscription;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 订阅VO
*/
@Data
public class SubscriptionVO {
/**
* 记录ID
*/
private Long id;
/**
* 公司ID
*/
private Long companyId;
/**
* 公司名称
*/
private String companyName;
/**
* 套餐ID
*/
private Long planId;
/**
* 套餐名称
*/
private String planName;
/**
* 订阅开始时间
*/
private LocalDateTime startTime;
/**
* 订阅结束时间
*/
private LocalDateTime endTime;
/**
* 生效状态(ACTIVE-生效中,PENDING-待生效,INACTIVE-已失效)
*/
private String status;
/**
* 实际支付金额
*/
private BigDecimal paidAmount;
/**
* 支付状态(UNPAID=未支付,PAID=已支付,REFUNDED=已退款)
*/
private String paymentStatus;
/**
* 支付时间
*/
private LocalDateTime paymentTime;
/**
* 第三方支付订单号
*/
private String orderNo;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}

Some files were not shown because too many files have changed in this diff Show More