Compare commits
2 Commits
d6d95c20d2
...
17dcdf3754
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17dcdf3754 | ||
|
|
9787bc1735 |
@@ -3,9 +3,11 @@ package com.qf.backend;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.qf.backend.mapper")
|
||||
@ComponentScan(basePackages = "com.qf.backend") // 确保扫描范围包含 config 包
|
||||
public class BackendApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,15 @@ public class SecurityConfig {
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
// 登录接口公开访问,不需要认证
|
||||
.requestMatchers("/api/auth/login").permitAll()
|
||||
// 公开注册接口,不需要认证
|
||||
.requestMatchers("/api/user/register").permitAll()
|
||||
// 公开获取商品列表接口,不需要认证
|
||||
.requestMatchers("/api/products/list").permitAll()
|
||||
// 公开获取商品详情接口,不需要认证
|
||||
.requestMatchers("/api/products/**").permitAll()
|
||||
// 公开获取店铺商品列表接口,不需要认证
|
||||
.requestMatchers("/api/shop/**").permitAll()
|
||||
|
||||
// 其他所有请求都需要认证
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.qf.backend.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
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.RestController;
|
||||
|
||||
import com.qf.backend.dto.LoginRequest;
|
||||
import com.qf.backend.dto.LoginResponse;
|
||||
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.service.User.UsersService;
|
||||
import com.qf.backend.util.JwtUtils;
|
||||
import com.qf.backend.util.ResultUtils;
|
||||
|
||||
@@ -39,9 +40,15 @@ public class AuthController {
|
||||
*/
|
||||
@Autowired
|
||||
private JwtUtils jwtUtils;
|
||||
/**
|
||||
* 注入用户服务,用于查询用户信息
|
||||
*/
|
||||
@Autowired
|
||||
private UsersService userService;
|
||||
|
||||
/**
|
||||
* 用户登录接口
|
||||
*
|
||||
* @param loginRequest 登录请求体,包含用户名和密码
|
||||
* @return ResponseEntity 包含JWT令牌的响应
|
||||
*
|
||||
@@ -54,12 +61,12 @@ public class AuthController {
|
||||
* 6. 返回包含JWT令牌的响应
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public Result<ResponseEntity<LoginResponse>> login(@RequestBody LoginRequest loginRequest) {
|
||||
public Result<LoginResponse> login(@RequestBody LoginRequest loginRequest) {
|
||||
try {
|
||||
// 1. 创建认证令牌,将用户名和密码封装到UsernamePasswordAuthenticationToken中
|
||||
// 这里的令牌是未认证状态的,因为还没有验证密码是否正确
|
||||
UsernamePasswordAuthenticationToken authenticationToken =
|
||||
new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());
|
||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||
loginRequest.getUsername(), loginRequest.getPassword());
|
||||
|
||||
// 2. 调用AuthenticationManager.authenticate()方法进行认证
|
||||
// 这个方法会触发以下流程:
|
||||
@@ -67,22 +74,28 @@ public class AuthController {
|
||||
// b. 使用PasswordEncoder验证密码是否匹配
|
||||
// c. 认证成功后,返回一个已认证的Authentication对象
|
||||
Authentication authentication = authenticationManager.authenticate(authenticationToken);
|
||||
|
||||
System.out.println(authentication);
|
||||
// 3. 从已认证的Authentication对象中获取UserDetails
|
||||
// UserDetails包含了用户的基本信息和权限列表
|
||||
// UserDetails是Spring Security的核心接口,包含了用户的基本信息和权限列表
|
||||
UserDetails userDetails = (UserDetails) authentication.getPrincipal();
|
||||
|
||||
// 4. 使用JwtUtils生成JWT令牌
|
||||
// 令牌中包含了用户名、权限等信息,以及过期时间
|
||||
String jwt = jwtUtils.generateToken(userDetails);
|
||||
// 5.从数据库重新查询用户信息 并获取role权限与permissions信息
|
||||
Userresponse user = userService.getUserByUsername(userDetails.getUsername()).getData();
|
||||
|
||||
// 5. 创建LoginResponse对象,封装JWT令牌和令牌类型
|
||||
LoginResponse loginResponse = new LoginResponse();
|
||||
loginResponse.setToken(jwt);
|
||||
loginResponse.setTokenType(jwtUtils.getTokenPrefix());
|
||||
// 6. 创建LoginResponse对象,封装JWT令牌和令牌类型
|
||||
LoginResponse loginResponse = new LoginResponse(
|
||||
user.getUsers().getId(),
|
||||
user.getUsers().getUsername(),
|
||||
user.getRoles(),
|
||||
user.getPermissions(),
|
||||
jwt,
|
||||
jwtUtils.getTokenPrefix()
|
||||
);
|
||||
// 5. 返回包含JWT令牌的响应
|
||||
// 响应格式为:{"token": "xxx", "tokenType": "Bearer"}
|
||||
return ResultUtils.success(ResponseEntity.ok(loginResponse));
|
||||
return ResultUtils.success(loginResponse);
|
||||
} catch (BadCredentialsException e) {
|
||||
// 认证失败,通常是用户名不存在或密码错误
|
||||
// 返回401 Unauthorized响应
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.OrderItems;
|
||||
import com.qf.backend.service.OrderItemsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单项控制器
|
||||
* 处理订单项相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/order-items")
|
||||
@RestController
|
||||
public class OrderItemsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderItemsController.class);
|
||||
|
||||
@Autowired
|
||||
private OrderItemsService orderItemsService;
|
||||
|
||||
/**
|
||||
* 根据订单ID查询订单项
|
||||
* @param orderId 订单ID
|
||||
* @return 订单项列表
|
||||
*/
|
||||
@GetMapping("/order/{orderId}")
|
||||
public Result<List<OrderItems>> getOrderItemsByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID查询订单项,订单ID:{}", orderId);
|
||||
return orderItemsService.getOrderItemsByOrderId(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID查询订单项
|
||||
* @param productId 商品ID
|
||||
* @return 订单项列表
|
||||
*/
|
||||
@GetMapping("/product/{productId}")
|
||||
public Result<List<OrderItems>> getOrderItemsByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询订单项,商品ID:{}", productId);
|
||||
return orderItemsService.getOrderItemsByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单项
|
||||
* @param orderItems 订单项信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createOrderItem(@RequestBody OrderItems orderItems) {
|
||||
logger.info("创建订单项,订单项信息:{}", orderItems);
|
||||
return orderItemsService.createOrderItem(orderItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单项信息
|
||||
* @param orderItems 订单项信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateOrderItem(@RequestBody OrderItems orderItems) {
|
||||
logger.info("更新订单项信息,订单项信息:{}", orderItems);
|
||||
return orderItemsService.updateOrderItem(orderItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单项
|
||||
* @param id 订单项ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteOrderItem(@PathVariable Long id) {
|
||||
logger.info("删除订单项,订单项ID:{}", id);
|
||||
return orderItemsService.deleteOrderItem(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单项ID查询订单项
|
||||
* @param id 订单项ID
|
||||
* @return 订单项信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<OrderItems> getOrderItemById(@PathVariable Long id) {
|
||||
logger.info("根据订单项ID查询订单项,订单项ID:{}", id);
|
||||
return orderItemsService.getOrderItemById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量创建订单项
|
||||
* @param orderItemsList 订单项列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> batchCreateOrderItems(@RequestBody List<OrderItems> orderItemsList) {
|
||||
logger.info("批量创建订单项,订单项数量:{}", orderItemsList.size());
|
||||
return orderItemsService.batchCreateOrderItems(orderItemsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID删除所有订单项
|
||||
* @param orderId 订单ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete-by-order/{orderId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteOrderItemsByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID删除所有订单项,订单ID:{}", orderId);
|
||||
return orderItemsService.deleteOrderItemsByOrderId(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算订单总金额
|
||||
* @param orderId 订单ID
|
||||
* @return 订单总金额
|
||||
*/
|
||||
@GetMapping("/calculate-total/{orderId}")
|
||||
public Result<Double> calculateOrderTotal(@PathVariable Long orderId) {
|
||||
logger.info("计算订单总金额,订单ID:{}", orderId);
|
||||
return orderItemsService.calculateOrderTotal(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据SKU ID查询订单项
|
||||
* @param skuId SKU ID
|
||||
* @return 订单项列表
|
||||
*/
|
||||
@GetMapping("/sku/{skuId}")
|
||||
public Result<List<OrderItems>> getOrderItemsBySkuId(@PathVariable Long skuId) {
|
||||
logger.info("根据SKU ID查询订单项,SKU ID:{}", skuId);
|
||||
return orderItemsService.getOrderItemsBySkuId(skuId);
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.OrderStatusHistory;
|
||||
import com.qf.backend.service.OrderStatusHistoryService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单状态历史控制器
|
||||
* 处理订单状态历史相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/order-status-history")
|
||||
@RestController
|
||||
public class OrderStatusHistoryController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrderStatusHistoryController.class);
|
||||
|
||||
@Autowired
|
||||
private OrderStatusHistoryService orderStatusHistoryService;
|
||||
|
||||
/**
|
||||
* 根据订单ID查询状态历史
|
||||
* @param orderId 订单ID
|
||||
* @return 订单状态历史列表
|
||||
*/
|
||||
@GetMapping("/order/{orderId}")
|
||||
public Result<List<OrderStatusHistory>> getHistoryByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID查询状态历史,订单ID:{}", orderId);
|
||||
return orderStatusHistoryService.getHistoryByOrderId(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单状态历史记录
|
||||
* @param orderStatusHistory 订单状态历史信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createStatusHistory(@RequestBody OrderStatusHistory orderStatusHistory) {
|
||||
logger.info("创建订单状态历史记录,订单状态历史信息:{}", orderStatusHistory);
|
||||
return orderStatusHistoryService.createStatusHistory(orderStatusHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态历史信息
|
||||
* @param orderStatusHistory 订单状态历史信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateStatusHistory(@RequestBody OrderStatusHistory orderStatusHistory) {
|
||||
logger.info("更新订单状态历史信息,订单状态历史信息:{}", orderStatusHistory);
|
||||
return orderStatusHistoryService.updateStatusHistory(orderStatusHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单状态历史记录
|
||||
* @param id 记录ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteStatusHistory(@PathVariable Long id) {
|
||||
logger.info("删除订单状态历史记录,记录ID:{}", id);
|
||||
return orderStatusHistoryService.deleteStatusHistory(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据记录ID查询订单状态历史
|
||||
* @param id 记录ID
|
||||
* @return 订单状态历史信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<OrderStatusHistory> getStatusHistoryById(@PathVariable Long id) {
|
||||
logger.info("根据记录ID查询订单状态历史,记录ID:{}", id);
|
||||
return orderStatusHistoryService.getStatusHistoryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量创建订单状态历史记录
|
||||
* @param historyList 订单状态历史列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchCreateStatusHistory(@RequestBody List<OrderStatusHistory> historyList) {
|
||||
logger.info("批量创建订单状态历史记录,记录数量:{}", historyList.size());
|
||||
return orderStatusHistoryService.batchCreateStatusHistory(historyList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID和状态查询历史记录
|
||||
* @param orderId 订单ID
|
||||
* @param status 订单状态
|
||||
* @return 订单状态历史列表
|
||||
*/
|
||||
@GetMapping("/order/{orderId}/status/{status}")
|
||||
public Result<List<OrderStatusHistory>> getHistoryByOrderIdAndStatus(@PathVariable Long orderId, @PathVariable Integer status) {
|
||||
logger.info("根据订单ID和状态查询历史记录,订单ID:{},状态:{}", orderId, status);
|
||||
return orderStatusHistoryService.getHistoryByOrderIdAndStatus(orderId, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单最新状态
|
||||
* @param orderId 订单ID
|
||||
* @return 最新订单状态历史信息
|
||||
*/
|
||||
@GetMapping("/order/{orderId}/latest")
|
||||
public Result<OrderStatusHistory> getLatestStatusHistory(@PathVariable Long orderId) {
|
||||
logger.info("获取订单最新状态,订单ID:{}", orderId);
|
||||
return orderStatusHistoryService.getLatestStatusHistory(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID删除所有状态历史
|
||||
* @param orderId 订单ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete-by-order/{orderId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteHistoryByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID删除所有状态历史,订单ID:{}", orderId);
|
||||
return orderStatusHistoryService.deleteHistoryByOrderId(orderId);
|
||||
}
|
||||
}
|
||||
@@ -1,149 +1,176 @@
|
||||
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.GetMapping;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Orders;
|
||||
import com.qf.backend.service.OrdersService;
|
||||
import java.util.List;
|
||||
import com.qf.backend.dto.request.OrderRequest;
|
||||
import com.qf.backend.dto.request.PageRequest;
|
||||
import com.qf.backend.entity.Order.Orders;
|
||||
import com.qf.backend.service.Order.OrderItemsService;
|
||||
import com.qf.backend.service.Order.OrdersService;
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
* 订单控制器 (订单接口)
|
||||
* 处理订单相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*
|
||||
* @author 30803
|
||||
*/
|
||||
@RequestMapping("/api/orders")
|
||||
@RestController
|
||||
@RequestMapping("/api/orders")
|
||||
public class OrdersController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OrdersController.class);
|
||||
|
||||
@Autowired
|
||||
private OrdersService ordersService;
|
||||
@Autowired
|
||||
private OrderItemsService orderItemsService;
|
||||
|
||||
/**
|
||||
* 根据订单号查询订单
|
||||
* @param orderNumber 订单号
|
||||
* 获取订单详情
|
||||
* @param orderRequest 订单ID请求
|
||||
* @return 订单信息
|
||||
*/
|
||||
@GetMapping("/number/{orderNumber}")
|
||||
public Result<Orders> getOrderByNumber(@PathVariable String orderNumber) {
|
||||
logger.info("根据订单号查询订单,订单号:{}", orderNumber);
|
||||
return ordersService.getOrderByNumber(orderNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询订单列表
|
||||
* @param userId 用户ID
|
||||
* @return 订单列表
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
public Result<List<Orders>> getOrdersByUserId(@PathVariable Long userId) {
|
||||
logger.info("根据用户ID查询订单列表,用户ID:{}", userId);
|
||||
return ordersService.getOrdersByUserId(userId);
|
||||
@PostMapping("/getorderinfo")
|
||||
// 只有用户本人或管理员才能获取订单信息
|
||||
@PreAuthorize("#orderRequest.getUserId() == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
||||
public Result<Orders> getOrderInfo(@RequestBody OrderRequest orderRequest) {
|
||||
logger.info("获取订单信息请求,订单ID:{}", orderRequest.getId());
|
||||
return ordersService.getOrderById(orderRequest.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param orders 订单信息
|
||||
* @return 是否成功
|
||||
* @param orderRequest 订单信息
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createOrder(@RequestBody Orders orders) {
|
||||
logger.info("创建订单,订单信息:{}", orders);
|
||||
return ordersService.createOrder(orders);
|
||||
// 只有登录用户才能创建订单
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
public Result<Boolean> createOrder(@RequestBody OrderRequest orderRequest) {
|
||||
logger.info("创建订单请求,订单信息:{}", orderRequest);
|
||||
Orders orders = new Orders(null, orderRequest.getOrderNo(), orderRequest.getUserId(),
|
||||
orderRequest.getShopId(), orderRequest.getTotalAmount(), orderRequest.getActualAmount(),
|
||||
orderRequest.getShippingFee(), 0, orderRequest.getShippingAddress(),
|
||||
orderRequest.getReceiverName(), orderRequest.getReceiverPhone(), orderRequest.getPaymentMethod(),
|
||||
null, null, null, null, orderRequest.getRemark(), null, null);
|
||||
// 1. 创建订单主表
|
||||
Result<Boolean> createOrderResult = ordersService.createOrder(orders);
|
||||
if (createOrderResult.getCode() != 200) {
|
||||
return createOrderResult;
|
||||
}
|
||||
// 2. 创建订单项
|
||||
if (orderRequest.getOrderItems() != null && !orderRequest.getOrderItems().isEmpty()) {
|
||||
for (var item : orderRequest.getOrderItems()) {
|
||||
item.setOrderId(orders.getId());
|
||||
}
|
||||
return orderItemsService.batchCreateOrderItems(orderRequest.getOrderItems());
|
||||
}
|
||||
return createOrderResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单信息
|
||||
* @param orders 订单信息
|
||||
* @return 是否成功
|
||||
* @param orderRequest 订单信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateOrder(@RequestBody Orders orders) {
|
||||
logger.info("更新订单信息,订单信息:{}", orders);
|
||||
@PostMapping("/update")
|
||||
// 只有管理员或店铺所有者才能更新订单
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||
public Result<Boolean> updateOrder(@RequestBody OrderRequest orderRequest) {
|
||||
logger.info("更新订单信息请求,订单信息:{}", orderRequest);
|
||||
Orders orders = new Orders(orderRequest.getId(), orderRequest.getOrderNo(), orderRequest.getUserId(),
|
||||
orderRequest.getShopId(), orderRequest.getTotalAmount(), orderRequest.getActualAmount(),
|
||||
orderRequest.getShippingFee(), orderRequest.getOrderStatus(), orderRequest.getShippingAddress(),
|
||||
orderRequest.getReceiverName(), orderRequest.getReceiverPhone(), orderRequest.getPaymentMethod(),
|
||||
orderRequest.getPaymentTime(), orderRequest.getShippingTime(), orderRequest.getDeliveryTime(),
|
||||
orderRequest.getCompleteTime(), orderRequest.getRemark(), null, null);
|
||||
return ordersService.updateOrder(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单
|
||||
* @param id 订单ID
|
||||
* @return 是否成功
|
||||
* @param orderRequest 订单ID请求
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteOrder(@PathVariable Long id) {
|
||||
logger.info("删除订单,订单ID:{}", id);
|
||||
return ordersService.deleteOrder(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单ID查询订单
|
||||
* @param id 订单ID
|
||||
* @return 订单信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Orders> getOrderById(@PathVariable Long id) {
|
||||
logger.info("根据订单ID查询订单,订单ID:{}", id);
|
||||
return ordersService.getOrderById(id);
|
||||
@PostMapping("/delete")
|
||||
// 只有管理员或店铺所有者才能删除订单
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||
public Result<Boolean> deleteOrder(@RequestBody OrderRequest orderRequest) {
|
||||
logger.info("删除订单请求,订单ID:{}", orderRequest.getId());
|
||||
return ordersService.deleteOrder(orderRequest.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询订单
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @param pageRequest 分页请求
|
||||
* @return 订单列表
|
||||
*/
|
||||
@GetMapping("/page/{page}/{size}")
|
||||
public Result<List<Orders>> listOrdersByPage(@PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询订单,页码:{},每页数量:{}", page, size);
|
||||
return ordersService.listOrdersByPage(page, size);
|
||||
@PostMapping("/list")
|
||||
// 只有管理员或店铺所有者才能查询所有订单
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #orderRequest.getShopId() == authentication.principal.shopId")
|
||||
public Result<List<Orders>> listOrdersByPage(@RequestBody PageRequest pageRequest) {
|
||||
logger.info("分页查询订单请求,页码:{},每页大小:{}", pageRequest.getPage(), pageRequest.getSize());
|
||||
return ordersService.listOrdersByPage(pageRequest.getPage(), pageRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询订单
|
||||
* @param orderRequest 用户ID请求
|
||||
* @return 订单列表
|
||||
*/
|
||||
@PostMapping("/byuser")
|
||||
// 只有用户本人或管理员才能查询用户订单
|
||||
@PreAuthorize("#orderRequest.getUserId() == authentication.principal.userId or hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Orders>> getOrdersByUser(@RequestBody OrderRequest orderRequest ) {
|
||||
logger.info("根据用户ID查询订单请求,用户ID:{},页码:{},每页大小:{}", orderRequest.getUserId(), orderRequest.getPage(), orderRequest.getSize());
|
||||
return ordersService.getOrdersByUserId(orderRequest.getUserId(), orderRequest.getPage(), orderRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询订单
|
||||
* @param shopId 店铺ID
|
||||
* @param orderRequest 店铺ID请求
|
||||
* @return 订单列表
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}")
|
||||
public Result<List<Orders>> getOrdersByShopId(@PathVariable Long shopId) {
|
||||
logger.info("根据店铺ID查询订单,店铺ID:{}", shopId);
|
||||
return ordersService.getOrdersByShopId(shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
* @param orderId 订单ID
|
||||
* @param status 订单状态
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update-status/{orderId}/{status}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> updateOrderStatus(@PathVariable Long orderId, @PathVariable Integer status) {
|
||||
logger.info("更新订单状态,订单ID:{},状态:{}", orderId, status);
|
||||
return ordersService.updateOrderStatus(orderId, status);
|
||||
@PostMapping("/byshop")
|
||||
// 只有店铺所有者或管理员才能查询店铺订单
|
||||
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Orders>> getOrdersByShop(@RequestBody OrderRequest orderRequest ) {
|
||||
logger.info("根据店铺ID查询订单请求,店铺ID:{},页码:{},每页大小:{}", orderRequest.getShopId(), orderRequest.getPage(), orderRequest.getSize());
|
||||
return ordersService.getOrdersByShopId(orderRequest.getShopId(), orderRequest.getPage(), orderRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据订单状态查询订单
|
||||
* @param status 订单状态
|
||||
* @param orderRequest 订单状态请求
|
||||
* @return 订单列表
|
||||
*/
|
||||
@GetMapping("/status/{status}")
|
||||
public Result<List<Orders>> getOrdersByStatus(@PathVariable Integer status) {
|
||||
logger.info("根据订单状态查询订单,状态:{}", status);
|
||||
return ordersService.getOrdersByStatus(status);
|
||||
@PostMapping("/bystatus")
|
||||
// 只有店铺所有者或管理员才能查询特定状态的订单
|
||||
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Orders>> getOrdersByStatus(@RequestBody OrderRequest orderRequest ) {
|
||||
logger.info("根据订单状态查询订单请求,状态:{},页码:{},每页大小:{}", orderRequest.getOrderStatus(), orderRequest.getPage(), orderRequest.getSize());
|
||||
return ordersService.getOrdersByStatus(orderRequest.getOrderStatus(), orderRequest.getPage(), orderRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
* @param orderRequest 订单状态请求
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PostMapping("/updatestatus")
|
||||
// 只有店铺所有者或管理员才能更新订单状态
|
||||
@PreAuthorize("#orderRequest.getShopId() == authentication.principal.shopId or hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateOrderStatus(@RequestBody OrderRequest orderRequest) {
|
||||
logger.info("更新订单状态请求,订单ID:{},状态:{}", orderRequest.getId(), orderRequest.getOrderStatus());
|
||||
return ordersService.updateOrderStatus(orderRequest.getId(), orderRequest.getOrderStatus());
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Payments;
|
||||
import com.qf.backend.service.PaymentsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付控制器
|
||||
* 处理支付相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/payments")
|
||||
@RestController
|
||||
public class PaymentsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PaymentsController.class);
|
||||
|
||||
@Autowired
|
||||
private PaymentsService paymentsService;
|
||||
|
||||
/**
|
||||
* 根据订单ID查询支付记录
|
||||
* @param orderId 订单ID
|
||||
* @return 支付记录
|
||||
*/
|
||||
@GetMapping("/order/{orderId}")
|
||||
public Result<Payments> getPaymentByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID查询支付记录,订单ID:{}", orderId);
|
||||
Payments payment = paymentsService.getPaymentByOrderId(orderId);
|
||||
return Result.success(payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据支付流水号查询支付记录
|
||||
* @param transactionId 支付流水号
|
||||
* @return 支付记录
|
||||
*/
|
||||
@GetMapping("/transaction/{transactionId}")
|
||||
public Result<Payments> getPaymentByTransactionId(@PathVariable String transactionId) {
|
||||
logger.info("根据支付流水号查询支付记录,支付流水号:{}", transactionId);
|
||||
Payments payment = paymentsService.getPaymentByTransactionId(transactionId);
|
||||
return Result.success(payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建支付记录
|
||||
* @param payments 支付信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createPayment(@RequestBody Payments payments) {
|
||||
logger.info("创建支付记录,支付信息:{}", payments);
|
||||
boolean result = paymentsService.createPayment(payments);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新支付信息
|
||||
* @param payments 支付信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updatePayment(@RequestBody Payments payments) {
|
||||
logger.info("更新支付信息,支付信息:{}", payments);
|
||||
boolean result = paymentsService.updatePayment(payments);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除支付记录
|
||||
* @param id 支付ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deletePayment(@PathVariable Long id) {
|
||||
logger.info("删除支付记录,支付ID:{}", id);
|
||||
boolean result = paymentsService.deletePayment(id);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据支付ID查询支付记录
|
||||
* @param id 支付ID
|
||||
* @return 支付记录
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Payments> getPaymentById(@PathVariable Long id) {
|
||||
logger.info("根据支付ID查询支付记录,支付ID:{}", id);
|
||||
Payments payment = paymentsService.getPaymentById(id);
|
||||
return Result.success(payment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询支付记录
|
||||
* @param userId 用户ID
|
||||
* @return 支付记录列表
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
public Result<List<Payments>> getPaymentsByUserId(@PathVariable Long userId) {
|
||||
logger.info("根据用户ID查询支付记录,用户ID:{}", userId);
|
||||
List<Payments> payments = paymentsService.getPaymentsByUserId(userId);
|
||||
return Result.success(payments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据支付状态查询支付记录
|
||||
* @param status 支付状态
|
||||
* @return 支付记录列表
|
||||
*/
|
||||
@GetMapping("/status/{status}")
|
||||
public Result<List<Payments>> getPaymentsByStatus(@PathVariable Integer status) {
|
||||
logger.info("根据支付状态查询支付记录,状态:{}", status);
|
||||
List<Payments> payments = paymentsService.getPaymentsByStatus(status);
|
||||
return Result.success(payments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新支付状态
|
||||
* @param paymentId 支付ID
|
||||
* @param status 支付状态
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update-status/{paymentId}/{status}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updatePaymentStatus(@PathVariable Long paymentId, @PathVariable Integer status) {
|
||||
logger.info("更新支付状态,支付ID:{},状态:{}", paymentId, status);
|
||||
boolean result = paymentsService.updatePaymentStatus(paymentId, status);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询支付记录
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 支付记录列表
|
||||
*/
|
||||
@GetMapping("/page/{page}/{size}")
|
||||
public Result<List<Payments>> listPaymentsByPage(@PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询支付记录,页码:{},每页数量:{}", page, size);
|
||||
List<Payments> payments = paymentsService.listPaymentsByPage(page, size);
|
||||
return Result.success(payments);
|
||||
}
|
||||
}
|
||||
@@ -1,145 +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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Permissions;
|
||||
import com.qf.backend.service.PermissionsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限管理控制器
|
||||
* 处理权限相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
* @author 30803
|
||||
*/
|
||||
@RequestMapping("/api/permissions")
|
||||
@RestController
|
||||
public class PermissionsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PermissionsController.class);
|
||||
|
||||
@Autowired
|
||||
private PermissionsService permissionsService;
|
||||
|
||||
/**
|
||||
* 查询所有权限
|
||||
* @return 权限列表
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Permissions>> listAllPermissions() {
|
||||
logger.info("管理员查询所有权限");
|
||||
return permissionsService.listAllPermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限ID查询权限
|
||||
* @param id 权限ID
|
||||
* @return 权限信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Permissions> getPermissionById(@PathVariable Long id) {
|
||||
logger.info("管理员根据ID查询权限,ID:{}", id);
|
||||
return permissionsService.getPermissionById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限编码查询权限
|
||||
* @param permissionCode 权限编码
|
||||
* @return 权限信息
|
||||
*/
|
||||
@GetMapping("/code/{permissionCode}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Permissions> getPermissionByCode(@PathVariable String permissionCode) {
|
||||
logger.info("管理员根据权限编码查询权限,权限编码:{}", permissionCode);
|
||||
return permissionsService.getPermissionByCode(permissionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建权限
|
||||
* @param permissions 权限信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createPermission(@RequestBody Permissions permissions) {
|
||||
logger.info("管理员创建权限:{}", permissions);
|
||||
return permissionsService.createPermission(permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限信息
|
||||
* @param permissions 权限信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updatePermission(@RequestBody Permissions permissions) {
|
||||
logger.info("管理员更新权限:{}", permissions);
|
||||
return permissionsService.updatePermission(permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除权限
|
||||
* @param id 权限ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deletePermission(@PathVariable Long id) {
|
||||
logger.info("管理员删除权限,ID:{}", id);
|
||||
return permissionsService.deletePermission(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除权限
|
||||
* @param ids 权限ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/batch")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchDeletePermissions(@RequestBody List<Long> ids) {
|
||||
logger.info("管理员批量删除权限,IDs:{}", ids);
|
||||
return permissionsService.batchDeletePermissions(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据菜单ID查询权限
|
||||
* @param menuId 菜单ID
|
||||
* @return 权限列表
|
||||
*/
|
||||
@GetMapping("/menu/{menuId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Permissions>> listPermissionsByMenuId(@PathVariable Long menuId) {
|
||||
logger.info("管理员根据菜单ID查询权限,菜单ID:{}", menuId);
|
||||
return permissionsService.listPermissionsByMenuId(menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限类型查询权限
|
||||
* @param permissionType 权限类型
|
||||
* @return 权限列表
|
||||
*/
|
||||
@GetMapping("/type/{permissionType}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Permissions>> listPermissionsByType(@PathVariable String permissionType) {
|
||||
logger.info("管理员根据权限类型查询权限,权限类型:{}", permissionType);
|
||||
return permissionsService.listPermissionsByType(permissionType);
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductAttributeValues;
|
||||
import com.qf.backend.service.ProductAttributeValuesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品属性值控制器
|
||||
* 处理商品属性值相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-attribute-values")
|
||||
@RestController
|
||||
public class ProductAttributeValuesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductAttributeValuesController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductAttributeValuesService productAttributeValuesService;
|
||||
|
||||
/**
|
||||
* 根据商品ID查询属性值
|
||||
* @param productId 商品ID
|
||||
* @return 属性值列表
|
||||
*/
|
||||
@GetMapping("/product/{productId}")
|
||||
public Result<List<ProductAttributeValues>> getAttributeValuesByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询属性值,商品ID:{}", productId);
|
||||
return productAttributeValuesService.getAttributeValuesByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID查询属性值
|
||||
* @param attributeId 属性ID
|
||||
* @return 属性值列表
|
||||
*/
|
||||
@GetMapping("/attribute/{attributeId}")
|
||||
public Result<List<ProductAttributeValues>> getAttributeValuesByAttributeId(@PathVariable Long attributeId) {
|
||||
logger.info("根据属性ID查询属性值,属性ID:{}", attributeId);
|
||||
return productAttributeValuesService.getAttributeValuesByAttributeId(attributeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建属性值
|
||||
* @param productAttributeValues 属性值信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createAttributeValue(@RequestBody ProductAttributeValues productAttributeValues) {
|
||||
logger.info("创建属性值,属性值信息:{}", productAttributeValues);
|
||||
return productAttributeValuesService.createAttributeValue(productAttributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性值信息
|
||||
* @param productAttributeValues 属性值信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateAttributeValue(@RequestBody ProductAttributeValues productAttributeValues) {
|
||||
logger.info("更新属性值信息,属性值信息:{}", productAttributeValues);
|
||||
return productAttributeValuesService.updateAttributeValue(productAttributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除属性值
|
||||
* @param id 属性值ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteAttributeValue(@PathVariable Long id) {
|
||||
logger.info("删除属性值,属性值ID:{}", id);
|
||||
return productAttributeValuesService.deleteAttributeValue(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性值ID查询属性值
|
||||
* @param id 属性值ID
|
||||
* @return 属性值信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductAttributeValues> getAttributeValueById(@PathVariable Long id) {
|
||||
logger.info("根据属性值ID查询属性值,属性值ID:{}", id);
|
||||
return productAttributeValuesService.getAttributeValueById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量创建商品属性值
|
||||
* @param attributeValues 属性值列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchCreateAttributeValues(@RequestBody List<ProductAttributeValues> attributeValues) {
|
||||
logger.info("批量创建商品属性值,属性值数量:{}", attributeValues.size());
|
||||
return productAttributeValuesService.batchCreateAttributeValues(attributeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID和属性ID查询属性值
|
||||
* @param productId 商品ID
|
||||
* @param attributeId 属性ID
|
||||
* @return 属性值信息
|
||||
*/
|
||||
@GetMapping("/product/{productId}/attribute/{attributeId}")
|
||||
public Result<ProductAttributeValues> getAttributeValueByProductAndAttribute(@PathVariable Long productId, @PathVariable Long attributeId) {
|
||||
logger.info("根据商品ID和属性ID查询属性值,商品ID:{},属性ID:{}", productId, attributeId);
|
||||
return productAttributeValuesService.getAttributeValueByProductAndAttribute(productId, attributeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID删除所有属性值
|
||||
* @param productId 商品ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete-by-product/{productId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteAttributeValuesByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID删除所有属性值,商品ID:{}", productId);
|
||||
return productAttributeValuesService.deleteAttributeValuesByProductId(productId);
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductAttributes;
|
||||
import com.qf.backend.service.ProductAttributesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品属性控制器
|
||||
* 处理商品属性相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-attributes")
|
||||
@RestController
|
||||
public class ProductAttributesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductAttributesController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductAttributesService productAttributesService;
|
||||
|
||||
/**
|
||||
* 根据分类ID查询属性
|
||||
* @param categoryId 分类ID
|
||||
* @return 属性列表
|
||||
*/
|
||||
@GetMapping("/category/{categoryId}")
|
||||
public Result<List<ProductAttributes>> getAttributesByCategoryId(@PathVariable Long categoryId) {
|
||||
logger.info("根据分类ID查询属性,分类ID:{}", categoryId);
|
||||
return productAttributesService.getAttributesByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性名称查询属性
|
||||
* @param attributeName 属性名称
|
||||
* @return 属性列表
|
||||
*/
|
||||
@GetMapping("/name/{attributeName}")
|
||||
public Result<List<ProductAttributes>> getAttributesByName(@PathVariable String attributeName) {
|
||||
logger.info("根据属性名称查询属性,属性名称:{}", attributeName);
|
||||
return productAttributesService.getAttributesByName(attributeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建属性
|
||||
* @param productAttributes 属性信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createAttribute(@RequestBody ProductAttributes productAttributes) {
|
||||
logger.info("创建属性,属性信息:{}", productAttributes);
|
||||
return productAttributesService.createAttribute(productAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新属性信息
|
||||
* @param productAttributes 属性信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateAttribute(@RequestBody ProductAttributes productAttributes) {
|
||||
logger.info("更新属性信息,属性信息:{}", productAttributes);
|
||||
return productAttributesService.updateAttribute(productAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除属性
|
||||
* @param id 属性ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteAttribute(@PathVariable Long id) {
|
||||
logger.info("删除属性,属性ID:{}", id);
|
||||
return productAttributesService.deleteAttribute(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID查询属性
|
||||
* @param id 属性ID
|
||||
* @return 属性信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductAttributes> getAttributeById(@PathVariable Long id) {
|
||||
logger.info("根据属性ID查询属性,属性ID:{}", id);
|
||||
return productAttributesService.getAttributeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除属性
|
||||
* @param ids 属性ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/batch-delete")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchDeleteAttributes(@RequestBody List<Long> ids) {
|
||||
logger.info("批量删除属性,属性ID数量:{}", ids.size());
|
||||
return productAttributesService.batchDeleteAttributes(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性类型查询属性
|
||||
* @param attributeType 属性类型
|
||||
* @return 属性列表
|
||||
*/
|
||||
@GetMapping("/type/{attributeType}")
|
||||
public Result<List<ProductAttributes>> getAttributesByType(@PathVariable String attributeType) {
|
||||
logger.info("根据属性类型查询属性,属性类型:{}", attributeType);
|
||||
return productAttributesService.getAttributesByType(attributeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询是否可搜索的属性
|
||||
* @param searchable 是否可搜索
|
||||
* @return 属性列表
|
||||
*/
|
||||
@GetMapping("/searchable")
|
||||
public Result<List<ProductAttributes>> getAttributesBySearchable(@RequestParam Boolean searchable) {
|
||||
logger.info("查询是否可搜索的属性,可搜索:{}", searchable);
|
||||
return productAttributesService.getAttributesBySearchable(searchable);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductCategories;
|
||||
import com.qf.backend.service.ProductCategoriesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品分类控制器
|
||||
* 处理商品分类相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-categories")
|
||||
@RestController
|
||||
public class ProductCategoriesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductCategoriesController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductCategoriesService productCategoriesService;
|
||||
|
||||
/**
|
||||
* 根据分类名称查询分类
|
||||
* @param categoryName 分类名称
|
||||
* @return 分类信息
|
||||
*/
|
||||
@GetMapping("/name/{categoryName}")
|
||||
public Result<ProductCategories> getCategoryByName(@PathVariable String categoryName) {
|
||||
logger.info("根据分类名称查询分类,分类名称:{}", categoryName);
|
||||
return productCategoriesService.getCategoryByName(categoryName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父分类ID查询子分类
|
||||
* @param parentId 父分类ID
|
||||
* @return 子分类列表
|
||||
*/
|
||||
@GetMapping("/parent/{parentId}")
|
||||
public Result<List<ProductCategories>> getSubCategoriesByParentId(@PathVariable Long parentId) {
|
||||
logger.info("根据父分类ID查询子分类,父分类ID:{}", parentId);
|
||||
return productCategoriesService.getSubCategoriesByParentId(parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分类
|
||||
* @param productCategories 分类信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createCategory(@RequestBody ProductCategories productCategories) {
|
||||
logger.info("创建分类,分类信息:{}", productCategories);
|
||||
return productCategoriesService.createCategory(productCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类信息
|
||||
* @param productCategories 分类信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateCategory(@RequestBody ProductCategories productCategories) {
|
||||
logger.info("更新分类信息,分类信息:{}", productCategories);
|
||||
return productCategoriesService.updateCategory(productCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param id 分类ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteCategory(@PathVariable Long id) {
|
||||
logger.info("删除分类,分类ID:{}", id);
|
||||
return productCategoriesService.deleteCategory(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有根分类(父分类ID为0或null的分类)
|
||||
* @return 根分类列表
|
||||
*/
|
||||
@GetMapping("/root")
|
||||
public Result<List<ProductCategories>> listRootCategories() {
|
||||
logger.info("查询所有根分类");
|
||||
return productCategoriesService.listRootCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID查询分类
|
||||
* @param id 分类ID
|
||||
* @return 分类信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductCategories> getCategoryById(@PathVariable Long id) {
|
||||
logger.info("根据分类ID查询分类,分类ID:{}", id);
|
||||
return productCategoriesService.getCategoryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除分类
|
||||
* @param ids 分类ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/batch-delete")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchDeleteCategories(@RequestBody List<Long> ids) {
|
||||
logger.info("批量删除分类,分类ID数量:{}", ids.size());
|
||||
return productCategoriesService.batchDeleteCategories(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有分类(树形结构)
|
||||
* @return 分类树形列表
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
public Result<List<ProductCategories>> listAllCategoriesWithTree() {
|
||||
logger.info("查询所有分类(树形结构)");
|
||||
return productCategoriesService.listAllCategoriesWithTree();
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductImages;
|
||||
import com.qf.backend.service.ProductImagesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品图片控制器
|
||||
* 处理商品图片相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-images")
|
||||
@RestController
|
||||
public class ProductImagesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductImagesController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductImagesService productImagesService;
|
||||
|
||||
/**
|
||||
* 根据商品ID查询图片
|
||||
* @param productId 商品ID
|
||||
* @return 图片列表
|
||||
*/
|
||||
@GetMapping("/product/{productId}")
|
||||
public Result<List<ProductImages>> getImagesByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询图片,商品ID:{}", productId);
|
||||
return productImagesService.getImagesByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID查询主图
|
||||
* @param productId 商品ID
|
||||
* @return 主图信息
|
||||
*/
|
||||
@GetMapping("/product/{productId}/main")
|
||||
public Result<ProductImages> getMainImageByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询主图,商品ID:{}", productId);
|
||||
return productImagesService.getMainImageByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品图片
|
||||
* @param productImages 图片信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createImage(@RequestBody ProductImages productImages) {
|
||||
logger.info("创建商品图片,图片信息:{}", productImages);
|
||||
return productImagesService.createImage(productImages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新图片信息
|
||||
* @param productImages 图片信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateImage(@RequestBody ProductImages productImages) {
|
||||
logger.info("更新图片信息,图片信息:{}", productImages);
|
||||
return productImagesService.updateImage(productImages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图片
|
||||
* @param id 图片ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteImage(@PathVariable Long id) {
|
||||
logger.info("删除图片,图片ID:{}", id);
|
||||
return productImagesService.deleteImage(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据图片ID查询图片
|
||||
* @param id 图片ID
|
||||
* @return 图片信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductImages> getImageById(@PathVariable Long id) {
|
||||
logger.info("根据图片ID查询图片,图片ID:{}", id);
|
||||
return productImagesService.getImageById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量创建商品图片
|
||||
* @param images 图片列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchCreateImages(@RequestBody List<ProductImages> images) {
|
||||
logger.info("批量创建商品图片,图片数量:{}", images.size());
|
||||
return productImagesService.batchCreateImages(images);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID删除所有图片
|
||||
* @param productId 商品ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete-by-product/{productId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteImagesByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID删除所有图片,商品ID:{}", productId);
|
||||
return productImagesService.deleteImagesByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置主图
|
||||
* @param productId 商品ID
|
||||
* @param imageId 图片ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/set-main/{productId}/{imageId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> setMainImage(@PathVariable Long productId, @PathVariable Long imageId) {
|
||||
logger.info("设置主图,商品ID:{},图片ID:{}", productId, imageId);
|
||||
return productImagesService.setMainImage(productId, imageId);
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductInventories;
|
||||
import com.qf.backend.service.ProductInventoriesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品库存控制器
|
||||
* 处理商品库存相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-inventories")
|
||||
@RestController
|
||||
public class ProductInventoriesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductInventoriesController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductInventoriesService productInventoriesService;
|
||||
|
||||
/**
|
||||
* 根据商品ID查询库存
|
||||
* @param productId 商品ID
|
||||
* @return 库存列表
|
||||
*/
|
||||
@GetMapping("/product/{productId}")
|
||||
public Result<List<ProductInventories>> getInventoriesByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询库存,商品ID:{}", productId);
|
||||
return productInventoriesService.getInventoriesByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据SKU ID查询库存
|
||||
* @param skuId SKU ID
|
||||
* @return 库存信息
|
||||
*/
|
||||
@GetMapping("/sku/{skuId}")
|
||||
public Result<ProductInventories> getInventoryBySkuId(@PathVariable Long skuId) {
|
||||
logger.info("根据SKU ID查询库存,SKU ID:{}", skuId);
|
||||
return productInventoriesService.getInventoryBySkuId(skuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建库存记录
|
||||
* @param productInventories 库存信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createInventory(@RequestBody ProductInventories productInventories) {
|
||||
logger.info("创建库存记录,库存信息:{}", productInventories);
|
||||
return productInventoriesService.createInventory(productInventories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新库存信息
|
||||
* @param productInventories 库存信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateInventory(@RequestBody ProductInventories productInventories) {
|
||||
logger.info("更新库存信息,库存信息:{}", productInventories);
|
||||
return productInventoriesService.updateInventory(productInventories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除库存记录
|
||||
* @param id 库存ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteInventory(@PathVariable Long id) {
|
||||
logger.info("删除库存记录,库存ID:{}", id);
|
||||
return productInventoriesService.deleteInventory(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据库存ID查询库存
|
||||
* @param id 库存ID
|
||||
* @return 库存信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductInventories> getInventoryById(@PathVariable Long id) {
|
||||
logger.info("根据库存ID查询库存,库存ID:{}", id);
|
||||
return productInventoriesService.getInventoryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加库存
|
||||
* @param skuId SKU ID
|
||||
* @param quantity 增加数量
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/increase/{skuId}/{quantity}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> increaseInventory(@PathVariable Long skuId, @PathVariable Integer quantity) {
|
||||
logger.info("增加库存,SKU ID:{},增加数量:{}", skuId, quantity);
|
||||
return productInventoriesService.increaseInventory(skuId, quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减少库存
|
||||
* @param skuId SKU ID
|
||||
* @param quantity 减少数量
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/decrease/{skuId}/{quantity}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> decreaseInventory(@PathVariable Long skuId, @PathVariable Integer quantity) {
|
||||
logger.info("减少库存,SKU ID:{},减少数量:{}", skuId, quantity);
|
||||
return productInventoriesService.decreaseInventory(skuId, quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查库存是否充足
|
||||
* @param skuId SKU ID
|
||||
* @param quantity 需要的数量
|
||||
* @return 是否充足
|
||||
*/
|
||||
@GetMapping("/check/{skuId}/{quantity}")
|
||||
public Result<Boolean> checkInventorySufficient(@PathVariable Long skuId, @PathVariable Integer quantity) {
|
||||
logger.info("检查库存是否充足,SKU ID:{},需要数量:{}", skuId, quantity);
|
||||
return productInventoriesService.checkInventorySufficient(skuId, quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新库存
|
||||
* @param inventoryUpdates 库存更新列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/batch-update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchUpdateInventory(@RequestBody List<ProductInventories> inventoryUpdates) {
|
||||
logger.info("批量更新库存,更新数量:{}", inventoryUpdates.size());
|
||||
return productInventoriesService.batchUpdateInventory(inventoryUpdates);
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductSkus;
|
||||
import com.qf.backend.service.ProductSkusService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品SKU控制器
|
||||
* 处理商品SKU相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/product-skus")
|
||||
@RestController
|
||||
public class ProductSkusController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductSkusController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductSkusService productSkusService;
|
||||
|
||||
/**
|
||||
* 根据商品ID查询SKU
|
||||
* @param productId 商品ID
|
||||
* @return SKU列表
|
||||
*/
|
||||
@GetMapping("/product/{productId}")
|
||||
public Result<List<ProductSkus>> getSkusByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID查询SKU,商品ID:{}", productId);
|
||||
return productSkusService.getSkusByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据SKU编码查询SKU
|
||||
* @param skuCode SKU编码
|
||||
* @return SKU信息
|
||||
*/
|
||||
@GetMapping("/code/{skuCode}")
|
||||
public Result<ProductSkus> getSkuByCode(@PathVariable String skuCode) {
|
||||
logger.info("根据SKU编码查询SKU,SKU编码:{}", skuCode);
|
||||
return productSkusService.getSkuByCode(skuCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建SKU
|
||||
* @param productSkus SKU信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createSku(@RequestBody ProductSkus productSkus) {
|
||||
logger.info("创建SKU,SKU信息:{}", productSkus);
|
||||
return productSkusService.createSku(productSkus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新SKU信息
|
||||
* @param productSkus SKU信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateSku(@RequestBody ProductSkus productSkus) {
|
||||
logger.info("更新SKU信息,SKU信息:{}", productSkus);
|
||||
return productSkusService.updateSku(productSkus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除SKU
|
||||
* @param id SKU ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteSku(@PathVariable Long id) {
|
||||
logger.info("删除SKU,SKU ID:{}", id);
|
||||
return productSkusService.deleteSku(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据SKU ID查询SKU
|
||||
* @param id SKU ID
|
||||
* @return SKU信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ProductSkus> getSkuById(@PathVariable Long id) {
|
||||
logger.info("根据SKU ID查询SKU,SKU ID:{}", id);
|
||||
return productSkusService.getSkuById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量创建SKU
|
||||
* @param skus SKU列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchCreateSkus(@RequestBody List<ProductSkus> skus) {
|
||||
logger.info("批量创建SKU,SKU数量:{}", skus.size());
|
||||
return productSkusService.batchCreateSkus(skus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID删除所有SKU
|
||||
* @param productId 商品ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete-by-product/{productId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteSkusByProductId(@PathVariable Long productId) {
|
||||
logger.info("根据商品ID删除所有SKU,商品ID:{}", productId);
|
||||
return productSkusService.deleteSkusByProductId(productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新SKU库存
|
||||
* @param skuId SKU ID
|
||||
* @param quantity 库存数量
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update-stock/{skuId}/{quantity}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateSkuStock(@PathVariable Long skuId, @PathVariable Integer quantity) {
|
||||
logger.info("更新SKU库存,SKU ID:{},库存数量:{}", skuId, quantity);
|
||||
return productSkusService.updateSkuStock(skuId, quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询SKU
|
||||
* @param skuIds SKU ID列表
|
||||
* @return SKU列表
|
||||
*/
|
||||
@PostMapping("/batch-get")
|
||||
public Result<List<ProductSkus>> batchGetSkus(@RequestBody List<Long> skuIds) {
|
||||
logger.info("批量查询SKU,SKU ID数量:{}", skuIds.size());
|
||||
return productSkusService.batchGetSkus(skuIds);
|
||||
}
|
||||
}
|
||||
@@ -1,151 +1,150 @@
|
||||
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.GetMapping;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Products;
|
||||
import com.qf.backend.service.ProductsService;
|
||||
import java.util.List;
|
||||
import com.qf.backend.dto.request.PageRequest;
|
||||
import com.qf.backend.dto.request.ProductRequest;
|
||||
import com.qf.backend.dto.response.ProductsResponse;
|
||||
import com.qf.backend.entity.Product.Products;
|
||||
import com.qf.backend.service.Products.ProductsService;
|
||||
|
||||
/**
|
||||
* 商品控制器
|
||||
* 商品控制器 (商品接口)
|
||||
* 处理商品相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*
|
||||
* @author 30803
|
||||
*/
|
||||
@RequestMapping("/api/products")
|
||||
@RestController
|
||||
@RequestMapping("/api/products")
|
||||
public class ProductsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProductsController.class);
|
||||
|
||||
@Autowired
|
||||
private ProductsService productsService;
|
||||
|
||||
/**
|
||||
* 根据商品名称查询商品
|
||||
* @param productName 商品名称
|
||||
* @return 商品列表
|
||||
* 获取商品详情
|
||||
* @param productRequest 商品ID请求
|
||||
* @return 商品信息
|
||||
*/
|
||||
@GetMapping("/name/{productName}")
|
||||
public Result<List<Products>> getProductsByName(@PathVariable String productName) {
|
||||
logger.info("根据商品名称查询商品,商品名称:{}", productName);
|
||||
return productsService.getProductsByName(productName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID查询商品
|
||||
* @param categoryId 分类ID
|
||||
* @return 商品列表
|
||||
*/
|
||||
@GetMapping("/category/{categoryId}")
|
||||
public Result<List<Products>> getProductsByCategoryId(@PathVariable Long categoryId) {
|
||||
logger.info("根据分类ID查询商品,分类ID:{}", categoryId);
|
||||
return productsService.getProductsByCategoryId(categoryId);
|
||||
@PostMapping("/getproductinfo")
|
||||
public Result<ProductsResponse> getProductInfo(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("获取商品信息请求,商品ID:{}", productRequest.getId());
|
||||
return productsService.getProductById(productRequest.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品
|
||||
* @param products 商品信息
|
||||
* @return 是否成功
|
||||
* @param productRequest 商品信息
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createProduct(@RequestBody Products products) {
|
||||
logger.info("创建商品,商品信息:{}", products);
|
||||
// 只有管理员或店铺所有者才能创建商品
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
||||
public Result<Boolean> createProduct(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("创建商品请求,商品信息:{}", productRequest);
|
||||
Products products = new Products(null, productRequest.getProductName(), productRequest.getShopId(),
|
||||
productRequest.getCategoryId(), productRequest.getDescription(), productRequest.getOriginalPrice(),
|
||||
productRequest.getCurrentPrice(), 0, 1, productRequest.getMainImage(), 0, null, null);
|
||||
return productsService.createProduct(products);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品信息
|
||||
* @param products 商品信息
|
||||
* @return 是否成功
|
||||
* @param productRequest 商品信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateProduct(@RequestBody Products products) {
|
||||
logger.info("更新商品信息,商品信息:{}", products);
|
||||
@PostMapping("/update")
|
||||
// 只有管理员或店铺所有者才能更新商品
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
||||
public Result<Boolean> updateProduct(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("更新商品信息请求,更新信息:{}", productRequest);
|
||||
Products products = new Products(productRequest.getId(), productRequest.getProductName(), productRequest.getShopId(),
|
||||
productRequest.getCategoryId(), productRequest.getDescription(), productRequest.getOriginalPrice(),
|
||||
productRequest.getCurrentPrice(), null, productRequest.getStatus(), productRequest.getMainImage(), null, null, null);
|
||||
return productsService.updateProduct(products);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param id 商品ID
|
||||
* @return 是否成功
|
||||
* @param productRequest 商品ID请求
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteProduct(@PathVariable Long id) {
|
||||
logger.info("删除商品,商品ID:{}", id);
|
||||
return productsService.deleteProduct(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID查询商品
|
||||
* @param id 商品ID
|
||||
* @return 商品信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Products> getProductById(@PathVariable Long id) {
|
||||
logger.info("根据商品ID查询商品,商品ID:{}", id);
|
||||
return productsService.getProductById(id);
|
||||
@PostMapping("/delete")
|
||||
// 只有管理员或店铺所有者才能删除商品
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
||||
public Result<Boolean> deleteProduct(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("删除商品请求,商品ID:{}", productRequest.getId());
|
||||
return productsService.deleteProduct(productRequest.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询商品
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @param pageRequest 分页请求
|
||||
* @return 商品列表
|
||||
*/
|
||||
@GetMapping("/page/{page}/{size}")
|
||||
public Result<List<Products>> listProductsByPage(@PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询商品,页码:{},每页数量:{}", page, size);
|
||||
return productsService.listProductsByPage(page, size);
|
||||
@PostMapping("/list")
|
||||
public Result<List<Products>> listProductsByPage(@RequestBody PageRequest pageRequest) {
|
||||
logger.info("分页查询商品请求,页码:{},每页大小:{}", pageRequest.getPage(), pageRequest.getSize());
|
||||
return productsService.listProductsByPage(pageRequest.getPage(), pageRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID查询商品
|
||||
* @param productRequest 分类ID请求
|
||||
* @return 商品列表
|
||||
*/
|
||||
@PostMapping("/bycategory")
|
||||
public Result<List<Products>> getProductsByCategory(@RequestBody ProductRequest productRequest ) {
|
||||
logger.info("根据分类ID查询商品请求,分类ID:{},页码:{},每页大小:{}",
|
||||
productRequest.getCategoryId(), productRequest.getPage(), productRequest.getSize());
|
||||
return productsService.getProductsByCategoryId(productRequest.getCategoryId(), productRequest.getPage(), productRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询商品
|
||||
* @param shopId 店铺ID
|
||||
* @param productRequest 店铺ID请求
|
||||
* @return 商品列表
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}")
|
||||
public Result<List<Products>> getProductsByShopId(@PathVariable Long shopId) {
|
||||
logger.info("根据店铺ID查询商品,店铺ID:{}", shopId);
|
||||
return productsService.getProductsByShopId(shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上下架商品
|
||||
* @param ids 商品ID列表
|
||||
* @param status 状态(上架/下架)
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/batch-status")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchUpdateProductStatus(@RequestBody List<Long> ids, @RequestParam Integer status) {
|
||||
logger.info("批量上下架商品,商品ID数量:{},状态:{}", ids.size(), status);
|
||||
return productsService.batchUpdateProductStatus(ids, status);
|
||||
@PostMapping("/byshop")
|
||||
public Result<List<Products>> getProductsByShop(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("根据店铺ID查询商品请求,店铺ID:{},页码:{},每页大小:{}",
|
||||
productRequest.getShopId(), productRequest.getPage(), productRequest.getSize());
|
||||
return productsService.getProductsByShopIds(List.of(productRequest.getShopId()), productRequest.getPage(), productRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索商品
|
||||
* @param keyword 关键词
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @param productRequest 搜索请求
|
||||
* @return 商品列表
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public Result<List<Products>> searchProducts(@RequestParam String keyword, @RequestParam int page, @RequestParam int size) {
|
||||
logger.info("搜索商品,关键词:{},页码:{},每页数量:{}", keyword, page, size);
|
||||
return productsService.searchProducts(keyword, page, size);
|
||||
@PostMapping("/search")
|
||||
public Result<List<Products>> searchProducts(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("搜索商品请求,关键词:{},页码:{},每页大小:{}",
|
||||
productRequest.getKeyword(), productRequest.getPage(), productRequest.getSize());
|
||||
return productsService.searchProducts(productRequest.getKeyword(), productRequest.getPage(), productRequest.getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上下架商品
|
||||
* @param productRequest 批量操作请求
|
||||
* @return 操作结果
|
||||
*/
|
||||
@PostMapping("/batchupdate")
|
||||
// 只有管理员或店铺所有者才能批量操作商品
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or #shopId == authentication.principal.shopId")
|
||||
public Result<Boolean> batchUpdateProductStatus(@RequestBody ProductRequest productRequest) {
|
||||
logger.info("批量上下架商品请求,商品ID列表:{},状态:{}", productRequest.getIds(), productRequest.getStatus());
|
||||
return productsService.batchUpdateProductStatus(productRequest.getIds(), productRequest.getStatus());
|
||||
}
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Refunds;
|
||||
import com.qf.backend.service.RefundsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 退款控制器
|
||||
* 处理退款相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/refunds")
|
||||
@RestController
|
||||
public class RefundsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RefundsController.class);
|
||||
|
||||
@Autowired
|
||||
private RefundsService refundsService;
|
||||
|
||||
/**
|
||||
* 根据订单ID查询退款记录
|
||||
* @param orderId 订单ID
|
||||
* @return 退款记录列表
|
||||
*/
|
||||
@GetMapping("/order/{orderId}")
|
||||
public Result<List<Refunds>> getRefundsByOrderId(@PathVariable Long orderId) {
|
||||
logger.info("根据订单ID查询退款记录,订单ID:{}", orderId);
|
||||
List<Refunds> refunds = refundsService.getRefundsByOrderId(orderId);
|
||||
return Result.success(refunds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据退款单号查询退款记录
|
||||
* @param refundNumber 退款单号
|
||||
* @return 退款记录
|
||||
*/
|
||||
@GetMapping("/number/{refundNumber}")
|
||||
public Result<Refunds> getRefundByNumber(@PathVariable String refundNumber) {
|
||||
logger.info("根据退款单号查询退款记录,退款单号:{}", refundNumber);
|
||||
Refunds refund = refundsService.getRefundByNumber(refundNumber);
|
||||
return Result.success(refund);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建退款记录
|
||||
* @param refunds 退款信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createRefund(@RequestBody Refunds refunds) {
|
||||
logger.info("创建退款记录,退款信息:{}", refunds);
|
||||
boolean result = refundsService.createRefund(refunds);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新退款信息
|
||||
* @param refunds 退款信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateRefund(@RequestBody Refunds refunds) {
|
||||
logger.info("更新退款信息,退款信息:{}", refunds);
|
||||
boolean result = refundsService.updateRefund(refunds);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除退款记录
|
||||
* @param id 退款ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteRefund(@PathVariable Long id) {
|
||||
logger.info("删除退款记录,退款ID:{}", id);
|
||||
boolean result = refundsService.deleteRefund(id);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据退款ID查询退款记录
|
||||
* @param id 退款ID
|
||||
* @return 退款记录
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Refunds> getRefundById(@PathVariable Long id) {
|
||||
logger.info("根据退款ID查询退款记录,退款ID:{}", id);
|
||||
Refunds refund = refundsService.getRefundById(id);
|
||||
return Result.success(refund);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询退款记录
|
||||
* @param userId 用户ID
|
||||
* @return 退款记录列表
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
public Result<List<Refunds>> getRefundsByUserId(@PathVariable Long userId) {
|
||||
logger.info("根据用户ID查询退款记录,用户ID:{}", userId);
|
||||
List<Refunds> refunds = refundsService.getRefundsByUserId(userId);
|
||||
return Result.success(refunds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据退款状态查询退款记录
|
||||
* @param status 退款状态
|
||||
* @return 退款记录列表
|
||||
*/
|
||||
@GetMapping("/status/{status}")
|
||||
public Result<List<Refunds>> getRefundsByStatus(@PathVariable Integer status) {
|
||||
logger.info("根据退款状态查询退款记录,状态:{}", status);
|
||||
List<Refunds> refunds = refundsService.getRefundsByStatus(status);
|
||||
return Result.success(refunds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新退款状态
|
||||
* @param refundId 退款ID
|
||||
* @param status 退款状态
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update-status/{refundId}/{status}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateRefundStatus(@PathVariable Long refundId, @PathVariable Integer status) {
|
||||
logger.info("更新退款状态,退款ID:{},状态:{}", refundId, status);
|
||||
boolean result = refundsService.updateRefundStatus(refundId, status);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询退款记录
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 退款记录列表
|
||||
*/
|
||||
@GetMapping("/page/{page}/{size}")
|
||||
public Result<List<Refunds>> listRefundsByPage(@PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询退款记录,页码:{},每页数量:{}", page, size);
|
||||
List<Refunds> refunds = refundsService.listRefundsByPage(page, size);
|
||||
return Result.success(refunds);
|
||||
}
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.RolePermissions;
|
||||
import com.qf.backend.service.RolePermissionsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色权限关联控制器
|
||||
* 处理角色与权限关联相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/role-permissions")
|
||||
@RestController
|
||||
public class RolePermissionsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RolePermissionsController.class);
|
||||
|
||||
@Autowired
|
||||
private RolePermissionsService rolePermissionsService;
|
||||
|
||||
/**
|
||||
* 根据角色ID查询角色权限关联
|
||||
* @param roleId 角色ID
|
||||
* @return 角色权限关联列表
|
||||
*/
|
||||
@GetMapping("/role/{roleId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<RolePermissions>> getRolePermissionsByRoleId(@PathVariable Long roleId) {
|
||||
logger.info("管理员根据角色ID查询角色权限关联,角色ID:{}", roleId);
|
||||
List<RolePermissions> rolePermissions = rolePermissionsService.getRolePermissionsByRoleId(roleId);
|
||||
return Result.success(rolePermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据权限ID查询角色权限关联
|
||||
* @param permissionId 权限ID
|
||||
* @return 角色权限关联列表
|
||||
*/
|
||||
@GetMapping("/permission/{permissionId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<RolePermissions>> getRolePermissionsByPermissionId(@PathVariable Long permissionId) {
|
||||
logger.info("管理员根据权限ID查询角色权限关联,权限ID:{}", permissionId);
|
||||
List<RolePermissions> rolePermissions = rolePermissionsService.getRolePermissionsByPermissionId(permissionId);
|
||||
return Result.success(rolePermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为角色添加权限
|
||||
* @param request 角色权限关联请求体
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> addPermissionToRole(@RequestBody RolePermissionRequest request) {
|
||||
logger.info("管理员为角色添加权限,角色ID:{},权限ID:{}", request.getRoleId(), request.getPermissionId());
|
||||
boolean result = rolePermissionsService.addPermissionToRole(request.getRoleId(), request.getPermissionId());
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从角色移除权限
|
||||
* @param request 角色权限关联请求体
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/remove")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> removePermissionFromRole(@RequestBody RolePermissionRequest request) {
|
||||
logger.info("管理员从角色移除权限,角色ID:{},权限ID:{}", request.getRoleId(), request.getPermissionId());
|
||||
boolean result = rolePermissionsService.removePermissionFromRole(request.getRoleId(), request.getPermissionId());
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量为角色添加权限
|
||||
* @param request 批量角色权限关联请求体
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-add")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchAddPermissionsToRole(@RequestBody BatchRolePermissionRequest request) {
|
||||
logger.info("管理员批量为角色添加权限,角色ID:{},权限ID列表:{}", request.getRoleId(), request.getPermissionIds());
|
||||
boolean result = rolePermissionsService.batchAddPermissionsToRole(request.getRoleId(), request.getPermissionIds());
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空角色的所有权限
|
||||
* @param roleId 角色ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/clear/{roleId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> clearRolePermissions(@PathVariable Long roleId) {
|
||||
logger.info("管理员清空角色的所有权限,角色ID:{}", roleId);
|
||||
boolean result = rolePermissionsService.clearRolePermissions(roleId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查角色是否拥有指定权限
|
||||
* @param roleId 角色ID
|
||||
* @param permissionId 权限ID
|
||||
* @return 是否拥有
|
||||
*/
|
||||
@GetMapping("/check")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> checkRoleHasPermission(Long roleId, Long permissionId) {
|
||||
logger.info("管理员检查角色是否拥有指定权限,角色ID:{},权限ID:{}", roleId, permissionId);
|
||||
boolean result = rolePermissionsService.checkRoleHasPermission(roleId, permissionId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询其拥有的权限ID列表
|
||||
* @param roleId 角色ID
|
||||
* @return 权限ID列表
|
||||
*/
|
||||
@GetMapping("/permission-ids/{roleId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Long>> listPermissionIdsByRoleId(@PathVariable Long roleId) {
|
||||
logger.info("管理员根据角色ID查询其拥有的权限ID列表,角色ID:{}", roleId);
|
||||
List<Long> permissionIds = rolePermissionsService.listPermissionIdsByRoleId(roleId);
|
||||
return Result.success(permissionIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色权限关联请求体
|
||||
*/
|
||||
public static class RolePermissionRequest {
|
||||
private Long roleId;
|
||||
private Long permissionId;
|
||||
|
||||
// getter和setter
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
public void setRoleId(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
public Long getPermissionId() {
|
||||
return permissionId;
|
||||
}
|
||||
public void setPermissionId(Long permissionId) {
|
||||
this.permissionId = permissionId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量角色权限关联请求体
|
||||
*/
|
||||
public static class BatchRolePermissionRequest {
|
||||
private Long roleId;
|
||||
private List<Long> permissionIds;
|
||||
|
||||
// getter和setter
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
public void setRoleId(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
public List<Long> getPermissionIds() {
|
||||
return permissionIds;
|
||||
}
|
||||
public void setPermissionIds(List<Long> permissionIds) {
|
||||
this.permissionIds = permissionIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Roles;
|
||||
import com.qf.backend.service.RolesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色管理控制器
|
||||
* 处理角色相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
* @author 30803
|
||||
*/
|
||||
@RequestMapping("/api/roles")
|
||||
@RestController
|
||||
public class RolesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(RolesController.class);
|
||||
|
||||
@Autowired
|
||||
private RolesService rolesService;
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
* @return 角色列表
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Roles>> listAllRoles() {
|
||||
logger.info("管理员查询所有角色");
|
||||
return rolesService.listAllRoles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色ID查询角色
|
||||
* @param id 角色ID
|
||||
* @return 角色信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Roles> getRoleById(@PathVariable Long id) {
|
||||
logger.info("管理员根据ID查询角色,ID:{}", id);
|
||||
return rolesService.getRoleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色名称查询角色
|
||||
* @param roleName 角色名称
|
||||
* @return 角色信息
|
||||
*/
|
||||
@GetMapping("/name/{roleName}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Roles> getRoleByName(@PathVariable String roleName) {
|
||||
logger.info("管理员根据名称查询角色,名称:{}", roleName);
|
||||
return rolesService.getRoleByName(roleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询其拥有的角色列表
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Roles>> listRolesByUserId(@PathVariable Long userId) {
|
||||
logger.info("管理员根据用户ID查询角色列表,用户ID:{}", userId);
|
||||
return rolesService.listRolesByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建角色
|
||||
* @param roles 角色信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createRole(@RequestBody Roles roles) {
|
||||
logger.info("管理员创建角色:{}", roles);
|
||||
return rolesService.createRole(roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色信息
|
||||
* @param roles 角色信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateRole(@RequestBody Roles roles) {
|
||||
logger.info("管理员更新角色:{}", roles);
|
||||
return rolesService.updateRole(roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
* @param id 角色ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteRole(@PathVariable Long id) {
|
||||
logger.info("管理员删除角色,ID:{}", id);
|
||||
return rolesService.deleteRole(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色
|
||||
* @param ids 角色ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/batch")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchDeleteRoles(@RequestBody List<Long> ids) {
|
||||
logger.info("管理员批量删除角色,IDs:{}", ids);
|
||||
return rolesService.batchDeleteRoles(ids);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ShopCategories;
|
||||
import com.qf.backend.service.ShopCategoriesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺分类控制器
|
||||
* 处理店铺分类相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/shop-categories")
|
||||
@RestController
|
||||
public class ShopCategoriesController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShopCategoriesController.class);
|
||||
|
||||
@Autowired
|
||||
private ShopCategoriesService shopCategoriesService;
|
||||
|
||||
/**
|
||||
* 根据分类名称查询分类
|
||||
* @param categoryName 分类名称
|
||||
* @return 分类信息
|
||||
*/
|
||||
@GetMapping("/name/{categoryName}")
|
||||
public Result<ShopCategories> getCategoryByName(@PathVariable String categoryName) {
|
||||
logger.info("根据分类名称查询分类,分类名称:{}", categoryName);
|
||||
return shopCategoriesService.getCategoryByName(categoryName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父分类ID查询子分类
|
||||
* @param parentId 父分类ID
|
||||
* @return 子分类列表
|
||||
*/
|
||||
@GetMapping("/parent/{parentId}")
|
||||
public Result<List<ShopCategories>> getSubCategoriesByParentId(@PathVariable Long parentId) {
|
||||
logger.info("根据父分类ID查询子分类,父分类ID:{}", parentId);
|
||||
return shopCategoriesService.getSubCategoriesByParentId(parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分类
|
||||
* @param shopCategories 分类信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> createCategory(@RequestBody ShopCategories shopCategories) {
|
||||
logger.info("创建分类,分类信息:{}", shopCategories);
|
||||
return shopCategoriesService.createCategory(shopCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类信息
|
||||
* @param shopCategories 分类信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateCategory(@RequestBody ShopCategories shopCategories) {
|
||||
logger.info("更新分类信息,分类信息:{}", shopCategories);
|
||||
return shopCategoriesService.updateCategory(shopCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param id 分类ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteCategory(@PathVariable Long id) {
|
||||
logger.info("删除分类,分类ID:{}", id);
|
||||
return shopCategoriesService.deleteCategory(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有根分类(父分类ID为0或null的分类)
|
||||
* @return 根分类列表
|
||||
*/
|
||||
@GetMapping("/root")
|
||||
public Result<List<ShopCategories>> listRootCategories() {
|
||||
logger.info("查询所有根分类");
|
||||
return shopCategoriesService.listRootCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID查询分类
|
||||
* @param id 分类ID
|
||||
* @return 分类信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ShopCategories> getCategoryById(@PathVariable Long id) {
|
||||
logger.info("根据分类ID查询分类,分类ID:{}", id);
|
||||
return shopCategoriesService.getCategoryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除分类
|
||||
* @param ids 分类ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/batch-delete")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchDeleteCategories(@RequestBody List<Long> ids) {
|
||||
logger.info("批量删除分类,分类ID数量:{}", ids.size());
|
||||
return shopCategoriesService.batchDeleteCategories(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有分类(树形结构)
|
||||
* @return 分类树形列表
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
public Result<List<ShopCategories>> listAllCategoriesWithTree() {
|
||||
logger.info("查询所有分类(树形结构)");
|
||||
return shopCategoriesService.listAllCategoriesWithTree();
|
||||
}
|
||||
}
|
||||
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,161 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ShopRatings;
|
||||
import com.qf.backend.service.ShopRatingsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺评分控制器
|
||||
* 处理店铺评分相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/shop-ratings")
|
||||
@RestController
|
||||
public class ShopRatingsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShopRatingsController.class);
|
||||
|
||||
@Autowired
|
||||
private ShopRatingsService shopRatingsService;
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询评分
|
||||
* @param shopId 店铺ID
|
||||
* @return 评分列表
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}")
|
||||
public Result<List<ShopRatings>> getRatingsByShopId(@PathVariable Long shopId) {
|
||||
logger.info("根据店铺ID查询评分,店铺ID:{}", shopId);
|
||||
return shopRatingsService.getRatingsByShopId(shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询评分
|
||||
* @param userId 用户ID
|
||||
* @return 评分列表
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
public Result<List<ShopRatings>> getRatingsByUserId(@PathVariable Long userId) {
|
||||
logger.info("根据用户ID查询评分,用户ID:{}", userId);
|
||||
return shopRatingsService.getRatingsByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建评分
|
||||
* @param shopRatings 评分信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createRating(@RequestBody ShopRatings shopRatings) {
|
||||
logger.info("创建评分,评分信息:{}", shopRatings);
|
||||
return shopRatingsService.createRating(shopRatings);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新评分信息
|
||||
* @param shopRatings 评分信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> updateRating(@RequestBody ShopRatings shopRatings) {
|
||||
logger.info("更新评分信息,评分信息:{}", shopRatings);
|
||||
return shopRatingsService.updateRating(shopRatings);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评分
|
||||
* @param id 评分ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteRating(@PathVariable Long id) {
|
||||
logger.info("删除评分,评分ID:{}", id);
|
||||
return shopRatingsService.deleteRating(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据评分ID查询评分
|
||||
* @param id 评分ID
|
||||
* @return 评分信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<ShopRatings> getRatingById(@PathVariable Long id) {
|
||||
logger.info("根据评分ID查询评分,评分ID:{}", id);
|
||||
return shopRatingsService.getRatingById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺平均评分
|
||||
* @param shopId 店铺ID
|
||||
* @return 平均评分
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}/average")
|
||||
public Result<Double> getAverageRatingByShopId(@PathVariable Long shopId) {
|
||||
logger.info("获取店铺平均评分,店铺ID:{}", shopId);
|
||||
return shopRatingsService.getAverageRatingByShopId(shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺评分数量
|
||||
* @param shopId 店铺ID
|
||||
* @return 评分数量
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}/count")
|
||||
public Result<Integer> getRatingCountByShopId(@PathVariable Long shopId) {
|
||||
logger.info("获取店铺评分数量,店铺ID:{}", shopId);
|
||||
return shopRatingsService.getRatingCountByShopId(shopId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据评分星级查询店铺评分
|
||||
* @param shopId 店铺ID
|
||||
* @param rating 评分星级
|
||||
* @return 评分列表
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}/rating/{rating}")
|
||||
public Result<List<ShopRatings>> getRatingsByShopIdAndRating(@PathVariable Long shopId, @PathVariable Integer rating) {
|
||||
logger.info("根据评分星级查询店铺评分,店铺ID:{},评分星级:{}", shopId, rating);
|
||||
return shopRatingsService.getRatingsByShopIdAndRating(shopId, rating);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否已对店铺评分
|
||||
* @param shopId 店铺ID
|
||||
* @param userId 用户ID
|
||||
* @return 是否已评分
|
||||
*/
|
||||
@GetMapping("/check")
|
||||
public Result<Boolean> checkUserHasRated(@RequestParam Long shopId, @RequestParam Long userId) {
|
||||
logger.info("检查用户是否已对店铺评分,店铺ID:{},用户ID:{}", shopId, userId);
|
||||
return shopRatingsService.checkUserHasRated(shopId, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询店铺评分
|
||||
* @param shopId 店铺ID
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 评分列表
|
||||
*/
|
||||
@GetMapping("/shop/{shopId}/page/{page}/{size}")
|
||||
public Result<List<ShopRatings>> listRatingsByShopIdAndPage(@PathVariable Long shopId, @PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询店铺评分,店铺ID:{},页码:{},每页数量:{}", shopId, page, size);
|
||||
return shopRatingsService.listRatingsByShopIdAndPage(shopId, page, size);
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.qf.backend.controller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Shops;
|
||||
import com.qf.backend.service.ShopsService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 店铺控制器
|
||||
* 处理店铺相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*/
|
||||
@RequestMapping("/api/shops")
|
||||
@RestController
|
||||
public class ShopsController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ShopsController.class);
|
||||
|
||||
@Autowired
|
||||
private ShopsService shopsService;
|
||||
|
||||
/**
|
||||
* 根据店铺名称查询店铺
|
||||
* @param shopName 店铺名称
|
||||
* @return 店铺列表
|
||||
*/
|
||||
@GetMapping("/name/{shopName}")
|
||||
public Result<List<Shops>> getShopsByName(@PathVariable String shopName) {
|
||||
logger.info("根据店铺名称查询店铺,店铺名称:{}", shopName);
|
||||
return shopsService.getShopsByName(shopName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询店铺
|
||||
* @param userId 用户ID
|
||||
* @return 店铺信息
|
||||
*/
|
||||
@GetMapping("/user/{userId}")
|
||||
public Result<Shops> getShopByUserId(@PathVariable Long userId) {
|
||||
logger.info("根据用户ID查询店铺,用户ID:{}", userId);
|
||||
return shopsService.getShopByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建店铺
|
||||
* @param shops 店铺信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> createShop(@RequestBody Shops shops) {
|
||||
logger.info("创建店铺,店铺信息:{}", shops);
|
||||
return shopsService.createShop(shops);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新店铺信息
|
||||
* @param shops 店铺信息
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
|
||||
public Result<Boolean> updateShop(@RequestBody Shops shops) {
|
||||
logger.info("更新店铺信息,店铺信息:{}", shops);
|
||||
return shopsService.updateShop(shops);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除店铺
|
||||
* @param id 店铺ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> deleteShop(@PathVariable Long id) {
|
||||
logger.info("删除店铺,店铺ID:{}", id);
|
||||
return shopsService.deleteShop(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺ID查询店铺
|
||||
* @param id 店铺ID
|
||||
* @return 店铺信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Shops> getShopById(@PathVariable Long id) {
|
||||
logger.info("根据店铺ID查询店铺,店铺ID:{}", id);
|
||||
return shopsService.getShopById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询店铺
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 店铺列表
|
||||
*/
|
||||
@GetMapping("/page/{page}/{size}")
|
||||
public Result<List<Shops>> listShopsByPage(@PathVariable int page, @PathVariable int size) {
|
||||
logger.info("分页查询店铺,页码:{},每页数量:{}", page, size);
|
||||
return shopsService.listShopsByPage(page, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据店铺分类ID查询店铺
|
||||
* @param categoryId 分类ID
|
||||
* @return 店铺列表
|
||||
*/
|
||||
@GetMapping("/category/{categoryId}")
|
||||
public Result<List<Shops>> getShopsByCategoryId(@PathVariable Long categoryId) {
|
||||
logger.info("根据店铺分类ID查询店铺,分类ID:{}", categoryId);
|
||||
return shopsService.getShopsByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新店铺状态
|
||||
* @param shopId 店铺ID
|
||||
* @param status 店铺状态
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PutMapping("/update-status/{shopId}/{status}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> updateShopStatus(@PathVariable Long shopId, @PathVariable Integer status) {
|
||||
logger.info("更新店铺状态,店铺ID:{},状态:{}", shopId, status);
|
||||
return shopsService.updateShopStatus(shopId, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索店铺
|
||||
* @param keyword 关键词
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 店铺列表
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public Result<List<Shops>> searchShops(@RequestParam String keyword, @RequestParam int page, @RequestParam int size) {
|
||||
logger.info("搜索店铺,关键词:{},页码:{},每页数量:{}", keyword, page, size);
|
||||
return shopsService.searchShops(keyword, page, size);
|
||||
}
|
||||
}
|
||||
@@ -1,169 +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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.UserRoles;
|
||||
import com.qf.backend.service.UserRolesService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户角色关联控制器
|
||||
* 处理用户与角色关联相关的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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为用户添加角色
|
||||
* @param userId 用户ID
|
||||
* @param roleId 角色ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> addRoleToUser(@RequestBody UserRolesRequest request) {
|
||||
logger.info("管理员为用户添加角色,用户ID:{},角色ID:{}", request.getUserId(), request.getRoleId());
|
||||
return userRolesService.addRoleToUser(request.getUserId(), request.getRoleId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 从用户移除角色
|
||||
* @param userId 用户ID
|
||||
* @param roleId 角色ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/remove")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> removeRoleFromUser(@RequestBody UserRolesRequest request) {
|
||||
logger.info("管理员从用户移除角色,用户ID:{},角色ID:{}", request.getUserId(), request.getRoleId());
|
||||
return userRolesService.removeRoleFromUser(request.getUserId(), request.getRoleId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量为用户添加角色
|
||||
* @param userId 用户ID
|
||||
* @param roleIds 角色ID列表
|
||||
* @return 是否成功
|
||||
*/
|
||||
@PostMapping("/batch-add")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> batchAddRolesToUser(@RequestBody BatchUserRolesRequest request) {
|
||||
logger.info("管理员批量为用户添加角色,用户ID:{},角色ID列表:{}", request.getUserId(), request.getRoleIds());
|
||||
return userRolesService.batchAddRolesToUser(request.getUserId(), request.getRoleIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空用户的所有角色
|
||||
* @param userId 用户ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
@DeleteMapping("/clear/{userId}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> clearUserRoles(@PathVariable Long userId) {
|
||||
logger.info("管理员清空用户的所有角色,用户ID:{}", userId);
|
||||
return userRolesService.clearUserRoles(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否拥有指定角色
|
||||
* @param userId 用户ID
|
||||
* @param roleId 角色ID
|
||||
* @return 是否拥有
|
||||
*/
|
||||
@GetMapping("/check")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Boolean> checkUserHasRole(Long userId, Long roleId) {
|
||||
logger.info("管理员检查用户是否拥有指定角色,用户ID:{},角色ID:{}", userId, roleId);
|
||||
return userRolesService.checkUserHasRole(userId, roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户角色关联请求体
|
||||
*/
|
||||
public static class UserRolesRequest {
|
||||
private Long userId;
|
||||
private Long roleId;
|
||||
|
||||
// getter和setter
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
public void setRoleId(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量用户角色关联请求体
|
||||
*/
|
||||
public static class BatchUserRolesRequest {
|
||||
private Long userId;
|
||||
private List<Long> roleIds;
|
||||
|
||||
// getter和setter
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public List<Long> getRoleIds() {
|
||||
return roleIds;
|
||||
}
|
||||
public void setRoleIds(List<Long> roleIds) {
|
||||
this.roleIds = roleIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,102 @@
|
||||
/*
|
||||
* 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
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 org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Users;
|
||||
import com.qf.backend.service.UsersService;
|
||||
import java.util.List;
|
||||
import com.qf.backend.dto.request.UsersRequest;
|
||||
import com.qf.backend.entity.User.Users;
|
||||
import com.qf.backend.service.User.UsersService;
|
||||
|
||||
|
||||
/**
|
||||
* 用户管理控制器
|
||||
* 用户控制器 (用户接口)
|
||||
* 处理用户相关的HTTP请求
|
||||
* 遵循RESTful API设计规范
|
||||
*
|
||||
* @author 30803
|
||||
*/
|
||||
@RequestMapping("/api/users")
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UsersController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UsersController.class);
|
||||
@Autowired
|
||||
private UsersService usersService;
|
||||
|
||||
/**
|
||||
* 分页获取用户列表 仅管理员角色
|
||||
* @param pageNum 页码
|
||||
* @param pageSize 每页数量
|
||||
* @return 用户列表
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Users>> listUsersByPage(int pageNum, int pageSize) {
|
||||
logger.info("管理员获取用户列表,页码:{},每页数量:{}", pageNum, pageSize);
|
||||
return usersService.listUsersByPage(pageNum, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询用户 仅管理员角色
|
||||
* @param id 用户ID
|
||||
* 获取用户信息
|
||||
* @param usersRequest 用户ID请求
|
||||
* @return 用户信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Users> getUserById(@PathVariable Long id) {
|
||||
logger.info("管理员根据id查询用户,id:{}", id);
|
||||
return usersService.getUserById(id);
|
||||
@PostMapping("/getuserinfo")
|
||||
// 只有用户本人或管理员才能获取用户信息
|
||||
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||
public Result<Users> getUserInfo(@RequestBody UsersRequest usersRequest) {
|
||||
logger.info("获取用户信息请求,用户ID:{}", usersRequest.getId());
|
||||
return usersService.getUserById(usersRequest.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询用户 用户可以查询自己的信息
|
||||
* @param username 用户名
|
||||
* @return 用户信息
|
||||
* 更新用户信息
|
||||
* @param usersRequest 用户信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
@GetMapping("/username/{username}")
|
||||
// @PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Users> getUserByUsername(@PathVariable String username) {
|
||||
logger.info("管理员根据用户名查询用户,用户名:{}", username);
|
||||
return usersService.getUserByUsername(username);
|
||||
@PostMapping("/info")
|
||||
// 只有用户本人或管理员才能更新用户信息
|
||||
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||
public Result<Boolean> updateUserInfo(@RequestBody UsersRequest usersRequest) {
|
||||
logger.info("更新用户信息请求,更新信息:{}", usersRequest);
|
||||
Users users = new Users(usersRequest.getId(), usersRequest.getUsername(), usersRequest.getPassword(),
|
||||
usersRequest.getEmail(), usersRequest.getPhone(), usersRequest.getAvatar(), null, 1, null, null);
|
||||
return usersService.updateUser(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据邮箱查询用户 仅管理员角色
|
||||
* @param email 邮箱
|
||||
* @return 用户信息
|
||||
* 注销登录
|
||||
* 修改用户状态为2(删除)
|
||||
* @param usersRequest 注销请求
|
||||
* @return 注销结果
|
||||
*/
|
||||
@GetMapping("/email/{email}")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<Users> getUserByEmail(@PathVariable String email) {
|
||||
logger.info("管理员根据邮箱查询用户,邮箱:{}", email);
|
||||
return usersService.getUserByEmail(email);
|
||||
@PostMapping("/logout")
|
||||
// 只有用户本人或管理员才能注销登录
|
||||
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||
public Result<Boolean> logout(@RequestBody UsersRequest usersRequest) {
|
||||
logger.info("注销登录请求,用户ID:{}", usersRequest.getId());
|
||||
return usersService.deleteUser(usersRequest.getId(),usersRequest.getStatus() );
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有用户 仅管理员角色
|
||||
* @return 用户列表
|
||||
* 重置密码
|
||||
*
|
||||
* @param usersRequest 重置密码请求
|
||||
* @return 重置结果
|
||||
*/
|
||||
@GetMapping
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Result<List<Users>> listAllUsers() {
|
||||
logger.info("管理员查询所有用户");
|
||||
return usersService.listAllUsers();
|
||||
@PostMapping("/resetpassword")
|
||||
// 只有用户本人或管理员才能重置密码
|
||||
@PreAuthorize("#usersRequest.id == authentication.principal.userId or hasRole('ROLE_ADMIN')") // SpEL 表达式
|
||||
public Result<Boolean> resetPassword(@RequestBody UsersRequest usersRequest) {
|
||||
logger.info("重置密码请求,用户ID:{}", usersRequest.getId());
|
||||
return usersService.updatePassword(usersRequest.getId(), usersRequest.getPassword());
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
* 默认为1,启用状态
|
||||
* @param usersRequest 注册请求
|
||||
* @return 注册结果
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public Result<Boolean> registerUser(@RequestBody UsersRequest usersRequest) {
|
||||
logger.info("用户注册请求,注册信息:{}", usersRequest);
|
||||
Users users = new Users(null, usersRequest.getUsername(), usersRequest.getPassword(), usersRequest.getEmail(),
|
||||
usersRequest.getPhone(), usersRequest.getAvatar(), null, 1, null, null);
|
||||
return usersService.createUser(users);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.qf.backend.dto;
|
||||
|
||||
public class ProductsDataList {
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.qf.backend.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.qf.backend.entity.Users;
|
||||
|
||||
public class UserDataList {
|
||||
private List<Users> userDataList;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.qf.backend.dto;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户DTO 用于表示用户结构(包含用户的基本信息 和 角色信息)
|
||||
* @author 30803
|
||||
* @date 2023-12-12
|
||||
* @description 用户DTO 用于表示用户结构
|
||||
*
|
||||
*/
|
||||
public class UserDto {
|
||||
private Long id; // 用户ID,主键,自增
|
||||
private String username; // 用户名
|
||||
private String email; // 邮箱
|
||||
private String phone; // 手机号
|
||||
private Integer status; // 状态:0:禁用, 1:启用
|
||||
private Long roleId; // 角色ID
|
||||
private String roleName; // 角色名称
|
||||
private String description; // 角色描述
|
||||
private Integer roleType; // 角色类型:0:默认用户,1:店主,2:管理员
|
||||
private Date createdAt; // 创建时间
|
||||
private Date updatedAt; // 更新时间
|
||||
|
||||
}
|
||||
@@ -3,14 +3,12 @@
|
||||
* 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.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 登录请求参数
|
||||
* @author 30803
|
||||
@@ -19,6 +17,6 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LoginRequest {
|
||||
private String username;
|
||||
private String password;
|
||||
private String username; // 用户名
|
||||
private String password; // 密码
|
||||
}
|
||||
37
src/main/java/com/qf/backend/dto/request/OrderRequest.java
Normal file
37
src/main/java/com/qf/backend/dto/request/OrderRequest.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.qf.backend.dto.request;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.qf.backend.entity.Order.OrderItems;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单请求DTO
|
||||
*/
|
||||
@Data
|
||||
public class OrderRequest {
|
||||
private Long id; // 订单ID
|
||||
private String orderNo; // 订单号
|
||||
private Long userId; // 用户ID
|
||||
private Long shopId; // 店铺ID
|
||||
private BigDecimal totalAmount; // 总金额
|
||||
private BigDecimal actualAmount; // 实际支付金额
|
||||
private BigDecimal shippingFee; // 运费
|
||||
private Integer orderStatus; // 订单状态:0:待付款, 1:待发货, 2:待收货, 3:已完成, 4:已取消, 5:已退款
|
||||
private String shippingAddress; // 收货地址
|
||||
private String receiverName; // 收件人姓名
|
||||
private String receiverPhone; // 收件人电话
|
||||
private String paymentMethod; // 支付方式
|
||||
private Date paymentTime; // 支付时间
|
||||
private Date shippingTime; // 发货时间
|
||||
private Date deliveryTime; // 送达时间
|
||||
private Date completeTime; // 完成时间
|
||||
private String remark; // 备注
|
||||
private List<OrderItems> orderItems; // 订单项列表
|
||||
|
||||
private Integer page; // 页码,用于分页查询
|
||||
private Integer size; // 每页大小,用于分页查询
|
||||
}
|
||||
10
src/main/java/com/qf/backend/dto/request/PageRequest.java
Normal file
10
src/main/java/com/qf/backend/dto/request/PageRequest.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.qf.backend.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PageRequest {
|
||||
private Integer page; // 当前页码
|
||||
private Integer size; // 每页数量
|
||||
|
||||
}
|
||||
26
src/main/java/com/qf/backend/dto/request/ProductRequest.java
Normal file
26
src/main/java/com/qf/backend/dto/request/ProductRequest.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.qf.backend.dto.request;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品请求DTO
|
||||
*/
|
||||
@Data
|
||||
public class ProductRequest {
|
||||
private Long id; // 商品ID
|
||||
private String productName; // 商品名称
|
||||
private Long shopId; // 店铺ID
|
||||
private Long categoryId; // 商品分类ID
|
||||
private String description; // 商品描述
|
||||
private BigDecimal originalPrice; // 原价
|
||||
private BigDecimal currentPrice; // 当前价格
|
||||
private Integer status; // 状态:0:下架, 1:上架
|
||||
private String mainImage; // 主图URL
|
||||
private String keyword; // 搜索关键词
|
||||
private Integer page; // 页码
|
||||
private Integer size; // 每页大小
|
||||
private List<Long> ids; // 商品ID列表,用于批量操作
|
||||
}
|
||||
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; // 每页数量,用于分页查询
|
||||
|
||||
}
|
||||
16
src/main/java/com/qf/backend/dto/request/UsersRequest.java
Normal file
16
src/main/java/com/qf/backend/dto/request/UsersRequest.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.qf.backend.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UsersRequest {
|
||||
private Long id; // 用户ID
|
||||
private String username; // 用户名,唯一
|
||||
private String password; // 密码,加密存储
|
||||
private String email; // 邮箱,唯一
|
||||
private String phone; // 手机号,唯一
|
||||
private String avatar; // 头像URL
|
||||
// 默认为1,启用状态
|
||||
private Integer status; // 状态:0:禁用, 1:启用, 2:删除
|
||||
|
||||
}
|
||||
@@ -2,10 +2,13 @@
|
||||
* 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.dto;
|
||||
package com.qf.backend.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.qf.backend.entity.User.Permissions;
|
||||
import com.qf.backend.entity.User.Roles;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -24,9 +27,10 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoginResponse {
|
||||
private Long userId; // 用户id
|
||||
private String username; // 用户名
|
||||
private List<String> roles; // 角色列表 暂时无用
|
||||
private List<String> permissions; // 权限列表 暂时无用
|
||||
private List<Roles> roles; // 角色列表 暂时无用
|
||||
private List<Permissions> permissions; // 权限列表 暂时无用
|
||||
private String token; // JWT令牌
|
||||
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;
|
||||
}
|
||||
}
|
||||
36
src/main/java/com/qf/backend/dto/response/Userresponse.java
Normal file
36
src/main/java/com/qf/backend/dto/response/Userresponse.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.qf.backend.dto.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.qf.backend.entity.User.Permissions;
|
||||
import com.qf.backend.entity.User.Roles;
|
||||
import com.qf.backend.entity.User.Users;
|
||||
|
||||
public class Userresponse {
|
||||
private Users users;
|
||||
// 角色列表
|
||||
private List<Roles> roles;
|
||||
// 权限列表
|
||||
private List<Permissions> permissions;
|
||||
|
||||
// getters and setters
|
||||
public Users getUsers() {
|
||||
return users;
|
||||
}
|
||||
public void setUsers(Users users) {
|
||||
this.users = users;
|
||||
}
|
||||
public List<Roles> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
public void setRoles(List<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.util.Date;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Order;
|
||||
|
||||
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.util.Date;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Product;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Product;
|
||||
|
||||
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.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.TableId;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Product;
|
||||
|
||||
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.util.Date;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Product;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Shop;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ShopCategories {
|
||||
private String categoryName; // 分类名称
|
||||
private Long parentId; // 父分类ID,顶级分类为0
|
||||
private Integer level; // 分类级别
|
||||
private String icon; // 分类图标
|
||||
private String icon; // 分类图标URL
|
||||
private Integer sort; // 排序
|
||||
private Integer status; // 状态:0:禁用, 1:启用
|
||||
private Date createdAt; // 创建时间
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.Shop;
|
||||
|
||||
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.util.Date;
|
||||
@@ -37,7 +37,7 @@ public class Shops {
|
||||
private BigDecimal rating; // 店铺评分
|
||||
private Integer salesVolume; // 销量
|
||||
private Integer status; // 状态:0: 未审核, 1: 已审核, 2: 已关闭, 3: 审核失败
|
||||
private String businessLicense; // 营业执照
|
||||
private String businessLicense; // 营业执照URL
|
||||
private Date businessStartTime; // 营业时间开始
|
||||
private Date businessEndTime; // 营业时间结束
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.qf.backend.entity;
|
||||
package com.qf.backend.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -21,7 +21,6 @@ import lombok.NoArgsConstructor;
|
||||
@AllArgsConstructor // 自动生成全参构造器
|
||||
@TableName("users")
|
||||
public class Users {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id; // 用户ID,主键,自增
|
||||
private String username; // 用户名,唯一
|
||||
@@ -31,7 +30,7 @@ public class Users {
|
||||
private String avatar; // 头像URL
|
||||
@TableField(exist = false) // 标记该字段在数据库中不存在
|
||||
private Date lastLoginTime; // 最后登录时间
|
||||
private Integer status; // 状态:0:禁用, 1:启用
|
||||
private Integer status; // 状态:0:禁用, 1:启用 ,2:冻结 ,默认1
|
||||
private Date createdAt; // 创建时间
|
||||
private Date updatedAt; // 更新时间
|
||||
}
|
||||
@@ -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 com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qf.backend.entity.ProductCategories;
|
||||
import com.qf.backend.entity.Products;
|
||||
import com.qf.backend.service.ProductCategoriesService;
|
||||
import com.qf.backend.service.ProductsService;
|
||||
import com.qf.backend.entity.Product.ProductCategories;
|
||||
import com.qf.backend.entity.Product.Products;
|
||||
import com.qf.backend.service.Products.ProductCategoriesService;
|
||||
import com.qf.backend.service.Products.ProductsService;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 商品数据初始化配置类,用于在系统启动时创建初始商品分类和商品信息
|
||||
|
||||
@@ -6,8 +6,10 @@ 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.Roles;
|
||||
import com.qf.backend.service.RolesService;
|
||||
import com.qf.backend.entity.User.Roles;
|
||||
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("店铺评分信息初始化完成");
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,10 @@ 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.Users;
|
||||
import com.qf.backend.service.UsersService;
|
||||
import com.qf.backend.entity.User.Users;
|
||||
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;
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.apache.ibatis.annotations.Select;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.OrderItems;
|
||||
import com.qf.backend.entity.Order.OrderItems;
|
||||
|
||||
/**
|
||||
* 订单商品项表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.OrderStatusHistory;
|
||||
import com.qf.backend.entity.Order.OrderStatusHistory;
|
||||
|
||||
/**
|
||||
* 订单状态历史表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Orders;
|
||||
import com.qf.backend.entity.Order.Orders;
|
||||
|
||||
/**
|
||||
* 订单信息表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductAttributeValues;
|
||||
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||
|
||||
/**
|
||||
* 商品属性值表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductAttributes;
|
||||
import com.qf.backend.entity.Product.ProductAttributes;
|
||||
|
||||
/**
|
||||
* 商品属性表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductCategories;
|
||||
import com.qf.backend.entity.Product.ProductCategories;
|
||||
|
||||
/**
|
||||
* 商品分类表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductImages;
|
||||
import com.qf.backend.entity.Product.ProductImages;
|
||||
|
||||
/**
|
||||
* 商品图片表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductInventories;
|
||||
import com.qf.backend.entity.Product.ProductInventories;
|
||||
|
||||
/**
|
||||
* 商品库存表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ProductSkus;
|
||||
import com.qf.backend.entity.Product.ProductSkus;
|
||||
|
||||
/**
|
||||
* 商品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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Products;
|
||||
import com.qf.backend.entity.Product.Products;
|
||||
|
||||
/**
|
||||
* 商品信息表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ShopCategories;
|
||||
import com.qf.backend.entity.Shop.ShopCategories;
|
||||
|
||||
/**
|
||||
* 店铺分类表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.ShopRatings;
|
||||
import com.qf.backend.entity.Shop.ShopRatings;
|
||||
|
||||
/**
|
||||
* 店铺评价表 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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Shops;
|
||||
import com.qf.backend.entity.Shop.Shops;
|
||||
|
||||
/**
|
||||
* 店铺信息表 Mapper 接口
|
||||
@@ -1,9 +1,9 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Permissions;
|
||||
import com.qf.backend.entity.User.Permissions;
|
||||
|
||||
/**
|
||||
* 权限信息表 Mapper 接口
|
||||
@@ -1,9 +1,9 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.RolePermissions;
|
||||
import com.qf.backend.entity.User.RolePermissions;
|
||||
|
||||
/**
|
||||
* 角色权限关联表 Mapper 接口
|
||||
@@ -1,9 +1,9 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Roles;
|
||||
import com.qf.backend.entity.User.Roles;
|
||||
|
||||
/**
|
||||
* 角色信息表 Mapper 接口
|
||||
@@ -1,9 +1,9 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.UserDetails;
|
||||
import com.qf.backend.entity.User.UserDetails;
|
||||
|
||||
/**
|
||||
* 用户详细信息表 Mapper 接口
|
||||
@@ -1,9 +1,9 @@
|
||||
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.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.UserRoles;
|
||||
import com.qf.backend.entity.User.UserRoles;
|
||||
|
||||
/**
|
||||
* 用户角色关联表 Mapper 接口
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.qf.backend.mapper;
|
||||
package com.qf.backend.mapper.User;
|
||||
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qf.backend.entity.Users;
|
||||
import com.qf.backend.entity.User.Users;
|
||||
|
||||
/**
|
||||
* 用户基本信息表 Mapper 接口
|
||||
@@ -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.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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.OrderStatusHistory;
|
||||
import com.qf.backend.entity.Order.OrderStatusHistory;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Orders;
|
||||
|
||||
import java.util.List;
|
||||
import com.qf.backend.entity.Order.Orders;
|
||||
|
||||
/**
|
||||
* 订单服务接口
|
||||
@@ -21,9 +21,11 @@ public interface OrdersService extends IService<Orders> {
|
||||
/**
|
||||
* 根据用户ID查询订单列表
|
||||
* @param userId 用户ID
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @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查询订单
|
||||
* @param shopId 店铺ID
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @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 page 当前页码
|
||||
* @param size 每页数量
|
||||
* @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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductAttributeValues;
|
||||
|
||||
import java.util.List;
|
||||
import com.qf.backend.entity.Product.ProductAttributeValues;
|
||||
|
||||
/**
|
||||
* 商品属性值服务接口
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.qf.backend.service;
|
||||
package com.qf.backend.service.Products;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductAttributes;
|
||||
import com.qf.backend.entity.Product.ProductAttributes;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductCategories;
|
||||
import com.qf.backend.entity.Product.ProductCategories;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductImages;
|
||||
import com.qf.backend.entity.Product.ProductImages;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductInventories;
|
||||
import com.qf.backend.entity.Product.ProductInventories;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ProductSkus;
|
||||
import com.qf.backend.entity.Product.ProductSkus;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Products;
|
||||
|
||||
import java.util.List;
|
||||
import com.qf.backend.dto.response.ProductsResponse;
|
||||
import com.qf.backend.entity.Product.Products;
|
||||
|
||||
/**
|
||||
* 商品服务接口
|
||||
@@ -14,16 +15,36 @@ public interface ProductsService extends IService<Products> {
|
||||
/**
|
||||
* 根据商品名称查询商品
|
||||
* @param productName 商品名称
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 商品列表
|
||||
*/
|
||||
Result<List<Products>> getProductsByName(String productName);
|
||||
Result<List<Products>> getProductsByName(String productName , int page, int size);
|
||||
|
||||
/**
|
||||
* 根据分类ID查询商品
|
||||
* @param categoryId 分类ID
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 根据商品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);
|
||||
|
||||
/**
|
||||
* 根据店铺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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ShopCategories;
|
||||
import com.qf.backend.entity.Shop.ShopCategories;
|
||||
|
||||
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.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.ShopRatings;
|
||||
import com.qf.backend.entity.Shop.ShopRatings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.qf.backend.service;
|
||||
package com.qf.backend.service.Shop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
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 店铺名称
|
||||
* @return 店铺列表
|
||||
*/
|
||||
Result<List<Shops>> getShopsByName(String shopName);
|
||||
Result<List<Shops>> getShopsByName(String shopName, int page, int size);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询店铺
|
||||
@@ -64,9 +64,11 @@ public interface ShopsService extends IService<Shops> {
|
||||
/**
|
||||
* 根据店铺分类ID查询店铺
|
||||
* @param categoryId 分类ID
|
||||
* @param page 当前页码
|
||||
* @param size 每页数量
|
||||
* @return 店铺列表
|
||||
*/
|
||||
Result<List<Shops>> getShopsByCategoryId(Long categoryId);
|
||||
Result<List<Shops>> getShopsByCategoryId(Long categoryId, int page, int size);
|
||||
|
||||
/**
|
||||
* 更新店铺状态
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.qf.backend.service;
|
||||
package com.qf.backend.service.User;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Permissions;
|
||||
import com.qf.backend.entity.User.Permissions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.qf.backend.service;
|
||||
package com.qf.backend.service.User;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qf.backend.entity.RolePermissions;
|
||||
import com.qf.backend.entity.User.RolePermissions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.qf.backend.service;
|
||||
package com.qf.backend.service.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.qf.backend.dto.Result;
|
||||
import com.qf.backend.entity.Roles;
|
||||
import com.qf.backend.entity.User.Roles;
|
||||
|
||||
/**
|
||||
* 角色服务接口
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user