refactor(项目结构): 重构项目包结构并优化代码组织
重构项目包结构,将实体类、Mapper接口和服务类按功能模块分组 优化JwtUtils工具类,新增获取用户ID功能 调整SecurityConfig配置,增加公开访问接口 删除冗余DTO类,合并到相应模块 新增MyBatisPlus配置类,配置分页插件
This commit is contained in:
25
src/main/java/com/qf/backend/config/MyBatisPlusConfig.java
Normal file
25
src/main/java/com/qf/backend/config/MyBatisPlusConfig.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.qf.backend.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBatis-Plus配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MyBatisPlusConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置MyBatis-Plus插件,主要是分页插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
// 添加分页插件,设置数据库类型为MySQL
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,7 +70,14 @@ public class SecurityConfig {
|
|||||||
// 登录接口公开访问,不需要认证
|
// 登录接口公开访问,不需要认证
|
||||||
.requestMatchers("/api/auth/login").permitAll()
|
.requestMatchers("/api/auth/login").permitAll()
|
||||||
// 公开注册接口,不需要认证
|
// 公开注册接口,不需要认证
|
||||||
.requestMatchers("/api/user/**").permitAll()
|
.requestMatchers("/api/user/register").permitAll()
|
||||||
|
// 公开获取商品列表接口,不需要认证
|
||||||
|
.requestMatchers("/api/products/list").permitAll()
|
||||||
|
// 公开获取商品详情接口,不需要认证
|
||||||
|
.requestMatchers("/api/products/**").permitAll()
|
||||||
|
// 公开获取店铺商品列表接口,不需要认证
|
||||||
|
.requestMatchers("/api/shop/**").permitAll()
|
||||||
|
|
||||||
// 其他所有请求都需要认证
|
// 其他所有请求都需要认证
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.qf.backend.controller;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.qf.backend.dto.Result;
|
|
||||||
import com.qf.backend.dto.request.PageRequest;
|
|
||||||
import com.qf.backend.dto.response.Userresponse;
|
|
||||||
import com.qf.backend.service.UsersService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 管理员用户控制器
|
|
||||||
* 处理管理员用户相关的HTTP请求
|
|
||||||
* 遵循RESTful API设计规范
|
|
||||||
* @author 30803
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/api/admin")
|
|
||||||
public class AdminUserControoler {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AdminUserControoler.class);
|
|
||||||
@Autowired
|
|
||||||
private UsersService usersService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取所有用户信息
|
|
||||||
* @param page 当前页码
|
|
||||||
* @param size 每页数量
|
|
||||||
* @return 所有用户信息
|
|
||||||
*/
|
|
||||||
@PostMapping("/getuserinfo")
|
|
||||||
public Result<List<Userresponse>> getAllUserInfo(@PathVariable PageRequest pageRequest ) {
|
|
||||||
logger.info("获取所有用户信息请求");
|
|
||||||
return usersService.listUsersByPage(pageRequest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.qf.backend.controller;
|
package com.qf.backend.controller;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
@@ -12,10 +11,12 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.qf.backend.dto.LoginRequest;
|
|
||||||
import com.qf.backend.dto.LoginResponse;
|
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
|
import com.qf.backend.dto.request.LoginRequest;
|
||||||
|
import com.qf.backend.dto.response.LoginResponse;
|
||||||
|
import com.qf.backend.dto.response.Userresponse;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
|
import com.qf.backend.service.User.UsersService;
|
||||||
import com.qf.backend.util.JwtUtils;
|
import com.qf.backend.util.JwtUtils;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
|
|
||||||
@@ -39,6 +40,11 @@ public class AuthController {
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private JwtUtils jwtUtils;
|
private JwtUtils jwtUtils;
|
||||||
|
/**
|
||||||
|
* 注入用户服务,用于查询用户信息
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private UsersService userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录接口
|
* 用户登录接口
|
||||||
@@ -55,7 +61,7 @@ public class AuthController {
|
|||||||
* 6. 返回包含JWT令牌的响应
|
* 6. 返回包含JWT令牌的响应
|
||||||
*/
|
*/
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Result<ResponseEntity<LoginResponse>> login(@RequestBody LoginRequest loginRequest) {
|
public Result<LoginResponse> login(@RequestBody LoginRequest loginRequest) {
|
||||||
try {
|
try {
|
||||||
// 1. 创建认证令牌,将用户名和密码封装到UsernamePasswordAuthenticationToken中
|
// 1. 创建认证令牌,将用户名和密码封装到UsernamePasswordAuthenticationToken中
|
||||||
// 这里的令牌是未认证状态的,因为还没有验证密码是否正确
|
// 这里的令牌是未认证状态的,因为还没有验证密码是否正确
|
||||||
@@ -76,17 +82,20 @@ public class AuthController {
|
|||||||
// 4. 使用JwtUtils生成JWT令牌
|
// 4. 使用JwtUtils生成JWT令牌
|
||||||
// 令牌中包含了用户名、权限等信息,以及过期时间
|
// 令牌中包含了用户名、权限等信息,以及过期时间
|
||||||
String jwt = jwtUtils.generateToken(userDetails);
|
String jwt = jwtUtils.generateToken(userDetails);
|
||||||
|
// 5.从数据库重新查询用户信息 并获取role权限与permissions信息
|
||||||
|
Userresponse user = userService.getUserByUsername(userDetails.getUsername()).getData();
|
||||||
|
|
||||||
// 5. 创建LoginResponse对象,封装JWT令牌和令牌类型
|
// 6. 创建LoginResponse对象,封装JWT令牌和令牌类型
|
||||||
LoginResponse loginResponse = new LoginResponse();
|
LoginResponse loginResponse = new LoginResponse(
|
||||||
loginResponse.setUsername(userDetails.getUsername());
|
user.getUsers().getId(),
|
||||||
// loginResponse.setRoles(userDetails.getAuthorities().stream().map(grantedAuthority -> grantedAuthority.getAuthority()).collect(Collectors.toList()));
|
user.getUsers().getUsername(),
|
||||||
// loginResponse.setPermissions(jwtUtils.getPermissions(userDetails));
|
user.getRoles(),
|
||||||
loginResponse.setToken(jwt);
|
user.getPermissions(),
|
||||||
loginResponse.setTokenType(jwtUtils.getTokenPrefix());
|
jwt,
|
||||||
|
jwtUtils.getTokenPrefix()
|
||||||
|
);
|
||||||
// 5. 返回包含JWT令牌的响应
|
// 5. 返回包含JWT令牌的响应
|
||||||
// 响应格式为:{"token": "xxx", "tokenType": "Bearer"}
|
return ResultUtils.success(loginResponse);
|
||||||
return ResultUtils.success(ResponseEntity.ok(loginResponse));
|
|
||||||
} catch (BadCredentialsException e) {
|
} catch (BadCredentialsException e) {
|
||||||
// 认证失败,通常是用户名不存在或密码错误
|
// 认证失败,通常是用户名不存在或密码错误
|
||||||
// 返回401 Unauthorized响应
|
// 返回401 Unauthorized响应
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.dto.request.OrderRequest;
|
import com.qf.backend.dto.request.OrderRequest;
|
||||||
import com.qf.backend.dto.request.PageRequest;
|
import com.qf.backend.dto.request.PageRequest;
|
||||||
import com.qf.backend.entity.Orders;
|
import com.qf.backend.entity.Order.Orders;
|
||||||
import com.qf.backend.service.OrderItemsService;
|
import com.qf.backend.service.Order.OrderItemsService;
|
||||||
import com.qf.backend.service.OrdersService;
|
import com.qf.backend.service.Order.OrdersService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单控制器 (订单接口)
|
* 订单控制器 (订单接口)
|
||||||
@@ -41,7 +41,7 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/getorderinfo")
|
@PostMapping("/getorderinfo")
|
||||||
// 只有用户本人或管理员才能获取订单信息
|
// 只有用户本人或管理员才能获取订单信息
|
||||||
@PreAuthorize("#userId == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
@PreAuthorize("#orderRequest.getUserId() == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
||||||
public Result<Orders> getOrderInfo(@RequestBody OrderRequest orderRequest) {
|
public Result<Orders> getOrderInfo(@RequestBody OrderRequest orderRequest) {
|
||||||
logger.info("获取订单信息请求,订单ID:{}", orderRequest.getId());
|
logger.info("获取订单信息请求,订单ID:{}", orderRequest.getId());
|
||||||
return ordersService.getOrderById(orderRequest.getId());
|
return ordersService.getOrderById(orderRequest.getId());
|
||||||
@@ -84,7 +84,7 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
// 只有管理员或店铺所有者才能更新订单
|
// 只有管理员或店铺所有者才能更新订单
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||||
public Result<Boolean> updateOrder(@RequestBody OrderRequest orderRequest) {
|
public Result<Boolean> updateOrder(@RequestBody OrderRequest orderRequest) {
|
||||||
logger.info("更新订单信息请求,订单信息:{}", orderRequest);
|
logger.info("更新订单信息请求,订单信息:{}", orderRequest);
|
||||||
Orders orders = new Orders(orderRequest.getId(), orderRequest.getOrderNo(), orderRequest.getUserId(),
|
Orders orders = new Orders(orderRequest.getId(), orderRequest.getOrderNo(), orderRequest.getUserId(),
|
||||||
@@ -103,7 +103,7 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
// 只有管理员或店铺所有者才能删除订单
|
// 只有管理员或店铺所有者才能删除订单
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||||
public Result<Boolean> deleteOrder(@RequestBody OrderRequest orderRequest) {
|
public Result<Boolean> deleteOrder(@RequestBody OrderRequest orderRequest) {
|
||||||
logger.info("删除订单请求,订单ID:{}", orderRequest.getId());
|
logger.info("删除订单请求,订单ID:{}", orderRequest.getId());
|
||||||
return ordersService.deleteOrder(orderRequest.getId());
|
return ordersService.deleteOrder(orderRequest.getId());
|
||||||
@@ -116,7 +116,7 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
// 只有管理员或店铺所有者才能查询所有订单
|
// 只有管理员或店铺所有者才能查询所有订单
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||||
public Result<List<Orders>> listOrdersByPage(@RequestBody PageRequest pageRequest) {
|
public Result<List<Orders>> listOrdersByPage(@RequestBody PageRequest pageRequest) {
|
||||||
logger.info("分页查询订单请求,页码:{},每页大小:{}", pageRequest.getPage(), pageRequest.getSize());
|
logger.info("分页查询订单请求,页码:{},每页大小:{}", pageRequest.getPage(), pageRequest.getSize());
|
||||||
return ordersService.listOrdersByPage(pageRequest.getPage(), pageRequest.getSize());
|
return ordersService.listOrdersByPage(pageRequest.getPage(), pageRequest.getSize());
|
||||||
@@ -129,10 +129,10 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/byuser")
|
@PostMapping("/byuser")
|
||||||
// 只有用户本人或管理员才能查询用户订单
|
// 只有用户本人或管理员才能查询用户订单
|
||||||
@PreAuthorize("#userId == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
@PreAuthorize("#orderRequest.getUserId() == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
||||||
public Result<List<Orders>> getOrdersByUser(@RequestBody OrderRequest orderRequest) {
|
public Result<List<Orders>> getOrdersByUser(@RequestBody OrderRequest orderRequest ) {
|
||||||
logger.info("根据用户ID查询订单请求,用户ID:{}", orderRequest.getUserId());
|
logger.info("根据用户ID查询订单请求,用户ID:{},页码:{},每页大小:{}", orderRequest.getUserId(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
return ordersService.getOrdersByUserId(orderRequest.getUserId());
|
return ordersService.getOrdersByUserId(orderRequest.getUserId(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,10 +142,10 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/byshop")
|
@PostMapping("/byshop")
|
||||||
// 只有店铺所有者或管理员才能查询店铺订单
|
// 只有店铺所有者或管理员才能查询店铺订单
|
||||||
@PreAuthorize("#shopId == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||||
public Result<List<Orders>> getOrdersByShop(@RequestBody OrderRequest orderRequest) {
|
public Result<List<Orders>> getOrdersByShop(@RequestBody OrderRequest orderRequest ) {
|
||||||
logger.info("根据店铺ID查询订单请求,店铺ID:{}", orderRequest.getShopId());
|
logger.info("根据店铺ID查询订单请求,店铺ID:{},页码:{},每页大小:{}", orderRequest.getShopId(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
return ordersService.getOrdersByShopId(orderRequest.getShopId());
|
return ordersService.getOrdersByShopId(orderRequest.getShopId(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,10 +155,10 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/bystatus")
|
@PostMapping("/bystatus")
|
||||||
// 只有店铺所有者或管理员才能查询特定状态的订单
|
// 只有店铺所有者或管理员才能查询特定状态的订单
|
||||||
@PreAuthorize("#shopId == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||||
public Result<List<Orders>> getOrdersByStatus(@RequestBody OrderRequest orderRequest) {
|
public Result<List<Orders>> getOrdersByStatus(@RequestBody OrderRequest orderRequest ) {
|
||||||
logger.info("根据订单状态查询订单请求,状态:{}", orderRequest.getOrderStatus());
|
logger.info("根据订单状态查询订单请求,状态:{},页码:{},每页大小:{}", orderRequest.getOrderStatus(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
return ordersService.getOrdersByStatus(orderRequest.getOrderStatus());
|
return ordersService.getOrdersByStatus(orderRequest.getOrderStatus(), orderRequest.getPage(), orderRequest.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,7 +168,7 @@ public class OrdersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/updatestatus")
|
@PostMapping("/updatestatus")
|
||||||
// 只有店铺所有者或管理员才能更新订单状态
|
// 只有店铺所有者或管理员才能更新订单状态
|
||||||
@PreAuthorize("#shopId == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||||
public Result<Boolean> updateOrderStatus(@RequestBody OrderRequest orderRequest) {
|
public Result<Boolean> updateOrderStatus(@RequestBody OrderRequest orderRequest) {
|
||||||
logger.info("更新订单状态请求,订单ID:{},状态:{}", orderRequest.getId(), orderRequest.getOrderStatus());
|
logger.info("更新订单状态请求,订单ID:{},状态:{}", orderRequest.getId(), orderRequest.getOrderStatus());
|
||||||
return ordersService.updateOrderStatus(orderRequest.getId(), orderRequest.getOrderStatus());
|
return ordersService.updateOrderStatus(orderRequest.getId(), orderRequest.getOrderStatus());
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.dto.request.PageRequest;
|
import com.qf.backend.dto.request.PageRequest;
|
||||||
import com.qf.backend.dto.request.ProductRequest;
|
import com.qf.backend.dto.request.ProductRequest;
|
||||||
import com.qf.backend.entity.Products;
|
import com.qf.backend.dto.response.ProductsResponse;
|
||||||
import com.qf.backend.service.ProductsService;
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
import com.qf.backend.service.Products.ProductsService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品控制器 (商品接口)
|
* 商品控制器 (商品接口)
|
||||||
@@ -37,7 +38,7 @@ public class ProductsController {
|
|||||||
* @return 商品信息
|
* @return 商品信息
|
||||||
*/
|
*/
|
||||||
@PostMapping("/getproductinfo")
|
@PostMapping("/getproductinfo")
|
||||||
public Result<Products> getProductInfo(@RequestBody ProductRequest productRequest) {
|
public Result<ProductsResponse> getProductInfo(@RequestBody ProductRequest productRequest) {
|
||||||
logger.info("获取商品信息请求,商品ID:{}", productRequest.getId());
|
logger.info("获取商品信息请求,商品ID:{}", productRequest.getId());
|
||||||
return productsService.getProductById(productRequest.getId());
|
return productsService.getProductById(productRequest.getId());
|
||||||
}
|
}
|
||||||
@@ -104,9 +105,10 @@ public class ProductsController {
|
|||||||
* @return 商品列表
|
* @return 商品列表
|
||||||
*/
|
*/
|
||||||
@PostMapping("/bycategory")
|
@PostMapping("/bycategory")
|
||||||
public Result<List<Products>> getProductsByCategory(@RequestBody ProductRequest productRequest) {
|
public Result<List<Products>> getProductsByCategory(@RequestBody ProductRequest productRequest ) {
|
||||||
logger.info("根据分类ID查询商品请求,分类ID:{}", productRequest.getCategoryId());
|
logger.info("根据分类ID查询商品请求,分类ID:{},页码:{},每页大小:{}",
|
||||||
return productsService.getProductsByCategoryId(productRequest.getCategoryId());
|
productRequest.getCategoryId(), productRequest.getPage(), productRequest.getSize());
|
||||||
|
return productsService.getProductsByCategoryId(productRequest.getCategoryId(), productRequest.getPage(), productRequest.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,8 +118,9 @@ public class ProductsController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/byshop")
|
@PostMapping("/byshop")
|
||||||
public Result<List<Products>> getProductsByShop(@RequestBody ProductRequest productRequest) {
|
public Result<List<Products>> getProductsByShop(@RequestBody ProductRequest productRequest) {
|
||||||
logger.info("根据店铺ID查询商品请求,店铺ID:{}", productRequest.getShopId());
|
logger.info("根据店铺ID查询商品请求,店铺ID:{},页码:{},每页大小:{}",
|
||||||
return productsService.getProductsByShopId(productRequest.getShopId());
|
productRequest.getShopId(), productRequest.getPage(), productRequest.getSize());
|
||||||
|
return productsService.getProductsByShopIds(List.of(productRequest.getShopId()), productRequest.getPage(), productRequest.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
96
src/main/java/com/qf/backend/controller/ShopController.java
Normal file
96
src/main/java/com/qf/backend/controller/ShopController.java
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package com.qf.backend.controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
import com.qf.backend.service.Shop.ShopsService;
|
||||||
|
import com.qf.backend.dto.Result;
|
||||||
|
import com.qf.backend.dto.request.ShopRequest;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
import com.qf.backend.service.Shop.ShopsService;
|
||||||
|
import com.qf.backend.service.Products.ProductsService;
|
||||||
|
import com.qf.backend.dto.response.ShopResponse;
|
||||||
|
import com.qf.backend.dto.response.ProductsResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取店铺信息接口
|
||||||
|
* @author 30803
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/shop")
|
||||||
|
public class ShopController {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ShopController.class);
|
||||||
|
@Autowired
|
||||||
|
private ShopsService shopsService;
|
||||||
|
@Autowired
|
||||||
|
private ProductsService productsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取店铺信息
|
||||||
|
* @param shopRequest 店铺请求
|
||||||
|
* @return 店铺信息
|
||||||
|
*/
|
||||||
|
@PostMapping("/info")
|
||||||
|
public Result<Shops> getShopInfo(@RequestBody ShopRequest shopRequest) {
|
||||||
|
logger.info("获取店铺信息请求,店铺ID:{}", shopRequest.getId());
|
||||||
|
return shopsService.getShopById(shopRequest.getId());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 分页查询店铺
|
||||||
|
* @param shopRequest 店铺请求
|
||||||
|
* @return 店铺列表
|
||||||
|
*/
|
||||||
|
@PostMapping("/page")
|
||||||
|
public Result<List<ShopResponse>> getShopsPage(@RequestBody ShopRequest shopRequest) {
|
||||||
|
logger.info("分页查询店铺请求,当前页码:{},每页数量:{}", shopRequest.getPage(), shopRequest.getSize());
|
||||||
|
|
||||||
|
// 1. 店铺查询
|
||||||
|
List<Shops> shops = shopsService.listShopsByPage(shopRequest.getPage(), shopRequest.getSize()).getData();
|
||||||
|
|
||||||
|
// 2. 提取店铺id
|
||||||
|
List<Long> shopIds = shops.stream().map(Shops::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 3. 调用商品服务查询商品
|
||||||
|
List<Products> products = productsService.getProductsByShopIds(shopIds, 1, 10).getData();
|
||||||
|
|
||||||
|
// 4. 转换商品为ProductsResponse
|
||||||
|
List<ProductsResponse> productsResponses = products.stream()
|
||||||
|
.map(product -> {
|
||||||
|
ProductsResponse pr = new ProductsResponse();
|
||||||
|
pr.setProducts(product);
|
||||||
|
return pr;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 5. 创建ShopResponse列表
|
||||||
|
List<ShopResponse> shopResponses = new ArrayList<>();
|
||||||
|
|
||||||
|
// 6. 为每个店铺创建ShopResponse
|
||||||
|
shops.forEach(shop -> {
|
||||||
|
ShopResponse shopResponse = new ShopResponse();
|
||||||
|
shopResponse.setShop(shop);
|
||||||
|
|
||||||
|
// 7. 提取当前店铺的商品
|
||||||
|
List<ProductsResponse> shopProducts = productsResponses.stream()
|
||||||
|
.filter(product -> product.getProducts().getShopId().equals(shop.getId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
shopResponse.setProducts(shopProducts);
|
||||||
|
shopResponses.add(shopResponse);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 8. 返回结果
|
||||||
|
return Result.success(shopResponses);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.qf.backend.controller;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.qf.backend.dto.Result;
|
|
||||||
import com.qf.backend.entity.User.UserRoles;
|
|
||||||
import com.qf.backend.service.UserRolesService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户角色关联控制器
|
|
||||||
* 处理用户与角色关联相关的HTTP请求
|
|
||||||
* 遵循RESTful API设计规范
|
|
||||||
* @author 30803
|
|
||||||
*/
|
|
||||||
@RequestMapping("/api/user-roles")
|
|
||||||
@RestController
|
|
||||||
public class UserRolesController {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(UserRolesController.class);
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserRolesService userRolesService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据用户ID查询角色关联
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return 用户角色关联列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/user/{userId}")
|
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
||||||
public Result<List<UserRoles>> getUserRolesByUserId(@PathVariable Long userId) {
|
|
||||||
logger.info("管理员根据用户ID查询角色关联,用户ID:{}", userId);
|
|
||||||
return userRolesService.getUserRolesByUserId(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据角色ID查询用户关联
|
|
||||||
* @param roleId 角色ID
|
|
||||||
* @return 用户角色关联列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/role/{roleId}")
|
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
||||||
public Result<List<UserRoles>> getUserRolesByRoleId(@PathVariable Long roleId) {
|
|
||||||
logger.info("管理员根据角色ID查询用户关联,角色ID:{}", roleId);
|
|
||||||
return userRolesService.getUserRolesByRoleId(roleId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.dto.request.UsersRequest;
|
import com.qf.backend.dto.request.UsersRequest;
|
||||||
import com.qf.backend.entity.User.Users;
|
import com.qf.backend.entity.User.Users;
|
||||||
import com.qf.backend.service.UsersService;
|
import com.qf.backend.service.User.UsersService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户控制器 (用户接口)
|
* 用户控制器 (用户接口)
|
||||||
@@ -35,7 +36,7 @@ public class UsersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/getuserinfo")
|
@PostMapping("/getuserinfo")
|
||||||
// 只有用户本人或管理员才能获取用户信息
|
// 只有用户本人或管理员才能获取用户信息
|
||||||
@PreAuthorize("#id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||||
public Result<Users> getUserInfo(@RequestBody UsersRequest usersRequest) {
|
public Result<Users> getUserInfo(@RequestBody UsersRequest usersRequest) {
|
||||||
logger.info("获取用户信息请求,用户ID:{}", usersRequest.getId());
|
logger.info("获取用户信息请求,用户ID:{}", usersRequest.getId());
|
||||||
return usersService.getUserById(usersRequest.getId());
|
return usersService.getUserById(usersRequest.getId());
|
||||||
@@ -48,7 +49,7 @@ public class UsersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/info")
|
@PostMapping("/info")
|
||||||
// 只有用户本人或管理员才能更新用户信息
|
// 只有用户本人或管理员才能更新用户信息
|
||||||
@PreAuthorize("#id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||||
public Result<Boolean> updateUserInfo(@RequestBody UsersRequest usersRequest) {
|
public Result<Boolean> updateUserInfo(@RequestBody UsersRequest usersRequest) {
|
||||||
logger.info("更新用户信息请求,更新信息:{}", usersRequest);
|
logger.info("更新用户信息请求,更新信息:{}", usersRequest);
|
||||||
Users users = new Users(usersRequest.getId(), usersRequest.getUsername(), usersRequest.getPassword(),
|
Users users = new Users(usersRequest.getId(), usersRequest.getUsername(), usersRequest.getPassword(),
|
||||||
@@ -64,7 +65,7 @@ public class UsersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
// 只有用户本人或管理员才能注销登录
|
// 只有用户本人或管理员才能注销登录
|
||||||
@PreAuthorize("#id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||||
public Result<Boolean> logout(@RequestBody UsersRequest usersRequest) {
|
public Result<Boolean> logout(@RequestBody UsersRequest usersRequest) {
|
||||||
logger.info("注销登录请求,用户ID:{}", usersRequest.getId());
|
logger.info("注销登录请求,用户ID:{}", usersRequest.getId());
|
||||||
return usersService.deleteUser(usersRequest.getId(),usersRequest.getStatus() );
|
return usersService.deleteUser(usersRequest.getId(),usersRequest.getStatus() );
|
||||||
@@ -78,7 +79,7 @@ public class UsersController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/resetpassword")
|
@PostMapping("/resetpassword")
|
||||||
// 只有用户本人或管理员才能重置密码
|
// 只有用户本人或管理员才能重置密码
|
||||||
@PreAuthorize("#id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||||
public Result<Boolean> resetPassword(@RequestBody UsersRequest usersRequest) {
|
public Result<Boolean> resetPassword(@RequestBody UsersRequest usersRequest) {
|
||||||
logger.info("重置密码请求,用户ID:{}", usersRequest.getId());
|
logger.info("重置密码请求,用户ID:{}", usersRequest.getId());
|
||||||
return usersService.updatePassword(usersRequest.getId(), usersRequest.getPassword());
|
return usersService.updatePassword(usersRequest.getId(), usersRequest.getPassword());
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.qf.backend.dto;
|
|
||||||
|
|
||||||
public class ProductsDataList {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,14 +3,12 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.qf.backend.dto;
|
package com.qf.backend.dto.request;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录请求参数
|
* 登录请求参数
|
||||||
* @author 30803
|
* @author 30803
|
||||||
@@ -19,6 +17,6 @@ import lombok.NoArgsConstructor;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class LoginRequest {
|
public class LoginRequest {
|
||||||
private String username;
|
private String username; // 用户名
|
||||||
private String password;
|
private String password; // 密码
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import java.math.BigDecimal;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.qf.backend.entity.OrderItems;
|
import com.qf.backend.entity.Order.OrderItems;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ public class OrderRequest {
|
|||||||
private Date completeTime; // 完成时间
|
private Date completeTime; // 完成时间
|
||||||
private String remark; // 备注
|
private String remark; // 备注
|
||||||
private List<OrderItems> orderItems; // 订单项列表
|
private List<OrderItems> orderItems; // 订单项列表
|
||||||
|
|
||||||
private Integer page; // 页码,用于分页查询
|
private Integer page; // 页码,用于分页查询
|
||||||
private Integer size; // 每页大小,用于分页查询
|
private Integer size; // 每页大小,用于分页查询
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/main/java/com/qf/backend/dto/request/ShopRequest.java
Normal file
33
src/main/java/com/qf/backend/dto/request/ShopRequest.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package com.qf.backend.dto.request;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺请求DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ShopRequest {
|
||||||
|
private Long id; // 店铺ID,主键,自增
|
||||||
|
|
||||||
|
private String shopName; // 店铺名称
|
||||||
|
private Long userId; // 店主用户ID,外键,关联users表
|
||||||
|
private Long categoryId; // 店铺分类ID,外键,关联shop_categories表
|
||||||
|
private String shopLogo; // 店铺Logo
|
||||||
|
private String coverImage; // 店铺封面图
|
||||||
|
private String description; // 店铺描述
|
||||||
|
private String address; // 店铺地址
|
||||||
|
private String contactPhone; // 联系人手机号
|
||||||
|
private String contactPerson; // 联系人姓名
|
||||||
|
private BigDecimal rating; // 店铺评分
|
||||||
|
private Integer salesVolume; // 销量
|
||||||
|
private Integer status; // 状态:0: 未审核, 1: 已审核, 2: 已关闭, 3: 审核失败
|
||||||
|
private String businessLicense; // 营业执照URL
|
||||||
|
private Date businessStartTime; // 营业时间开始
|
||||||
|
private Date businessEndTime; // 营业时间结束
|
||||||
|
private Integer page; // 当前页码,用于分页查询
|
||||||
|
private Integer size; // 每页数量,用于分页查询
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,10 +2,13 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
package com.qf.backend.dto;
|
package com.qf.backend.dto.response;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.User.Permissions;
|
||||||
|
import com.qf.backend.entity.User.Roles;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -24,9 +27,10 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class LoginResponse {
|
public class LoginResponse {
|
||||||
|
private Long userId; // 用户id
|
||||||
private String username; // 用户名
|
private String username; // 用户名
|
||||||
private List<String> roles; // 角色列表 暂时无用
|
private List<Roles> roles; // 角色列表 暂时无用
|
||||||
private List<String> permissions; // 权限列表 暂时无用
|
private List<Permissions> permissions; // 权限列表 暂时无用
|
||||||
private String token; // JWT令牌
|
private String token; // JWT令牌
|
||||||
private String tokenType; // 令牌类型,通常为Bearer
|
private String tokenType; // 令牌类型,通常为Bearer
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.qf.backend.dto.response;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.Order.OrderItems;
|
||||||
|
import com.qf.backend.entity.Order.Orders;
|
||||||
|
import com.qf.backend.entity.Refunds;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
import com.qf.backend.entity.User.Users;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单响应类
|
||||||
|
* 返回订单详情信息 下单用户 订单所属店铺 订单商品列表 订单状态(Refunds支付状态 已退款、已取消)
|
||||||
|
*
|
||||||
|
* @author QF
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023-12-15
|
||||||
|
*/
|
||||||
|
public class OrdersResponse {
|
||||||
|
private Orders orders; // 订单信息
|
||||||
|
private Users user; // 下单用户
|
||||||
|
private Shops shop; // 订单所属店铺
|
||||||
|
private List<OrderItems> ordersItems; // 订单商品列表 包含商品详情 商品【数量、单价、小计】
|
||||||
|
private Refunds refund; // 订单退款状态(0:正常, 1:已退款, 2:退款中)
|
||||||
|
public Orders getOrders() {
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
public void setOrders(Orders orders) {
|
||||||
|
this.orders = orders;
|
||||||
|
}
|
||||||
|
public Users getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
public void setUser(Users user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
public Shops getShop() {
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
public void setShop(Shops shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
public List<OrderItems> getOrdersItems() {
|
||||||
|
return ordersItems;
|
||||||
|
}
|
||||||
|
public void setOrdersItems(List<OrderItems> ordersItems) {
|
||||||
|
this.ordersItems = ordersItems;
|
||||||
|
}
|
||||||
|
public Refunds getRefund() {
|
||||||
|
return refund;
|
||||||
|
}
|
||||||
|
public void setRefund(Refunds refund) {
|
||||||
|
this.refund = refund;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
103
src/main/java/com/qf/backend/dto/response/ProductsResponse.java
Normal file
103
src/main/java/com/qf/backend/dto/response/ProductsResponse.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package com.qf.backend.dto.response;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品响应类,用于商品详情和列表查询
|
||||||
|
* 包含商品基本信息、分类信息和店铺信息
|
||||||
|
*
|
||||||
|
* @author 30803
|
||||||
|
*/
|
||||||
|
public class ProductsResponse {
|
||||||
|
private Products products;
|
||||||
|
/**
|
||||||
|
* 商品分类信息
|
||||||
|
*/
|
||||||
|
private ProductCategories category;
|
||||||
|
/**
|
||||||
|
* 商品属性列表
|
||||||
|
*/
|
||||||
|
private List<ProductAttributes> Attributes;
|
||||||
|
/**
|
||||||
|
* 商品属性值列表
|
||||||
|
*/
|
||||||
|
private List<ProductAttributeValues> AttributeValuesList;
|
||||||
|
/**
|
||||||
|
* 商品SKU列表
|
||||||
|
*/
|
||||||
|
private List<ProductSkus> productSkus;
|
||||||
|
/**
|
||||||
|
* 商品图片列表
|
||||||
|
*/
|
||||||
|
private List<ProductImages> productImages;
|
||||||
|
/**
|
||||||
|
* 商品店铺信息
|
||||||
|
*/
|
||||||
|
private Shops shop;
|
||||||
|
|
||||||
|
public Products getProducts() {
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProducts(Products products) {
|
||||||
|
this.products = products;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductCategories getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(ProductCategories category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Shops getShop() {
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShop(Shops shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductAttributes> getAttributes() {
|
||||||
|
return Attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributes(List<ProductAttributes> attributes) {
|
||||||
|
Attributes = attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductAttributeValues> getAttributeValuesList() {
|
||||||
|
return AttributeValuesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributeValuesList(List<ProductAttributeValues> attributeValuesList) {
|
||||||
|
AttributeValuesList = attributeValuesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductSkus> getProductSkus() {
|
||||||
|
return productSkus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductSkus(List<ProductSkus> productSkus) {
|
||||||
|
this.productSkus = productSkus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductImages> getProductImages() {
|
||||||
|
return productImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductImages(List<ProductImages> productImages) {
|
||||||
|
this.productImages = productImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
32
src/main/java/com/qf/backend/dto/response/ShopResponse.java
Normal file
32
src/main/java/com/qf/backend/dto/response/ShopResponse.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package com.qf.backend.dto.response;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺响应类
|
||||||
|
* 返回店铺详情信息
|
||||||
|
*
|
||||||
|
* @author QF
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2023-12-15
|
||||||
|
*/
|
||||||
|
public class ShopResponse {
|
||||||
|
private Shops shop; // 店铺信息
|
||||||
|
|
||||||
|
private List<ProductsResponse> products; // 店铺商品列表
|
||||||
|
|
||||||
|
public Shops getShop() {
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
public void setShop(Shops shop) {
|
||||||
|
this.shop = shop;
|
||||||
|
}
|
||||||
|
public List<ProductsResponse> getProducts() {
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
public void setProducts(List<ProductsResponse> products) {
|
||||||
|
this.products = products;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,17 @@ package com.qf.backend.dto.response;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.qf.backend.entity.User.Permissions;
|
||||||
import com.qf.backend.entity.User.Roles;
|
import com.qf.backend.entity.User.Roles;
|
||||||
import com.qf.backend.entity.User.Users;
|
import com.qf.backend.entity.User.Users;
|
||||||
|
|
||||||
public class Userresponse {
|
public class Userresponse {
|
||||||
private Users users;
|
private Users users;
|
||||||
|
// 角色列表
|
||||||
private List<Roles> roles;
|
private List<Roles> roles;
|
||||||
|
// 权限列表
|
||||||
|
private List<Permissions> permissions;
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
public Users getUsers() {
|
public Users getUsers() {
|
||||||
return users;
|
return users;
|
||||||
@@ -21,4 +26,11 @@ public class Userresponse {
|
|||||||
public void setRoles(List<Roles> roles) {
|
public void setRoles(List<Roles> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
public List<Permissions> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
public void setPermissions(List<Permissions> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Order;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Order;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Order;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Product;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Shop;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class ShopCategories {
|
|||||||
private String categoryName; // 分类名称
|
private String categoryName; // 分类名称
|
||||||
private Long parentId; // 父分类ID,顶级分类为0
|
private Long parentId; // 父分类ID,顶级分类为0
|
||||||
private Integer level; // 分类级别
|
private Integer level; // 分类级别
|
||||||
private String icon; // 分类图标
|
private String icon; // 分类图标URL
|
||||||
private Integer sort; // 排序
|
private Integer sort; // 排序
|
||||||
private Integer status; // 状态:0:禁用, 1:启用
|
private Integer status; // 状态:0:禁用, 1:启用
|
||||||
private Date createdAt; // 创建时间
|
private Date createdAt; // 创建时间
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Shop;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.entity;
|
package com.qf.backend.entity.Shop;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -37,7 +37,7 @@ public class Shops {
|
|||||||
private BigDecimal rating; // 店铺评分
|
private BigDecimal rating; // 店铺评分
|
||||||
private Integer salesVolume; // 销量
|
private Integer salesVolume; // 销量
|
||||||
private Integer status; // 状态:0: 未审核, 1: 已审核, 2: 已关闭, 3: 审核失败
|
private Integer status; // 状态:0: 未审核, 1: 已审核, 2: 已关闭, 3: 审核失败
|
||||||
private String businessLicense; // 营业执照
|
private String businessLicense; // 营业执照URL
|
||||||
private Date businessStartTime; // 营业时间开始
|
private Date businessStartTime; // 营业时间开始
|
||||||
private Date businessEndTime; // 营业时间结束
|
private Date businessEndTime; // 营业时间结束
|
||||||
private Date createdAt; // 创建时间
|
private Date createdAt; // 创建时间
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.qf.backend.entity.User;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
public class CustomUserDetails implements UserDetails {
|
||||||
|
|
||||||
|
private Long id; // 👈 新增用户ID
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
private boolean accountNonExpired;
|
||||||
|
private boolean accountNonLocked;
|
||||||
|
private boolean credentialsNonExpired;
|
||||||
|
private boolean enabled;
|
||||||
|
private Collection<? extends GrantedAuthority> authorities;
|
||||||
|
|
||||||
|
// 构造方法(推荐)
|
||||||
|
public CustomUserDetails(Long id, String username, String password,
|
||||||
|
Collection<? extends GrantedAuthority> authorities,
|
||||||
|
boolean enabled, boolean accountNonExpired,
|
||||||
|
boolean accountNonLocked, boolean credentialsNonExpired) {
|
||||||
|
this.id = id;
|
||||||
|
this.username = username;
|
||||||
|
this.password = password;
|
||||||
|
this.authorities = authorities;
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.accountNonExpired = accountNonExpired;
|
||||||
|
this.accountNonLocked = accountNonLocked;
|
||||||
|
this.credentialsNonExpired = credentialsNonExpired;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter(必须提供 id 的 getter)
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter(可选,根据需要添加)
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 以下是 UserDetails 接口必须实现的方法 ==========
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {
|
||||||
|
return accountNonExpired;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {
|
||||||
|
return accountNonLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {
|
||||||
|
return credentialsNonExpired;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
package com.qf.backend.inti;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
|
import com.qf.backend.entity.Product.ProductInventories;
|
||||||
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
import com.qf.backend.service.Products.ProductAttributeValuesService;
|
||||||
|
import com.qf.backend.service.Products.ProductAttributesService;
|
||||||
|
import com.qf.backend.service.Products.ProductImagesService;
|
||||||
|
import com.qf.backend.service.Products.ProductInventoriesService;
|
||||||
|
import com.qf.backend.service.Products.ProductSkusService;
|
||||||
|
import com.qf.backend.service.Products.ProductsService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品详细数据初始化配置类,用于在系统启动时创建商品的详细数据
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ProductDataDetailInitializer {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ProductDataDetailInitializer.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductsService productsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductAttributesService productAttributesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductAttributeValuesService productAttributeValuesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductImagesService productImagesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductSkusService productSkusService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProductInventoriesService productInventoriesService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统启动时初始化商品详细数据
|
||||||
|
*/
|
||||||
|
// @PostConstruct
|
||||||
|
public void initProductDetailData() {
|
||||||
|
logger.info("开始初始化商品详细数据...");
|
||||||
|
|
||||||
|
// 初始化商品属性
|
||||||
|
initProductAttributes();
|
||||||
|
|
||||||
|
// 初始化商品属性值
|
||||||
|
initProductAttributeValues();
|
||||||
|
|
||||||
|
// 初始化商品图片
|
||||||
|
initProductImages();
|
||||||
|
|
||||||
|
// 初始化商品SKU
|
||||||
|
initProductSkus();
|
||||||
|
|
||||||
|
// 初始化商品库存
|
||||||
|
initProductInventories();
|
||||||
|
|
||||||
|
logger.info("商品详细数据初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化商品属性
|
||||||
|
*/
|
||||||
|
private void initProductAttributes() {
|
||||||
|
logger.info("开始初始化商品属性...");
|
||||||
|
|
||||||
|
// 定义初始商品属性信息
|
||||||
|
Object[][] attributeInfos = {
|
||||||
|
// 手机分类 (categoryId = 10)
|
||||||
|
{"颜色", 10, 0, 1}, // 0: 规格属性
|
||||||
|
{"存储容量", 10, 0, 2},
|
||||||
|
{"运行内存", 10, 0, 3},
|
||||||
|
// 电脑分类 (categoryId = 5)
|
||||||
|
{"处理器", 5, 0, 1},
|
||||||
|
{"内存", 5, 0, 2},
|
||||||
|
{"硬盘", 5, 0, 3},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] attributeInfo : attributeInfos) {
|
||||||
|
String attributeName = (String) attributeInfo[0];
|
||||||
|
Long categoryId = Long.valueOf((Integer) attributeInfo[1]);
|
||||||
|
Integer attributeType = (Integer) attributeInfo[2];
|
||||||
|
Integer sort = (Integer) attributeInfo[3];
|
||||||
|
|
||||||
|
// 检查属性是否已存在
|
||||||
|
QueryWrapper<ProductAttributes> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("attribute_name", attributeName)
|
||||||
|
.eq("category_id", categoryId);
|
||||||
|
ProductAttributes existingAttribute = productAttributesService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingAttribute == null) {
|
||||||
|
// 创建新属性
|
||||||
|
ProductAttributes attribute = new ProductAttributes();
|
||||||
|
attribute.setAttributeName(attributeName);
|
||||||
|
attribute.setCategoryId(categoryId);
|
||||||
|
attribute.setAttributeType(attributeType);
|
||||||
|
attribute.setSort(sort);
|
||||||
|
attribute.setCreatedAt(new Date());
|
||||||
|
attribute.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
productAttributesService.save(attribute);
|
||||||
|
logger.info("成功创建商品属性: {} (分类ID: {})", attributeName, categoryId);
|
||||||
|
} else {
|
||||||
|
logger.info("商品属性 {} (分类ID: {}) 已存在,跳过创建", attributeName, categoryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("商品属性初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化商品属性值
|
||||||
|
*/
|
||||||
|
private void initProductAttributeValues() {
|
||||||
|
logger.info("开始初始化商品属性值...");
|
||||||
|
|
||||||
|
// 获取iPhone 16 Pro商品
|
||||||
|
Products iphoneProduct = productsService.getOne(new QueryWrapper<Products>().eq("product_name", "iPhone 16 Pro"));
|
||||||
|
if (iphoneProduct != null) {
|
||||||
|
Long productId = iphoneProduct.getId();
|
||||||
|
|
||||||
|
// 获取颜色属性ID
|
||||||
|
ProductAttributes colorAttr = productAttributesService.getOne(new QueryWrapper<ProductAttributes>()
|
||||||
|
.eq("attribute_name", "颜色")
|
||||||
|
.eq("category_id", 10));
|
||||||
|
|
||||||
|
// 获取存储容量属性ID
|
||||||
|
ProductAttributes storageAttr = productAttributesService.getOne(new QueryWrapper<ProductAttributes>()
|
||||||
|
.eq("attribute_name", "存储容量")
|
||||||
|
.eq("category_id", 10));
|
||||||
|
|
||||||
|
if (colorAttr != null && storageAttr != null) {
|
||||||
|
// 定义iPhone 16 Pro的属性值
|
||||||
|
Object[][] attributeValueInfos = {
|
||||||
|
{productId, colorAttr.getId(), "深空黑色", 1},
|
||||||
|
{productId, colorAttr.getId(), "银色", 2},
|
||||||
|
{productId, colorAttr.getId(), "金色", 3},
|
||||||
|
{productId, colorAttr.getId(), "白色", 4},
|
||||||
|
{productId, storageAttr.getId(), "128GB", 1},
|
||||||
|
{productId, storageAttr.getId(), "256GB", 2},
|
||||||
|
{productId, storageAttr.getId(), "512GB", 3},
|
||||||
|
{productId, storageAttr.getId(), "1TB", 4},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] valueInfo : attributeValueInfos) {
|
||||||
|
Long prodId = (Long) valueInfo[0];
|
||||||
|
Long attrId = (Long) valueInfo[1];
|
||||||
|
String attrValue = (String) valueInfo[2];
|
||||||
|
Integer sort = (Integer) valueInfo[3];
|
||||||
|
|
||||||
|
// 检查属性值是否已存在
|
||||||
|
QueryWrapper<ProductAttributeValues> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("product_id", prodId)
|
||||||
|
.eq("attribute_id", attrId)
|
||||||
|
.eq("attribute_value", attrValue);
|
||||||
|
ProductAttributeValues existingValue = productAttributeValuesService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingValue == null) {
|
||||||
|
// 创建新属性值
|
||||||
|
ProductAttributeValues attributeValue = new ProductAttributeValues();
|
||||||
|
attributeValue.setProductId(prodId);
|
||||||
|
attributeValue.setAttributeId(attrId);
|
||||||
|
attributeValue.setAttributeValue(attrValue);
|
||||||
|
attributeValue.setSort(sort);
|
||||||
|
attributeValue.setCreatedAt(new Date());
|
||||||
|
attributeValue.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
productAttributeValuesService.save(attributeValue);
|
||||||
|
logger.info("成功创建商品属性值: {} (商品ID: {}, 属性ID: {})", attrValue, prodId, attrId);
|
||||||
|
} else {
|
||||||
|
logger.info("商品属性值 {} (商品ID: {}, 属性ID: {}) 已存在,跳过创建", attrValue, prodId, attrId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("商品属性值初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化商品图片
|
||||||
|
*/
|
||||||
|
private void initProductImages() {
|
||||||
|
logger.info("开始初始化商品图片...");
|
||||||
|
|
||||||
|
// 获取所有商品
|
||||||
|
for (Products product : productsService.list()) {
|
||||||
|
Long productId = product.getId();
|
||||||
|
String productName = product.getProductName();
|
||||||
|
|
||||||
|
// 定义商品图片信息
|
||||||
|
Object[][] imageInfos = {
|
||||||
|
{productId, product.getMainImage(), 1, 1}, // 主图
|
||||||
|
{productId, productName.toLowerCase().replace(" ", "") + "_1.jpg", 2, 0},
|
||||||
|
{productId, productName.toLowerCase().replace(" ", "") + "_2.jpg", 3, 0},
|
||||||
|
{productId, productName.toLowerCase().replace(" ", "") + "_3.jpg", 4, 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] imageInfo : imageInfos) {
|
||||||
|
Long prodId = (Long) imageInfo[0];
|
||||||
|
String imageUrl = (String) imageInfo[1];
|
||||||
|
Integer sort = (Integer) imageInfo[2];
|
||||||
|
Integer isMain = (Integer) imageInfo[3];
|
||||||
|
|
||||||
|
// 检查图片是否已存在
|
||||||
|
QueryWrapper<ProductImages> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("product_id", prodId)
|
||||||
|
.eq("image_url", imageUrl);
|
||||||
|
ProductImages existingImage = productImagesService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingImage == null) {
|
||||||
|
// 创建新图片
|
||||||
|
ProductImages productImage = new ProductImages();
|
||||||
|
productImage.setProductId(prodId);
|
||||||
|
productImage.setImageUrl(imageUrl);
|
||||||
|
productImage.setSort(sort);
|
||||||
|
productImage.setIsMain(isMain);
|
||||||
|
productImage.setCreatedAt(new Date());
|
||||||
|
|
||||||
|
productImagesService.save(productImage);
|
||||||
|
logger.info("成功创建商品图片: {} (商品ID: {})", imageUrl, prodId);
|
||||||
|
} else {
|
||||||
|
logger.info("商品图片 {} (商品ID: {}) 已存在,跳过创建", imageUrl, prodId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("商品图片初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化商品SKU
|
||||||
|
*/
|
||||||
|
private void initProductSkus() {
|
||||||
|
logger.info("开始初始化商品SKU...");
|
||||||
|
|
||||||
|
// 获取iPhone 16 Pro商品
|
||||||
|
Products iphoneProduct = productsService.getOne(new QueryWrapper<Products>().eq("product_name", "iPhone 16 Pro"));
|
||||||
|
if (iphoneProduct != null) {
|
||||||
|
Long productId = iphoneProduct.getId();
|
||||||
|
|
||||||
|
// 定义iPhone 16 Pro的SKU信息
|
||||||
|
Object[][] skuInfos = {
|
||||||
|
{productId, "IP16P-128GB-B", "{\"颜色\":\"深空黑色\",\"存储容量\":\"128GB\"}", 7999.00, 100, "iphone16_black_128.jpg", 1},
|
||||||
|
{productId, "IP16P-128GB-S", "{\"颜色\":\"银色\",\"存储容量\":\"128GB\"}", 7999.00, 100, "iphone16_silver_128.jpg", 1},
|
||||||
|
{productId, "IP16P-256GB-B", "{\"颜色\":\"深空黑色\",\"存储容量\":\"256GB\"}", 8999.00, 100, "iphone16_black_256.jpg", 1},
|
||||||
|
{productId, "IP16P-256GB-S", "{\"颜色\":\"银色\",\"存储容量\":\"256GB\"}", 8999.00, 100, "iphone16_silver_256.jpg", 1},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] skuInfo : skuInfos) {
|
||||||
|
Long prodId = (Long) skuInfo[0];
|
||||||
|
String skuCode = (String) skuInfo[1];
|
||||||
|
String skuSpecs = (String) skuInfo[2];
|
||||||
|
Double price = (Double) skuInfo[3];
|
||||||
|
Integer stock = (Integer) skuInfo[4];
|
||||||
|
String image = (String) skuInfo[5];
|
||||||
|
Integer status = (Integer) skuInfo[6];
|
||||||
|
|
||||||
|
// 检查SKU是否已存在
|
||||||
|
QueryWrapper<ProductSkus> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("product_id", prodId)
|
||||||
|
.eq("sku_code", skuCode);
|
||||||
|
ProductSkus existingSku = productSkusService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingSku == null) {
|
||||||
|
// 创建新SKU
|
||||||
|
ProductSkus productSku = new ProductSkus();
|
||||||
|
productSku.setProductId(prodId);
|
||||||
|
productSku.setSkuCode(skuCode);
|
||||||
|
productSku.setSkuSpecs(skuSpecs);
|
||||||
|
productSku.setPrice(new BigDecimal(Double.toString(price)));
|
||||||
|
productSku.setStock(stock);
|
||||||
|
productSku.setImage(image);
|
||||||
|
productSku.setStatus(status);
|
||||||
|
productSku.setCreatedAt(new Date());
|
||||||
|
productSku.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
productSkusService.save(productSku);
|
||||||
|
logger.info("成功创建商品SKU: {} (商品ID: {})", skuCode, prodId);
|
||||||
|
} else {
|
||||||
|
logger.info("商品SKU {} (商品ID: {}) 已存在,跳过创建", skuCode, prodId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("商品SKU初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化商品库存
|
||||||
|
*/
|
||||||
|
private void initProductInventories() {
|
||||||
|
logger.info("开始初始化商品库存...");
|
||||||
|
|
||||||
|
// 获取所有商品SKU
|
||||||
|
for (ProductSkus sku : productSkusService.list()) {
|
||||||
|
Long skuId = sku.getId();
|
||||||
|
|
||||||
|
// 检查库存是否已存在
|
||||||
|
QueryWrapper<ProductInventories> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("sku_id", skuId);
|
||||||
|
ProductInventories existingInventory = productInventoriesService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingInventory == null) {
|
||||||
|
// 创建新库存
|
||||||
|
ProductInventories inventory = new ProductInventories();
|
||||||
|
inventory.setSkuId(skuId);
|
||||||
|
inventory.setCurrentStock(sku.getStock());
|
||||||
|
inventory.setSafetyStock(10); // 默认安全库存为10
|
||||||
|
inventory.setLockStock(0);
|
||||||
|
inventory.setLastUpdateTime(new Date());
|
||||||
|
inventory.setCreatedAt(new Date());
|
||||||
|
inventory.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
productInventoriesService.save(inventory);
|
||||||
|
logger.info("成功创建商品库存: SKU ID={}, 当前库存={}", skuId, sku.getStock());
|
||||||
|
} else {
|
||||||
|
logger.info("商品库存 SKU ID={} 已存在,跳过创建", skuId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("商品库存初始化完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.qf.backend.entity.ProductCategories;
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
import com.qf.backend.entity.Products;
|
import com.qf.backend.entity.Product.Products;
|
||||||
import com.qf.backend.service.ProductCategoriesService;
|
import com.qf.backend.service.Products.ProductCategoriesService;
|
||||||
import com.qf.backend.service.ProductsService;
|
import com.qf.backend.service.Products.ProductsService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品数据初始化配置类,用于在系统启动时创建初始商品分类和商品信息
|
* 商品数据初始化配置类,用于在系统启动时创建初始商品分类和商品信息
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.qf.backend.entity.User.Roles;
|
import com.qf.backend.entity.User.Roles;
|
||||||
import com.qf.backend.service.RolesService;
|
import com.qf.backend.service.User.RolesService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色初始化配置类,用于在系统启动时创建内置角色
|
* 角色初始化配置类,用于在系统启动时创建内置角色
|
||||||
|
|||||||
188
src/main/java/com/qf/backend/inti/ShopDataInitializer.java
Normal file
188
src/main/java/com/qf/backend/inti/ShopDataInitializer.java
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
package com.qf.backend.inti;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.qf.backend.entity.Shop.ShopCategories;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
import com.qf.backend.service.Shop.ShopCategoriesService;
|
||||||
|
import com.qf.backend.service.Shop.ShopsService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺数据初始化配置类,用于在系统启动时创建店铺分类和店铺信息
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ShopDataInitializer {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ShopDataInitializer.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopCategoriesService shopCategoriesService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopsService shopsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统启动时初始化店铺数据
|
||||||
|
*/
|
||||||
|
// @PostConstruct
|
||||||
|
public void initShopData() {
|
||||||
|
logger.info("开始初始化店铺数据...");
|
||||||
|
|
||||||
|
// 初始化店铺分类
|
||||||
|
initShopCategories();
|
||||||
|
|
||||||
|
// 初始化店铺信息
|
||||||
|
initShops();
|
||||||
|
|
||||||
|
logger.info("店铺数据初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化店铺分类
|
||||||
|
*/
|
||||||
|
private void initShopCategories() {
|
||||||
|
logger.info("开始初始化店铺分类...");
|
||||||
|
|
||||||
|
// 定义初始店铺分类信息
|
||||||
|
Object[][] categoryInfos = {
|
||||||
|
// 顶级分类
|
||||||
|
{"1", "数码家电", "0", 1, "digital-appliance.jpg", 1, 1},
|
||||||
|
{"2", "服装鞋包", "0", 1, "clothing-shoes.jpg", 2, 1},
|
||||||
|
{"3", "家居生活", "0", 1, "home-living.jpg", 3, 1},
|
||||||
|
// 二级分类 - 数码家电
|
||||||
|
{"4", "手机数码", "1", 2, "phone-digital.jpg", 1, 1},
|
||||||
|
{"5", "电脑办公", "1", 2, "computer-office.jpg", 2, 1},
|
||||||
|
{"6", "家用电器", "1", 2, "home-appliance.jpg", 3, 1},
|
||||||
|
// 二级分类 - 服装鞋包
|
||||||
|
{"7", "男装", "2", 2, "men-clothing.jpg", 1, 1},
|
||||||
|
{"8", "女装", "2", 2, "women-clothing.jpg", 2, 1},
|
||||||
|
{"9", "鞋靴", "2", 2, "shoes.jpg", 3, 1},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] categoryInfo : categoryInfos) {
|
||||||
|
String categoryName = (String) categoryInfo[1]; // 第二个元素是分类名称
|
||||||
|
Long parentId = Long.valueOf((String) categoryInfo[2]); // 第三个元素是父分类ID
|
||||||
|
Integer level = (Integer) categoryInfo[3]; // 第四个元素是级别
|
||||||
|
String icon = (String) categoryInfo[4]; // 第五个元素是图标
|
||||||
|
Integer sort = (Integer) categoryInfo[5]; // 第六个元素是排序
|
||||||
|
Integer status = (Integer) categoryInfo[6]; // 第七个元素是状态
|
||||||
|
|
||||||
|
// 检查分类是否已存在
|
||||||
|
QueryWrapper<ShopCategories> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("category_name", categoryName)
|
||||||
|
.eq("parent_id", parentId);
|
||||||
|
ShopCategories existingCategory = shopCategoriesService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingCategory == null) {
|
||||||
|
// 创建新分类
|
||||||
|
ShopCategories category = new ShopCategories();
|
||||||
|
category.setCategoryName(categoryName);
|
||||||
|
category.setParentId(parentId);
|
||||||
|
category.setLevel(level);
|
||||||
|
category.setIcon(icon);
|
||||||
|
category.setSort(sort);
|
||||||
|
category.setStatus(status);
|
||||||
|
category.setCreatedAt(new Date());
|
||||||
|
category.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
shopCategoriesService.save(category);
|
||||||
|
logger.info("成功创建店铺分类: {}", categoryName);
|
||||||
|
} else {
|
||||||
|
logger.info("店铺分类 {} 已存在,跳过创建", categoryName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("店铺分类初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化店铺信息
|
||||||
|
*/
|
||||||
|
private void initShops() {
|
||||||
|
logger.info("开始初始化店铺信息...");
|
||||||
|
|
||||||
|
// 定义初始店铺信息
|
||||||
|
Object[][] shopInfos = {
|
||||||
|
{"Apple官方旗舰店", 2, 4, "apple-logo.jpg", "apple-cover.jpg", "Apple官方授权旗舰店,销售最新款Apple产品", "北京市朝阳区三里屯SOHO", "400-123-4567", "Apple客服", 4.8, 10000, 1, "business-license-1.jpg", "09:00:00", "21:00:00"},
|
||||||
|
{"华为官方旗舰店", 2, 4, "huawei-logo.jpg", "huawei-cover.jpg", "华为官方授权旗舰店,销售华为全系列产品", "上海市浦东新区陆家嘴金融中心", "400-789-0123", "华为客服", 4.7, 8000, 1, "business-license-2.jpg", "09:00:00", "21:00:00"},
|
||||||
|
{"小米官方旗舰店", 2, 4, "xiaomi-logo.jpg", "xiaomi-cover.jpg", "小米官方授权旗舰店,销售小米全系列产品", "广州市天河区天河城", "400-345-6789", "小米客服", 4.6, 7000, 1, "business-license-3.jpg", "09:00:00", "21:00:00"},
|
||||||
|
{"Nike官方旗舰店", 2, 8, "nike-logo.jpg", "nike-cover.jpg", "Nike官方授权旗舰店,销售Nike运动产品", "深圳市南山区科技园", "400-678-9012", "Nike客服", 4.5, 6000, 1, "business-license-4.jpg", "10:00:00", "22:00:00"},
|
||||||
|
{"Adidas官方旗舰店", 2, 8, "adidas-logo.jpg", "adidas-cover.jpg", "Adidas官方授权旗舰店,销售Adidas运动产品", "杭州市西湖区武林广场", "400-901-2345", "Adidas客服", 4.4, 5000, 1, "business-license-5.jpg", "10:00:00", "22:00:00"},
|
||||||
|
};
|
||||||
|
|
||||||
|
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
|
for (Object[] shopInfo : shopInfos) {
|
||||||
|
String shopName = (String) shopInfo[0];
|
||||||
|
Long userId = Long.valueOf((Integer) shopInfo[1]);
|
||||||
|
Long categoryId = Long.valueOf((Integer) shopInfo[2]);
|
||||||
|
String shopLogo = (String) shopInfo[3];
|
||||||
|
String coverImage = (String) shopInfo[4];
|
||||||
|
String description = (String) shopInfo[5];
|
||||||
|
String address = (String) shopInfo[6];
|
||||||
|
String contactPhone = (String) shopInfo[7];
|
||||||
|
String contactPerson = (String) shopInfo[8];
|
||||||
|
Double rating = (Double) shopInfo[9];
|
||||||
|
Integer salesVolume = (Integer) shopInfo[10];
|
||||||
|
Integer status = (Integer) shopInfo[11];
|
||||||
|
String businessLicense = (String) shopInfo[12];
|
||||||
|
String businessStartTimeStr = (String) shopInfo[13];
|
||||||
|
String businessEndTimeStr = (String) shopInfo[14];
|
||||||
|
|
||||||
|
// 检查店铺是否已存在
|
||||||
|
QueryWrapper<Shops> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("shop_name", shopName);
|
||||||
|
Shops existingShop = shopsService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingShop == null) {
|
||||||
|
// 创建新店铺
|
||||||
|
Shops shop = new Shops();
|
||||||
|
shop.setShopName(shopName);
|
||||||
|
shop.setUserId(userId);
|
||||||
|
shop.setCategoryId(categoryId);
|
||||||
|
shop.setShopLogo(shopLogo);
|
||||||
|
shop.setCoverImage(coverImage);
|
||||||
|
shop.setDescription(description);
|
||||||
|
shop.setAddress(address);
|
||||||
|
shop.setContactPhone(contactPhone);
|
||||||
|
shop.setContactPerson(contactPerson);
|
||||||
|
shop.setRating(new BigDecimal(Double.toString(rating)));
|
||||||
|
shop.setSalesVolume(salesVolume);
|
||||||
|
shop.setStatus(status);
|
||||||
|
shop.setBusinessLicense(businessLicense);
|
||||||
|
|
||||||
|
// 解析营业时间
|
||||||
|
try {
|
||||||
|
Date businessStartTime = timeFormat.parse(businessStartTimeStr);
|
||||||
|
Date businessEndTime = timeFormat.parse(businessEndTimeStr);
|
||||||
|
shop.setBusinessStartTime(businessStartTime);
|
||||||
|
shop.setBusinessEndTime(businessEndTime);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
logger.error("解析营业时间失败: {}", e.getMessage());
|
||||||
|
// 使用默认营业时间
|
||||||
|
shop.setBusinessStartTime(new Date());
|
||||||
|
shop.setBusinessEndTime(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.setCreatedAt(new Date());
|
||||||
|
shop.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
shopsService.save(shop);
|
||||||
|
logger.info("成功创建店铺: {}", shopName);
|
||||||
|
} else {
|
||||||
|
logger.info("店铺 {} 已存在,跳过创建", shopName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("店铺信息初始化完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.qf.backend.inti;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.qf.backend.entity.Shop.ShopRatings;
|
||||||
|
import com.qf.backend.service.Shop.ShopRatingsService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺评分数据初始化配置类,用于在系统启动时创建初始店铺评分信息
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ShopRatingsInitializer {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ShopRatingsInitializer.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopRatingsService shopRatingsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统启动时初始化店铺评分数据
|
||||||
|
*/
|
||||||
|
// @PostConstruct
|
||||||
|
public void initShopRatingsData() {
|
||||||
|
logger.info("开始初始化店铺评分数据...");
|
||||||
|
|
||||||
|
// 初始化店铺评分信息
|
||||||
|
initShopRatings();
|
||||||
|
|
||||||
|
logger.info("店铺评分数据初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化店铺评分信息
|
||||||
|
*/
|
||||||
|
private void initShopRatings() {
|
||||||
|
logger.info("开始初始化店铺评分信息...");
|
||||||
|
|
||||||
|
// 定义初始店铺评分信息
|
||||||
|
Object[][] ratingInfos = {
|
||||||
|
{1, 1, 1, 5, "商品质量很好,物流速度快,下次还会再来", "[\"rating1.jpg\",\"rating2.jpg\"]", 1},
|
||||||
|
{1, 2, 2, 4, "商品还不错,服务态度很好", "[\"rating3.jpg\"]", 1},
|
||||||
|
{1, 3, 3, 5, "非常满意的购物体验,商品超出预期", "[\"rating4.jpg\",\"rating5.jpg\",\"rating6.jpg\"]", 1},
|
||||||
|
{2, 1, 4, 3, "商品一般,物流有点慢", null, 1},
|
||||||
|
{2, 2, 5, 4, "商品质量不错,包装很严实", "[\"rating7.jpg\"]", 1},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (Object[] ratingInfo : ratingInfos) {
|
||||||
|
Long shopId = Long.valueOf((Integer) ratingInfo[0]);
|
||||||
|
Long userId = Long.valueOf((Integer) ratingInfo[1]);
|
||||||
|
Long orderId = Long.valueOf((Integer) ratingInfo[2]);
|
||||||
|
Integer rating = (Integer) ratingInfo[3];
|
||||||
|
String content = (String) ratingInfo[4];
|
||||||
|
String images = (String) ratingInfo[5];
|
||||||
|
Integer status = (Integer) ratingInfo[6];
|
||||||
|
|
||||||
|
// 检查评分是否已存在(根据店铺ID、用户ID和订单ID组合判断)
|
||||||
|
QueryWrapper<ShopRatings> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("shop_id", shopId)
|
||||||
|
.eq("user_id", userId)
|
||||||
|
.eq("order_id", orderId);
|
||||||
|
ShopRatings existingRating = shopRatingsService.getOne(queryWrapper);
|
||||||
|
|
||||||
|
if (existingRating == null) {
|
||||||
|
// 创建新评分
|
||||||
|
ShopRatings shopRating = new ShopRatings();
|
||||||
|
shopRating.setShopId(shopId);
|
||||||
|
shopRating.setUserId(userId);
|
||||||
|
shopRating.setOrderId(orderId);
|
||||||
|
shopRating.setRating(rating);
|
||||||
|
shopRating.setContent(content);
|
||||||
|
shopRating.setImages(images);
|
||||||
|
shopRating.setStatus(status);
|
||||||
|
shopRating.setCreatedAt(new Date());
|
||||||
|
shopRating.setUpdatedAt(new Date());
|
||||||
|
|
||||||
|
shopRatingsService.save(shopRating);
|
||||||
|
logger.info("成功创建店铺评分: 店铺ID={}, 用户ID={}, 评分={}星", shopId, userId, rating);
|
||||||
|
} else {
|
||||||
|
logger.info("店铺评分已存在,跳过创建: 店铺ID={}, 用户ID={}, 订单ID={}", shopId, userId, orderId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("店铺评分信息初始化完成");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,9 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.qf.backend.entity.User.Users;
|
import com.qf.backend.entity.User.Users;
|
||||||
import com.qf.backend.service.UsersService;
|
import com.qf.backend.service.User.UsersService;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户初始化配置类,用于在系统启动时创建内置用户
|
* 用户初始化配置类,用于在系统启动时创建内置用户
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Orders;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Select;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.OrderItems;
|
import com.qf.backend.entity.Order.OrderItems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单商品项表 Mapper 接口
|
* 订单商品项表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Orders;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.OrderStatusHistory;
|
import com.qf.backend.entity.Order.OrderStatusHistory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单状态历史表 Mapper 接口
|
* 订单状态历史表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Orders;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.Orders;
|
import com.qf.backend.entity.Order.Orders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单信息表 Mapper 接口
|
* 订单信息表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductAttributeValues;
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品属性值表 Mapper 接口
|
* 商品属性值表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductAttributes;
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品属性表 Mapper 接口
|
* 商品属性表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductCategories;
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品分类表 Mapper 接口
|
* 商品分类表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductImages;
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品图片表 Mapper 接口
|
* 商品图片表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductInventories;
|
import com.qf.backend.entity.Product.ProductInventories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品库存表 Mapper 接口
|
* 商品库存表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ProductSkus;
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品SKU表 Mapper 接口
|
* 商品SKU表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.Products;
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品信息表 Mapper 接口
|
* 商品信息表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Shop;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ShopCategories;
|
import com.qf.backend.entity.Shop.ShopCategories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺分类表 Mapper 接口
|
* 店铺分类表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Shop;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.ShopRatings;
|
import com.qf.backend.entity.Shop.ShopRatings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺评价表 Mapper 接口
|
* 店铺评价表 Mapper 接口
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.Shop;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.entity.Shops;
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺信息表 Mapper 接口
|
* 店铺信息表 Mapper 接口
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.mapper;
|
package com.qf.backend.mapper.User;
|
||||||
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Order;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.OrderItems;
|
import com.qf.backend.entity.Order.OrderItems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单项服务接口
|
* 订单项服务接口
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Order;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.OrderStatusHistory;
|
import com.qf.backend.entity.Order.OrderStatusHistory;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Order;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Orders;
|
import com.qf.backend.entity.Order.Orders;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单服务接口
|
* 订单服务接口
|
||||||
@@ -21,9 +21,11 @@ public interface OrdersService extends IService<Orders> {
|
|||||||
/**
|
/**
|
||||||
* 根据用户ID查询订单列表
|
* 根据用户ID查询订单列表
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 订单列表
|
* @return 订单列表
|
||||||
*/
|
*/
|
||||||
Result<List<Orders>> getOrdersByUserId(Long userId);
|
Result<List<Orders>> getOrdersByUserId(Long userId, int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建订单
|
* 创建订单
|
||||||
@@ -64,9 +66,11 @@ public interface OrdersService extends IService<Orders> {
|
|||||||
/**
|
/**
|
||||||
* 根据店铺ID查询订单
|
* 根据店铺ID查询订单
|
||||||
* @param shopId 店铺ID
|
* @param shopId 店铺ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 订单列表
|
* @return 订单列表
|
||||||
*/
|
*/
|
||||||
Result<List<Orders>> getOrdersByShopId(Long shopId);
|
Result<List<Orders>> getOrdersByShopId(Long shopId, int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新订单状态
|
* 更新订单状态
|
||||||
@@ -79,7 +83,9 @@ public interface OrdersService extends IService<Orders> {
|
|||||||
/**
|
/**
|
||||||
* 根据订单状态查询订单
|
* 根据订单状态查询订单
|
||||||
* @param status 订单状态
|
* @param status 订单状态
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 订单列表
|
* @return 订单列表
|
||||||
*/
|
*/
|
||||||
Result<List<Orders>> getOrdersByStatus(Integer status);
|
Result<List<Orders>> getOrdersByStatus(Integer status, int page, int size);
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductAttributeValues;
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品属性值服务接口
|
* 商品属性值服务接口
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductAttributes;
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductCategories;
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductImages;
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductInventories;
|
import com.qf.backend.entity.Product.ProductInventories;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductSkus;
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Products;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Products;
|
import com.qf.backend.dto.response.ProductsResponse;
|
||||||
|
import com.qf.backend.entity.Product.Products;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品服务接口
|
* 商品服务接口
|
||||||
@@ -14,16 +15,36 @@ public interface ProductsService extends IService<Products> {
|
|||||||
/**
|
/**
|
||||||
* 根据商品名称查询商品
|
* 根据商品名称查询商品
|
||||||
* @param productName 商品名称
|
* @param productName 商品名称
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 商品列表
|
* @return 商品列表
|
||||||
*/
|
*/
|
||||||
Result<List<Products>> getProductsByName(String productName);
|
Result<List<Products>> getProductsByName(String productName , int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据分类ID查询商品
|
* 根据分类ID查询商品
|
||||||
* @param categoryId 分类ID
|
* @param categoryId 分类ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 商品列表
|
* @return 商品列表
|
||||||
*/
|
*/
|
||||||
Result<List<Products>> getProductsByCategoryId(Long categoryId);
|
Result<List<Products>> getProductsByCategoryId(Long categoryId , int page, int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品ID查询商品
|
||||||
|
* @param id 商品ID
|
||||||
|
* @return 商品详情
|
||||||
|
*/
|
||||||
|
Result<ProductsResponse> getProductById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据店铺ID列表查询商品
|
||||||
|
* @param shopIds 店铺ID列表
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
|
Result<List<Products>> getProductsByShopIds(List<Long> shopIds , int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建商品
|
* 创建商品
|
||||||
@@ -46,12 +67,6 @@ public interface ProductsService extends IService<Products> {
|
|||||||
*/
|
*/
|
||||||
Result<Boolean> deleteProduct(Long id);
|
Result<Boolean> deleteProduct(Long id);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据商品ID查询商品
|
|
||||||
* @param id 商品ID
|
|
||||||
* @return 商品信息
|
|
||||||
*/
|
|
||||||
Result<Products> getProductById(Long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询商品
|
* 分页查询商品
|
||||||
@@ -61,12 +76,6 @@ public interface ProductsService extends IService<Products> {
|
|||||||
*/
|
*/
|
||||||
Result<List<Products>> listProductsByPage(int page, int size);
|
Result<List<Products>> listProductsByPage(int page, int size);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据店铺ID查询商品
|
|
||||||
* @param shopId 店铺ID
|
|
||||||
* @return 商品列表
|
|
||||||
*/
|
|
||||||
Result<List<Products>> getProductsByShopId(Long shopId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量上下架商品
|
* 批量上下架商品
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Shop;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ShopCategories;
|
import com.qf.backend.entity.Shop.ShopCategories;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Shop;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ShopRatings;
|
import com.qf.backend.entity.Shop.ShopRatings;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.Shop;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Shops;
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 店铺服务接口
|
* 店铺服务接口
|
||||||
@@ -16,7 +16,7 @@ public interface ShopsService extends IService<Shops> {
|
|||||||
* @param shopName 店铺名称
|
* @param shopName 店铺名称
|
||||||
* @return 店铺列表
|
* @return 店铺列表
|
||||||
*/
|
*/
|
||||||
Result<List<Shops>> getShopsByName(String shopName);
|
Result<List<Shops>> getShopsByName(String shopName, int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询店铺
|
* 根据用户ID查询店铺
|
||||||
@@ -64,9 +64,11 @@ public interface ShopsService extends IService<Shops> {
|
|||||||
/**
|
/**
|
||||||
* 根据店铺分类ID查询店铺
|
* 根据店铺分类ID查询店铺
|
||||||
* @param categoryId 分类ID
|
* @param categoryId 分类ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
* @return 店铺列表
|
* @return 店铺列表
|
||||||
*/
|
*/
|
||||||
Result<List<Shops>> getShopsByCategoryId(Long categoryId);
|
Result<List<Shops>> getShopsByCategoryId(Long categoryId, int page, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新店铺状态
|
* 更新店铺状态
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.entity.User.RolePermissions;
|
import com.qf.backend.entity.User.RolePermissions;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -13,10 +13,10 @@ public interface UserRolesService extends IService<UserRoles> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户ID查询用户角色关联
|
* 根据用户ID查询用户角色关联
|
||||||
* @param userId 用户ID
|
* @param userIds 用户IDs
|
||||||
* @return 用户角色关联列表
|
* @return 用户角色关联列表
|
||||||
*/
|
*/
|
||||||
Result<List<UserRoles>> getUserRolesByUserId(Long userId);
|
Result<List<UserRoles>> getUserRolesByUserId(List<Long> userIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色ID查询用户角色关联
|
* 根据角色ID查询用户角色关联
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service;
|
package com.qf.backend.service.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -21,21 +21,21 @@ public interface UsersService extends IService<Users> {
|
|||||||
* @param isUsername 是否为用户名标识(true为用户名,false为邮箱)
|
* @param isUsername 是否为用户名标识(true为用户名,false为邮箱)
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
Result<Users> getUserByIdentifier(String identifier, boolean isUsername);
|
Result<Userresponse> getUserByIdentifier(String identifier, boolean isUsername);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户名查询用户
|
* 根据用户名查询用户
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
Result<Users> getUserByUsername(String username);
|
Result<Userresponse> getUserByUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据邮箱查询用户
|
* 根据邮箱查询用户
|
||||||
* @param email 邮箱
|
* @param email 邮箱
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
Result<Users> getUserByEmail(String email);
|
Result<Userresponse> getUserByEmail(String email);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.qf.backend.service;
|
|
||||||
|
|
||||||
import com.qf.backend.dto.LoginResponse;
|
|
||||||
import com.qf.backend.dto.Result;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户登录服务接口
|
|
||||||
*/
|
|
||||||
public interface UserLoginService {
|
|
||||||
/**
|
|
||||||
* 用户登录
|
|
||||||
* @param username 用户名
|
|
||||||
* @param password 密码
|
|
||||||
* @return 登录结果,包含登录状态、token等信息
|
|
||||||
*/
|
|
||||||
Result<LoginResponse> login(String username, String password);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Orders;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -14,11 +14,11 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.OrderItems;
|
import com.qf.backend.entity.Order.OrderItems;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.OrderItemsMapper;
|
import com.qf.backend.mapper.Orders.OrderItemsMapper;
|
||||||
import com.qf.backend.service.OrderItemsService;
|
import com.qf.backend.service.Order.OrderItemsService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Orders;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.OrderStatusHistory;
|
import com.qf.backend.entity.Order.OrderStatusHistory;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.OrderStatusHistoryMapper;
|
import com.qf.backend.mapper.Orders.OrderStatusHistoryMapper;
|
||||||
import com.qf.backend.service.OrderStatusHistoryService;
|
import com.qf.backend.service.Order.OrderStatusHistoryService;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Orders;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -10,13 +10,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Orders;
|
import com.qf.backend.entity.Order.Orders;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.OrdersMapper;
|
import com.qf.backend.mapper.Orders.OrdersMapper;
|
||||||
import com.qf.backend.service.OrdersService;
|
import com.qf.backend.service.Order.OrdersService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -47,19 +48,31 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> impleme
|
|||||||
throw new BusinessException(ErrorCode.DATABASE_ERROR, "查询订单失败: " + e.getMessage(), e);
|
throw new BusinessException(ErrorCode.DATABASE_ERROR, "查询订单失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 根据用户ID查询订单列表
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 订单列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Orders>> getOrdersByUserId(Long userId) {
|
public Result<List<Orders>> getOrdersByUserId(Long userId, int page, int size) {
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (userId == null) {
|
if (userId == null || page <= 0 || size <= 0) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "用户ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "用户ID、页码和每页数量必须且大于0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Orders> ordersList = ordersMapper.selectList(
|
// 使用MyBatis-Plus的分页功能
|
||||||
|
// 构建分页查询条件
|
||||||
|
Page<Orders> ordersPage = new Page<>(page, size);
|
||||||
|
// 执行分页查询
|
||||||
|
// 分页查询用户订单
|
||||||
|
Page<Orders> pageResult = ordersMapper.selectPage(ordersPage,
|
||||||
new QueryWrapper<Orders>().eq("user_id", userId).orderByDesc("create_time")
|
new QueryWrapper<Orders>().eq("user_id", userId).orderByDesc("create_time")
|
||||||
);
|
);
|
||||||
return ResultUtils.success(ordersList);
|
return ResultUtils.success(pageResult.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -219,17 +232,22 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Orders>> getOrdersByShopId(Long shopId) {
|
public Result<List<Orders>> getOrdersByShopId(Long shopId, int page, int size) {
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (shopId == null) {
|
if (shopId == null || page <= 0 || size <= 0) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "店铺ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "店铺ID、页码和每页数量必须且大于0");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Orders> ordersList = ordersMapper.selectList(
|
// 使用MyBatis-Plus的分页功能
|
||||||
|
// 构建分页查询条件
|
||||||
|
Page<Orders> ordersPage = new Page<>(page, size);
|
||||||
|
// 执行分页查询
|
||||||
|
// 分页查询店铺订单
|
||||||
|
Page<Orders> pageResult = ordersMapper.selectPage(ordersPage,
|
||||||
new QueryWrapper<Orders>().eq("shop_id", shopId).orderByDesc("create_time")
|
new QueryWrapper<Orders>().eq("shop_id", shopId).orderByDesc("create_time")
|
||||||
);
|
);
|
||||||
return ResultUtils.success(ordersList);
|
return ResultUtils.success(pageResult.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -280,17 +298,22 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Orders>> getOrdersByStatus(Integer status) {
|
public Result<List<Orders>> getOrdersByStatus(Integer status, int page, int size) {
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (status == null) {
|
if (status == null || page <= 0 || size <= 0) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "订单状态不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "订单状态和页码必须且大于0");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Orders> ordersList = ordersMapper.selectList(
|
// 使用MyBatis-Plus的分页功能
|
||||||
new QueryWrapper<Orders>().eq("status", status).orderByDesc("create_time")
|
// 构建分页查询条件
|
||||||
|
Page<Orders> ordersPage = new Page<>(page, size);
|
||||||
|
// 执行分页查询
|
||||||
|
// 分页查询订单
|
||||||
|
Page<Orders> pageResult = ordersMapper.selectPage(ordersPage,
|
||||||
|
new QueryWrapper<Orders>().eq("order_status", status).orderByDesc("create_time")
|
||||||
);
|
);
|
||||||
return ResultUtils.success(ordersList);
|
return ResultUtils.success(pageResult.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -8,11 +8,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductAttributeValues;
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductAttributeValuesMapper;
|
import com.qf.backend.mapper.Products.ProductAttributeValuesMapper;
|
||||||
import com.qf.backend.service.ProductAttributeValuesService;
|
import com.qf.backend.service.Products.ProductAttributeValuesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductAttributes;
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductAttributesMapper;
|
import com.qf.backend.mapper.Products.ProductAttributesMapper;
|
||||||
import com.qf.backend.service.ProductAttributesService;
|
import com.qf.backend.service.Products.ProductAttributesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品属性服务实现类
|
* 商品属性服务实现类
|
||||||
@@ -1,20 +1,21 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductCategories;
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductCategoriesMapper;
|
import com.qf.backend.mapper.Products.ProductCategoriesMapper;
|
||||||
import com.qf.backend.service.ProductCategoriesService;
|
import com.qf.backend.service.Products.ProductCategoriesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品分类服务实现类
|
* 商品分类服务实现类
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,11 +11,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductImages;
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductImagesMapper;
|
import com.qf.backend.mapper.Products.ProductImagesMapper;
|
||||||
import com.qf.backend.service.ProductImagesService;
|
import com.qf.backend.service.Products.ProductImagesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductInventories;
|
import com.qf.backend.entity.Product.ProductInventories;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductInventoriesMapper;
|
import com.qf.backend.mapper.Products.ProductInventoriesMapper;
|
||||||
import com.qf.backend.service.ProductInventoriesService;
|
import com.qf.backend.service.Products.ProductInventoriesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ProductSkus;
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductSkusMapper;
|
import com.qf.backend.mapper.Products.ProductSkusMapper;
|
||||||
import com.qf.backend.service.ProductSkusService;
|
import com.qf.backend.service.Products.ProductSkusService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Products;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -9,11 +9,24 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Products;
|
import com.qf.backend.dto.response.ProductsResponse;
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||||
|
import com.qf.backend.entity.Product.ProductAttributes;
|
||||||
|
import com.qf.backend.entity.Product.ProductCategories;
|
||||||
|
import com.qf.backend.entity.Product.ProductImages;
|
||||||
|
import com.qf.backend.entity.Product.ProductSkus;
|
||||||
|
import com.qf.backend.entity.Product.Products;
|
||||||
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ProductsMapper;
|
import com.qf.backend.mapper.Products.ProductsMapper;
|
||||||
import com.qf.backend.service.ProductsService;
|
import com.qf.backend.service.Products.ProductAttributeValuesService;
|
||||||
|
import com.qf.backend.service.Products.ProductAttributesService;
|
||||||
|
import com.qf.backend.service.Products.ProductCategoriesService;
|
||||||
|
import com.qf.backend.service.Products.ProductImagesService;
|
||||||
|
import com.qf.backend.service.Products.ProductSkusService;
|
||||||
|
import com.qf.backend.service.Products.ProductsService;
|
||||||
|
import com.qf.backend.service.Shop.ShopsService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -25,16 +38,43 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProductsMapper productsMapper;
|
private ProductsMapper productsMapper;
|
||||||
|
@Autowired
|
||||||
|
private ShopsService shopsService;
|
||||||
|
@Autowired
|
||||||
|
private ProductCategoriesService categoriesService;
|
||||||
|
@Autowired
|
||||||
|
private ProductAttributesService attributesService;
|
||||||
|
@Autowired
|
||||||
|
private ProductAttributeValuesService attributeValuesService;
|
||||||
|
@Autowired
|
||||||
|
private ProductSkusService skusService;
|
||||||
|
@Autowired
|
||||||
|
private ProductImagesService imagesService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品名称查询商品列表
|
||||||
|
*
|
||||||
|
* @param productName 商品名称
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Products>> getProductsByName(String productName) {
|
public Result<List<Products>> getProductsByName(String productName, int page, int size) {
|
||||||
if (ValidateUtil.isEmpty(productName)) {
|
if (ValidateUtil.isEmpty(productName)) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "商品名称不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "商品名称不能为空");
|
||||||
}
|
}
|
||||||
|
if (page < 1) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "页码不能小于1");
|
||||||
|
}
|
||||||
|
if (size < 1 || size > 100) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "每页数量必须在1-100之间");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Products> products = productsMapper.selectList(
|
Page<Products> productPage = new Page<>(page, size);
|
||||||
new QueryWrapper<Products>().like("product_name", productName));
|
Page<Products> resultPage = productsMapper.selectPage(productPage, new QueryWrapper<Products>().like("product_name", productName));
|
||||||
return ResultUtils.success(products);
|
return ResultUtils.success(resultPage.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -42,15 +82,29 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类ID查询商品列表
|
||||||
|
*
|
||||||
|
* @param categoryId 分类ID
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Products>> getProductsByCategoryId(Long categoryId) {
|
public Result<List<Products>> getProductsByCategoryId(Long categoryId, int page, int size) {
|
||||||
if (ValidateUtil.isEmpty(categoryId)) {
|
if (ValidateUtil.isEmpty(categoryId)) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "分类ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "分类ID不能为空");
|
||||||
}
|
}
|
||||||
|
if (page < 1) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "页码不能小于1");
|
||||||
|
}
|
||||||
|
if (size < 1 || size > 100) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "每页数量必须在1-100之间");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
List<Products> products = productsMapper.selectList(
|
Page<Products> productPage = new Page<>(page, size);
|
||||||
new QueryWrapper<Products>().eq("category_id", categoryId));
|
Page<Products> resultPage = productsMapper.selectPage(productPage, new QueryWrapper<Products>().eq("category_id", categoryId));
|
||||||
return ResultUtils.success(products);
|
return ResultUtils.success(resultPage.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -58,6 +112,12 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建商品
|
||||||
|
*
|
||||||
|
* @param products 商品信息
|
||||||
|
* @return 创建结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> createProduct(Products products) {
|
public Result<Boolean> createProduct(Products products) {
|
||||||
if (ValidateUtil.isEmpty(products)) {
|
if (ValidateUtil.isEmpty(products)) {
|
||||||
@@ -85,6 +145,12 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新商品信息
|
||||||
|
*
|
||||||
|
* @param products 商品信息
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> updateProduct(Products products) {
|
public Result<Boolean> updateProduct(Products products) {
|
||||||
if (ValidateUtil.isEmpty(products)) {
|
if (ValidateUtil.isEmpty(products)) {
|
||||||
@@ -111,6 +177,12 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除商品
|
||||||
|
*
|
||||||
|
* @param id 商品ID
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> deleteProduct(Long id) {
|
public Result<Boolean> deleteProduct(Long id) {
|
||||||
if (ValidateUtil.isEmpty(id)) {
|
if (ValidateUtil.isEmpty(id)) {
|
||||||
@@ -131,8 +203,14 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品ID查询商品详情 (包含关联分类信息和店铺信息 )
|
||||||
|
*
|
||||||
|
* @param id 商品ID
|
||||||
|
* @return 商品详情
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<Products> getProductById(Long id) {
|
public Result<ProductsResponse> getProductById(Long id) {
|
||||||
if (ValidateUtil.isEmpty(id)) {
|
if (ValidateUtil.isEmpty(id)) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "商品ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "商品ID不能为空");
|
||||||
}
|
}
|
||||||
@@ -141,7 +219,9 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
if (product == null) {
|
if (product == null) {
|
||||||
throw new BusinessException(ErrorCode.NOT_FOUND, "商品不存在");
|
throw new BusinessException(ErrorCode.NOT_FOUND, "商品不存在");
|
||||||
}
|
}
|
||||||
return ResultUtils.success(product);
|
// 获取商品详情
|
||||||
|
ProductsResponse productsResponse = getProductDetail(product);
|
||||||
|
return ResultUtils.success(productsResponse);
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -149,6 +229,13 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询商品列表
|
||||||
|
*
|
||||||
|
* @param page 页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Products>> listProductsByPage(int page, int size) {
|
public Result<List<Products>> listProductsByPage(int page, int size) {
|
||||||
if (page < 1) {
|
if (page < 1) {
|
||||||
@@ -168,22 +255,43 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据店铺ID列表查询商品列表
|
||||||
|
*
|
||||||
|
* @param shopIds 店铺ID列表
|
||||||
|
* @param page 当前页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Products>> getProductsByShopId(Long shopId) {
|
public Result<List<Products>> getProductsByShopIds(List<Long> shopIds, int page, int size) {
|
||||||
if (ValidateUtil.isEmpty(shopId)) {
|
if (ValidateUtil.isEmpty(shopIds)) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "店铺ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "店铺ID列表不能为空");
|
||||||
|
}
|
||||||
|
if (page < 1) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "页码不能小于1");
|
||||||
|
}
|
||||||
|
if (size < 1 || size > 100) {
|
||||||
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "每页数量必须在1-100之间");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
List<Products> products = productsMapper.selectList(
|
Page<Products> productPage = new Page<>(page, size);
|
||||||
new QueryWrapper<Products>().eq("shop_id", shopId));
|
Page<Products> resultPage = productsMapper.selectPage(productPage, new QueryWrapper<Products>().in("shop_id", shopIds));
|
||||||
return ResultUtils.success(products);
|
return ResultUtils.success(resultPage.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new BusinessException(ErrorCode.DATABASE_ERROR, "查询商品失败", e);
|
throw new BusinessException(ErrorCode.DATABASE_ERROR, "分页查询商品失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新商品状态
|
||||||
|
*
|
||||||
|
* @param ids 商品ID列表
|
||||||
|
* @param status 商品状态
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<Boolean> batchUpdateProductStatus(List<Long> ids, Integer status) {
|
public Result<Boolean> batchUpdateProductStatus(List<Long> ids, Integer status) {
|
||||||
if (ValidateUtil.isEmpty(ids)) {
|
if (ValidateUtil.isEmpty(ids)) {
|
||||||
@@ -221,6 +329,14 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索商品
|
||||||
|
*
|
||||||
|
* @param keyword 搜索关键词
|
||||||
|
* @param page 页码
|
||||||
|
* @param size 每页数量
|
||||||
|
* @return 商品列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Products>> searchProducts(String keyword, int page, int size) {
|
public Result<List<Products>> searchProducts(String keyword, int page, int size) {
|
||||||
if (ValidateUtil.isEmpty(keyword)) {
|
if (ValidateUtil.isEmpty(keyword)) {
|
||||||
@@ -245,4 +361,67 @@ public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products> i
|
|||||||
throw new BusinessException(ErrorCode.DATABASE_ERROR, "搜索商品失败", e);
|
throw new BusinessException(ErrorCode.DATABASE_ERROR, "搜索商品失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据商品查询对应的分类信息和店铺信息 (包含关联分类信息和店铺信息 )
|
||||||
|
*
|
||||||
|
* @param product 商品信息
|
||||||
|
* @return 商品详情
|
||||||
|
*/
|
||||||
|
public ProductsResponse getProductDetail(Products product) {
|
||||||
|
// 验证参数
|
||||||
|
if (product == null || product.getId() == null) {
|
||||||
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "商品ID不能为空");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 创建商品详情对象
|
||||||
|
ProductsResponse productsResponse = new ProductsResponse();
|
||||||
|
// 提取商品id信息
|
||||||
|
Long productId = product.getId();
|
||||||
|
|
||||||
|
// 1. 查询商品基本信息
|
||||||
|
Products products = productsMapper.selectById(productId);
|
||||||
|
if (products == null) {
|
||||||
|
throw new BusinessException(ErrorCode.NOT_FOUND, "商品不存在");
|
||||||
|
}
|
||||||
|
productsResponse.setProducts(products);
|
||||||
|
|
||||||
|
// 2. 根据商品的shopId查询店铺信息
|
||||||
|
if (products.getShopId() != null) {
|
||||||
|
Shops shop = shopsService.getShopById(products.getShopId()).getData();
|
||||||
|
productsResponse.setShop(shop);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 根据商品的categoryId查询分类信息
|
||||||
|
if (products.getCategoryId() != null) {
|
||||||
|
ProductCategories category = categoriesService.getCategoryById(products.getCategoryId()).getData();
|
||||||
|
productsResponse.setCategory(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 查询商品属性信息
|
||||||
|
List<ProductAttributes> attributes = attributesService.list(new QueryWrapper<ProductAttributes>()
|
||||||
|
.eq("category_id", products.getCategoryId()));
|
||||||
|
productsResponse.setAttributes(attributes);
|
||||||
|
|
||||||
|
// 5. 查询商品属性值信息
|
||||||
|
List<ProductAttributeValues> attributeValues = attributeValuesService
|
||||||
|
.list(new QueryWrapper<ProductAttributeValues>()
|
||||||
|
.eq("product_id", productId));
|
||||||
|
productsResponse.setAttributeValuesList(attributeValues);
|
||||||
|
|
||||||
|
// 6. 查询商品SKU信息
|
||||||
|
List<ProductSkus> productSkus = skusService.list(new QueryWrapper<ProductSkus>()
|
||||||
|
.eq("product_id", productId));
|
||||||
|
productsResponse.setProductSkus(productSkus);
|
||||||
|
|
||||||
|
// 7. 查询商品图片信息
|
||||||
|
List<ProductImages> productImages = imagesService.list(new QueryWrapper<ProductImages>()
|
||||||
|
.eq("product_id", productId));
|
||||||
|
productsResponse.setProductImages(productImages);
|
||||||
|
|
||||||
|
return productsResponse;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(ErrorCode.DATABASE_ERROR, "查询商品详情失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Shop;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,11 +10,11 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ShopCategories;
|
import com.qf.backend.entity.Shop.ShopCategories;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ShopCategoriesMapper;
|
import com.qf.backend.mapper.Shop.ShopCategoriesMapper;
|
||||||
import com.qf.backend.service.ShopCategoriesService;
|
import com.qf.backend.service.Shop.ShopCategoriesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Shop;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,11 +11,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.ShopRatings;
|
import com.qf.backend.entity.Shop.ShopRatings;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ShopRatingsMapper;
|
import com.qf.backend.mapper.Shop.ShopRatingsMapper;
|
||||||
import com.qf.backend.service.ShopRatingsService;
|
import com.qf.backend.service.Shop.ShopRatingsService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.Shop;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,14 +11,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.entity.Shops;
|
import com.qf.backend.entity.Shop.Shops;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.ShopsMapper;
|
import com.qf.backend.mapper.Shop.ShopsMapper;
|
||||||
import com.qf.backend.service.ShopsService;
|
import com.qf.backend.service.Shop.ShopsService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 店铺服务实现类
|
||||||
|
* @author 30803
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements ShopsService {
|
public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements ShopsService {
|
||||||
|
|
||||||
@@ -29,18 +34,18 @@ public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements
|
|||||||
|
|
||||||
// 根据店铺名称查询店铺
|
// 根据店铺名称查询店铺
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Shops>> getShopsByName(String shopName) {
|
public Result<List<Shops>> getShopsByName(String shopName, int page, int size) {
|
||||||
logger.info("根据店铺名称查询店铺: {}", shopName);
|
logger.info("根据店铺名称查询店铺: {}, 当前页码: {}, 每页数量: {}", shopName, page, size);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ValidateUtil.isEmpty(shopName)) {
|
if (ValidateUtil.isEmpty(shopName)) {
|
||||||
throw new BusinessException(ErrorCode.INVALID_PARAM, "店铺名称不能为空");
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "店铺名称不能为空");
|
||||||
}
|
}
|
||||||
|
// 构建分页查询条件
|
||||||
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().like("shop_name", shopName);
|
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().like("shop_name", shopName);
|
||||||
List<Shops> shopsList = shopsMapper.selectList(queryWrapper);
|
Page<Shops> shopsList = shopsMapper.selectPage(new Page<>(page, size), queryWrapper);
|
||||||
logger.info("查询到 {} 个店铺", shopsList.size());
|
logger.info("查询到 {} 个店铺", shopsList.getTotal());
|
||||||
return ResultUtils.success(shopsList);
|
return ResultUtils.success(shopsList.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -186,9 +191,9 @@ public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements
|
|||||||
|
|
||||||
Shops shop = getShopByIdAndCheckExist(id);
|
Shops shop = getShopByIdAndCheckExist(id);
|
||||||
if (shop == null) {
|
if (shop == null) {
|
||||||
throw new BusinessException(ErrorCode.SHOP_NOT_FOUND, "店铺不存在");
|
throw new BusinessException(ErrorCode.SHOP_NOT_FOUND, "店铺不存在: 店铺ID = " + id);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
return ResultUtils.success(shop);
|
return ResultUtils.success(shop);
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -228,18 +233,17 @@ public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements
|
|||||||
|
|
||||||
// 根据店铺分类ID查询店铺
|
// 根据店铺分类ID查询店铺
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Shops>> getShopsByCategoryId(Long categoryId) {
|
public Result<List<Shops>> getShopsByCategoryId(Long categoryId, int page, int size) {
|
||||||
logger.info("根据店铺分类ID查询店铺: 分类ID = {}", categoryId);
|
logger.info("根据店铺分类ID查询店铺: 分类ID = {}", categoryId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (categoryId == null) {
|
if (categoryId == null) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "分类ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "分类ID不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().eq("category_id", categoryId);
|
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().eq("category_id", categoryId);
|
||||||
List<Shops> shopsList = shopsMapper.selectList(queryWrapper);
|
Page<Shops> shopsList = shopsMapper.selectPage(new Page<>(page, size), queryWrapper);
|
||||||
logger.info("查询到 {} 个店铺", shopsList.size());
|
logger.info("查询到 {} 个店铺", shopsList.getTotal());
|
||||||
return ResultUtils.success(shopsList);
|
return ResultUtils.success(shopsList.getRecords());
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -331,5 +335,4 @@ public class ShopsServiceImpl extends ServiceImpl<ShopsMapper, Shops> implements
|
|||||||
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().eq("id", id);
|
QueryWrapper<Shops> queryWrapper = new QueryWrapper<Shops>().eq("id", id);
|
||||||
return shopsMapper.selectOne(queryWrapper);
|
return shopsMapper.selectOne(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -13,8 +13,8 @@ import com.qf.backend.dto.Result;
|
|||||||
import com.qf.backend.entity.User.Permissions;
|
import com.qf.backend.entity.User.Permissions;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.PermissionsMapper;
|
import com.qf.backend.mapper.User.PermissionsMapper;
|
||||||
import com.qf.backend.service.PermissionsService;
|
import com.qf.backend.service.User.PermissionsService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qf.backend.entity.User.RolePermissions;
|
import com.qf.backend.entity.User.RolePermissions;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.RolePermissionsMapper;
|
import com.qf.backend.mapper.User.RolePermissionsMapper;
|
||||||
import com.qf.backend.service.RolePermissionsService;
|
import com.qf.backend.service.User.RolePermissionsService;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色权限关联服务实现类
|
* 角色权限关联服务实现类
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@ import com.qf.backend.dto.Result;
|
|||||||
import com.qf.backend.entity.User.Roles;
|
import com.qf.backend.entity.User.Roles;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.RolesMapper;
|
import com.qf.backend.mapper.User.RolesMapper;
|
||||||
import com.qf.backend.service.RolesService;
|
import com.qf.backend.service.User.RolesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -6,19 +6,19 @@ import java.util.List;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.User;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
|
import com.qf.backend.dto.response.Userresponse;
|
||||||
|
import com.qf.backend.entity.User.CustomUserDetails;
|
||||||
import com.qf.backend.entity.User.Roles;
|
import com.qf.backend.entity.User.Roles;
|
||||||
import com.qf.backend.entity.User.UserRoles;
|
import com.qf.backend.entity.User.UserRoles;
|
||||||
import com.qf.backend.entity.User.Users;
|
import com.qf.backend.service.User.RolesService;
|
||||||
import com.qf.backend.service.RolesService;
|
import com.qf.backend.service.User.UserRolesService;
|
||||||
import com.qf.backend.service.UserRolesService;
|
import com.qf.backend.service.User.UsersService;
|
||||||
import com.qf.backend.service.UsersService;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -48,19 +48,18 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
|||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
// 1. 从数据库中查询用户
|
// 1. 从数据库中查询用户
|
||||||
Result<Users> result = usersService.getUserByUsername(username);
|
Result<Userresponse> result = usersService.getUserByUsername(username);
|
||||||
if (result == null || result.getData() == null) {
|
if (result == null || result.getData() == null) {
|
||||||
throw new UsernameNotFoundException("用户名不存在: " + username);
|
throw new UsernameNotFoundException("用户名不存在: " + username);
|
||||||
}
|
}
|
||||||
|
Userresponse user = result.getData();
|
||||||
Users user = result.getData();
|
|
||||||
|
|
||||||
// 2. 构建权限列表(这里简化处理,实际应从数据库中查询用户的角色和权限)
|
// 2. 构建权限列表(这里简化处理,实际应从数据库中查询用户的角色和权限)
|
||||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
List<GrantedAuthority> authorities = new ArrayList<>();
|
||||||
// 查询用户角色关联
|
// 查询用户角色关联
|
||||||
Result<List<UserRoles>> userRoleResultList = userRolesService.getUserRolesByUserId(user.getId());
|
Result<List<UserRoles>> userRoleResultList = userRolesService.getUserRolesByUserId(List.of(user.getUsers().getId()));
|
||||||
if (userRoleResultList == null || userRoleResultList.getData() == null) {
|
if (userRoleResultList == null || userRoleResultList.getData() == null) {
|
||||||
throw new UsernameNotFoundException("用户角色不存在: " + user.getId());
|
throw new UsernameNotFoundException("用户角色不存在: " + user.getUsers().getId());
|
||||||
}
|
}
|
||||||
// 3. 查询角色权限
|
// 3. 查询角色权限
|
||||||
for (UserRoles userRole : userRoleResultList.getData()) {
|
for (UserRoles userRole : userRoleResultList.getData()) {
|
||||||
@@ -74,14 +73,15 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
|||||||
}
|
}
|
||||||
// 3. 返回UserDetails对象
|
// 3. 返回UserDetails对象
|
||||||
// 注意:在实际应用中,密码应该加密存储,这里直接使用明文密码(仅用于演示)
|
// 注意:在实际应用中,密码应该加密存储,这里直接使用明文密码(仅用于演示)
|
||||||
return User.builder()
|
return new CustomUserDetails(
|
||||||
.username(user.getUsername()) // 用户名
|
user.getUsers().getId(), // 👈 传入 ID
|
||||||
.password(user.getPassword()) // 密码需要加密存储,这里直接使用明文密码(仅用于演示)
|
user.getUsers().getUsername(), // 用户名
|
||||||
.authorities(authorities) // 假设用户默认拥有USER权限
|
user.getUsers().getPassword(), // 必须是加密后的密码!
|
||||||
.accountExpired(false) // 假设账号永不过期
|
authorities, // 权限列表
|
||||||
.accountLocked(false) // 假设账号永不过期
|
user.getUsers().getStatus() != 0, // enabled: status=0 表示禁用
|
||||||
.credentialsExpired(false) // 假设密码永不过期
|
true, // accountNonExpired 账号未过期
|
||||||
.disabled(user.getStatus() == 0) // 假设status为0表示禁用
|
true, // accountNonLocked 账号未锁定
|
||||||
.build();
|
true // credentialsNonExpired 凭证未过期
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -17,8 +17,8 @@ import com.qf.backend.dto.Result;
|
|||||||
import com.qf.backend.entity.User.UserRoles;
|
import com.qf.backend.entity.User.UserRoles;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.UserRolesMapper;
|
import com.qf.backend.mapper.User.UserRolesMapper;
|
||||||
import com.qf.backend.service.UserRolesService;
|
import com.qf.backend.service.User.UserRolesService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
|
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ public class UsersRolesServiceImpl extends ServiceImpl<UserRolesMapper, UserRole
|
|||||||
private UserRolesMapper userRolesMapper;
|
private UserRolesMapper userRolesMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<UserRoles>> getUserRolesByUserId(Long userId) {
|
public Result<List<UserRoles>> getUserRolesByUserId(List<Long> userIds) {
|
||||||
if (userId == null) {
|
if (userIds == null || userIds.isEmpty()) {
|
||||||
throw new BusinessException(ErrorCode.MISSING_PARAM, "用户ID不能为空");
|
throw new BusinessException(ErrorCode.MISSING_PARAM, "用户ID列表不能为空");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
List<UserRoles> userRoles = userRolesMapper.selectList(new QueryWrapper<UserRoles>().eq("user_id", userId));
|
List<UserRoles> userRoles = userRolesMapper.selectList(new QueryWrapper<UserRoles>().in("user_id", userIds));
|
||||||
return ResultUtils.success(userRoles);
|
return ResultUtils.success(userRoles);
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -87,7 +87,7 @@ public class UsersRolesServiceImpl extends ServiceImpl<UserRolesMapper, UserRole
|
|||||||
return ResultUtils.success(result > 0);
|
return ResultUtils.success(result > 0);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 更新用户ID关联的角色
|
* 更新用户ID关联的角色 (是否有用存疑)
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @param roleId 角色ID
|
* @param roleId 角色ID
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -21,15 +21,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||||||
import com.qf.backend.dto.Result;
|
import com.qf.backend.dto.Result;
|
||||||
import com.qf.backend.dto.request.PageRequest;
|
import com.qf.backend.dto.request.PageRequest;
|
||||||
import com.qf.backend.dto.response.Userresponse;
|
import com.qf.backend.dto.response.Userresponse;
|
||||||
|
import com.qf.backend.entity.User.Permissions;
|
||||||
|
import com.qf.backend.entity.User.RolePermissions;
|
||||||
import com.qf.backend.entity.User.Roles;
|
import com.qf.backend.entity.User.Roles;
|
||||||
import com.qf.backend.entity.User.UserRoles;
|
import com.qf.backend.entity.User.UserRoles;
|
||||||
import com.qf.backend.entity.User.Users;
|
import com.qf.backend.entity.User.Users;
|
||||||
import com.qf.backend.exception.BusinessException;
|
import com.qf.backend.exception.BusinessException;
|
||||||
import com.qf.backend.exception.ErrorCode;
|
import com.qf.backend.exception.ErrorCode;
|
||||||
import com.qf.backend.mapper.RolesMapper;
|
import com.qf.backend.mapper.User.UsersMapper;
|
||||||
import com.qf.backend.mapper.UsersMapper;
|
import com.qf.backend.service.User.PermissionsService;
|
||||||
import com.qf.backend.service.UserRolesService;
|
import com.qf.backend.service.User.RolePermissionsService;
|
||||||
import com.qf.backend.service.UsersService;
|
import com.qf.backend.service.User.RolesService;
|
||||||
|
import com.qf.backend.service.User.UserRolesService;
|
||||||
|
import com.qf.backend.service.User.UsersService;
|
||||||
import com.qf.backend.util.ResultUtils;
|
import com.qf.backend.util.ResultUtils;
|
||||||
import com.qf.backend.util.ValidateUtil;
|
import com.qf.backend.util.ValidateUtil;
|
||||||
|
|
||||||
@@ -43,13 +47,15 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserRolesService userRolesService;
|
private UserRolesService userRolesService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RolesMapper rolesMapper;
|
private RolesService rolesService;
|
||||||
|
@Autowired
|
||||||
|
private RolePermissionsService rolePermissionsService;
|
||||||
|
@Autowired
|
||||||
|
private PermissionsService permissionsService;
|
||||||
|
|
||||||
// 根据用户名或邮箱查询用户(通用方法)
|
// 根据用户名或邮箱查询用户(通用方法)
|
||||||
@Override
|
@Override
|
||||||
public Result<Users> getUserByIdentifier(String identifier, boolean isUsername) {
|
public Result<Userresponse> getUserByIdentifier(String identifier, boolean isUsername) {
|
||||||
logger.info(isUsername ? "根据用户名查询用户: {}" : "根据邮箱查询用户: {}", identifier);
|
logger.info(isUsername ? "根据用户名查询用户: {}" : "根据邮箱查询用户: {}", identifier);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -64,13 +70,15 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
|||||||
|
|
||||||
// 根据标识符类型调用不同的查询方法
|
// 根据标识符类型调用不同的查询方法
|
||||||
Users users = isUsername
|
Users users = isUsername
|
||||||
? usersMapper.selectByUsername(identifier)
|
? usersMapper.selectByUsername(identifier)
|
||||||
: usersMapper.selectByEmail(identifier);
|
: usersMapper.selectByEmail(identifier);
|
||||||
|
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
throw new BusinessException(ErrorCode.USER_NOT_FOUND, "用户不存在: " + identifier);
|
throw new BusinessException(ErrorCode.USER_NOT_FOUND, "用户不存在: " + identifier);
|
||||||
}
|
}
|
||||||
return ResultUtils.success(users);
|
Userresponse userresponse = getUserPermissionsMap(Collections.singletonList(users)).get(0);
|
||||||
|
|
||||||
|
return ResultUtils.success(userresponse);
|
||||||
} catch (BusinessException e) {
|
} catch (BusinessException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -81,13 +89,13 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
|||||||
|
|
||||||
// 根据用户名查询用户
|
// 根据用户名查询用户
|
||||||
@Override
|
@Override
|
||||||
public Result<Users> getUserByUsername(String username) {
|
public Result<Userresponse> getUserByUsername(String username) {
|
||||||
return getUserByIdentifier(username, true);
|
return getUserByIdentifier(username, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据邮箱查询用户
|
// 根据邮箱查询用户
|
||||||
@Override
|
@Override
|
||||||
public Result<Users> getUserByEmail(String email) {
|
public Result<Userresponse> getUserByEmail(String email) {
|
||||||
return getUserByIdentifier(email, false);
|
return getUserByIdentifier(email, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,47 +267,12 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
|||||||
throw new BusinessException(ErrorCode.INVALID_PARAM, "每页大小必须在1-100之间");
|
throw new BusinessException(ErrorCode.INVALID_PARAM, "每页大小必须在1-100之间");
|
||||||
}
|
}
|
||||||
// 使用MyBatis-Plus的分页功能
|
// 使用MyBatis-Plus的分页功能
|
||||||
|
// 构建分页查询条件
|
||||||
Page<Users> userPage = new Page<>(pageRequest.getPage(), pageRequest.getSize());
|
Page<Users> userPage = new Page<>(pageRequest.getPage(), pageRequest.getSize());
|
||||||
|
// 执行分页查询
|
||||||
Page<Users> resultPage = usersMapper.selectPage(userPage, null);
|
Page<Users> resultPage = usersMapper.selectPage(userPage, null);
|
||||||
// 1. 获取当前页所有用户
|
// 转换为响应DTO
|
||||||
List<Users> userList = resultPage.getRecords();
|
List<Userresponse> userResponseList = getUserPermissionsMap(resultPage.getRecords());
|
||||||
// 2. 提取所有用户ID
|
|
||||||
List<Long> userIds = userList.stream().map(Users::getId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
// 3. 一次性查询所有用户-角色关联
|
|
||||||
List<UserRoles> userRolesList = userRolesService.list(new QueryWrapper<UserRoles>()
|
|
||||||
.in("user_id", userIds));
|
|
||||||
|
|
||||||
// 4. 提取所有角色ID
|
|
||||||
List<Long> roleIds = userRolesList.stream().map(UserRoles::getRoleId).collect(Collectors.toList());
|
|
||||||
|
|
||||||
// 5. 一次性查询所有角色信息
|
|
||||||
List<Roles> rolesList = rolesMapper.selectList(new QueryWrapper<Roles>()
|
|
||||||
.in("id", roleIds));
|
|
||||||
|
|
||||||
// 6. 构建角色映射,按角色ID分组
|
|
||||||
Map<Long, Roles> roleMap = rolesList.stream()
|
|
||||||
.collect(Collectors.toMap(Roles::getId, role -> role));
|
|
||||||
|
|
||||||
// 7. 构建用户-角色列表映射
|
|
||||||
Map<Long, List<Roles>> userRoleMap = new HashMap<>();
|
|
||||||
for (UserRoles userRole : userRolesList) {
|
|
||||||
Long userId = userRole.getUserId();
|
|
||||||
Roles role = roleMap.get(userRole.getRoleId());
|
|
||||||
if (role != null) {
|
|
||||||
userRoleMap.computeIfAbsent(userId, k -> new ArrayList<>())
|
|
||||||
.add(role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8. 构建响应DTO
|
|
||||||
List<Userresponse> userResponseList = userList.stream().map(user -> {
|
|
||||||
Userresponse response = new Userresponse();
|
|
||||||
response.setUsers(user);
|
|
||||||
// 从Map中取角色,避免空指针
|
|
||||||
response.setRoles(userRoleMap.getOrDefault(user.getId(), Collections.emptyList()));
|
|
||||||
return response;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
logger.info("分页查询成功: 共 {} 条记录, 第 {} 页", resultPage.getTotal(), pageRequest.getPage());
|
logger.info("分页查询成功: 共 {} 条记录, 第 {} 页", resultPage.getTotal(), pageRequest.getPage());
|
||||||
return ResultUtils.success(userResponseList);
|
return ResultUtils.success(userResponseList);
|
||||||
@@ -394,4 +367,68 @@ public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements
|
|||||||
return usersMapper.selectOne(queryWrapper);
|
return usersMapper.selectOne(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户列表获取用户权限信息
|
||||||
|
* @param users 用户列表
|
||||||
|
* @return Userresponse 包含用户权限信息的列表
|
||||||
|
*/
|
||||||
|
private List<Userresponse> getUserPermissionsMap(List<Users> users) {
|
||||||
|
// 1. 获取当前页所有用户
|
||||||
|
List<Users> userList = users;
|
||||||
|
// 2. 提取所有用户ID
|
||||||
|
List<Long> userIds = userList.stream().map(Users::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 3. 一次性查询所有用户-角色关联
|
||||||
|
List<UserRoles> userRolesList = userRolesService.list(new QueryWrapper<UserRoles>()
|
||||||
|
.in("user_id", userIds));
|
||||||
|
|
||||||
|
// 4. 提取所有角色ID
|
||||||
|
List<Long> roleIds = userRolesList.stream().map(UserRoles::getRoleId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 5. 一次性查询所有角色-权限关联
|
||||||
|
List<RolePermissions> rolePermissionsList = rolePermissionsService.list(new QueryWrapper<RolePermissions>()
|
||||||
|
.in("role_id", roleIds));
|
||||||
|
|
||||||
|
// 6. 提取所有权限ID
|
||||||
|
List<Long> permissionIds = rolePermissionsList.stream().map(RolePermissions::getPermissionId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 7. 一次性查询所有权限信息
|
||||||
|
List<Permissions> permissionsList = permissionsService.list(new QueryWrapper<Permissions>()
|
||||||
|
.in("id", permissionIds));
|
||||||
|
|
||||||
|
// 7. 构建权限映射,按权限ID分组
|
||||||
|
Map<Long, Permissions> permissionMap = permissionsList.stream()
|
||||||
|
.collect(Collectors.toMap(Permissions::getId, permission -> permission));
|
||||||
|
|
||||||
|
// 8. 一次性查询所有角色信息
|
||||||
|
List<Roles> rolesList = rolesService.list(new QueryWrapper<Roles>()
|
||||||
|
.in("id", roleIds));
|
||||||
|
|
||||||
|
// 8. 构建角色映射,按角色ID分组
|
||||||
|
Map<Long, Roles> roleMap = rolesList.stream()
|
||||||
|
.collect(Collectors.toMap(Roles::getId, role -> role));
|
||||||
|
|
||||||
|
// 9. 构建用户-角色列表映射
|
||||||
|
Map<Long, List<Roles>> userRoleMap = new HashMap<>();
|
||||||
|
for (UserRoles userRole : userRolesList) {
|
||||||
|
Long userId = userRole.getUserId();
|
||||||
|
Roles role = roleMap.get(userRole.getRoleId());
|
||||||
|
if (role != null) {
|
||||||
|
userRoleMap.computeIfAbsent(userId, k -> new ArrayList<>())
|
||||||
|
.add(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. 构建响应DTO
|
||||||
|
List<Userresponse> userResponseList = userList.stream().map(user -> {
|
||||||
|
Userresponse response = new Userresponse();
|
||||||
|
response.setUsers(user);
|
||||||
|
// 从Map中取角色,避免空指针
|
||||||
|
response.setRoles(userRoleMap.getOrDefault(user.getId(), Collections.emptyList()));
|
||||||
|
return response;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return userResponseList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.qf.backend.service.impl;
|
package com.qf.backend.service.impl.User;
|
||||||
|
|
||||||
|
|
||||||
class rolesMapper {
|
class rolesMapper {
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.qf.backend.service.impl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.qf.backend.dto.LoginResponse;
|
|
||||||
import com.qf.backend.dto.Result;
|
|
||||||
import com.qf.backend.entity.User.Permissions;
|
|
||||||
import com.qf.backend.entity.User.Roles;
|
|
||||||
import com.qf.backend.entity.User.UserRoles;
|
|
||||||
import com.qf.backend.entity.User.Users;
|
|
||||||
import com.qf.backend.exception.ErrorCode;
|
|
||||||
import com.qf.backend.service.PermissionsService;
|
|
||||||
import com.qf.backend.service.RolePermissionsService;
|
|
||||||
import com.qf.backend.service.RolesService;
|
|
||||||
import com.qf.backend.service.UserLoginService;
|
|
||||||
import com.qf.backend.service.UserRolesService;
|
|
||||||
import com.qf.backend.service.UsersService;
|
|
||||||
import com.qf.backend.util.ResultUtils;
|
|
||||||
import com.qf.backend.util.ValidateUtil;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author 30803
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class UserLoginServiceImpl implements UserLoginService {
|
|
||||||
private Logger logger = LoggerFactory.getLogger(UserLoginServiceImpl.class);
|
|
||||||
@Autowired
|
|
||||||
private UsersService usersServiceImpl;
|
|
||||||
@Autowired
|
|
||||||
private UserRolesService userRolesServiceImpl;
|
|
||||||
@Autowired
|
|
||||||
private RolesService rolesServiceImpl;
|
|
||||||
@Autowired
|
|
||||||
private RolePermissionsService rolePermissionsServiceImpl;
|
|
||||||
@Autowired
|
|
||||||
private PermissionsService permissionsServiceImpl;
|
|
||||||
/**
|
|
||||||
* 用户登录
|
|
||||||
* @param username 用户名
|
|
||||||
* @param password 密码
|
|
||||||
* @return 登录结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Result<LoginResponse> login(String username, String password) {
|
|
||||||
logger.info("用户登录,用户名:{}", username);
|
|
||||||
// 1. 校验用户名和密码是否为空
|
|
||||||
try{
|
|
||||||
if (ValidateUtil.isEmpty(username) || ValidateUtil.isEmpty(password)) {
|
|
||||||
throw new IllegalArgumentException("用户名或密码不能为空");
|
|
||||||
}
|
|
||||||
// 2. 登录
|
|
||||||
Result<Users> result = usersServiceImpl.login(username, password);
|
|
||||||
if (result == null || result.getData() == null) {
|
|
||||||
throw new IllegalArgumentException("用户名不存在或密码错误");
|
|
||||||
}
|
|
||||||
|
|
||||||
Users user = result.getData();
|
|
||||||
// 3. 获取用户角色
|
|
||||||
Result<List<UserRoles>> userRolesResult = userRolesServiceImpl.getUserRolesByUserId(user.getId());
|
|
||||||
if (userRolesResult == null || userRolesResult.getData() == null) {
|
|
||||||
throw new IllegalArgumentException("获取用户角色失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<UserRoles> userRoles = userRolesResult.getData();
|
|
||||||
Set<String> roleNames = new HashSet<>();
|
|
||||||
Set<Long> roleIds = new HashSet<>();
|
|
||||||
|
|
||||||
// 4. 获取角色名称和角色ID
|
|
||||||
for (UserRoles ur : userRoles) {
|
|
||||||
Roles role = rolesServiceImpl.getById(ur.getRoleId());
|
|
||||||
if (role != null) {
|
|
||||||
roleNames.add(String.valueOf(role.getRoleType()));
|
|
||||||
roleIds.add(role.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 获取用户权限
|
|
||||||
Set<String> permissionCodes = new HashSet<>();
|
|
||||||
for (Long roleId : roleIds) {
|
|
||||||
List<Long> permissionIds = rolePermissionsServiceImpl.listPermissionIdsByRoleId(roleId);
|
|
||||||
for (Long permissionId : permissionIds) {
|
|
||||||
Permissions permission = permissionsServiceImpl.getById(permissionId);
|
|
||||||
if (permission != null) {
|
|
||||||
permissionCodes.add(permission.getPermissionCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. 构建LoginResponse对象
|
|
||||||
LoginResponse loginResponse = new LoginResponse();
|
|
||||||
loginResponse.setUsername(user.getUsername());
|
|
||||||
loginResponse.setRoles(new ArrayList<>(roleNames));
|
|
||||||
loginResponse.setPermissions(new ArrayList<>(permissionCodes));
|
|
||||||
return ResultUtils.success(loginResponse);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("用户登录失败,用户名:{}", username, e);
|
|
||||||
return ResultUtils.fail(ErrorCode.SYSTEM_ERROR, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -47,6 +47,13 @@ public class JwtUtils {
|
|||||||
return getClaimFromToken(token, Claims::getSubject);
|
return getClaimFromToken(token, Claims::getSubject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从token中获取用户id
|
||||||
|
*/
|
||||||
|
public Long getUserIdFromToken(String token) {
|
||||||
|
return getClaimFromToken(token, claims -> claims.get("userId", Long.class));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从token中获取过期时间
|
* 从token中获取过期时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user