|
|
@ -47,6 +47,26 @@ public class GoodsApplicationService { |
|
|
|
R<String> result = seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_SYNC_PRICE,""); |
|
|
|
} |
|
|
|
|
|
|
|
public void syncStandGoodsSpu(){ |
|
|
|
//兼容任务调度
|
|
|
|
AuthContextUtils.setTenant("001"); |
|
|
|
//获取stand表的存货
|
|
|
|
R<String> result = seeYonRequestBaseService.getBase(TbsSeeYonConst.ERP_CUS_INV_STAND,""); |
|
|
|
String listJson = result.getData(); |
|
|
|
List<StandInventory> inventoryList = JsonUtil.jsonToList(listJson,StandInventory.class); |
|
|
|
|
|
|
|
LambdaQueryWrapper<GoodsSpu> spuLqw = new LambdaQueryWrapper<>(); |
|
|
|
spuLqw.eq(GoodsSpu::getCategoryFirst,"1"); |
|
|
|
List<GoodsSpu> goodsSpuList = goodsSpuService.list(spuLqw); |
|
|
|
for(GoodsSpu spu:goodsSpuList) { |
|
|
|
GoodsSpu finalSpu = spu; |
|
|
|
List<StandInventory> 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<GoodsCategory> cateLqw = new LambdaQueryWrapper<>(); |
|
|
|
cateLqw.likeRight(GoodsCategory::getLevelPathNames,inventory.getInvBrand()) |
|
|
|
.likeLeft(GoodsCategory::getLevelPathNames,inventory.getInvSeries()) |
|
|
|
.like(GoodsCategory::getLevelPathNames,inventory.getInvCategory()); |
|
|
|
List<GoodsCategory> 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<GoodsCategory> brandLqw = new LambdaQueryWrapper<>(); |
|
|
|
brandLqw.eq(GoodsCategory::getName, inventory.getInvBrand()); |
|
|
|
List<GoodsCategory> 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<GoodsCategory> categoryLqw = new LambdaQueryWrapper<>(); |
|
|
|
categoryLqw.eq(GoodsCategory::getParentId, Long.parseLong(spu.getCategoryFirst())); |
|
|
|
categoryLqw.eq(GoodsCategory::getName, inventory.getInvCategory()); |
|
|
|
List<GoodsCategory> 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<GoodsCategory> seriesLqw = new LambdaQueryWrapper<>(); |
|
|
|
seriesLqw.eq(GoodsCategory::getParentId, Long.parseLong(spu.getCategorySecond())); |
|
|
|
seriesLqw.eq(GoodsCategory::getName, inventory.getInvSeries()); |
|
|
|
List<GoodsCategory> 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<GoodsTargetInfo> list = this.getGoodsTargetInfo(goodsType, Arrays.asList(goodsIds)); |
|
|
|
if(list.size()>0){ |
|
|
|