Commit 6ee78b2a by 刘宇峰

修改断言工具

1 parent 03f44ddd
...@@ -9,6 +9,7 @@ import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListByCondit ...@@ -9,6 +9,7 @@ import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListByCondit
import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListRequest; import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListRequest;
import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListRequestDTO; import cn.com.glsx.admin.modules.model.cloudcrane.request.QueryGoodsListRequestDTO;
import cn.com.glsx.admin.modules.model.cloudcrane.response.*; import cn.com.glsx.admin.modules.model.cloudcrane.response.*;
import cn.hutool.core.lang.Assert;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -17,7 +18,6 @@ import org.apache.commons.collections4.CollectionUtils; ...@@ -17,7 +18,6 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -90,7 +90,7 @@ public class GoodsService { ...@@ -90,7 +90,7 @@ public class GoodsService {
* @date 2023/4/11 10:12 * @date 2023/4/11 10:12
*/ */
public List<QueryGoodsDetailResponse> queryGoodsDetail(List<String> goodsSkuCodes) { public List<QueryGoodsDetailResponse> queryGoodsDetail(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsDetail(goodsSkuCodes); // cloudCraneService.queryGoodsDetail(goodsSkuCodes);
List<Goods> goodsList = goodsMapper.queryGoodsDetail(goodsSkuCodes); List<Goods> goodsList = goodsMapper.queryGoodsDetail(goodsSkuCodes);
...@@ -108,7 +108,7 @@ public class GoodsService { ...@@ -108,7 +108,7 @@ public class GoodsService {
* @date 2023/4/11 11:29 * @date 2023/4/11 11:29
*/ */
public List<QueryGoodsImageListResponse> queryGoodsImageList(List<String> goodsSkuCodes) { public List<QueryGoodsImageListResponse> queryGoodsImageList(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsImageList(goodsSkuCodes); // cloudCraneService.queryGoodsImageList(goodsSkuCodes);
return goodsImageMapper.queryGoodsImageList(goodsSkuCodes); return goodsImageMapper.queryGoodsImageList(goodsSkuCodes);
} }
...@@ -122,7 +122,7 @@ public class GoodsService { ...@@ -122,7 +122,7 @@ public class GoodsService {
* @date 2023/4/11 11:35 * @date 2023/4/11 11:35
*/ */
public List<QueryGoodsShelvesListResponse> queryGoodsShelvesList(List<String> goodsSkuCodes) { public List<QueryGoodsShelvesListResponse> queryGoodsShelvesList(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsShelvesList(goodsSkuCodes); // cloudCraneService.queryGoodsShelvesList(goodsSkuCodes);
return goodsMapper.queryGoodsShelvesList(goodsSkuCodes); return goodsMapper.queryGoodsShelvesList(goodsSkuCodes);
} }
...@@ -136,7 +136,7 @@ public class GoodsService { ...@@ -136,7 +136,7 @@ public class GoodsService {
* @date 2023/4/11 11:38 * @date 2023/4/11 11:38
*/ */
public List<QueryGoodsPriceListResponse> queryGoodsPriceList(List<String> goodsSkuCodes) { public List<QueryGoodsPriceListResponse> queryGoodsPriceList(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsPriceList(goodsSkuCodes); // cloudCraneService.queryGoodsPriceList(goodsSkuCodes);
return goodsMapper.queryGoodsPriceList(goodsSkuCodes); return goodsMapper.queryGoodsPriceList(goodsSkuCodes);
} }
...@@ -150,7 +150,7 @@ public class GoodsService { ...@@ -150,7 +150,7 @@ public class GoodsService {
* @date 2023/4/11 11:44 * @date 2023/4/11 11:44
*/ */
public List<QueryGoodsStockListResponse> queryGoodsStockList(List<String> goodsSkuCodes) { public List<QueryGoodsStockListResponse> queryGoodsStockList(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsStockList(goodsSkuCodes); // cloudCraneService.queryGoodsStockList(goodsSkuCodes);
return goodsStockMapper.queryGoodsStockList(goodsSkuCodes); return goodsStockMapper.queryGoodsStockList(goodsSkuCodes);
} }
...@@ -164,7 +164,7 @@ public class GoodsService { ...@@ -164,7 +164,7 @@ public class GoodsService {
* @date 2023/4/11 11:55 * @date 2023/4/11 11:55
*/ */
public List<QueryGoodsSaleLimitListResponse> queryGoodsSaleLimitList(List<String> goodsSkuCodes) { public List<QueryGoodsSaleLimitListResponse> queryGoodsSaleLimitList(List<String> goodsSkuCodes) {
Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes can not be null."); Assert.notEmpty(goodsSkuCodes, "goodsSkuCodes cannot be empty.");
// cloudCraneService.queryGoodsSaleLimitList(goodsSkuCodes); // cloudCraneService.queryGoodsSaleLimitList(goodsSkuCodes);
return goodsSaleLimitMapper.queryGoodsSaleLimitList(goodsSkuCodes); return goodsSaleLimitMapper.queryGoodsSaleLimitList(goodsSkuCodes);
} }
......
...@@ -17,10 +17,12 @@ import cn.com.glsx.admin.modules.model.cloudcrane.request.OrderGoodsSkuModel; ...@@ -17,10 +17,12 @@ import cn.com.glsx.admin.modules.model.cloudcrane.request.OrderGoodsSkuModel;
import cn.com.glsx.admin.modules.model.cloudcrane.response.OrderChildOrderDetailItem; import cn.com.glsx.admin.modules.model.cloudcrane.response.OrderChildOrderDetailItem;
import cn.com.glsx.admin.modules.model.cloudcrane.response.OrderGoodsListItem; import cn.com.glsx.admin.modules.model.cloudcrane.response.OrderGoodsListItem;
import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryOrderDetailResponse; import cn.com.glsx.admin.modules.model.cloudcrane.response.QueryOrderDetailResponse;
import cn.hutool.core.lang.Assert;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.glsx.plat.common.utils.DateUtils; import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.common.utils.SnowFlake; import com.glsx.plat.common.utils.SnowFlake;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
...@@ -28,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -28,7 +30,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example;
import java.util.*; import java.util.*;
...@@ -80,17 +81,20 @@ public class OrderChildService implements InitializingBean { ...@@ -80,17 +81,20 @@ public class OrderChildService implements InitializingBean {
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public void orderGoodsCheck(CreateOrderRequest req) { public void orderGoodsCheck(CreateOrderRequest req) {
if (CollectionUtils.isEmpty(req.getGoodsSkuList())) {
return;
}
for (OrderGoodsSkuModel goodsSkuModel : req.getGoodsSkuList()) { for (OrderGoodsSkuModel goodsSkuModel : req.getGoodsSkuList()) {
String goodsSkuCode = goodsSkuModel.getGoodsSkuCode(); String goodsSkuCode = goodsSkuModel.getGoodsSkuCode();
Goods goods = goodsMapper.selectByGoodsSkuCode(goodsSkuCode); Goods goods = goodsMapper.selectByGoodsSkuCode(goodsSkuCode);
Assert.notNull(goods, "商品不存在,goodsSkuCode:" + goodsSkuCode); Assert.notNull(goods, "商品{}不存在", goodsSkuCode);
Assert.isTrue(goods.getIsDeleted() == 0, "商品已被删除,goodsSkuCode:" + goodsSkuCode); Assert.isTrue(goods.getIsDeleted() == 0, "商品{}已被删除" + goodsSkuCode);
//校验库存 //校验库存
GoodsStock goodsStock = goodsStockMapper.selectByGoodsSkuCode(goodsSkuCode); GoodsStock goodsStock = goodsStockMapper.selectByGoodsSkuCode(goodsSkuCode);
Assert.isTrue(goodsStock == null || goodsStock.getStockStatus().equals(StockStatusEnum.NO_STOCK.getValue()) || goodsSkuModel.getSellQty().intValue() < goodsStock.getStockNum(), "商品库存不足,goodsSkuCode:" + goodsSkuCode); Assert.isTrue(goodsStock == null || goodsStock.getStockStatus().equals(StockStatusEnum.NO_STOCK.getValue()) || goodsSkuModel.getSellQty() < goodsStock.getStockNum(), "商品库存不足,goodsSkuCode:" + goodsSkuCode);
Assert.isTrue(goods.getIsDeleted() == 0, "商品已被删除,goodsSkuCode:" + goodsSkuCode); Assert.isTrue(goods.getIsDeleted() == 0, "商品{}已被删除", goodsSkuCode);
int updateCount = goodsStockMapper.reduceGoodsStockById(goodsSkuCode, goodsSkuModel.getSellQty()); int updateCount = goodsStockMapper.reduceGoodsStockById(goodsSkuCode, goodsSkuModel.getSellQty());
Assert.isTrue(updateCount > 0, "商品库存不足,goodsSkuCode:" + goodsSkuCode); Assert.isTrue(updateCount > 0, "商品{}库存不足", goodsSkuCode);
} }
} }
...@@ -127,7 +131,7 @@ public class OrderChildService implements InitializingBean { ...@@ -127,7 +131,7 @@ public class OrderChildService implements InitializingBean {
for (OrderGoodsListItem goodsItem : orderGoodsList) { for (OrderGoodsListItem goodsItem : orderGoodsList) {
String goodsSkuCode = goodsItem.getGoodsSkuCode(); String goodsSkuCode = goodsItem.getGoodsSkuCode();
Goods goods = localGoodsMap.get(goodsSkuCode); Goods goods = localGoodsMap.get(goodsSkuCode);
Assert.notNull(goods, "商品不存在,goodsSkuCode:" + goodsSkuCode); Assert.notNull(goods, "商品{}不存在,goodsSkuCode:" + goodsSkuCode);
//组装订单商品 //组装订单商品
GoodsImage goodsImage = localGoodsImageMap.get(goodsSkuCode); GoodsImage goodsImage = localGoodsImageMap.get(goodsSkuCode);
......
...@@ -6,6 +6,7 @@ import cn.com.glsx.admin.modules.enums.SubmitStateEnum; ...@@ -6,6 +6,7 @@ import cn.com.glsx.admin.modules.enums.SubmitStateEnum;
import cn.com.glsx.admin.modules.mapper.OrderMapper; import cn.com.glsx.admin.modules.mapper.OrderMapper;
import cn.com.glsx.admin.modules.model.cloudcrane.request.*; import cn.com.glsx.admin.modules.model.cloudcrane.request.*;
import cn.com.glsx.admin.modules.model.cloudcrane.response.*; import cn.com.glsx.admin.modules.model.cloudcrane.response.*;
import cn.hutool.core.lang.Assert;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
...@@ -17,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,7 +18,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
...@@ -47,6 +47,8 @@ public class OrderService { ...@@ -47,6 +47,8 @@ public class OrderService {
*/ */
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public CreateOrderResponse createOrder(CreateOrderRequest req) { public CreateOrderResponse createOrder(CreateOrderRequest req) {
Assert.notEmpty(req.getGoodsSkuList(), "订单{}购买商品不能为空", req.getTparOrderCode());
String tparOrderCode = getTparOrderCode(req); String tparOrderCode = getTparOrderCode(req);
//商品校验和预减库存 //商品校验和预减库存
orderChildService.orderGoodsCheck(req); orderChildService.orderGoodsCheck(req);
...@@ -86,8 +88,8 @@ public class OrderService { ...@@ -86,8 +88,8 @@ public class OrderService {
@Transactional(propagation = Propagation.REQUIRED) @Transactional(propagation = Propagation.REQUIRED)
public ConfirmOrderResponse confirmOrder(ConfirmOrderRequest req) { public ConfirmOrderResponse confirmOrder(ConfirmOrderRequest req) {
Order order = orderMapper.selectByTparOrderCode(req.getTparOrderCode()); Order order = orderMapper.selectByTparOrderCode(req.getTparOrderCode());
Assert.notNull(order, "订单不存在:" + req.getTparOrderCode()); Assert.notNull(order, "订单{}不存在", req.getTparOrderCode());
Assert.isTrue(order.getSubmitState().equals(SubmitStateEnum.PRE_ORDER.getValue()), "订单非预占状态:" + req.getTparOrderCode()); Assert.isTrue(order.getSubmitState().equals(SubmitStateEnum.PRE_ORDER.getValue()), "订单{}非预占状态", req.getTparOrderCode());
//向第三方提交确认订单 //向第三方提交确认订单
ConfirmOrderResponse confirmOrderResponse = cloudCraneService.confirmOrder(req); ConfirmOrderResponse confirmOrderResponse = cloudCraneService.confirmOrder(req);
order.setSubmitState(SubmitStateEnum.CONFIRM_ORDER.getValue()); order.setSubmitState(SubmitStateEnum.CONFIRM_ORDER.getValue());
...@@ -158,7 +160,7 @@ public class OrderService { ...@@ -158,7 +160,7 @@ public class OrderService {
if (StringUtils.isNotEmpty(tparOrderCode)) { if (StringUtils.isNotEmpty(tparOrderCode)) {
//判断库中是否已存在该订单 //判断库中是否已存在该订单
Order order = orderMapper.selectByTparOrderCode(req.getTparOrderCode()); Order order = orderMapper.selectByTparOrderCode(req.getTparOrderCode());
Assert.isTrue(order == null, "已存在该订单编号:" + req.getTparOrderCode()); Assert.isNull(order, "已存在该订单编号{}", req.getTparOrderCode());
} else { } else {
//未传订单号就随机生成一个 //未传订单号就随机生成一个
tparOrderCode = MAIN_ORDER_CODE_PRIX + SnowFlake.nextSerialNumber(); tparOrderCode = MAIN_ORDER_CODE_PRIX + SnowFlake.nextSerialNumber();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!