Files
TaoTaoWang_backend/src/main/java/com/qf/backend/controller/OrderItemsController.java
qingfeng1121 c5f631d043 refactor: 重构项目结构,将Result类及相关工具类移动到dto和util包
将Result类从common包移动到dto包,ResultUtils类从common包移动到util包
调整所有相关文件的import语句以匹配新的包结构
新增CorsConfig配置类处理跨域请求
优化AuthController的登录接口返回统一响应格式
2025-12-09 10:58:12 +08:00

147 lines
5.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}