diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java index 482bd3b2..ea621045 100644 --- a/src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java @@ -50,6 +50,7 @@ public class GoodsImminentBatchController { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(param); PageUtil.startPage(); List list = goodsImminentBatchService.list(lqw); + list.forEach(a->a.setQuantity(a.getQuantity()-a.getOrderQuantity())); return R.byPageHelperList(list); } @@ -61,8 +62,9 @@ public class GoodsImminentBatchController { @GetMapping("/getById/{id}") @SysLog(module = SystemModule.GOODS, title = "临期批次", biz = BizType.QUERY) public R getById(@PathVariable("id") String id){ - GoodsImminentBatch goodsImminentBatch = goodsImminentBatchService.getById(id); - return R.ok(goodsImminentBatch); + GoodsImminentBatch a = goodsImminentBatchService.getById(id); + a.setQuantity(a.getQuantity()-a.getOrderQuantity()); + return R.ok(a); } /** @@ -88,6 +90,10 @@ public class GoodsImminentBatchController { return R.error("已存在订单,无法修改批号"); } } + + int rs = entity.getQuantity()+org.getOrderQuantity(); + entity.setQuantity(rs); + boolean result = goodsImminentBatchService.updateById(entity); return R.isTrue(result); } diff --git a/src/main/java/com/qs/serve/modules/goods/entity/GoodsImminentBatch.java b/src/main/java/com/qs/serve/modules/goods/entity/GoodsImminentBatch.java index 4306a212..d2235427 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/GoodsImminentBatch.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/GoodsImminentBatch.java @@ -28,6 +28,7 @@ public class GoodsImminentBatch implements Serializable { private static final long serialVersionUID = 1L; /** id */ + @TableId(type = IdType.AUTO) private Long id; /** skuID */ diff --git a/src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java b/src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java index 01abe494..c68962f9 100644 --- a/src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java +++ b/src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java @@ -156,6 +156,7 @@ public class OmsOrderApi { PageUtil.startPage(); LambdaQueryWrapper orderWrapper = new LambdaQueryWrapper<>(param); orderWrapper.eq(OmsOrder::getUserId,AuthContextUtils.getSysUserId()); + orderWrapper.eq(OmsOrder::getOrderType,param.getOrderType()==null?0:param.getOrderType()); orderWrapper.orderByDesc(OmsOrder::getId); List list = omsOrderService.list(orderWrapper); diff --git a/src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java b/src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java index c8b8f64f..e801ae23 100644 --- a/src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java @@ -3,6 +3,7 @@ package com.qs.serve.modules.oms.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qs.serve.common.config.properties.ProjectApisProperties; +import com.qs.serve.common.framework.redis.RedisService; import com.qs.serve.common.model.dto.R; import com.qs.serve.common.util.*; import com.qs.serve.modules.bms.entity.BmsRegion; @@ -37,6 +38,7 @@ import com.qs.serve.modules.sys.entity.SysUser; import com.qs.serve.modules.sys.service.SysDeptService; import com.qs.serve.modules.sys.service.SysUserService; import com.qs.serve.modules.tbs.common.TbsSeeYonConst; +import com.qs.serve.modules.tbs.entity.TbsCostApply; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; @@ -84,6 +86,7 @@ public class OmsOrderServiceImpl extends ServiceImpl im private GoodsRuleService goodsRuleService; private GoodsAccreditService goodsAccreditService; private GoodsImminentBatchService goodsImminentBatchService; + private RedisService redisService; @Override @@ -233,6 +236,9 @@ public class OmsOrderServiceImpl extends ServiceImpl im if(!order.getStatus().equals(0)){ Assert.throwEx("非草稿状态无法修改"); } + if(order.getOrderType().equals(3)){ + Assert.throwEx("临期品订单不支持该接口修改"); + } order.setId(param.getId()); order.setOrderType(param.getOrderType()); order.setOrderSource(param.getOrderSource()); @@ -395,13 +401,28 @@ public class OmsOrderServiceImpl extends ServiceImpl im } Set spuIds = orderItems.stream().map(OmsOrderItem::getSpuId).collect(Collectors.toSet()); List skuIds = orderItems.stream().map(OmsOrderItem::getSkuId).collect(Collectors.toList()); + List skuList = new ArrayList<>(); if(CollectionUtil.isNotEmpty(skuIds)){ - List spuTmpList = goodsSpuService.listByIds(skuIds); - spuIds.addAll(spuTmpList.stream().map(GoodsSpu::getId).collect(Collectors.toList())); + skuList = goodsSkuService.listByIds(skuIds); + for (GoodsSku sku : skuList) { + if(!sku.getOrderFlag().equals(1)&&sku.getSpecialFlag().equals(0)){ + Assert.throwEx("单品["+sku.getSpuCode()+"]不予下单且非特殊品"); + } + } + skuIds.addAll(skuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toList())); } List spuList = goodsSpuService.listByIds(spuIds); for (GoodsSpu goodsSpu : spuList) { + if(!goodsSpu.getShelf().equals(1)){ + Assert.throwEx("SKU已下架["+goodsSpu.getSpuCode()+"]不予下单"); + } + if(!goodsSpu.getOrderFlag().equals(1)){ + boolean msp = skuList.stream().anyMatch(m->m.getSpuId().equals(goodsSpu.getId())&&m.getSpecialFlag().equals(1)); + if(!msp){ + Assert.throwEx("SKU["+goodsSpu.getSpuCode()+"]不予下单"); + } + } matchIgnoreCate(igcids,goodsSpu.getCategoryFirst(),goodsSpu); matchIgnoreCate(igcids,goodsSpu.getCategorySecond(),goodsSpu); matchIgnoreCate(igcids,goodsSpu.getCategoryThird(),goodsSpu); @@ -463,7 +484,15 @@ public class OmsOrderServiceImpl extends ServiceImpl im List shoppingCarts = confirmOrder.getShoppingCarts(); OmsOrder order = new OmsOrder(); order.setLatitudeFrom(confirmOrder.getLatitudeFrom().toLowerCase(Locale.ROOT)); - order.setOrderSn("SN"+CodeGenUtil.generate(CodeGenUtil.SourceKey.OmsOrder)); + String orderPrefix = null; + if(order.getOrderType()==null||order.getOrderType().equals(0)){ + orderPrefix = "SN"; + }else if(order.getOrderType().equals(1)){ + orderPrefix = "ZP"; + }else if(order.getOrderType().equals(2)){ + orderPrefix = "SC"; + } + order.setOrderSn(orderPrefix+CodeGenUtil.generate(CodeGenUtil.SourceKey.OmsOrder)); GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(confirmOrder.getBrandRuleId()); if(categoryRule!=null){ @@ -646,7 +675,7 @@ public class OmsOrderServiceImpl extends ServiceImpl im SysUser user = sysUserService.getById(AuthContextUtils.getSysUserId()); GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(param.getBrandRuleId()); BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId()); - BmsSupplierAddress supplierDefaultAddress = bmsSupplierAddressService.getDefault(Long.parseLong(supplier.getId())); + BmsSupplierAddress supplierAddress = bmsSupplierAddressService.getById(param.getAddressId());; OmsOrder order; if(param.getId()!=null){ @@ -664,7 +693,7 @@ public class OmsOrderServiceImpl extends ServiceImpl im order.setSupplierId(Long.parseLong(supplier.getId())); order.setSupplierCode(supplier.getCode()); order.setSupplierName(supplier.getName()); - order.setSupplierAddrId(supplierDefaultAddress!=null?supplierDefaultAddress.getId():0); + order.setSupplierAddrId(supplierAddress!=null?supplierAddress.getId():0); order.setBrandRuleId(param.getBrandRuleId()); order.setUserId(user.getId()); order.setUserName(user.getName()); @@ -675,69 +704,66 @@ public class OmsOrderServiceImpl extends ServiceImpl im order.setRemark(param.getRemark()); this.saveOrUpdate(order); - if(order.getStatus()==null||order.getStatus().equals(0)){ - if(CollectionUtil.isEmpty(param.getItemList())){ - return order; - } - } - - Set batchSkuIds = param.getItemList().stream().map(OmsOrderImminentBo.ItemParam::getBatchSkuId) - .collect(Collectors.toSet()); - if(CollectionUtil.isEmpty(param.getItemList())){ - Assert.throwEx("请选择商品"); - } - List imminentBatches = goodsImminentBatchService - .list( - new LambdaQueryWrapper() - .in(GoodsImminentBatch::getId,batchSkuIds) - .ge(GoodsImminentBatch::getEndDate, LocalDate.now()) - ); - if(CollectionUtil.isEmpty(imminentBatches)){ - Assert.throwEx("参数过期或无效,请重新选择商品"); - } + List orderItems = new ArrayList<>(); - Set skuIds = imminentBatches.stream() - .map(GoodsImminentBatch::getSkuId).collect(Collectors.toSet()); - if(skuIds.size()!=imminentBatches.size()){ - Assert.throwEx("不同批次相同产品,请分开下单"); - } + if(CollectionUtil.isNotEmpty(param.getItemList())){ + Set batchSkuIds = param.getItemList().stream().map(OmsOrderImminentBo.ItemParam::getBatchSkuId) + .collect(Collectors.toSet()); + if(order.getStatus()!=null&&!order.getStatus().equals(0)&&CollectionUtil.isEmpty(param.getItemList())){ + Assert.throwEx("请选择商品"); + } + List imminentBatches = goodsImminentBatchService + .list( + new LambdaQueryWrapper() + .in(GoodsImminentBatch::getId,batchSkuIds) + .ge(GoodsImminentBatch::getEndDate, LocalDate.now()) + ); + if(CollectionUtil.isEmpty(imminentBatches)){ + Assert.throwEx("参数过期或无效,请重新选择商品"); + } - List goodsSkuList = goodsSkuService.listByIds(skuIds); + Set skuIds = imminentBatches.stream() + .map(GoodsImminentBatch::getSkuId).collect(Collectors.toSet()); + if(skuIds.size()!=imminentBatches.size()){ + Assert.throwEx("不同批次相同产品,请分开下单"); + } - List spuIds = goodsSkuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toList()); - spuIds.add(0L); - List spuList = goodsSpuService.listByIds(spuIds); + List goodsSkuList = goodsSkuService.listByIds(skuIds); - List orderItems = new ArrayList<>(); + List spuIds = goodsSkuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toList()); + spuIds.add(0L); + List spuList = goodsSpuService.listByIds(spuIds); - for (OmsOrderImminentBo.ItemParam item : param.getItemList()) { - for (GoodsImminentBatch batch : imminentBatches) { - if(item.getBatchSkuId().equals(batch.getId())){ - for (GoodsSku sku : goodsSkuList) { - if(sku.getId().toString().equals(batch.getSkuId())){ - //创建OrderItem - OmsOrderItem orderItem = createImminentOrderItem(order, spuList, item, batch, sku); - orderItems.add(orderItem); + for (OmsOrderImminentBo.ItemParam item : param.getItemList()) { + for (GoodsImminentBatch batch : imminentBatches) { + if(item.getBatchSkuId().equals(batch.getId())){ + for (GoodsSku sku : goodsSkuList) { + if(sku.getId().toString().equals(batch.getSkuId())){ + //创建OrderItem + OmsOrderItem orderItem = createImminentOrderItem(order, spuList, item, batch, sku); + orderItems.add(orderItem); + } } } } } - } - List skuCodes = orderItems.stream() - .map(OmsOrderItem::getSkuCode).collect(Collectors.toList()); + List skuCodes = orderItems.stream() + .map(OmsOrderItem::getSkuCode).collect(Collectors.toList()); - //商品特殊价 - buildSkuSpecPrice(supplier, orderItems, skuCodes); + //商品特殊价 + buildSkuSpecPrice(supplier, orderItems, skuCodes); - //拦截商品授权维度规则 - this.checkGoodsRule(supplier, orderItems); + //拦截商品授权维度规则 + this.checkGoodsRule(supplier, orderItems); - //拦截客户维度规则 - goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); + //拦截客户维度规则 + goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); - //拦截品类下单规则 - this.handleCategoryRule(categoryRule,orderItems); + //拦截品类下单规则 + this.handleCategoryRule(categoryRule,orderItems); + + } this.updateById(order); //移除已有的ITEM @@ -745,12 +771,16 @@ public class OmsOrderServiceImpl extends ServiceImpl im rmItemLqw.eq(OmsOrderItem::getOrderId,param.getId()); omsOrderItemService.remove(rmItemLqw); //重新保存item - omsOrderItemService.saveBatch(orderItems); + if(orderItems.size()>0){ + omsOrderItemService.saveBatch(orderItems); + } //立即下单 if(param.getInstantFlag()!=null&¶m.getInstantFlag().equals(1)){ + if(supplier.getCdOrderFlag().equals(1) && !StringUtils.hasText(param.getCdOrderRemark()) ){ + Assert.throwEx("请补充CD单号"); + } this.buildPriceOrder(order.getId()+"",null); } - return order; } @@ -799,6 +829,7 @@ public class OmsOrderServiceImpl extends ServiceImpl im @Override public void buildPriceOrder(String id,String amount) { + redisService.throwResLock(OmsOrder.class.getSimpleName(),id); OmsOrder omsOrder = super.getById(id); String userId = AuthContextUtils.getSysUserId(); SysUser sysUser = sysUserService.getById(userId); @@ -812,9 +843,6 @@ public class OmsOrderServiceImpl extends ServiceImpl im if(!omsOrder.getStatus().equals(0)&&!omsOrder.getStatus().equals(6)){ Assert.throwEx("订单状态不支持下单"); } - if(omsOrder.getOrderType().equals(3)){ - Assert.throwEx("临期品订单不支持该接口修改"); - } LambdaQueryWrapper iteLqw = new LambdaQueryWrapper<>(); iteLqw.eq(OmsOrderItem::getOrderId,id); List orderItemList = omsOrderItemService.list(iteLqw); @@ -823,6 +851,27 @@ public class OmsOrderServiceImpl extends ServiceImpl im Assert.throwEx("空项目不支持下单"); } + List imminentBatches = new ArrayList<>(); + + if(omsOrder.getOrderType().equals(3)){ + //临期品相关拦截 + for (OmsOrderItem orderItem : orderItemList) { + if(orderItem.getSkuBatchId()==null){ + Assert.throwEx(orderItem.getSkuCode() + " 单品无效或过期"); + } + GoodsImminentBatch imminentBatch = goodsImminentBatchService.getById(orderItem.getSkuBatchId()); + if(imminentBatch==null){ + Assert.throwEx(orderItem.getSkuCode() + " 单品无效或过期"); + } + int spur = imminentBatch.getQuantity() - imminentBatch.getOrderQuantity(); + if(orderItem.getQuantity() > spur){ + Assert.throwEx(orderItem.getSkuCode() + " 单品库存不足"); + } + imminentBatch.setOrderQuantity(imminentBatch.getOrderQuantity() + orderItem.getQuantity()); + imminentBatches.add(imminentBatch); + } + + } //拦截相同的skuItem long countDistinct = orderItemList.stream().map(OmsOrderItem::getSkuId).distinct().count(); if(orderItemList.size()!=countDistinct){ @@ -931,7 +980,12 @@ public class OmsOrderServiceImpl extends ServiceImpl im xltOrderItem.setXieRuShiJian(nowTime); xltOrderItem.setChuLiShiJian(null); xltOrderItem.setRowCreateDate(nowTime); - xltOrderItem.setBeiZhu(orderItem.getRemark()); + if(omsOrder.getOrderType().equals(3)){ + String itemRm = orderItem.getRemark()==null?"":orderItem.getRemark(); + xltOrderItem.setBeiZhu("批号["+orderItem.getSkuBatchCode()+"]"+ itemRm); + }else { + xltOrderItem.setBeiZhu(orderItem.getRemark()); + } xltOrderItem.setZhuangTai(0); xltOrderItemList.add(xltOrderItem); } @@ -944,6 +998,10 @@ public class OmsOrderServiceImpl extends ServiceImpl im omsOrder.setCheckUserId(AuthContextUtils.getSysUserId()); this.updateById(omsOrder); + if(imminentBatches.size() > 0){ + goodsImminentBatchService.updateBatchById(imminentBatches); + } + } @Override @@ -965,11 +1023,34 @@ public class OmsOrderServiceImpl extends ServiceImpl im @Override public boolean cancelOrder(String orderSn) { - seeYonRequestBaseService.postBase(ERP_ORDER_CANCEL+"/"+orderSn + OmsOrder order = this.getOne(new LambdaQueryWrapper().eq(OmsOrder::getOrderSn,orderSn)); + if(order==null){ + Assert.throwEx("订单编码异常"); + } + + List updItemBatch = new ArrayList<>(); + if(order.getOrderType().equals(3)){ + List itemList = omsOrderItemService.list(new LambdaQueryWrapper() + .eq(OmsOrderItem::getOrderId,order.getId())); + for (OmsOrderItem orderItem : itemList) { + GoodsImminentBatch batch = goodsImminentBatchService.getById(orderItem.getSkuBatchId()); + GoodsImminentBatch newBatch = new GoodsImminentBatch(); + newBatch.setId(batch.getId()); + newBatch.setOrderQuantity(batch.getOrderQuantity() - orderItem.getQuantity()); + updItemBatch.add(newBatch); + } + } + + R r = seeYonRequestBaseService.postBase(ERP_ORDER_CANCEL+"/"+orderSn ,null ,"获取订单状态" ); - return false; + if(r.getStatus()==200){ + if(CollectionUtil.isNotEmpty(updItemBatch)){ + goodsImminentBatchService.updateBatchById(updItemBatch); + } + } + return r.getStatus()==200; } private void toU8Api(OmsOrder omsOrder, SysUser sysUser, SysDept dept, List list) { diff --git a/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml b/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml index 9fcaad0d..06999b4c 100644 --- a/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml +++ b/src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml @@ -39,6 +39,7 @@ LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third` and goods_imminent_batch.del_flag = 0 + and goods_imminent_batch.end_date >= now() and goods_sku.del_flag = 0 and goods_spu.del_flag = 0 and goods_sku.order_flag = 1 @@ -65,6 +66,7 @@ LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third` and goods_imminent_batch.del_flag = 0 + and goods_imminent_batch.end_date >= now() and goods_sku.del_flag = 0 and goods_spu.del_flag = 0 and goods_sku.order_flag = 1