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 71e580b6..482bd3b2 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 @@ -12,6 +12,8 @@ import com.qs.serve.common.util.StringUtils; import com.qs.serve.modules.goods.entity.GoodsSku; import com.qs.serve.modules.goods.entity.bo.GoodsImminentBatchBo; import com.qs.serve.modules.goods.service.GoodsSkuService; +import com.qs.serve.modules.oms.entity.OmsOrderItem; +import com.qs.serve.modules.oms.service.OmsOrderItemService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; @@ -34,6 +36,7 @@ import java.util.List; @RequestMapping("goods/imminentBatch") public class GoodsImminentBatchController { + private OmsOrderItemService orderItemService; private GoodsImminentBatchService goodsImminentBatchService; private GoodsSkuService goodsSkuService; @@ -67,12 +70,24 @@ public class GoodsImminentBatchController { * @param param * @return */ - @PostMapping("/updateById") + @PostMapping("/update") @SysLog(module = SystemModule.GOODS, title = "临期批次", biz = BizType.UPDATE) public R updateById(@RequestBody @Valid GoodsImminentBatchBo param){ - //param.setBatchCode(null); param.setSkuId(null); GoodsImminentBatch entity = CopierUtil.copy(param,new GoodsImminentBatch()); + if(goodsImminentBatchService.checkExist(param.getBatchCode(),param.getSkuId(),entity.getId())){ + return R.error("已重复"); + } + GoodsImminentBatch org = goodsImminentBatchService.getById(param.getId()); + if(!org.getBatchCode().equals(entity.getBatchCode())){ + long count = orderItemService.count( + new LambdaQueryWrapper() + .eq(OmsOrderItem::getSkuBatchId,param.getId()) + ); + if(count>0){ + return R.error("已存在订单,无法修改批号"); + } + } boolean result = goodsImminentBatchService.updateById(entity); return R.isTrue(result); } @@ -89,7 +104,7 @@ public class GoodsImminentBatchController { GoodsSku goodsSku = goodsSkuService.getById(param.getSkuId()); entity.setSkuCode(goodsSku.getSkuCode()); entity.setSkuName(goodsSku.getSkuName()); - if(goodsImminentBatchService.checkExist(param.getBatchCode(),param.getSkuId())){ + if(goodsImminentBatchService.checkExist(param.getBatchCode(),param.getSkuId(),0L)){ return R.error("已重复"); } boolean result = goodsImminentBatchService.save(entity); 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 7f192aa7..4306a212 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,7 +28,7 @@ public class GoodsImminentBatch implements Serializable { private static final long serialVersionUID = 1L; /** id */ - private Integer id; + private Long id; /** skuID */ @NotBlank(message = "skuID不能为空") @@ -99,11 +99,13 @@ public class GoodsImminentBatch implements Serializable { /** 查询开始 */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") + @TableField(exist = false) private LocalDate queryStartDate; /** 查询结束 */ @DateTimeFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8") + @TableField(exist = false) private LocalDate queryEndDate; } diff --git a/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsImminentBatchBo.java b/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsImminentBatchBo.java index bdafed58..486df7bf 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsImminentBatchBo.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/bo/GoodsImminentBatchBo.java @@ -26,7 +26,7 @@ public class GoodsImminentBatchBo implements Serializable { private static final long serialVersionUID = 1L; /** id */ - private Integer id; + private Long id; /** skuID */ @NotBlank(message = "skuID不能为空") diff --git a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java index 1b897909..d23143f5 100644 --- a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java +++ b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsImminentBatchMapper.java @@ -17,5 +17,11 @@ import java.util.List; */ public interface GoodsImminentBatchMapper extends BaseMapper { + @InterceptorIgnore(tenantLine = "1") + long countVoList(@Param("query") GoodsImminentBatchQuery query); + + @InterceptorIgnore(tenantLine = "1") + List selectVoList(@Param("query") GoodsImminentBatchQuery query, @Param("pageInfo") RowParam rowParam); + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java index 0600d4f5..c8f8cecf 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsImminentBatchService.java @@ -14,7 +14,7 @@ import java.util.List; */ public interface GoodsImminentBatchService extends IService { - boolean checkExist(String batchCode,String skuId); + boolean checkExist(String batchCode,String skuId,Long rowId); long countVoList(GoodsImminentBatchQuery query); diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java index c1ec5362..30332f17 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsImminentBatchServiceImpl.java @@ -25,8 +25,12 @@ import java.util.List; public class GoodsImminentBatchServiceImpl extends ServiceImpl implements GoodsImminentBatchService { @Override - public boolean checkExist(String batchCode, String skuId) { - long count = this.count(new LambdaQueryWrapper().eq(GoodsImminentBatch::getBatchCode,batchCode).eq(GoodsImminentBatch::getSkuId,skuId)); + public boolean checkExist(String batchCode, String skuId,Long rowId) { + long count = this.count(new LambdaQueryWrapper() + .eq(GoodsImminentBatch::getBatchCode,batchCode) + .eq(GoodsImminentBatch::getSkuId,skuId) + .ne(GoodsImminentBatch::getId,rowId) + ); return count>0; } 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 f13ac039..bd378819 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 @@ -22,10 +22,7 @@ import com.qs.serve.modules.goods.service.GoodsSkuService; import com.qs.serve.modules.goods.service.GoodsSpuService; import com.qs.serve.modules.oms.entity.OmsOrder; import com.qs.serve.modules.oms.entity.OmsOrderItem; -import com.qs.serve.modules.oms.entity.bo.OmsCancelOrder; -import com.qs.serve.modules.oms.entity.bo.OmsOrderBo; -import com.qs.serve.modules.oms.entity.bo.OmsOrderModifyParam; -import com.qs.serve.modules.oms.entity.bo.OmsOrderSkuBo; +import com.qs.serve.modules.oms.entity.bo.*; import com.qs.serve.modules.oms.entity.vo.OmsConfirmOrderResult; import com.qs.serve.modules.oms.service.OmsOrderItemService; import com.qs.serve.modules.oms.service.OmsOrderService; @@ -43,8 +40,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static com.qs.serve.modules.tbs.common.TbsSeeYonConst.ERP_ORDER_STATUS; - /** * API订单模块 订单 * @author YenHex @@ -301,7 +296,7 @@ public class OmsOrderApi { } /** - * 删除 + * 删除订单 * @param id * @return */ @@ -317,5 +312,26 @@ public class OmsOrderApi { return R.error("当前状态无法删除"); } + /** + * 创建临期品订单 + * @param omsOrderBo + * @return + */ + @PostMapping("/createImminentOrder") + public R createImminentOrder(@RequestBody @Valid OmsOrderImminentBo omsOrderBo){ + return R.ok(omsOrderService.modifyImminentOrder(omsOrderBo)); + } + + /** + * 修改临期品的订单 + * @param param + * @return + */ + @PostMapping("/modifyImminentOrder") + public R modifyImminentOrder(@RequestBody @Valid OmsOrderImminentBo param){ + omsOrderService.modifyImminentOrder(param); + return R.ok(); + } + } diff --git a/src/main/java/com/qs/serve/modules/oms/entity/OmsOrderItem.java b/src/main/java/com/qs/serve/modules/oms/entity/OmsOrderItem.java index 7e7db682..d36d49d9 100644 --- a/src/main/java/com/qs/serve/modules/oms/entity/OmsOrderItem.java +++ b/src/main/java/com/qs/serve/modules/oms/entity/OmsOrderItem.java @@ -51,7 +51,12 @@ public class OmsOrderItem implements Serializable { private String skuTitle; - /** skuId */ + /** skuBatchId */ + private Long skuBatchId; + + /** skuBatchCode */ + private String skuBatchCode; + private Long skuId; /** sku编码 */ diff --git a/src/main/java/com/qs/serve/modules/oms/entity/bo/OmsOrderImminentBo.java b/src/main/java/com/qs/serve/modules/oms/entity/bo/OmsOrderImminentBo.java new file mode 100644 index 00000000..af718024 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/oms/entity/bo/OmsOrderImminentBo.java @@ -0,0 +1,58 @@ +package com.qs.serve.modules.oms.entity.bo; + +import lombok.Data; + +import java.util.List; + +/** + * @author YenHex + * @since 2022/10/14 + */ +@Data +public class OmsOrderImminentBo { + + /** 编辑时必填 */ + private String id; + + private String supplierId; + + private String orderSource; + + /** SKU下单列表 */ + private List itemList; + + /** 品牌规则ID */ + private Long brandRuleId; + + /** 立刻下单标识 */ + private Integer instantFlag; + + /** CD单据备注 */ + private String cdOrderRemark; + + /** 收货地址 */ + private Long addressId; + + /** 发票类型:0->普通发票;1->增值税发票; */ + private Integer billType; + + /** 是否加急 */ + private Integer urgentFlag; + + /** 备注 */ + private String remark; + + @Data + public static class ItemParam{ + + private Long batchSkuId; + + /** 数量 */ + private Integer qty; + + + private String remark; + + } + +} diff --git a/src/main/java/com/qs/serve/modules/oms/service/OmsOrderService.java b/src/main/java/com/qs/serve/modules/oms/service/OmsOrderService.java index c6eb1eb7..ff1b33da 100644 --- a/src/main/java/com/qs/serve/modules/oms/service/OmsOrderService.java +++ b/src/main/java/com/qs/serve/modules/oms/service/OmsOrderService.java @@ -2,10 +2,7 @@ package com.qs.serve.modules.oms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.qs.serve.modules.oms.entity.OmsOrder; -import com.qs.serve.modules.oms.entity.bo.OmsOrderBo; -import com.qs.serve.modules.oms.entity.bo.OmsOrderModifyParam; -import com.qs.serve.modules.oms.entity.bo.OmsOrderSkuBo; -import com.qs.serve.modules.oms.entity.bo.OmsSpuAssesInfoBo; +import com.qs.serve.modules.oms.entity.bo.*; import com.qs.serve.modules.oms.entity.vo.OmsConfirmOrderResult; import com.qs.serve.modules.oms.entity.vo.OmsSpuAssesInfo; @@ -74,5 +71,12 @@ public interface OmsOrderService extends IService { */ void buildPriceOrder(String id,String amount); + /** + * 临期品订单 + * @param param + * @return + */ + String modifyImminentOrder(OmsOrderImminentBo param); + } 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 01ad0f0e..fb658ab5 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 @@ -46,6 +46,7 @@ import com.qs.serve.modules.oms.mapper.OmsOrderMapper; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -82,6 +83,7 @@ public class OmsOrderServiceImpl extends ServiceImpl im private SeeYonRequestBaseService seeYonRequestBaseService; private GoodsRuleService goodsRuleService; private GoodsAccreditService goodsAccreditService; + private GoodsImminentBatchService goodsImminentBatchService; @Override @@ -333,35 +335,11 @@ public class OmsOrderServiceImpl extends ServiceImpl im //防止空指针 skuCodes.add("NULL"); - List customerPrices = goodsCustomerPriceService.getBySupplierCodeAndCode(supplier.getCode(),skuCodes); - for (OmsOrderItem orderItem : newOrderItemList) { - for (GoodsCustomerPrice customerPrice : customerPrices) { - if(orderItem.getSkuCode().equals(customerPrice.getSkuCode())){ - orderItem.setSalesPrice(customerPrice.getRealPrice()); - break; - } - } - } + //商品特殊价 + this.buildSkuSpecPrice(supplier, newOrderItemList, skuCodes); //拦截商品授权维度规则 - GoodsAccrIdsDto accrIdsDto = goodsAccreditService.listIgnoreAcc2(supplier.getId(),supplier.listBizRegionIds(),supplier.listSaleRegionIds()); - if(accrIdsDto!=null){ - List skuIds = goodsSkuMapper.listByOtherIds( - accrIdsDto.getCateIds(), - accrIdsDto.getSpuIds(), - accrIdsDto.getSkuIds(), - accrIdsDto.getNotInCateIds(), - accrIdsDto.getNotInSpuIds(), - accrIdsDto.getNotInSkuIds() - ); - for (OmsOrderItem orderItem : newOrderItemList) { - for (Long skuId : skuIds) { - if(orderItem.getSkuId().equals(skuId)){ - Assert.throwEx("商品未授权:"+orderItem.getSkuCode()); - } - } - } - } + this.checkGoodsRule(supplier, newOrderItemList); //拦截客户维度规则 goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); @@ -382,6 +360,27 @@ public class OmsOrderServiceImpl extends ServiceImpl im } } + private void checkGoodsRule(BmsSupplier supplier, List newOrderItemList) { + GoodsAccrIdsDto accrIdsDto = goodsAccreditService.listIgnoreAcc2(supplier.getId(), supplier.listBizRegionIds(), supplier.listSaleRegionIds()); + if(accrIdsDto!=null){ + List skuIds = goodsSkuMapper.listByOtherIds( + accrIdsDto.getCateIds(), + accrIdsDto.getSpuIds(), + accrIdsDto.getSkuIds(), + accrIdsDto.getNotInCateIds(), + accrIdsDto.getNotInSpuIds(), + accrIdsDto.getNotInSkuIds() + ); + for (OmsOrderItem orderItem : newOrderItemList) { + for (Long skuId : skuIds) { + if(orderItem.getSkuId().equals(skuId)){ + Assert.throwEx("商品未授权:"+orderItem.getSkuCode()); + } + } + } + } + } + /** * 拦截规则 * @param categoryRule @@ -640,6 +639,154 @@ public class OmsOrderServiceImpl extends ServiceImpl im return spuAssesInfoList; } + @Override + public String modifyImminentOrder(OmsOrderImminentBo param) { + + 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())); + + OmsOrder order; + if(param.getId()!=null){ + order = this.getById(param.getId()); + }else { + order = new OmsOrder(); + order.setOrderSn("SP"+CodeGenUtil.generate(CodeGenUtil.SourceKey.OmsOrder)); + } + order.setLatitudeFrom("sp"); + order.setCdOrderRemark(param.getCdOrderRemark()); + order.setOrderType(1); + order.setSupplierId(Long.parseLong(supplier.getId())); + order.setSupplierCode(supplier.getCode()); + order.setSupplierName(supplier.getName()); + order.setSupplierAddrId(supplierDefaultAddress!=null?supplierDefaultAddress.getId():0); + order.setBrandRuleId(param.getBrandRuleId()); + order.setUserId(user.getId()); + order.setUserName(user.getName()); + order.setUserCode(user.getCode()); + order.setUserPhone(user.getMobile()); + order.setBillType(param.getBillType()); + order.setUrgentFlag(param.getUrgentFlag()); + order.setRemark(param.getRemark()); + this.save(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("参数过期或无效,请重新选择商品"); + } + + Set skuIds = imminentBatches.stream() + .map(GoodsImminentBatch::getSkuId).collect(Collectors.toSet()); + if(skuIds.size()!=imminentBatches.size()){ + Assert.throwEx("不同批次相同产品,请分开下单"); + } + + List goodsSkuList = goodsSkuService.listByIds(skuIds); + + List spuIds = goodsSkuList.stream().map(GoodsSku::getSpuId).collect(Collectors.toList()); + spuIds.add(0L); + List spuList = goodsSpuService.listByIds(spuIds); + + List orderItems = new ArrayList<>(); + + 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()); + + //商品特殊价 + buildSkuSpecPrice(supplier, orderItems, skuCodes); + + //拦截商品授权维度规则 + this.checkGoodsRule(supplier, orderItems); + + //拦截客户维度规则 + goodsRuleService.checkSkuCode(skuCodes,goodsRuleService.listBySupplierId(order.getSupplierId().toString()),true); + + //拦截品类下单规则 + this.handleCategoryRule(categoryRule,orderItems); + + this.updateById(order); + //移除已有的ITEM + LambdaQueryWrapper rmItemLqw = new LambdaQueryWrapper<>(); + rmItemLqw.eq(OmsOrderItem::getOrderId,param.getId()); + omsOrderItemService.remove(rmItemLqw); + //重新保存item + omsOrderItemService.saveBatch(orderItems); + //立即下单 + if(param.getInstantFlag()!=null&¶m.getInstantFlag().equals(1)){ + this.buildPriceOrder(order.getId()+"",null); + } + + return order.getId().toString(); + } + + @NotNull + private OmsOrderItem createImminentOrderItem(OmsOrder order, List spuList, OmsOrderImminentBo.ItemParam item, GoodsImminentBatch batch, GoodsSku sku) { + OmsOrderItem orderItem = new OmsOrderItem(); + orderItem.setOrderId(order.getId()); + orderItem.setOrderSn(order.getOrderSn()); + orderItem.setSpuId(sku.getId()); + for (GoodsSpu spu : spuList) { + if(sku.getSpuId().equals(spu.getId())){ + orderItem.setSpuCode(spu.getSpuCode()); + orderItem.setSpuTitle(spu.getSpuCode()); + break; + } + } + orderItem.setWeight(sku.getWeight()); + orderItem.setVolume(sku.getVolume()); + orderItem.setRemark(sku.getRemark()); + orderItem.setSkuBatchId(batch.getId()); + orderItem.setSkuBatchCode(batch.getBatchCode()); + orderItem.setSkuId(sku.getId()); + orderItem.setSkuTitle(sku.getSkuName()); + orderItem.setSkuCode(sku.getSkuCode()); + orderItem.setSpecValues(sku.getSpecInfos()); + orderItem.setSkuUnit(sku.getUnitName()); + orderItem.setSkuImg(sku.getPicUrl()); + orderItem.setSalesPrice(sku.getSalesPrice()); + orderItem.setCusPrice(sku.getSalesPrice()); + orderItem.setMarketPrice(sku.getMarketPrice()); + orderItem.setQuantity(item.getQty()); + return orderItem; + } + + private void buildSkuSpecPrice(BmsSupplier supplier, List orderItems, List skuCodes) { + List customerPrices = goodsCustomerPriceService.getBySupplierCodeAndCode(supplier.getCode(), skuCodes); + for (OmsOrderItem orderItem : orderItems) { + for (GoodsCustomerPrice customerPrice : customerPrices) { + if (orderItem.getSkuCode().equals(customerPrice.getSkuCode())) { + orderItem.setSalesPrice(customerPrice.getRealPrice()); + break; + } + } + } + } + @Override public void buildPriceOrder(String id,String amount) { OmsOrder omsOrder = super.getById(id);