mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 13:03:43 +08:00
refactor:项目结构调整
This commit is contained in:
parent
f6f25a94cf
commit
29fde8f974
@ -19,5 +19,5 @@ public class OrderPayForm implements Serializable {
|
|||||||
private Integer payType;
|
private Integer payType;
|
||||||
|
|
||||||
@NotBlank(message = "订单ID不能为空")
|
@NotBlank(message = "订单ID不能为空")
|
||||||
private String orderId;
|
private Long orderId;
|
||||||
}
|
}
|
||||||
|
@ -1,127 +0,0 @@
|
|||||||
package com.youlai.mall.oms.controller.admin;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.youlai.common.enums.BusinessTypeEnum;
|
|
||||||
import com.youlai.common.enums.QueryModeEnum;
|
|
||||||
import com.youlai.common.redis.component.BusinessNoGenerator;
|
|
||||||
import com.youlai.common.result.Result;
|
|
||||||
import com.youlai.common.result.ResultCode;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@Api(tags = "【系统管理】订单服务")
|
|
||||||
@RestController("AdminOrderController")
|
|
||||||
@RequestMapping("/api.admin/v1/orders")
|
|
||||||
@Slf4j
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class OrderController {
|
|
||||||
|
|
||||||
private IOmsOrderService iOmsOrderService;
|
|
||||||
|
|
||||||
@ApiOperation(value = "列表分页", httpMethod = "GET")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "queryMode", value = "查询模式", paramType = "query", dataType = "QueryModeEnum"),
|
|
||||||
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
|
|
||||||
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
|
|
||||||
@ApiImplicitParam(name = "orderSn", value = "订单编号", paramType = "query", dataType = "String"),
|
|
||||||
@ApiImplicitParam(name = "status", value = "订单状态", paramType = "query", dataType = "Integer"),
|
|
||||||
@ApiImplicitParam(name = "startDate", value = "开始日期", paramType = "query", dataType = "String"),
|
|
||||||
@ApiImplicitParam(name = "endDate", value = "结束日期", paramType = "query", dataType = "String"),
|
|
||||||
})
|
|
||||||
@GetMapping
|
|
||||||
public Result list(
|
|
||||||
String queryMode,
|
|
||||||
Integer page,
|
|
||||||
Integer limit,
|
|
||||||
String orderSn,
|
|
||||||
Integer status,
|
|
||||||
String startDate,
|
|
||||||
String endDate
|
|
||||||
) {
|
|
||||||
QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
|
|
||||||
switch (queryModeEnum) {
|
|
||||||
case PAGE:
|
|
||||||
LambdaQueryWrapper<OmsOrder1> queryWrapper = new LambdaQueryWrapper<OmsOrder1>()
|
|
||||||
.like(StrUtil.isNotBlank(orderSn), OmsOrder1::getOrderSn, orderSn)
|
|
||||||
.eq(status != null, OmsOrder1::getStatus, status)
|
|
||||||
.apply(StrUtil.isNotBlank(startDate),
|
|
||||||
"date_format (gmt_crate,'%Y-%m-%d') >= date_format('" + startDate + "','%Y-%m-%d')")
|
|
||||||
.apply(StrUtil.isNotBlank(endDate),
|
|
||||||
"date_format (gmt_crate,'%Y-%m-%d') <= date_format('" + endDate + "','%Y-%m-%d')")
|
|
||||||
.orderByDesc(OmsOrder1::getGmtModified)
|
|
||||||
.orderByDesc(OmsOrder1::getGmtCreate);
|
|
||||||
Page<OmsOrder1> result = iOmsOrderService.page(new Page<>(page, limit), queryWrapper);
|
|
||||||
return Result.success(result.getRecords(), result.getTotal());
|
|
||||||
default:
|
|
||||||
return Result.failed(ResultCode.QUERY_MODE_IS_NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "订单详情", httpMethod = "GET")
|
|
||||||
@ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path", dataType = "Long")
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public Result detail(@PathVariable Long id) {
|
|
||||||
OrderBO order = iOmsOrderService.getByOrderId(id);
|
|
||||||
return Result.success(order);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "订单提交", httpMethod = "POST")
|
|
||||||
@ApiImplicitParam(name = "orderBO", value = "实体JSON对象", required = true, paramType = "body", dataType = "OrderBO")
|
|
||||||
@PostMapping
|
|
||||||
public Result add(@RequestBody OrderBO orderBO) {
|
|
||||||
boolean status = iOmsOrderService.save(orderBO);
|
|
||||||
return Result.judge(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "修改订单", httpMethod = "PUT")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path", dataType = "Long"),
|
|
||||||
@ApiImplicitParam(name = "order", value = "实体JSON对象", required = true, paramType = "body", dataType = "OmsOrder")
|
|
||||||
})
|
|
||||||
@PutMapping(value = "/{id}")
|
|
||||||
public Result update(
|
|
||||||
@PathVariable Long id,
|
|
||||||
@RequestBody OmsOrder1 order) {
|
|
||||||
boolean status = iOmsOrderService.updateById(order);
|
|
||||||
return Result.judge(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "局部更新", httpMethod = "PATCH")
|
|
||||||
@ApiImplicitParams({
|
|
||||||
@ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path", dataType = "Long"),
|
|
||||||
@ApiImplicitParam(name = "status", value = "订单状态", paramType = "query", dataType = "Integer")
|
|
||||||
})
|
|
||||||
@PatchMapping(value = "/{id}")
|
|
||||||
public Result patch(@PathVariable Long id,
|
|
||||||
@RequestParam Integer status) {
|
|
||||||
LambdaUpdateWrapper<OmsOrder1> updateWrapper = new LambdaUpdateWrapper<OmsOrder1>().eq(OmsOrder1::getId, id);
|
|
||||||
updateWrapper.set(status != null, OmsOrder1::getStatus, status);
|
|
||||||
boolean result = iOmsOrderService.update(updateWrapper);
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "订单详情", httpMethod = "GET")
|
|
||||||
@ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path", dataType = "Long")
|
|
||||||
@GetMapping("/{id}/detail")
|
|
||||||
public Result orderDetail(@PathVariable Long id) {
|
|
||||||
OmsOrder1 order = iOmsOrderService.getById(id);
|
|
||||||
return Result.success(order);
|
|
||||||
}
|
|
||||||
|
|
||||||
private BusinessNoGenerator businessNoGenerator;
|
|
||||||
|
|
||||||
@PostMapping("/order_sn")
|
|
||||||
public Result generateOrderSn() {
|
|
||||||
String orderSn = businessNoGenerator.generate(BusinessTypeEnum.ORDER);
|
|
||||||
log.info("订单编号:{}", orderSn);
|
|
||||||
return Result.success(orderSn);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@ package com.youlai.mall.oms.controller.app;
|
|||||||
|
|
||||||
import com.youlai.common.result.Result;
|
import com.youlai.common.result.Result;
|
||||||
import com.youlai.mall.oms.pojo.vo.CartVO;
|
import com.youlai.mall.oms.pojo.vo.CartVO;
|
||||||
import com.youlai.mall.oms.service.CartService;
|
import com.youlai.mall.oms.service.ICartService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@ -25,12 +25,12 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CartController {
|
public class CartController {
|
||||||
|
|
||||||
private CartService cartService;
|
private ICartService ICartService;
|
||||||
|
|
||||||
@ApiOperation(value = "查询购物车", httpMethod = "GET")
|
@ApiOperation(value = "查询购物车", httpMethod = "GET")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Result getCart() {
|
public Result getCart() {
|
||||||
CartVO cart = cartService.getCart();
|
CartVO cart = ICartService.getCart();
|
||||||
return Result.success(cart);
|
return Result.success(cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ public class CartController {
|
|||||||
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result addCartItem(@RequestParam Long skuId) {
|
public Result addCartItem(@RequestParam Long skuId) {
|
||||||
cartService.addCartItem(skuId);
|
ICartService.addCartItem(skuId);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ public class CartController {
|
|||||||
Integer num,
|
Integer num,
|
||||||
Boolean checked
|
Boolean checked
|
||||||
) {
|
) {
|
||||||
cartService.updateCartItem(skuId, num, checked);
|
ICartService.updateCartItem(skuId, num, checked);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class CartController {
|
|||||||
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
|
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
|
||||||
@PatchMapping("/batch")
|
@PatchMapping("/batch")
|
||||||
public Result checkAll(Boolean checked) {
|
public Result checkAll(Boolean checked) {
|
||||||
cartService.checkAll(checked);
|
ICartService.checkAll(checked);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,14 +65,14 @@ public class CartController {
|
|||||||
@ApiImplicitParam(name = "skuId", value = "SKU ID集合", required = true, paramType = "param", dataType = "Long")
|
@ApiImplicitParam(name = "skuId", value = "SKU ID集合", required = true, paramType = "param", dataType = "Long")
|
||||||
@DeleteMapping("/skuId/{skuId}")
|
@DeleteMapping("/skuId/{skuId}")
|
||||||
public Result deleteCartItem(@PathVariable Long skuId) {
|
public Result deleteCartItem(@PathVariable Long skuId) {
|
||||||
cartService.deleteCartItem(skuId);
|
ICartService.deleteCartItem(skuId);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "清空购物车", httpMethod = "DELETE")
|
@ApiOperation(value = "清空购物车", httpMethod = "DELETE")
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
public Result deleteCart() {
|
public Result deleteCart() {
|
||||||
cartService.deleteCart();
|
ICartService.deleteCart();
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import com.youlai.common.result.Result;
|
|||||||
import com.youlai.mall.oms.enums.PayTypeEnum;
|
import com.youlai.mall.oms.enums.PayTypeEnum;
|
||||||
import com.youlai.mall.oms.pojo.form.OrderPayForm;
|
import com.youlai.mall.oms.pojo.form.OrderPayForm;
|
||||||
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
||||||
import com.youlai.mall.oms.service.OrderPayService;
|
import com.youlai.mall.oms.service.IOrderPayService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderPayController {
|
public class OrderPayController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrderPayService orderPayService;
|
private IOrderPayService orderPayService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单支付
|
* 订单支付
|
||||||
@ -55,7 +55,9 @@ public class OrderPayController {
|
|||||||
|
|
||||||
@ApiOperation(value = "获取订单支付详情")
|
@ApiOperation(value = "获取订单支付详情")
|
||||||
@GetMapping("/info")
|
@GetMapping("/info")
|
||||||
public Result<PayInfoVO> info(@ApiParam(name = "orderId", value = "订单ID", required = true, defaultValue = "1") @RequestParam("orderId") String orderId) {
|
public Result<PayInfoVO> info(
|
||||||
|
@ApiParam(name = "orderId", value = "订单ID", required = true, defaultValue = "1")
|
||||||
|
@RequestParam("orderId") Long orderId) {
|
||||||
return Result.success(orderPayService.info(orderId));
|
return Result.success(orderPayService.info(orderId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.youlai.mall.oms.dao;
|
package com.youlai.mall.oms.dao;
|
||||||
|
|
||||||
import com.youlai.mall.oms.pojo.entity.OrderLogsEntity;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@ -12,6 +12,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface OrderLogDao extends BaseMapper<OrderLogsEntity> {
|
public interface OrderLogDao extends BaseMapper<OmsOrderLog> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package com.youlai.mall.oms.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface OmsOrderItemMapper extends BaseMapper<OmsOrderItem1> {
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.youlai.mall.oms.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface OmsOrderMapper extends BaseMapper<OmsOrder1> {
|
|
||||||
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ import com.youlai.mall.oms.pojo.vo.CartVO;
|
|||||||
/**
|
/**
|
||||||
* 购物车业务接口
|
* 购物车业务接口
|
||||||
*/
|
*/
|
||||||
public interface CartService {
|
public interface ICartService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加商品到购物车
|
* 添加商品到购物车
|
||||||
@ -41,7 +41,7 @@ public interface CartService {
|
|||||||
/**
|
/**
|
||||||
* 清空购物车中已选择商品
|
* 清空购物车中已选择商品
|
||||||
*/
|
*/
|
||||||
void cleanSelected();
|
void deleteSelectedItem();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -11,6 +11,6 @@ import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
|
|||||||
* @email huawei_code@163.com
|
* @email huawei_code@163.com
|
||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
public interface OrderDeliveryService extends IService<OmsOrderDelivery> {
|
public interface IOrderDeliveryService extends IService<OmsOrderDelivery> {
|
||||||
}
|
}
|
||||||
|
|
@ -13,7 +13,7 @@ import java.util.Map;
|
|||||||
* @email huawei_code@163.com
|
* @email huawei_code@163.com
|
||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
public interface OrderGoodsService extends IService<OmsOrderItem> {
|
public interface IOrderItemService extends IService<OmsOrderItem> {
|
||||||
|
|
||||||
List<OmsOrderItem> getByOrderId(Long orderId);
|
List<OmsOrderItem> getByOrderId(Long orderId);
|
||||||
|
|
@ -11,7 +11,7 @@ import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
|
|||||||
* @email huawei_code@163.com
|
* @email huawei_code@163.com
|
||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
public interface OrderLogsService extends IService<OmsOrderLog> {
|
public interface IOrderLogService extends IService<OmsOrderLog> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加订单操作日志记录
|
* 添加订单操作日志记录
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
|
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
|
||||||
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付信息表
|
* 支付信息表
|
||||||
@ -12,18 +13,19 @@ import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
|||||||
* @email huawei_code@163.com
|
* @email huawei_code@163.com
|
||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
public interface OrderPayService extends IService<OmsOrderPay> {
|
|
||||||
|
public interface IOrderPayService extends IService<OmsOrderPay> {
|
||||||
/**
|
/**
|
||||||
* 获取订单支付详情
|
* 获取订单支付详情
|
||||||
* @param orderId 订单ID
|
* @param orderId 订单ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PayInfoVO info(String orderId);
|
PayInfoVO info(Long orderId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单支付
|
* 订单支付
|
||||||
* @param orderId 订单ID
|
* @param orderId 订单ID
|
||||||
*/
|
*/
|
||||||
void balancePay(String orderId);
|
void balancePay(Long orderId);
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,7 @@ public interface IOrderService extends IService<OmsOrder> {
|
|||||||
* @param id 订单ID
|
* @param id 订单ID
|
||||||
* @return 是否取消成功
|
* @return 是否取消成功
|
||||||
*/
|
*/
|
||||||
boolean cancelOrder(String id);
|
boolean cancelOrder(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除订单
|
* 删除订单
|
||||||
@ -57,7 +57,7 @@ public interface IOrderService extends IService<OmsOrder> {
|
|||||||
* @param id 订单ID
|
* @param id 订单ID
|
||||||
* @return 是否删除成功
|
* @return 是否删除成功
|
||||||
*/
|
*/
|
||||||
boolean deleteOrder(String id);
|
boolean deleteOrder(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单列表查询
|
* 订单列表查询
|
||||||
@ -73,6 +73,6 @@ public interface IOrderService extends IService<OmsOrder> {
|
|||||||
* @param id 订单ID
|
* @param id 订单ID
|
||||||
* @return 订单信息
|
* @return 订单信息
|
||||||
*/
|
*/
|
||||||
OmsOrder getByOrderId(String id);
|
OmsOrder getByOrderId(Long id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,6 @@ import com.youlai.mall.oms.pojo.domain.OmsOrderSetting;
|
|||||||
* @email huawei_code@163.com
|
* @email huawei_code@163.com
|
||||||
* @date 2020-12-30 22:31:10
|
* @date 2020-12-30 22:31:10
|
||||||
*/
|
*/
|
||||||
public interface OrderSettingService extends IService<OmsOrderSetting> {
|
public interface IOrderSettingService extends IService<OmsOrderSetting> {
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,7 @@ import com.youlai.mall.pms.api.app.InventoryFeignService;
|
|||||||
import com.youlai.mall.pms.pojo.dto.SkuDTO;
|
import com.youlai.mall.pms.pojo.dto.SkuDTO;
|
||||||
import com.youlai.mall.oms.pojo.vo.CartItemVO;
|
import com.youlai.mall.oms.pojo.vo.CartItemVO;
|
||||||
import com.youlai.mall.oms.pojo.vo.CartVO;
|
import com.youlai.mall.oms.pojo.vo.CartVO;
|
||||||
import com.youlai.mall.oms.service.CartService;
|
import com.youlai.mall.oms.service.ICartService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -39,7 +39,7 @@ import static com.youlai.mall.oms.common.RedisConstants.CART_KEY;
|
|||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CartServiceImpl implements CartService {
|
public class CartServiceImpl implements ICartService {
|
||||||
|
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public class CartServiceImpl implements CartService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanSelected() {
|
public void deleteSelectedItem() {
|
||||||
log.info("清空购物车中已选择商品");
|
log.info("清空购物车中已选择商品");
|
||||||
BoundHashOperations cartHashOpts = getCartHashOpts();
|
BoundHashOperations cartHashOpts = getCartHashOpts();
|
||||||
for (Object value : cartHashOpts.values()) {
|
for (Object value : cartHashOpts.values()) {
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package com.youlai.mall.oms.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.youlai.mall.oms.mapper.OmsOrderItemMapper;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class OmsOrderItemServiceImpl extends ServiceImpl<OmsOrderItemMapper, OmsOrderItem1> implements IService<OmsOrderItem1> {
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
package com.youlai.mall.oms.service.impl;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.youlai.common.result.Result;
|
|
||||||
import com.youlai.common.web.exception.BizException;
|
|
||||||
import com.youlai.mall.oms.mapper.OmsOrderMapper;
|
|
||||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
|
||||||
import com.youlai.mall.ums.pojo.dto.MemberDTO;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder1> implements IOmsOrderService {
|
|
||||||
|
|
||||||
private IOmsOrderItemService iOmsOrderItemService;
|
|
||||||
|
|
||||||
private MemberFeignService memberFeignService;
|
|
||||||
/**
|
|
||||||
* 提交订单
|
|
||||||
*
|
|
||||||
* @param orderBO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean save(OrderBO orderBO) {
|
|
||||||
// 订单
|
|
||||||
OmsOrder1 order = orderBO.getOrder();
|
|
||||||
String orderSn = IdUtil.createSnowflake(1, 1).nextIdStr();
|
|
||||||
order.setOrderSn(orderSn);
|
|
||||||
this.save(order);
|
|
||||||
|
|
||||||
// 订单明细
|
|
||||||
List<OmsOrderItem1> orderItems = orderBO.getOrderItems();
|
|
||||||
if (CollectionUtil.isEmpty(orderItems)) {
|
|
||||||
throw new BizException("订单明细不能为空");
|
|
||||||
}
|
|
||||||
orderItems.forEach(item -> {
|
|
||||||
item.setOrderId(order.getId());
|
|
||||||
});
|
|
||||||
iOmsOrderItemService.saveBatch(orderItems);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OrderBO getByOrderId(Long orderId) {
|
|
||||||
OrderBO orderBO = new OrderBO();
|
|
||||||
// 订单
|
|
||||||
OmsOrder1 order = this.getById(orderId);
|
|
||||||
if (order == null) {
|
|
||||||
throw new BizException("订单不存在");
|
|
||||||
}
|
|
||||||
// 订单明细
|
|
||||||
List<OmsOrderItem1> orderItems = iOmsOrderItemService.list(
|
|
||||||
new LambdaQueryWrapper<OmsOrderItem1>().eq(OmsOrderItem1::getOrderId, orderId)
|
|
||||||
);
|
|
||||||
orderItems = Optional.ofNullable(orderItems).orElse(new ArrayList<>());
|
|
||||||
|
|
||||||
// 会员明细
|
|
||||||
Result<MemberDTO> result = memberFeignService.getUserById(order.getUserId());
|
|
||||||
MemberDTO member = result.getData();
|
|
||||||
orderBO.setOrder(order).setOrderItems(orderItems).setMember(member);
|
|
||||||
return orderBO;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -3,10 +3,10 @@ package com.youlai.mall.oms.service.impl;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;;
|
||||||
import com.youlai.mall.oms.dao.OrderDeliveryDao;
|
import com.youlai.mall.oms.dao.OrderDeliveryDao;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderDelivery;
|
||||||
import com.youlai.mall.oms.service.OrderDeliveryService;
|
import com.youlai.mall.oms.service.IOrderDeliveryService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service("orderDeliveryService")
|
@Service("orderDeliveryService")
|
||||||
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryDao, OmsOrderDelivery> implements OrderDeliveryService {
|
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryDao, OmsOrderDelivery> implements IOrderDeliveryService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package com.youlai.mall.oms.service.impl;
|
package com.youlai.mall.oms.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
|
||||||
import com.youlai.mall.oms.dao.OrderItemDao;
|
import com.youlai.mall.oms.dao.OrderItemDao;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
||||||
import com.youlai.mall.oms.service.OrderGoodsService;
|
import com.youlai.mall.oms.service.IOrderItemService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -15,24 +14,25 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Service("orderGoodsService")
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderGoodsServiceImpl extends ServiceImpl<OrderItemDao, OmsOrderItem> implements OrderGoodsService {
|
@Service
|
||||||
|
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OmsOrderItem> implements IOrderItemService {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<OmsOrderItem> getByOrderId(Long orderId) {
|
public List<OmsOrderItem> getByOrderId(Long orderId) {
|
||||||
log.info("根据订单ID,查询订单商品列表,orderId={}", orderId);
|
log.info("根据订单ID,查询订单商品列表,orderId={}", orderId);
|
||||||
QueryWrapper<OmsOrderItem> queryWrapper = new QueryWrapper<>();
|
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<OmsOrderItem>().eq(OmsOrderItem::getOrderId, orderId);
|
||||||
queryWrapper.ge("order_id", orderId);
|
return this.list(queryWrapper);
|
||||||
return baseMapper.selectList(queryWrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Long, List<OmsOrderItem>> getByOrderIds(List<Long> orderIds) {
|
public Map<Long, List<OmsOrderItem>> getByOrderIds(List<Long> orderIds) {
|
||||||
QueryWrapper<OmsOrderItem> orderGoodsQuery = new QueryWrapper<>();
|
LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<OmsOrderItem>().in(OmsOrderItem::getOrderId, orderIds)
|
||||||
orderGoodsQuery.in("order_id", orderIds).orderByDesc("order_id", "id");
|
.orderByDesc(OmsOrderItem::getOrderId)
|
||||||
List<OmsOrderItem> orderGoods = this.list(orderGoodsQuery);
|
.orderByDesc(OmsOrderItem::getId);
|
||||||
|
|
||||||
|
List<OmsOrderItem> orderGoods = this.list(queryWrapper);
|
||||||
if (orderGoods == null || orderGoods.size() == 0) {
|
if (orderGoods == null || orderGoods.size() == 0) {
|
||||||
log.info("根据订单ID列表查询商品为空,orderIds={}", orderIds);
|
log.info("根据订单ID列表查询商品为空,orderIds={}", orderIds);
|
||||||
return new HashMap<>(8);
|
return new HashMap<>(8);
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.youlai.mall.oms.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.youlai.common.web.util.RequestUtils;
|
||||||
|
import com.youlai.mall.oms.dao.OrderLogDao;
|
||||||
|
import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
|
||||||
|
import com.youlai.mall.oms.service.IOrderLogService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class OrderLogServiceImpl extends ServiceImpl<OrderLogDao, OmsOrderLog> implements IOrderLogService {
|
||||||
|
@Override
|
||||||
|
public void addOrderLogs(Long orderId, Integer orderStatus, String user, String detail) {
|
||||||
|
log.info("添加订单操作日志,orderId={},detail={}", orderId, detail);
|
||||||
|
OmsOrderLog orderLog = new OmsOrderLog();
|
||||||
|
orderLog.setDetail(detail);
|
||||||
|
orderLog.setOrderId(orderId);
|
||||||
|
orderLog.setOrderStatus(orderStatus);
|
||||||
|
orderLog.setUser(user);
|
||||||
|
this.save(orderLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addOrderLogs(Long orderId, Integer orderStatus, String detail) {
|
||||||
|
Long userId = RequestUtils.getUserId();
|
||||||
|
addOrderLogs(orderId, orderStatus, userId.toString(), detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,35 +0,0 @@
|
|||||||
package com.youlai.mall.oms.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.youlai.common.web.util.RequestUtils;
|
|
||||||
import com.youlai.mall.oms.dao.OrderLogDao;
|
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderLog;
|
|
||||||
import com.youlai.mall.oms.service.OrderLogsService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service("orderLogsService")
|
|
||||||
@Slf4j
|
|
||||||
public class OrderLogsServiceImpl extends ServiceImpl<OrderLogDao, OmsOrderLog> implements OrderLogsService {
|
|
||||||
@Override
|
|
||||||
public void addOrderLogs(Long orderId, Integer orderStatus, String user, String detail) {
|
|
||||||
try {
|
|
||||||
log.info("添加订单操作日志,orderId={},detail={}", orderId, detail);
|
|
||||||
OmsOrderLog orderLogs = new OmsOrderLog();
|
|
||||||
orderLogs.setDetail(detail);
|
|
||||||
orderLogs.setOrderId(orderId);
|
|
||||||
orderLogs.setOrderStatus(orderStatus);
|
|
||||||
orderLogs.setUser(user);
|
|
||||||
baseMapper.insert(orderLogs);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("添加订单操作日志失败,orderId={}", orderId, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addOrderLogs(Long orderId, Integer orderStatus, String detail) {
|
|
||||||
Long userId = RequestUtils.getUserId();
|
|
||||||
addOrderLogs(orderId, orderStatus, userId.toString(), detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -13,8 +13,8 @@ import com.youlai.mall.oms.enums.OrderStatusEnum;
|
|||||||
import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderPay;
|
||||||
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
import com.youlai.mall.oms.pojo.vo.PayInfoVO;
|
||||||
import com.youlai.mall.oms.service.OrderLogsService;
|
import com.youlai.mall.oms.service.IOrderLogService;
|
||||||
import com.youlai.mall.oms.service.OrderPayService;
|
import com.youlai.mall.oms.service.IOrderPayService;
|
||||||
import com.youlai.mall.oms.service.IOrderService;
|
import com.youlai.mall.oms.service.IOrderService;
|
||||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
import com.youlai.mall.ums.api.app.MemberFeignService;
|
||||||
import com.youlai.mall.ums.pojo.dto.MemberDTO;
|
import com.youlai.mall.ums.pojo.dto.MemberDTO;
|
||||||
@ -27,22 +27,22 @@ import java.util.Date;
|
|||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Service("orderPayService")
|
public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> implements IOrderPayService {
|
||||||
public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> implements OrderPayService {
|
|
||||||
|
|
||||||
private IOrderService IOrderService;
|
private IOrderService orderService;
|
||||||
|
|
||||||
private OrderLogsService orderLogsService;
|
private IOrderLogService orderLogService;
|
||||||
|
|
||||||
private MemberFeignService memberFeignService;
|
private MemberFeignService memberFeignService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PayInfoVO info(String orderId) {
|
public PayInfoVO info(Long orderId) {
|
||||||
Long userId = RequestUtils.getUserId();
|
Long userId = RequestUtils.getUserId();
|
||||||
PayInfoVO payInfoVO = new PayInfoVO();
|
PayInfoVO payInfoVO = new PayInfoVO();
|
||||||
// 1、获取订单应支付金额
|
// 1、获取订单应支付金额
|
||||||
OmsOrder omsOrder = IOrderService.getByOrderId(orderId);
|
OmsOrder omsOrder = orderService.getByOrderId(orderId);
|
||||||
payInfoVO.setPayPrice(omsOrder.getPayAmount());
|
payInfoVO.setPayPrice(omsOrder.getPayAmount());
|
||||||
|
|
||||||
// 2、获取会员余额
|
// 2、获取会员余额
|
||||||
@ -65,10 +65,10 @@ public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GlobalTransactional(rollbackFor = Exception.class)
|
@GlobalTransactional(rollbackFor = Exception.class)
|
||||||
public void balancePay(String orderId) {
|
public void balancePay(Long orderId) {
|
||||||
// 1、查询订单详情,判断订单状态是否是待支付状态
|
// 1、查询订单详情,判断订单状态是否是待支付状态
|
||||||
log.info("订单进入支付流程,orderId:{}", orderId);
|
log.info("订单进入支付流程,orderId:{}", orderId);
|
||||||
OmsOrder order = IOrderService.getByOrderId(orderId);
|
OmsOrder order = orderService.getByOrderId(orderId);
|
||||||
OrderStatusEnum orderStatusEnum = OrderStatusEnum.getValue(order.getStatus()) ;
|
OrderStatusEnum orderStatusEnum = OrderStatusEnum.getValue(order.getStatus()) ;
|
||||||
if (orderStatusEnum != OrderStatusEnum.NEED_PAY) {
|
if (orderStatusEnum != OrderStatusEnum.NEED_PAY) {
|
||||||
log.error("订单状态异常无法支付,orderStatus={}", orderStatusEnum.getText());
|
log.error("订单状态异常无法支付,orderStatus={}", orderStatusEnum.getText());
|
||||||
@ -95,9 +95,9 @@ public class OrderPayServiceImpl extends ServiceImpl<OrderPayDao, OmsOrderPay> i
|
|||||||
order.setStatus(OrderStatusEnum.IS_PAY.getCode());
|
order.setStatus(OrderStatusEnum.IS_PAY.getCode());
|
||||||
order.setPayTime(new Date());
|
order.setPayTime(new Date());
|
||||||
order.setPayType(PayTypeEnum.BALANCE.getCode());
|
order.setPayType(PayTypeEnum.BALANCE.getCode());
|
||||||
IOrderService.updateById(order);
|
orderService.updateById(order);
|
||||||
this.save(createOrderPay(order, PayTypeEnum.BALANCE.getCode()));
|
this.save(createOrderPay(order, PayTypeEnum.BALANCE.getCode()));
|
||||||
orderLogsService.addOrderLogs(order.getId(), OrderStatusEnum.IS_PAY.getCode(), userId.toString(), "支付订单");
|
orderLogService.addOrderLogs(order.getId(), OrderStatusEnum.IS_PAY.getCode(), userId.toString(), "支付订单");
|
||||||
}
|
}
|
||||||
|
|
||||||
private OmsOrderPay createOrderPay(OmsOrder order, Integer payType) {
|
private OmsOrderPay createOrderPay(OmsOrder order, Integer payType) {
|
||||||
|
@ -10,7 +10,7 @@ import com.youlai.mall.oms.config.rabbitmq.OmsRabbitConstants;
|
|||||||
import com.youlai.mall.oms.enums.OrderStatusEnum;
|
import com.youlai.mall.oms.enums.OrderStatusEnum;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
||||||
import com.youlai.mall.oms.service.OrderGoodsService;
|
import com.youlai.mall.oms.service.IOrderItemService;
|
||||||
import com.youlai.mall.oms.service.OrderRabbitService;
|
import com.youlai.mall.oms.service.OrderRabbitService;
|
||||||
import com.youlai.mall.oms.service.IOrderService;
|
import com.youlai.mall.oms.service.IOrderService;
|
||||||
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
||||||
@ -32,9 +32,9 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class OrderRabbitServiceImpl implements OrderRabbitService {
|
public class OrderRabbitServiceImpl implements OrderRabbitService {
|
||||||
|
|
||||||
private IOrderService IOrderService;
|
private IOrderService orderService;
|
||||||
|
|
||||||
private OrderGoodsService orderGoodsService;
|
private IOrderItemService orderItemService;
|
||||||
|
|
||||||
private InventoryFeignService inventoryFeignService;
|
private InventoryFeignService inventoryFeignService;
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ public class OrderRabbitServiceImpl implements OrderRabbitService {
|
|||||||
log.info("获取到消息,msgTag={},message={},body={}", msgTag, message.toString(), orderSn);
|
log.info("获取到消息,msgTag={},message={},body={}", msgTag, message.toString(), orderSn);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OmsOrder order = IOrderService.getOne(new LambdaQueryWrapper<OmsOrder>().eq(OmsOrder::getOrderSn,orderSn));
|
OmsOrder order = orderService.getOne(new LambdaQueryWrapper<OmsOrder>().eq(OmsOrder::getOrderSn, orderSn));
|
||||||
if (order.getStatus().equals(OrderStatusEnum.NEED_PAY.getCode())) {
|
if (order.getStatus().equals(OrderStatusEnum.NEED_PAY.getCode())) {
|
||||||
if (IOrderService.closeOrderBySystem(orderSn)){
|
if (orderService.closeOrderBySystem(orderSn)) {
|
||||||
unlockInventory(order.getId());
|
unlockInventory(order.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,13 +68,8 @@ public class OrderRabbitServiceImpl implements OrderRabbitService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void unlockInventory(Long orderId) {
|
private void unlockInventory(Long orderId) {
|
||||||
List<OmsOrderItem> orderGoods = orderGoodsService.getByOrderId(orderId);
|
List<OmsOrderItem> orderItems = orderItemService.getByOrderId(orderId);
|
||||||
List<InventoryDTO> items = orderGoods.stream().map(good -> {
|
List<InventoryDTO> items = orderItems.stream().map(item -> InventoryDTO.builder().skuId(item.getSkuId()).num(item.getSkuQuantity()).build()).collect(Collectors.toList());
|
||||||
InventoryDTO item = new InventoryDTO();
|
|
||||||
item.setInventoryId(good.getSkuId());
|
|
||||||
item.setNum(good.getSkuQuantity());
|
|
||||||
return item;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
Result result = inventoryFeignService.unlockInventory(items);
|
Result result = inventoryFeignService.unlockInventory(items);
|
||||||
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
|
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
|
||||||
log.error("释放库存异常,商品列表={}", items);
|
log.error("释放库存异常,商品列表={}", items);
|
||||||
|
@ -17,8 +17,6 @@ import com.youlai.common.web.util.BeanMapperUtils;
|
|||||||
import com.youlai.common.web.util.RequestUtils;
|
import com.youlai.common.web.util.RequestUtils;
|
||||||
import com.youlai.mall.oms.config.rabbitmq.OmsRabbitConstants;
|
import com.youlai.mall.oms.config.rabbitmq.OmsRabbitConstants;
|
||||||
import com.youlai.mall.oms.dao.OrderDao;
|
import com.youlai.mall.oms.dao.OrderDao;
|
||||||
import com.youlai.mall.oms.dao.OrderDeliveryDao;
|
|
||||||
import com.youlai.mall.oms.dao.OrderItemDao;
|
|
||||||
import com.youlai.mall.oms.enums.OrderStatusEnum;
|
import com.youlai.mall.oms.enums.OrderStatusEnum;
|
||||||
import com.youlai.mall.oms.enums.OrderTypeEnum;
|
import com.youlai.mall.oms.enums.OrderTypeEnum;
|
||||||
import com.youlai.mall.oms.pojo.bo.app.OrderBO;
|
import com.youlai.mall.oms.pojo.bo.app.OrderBO;
|
||||||
@ -27,10 +25,7 @@ import com.youlai.mall.oms.pojo.domain.OmsOrder;
|
|||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
||||||
import com.youlai.mall.oms.pojo.dto.OrderSubmitInfoDTO;
|
import com.youlai.mall.oms.pojo.dto.OrderSubmitInfoDTO;
|
||||||
import com.youlai.mall.oms.pojo.vo.*;
|
import com.youlai.mall.oms.pojo.vo.*;
|
||||||
import com.youlai.mall.oms.service.CartService;
|
import com.youlai.mall.oms.service.*;
|
||||||
import com.youlai.mall.oms.service.OrderGoodsService;
|
|
||||||
import com.youlai.mall.oms.service.OrderLogsService;
|
|
||||||
import com.youlai.mall.oms.service.IOrderService;
|
|
||||||
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
||||||
import com.youlai.mall.pms.pojo.dto.SkuDTO;
|
import com.youlai.mall.pms.pojo.dto.SkuDTO;
|
||||||
import com.youlai.mall.pms.pojo.dto.InventoryDTO;
|
import com.youlai.mall.pms.pojo.dto.InventoryDTO;
|
||||||
@ -42,6 +37,7 @@ import lombok.SneakyThrows;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.core.task.AsyncTaskExecutor;
|
import org.springframework.core.task.AsyncTaskExecutor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
@ -52,11 +48,12 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Service
|
||||||
public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements IOrderService {
|
public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements IOrderService {
|
||||||
|
|
||||||
private static final ThreadLocal<OrderSubmitInfoDTO> threadLocal = new ThreadLocal<>();
|
private static final ThreadLocal<OrderSubmitInfoDTO> threadLocal = new ThreadLocal<>();
|
||||||
|
|
||||||
private CartService cartService;
|
private ICartService cartService;
|
||||||
|
|
||||||
private InventoryFeignService inventoryFeignService;
|
private InventoryFeignService inventoryFeignService;
|
||||||
|
|
||||||
@ -64,13 +61,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
|
|
||||||
private AsyncTaskExecutor executor;
|
private AsyncTaskExecutor executor;
|
||||||
|
|
||||||
private OrderItemDao orderItemDao;
|
private IOrderItemService orderItemService;
|
||||||
|
|
||||||
private OrderDeliveryDao orderDeliveryDao;
|
private IOrderDeliveryService orderDeliveryService;
|
||||||
|
|
||||||
private OrderLogsService orderLogsService;
|
private IOrderLogService orderLogService;
|
||||||
|
|
||||||
private OrderGoodsService orderGoodsService;
|
|
||||||
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
@ -105,12 +100,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
public OrderSubmitResultVO submit(OrderSubmitInfoDTO submitInfoDTO) {
|
public OrderSubmitResultVO submit(OrderSubmitInfoDTO submitInfoDTO) {
|
||||||
log.info("开始创建订单:{}", submitInfoDTO);
|
log.info("开始创建订单:{}", submitInfoDTO);
|
||||||
threadLocal.set(submitInfoDTO);
|
threadLocal.set(submitInfoDTO);
|
||||||
|
|
||||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||||
OrderBO orderBO = new OrderBO();
|
|
||||||
|
|
||||||
// 创建订单
|
OrderBO orderBO = new OrderBO();
|
||||||
CompletableFuture<Void> orderFuture = CompletableFuture.runAsync(() -> {
|
CompletableFuture<Void> orderFuture;
|
||||||
|
CompletableFuture<Void> orderItemFuture;
|
||||||
|
CompletableFuture<Void> orderDeliveryFuture;
|
||||||
|
|
||||||
|
// 创建订单任务
|
||||||
|
{
|
||||||
|
orderFuture = CompletableFuture.runAsync(() -> {
|
||||||
RequestContextHolder.setRequestAttributes(attributes);
|
RequestContextHolder.setRequestAttributes(attributes);
|
||||||
threadLocal.set(submitInfoDTO);
|
threadLocal.set(submitInfoDTO);
|
||||||
|
|
||||||
@ -125,9 +124,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
orderBO.setOrder(order);
|
orderBO.setOrder(order);
|
||||||
|
|
||||||
}, executor);
|
}, executor);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建订单商品
|
// 创建订单商品任务
|
||||||
CompletableFuture<Void> orderItemFuture = CompletableFuture.runAsync(() -> {
|
{
|
||||||
|
orderItemFuture = CompletableFuture.runAsync(() -> {
|
||||||
RequestContextHolder.setRequestAttributes(attributes);
|
RequestContextHolder.setRequestAttributes(attributes);
|
||||||
threadLocal.set(submitInfoDTO);
|
threadLocal.set(submitInfoDTO);
|
||||||
|
|
||||||
@ -162,9 +163,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
}
|
}
|
||||||
orderBO.setOrderItems(orderItems);
|
orderBO.setOrderItems(orderItems);
|
||||||
}, executor);
|
}, executor);
|
||||||
|
}
|
||||||
|
|
||||||
// 生成发货信息
|
// 创建发货信息任务
|
||||||
CompletableFuture<Void> orderDeliveryFuture = CompletableFuture.runAsync(() -> {
|
{
|
||||||
|
orderDeliveryFuture = CompletableFuture.runAsync(() -> {
|
||||||
RequestContextHolder.setRequestAttributes(attributes);
|
RequestContextHolder.setRequestAttributes(attributes);
|
||||||
threadLocal.set(submitInfoDTO);
|
threadLocal.set(submitInfoDTO);
|
||||||
|
|
||||||
@ -186,48 +189,95 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
|
|
||||||
orderBO.setOrderDelivery(orderDelivery);
|
orderBO.setOrderDelivery(orderDelivery);
|
||||||
}, executor);
|
}, executor);
|
||||||
|
}
|
||||||
|
|
||||||
CompletableFuture<Void> future = CompletableFuture.allOf(orderFuture, orderItemFuture, orderDeliveryFuture);
|
CompletableFuture<Void> future = CompletableFuture.allOf(orderFuture, orderItemFuture, orderDeliveryFuture);
|
||||||
future.get();
|
future.get();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 订单验价
|
// 订单验价
|
||||||
computePrice(orderBO.getOmsOrder(), orderBO.getOrderGoods());
|
{
|
||||||
|
OmsOrder order = orderBO.getOrder();
|
||||||
|
List<OmsOrderItem> orderItems = orderBO.getOrderItems();
|
||||||
|
|
||||||
// 扣减库存
|
log.info("计算订单价格:order:{},orderItems:{}", order, orderItems);
|
||||||
lockStock(orderBO.getOrderGoods());
|
|
||||||
|
|
||||||
// 保存订单
|
if (order == null || CollectionUtil.isEmpty(orderItems)) {
|
||||||
this.baseMapper.insert(orderBO.getOmsOrder());
|
throw new BizException("订单或订单商品列表为空,订单创建失败");
|
||||||
Long orderId = orderBO.getOmsOrder().getId();
|
|
||||||
|
|
||||||
// 保存订单商品
|
|
||||||
for (OmsOrderItem orderGood : orderBO.getOrderGoods()) {
|
|
||||||
orderGood.setOrderId(orderId);
|
|
||||||
orderItemDao.insert(orderGood);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存订单发货信息
|
Long totalAmount = orderItems.stream().mapToLong(OmsOrderItem::getSkuTotalPrice).sum();
|
||||||
orderBO.getOmsOrderDelivery().setOrderId(orderId);
|
int totalQuantity = orderItems.stream().mapToInt(OmsOrderItem::getSkuQuantity).sum();
|
||||||
orderDeliveryDao.insert(orderBO.getOmsOrderDelivery());
|
Long payAmount = totalAmount;
|
||||||
|
if (order.getCouponAmount() != null) {
|
||||||
|
payAmount -= order.getCouponAmount();
|
||||||
|
}
|
||||||
|
if (order.getFreightAmount() != null) {
|
||||||
|
payAmount -= order.getFreightAmount();
|
||||||
|
}
|
||||||
|
|
||||||
// 保存订单日志
|
|
||||||
// 清空购物车
|
OrderSubmitInfoDTO orderSubmitInfo = threadLocal.get();
|
||||||
if (ObjectUtil.isNull(submit.getSkuId())) {
|
int compare = Long.compare(orderSubmitInfo.getPayAmount().longValue(), payAmount.longValue());
|
||||||
cartService.cleanSelected();
|
if (compare != 0) {
|
||||||
|
throw new BizException("订单价格变化,请重新提交");
|
||||||
|
}
|
||||||
|
|
||||||
|
order.setTotalAmount(totalAmount);
|
||||||
|
order.setTotalQuantity(totalQuantity);
|
||||||
|
order.setPayAmount(payAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 锁定库存
|
||||||
|
{
|
||||||
|
List<OmsOrderItem> orderItems = orderBO.getOrderItems();
|
||||||
|
List<InventoryDTO> items = orderItems.stream().map(orderItem -> InventoryDTO.builder()
|
||||||
|
.skuId(orderItem.getSkuId())
|
||||||
|
.num(orderItem.getSkuQuantity())
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Result result = inventoryFeignService.lockInventory(items);
|
||||||
|
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
|
||||||
|
throw new BizException("下单失败,锁定库存错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存订单
|
||||||
|
OmsOrder order = orderBO.getOrder();
|
||||||
|
this.save(order);
|
||||||
|
Long orderId = order.getId();
|
||||||
|
|
||||||
|
// 保存订单商品
|
||||||
|
List<OmsOrderItem> orderItems = orderBO.getOrderItems();
|
||||||
|
orderItems.forEach(item -> item.setOrderId(orderId));
|
||||||
|
orderItemService.saveBatch(orderItems);
|
||||||
|
|
||||||
|
// 保存发货信息
|
||||||
|
OmsOrderDelivery orderDelivery = orderBO.getOrderDelivery();
|
||||||
|
orderDelivery.setOrderId(orderId);
|
||||||
|
orderDeliveryService.save(orderDelivery);
|
||||||
|
|
||||||
|
// 删除购物车中已购买的商品
|
||||||
|
if (ObjectUtil.isNull(submitInfoDTO.getSkuId())) {
|
||||||
|
cartService.deleteSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将订单放入定时队列中,超时未支付系统自动关单,释放库存
|
// 将订单放入定时队列中,超时未支付系统自动关单,释放库存
|
||||||
rabbitTemplate.convertAndSend(OmsRabbitConstants.ORDER_EVENT_EXCHANGE,
|
rabbitTemplate.convertAndSend(OmsRabbitConstants.ORDER_EVENT_EXCHANGE,
|
||||||
OmsRabbitConstants.ORDER_CREATE_ORDER_KEY, orderBO.getOmsOrder().getOrderSn());
|
OmsRabbitConstants.ORDER_CREATE_ORDER_KEY,
|
||||||
|
orderBO.getOrder().getOrderSn()
|
||||||
|
);
|
||||||
|
|
||||||
orderLogsService.addOrderLogs(orderBO.getOmsOrder().getId(), orderBO.getOmsOrder().getStatus(), RequestUtils.getUserId().toString(), "创建订单");
|
// 保存日志
|
||||||
|
orderLogService.addOrderLogs(orderId,
|
||||||
|
orderBO.getOrder().getStatus(),
|
||||||
|
RequestUtils.getUserId().toString(),
|
||||||
|
"创建订单"
|
||||||
|
);
|
||||||
|
|
||||||
OrderSubmitResultVO result = new OrderSubmitResultVO();
|
OrderSubmitResultVO result = new OrderSubmitResultVO();
|
||||||
result.setId(orderId);
|
result.setId(orderId);
|
||||||
result.setOrderSn(orderBO.getOmsOrder().getOrderSn());
|
result.setOrderSn(order.getOrderSn());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,14 +293,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
order.setStatus(OrderStatusEnum.SYS_CANCEL.getCode());
|
order.setStatus(OrderStatusEnum.SYS_CANCEL.getCode());
|
||||||
baseMapper.updateById(order);
|
baseMapper.updateById(order);
|
||||||
// 添加订单操作日志
|
// 添加订单操作日志
|
||||||
orderLogsService.addOrderLogs(order.getId(), order.getStatus(),
|
orderLogService.addOrderLogs(order.getId(), order.getStatus(),
|
||||||
"系统操作", OrderStatusEnum.SYS_CANCEL.getText());
|
"系统操作", OrderStatusEnum.SYS_CANCEL.getText());
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean cancelOrder(String id) {
|
public boolean cancelOrder(Long id) {
|
||||||
log.info("会员取消订单,orderId={}", id);
|
log.info("会员取消订单,orderId={}", id);
|
||||||
OmsOrder order = getByOrderId(id);
|
OmsOrder order = getByOrderId(id);
|
||||||
if (!order.getStatus().equals(OrderStatusEnum.NEED_PAY.getCode())) {
|
if (!order.getStatus().equals(OrderStatusEnum.NEED_PAY.getCode())) {
|
||||||
@ -260,22 +310,21 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
order.setStatus(OrderStatusEnum.USER_CANCEL.getCode());
|
order.setStatus(OrderStatusEnum.USER_CANCEL.getCode());
|
||||||
baseMapper.updateById(order);
|
baseMapper.updateById(order);
|
||||||
// 添加订单操作日志
|
// 添加订单操作日志
|
||||||
orderLogsService.addOrderLogs(order.getId(), order.getStatus(), OrderStatusEnum.USER_CANCEL.getText());
|
orderLogService.addOrderLogs(order.getId(), order.getStatus(), OrderStatusEnum.USER_CANCEL.getText());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean deleteOrder(String id) {
|
public boolean deleteOrder(Long id) {
|
||||||
// 查询订单,校验订单状态
|
// 查询订单,校验订单状态
|
||||||
OmsOrder order = this.getByOrderId(id);
|
OmsOrder order = this.getByOrderId(id);
|
||||||
if (!order.getStatus().equals(OrderStatusEnum.SYS_CANCEL.getCode()) &&
|
if (!order.getStatus().equals(OrderStatusEnum.SYS_CANCEL.getCode()) &&
|
||||||
order.getStatus().equals(OrderStatusEnum.USER_CANCEL.getCode())) {
|
order.getStatus().equals(OrderStatusEnum.USER_CANCEL.getCode())) {
|
||||||
throw new BizException(StrUtil.format("订单无法删除,订单状态【{}】", Objects.requireNonNull(OrderStatusEnum.getValue(order.getStatus())).getText()));
|
throw new BizException(StrUtil.format("订单无法删除,订单状态【{}】", Objects.requireNonNull(OrderStatusEnum.getValue(order.getStatus())).getText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
orderLogsService.addOrderLogs(order.getId(), order.getStatus(), "会员删除订单");
|
orderLogService.addOrderLogs(order.getId(), order.getStatus(), "会员删除订单");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +343,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Long> orderIds = orderList.stream().map(orderEntity -> orderEntity.getId()).collect(Collectors.toList());
|
List<Long> orderIds = orderList.stream().map(orderEntity -> orderEntity.getId()).collect(Collectors.toList());
|
||||||
Map<Long, List<OmsOrderItem>> orderGoodsMap = orderGoodsService.getByOrderIds(orderIds);
|
Map<Long, List<OmsOrderItem>> orderGoodsMap = orderItemService.getByOrderIds(orderIds);
|
||||||
List<OrderListVO> result = orderList.stream().map(orderEntity -> {
|
List<OrderListVO> result = orderList.stream().map(orderEntity -> {
|
||||||
OrderListVO orderListVO = BeanMapperUtils.map(orderEntity, OrderListVO.class);
|
OrderListVO orderListVO = BeanMapperUtils.map(orderEntity, OrderListVO.class);
|
||||||
orderListVO.setStatusDesc(OrderStatusEnum.getValue(orderListVO.getStatus()).getText());
|
orderListVO.setStatusDesc(OrderStatusEnum.getValue(orderListVO.getStatus()).getText());
|
||||||
@ -309,63 +358,19 @@ public class OrderServiceImpl extends ServiceImpl<OrderDao, OmsOrder> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OmsOrder getByOrderId(String id) {
|
public OmsOrder getByOrderId(Long id) {
|
||||||
Long userId = RequestUtils.getUserId();
|
Long userId = RequestUtils.getUserId();
|
||||||
QueryWrapper<OmsOrder> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<OmsOrder> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("member_id", userId).eq("id", id);
|
queryWrapper.eq("member_id", userId).eq("id", id);
|
||||||
OmsOrder omsOrder = this.getOne(queryWrapper);
|
OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>()
|
||||||
if (omsOrder == null) {
|
.eq(OmsOrder::getId, id)
|
||||||
|
.eq(OmsOrder::getMemberId, userId));
|
||||||
|
if (order == null) {
|
||||||
throw new BizException("订单不存在,订单ID非法");
|
throw new BizException("订单不存在,订单ID非法");
|
||||||
}
|
}
|
||||||
return omsOrder;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lockStock(List<OmsOrderItem> orderGoods) {
|
|
||||||
List<InventoryDTO> items = orderGoods.stream().map(good -> {
|
|
||||||
InventoryDTO item = new InventoryDTO();
|
|
||||||
item.setInventoryId(good.getSkuId());
|
|
||||||
item.setNum(good.getSkuQuantity());
|
|
||||||
return item;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
Result result = inventoryFeignService.lockInventory(items);
|
|
||||||
if (result == null || !StrUtil.equals(result.getCode(), ResultCode.SUCCESS.getCode())) {
|
|
||||||
log.error("锁定库存异常,商品列表={}", items);
|
|
||||||
throw new BizException("下单失败,锁定库存错误");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算订单商品价格
|
|
||||||
*
|
|
||||||
* @param order
|
|
||||||
* @param orderGoods
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Long computePrice(OmsOrder order, List<OmsOrderItem> orderGoods) {
|
|
||||||
log.info("计算订单价格:order:{},orderGoods:{}", order, orderGoods);
|
|
||||||
if (order == null || CollectionUtil.isEmpty(orderGoods)) {
|
|
||||||
throw new BizException("订单或订单商品列表为空,订单创建失败");
|
|
||||||
}
|
|
||||||
Long totalAmount = orderGoods.stream().mapToLong(OmsOrderItem::getSkuTotalPrice).sum();
|
|
||||||
int totalQuantity = orderGoods.stream().mapToInt(OmsOrderItem::getSkuQuantity).sum();
|
|
||||||
Long payAmount = totalAmount;
|
|
||||||
if (order.getCouponAmount() != null) {
|
|
||||||
payAmount -= order.getCouponAmount();
|
|
||||||
}
|
|
||||||
if (order.getFreightAmount() != null) {
|
|
||||||
payAmount -= order.getFreightAmount();
|
|
||||||
}
|
|
||||||
order.setTotalAmount(totalAmount);
|
|
||||||
order.setTotalQuantity(totalQuantity);
|
|
||||||
order.setPayAmount(payAmount);
|
|
||||||
|
|
||||||
OrderSubmitInfoDTO submit = threadLocal.get();
|
|
||||||
if (!StrUtil.equals(submit.getPayAmount().toString(), payAmount.toString())) {
|
|
||||||
throw new BizException("订单价格变化,请重新提交");
|
|
||||||
}
|
|
||||||
return payAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取订单商品 1. 直接购买 2. 购物车结算
|
* 获取订单商品 1. 直接购买 2. 购物车结算
|
||||||
|
@ -3,11 +3,11 @@ package com.youlai.mall.oms.service.impl;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.mall.oms.dao.OrderSettingDao;
|
import com.youlai.mall.oms.dao.OrderSettingDao;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderSetting;
|
import com.youlai.mall.oms.pojo.domain.OmsOrderSetting;
|
||||||
import com.youlai.mall.oms.service.OrderSettingService;
|
import com.youlai.mall.oms.service.IOrderSettingService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
@Service("orderSettingService")
|
@Service
|
||||||
public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingDao, OmsOrderSetting> implements OrderSettingService {
|
public class OrderSettingServiceImpl extends ServiceImpl<OrderSettingDao, OmsOrderSetting> implements IOrderSettingService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
package com.youlai.mall.oms.controller;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import com.youlai.common.result.ResultCode;
|
|
||||||
import com.youlai.mall.oms.controller.admin.OrderController;
|
|
||||||
import com.youlai.mall.pms.api.app.InventoryFeignService;
|
|
||||||
import com.youlai.mall.ums.api.app.MemberFeignService;
|
|
||||||
import io.seata.spring.annotation.GlobalTransactional;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
||||||
|
|
||||||
|
|
||||||
@AutoConfigureMockMvc
|
|
||||||
@SpringBootTest
|
|
||||||
@Slf4j
|
|
||||||
public class OrderControllerTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public MockMvc mockMvc;
|
|
||||||
@Autowired
|
|
||||||
public OrderController orderController;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 提交订单
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void saveOrder() throws Exception {
|
|
||||||
|
|
||||||
String goods = "{\"order\":{\"userId\":0,\"status\":10,\"source\":0,\"consignee\":\"str\",\"mobile\":\"str\",\"postcode\":\"str\",\"address\":\"str\",\"couponId\":0,\"skuPrice\":0,\"freightPrice\":0,\"couponPrice\":0,\"orderPrice\":0,\"integrationPrice\":0,\"payPrice\":0,\"payId\":\"str\",\"payType\":0,\"payTime\":1606379283562,\"shipSn\":\"str\",\"shipChannel\":\"str\"},\n" +
|
|
||||||
" \"orderItems\":[{\"spuId\":0,\"spuName\":\"str\",\"skuId\":\"0\",\"skuBarCode\":\"str\",\"skuSpecifications\":\"str\",\"skuPrice\":0,\"skuQuantity\":0,\"pic\":\"str\"}]}";
|
|
||||||
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.POST, "/orders")
|
|
||||||
.contentType("application/json")
|
|
||||||
.content(goods))
|
|
||||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
|
||||||
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value(ResultCode.SUCCESS.getCode()))
|
|
||||||
.andDo(print())
|
|
||||||
.andReturn();
|
|
||||||
|
|
||||||
log.info(result.getResponse().getContentAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InventoryFeignService inventoryFeignService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MemberFeignService memberFeignService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IOmsOrderService iOmsOrderService;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@GlobalTransactional(rollbackFor = Exception.class)
|
|
||||||
public void submitOrder() {
|
|
||||||
// 扣减库存
|
|
||||||
// skuFeignService.lockStock(151l, -1);
|
|
||||||
// 增加积分
|
|
||||||
memberFeignService.updatePoint(1l, 10);
|
|
||||||
// 修改订单状态
|
|
||||||
iOmsOrderService.update(new LambdaUpdateWrapper<OmsOrder1>().eq(OmsOrder1::getId, 1l).set(OmsOrder1::getStatus, 901));
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,6 +2,7 @@ package com.youlai.mall.pms.pojo.dto;
|
|||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,11 +11,11 @@ import lombok.Data;
|
|||||||
* @createTime 2021-03-07 15:14
|
* @createTime 2021-03-07 15:14
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ApiModel
|
@Builder
|
||||||
public class InventoryDTO {
|
public class InventoryDTO {
|
||||||
|
|
||||||
@ApiModelProperty("库存ID")
|
@ApiModelProperty("库存ID")
|
||||||
private Long inventoryId;
|
private Long skuId;
|
||||||
|
|
||||||
@ApiModelProperty("数量")
|
@ApiModelProperty("数量")
|
||||||
private Integer num;
|
private Integer num;
|
||||||
|
@ -34,12 +34,12 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
|
|||||||
|
|
||||||
inventories.forEach(item -> {
|
inventories.forEach(item -> {
|
||||||
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
|
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
|
||||||
.eq(PmsSku::getId, item.getInventoryId())
|
.eq(PmsSku::getId, item.getSkuId())
|
||||||
.apply("inventory >= locked_inventory + {0}", item.getNum())
|
.apply("inventory >= locked_inventory + {0}", item.getNum())
|
||||||
.setSql("locked_inventory = locked_inventory + " + item.getNum())
|
.setSql("locked_inventory = locked_inventory + " + item.getNum())
|
||||||
);
|
);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new BizException("锁定库存失败,库存ID:" + item.getInventoryId() + ",数量:" + item.getNum());
|
throw new BizException("锁定库存失败,库存ID:" + item.getSkuId() + ",数量:" + item.getNum());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,11 +52,11 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
|
|||||||
|
|
||||||
inventories.forEach(item -> {
|
inventories.forEach(item -> {
|
||||||
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
|
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
|
||||||
.eq(PmsSku::getId, item.getInventoryId())
|
.eq(PmsSku::getId, item.getSkuId())
|
||||||
.setSql("locked_inventory = locked_inventory - " + item.getNum())
|
.setSql("locked_inventory = locked_inventory - " + item.getNum())
|
||||||
);
|
);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new BizException("解锁库存失败,库存ID:" + item.getInventoryId() + ",数量:" + item.getNum());
|
throw new BizException("解锁库存失败,库存ID:" + item.getSkuId() + ",数量:" + item.getNum());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user