Skip to content

Commit

Permalink
feature: 订单服务开发根据订单号删除订单功能 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Apr 18, 2023
1 parent 1a9e4ce commit 009bd7d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ public interface OrderService {
* @param orderSn 订单号
*/
void canalOrder(String orderSn);

/**
* 删除订单
*
* @param orderSn 订单号
*/
void deleteOrder(String orderSn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public void canalOrder(String orderSn) {
orderRepository.canalOrder(orderSn);
}

@Override
public void deleteOrder(String orderSn) {
orderRepository.deleteOrder(orderSn);
}

/**
* 根据用户ID查询选中状态购物车商品
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public enum OrderCanalErrorCodeEnum implements IErrorCode {

ORDER_CANAL_REPETITION_ERROR("B006004", "订单重复取消,请稍后再试"),

ORDER_STATUS_REVERSAL_ERROR("B006005", "订单状态反转失败,请稍后再试");
ORDER_STATUS_REVERSAL_ERROR("B006005", "订单状态反转失败,请稍后再试"),

ORDER_DELETE_ERROR("B006006", "订单状态反转失败,请稍后再试");

/**
* 错误码
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ public interface OrderRepository {
* @param order 订单聚合根
*/
void statusReversal(Order order);

/**
* 删除订单
*
* @param orderSn 订单号
*/
void deleteOrder(String orderSn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,20 @@ public void statusReversal(Order order) {
lock.unlock();
}
}

@Override
public void deleteOrder(String orderSn) {
LambdaQueryWrapper<OrderDO> queryWrapper = Wrappers.lambdaQuery(OrderDO.class)
.eq(OrderDO::getOrderSn, orderSn);
OrderDO orderDO = orderMapper.selectOne(queryWrapper);
if (orderDO == null) {
throw new ServiceException(OrderCanalErrorCodeEnum.ORDER_CANAL_UNKNOWN_ERROR);
}
LambdaUpdateWrapper<OrderDO> updateWrapper = Wrappers.lambdaUpdate(OrderDO.class)
.eq(OrderDO::getOrderSn, orderSn);
int updateResult = orderMapper.delete(updateWrapper);
if (updateResult <= 0) {
throw new ServiceException(OrderCanalErrorCodeEnum.ORDER_DELETE_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.opengoofy.congomall.springboot.starter.idempotent.enums.IdempotentTypeEnum;
import org.opengoofy.congomall.springboot.starter.log.annotation.MLog;
import org.opengoofy.congomall.springboot.starter.web.Results;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -89,4 +90,16 @@ public Result<Void> canalOrder(@PathVariable("orderSn") String orderSn) {
orderService.canalOrder(orderSn);
return Results.success();
}

@DeleteMapping("/{orderSn}")
@ApiOperation("商品订单删除")
@Idempotent(
type = IdempotentTypeEnum.PARAM,
uniqueKeyPrefix = "del_",
message = "订单删除失败,请刷新订单状态或重新操作"
)
public Result<Void> deleteOrder(@PathVariable("orderSn") String orderSn) {
orderService.deleteOrder(orderSn);
return Results.success();
}
}

0 comments on commit 009bd7d

Please sign in to comment.