Browse Source

feat:添加临期品订单适配

checkBack
Yen 1 year ago
parent
commit
1467e05b71
  1. 10
      src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java
  2. 1
      src/main/java/com/qs/serve/modules/goods/entity/GoodsImminentBatch.java
  3. 1
      src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java
  4. 119
      src/main/java/com/qs/serve/modules/oms/service/impl/OmsOrderServiceImpl.java
  5. 2
      src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml

10
src/main/java/com/qs/serve/modules/goods/controller/GoodsImminentBatchController.java

@ -50,6 +50,7 @@ public class GoodsImminentBatchController {
LambdaQueryWrapper<GoodsImminentBatch> lqw = new LambdaQueryWrapper<>(param); LambdaQueryWrapper<GoodsImminentBatch> lqw = new LambdaQueryWrapper<>(param);
PageUtil.startPage(); PageUtil.startPage();
List<GoodsImminentBatch> list = goodsImminentBatchService.list(lqw); List<GoodsImminentBatch> list = goodsImminentBatchService.list(lqw);
list.forEach(a->a.setQuantity(a.getQuantity()-a.getOrderQuantity()));
return R.byPageHelperList(list); return R.byPageHelperList(list);
} }
@ -61,8 +62,9 @@ public class GoodsImminentBatchController {
@GetMapping("/getById/{id}") @GetMapping("/getById/{id}")
@SysLog(module = SystemModule.GOODS, title = "临期批次", biz = BizType.QUERY) @SysLog(module = SystemModule.GOODS, title = "临期批次", biz = BizType.QUERY)
public R<GoodsImminentBatch> getById(@PathVariable("id") String id){ public R<GoodsImminentBatch> getById(@PathVariable("id") String id){
GoodsImminentBatch goodsImminentBatch = goodsImminentBatchService.getById(id); GoodsImminentBatch a = goodsImminentBatchService.getById(id);
return R.ok(goodsImminentBatch); a.setQuantity(a.getQuantity()-a.getOrderQuantity());
return R.ok(a);
} }
/** /**
@ -88,6 +90,10 @@ public class GoodsImminentBatchController {
return R.error("已存在订单,无法修改批号"); return R.error("已存在订单,无法修改批号");
} }
} }
int rs = entity.getQuantity()+org.getOrderQuantity();
entity.setQuantity(rs);
boolean result = goodsImminentBatchService.updateById(entity); boolean result = goodsImminentBatchService.updateById(entity);
return R.isTrue(result); return R.isTrue(result);
} }

1
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; private static final long serialVersionUID = 1L;
/** id */ /** id */
@TableId(type = IdType.AUTO)
private Long id; private Long id;
/** skuID */ /** skuID */

1
src/main/java/com/qs/serve/modules/oms/controller/api/OmsOrderApi.java

@ -156,6 +156,7 @@ public class OmsOrderApi {
PageUtil.startPage(); PageUtil.startPage();
LambdaQueryWrapper<OmsOrder> orderWrapper = new LambdaQueryWrapper<>(param); LambdaQueryWrapper<OmsOrder> orderWrapper = new LambdaQueryWrapper<>(param);
orderWrapper.eq(OmsOrder::getUserId,AuthContextUtils.getSysUserId()); orderWrapper.eq(OmsOrder::getUserId,AuthContextUtils.getSysUserId());
orderWrapper.eq(OmsOrder::getOrderType,param.getOrderType()==null?0:param.getOrderType());
orderWrapper.orderByDesc(OmsOrder::getId); orderWrapper.orderByDesc(OmsOrder::getId);
List<OmsOrder> list = omsOrderService.list(orderWrapper); List<OmsOrder> list = omsOrderService.list(orderWrapper);

119
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.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qs.serve.common.config.properties.ProjectApisProperties; 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.model.dto.R;
import com.qs.serve.common.util.*; import com.qs.serve.common.util.*;
import com.qs.serve.modules.bms.entity.BmsRegion; 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.SysDeptService;
import com.qs.serve.modules.sys.service.SysUserService; import com.qs.serve.modules.sys.service.SysUserService;
import com.qs.serve.modules.tbs.common.TbsSeeYonConst; import com.qs.serve.modules.tbs.common.TbsSeeYonConst;
import com.qs.serve.modules.tbs.entity.TbsCostApply;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -84,6 +86,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
private GoodsRuleService goodsRuleService; private GoodsRuleService goodsRuleService;
private GoodsAccreditService goodsAccreditService; private GoodsAccreditService goodsAccreditService;
private GoodsImminentBatchService goodsImminentBatchService; private GoodsImminentBatchService goodsImminentBatchService;
private RedisService redisService;
@Override @Override
@ -233,6 +236,9 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
if(!order.getStatus().equals(0)){ if(!order.getStatus().equals(0)){
Assert.throwEx("非草稿状态无法修改"); Assert.throwEx("非草稿状态无法修改");
} }
if(order.getOrderType().equals(3)){
Assert.throwEx("临期品订单不支持该接口修改");
}
order.setId(param.getId()); order.setId(param.getId());
order.setOrderType(param.getOrderType()); order.setOrderType(param.getOrderType());
order.setOrderSource(param.getOrderSource()); order.setOrderSource(param.getOrderSource());
@ -395,13 +401,28 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
} }
Set<Long> spuIds = orderItems.stream().map(OmsOrderItem::getSpuId).collect(Collectors.toSet()); Set<Long> spuIds = orderItems.stream().map(OmsOrderItem::getSpuId).collect(Collectors.toSet());
List<Long> skuIds = orderItems.stream().map(OmsOrderItem::getSkuId).collect(Collectors.toList()); List<Long> skuIds = orderItems.stream().map(OmsOrderItem::getSkuId).collect(Collectors.toList());
List<GoodsSku> skuList = new ArrayList<>();
if(CollectionUtil.isNotEmpty(skuIds)){ if(CollectionUtil.isNotEmpty(skuIds)){
List<GoodsSpu> spuTmpList = goodsSpuService.listByIds(skuIds); skuList = goodsSkuService.listByIds(skuIds);
spuIds.addAll(spuTmpList.stream().map(GoodsSpu::getId).collect(Collectors.toList())); 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<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds); List<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds);
for (GoodsSpu goodsSpu : spuList) { 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.getCategoryFirst(),goodsSpu);
matchIgnoreCate(igcids,goodsSpu.getCategorySecond(),goodsSpu); matchIgnoreCate(igcids,goodsSpu.getCategorySecond(),goodsSpu);
matchIgnoreCate(igcids,goodsSpu.getCategoryThird(),goodsSpu); matchIgnoreCate(igcids,goodsSpu.getCategoryThird(),goodsSpu);
@ -463,7 +484,15 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
List<OmsShoppingCart> shoppingCarts = confirmOrder.getShoppingCarts(); List<OmsShoppingCart> shoppingCarts = confirmOrder.getShoppingCarts();
OmsOrder order = new OmsOrder(); OmsOrder order = new OmsOrder();
order.setLatitudeFrom(confirmOrder.getLatitudeFrom().toLowerCase(Locale.ROOT)); 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()); GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(confirmOrder.getBrandRuleId());
if(categoryRule!=null){ if(categoryRule!=null){
@ -646,7 +675,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
SysUser user = sysUserService.getById(AuthContextUtils.getSysUserId()); SysUser user = sysUserService.getById(AuthContextUtils.getSysUserId());
GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(param.getBrandRuleId()); GoodsCategoryRule categoryRule = goodsCategoryRuleMapper.selectById(param.getBrandRuleId());
BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId()); BmsSupplier supplier = bmsSupplierMapper.selectById(param.getSupplierId());
BmsSupplierAddress supplierDefaultAddress = bmsSupplierAddressService.getDefault(Long.parseLong(supplier.getId())); BmsSupplierAddress supplierAddress = bmsSupplierAddressService.getById(param.getAddressId());;
OmsOrder order; OmsOrder order;
if(param.getId()!=null){ if(param.getId()!=null){
@ -664,7 +693,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
order.setSupplierId(Long.parseLong(supplier.getId())); order.setSupplierId(Long.parseLong(supplier.getId()));
order.setSupplierCode(supplier.getCode()); order.setSupplierCode(supplier.getCode());
order.setSupplierName(supplier.getName()); order.setSupplierName(supplier.getName());
order.setSupplierAddrId(supplierDefaultAddress!=null?supplierDefaultAddress.getId():0); order.setSupplierAddrId(supplierAddress!=null?supplierAddress.getId():0);
order.setBrandRuleId(param.getBrandRuleId()); order.setBrandRuleId(param.getBrandRuleId());
order.setUserId(user.getId()); order.setUserId(user.getId());
order.setUserName(user.getName()); order.setUserName(user.getName());
@ -675,15 +704,12 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
order.setRemark(param.getRemark()); order.setRemark(param.getRemark());
this.saveOrUpdate(order); this.saveOrUpdate(order);
if(order.getStatus()==null||order.getStatus().equals(0)){ List<OmsOrderItem> orderItems = new ArrayList<>();
if(CollectionUtil.isEmpty(param.getItemList())){
return order;
}
}
if(CollectionUtil.isNotEmpty(param.getItemList())){
Set<Long> batchSkuIds = param.getItemList().stream().map(OmsOrderImminentBo.ItemParam::getBatchSkuId) Set<Long> batchSkuIds = param.getItemList().stream().map(OmsOrderImminentBo.ItemParam::getBatchSkuId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if(CollectionUtil.isEmpty(param.getItemList())){ if(order.getStatus()!=null&&!order.getStatus().equals(0)&&CollectionUtil.isEmpty(param.getItemList())){
Assert.throwEx("请选择商品"); Assert.throwEx("请选择商品");
} }
List<GoodsImminentBatch> imminentBatches = goodsImminentBatchService List<GoodsImminentBatch> imminentBatches = goodsImminentBatchService
@ -708,8 +734,6 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
spuIds.add(0L); spuIds.add(0L);
List<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds); List<GoodsSpu> spuList = goodsSpuService.listByIds(spuIds);
List<OmsOrderItem> orderItems = new ArrayList<>();
for (OmsOrderImminentBo.ItemParam item : param.getItemList()) { for (OmsOrderImminentBo.ItemParam item : param.getItemList()) {
for (GoodsImminentBatch batch : imminentBatches) { for (GoodsImminentBatch batch : imminentBatches) {
if(item.getBatchSkuId().equals(batch.getId())){ if(item.getBatchSkuId().equals(batch.getId())){
@ -739,18 +763,24 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
//拦截品类下单规则 //拦截品类下单规则
this.handleCategoryRule(categoryRule,orderItems); this.handleCategoryRule(categoryRule,orderItems);
}
this.updateById(order); this.updateById(order);
//移除已有的ITEM //移除已有的ITEM
LambdaQueryWrapper<OmsOrderItem> rmItemLqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OmsOrderItem> rmItemLqw = new LambdaQueryWrapper<>();
rmItemLqw.eq(OmsOrderItem::getOrderId,param.getId()); rmItemLqw.eq(OmsOrderItem::getOrderId,param.getId());
omsOrderItemService.remove(rmItemLqw); omsOrderItemService.remove(rmItemLqw);
//重新保存item //重新保存item
if(orderItems.size()>0){
omsOrderItemService.saveBatch(orderItems); omsOrderItemService.saveBatch(orderItems);
}
//立即下单 //立即下单
if(param.getInstantFlag()!=null&&param.getInstantFlag().equals(1)){ if(param.getInstantFlag()!=null&&param.getInstantFlag().equals(1)){
if(supplier.getCdOrderFlag().equals(1) && !StringUtils.hasText(param.getCdOrderRemark()) ){
Assert.throwEx("请补充CD单号");
}
this.buildPriceOrder(order.getId()+"",null); this.buildPriceOrder(order.getId()+"",null);
} }
return order; return order;
} }
@ -799,6 +829,7 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
@Override @Override
public void buildPriceOrder(String id,String amount) { public void buildPriceOrder(String id,String amount) {
redisService.throwResLock(OmsOrder.class.getSimpleName(),id);
OmsOrder omsOrder = super.getById(id); OmsOrder omsOrder = super.getById(id);
String userId = AuthContextUtils.getSysUserId(); String userId = AuthContextUtils.getSysUserId();
SysUser sysUser = sysUserService.getById(userId); SysUser sysUser = sysUserService.getById(userId);
@ -812,9 +843,6 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
if(!omsOrder.getStatus().equals(0)&&!omsOrder.getStatus().equals(6)){ if(!omsOrder.getStatus().equals(0)&&!omsOrder.getStatus().equals(6)){
Assert.throwEx("订单状态不支持下单"); Assert.throwEx("订单状态不支持下单");
} }
if(omsOrder.getOrderType().equals(3)){
Assert.throwEx("临期品订单不支持该接口修改");
}
LambdaQueryWrapper<OmsOrderItem> iteLqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OmsOrderItem> iteLqw = new LambdaQueryWrapper<>();
iteLqw.eq(OmsOrderItem::getOrderId,id); iteLqw.eq(OmsOrderItem::getOrderId,id);
List<OmsOrderItem> orderItemList = omsOrderItemService.list(iteLqw); List<OmsOrderItem> orderItemList = omsOrderItemService.list(iteLqw);
@ -823,6 +851,27 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
Assert.throwEx("空项目不支持下单"); Assert.throwEx("空项目不支持下单");
} }
List<GoodsImminentBatch> 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 //拦截相同的skuItem
long countDistinct = orderItemList.stream().map(OmsOrderItem::getSkuId).distinct().count(); long countDistinct = orderItemList.stream().map(OmsOrderItem::getSkuId).distinct().count();
if(orderItemList.size()!=countDistinct){ if(orderItemList.size()!=countDistinct){
@ -931,7 +980,12 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
xltOrderItem.setXieRuShiJian(nowTime); xltOrderItem.setXieRuShiJian(nowTime);
xltOrderItem.setChuLiShiJian(null); xltOrderItem.setChuLiShiJian(null);
xltOrderItem.setRowCreateDate(nowTime); xltOrderItem.setRowCreateDate(nowTime);
if(omsOrder.getOrderType().equals(3)){
String itemRm = orderItem.getRemark()==null?"":orderItem.getRemark();
xltOrderItem.setBeiZhu("批号["+orderItem.getSkuBatchCode()+"]"+ itemRm);
}else {
xltOrderItem.setBeiZhu(orderItem.getRemark()); xltOrderItem.setBeiZhu(orderItem.getRemark());
}
xltOrderItem.setZhuangTai(0); xltOrderItem.setZhuangTai(0);
xltOrderItemList.add(xltOrderItem); xltOrderItemList.add(xltOrderItem);
} }
@ -944,6 +998,10 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
omsOrder.setCheckUserId(AuthContextUtils.getSysUserId()); omsOrder.setCheckUserId(AuthContextUtils.getSysUserId());
this.updateById(omsOrder); this.updateById(omsOrder);
if(imminentBatches.size() > 0){
goodsImminentBatchService.updateBatchById(imminentBatches);
}
} }
@Override @Override
@ -965,11 +1023,34 @@ public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper,OmsOrder> im
@Override @Override
public boolean cancelOrder(String orderSn) { public boolean cancelOrder(String orderSn) {
seeYonRequestBaseService.postBase(ERP_ORDER_CANCEL+"/"+orderSn OmsOrder order = this.getOne(new LambdaQueryWrapper<OmsOrder>().eq(OmsOrder::getOrderSn,orderSn));
if(order==null){
Assert.throwEx("订单编码异常");
}
List<GoodsImminentBatch> updItemBatch = new ArrayList<>();
if(order.getOrderType().equals(3)){
List<OmsOrderItem> itemList = omsOrderItemService.list(new LambdaQueryWrapper<OmsOrderItem>()
.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 ,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<OmsOrderItem> list) { private void toU8Api(OmsOrder omsOrder, SysUser sysUser, SysDept dept, List<OmsOrderItem> list) {

2
src/main/resources/mapper/goods/GoodsImminentBatchMapper.xml

@ -39,6 +39,7 @@
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third` LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
<where> <where>
and goods_imminent_batch.del_flag = 0 and goods_imminent_batch.del_flag = 0
and goods_imminent_batch.end_date &gt;= now()
and goods_sku.del_flag = 0 and goods_sku.del_flag = 0
and goods_spu.del_flag = 0 and goods_spu.del_flag = 0
and goods_sku.order_flag = 1 and goods_sku.order_flag = 1
@ -65,6 +66,7 @@
LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third` LEFT JOIN `goods_category` `cate3` ON `cate3`.`id` = `goods_spu`.`category_third`
<where> <where>
and goods_imminent_batch.del_flag = 0 and goods_imminent_batch.del_flag = 0
and goods_imminent_batch.end_date &gt;= now()
and goods_sku.del_flag = 0 and goods_sku.del_flag = 0
and goods_spu.del_flag = 0 and goods_spu.del_flag = 0
and goods_sku.order_flag = 1 and goods_sku.order_flag = 1

Loading…
Cancel
Save