From b42fcdd6d01aee9c2531918b35183082d2d18736 Mon Sep 17 00:00:00 2001 From: "15989082884@163.com" <15989082884@163.com> Date: Sun, 31 Dec 2023 17:33:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=95=86=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AF=B9=E5=BA=94=E5=88=86=E7=B1=BB=EF=BC=8C=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/mapper/GoodsCategoryMapper.java | 4 + .../service/GoodsApplicationService.java | 140 +++++++++++++++--- .../goods/service/GoodsCategoryService.java | 2 + .../impl/GoodsCategoryServiceImpl.java | 16 ++ 4 files changed, 140 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsCategoryMapper.java b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsCategoryMapper.java index 89e34a14..0e6da8b9 100644 --- a/src/main/java/com/qs/serve/modules/goods/mapper/GoodsCategoryMapper.java +++ b/src/main/java/com/qs/serve/modules/goods/mapper/GoodsCategoryMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.qs.serve.modules.goods.entity.GoodsCategory; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; /** @@ -15,5 +16,8 @@ public interface GoodsCategoryMapper extends BaseMapper { @Update("update goods_category set del_flag = 1 , `code`= #{obj.code} where id = #{obj.id}") int deleteByCate(@Param("obj") GoodsCategory entity); + + @Select("SELECT MAX(code) FROM goods_category WHERE code LIKE CONCAT(#{prefix}, '%')") + String findMaxCodeStartingWith(String prefix); } diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java index 268dc86b..3c9f25ac 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsApplicationService.java @@ -47,6 +47,26 @@ public class GoodsApplicationService { R result = seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_SYNC_PRICE,""); } + public void syncStandGoodsSpu(){ + //兼容任务调度 + AuthContextUtils.setTenant("001"); + //获取stand表的存货 + R result = seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_STAND,""); + String listJson = result.getData(); + List inventoryList = JsonUtil.jsonToList(listJson,StandInventory.class); + + LambdaQueryWrapper spuLqw = new LambdaQueryWrapper<>(); + spuLqw.eq(GoodsSpu::getCategoryFirst,"1"); + List goodsSpuList = goodsSpuService.list(spuLqw); + for(GoodsSpu spu:goodsSpuList) { + GoodsSpu finalSpu = spu; + List tempInvList = inventoryList.stream().filter(a->a.getInvSkuCode().equals(finalSpu.getSpuCode())).collect(Collectors.toList()); + StandInventory inventory = tempInvList.get(0); + spu = setCategoryInfo(inventory, spu); + goodsSpuService.updateById(spu); + } + } + public void syncStandGoods(boolean isFullUpdate){ //兼容任务调度 AuthContextUtils.setTenant("001"); @@ -100,28 +120,8 @@ public class GoodsApplicationService { spu.setId(spuId); spu.setSpuCode(inventory.getInvSkuCode()); spu.setName(inventory.getInvSku()); - //匹配类目 - LambdaQueryWrapper cateLqw = new LambdaQueryWrapper<>(); - cateLqw.likeRight(GoodsCategory::getLevelPathNames,inventory.getInvBrand()) - .likeLeft(GoodsCategory::getLevelPathNames,inventory.getInvSeries()) - .like(GoodsCategory::getLevelPathNames,inventory.getInvCategory()); - List categoryList = goodsCategoryService.list(cateLqw); - if(categoryList.size()>0){ - GoodsCategory goodsCategory = categoryList.get(0); - String[] cateIds = goodsCategory.getLevelPath().split("_"); - if(cateIds.length>2){ - spu.setCategoryFirst(cateIds[0]); - spu.setCategorySecond(cateIds[1]); - spu.setCategoryThird(cateIds[2]); - spu.setCategoryLast(cateIds[2]); - } - } - if(spu.getCategoryFirst()==null) { - spu.setCategoryFirst("1"); - spu.setCategorySecond("2"); - spu.setCategoryThird("3"); - spu.setCategoryLast("3"); - } + + spu = setCategoryInfo(inventory,spu); spu.setShelf(1); spu.setOrderFlag(Integer.parseInt(inventory.getInvOrderStatus())); @@ -130,6 +130,15 @@ public class GoodsApplicationService { //防止多次保存 spuId = spu.getId(); spuCodeGetIdMap.put(spu.getSpuCode(),spuId); + }else{ + GoodsSpu spu = new GoodsSpu(); + spu.setId(spuId); + spu.setName(inventory.getInvSku()); + spu.setShelf(1); + spu.setOrderFlag(Integer.parseInt(inventory.getInvOrderStatus())); + spu.setCostFlag(Integer.parseInt(inventory.getInvCostStatus())); + spu = setCategoryInfo(inventory,spu); + goodsSpuService.updateById(spu); } GoodsSku sku = new GoodsSku(); sku.setId(skuId); @@ -164,6 +173,93 @@ public class GoodsApplicationService { seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_SHELF,""); } + private GoodsSpu setCategoryInfo(StandInventory inventory, GoodsSpu spu) { + // 创建品牌级别的查询包装器 + LambdaQueryWrapper brandLqw = new LambdaQueryWrapper<>(); + brandLqw.eq(GoodsCategory::getName, inventory.getInvBrand()); + List brandList = goodsCategoryService.list(brandLqw); + + // 如果品牌不存在,则创建一个新的品牌类别 + if (brandList.size() == 0) { + GoodsCategory brand = new GoodsCategory(); + brand.setEnable(1); + brand.setParentId(null); // 设置父ID为null,表示这是顶级类别 + brand.setCode(goodsCategoryService.findMaxCodeStartingWith("B")); // 生成以"B"开头的最大代码 + brand.setName(inventory.getInvBrand()); // 设置品牌名称 + brand.setDescription(null); // 描述设置为null + brand.setCostFlag(1); // 设置成本标志 + brand.setSort(0); // 排序设置为0 + goodsCategoryService.modify(brand); // 保存新的品牌类别 + brandList = goodsCategoryService.list(brandLqw); // 重新获取品牌列表 + } + + // 如果品牌列表不为空,设置第一级类别ID + if (brandList.size() > 0) { + spu.setCategoryFirst(brandList.get(0).getId().toString()); + } + + // 创建类别级别的查询包装器 + LambdaQueryWrapper categoryLqw = new LambdaQueryWrapper<>(); + categoryLqw.eq(GoodsCategory::getParentId, Long.parseLong(spu.getCategoryFirst())); + categoryLqw.eq(GoodsCategory::getName, inventory.getInvCategory()); + List brandCategoryList = goodsCategoryService.list(categoryLqw); + + // 如果类别不存在,则创建一个新的类别 + if (brandCategoryList.size() == 0) { + GoodsCategory category = new GoodsCategory(); + category.setEnable(1); + category.setParentId(Long.parseLong(spu.getCategoryFirst())); // 设置父ID为第一级类别ID + category.setCode(goodsCategoryService.findMaxCodeStartingWith("C")); // 生成以"C"开头的最大代码 + category.setName(inventory.getInvCategory()); // 设置类别名称 + category.setDescription(null); // 描述设置为null + category.setCostFlag(1); // 设置成本标志 + category.setSort(0); // 排序设置为0 + goodsCategoryService.modify(category); // 保存新的类别 + brandCategoryList = goodsCategoryService.list(categoryLqw); // 重新获取类别列表 + } + + // 如果类别列表不为空,设置第二级类别ID + if (brandCategoryList.size() > 0) { + spu.setCategorySecond(brandCategoryList.get(0).getId().toString()); + } + + // 创建系列级别的查询包装器 + LambdaQueryWrapper seriesLqw = new LambdaQueryWrapper<>(); + seriesLqw.eq(GoodsCategory::getParentId, Long.parseLong(spu.getCategorySecond())); + seriesLqw.eq(GoodsCategory::getName, inventory.getInvSeries()); + List seriesList = goodsCategoryService.list(seriesLqw); + + // 如果系列不存在,则创建一个新的系列 + if (seriesList.size() == 0) { + GoodsCategory series = new GoodsCategory(); + series.setEnable(1); + series.setParentId(Long.parseLong(spu.getCategorySecond())); // 设置父ID为第二级类别ID + series.setCode(goodsCategoryService.findMaxCodeStartingWith("S")); // 生成以"S"开头的最大代码 + series.setName(inventory.getInvSeries()); // 设置系列名称 + series.setDescription(null); // 描述设置为null + series.setCostFlag(1); // 设置成本标志 + series.setSort(0); // 排序设置为0 + goodsCategoryService.modify(series); // 保存新的系列 + seriesList = goodsCategoryService.list(seriesLqw); // 重新获取系列列表 + } + + // 如果系列列表不为空,设置第三级和最终类别ID + if (seriesList.size() > 0) { + spu.setCategoryThird(seriesList.get(0).getId().toString()); + spu.setCategoryLast(spu.getCategoryThird()); + } + + // 如果最终类别为空,则设置默认类别 + if(spu.getCategoryLast() == null) { + spu.setCategoryFirst("1"); + spu.setCategorySecond("2"); + spu.setCategoryThird("3"); + spu.setCategoryLast("3"); + } + return spu; + } + + public GoodsTargetInfo getGoodsTargetInfo(String goodsType,Long goodsIds){ List list = this.getGoodsTargetInfo(goodsType, Arrays.asList(goodsIds)); if(list.size()>0){ diff --git a/src/main/java/com/qs/serve/modules/goods/service/GoodsCategoryService.java b/src/main/java/com/qs/serve/modules/goods/service/GoodsCategoryService.java index 6b30bf90..9bc314e4 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/GoodsCategoryService.java +++ b/src/main/java/com/qs/serve/modules/goods/service/GoodsCategoryService.java @@ -21,5 +21,7 @@ public interface GoodsCategoryService extends IService { void deleteCateById(Long id); + String findMaxCodeStartingWith(String prefix); + } diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCategoryServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCategoryServiceImpl.java index 9ca21875..af79eecb 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCategoryServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsCategoryServiceImpl.java @@ -168,5 +168,21 @@ public class GoodsCategoryServiceImpl extends ServiceImpl