From f04b126adf3c8b6689217e36bee29530942709e0 Mon Sep 17 00:00:00 2001 From: Yen Date: Thu, 16 Nov 2023 11:27:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=A4=E4=B8=AA=E6=9C=88?= =?UTF-8?q?=E5=8F=91=E8=B4=A7=E5=8D=95spu=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/mapper/ErpDispatchDataMapper.java | 7 + .../goods/controller/GoodsSpuController.java | 147 +++++++++++------- .../goods/entity/so/GoodsHisOrderQuery.java | 16 ++ 3 files changed, 116 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/qs/serve/modules/goods/entity/so/GoodsHisOrderQuery.java diff --git a/src/main/java/com/qs/serve/modules/erp/mapper/ErpDispatchDataMapper.java b/src/main/java/com/qs/serve/modules/erp/mapper/ErpDispatchDataMapper.java index e1144d92..318e1872 100644 --- a/src/main/java/com/qs/serve/modules/erp/mapper/ErpDispatchDataMapper.java +++ b/src/main/java/com/qs/serve/modules/erp/mapper/ErpDispatchDataMapper.java @@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.qs.serve.modules.erp.entity.ErpDispatchData; import com.qs.serve.modules.erp.entity.dto.ErpDispatchSumVo; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.List; /** @@ -33,5 +35,10 @@ public interface ErpDispatchDataMapper extends BaseMapper { @Param("endNumber")Integer endNumber, @Param("cusCodes")List cusCodes); + + @InterceptorIgnore(tenantLine = "1") + @Select("SELECT inv_code FROM `erp_dispatch_data` where `date` > #{lastTowMonth}") + List selectLast2MonthInvCode(@Param("lastTowMonth") LocalDate lastTowMonth); + } diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java index 3b085ef0..964afb3d 100644 --- a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java @@ -8,10 +8,12 @@ import com.qs.serve.common.model.dto.R; import com.qs.serve.common.model.enums.BizType; import com.qs.serve.common.model.enums.SystemModule; import com.qs.serve.common.util.*; +import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; import com.qs.serve.modules.goods.common.GoodsConst; import com.qs.serve.modules.goods.entity.*; import com.qs.serve.modules.goods.entity.bo.*; import com.qs.serve.modules.goods.entity.dto.InventoryCusPrice; +import com.qs.serve.modules.goods.entity.so.GoodsHisOrderQuery; import com.qs.serve.modules.goods.entity.so.InventoryCusPriceQuery; import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; import com.qs.serve.modules.goods.service.*; @@ -25,10 +27,12 @@ import com.qs.serve.modules.tbs.service.TbsBudgetConditionService; import io.netty.util.internal.StringUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -53,6 +57,7 @@ public class GoodsSpuController { private TbsBudgetConditionService budgetConditionService; private GoodsCategoryService goodsCategoryService; private SeeYonRequestBaseService seeYonRequestBaseService; + private ErpDispatchDataMapper dispatchDataMapper; /** * 翻页搜索 @@ -85,63 +90,35 @@ public class GoodsSpuController { @GetMapping("/shelfPageToSku") public R> shelfPageToSku(GoodsSpu param){ PageVo result = this.getShelfPage(param).getData(); - List goodsSpuList = result.getList(); - List spuCodes = goodsSpuList.stream().map(GoodsSpu::getSpuCode).collect(Collectors.toList()); - List toSkuKeys = goodsSpuService.getSpuToSkuInfo(GoodsConst.DEFAULT_PlaCE,spuCodes); - - List inventoryCusPrices = null; - try { - String supplierCode = param.getSupplierCode(); - List skuCodes = toSkuKeys.stream().map(OmsSpuToSkuKey::getInvCode).collect(Collectors.toList()); - if(skuCodes.size()>0){ - InventoryCusPriceQuery query = new InventoryCusPriceQuery(); - query.setCusCode(supplierCode); - query.setInvCodes(skuCodes); - R res = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); - if(res.getStatus().equals(200)){ - inventoryCusPrices = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class); - } - } - } catch (Exception e) { - log.error("客户特殊价异常:{}",e.getMessage()); - } - - for (GoodsSpu spu : goodsSpuList) { - //兼容特殊sku - if(param.getSelectSpecialFlag()!=null&¶m.getSelectSpecialFlag().equals(1)){ - if(!spu.getSpecialSkuId().equals(0L)){ - GoodsSku goodsSku = goodsSkuService.getById(spu.getSpecialSkuId()); - spu.setSkuCode(goodsSku.getSkuCode()); - spu.setSkuPrice(goodsSku.getSalesPrice()); - spu.setVolume(goodsSku.getVolume().toString()); - spu.setWeight(goodsSku.getWeight().toString()); - continue; - } - } - for (OmsSpuToSkuKey skuKey : toSkuKeys) { - if(spu.getSpuCode().equals(skuKey.getSkuCode())){ - GoodsSku goodsSku = goodsSkuService.getByCode(skuKey.getInvCode()); - spu.setSkuCode(goodsSku.getSkuCode()); - spu.setSkuPrice(goodsSku.getSalesPrice()); - spu.setVolume(goodsSku.getVolume().toString()); - spu.setWeight(goodsSku.getWeight().toString()); - if(inventoryCusPrices!=null){ - for (InventoryCusPrice cusPrice : inventoryCusPrices) { - if(cusPrice.getPrice()!=null&&cusPrice.getInvCode().equals(skuKey.getInvCode())){ - spu.setSkuPrice(cusPrice.getPrice()); - break; - } - } - } - break; - } - } - } + List goodsSpuList = this.buildGoodsSpuInfo(param.getSupplierCode(),param.getSelectSpecialFlag(), result.getList()); + result.setList(goodsSpuList); + return R.ok(result); + } - result.setList(goodsSpuList); - return R.ok(result); + /** + * 获取最近两个月发货spu + * @param query + * @return + */ + @PostMapping("listLast2Month") + public R> listLast2Month(@RequestBody @Valid GoodsHisOrderQuery query){ + LocalDate date = LocalDate.now().plusMonths(-2); + List invCodes = dispatchDataMapper.selectLast2MonthInvCode(date); + + if(CollectionUtil.isNotEmpty(invCodes)){ + List goodsSkus = goodsSkuService.getByCodes(invCodes); + List goodsSpuIds = goodsSkus.stream().map(GoodsSku::getSpuId).distinct().collect(Collectors.toList()); + GoodsSpu param = new GoodsSpu(); + param.setSelectIds(goodsSpuIds); + param.setSelectCateIds(query.getCateIds()); + param.setShelf(1); + List list = goodsSpuService.selectSpuList(param); + List goodsSpuList = this.buildGoodsSpuInfo(query.getSupplierCode(),0, list); + return R.ok(goodsSpuList); + } + return R.ok(new ArrayList<>()); } /** @@ -436,5 +413,67 @@ public class GoodsSpuController { } } + /** + * 封装通用的spu信息(客户特殊价,转换并关联开平产SKU) + * @param supplierCode 客户编码 + * @param selectSpecialFlag 兼容特殊sku + * @param goodsSpuList + * @return + */ + @NotNull + private List buildGoodsSpuInfo(String supplierCode,Integer selectSpecialFlag, List goodsSpuList) { + List spuCodes = goodsSpuList.stream().map(GoodsSpu::getSpuCode).collect(Collectors.toList()); + List toSkuKeys = goodsSpuService.getSpuToSkuInfo(GoodsConst.DEFAULT_PlaCE,spuCodes); + + List inventoryCusPrices = null; + try { + List skuCodes = toSkuKeys.stream().map(OmsSpuToSkuKey::getInvCode).collect(Collectors.toList()); + if(skuCodes.size()>0){ + InventoryCusPriceQuery query = new InventoryCusPriceQuery(); + query.setCusCode(supplierCode); + query.setInvCodes(skuCodes); + R res = seeYonRequestBaseService.postBase(TbsSeeYonConst.ERP_CUS_INV_PRICE,query,"查询客户特殊价"); + if(res.getStatus().equals(200)){ + inventoryCusPrices = JsonUtil.jsonToList(res.getData(), InventoryCusPrice.class); + } + } + } catch (Exception e) { + log.error("客户特殊价异常:{}",e.getMessage()); + } + + for (GoodsSpu spu : goodsSpuList) { + //兼容特殊sku + if(selectSpecialFlag!=null&& selectSpecialFlag.equals(1)){ + if(!spu.getSpecialSkuId().equals(0L)){ + GoodsSku goodsSku = goodsSkuService.getById(spu.getSpecialSkuId()); + spu.setSkuCode(goodsSku.getSkuCode()); + spu.setSkuPrice(goodsSku.getSalesPrice()); + spu.setVolume(goodsSku.getVolume().toString()); + spu.setWeight(goodsSku.getWeight().toString()); + continue; + } + } + for (OmsSpuToSkuKey skuKey : toSkuKeys) { + if(spu.getSpuCode().equals(skuKey.getSkuCode())){ + GoodsSku goodsSku = goodsSkuService.getByCode(skuKey.getInvCode()); + spu.setSkuCode(goodsSku.getSkuCode()); + spu.setSkuPrice(goodsSku.getSalesPrice()); + spu.setVolume(goodsSku.getVolume().toString()); + spu.setWeight(goodsSku.getWeight().toString()); + if(inventoryCusPrices!=null){ + for (InventoryCusPrice cusPrice : inventoryCusPrices) { + if(cusPrice.getPrice()!=null&&cusPrice.getInvCode().equals(skuKey.getInvCode())){ + spu.setSkuPrice(cusPrice.getPrice()); + break; + } + } + } + break; + } + } + } + return goodsSpuList; + } + } diff --git a/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsHisOrderQuery.java b/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsHisOrderQuery.java new file mode 100644 index 00000000..b839ccb8 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/entity/so/GoodsHisOrderQuery.java @@ -0,0 +1,16 @@ +package com.qs.serve.modules.goods.entity.so; + +import lombok.Data; +import java.util.List; +/** + * @author YenHex + * @since 2023/11/16 + */ +@Data +public class GoodsHisOrderQuery { + + String supplierCode; + + List cateIds; + +}