feat(订单): 添加根据订单ID和商品ID查询订单商品的功能

为了支持退货审批流程,新增了根据订单ID和商品ID查询订单商品的功能。该功能在订单应用服务中实现,并通过API接口暴露给前端使用。
This commit is contained in:
dzq 2025-04-07 09:56:18 +08:00
parent 43c12b152e
commit cf215b9ef8
5 changed files with 89 additions and 1 deletions
agileboot-api/src/main/java/com/agileboot/api/controller
agileboot-domain/src/main/java/com/agileboot/domain/shop/order

View File

@ -1,15 +1,86 @@
package com.agileboot.api.controller;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.shop.approval.ReturnApprovalApplicationService;
import com.agileboot.domain.shop.approval.command.AddReturnApprovalCommand;
import com.agileboot.domain.shop.order.OrderApplicationService;
import com.agileboot.domain.shop.order.db.ShopOrderGoodsEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
/**
* 审批请求控制器
* <p>
* 处理与审批相关的HTTP请求包括退货审批的提交等操作
* </p>
*/
@RestController
@RequestMapping("/api/approval")
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "审批接口")
public class ApprovalApiController {
/** 退货审批应用服务,用于处理审批相关业务逻辑 */
private final ReturnApprovalApplicationService approvalApplicationService;
/** 订单应用服务,用于处理订单相关查询操作 */
private final OrderApplicationService orderApplicationService;
/**
* 提交退货审批申请
*
* @param command 包含审批信息的命令对象需要包含订单ID商品ID退货数量及图片
* @return 包含操作结果的响应对象
* @throws ApiException 当参数校验失败或业务逻辑出错时抛出
*/
@PostMapping("/submit")
@ApiOperation(value = "提交退货审批")
public ResponseDTO<String> submitApproval(@Valid @RequestBody AddReturnApprovalCommand command) {
try {
if (null == command.getOrderId()) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "订单ID不能为空"));
}
if (null == command.getGoodsId()) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "商品ID不能为空"));
}
if (null == command.getReturnQuantity()) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "归还数量不能为空"));
}
if (StringUtils.isBlank(command.getReturnImages())) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "归还图片不能为空"));
}
// 查询订单商品信息
ShopOrderGoodsEntity orderGoods = orderApplicationService.getOrderGoodsByOrderIdAndGoodsId(command.getOrderId(), command.getGoodsId());
if (null == orderGoods) {
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "订单商品不存在"));
}
// 设置商品价格并初始化审批状态
command.setGoodsPrice(orderGoods.getPrice());
command.setStatus(1);
// 执行业务逻辑
approvalApplicationService.addApproval(command);
return ResponseDTO.ok("审批提交成功");
} catch (Exception e) {
log.error("提交审批失败", e);
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, "提交审批失败"));
}
}
}

View File

@ -37,6 +37,8 @@ import java.util.Objects;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.s;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -301,4 +303,8 @@ public class OrderApplicationService {
return new GetOrdersByOpenIdDTO(orderList, orderGoods, goods);
}
public ShopOrderGoodsEntity getOrderGoodsByOrderIdAndGoodsId(Long orderId, Long goodsId) {
return orderGoodsService.getByOrderIdAndGoodsId(orderId, goodsId);
}
}

View File

@ -1,5 +1,8 @@
package com.agileboot.domain.shop.order.db;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
@ -12,4 +15,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface ShopOrderGoodsMapper extends BaseMapper<ShopOrderGoodsEntity> {
@Select("SELECT * FROM shop_order_goods WHERE order_id = #{orderId} AND goods_id = #{goodsId} LIMIT 1")
ShopOrderGoodsEntity selectByOrderIdAndGoodsId(@Param("orderId") Long orderId, @Param("goodsId") Long goodsId);
}

View File

@ -11,5 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2025-03-10
*/
public interface ShopOrderGoodsService extends IService<ShopOrderGoodsEntity> {
ShopOrderGoodsEntity getByOrderIdAndGoodsId(Long orderId, Long goodsId);
}

View File

@ -14,4 +14,9 @@ import org.springframework.stereotype.Service;
@Service
public class ShopOrderGoodsServiceImpl extends ServiceImpl<ShopOrderGoodsMapper, ShopOrderGoodsEntity> implements ShopOrderGoodsService {
@Override
public ShopOrderGoodsEntity getByOrderIdAndGoodsId(Long orderId, Long goodsId) {
return baseMapper.selectByOrderIdAndGoodsId(orderId, goodsId);
}
}