diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndFhbBizController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndFhbBizController.java index fa835162b..b36cf148b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndFhbBizController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndFhbBizController.java @@ -18,7 +18,6 @@ import com.ruoyi.web.controller.xkt.migartion.vo.fhb.FhbProdStockVO; import com.ruoyi.web.controller.xkt.migartion.vo.fhb.FhbProdVO; import com.ruoyi.web.controller.xkt.migartion.vo.gt.GtCateVO; import com.ruoyi.web.controller.xkt.migartion.vo.gt.GtProdSkuVO; -import com.ruoyi.web.controller.xkt.migartion.vo.ty.TyProdStockVO; import com.ruoyi.xkt.domain.*; import com.ruoyi.xkt.enums.EProductStatus; import com.ruoyi.xkt.enums.ListingType; @@ -39,7 +38,6 @@ import java.net.URLEncoder; import java.time.LocalDate; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** @@ -194,6 +192,311 @@ public class GtAndFhbBizController extends BaseController { } + // 新增颜色、客户、商品基础数据 + @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") + @PutMapping("/init-prod") + @Transactional + public R initProd(@Validated @RequestBody GtAndFHBInitVO initVO) { + // 去掉可能的空格 + initVO.setExcludeArtNoList(initVO.getExcludeArtNoList().stream().map(String::trim).collect(Collectors.toList())); + Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper() + .eq(Store::getId, initVO.getStoreId()).eq(Store::getDelFlag, Constants.UNDELETED))) + .orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR)); + // 步骤1: 新建颜色 + this.initStoreColorList(initVO.getStoreId(), initVO.getSupplierId()); + // 步骤2: 新建客户 + this.initStoreCusList(initVO); + + Map> multiSaleSameGoMap = new HashMap<>(); + Map> multiOffSaleSameGoMap = new HashMap<>(); + Map> multiSameFhbMap = new HashMap<>(); + List gtSaleBasicList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_GT_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); + // 查看gt 在售的商品 这边有多少相似的货号 + gtSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct() + // 过滤掉需要特殊处理的货号 + .filter(article_number -> !initVO.getExcludeArtNoList().contains(article_number)) + .forEach(article_number -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(article_number); + List existList = multiSaleSameGoMap.containsKey(cleanArtNo) ? multiSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(article_number); + multiSaleSameGoMap.put(cleanArtNo, existList); + }); + + // 查看gt 下架的商品有多少相似的货号 + List gtOffSaleBasicList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_GT_OFF_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); + gtOffSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct().forEach(article_number -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(article_number); + List existList = multiOffSaleSameGoMap.containsKey(cleanArtNo) ? multiOffSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(article_number); + multiOffSaleSameGoMap.put(cleanArtNo, existList); + }); + + // 查看Fhb 这边有多少相似的货号 + List fhbProdList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + initVO.getSupplierId()), new ArrayList<>()); + // Fhb按照颜色分类 + Map> fhbProdGroupMap = fhbProdList.stream().collect(Collectors.groupingBy(FhbProdVO.SMIVO::getArtNo)); + fhbProdList.stream().map(FhbProdVO.SMIVO::getArtNo).distinct() + // 过滤掉需要特殊处理的货号 + .filter(artNo -> !initVO.getExcludeArtNoList().contains(artNo)) + .forEach(artNo -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(artNo); + List existList = multiSameFhbMap.containsKey(cleanArtNo) ? multiSameFhbMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(artNo); + multiSameFhbMap.put(cleanArtNo, existList); + }); + // gt按照货号分组 + Map> gtSaleGroupMap = gtSaleBasicList.stream().collect(Collectors.groupingBy(GtProdSkuVO::getArticle_number)); + + // GT分类 + List cacheList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_GT_SALE_CATE_KEY + initVO.getUserId()), new ArrayList<>()); + List prodCateList = this.prodCateMapper.selectList(new LambdaQueryWrapper() + .eq(SysProductCategory::getDelFlag, Constants.UNDELETED)); + Map dbCateNameMap = prodCateList.stream().collect(Collectors.toMap(SysProductCategory::getName, SysProductCategory::getId)); + // GT商品分类和步橘分类映射 + Map cateRelationMap = new HashMap<>(); + cacheList.forEach(gtCate -> { + final Long cateId = Optional.ofNullable(dbCateNameMap.get(gtCate.getName())).orElseThrow(() -> new ServiceException("GT分类不存在!", HttpStatus.ERROR)); + cateRelationMap.put(gtCate.getId(), cateId); + }); + + System.err.println("============ 两边系统“一致”的货号 ============"); + // 清洗后,相同货号映射 + Set commonArtNos = new HashSet<>(multiSaleSameGoMap.keySet()); + commonArtNos.retainAll(multiSameFhbMap.keySet()); + // 待导入的商品 + List storeProdList = new ArrayList<>(); + // 当天 + final Date voucherDate = java.sql.Date.valueOf(LocalDate.now()); + // 所有商品的类目属性map key gt的product_id value StoreProductCategoryAttribute + Map prodAttrMap = new HashMap<>(); + commonArtNos.forEach(cleanArtNo -> { + // 获取GT匹配的商品中的第一个商品 + List gtMatchSkuList = this.getGtFirstSku(multiSaleSameGoMap, gtSaleGroupMap, cleanArtNo); + // 初始化档口商品 + StoreProduct storeProd = new StoreProduct().setStoreId(initVO.getStoreId()).setProdCateId(cateRelationMap.get(gtMatchSkuList.get(0).getCategory_nid())) + .setProdArtNum(gtMatchSkuList.get(0).getArticle_number()).setProdTitle(gtMatchSkuList.get(0).getCharacters()).setListingWay(ListingType.RIGHT_NOW.getValue()) + .setVoucherDate(voucherDate).setProdStatus(EProductStatus.ON_SALE.getValue()).setRecommendWeight(0L).setSaleWeight(0L).setPopularityWeight(0L); + // 提前设置档口商品的类目属性 + this.preMatchAttr(gtMatchSkuList.get(0).getProduct_id(), initVO.getUserId(), prodAttrMap); + storeProdList.add(storeProd); + }); + this.storeProdMapper.insert(storeProdList); + + // 商品所有颜色 尺码 颜色库存初始化 + List prodSvcList = new ArrayList<>(); + List prodAttrList = new ArrayList<>(); + storeProdList.forEach(storeProd -> { + // 获取clearArtNo + String clearArtNo = this.extractCoreArticleNumber(storeProd.getProdArtNum()); + // FHB匹配的货号 + List fhbMatchArtNoList = multiSameFhbMap.get(clearArtNo); + // 获取GT匹配的商品sku列表 + List gtMatchSkuList = this.getGtFirstSku(multiSaleSameGoMap, gtSaleGroupMap, clearArtNo); + fhbMatchArtNoList.forEach(fhbArtNo -> { + // 初始化商品服务承诺 + prodSvcList.add(new StoreProductService().setStoreProdId(storeProd.getId()).setCustomRefund("0") + .setThirtyDayRefund("0").setOneBatchSale("1").setRefundWithinThreeDay("0")); + // 初始化商品的类目属性 + StoreProductCategoryAttribute cateAttr = Optional.ofNullable(prodAttrMap.get(gtMatchSkuList.get(0).getProduct_id())) + .orElseThrow(() -> new ServiceException("没有GT商品类目属性!" + storeProd.getProdArtNum(), HttpStatus.ERROR)); + cateAttr.setStoreId(storeProd.getStoreId()).setStoreProdId(storeProd.getId()); + prodAttrList.add(cateAttr); + }); + }); + // 插入档口服务承诺、商品基本属性 + this.prodSvcMapper.insert(prodSvcList); + this.prodCateAttrMapper.insert(prodAttrList); + return R.ok(); + } + + + /** + * 商品颜色及商品颜色尺码 + * + * @param initVO + * @return + */ + @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") + @PutMapping("/init-color") + @Transactional + public R initColor(@Validated @RequestBody GtAndFHBInitVO initVO) { + // 从数据库查询最新数据 + List storeProdList = this.storeProdMapper.selectList(new LambdaQueryWrapper() + .eq(StoreProduct::getStoreId, initVO.getStoreId()).eq(StoreProduct::getDelFlag, Constants.UNDELETED)); + List storeColorList = this.storeColorMapper.selectList(new LambdaQueryWrapper() + .eq(StoreColor::getStoreId, initVO.getStoreId()).eq(StoreColor::getDelFlag, Constants.UNDELETED)); + Map storeColorMap = storeColorList.stream().collect(Collectors.toMap(StoreColor::getColorName, x -> x, (v1, v2) -> v2)); + + Map> multiSaleSameGoMap = new HashMap<>(); + Map> multiOffSaleSameGoMap = new HashMap<>(); + Map> multiSameFhbMap = new HashMap<>(); + List gtSaleBasicList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_GT_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); + // 查看gt 在售的商品 这边有多少相似的货号 + gtSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct() + // 过滤掉需要特殊处理的货号 + .filter(article_number -> !initVO.getExcludeArtNoList().contains(article_number)) + .forEach(article_number -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(article_number); + List existList = multiSaleSameGoMap.containsKey(cleanArtNo) ? multiSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(article_number); + multiSaleSameGoMap.put(cleanArtNo, existList); + }); + + // 查看gt 下架的商品有多少相似的货号 + List gtOffSaleBasicList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_GT_OFF_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); + gtOffSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct().forEach(article_number -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(article_number); + List existList = multiOffSaleSameGoMap.containsKey(cleanArtNo) ? multiOffSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(article_number); + multiOffSaleSameGoMap.put(cleanArtNo, existList); + }); + + // 查看Fhb 这边有多少相似的货号 + List fhbProdList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + initVO.getSupplierId()), new ArrayList<>()); + // Fhb按照颜色分类 + Map> fhbProdGroupMap = fhbProdList.stream().collect(Collectors.groupingBy(FhbProdVO.SMIVO::getArtNo)); + fhbProdList.stream().map(FhbProdVO.SMIVO::getArtNo).distinct() + // 过滤掉需要特殊处理的货号 + .filter(artNo -> !initVO.getExcludeArtNoList().contains(artNo)) + .forEach(artNo -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(artNo); + List existList = multiSameFhbMap.containsKey(cleanArtNo) ? multiSameFhbMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(artNo); + multiSameFhbMap.put(cleanArtNo, existList); + }); + // gt按照货号分组 + Map> gtSaleGroupMap = gtSaleBasicList.stream().collect(Collectors.groupingBy(GtProdSkuVO::getArticle_number)); + + // 商品所有颜色 尺码 颜色库存初始化 + List prodColorList = new ArrayList<>(); + List prodColorSizeList = new ArrayList<>(); + storeProdList.forEach(storeProd -> { + // 获取clearArtNo + String clearArtNo = this.extractCoreArticleNumber(storeProd.getProdArtNum()); + // FHB匹配的货号 + List fhbMatchArtNoList = multiSameFhbMap.get(clearArtNo); + // 获取GT匹配的商品sku列表 + List gtMatchSkuList = this.getGtFirstSku(multiSaleSameGoMap, gtSaleGroupMap, clearArtNo); + // 当前货号在GT的所有尺码,作为标准尺码 + List gtStandardSizeList = gtMatchSkuList.stream().map(sku -> (int) Math.floor(Double.parseDouble(sku.getSize()))).collect(Collectors.toList()); + AtomicInteger orderNum = new AtomicInteger(); + fhbMatchArtNoList.forEach(fhbArtNo -> { + List fhbMatchSkuList = fhbProdGroupMap.get(fhbArtNo); + for (FhbProdVO.SMIVO smivo : fhbMatchSkuList) { + StoreColor storeColor = Optional.ofNullable(storeColorMap.get(smivo.getColor())) + .orElseThrow(() -> new ServiceException("没有FHB商品颜色!" + fhbArtNo, HttpStatus.ERROR)); + // 该商品的颜色 + prodColorList.add(new StoreProductColor().setStoreId(storeProd.getStoreId()).setStoreProdId(storeProd.getId()).setOrderNum(orderNum.addAndGet(1)) + .setColorName(storeColor.getColorName()).setStoreColorId(storeColor.getId()).setProdStatus(EProductStatus.ON_SALE.getValue())); + // 该颜色所有的尺码 + for (int j = 0; j < Constants.SIZE_LIST.size(); j++) { + // FHB系统条码前缀 + final String otherSnPrefix = smivo.getSupplierId() + + String.format("%05d", smivo.getSupplierSkuId()) + Constants.SIZE_LIST.get(j); + prodColorSizeList.add(new StoreProductColorSize().setSize(Constants.SIZE_LIST.get(j)).setStoreColorId(storeColor.getId()) + .setStoreProdId(storeProd.getId()).setStandard(gtStandardSizeList.contains(Constants.SIZE_LIST.get(j)) ? 1 : 0) + // 销售价格以FHB价格为准 + .setPrice(smivo.getSalePrice()) + .setOtherSnPrefix(otherSnPrefix).setNextSn(0)); + } + } + }); + }); + // 插入商品颜色及颜色对应的尺码,档口服务承诺 + this.prodColorMapper.insert(prodColorList); + prodColorSizeList.sort(Comparator.comparing(StoreProductColorSize::getStoreProdId).thenComparing(StoreProductColorSize::getSize)); + this.prodColorSizeMapper.insert(prodColorSizeList); + // 还要更新步橘系统的条码前缀 + prodColorSizeList.forEach(x -> x.setSnPrefix(initVO.getStoreId() + String.format("%08d", x.getId()))); + this.prodColorSizeMapper.updateById(prodColorSizeList); + return R.ok(); + } + + @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") + @PutMapping("/init-cus-disc") + @Transactional + public R initCusDisc(@Validated @RequestBody GtAndFHBInitVO initVO) { + + List storeProdList = this.storeProdMapper.selectList(new LambdaQueryWrapper() + .eq(StoreProduct::getStoreId, initVO.getStoreId()).eq(StoreProduct::getDelFlag, Constants.UNDELETED)); + List prodColorList = this.prodColorMapper.selectList(new LambdaQueryWrapper() + .eq(StoreProductColor::getStoreId, initVO.getStoreId()).eq(StoreProductColor::getDelFlag, Constants.UNDELETED)); + List storeCusList = this.storeCusMapper.selectList(new LambdaQueryWrapper() + .eq(StoreCustomer::getStoreId, initVO.getStoreId()).eq(StoreCustomer::getDelFlag, Constants.UNDELETED)); + + Map> multiSameFhbMap = new HashMap<>(); + // 查看Fhb 这边有多少相似的货号 + List fhbProdList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_KEY + initVO.getSupplierId()), new ArrayList<>()); + fhbProdList.stream().map(FhbProdVO.SMIVO::getArtNo).distinct() + // 过滤掉需要特殊处理的货号 + .filter(artNo -> !initVO.getExcludeArtNoList().contains(artNo)) + .forEach(artNo -> { + // 只保留核心连续的数字,去除其他所有符号 + String cleanArtNo = this.extractCoreArticleNumber(artNo); + List existList = multiSameFhbMap.containsKey(cleanArtNo) ? multiSameFhbMap.get(cleanArtNo) : new ArrayList<>(); + existList.add(artNo); + multiSameFhbMap.put(cleanArtNo, existList); + }); + + // 从redis中获取客户优惠数据 + List fhbCusDiscCacheList = ObjectUtils.defaultIfNull(redisCache + .getCacheObject(CacheConstants.MIGRATION_SUPPLIER_CUS_DISCOUNT_KEY + initVO.getSupplierId()), new ArrayList<>()); + if (CollectionUtils.isEmpty(fhbCusDiscCacheList)) { + throw new ServiceException("fhb供应商客户优惠列表为空!" + initVO.getSupplierId(), HttpStatus.ERROR); + } + List fhbStockCacheList = redisCache + .getCacheObject(CacheConstants.MIGRATION_SUPPLIER_PROD_STOCK_KEY + initVO.getSupplierId()); + if (CollectionUtils.isEmpty(fhbStockCacheList)) { + throw new ServiceException("fhb供应商商品库存列表为空!" + initVO.getSupplierId(), HttpStatus.ERROR); + } + // FHB 货号颜色优惠对应关系 + Map>> fhbCusDiscGroupMap = fhbCusDiscCacheList.stream().collect(Collectors + .groupingBy(FhbCusDiscountVO.SMCDRecordVO::getArtNo, Collectors.groupingBy(FhbCusDiscountVO.SMCDRecordVO::getColor))); + // FHB 货号颜色库存对应关系 + Map> fhbStockGroupMap = fhbStockCacheList.stream().collect(Collectors + .groupingBy(FhbProdStockVO.SMPSRecordVO::getArtNo, Collectors.toMap(FhbProdStockVO.SMPSRecordVO::getColor, x -> x))); + // 步橘系统商品所有颜色maps + Map> prodColorGroupMap = prodColorList.stream().collect(Collectors + .groupingBy(StoreProductColor::getStoreProdId, Collectors.toMap(StoreProductColor::getColorName, x -> x))); + // 步橘系统客户名称map + Map buJuStoreCusMap = storeCusList.stream().collect(Collectors.toMap(StoreCustomer::getCusName, x -> x)); + List prodCusDiscList = new ArrayList<>(); + List prodStockList = new ArrayList<>(); + // 依次遍历商品列表,找到货号和FHB货号对应关系,然后用颜色进行匹配,建立客户优惠关系 + storeProdList.forEach(storeProd -> { + final String cleanArtNo = this.extractCoreArticleNumber(storeProd.getProdArtNum()); + // 当前商品颜色列表 key 颜色中文名称 + Map buJuProdColorMap = Optional.ofNullable(prodColorGroupMap.get(storeProd.getId())).orElseThrow(() -> new ServiceException("没有商品颜色!" + storeProd.getProdArtNum(), HttpStatus.ERROR)); + // 根据步橘货号 找到FHB对应的货号,可能是列表 + List fhbAtrNoList = Optional.ofNullable(multiSameFhbMap.get(cleanArtNo)).orElseThrow(() -> new ServiceException("没有FHB货号!" + storeProd.getProdArtNum(), HttpStatus.ERROR)); + fhbAtrNoList.forEach(fhbAtrNo -> { + // 处理档口客户商品优惠 + this.handleCusDisc(fhbAtrNo, fhbCusDiscGroupMap, buJuProdColorMap, buJuStoreCusMap, storeProd.getStoreId(), storeProd.getId(), prodCusDiscList); + // 处理档口商品库存 + this.handleProdStock(fhbAtrNo, fhbStockGroupMap, buJuProdColorMap, storeProd.getStoreId(), storeProd.getId(), storeProd.getProdArtNum(), prodStockList); + }); + }); + // 档口客户优惠 + this.storeCusProdDiscMapper.insert(prodCusDiscList); + // 档口客户库存 + this.prodStockMapper.insert(prodStockList); + return R.ok(); + } + /** * 步骤1: 准备数据,新建颜色; * 步骤2: GT 和 FHB 货号对应关系,然后直接copy 对应的属性关系 @@ -206,11 +509,9 @@ public class GtAndFhbBizController extends BaseController { * 步骤4: 客户与货号的优惠关系 * 步骤5: 批量创建数据到ES服务器 */ - @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") +/* @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") @PutMapping("/init") - @Transactional - public void initToDB(@Validated @RequestBody GtAndFHBInitVO initVO) { // 去掉可能的空格 initVO.setExcludeArtNoList(initVO.getExcludeArtNoList().stream().map(String::trim).collect(Collectors.toList())); @@ -233,12 +534,6 @@ public class GtAndFhbBizController extends BaseController { } - - /** - * 初始化档口商品列表 - * - * @param storeColorMap 档口颜色map - */ private R init(GtAndFHBInitVO initVO, Map storeColorMap) { // 步骤2: GT 和 FHB 货号对应关系,然后直接copy 对应的属性关系 // a. 商品与颜色对应关系 @@ -394,7 +689,7 @@ public class GtAndFhbBizController extends BaseController { this.initStoreCusProdDiscAndProdStock(initVO, storeProdList, storeCusList, prodColorList, multiSameFhbMap); return R.ok(); - } + }*/ /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndTyBizController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndTyBizController.java index 64d7b8988..6d074bd8c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndTyBizController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/xkt/migartion/GtAndTyBizController.java @@ -326,7 +326,7 @@ public class GtAndTyBizController extends BaseController { .eq(StoreProduct::getStoreId, initVO.getStoreId()).eq(StoreProduct::getDelFlag, Constants.UNDELETED)); List storeColorList = this.storeColorMapper.selectList(new LambdaQueryWrapper() .eq(StoreColor::getStoreId, initVO.getStoreId()).eq(StoreColor::getDelFlag, Constants.UNDELETED)); - Map storeColorMap = storeColorList.stream().collect(Collectors.toMap(StoreColor::getColorName, x -> x, (v1, v2) -> v2)); + Map storeColorMap = storeColorList.stream().collect(Collectors.toMap(StoreColor::getColorName, x -> x)); Map> multiSaleSameGoMap = new HashMap<>(); Map> multiOffSaleSameGoMap = new HashMap<>(); @@ -388,8 +388,8 @@ public class GtAndTyBizController extends BaseController { AtomicInteger orderNum = new AtomicInteger(); tyMatchArtNoList.forEach(tyArtNo -> { List tyMatchSkuList = tyProdGroupMap.get(tyArtNo); - for (int i = 0; i < tyMatchSkuList.size(); i++) { - StoreColor storeColor = Optional.ofNullable(storeColorMap.get(tyMatchSkuList.get(i).getColorName())) + for (TyProdImportVO tyProdImportVO : tyMatchSkuList) { + StoreColor storeColor = Optional.ofNullable(storeColorMap.get(tyProdImportVO.getColorName())) .orElseThrow(() -> new ServiceException("没有TY商品颜色!" + tyArtNo, HttpStatus.ERROR)); // 该商品的颜色 prodColorList.add(new StoreProductColor().setStoreId(storeProd.getStoreId()).setStoreProdId(storeProd.getId()).setOrderNum(orderNum.addAndGet(1)) @@ -397,9 +397,9 @@ public class GtAndTyBizController extends BaseController { // 该颜色所有的尺码 for (int j = 0; j < Constants.SIZE_LIST.size(); j++) { // TY系统条码前缀 - final String otherSnPrefix = tyMatchSkuList.get(i).getTySnPrefix() + Constants.SIZE_LIST.get(j); + final String otherSnPrefix = tyProdImportVO.getTySnPrefix() + Constants.SIZE_LIST.get(j); prodColorSizeList.add(new StoreProductColorSize().setSize(Constants.SIZE_LIST.get(j)).setStoreColorId(storeColor.getId()) - .setStoreProdId(storeProd.getId()).setPrice(tyMatchSkuList.get(i).getPrice()).setOtherSnPrefix(otherSnPrefix).setNextSn(0) + .setStoreProdId(storeProd.getId()).setPrice(tyProdImportVO.getPrice()).setOtherSnPrefix(otherSnPrefix).setNextSn(0) .setStandard(gtStandardSizeList.contains(Constants.SIZE_LIST.get(j)) ? 1 : 0)); } } @@ -422,13 +422,6 @@ public class GtAndTyBizController extends BaseController { List storeProdList = this.storeProdMapper.selectList(new LambdaQueryWrapper() .eq(StoreProduct::getStoreId, initVO.getStoreId()).eq(StoreProduct::getDelFlag, Constants.UNDELETED)); - - Date date = DateUtils.parseDate("2025-09-27 10:40:38"); - - storeProdList = storeProdList.stream().filter(x -> x.getCreateTime().after(date)).collect(Collectors.toList()); - - - List prodColorList = this.prodColorMapper.selectList(new LambdaQueryWrapper() .eq(StoreProductColor::getStoreId, initVO.getStoreId()).eq(StoreProductColor::getDelFlag, Constants.UNDELETED)); List storeCusList = this.storeCusMapper.selectList(new LambdaQueryWrapper() @@ -466,7 +459,7 @@ public class GtAndTyBizController extends BaseController { .groupingBy(TyCusDiscImportVO::getProdArtNum, Collectors.groupingBy(TyCusDiscImportVO::getColorName))); // 步橘系统商品所有颜色maps Map> prodColorGroupMap = prodColorList.stream().collect(Collectors - .groupingBy(StoreProductColor::getStoreProdId, Collectors.toMap(StoreProductColor::getColorName, x -> x, (v1, v2) -> v2))); + .groupingBy(StoreProductColor::getStoreProdId, Collectors.toMap(StoreProductColor::getColorName, x -> x))); // 步橘系统客户名称map Map buJuStoreCusMap = storeCusList.stream().collect(Collectors.toMap(StoreCustomer::getCusName, x -> x)); List prodCusDiscList = new ArrayList<>(); @@ -493,179 +486,13 @@ public class GtAndTyBizController extends BaseController { } - /* @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") - @PutMapping("/init") - @Transactional - public R initToDB(@Validated @RequestBody GtAndTYInitVO initVO) { - // 去掉可能的空格 - initVO.setExcludeArtNoList(initVO.getExcludeArtNoList().stream().map(String::trim).collect(Collectors.toList())); - Optional.ofNullable(this.storeMapper.selectOne(new LambdaQueryWrapper() - .eq(Store::getId, initVO.getStoreId()).eq(Store::getDelFlag, Constants.UNDELETED))) - .orElseThrow(() -> new ServiceException("档口不存在!", HttpStatus.ERROR)); - // 步骤1: 准备数据,新建颜色 - Map storeColorMap = this.initStoreColorList(initVO.getStoreId(), initVO.getUserId()); - // 步骤2: GT 和 TY 货号对应关系,然后直接copy 对应的属性关系 - // a. 商品与颜色对应关系 - // b. 商品颜色尺码 + 价格 对应关系 - // c. 库存初始化 - // d. 服务承诺初始化 - // e. 类目属性初始化 - this.init(initVO, storeColorMap); - - return R.ok(); - } - - private void init(GtAndTYInitVO initVO, Map storeColorMap) { - Map> multiSaleSameGoMap = new HashMap<>(); - Map> multiOffSaleSameGoMap = new HashMap<>(); - Map> multiSameTyMap = new HashMap<>(); - List gtSaleBasicList = ObjectUtils.defaultIfNull(redisCache - .getCacheObject(CacheConstants.MIGRATION_GT_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); - // 查看gt 在售的商品 这边有多少相似的货号 - gtSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct() - // 过滤掉需要特殊处理的货号 - .filter(article_number -> !initVO.getExcludeArtNoList().contains(article_number)) - .forEach(article_number -> { - // 只保留核心连续的数字,去除其他所有符号 - String cleanArtNo = this.extractCoreArticleNumber(article_number); - List existList = multiSaleSameGoMap.containsKey(cleanArtNo) ? multiSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); - existList.add(article_number); - multiSaleSameGoMap.put(cleanArtNo, existList); - }); - - // 查看gt 下架的商品有多少相似的货号 - List gtOffSaleBasicList = ObjectUtils.defaultIfNull(redisCache - .getCacheObject(CacheConstants.MIGRATION_GT_OFF_SALE_BASIC_KEY + initVO.getUserId()), new ArrayList<>()); - gtOffSaleBasicList.stream().map(GtProdSkuVO::getArticle_number).distinct().forEach(article_number -> { - // 只保留核心连续的数字,去除其他所有符号 - String cleanArtNo = this.extractCoreArticleNumber(article_number); - List existList = multiOffSaleSameGoMap.containsKey(cleanArtNo) ? multiOffSaleSameGoMap.get(cleanArtNo) : new ArrayList<>(); - existList.add(article_number); - multiOffSaleSameGoMap.put(cleanArtNo, existList); - }); - - // 查看TY 这边有多少相似的货号 - List tyProdList = redisCache.getCacheObject(CacheConstants.MIGRATION_TY_PROD_KEY + initVO.getUserId()); - // TY按照颜色分类 - Map> tyProdGroupMap = tyProdList.stream().collect(Collectors.groupingBy(TyProdImportVO::getProdArtNum)); - tyProdList.stream().map(TyProdImportVO::getProdArtNum).distinct() - // 过滤掉需要特殊处理的货号 - .filter(artNo -> !initVO.getExcludeArtNoList().contains(artNo)) - .forEach(artNo -> { - // 只保留核心连续的数字,去除其他所有符号 - String cleanArtNo = this.extractCoreArticleNumber(artNo); - List existList = multiSameTyMap.containsKey(cleanArtNo) ? multiSameTyMap.get(cleanArtNo) : new ArrayList<>(); - existList.add(artNo); - multiSameTyMap.put(cleanArtNo, existList); - }); - - // gt按照货号分组 - Map> gtSaleGroupMap = gtSaleBasicList.stream().collect(Collectors.groupingBy(GtProdSkuVO::getArticle_number)); - - // GT分类 - List cacheList = ObjectUtils.defaultIfNull(redisCache - .getCacheObject(CacheConstants.MIGRATION_GT_SALE_CATE_KEY + initVO.getUserId()), new ArrayList<>()); - List prodCateList = this.prodCateMapper.selectList(new LambdaQueryWrapper() - .eq(SysProductCategory::getDelFlag, Constants.UNDELETED)); - Map dbCateNameMap = prodCateList.stream().collect(Collectors.toMap(SysProductCategory::getName, SysProductCategory::getId)); - // GT商品分类和步橘分类映射 - Map cateRelationMap = new HashMap<>(); - cacheList.forEach(gtCate -> { - final Long cateId = Optional.ofNullable(dbCateNameMap.get(gtCate.getName())).orElseThrow(() -> new ServiceException("GT分类不存在!", HttpStatus.ERROR)); - cateRelationMap.put(gtCate.getId(), cateId); - }); - - System.err.println("============ 两边系统“一致”的货号 ============"); - // 清洗后,相同货号映射 - Set commonArtNos = new HashSet<>(multiSaleSameGoMap.keySet()); - commonArtNos.retainAll(multiSameTyMap.keySet()); - // 待导入的商品 - List storeProdList = new ArrayList<>(); - // 当天 - final Date voucherDate = java.sql.Date.valueOf(LocalDate.now()); - // 所有商品的类目属性map key gt的product_id value StoreProductCategoryAttribute - Map prodAttrMap = new HashMap<>(); - commonArtNos.forEach(cleanArtNo -> { - // 获取GT匹配的商品中的第一个商品 - List gtMatchSkuList = this.getGtFirstSku(multiSaleSameGoMap, gtSaleGroupMap, cleanArtNo); - // 初始化档口商品 - StoreProduct storeProd = new StoreProduct().setStoreId(initVO.getStoreId()).setProdCateId(cateRelationMap.get(gtMatchSkuList.get(0).getCategory_nid())) - .setProdArtNum(cleanArtNo).setProdTitle(gtMatchSkuList.get(0).getCharacters()).setListingWay(ListingType.RIGHT_NOW.getValue()) - .setVoucherDate(voucherDate).setProdStatus(EProductStatus.ON_SALE.getValue()).setRecommendWeight(0L).setSaleWeight(0L).setPopularityWeight(0L); - // 提前设置档口商品的类目属性 - this.preMatchAttr(gtMatchSkuList.get(0).getProduct_id(), initVO.getUserId(), prodAttrMap); - storeProdList.add(storeProd); - }); - this.storeProdMapper.insert(storeProdList); - - // 商品所有颜色 尺码 颜色库存初始化 - List prodColorList = new ArrayList<>(); - List prodColorSizeList = new ArrayList<>(); - List prodSvcList = new ArrayList<>(); - List prodAttrList = new ArrayList<>(); - storeProdList.forEach(storeProd -> { - // TY匹配的货号 - List tyMatchArtNoList = multiSameTyMap.get(storeProd.getProdArtNum()); - // 获取GT匹配的商品sku列表 - List gtMatchSkuList = this.getGtFirstSku(multiSaleSameGoMap, gtSaleGroupMap, storeProd.getProdArtNum()); - // 当前货号在GT的所有尺码,作为标准尺码 - List gtStandardSizeList = gtMatchSkuList.stream().map(sku -> (int) Math.floor(Double.parseDouble(sku.getSize()))).collect(Collectors.toList()); - tyMatchArtNoList.forEach(tyArtNo -> { - List tyMatchSkuList = tyProdGroupMap.get(tyArtNo); - for (int i = 0; i < tyMatchSkuList.size(); i++) { - StoreColor storeColor = Optional.ofNullable(storeColorMap.get(tyMatchSkuList.get(i).getColorName())) - .orElseThrow(() -> new ServiceException("没有TY商品颜色!" + tyArtNo, HttpStatus.ERROR)); - // 该商品的颜色 - prodColorList.add(new StoreProductColor().setStoreId(storeProd.getStoreId()).setStoreProdId(storeProd.getId()).setOrderNum(i + 1) - .setColorName(storeColor.getColorName()).setStoreColorId(storeColor.getId()).setProdStatus(EProductStatus.ON_SALE.getValue())); - // 该颜色所有的尺码 - for (int j = 0; j < Constants.SIZE_LIST.size(); j++) { - // TY系统条码前缀 - final String otherSnPrefix = tyMatchSkuList.get(i).getTySnPrefix() + Constants.SIZE_LIST.get(j); - prodColorSizeList.add(new StoreProductColorSize().setSize(Constants.SIZE_LIST.get(j)).setStoreColorId(storeColor.getId()) - .setStoreProdId(storeProd.getId()).setPrice(tyMatchSkuList.get(i).getPrice()).setOtherSnPrefix(otherSnPrefix).setNextSn(0) - .setStandard(gtStandardSizeList.contains(Constants.SIZE_LIST.get(j)) ? 1 : 0)); - } - } - }); - - // 初始化商品服务承诺 - prodSvcList.add(new StoreProductService().setStoreProdId(storeProd.getId()).setCustomRefund("0") - .setThirtyDayRefund("0").setOneBatchSale("1").setRefundWithinThreeDay("0")); - - // 初始化商品的类目属性 - StoreProductCategoryAttribute cateAttr = Optional.ofNullable(prodAttrMap.get(gtMatchSkuList.get(0).getProduct_id())) - .orElseThrow(() -> new ServiceException("没有GT商品类目属性!" + storeProd.getProdArtNum(), HttpStatus.ERROR)); - cateAttr.setStoreId(storeProd.getStoreId()).setStoreProdId(storeProd.getId()); - prodAttrList.add(cateAttr); - }); - // 插入商品颜色及颜色对应的尺码,档口服务承诺 - this.prodColorMapper.insert(prodColorList); - this.prodColorSizeMapper.insert(prodColorSizeList); - this.prodSvcMapper.insert(prodSvcList); - this.prodCateAttrMapper.insert(prodAttrList); - - // 还要更新步橘系统的条码前缀 - prodColorSizeList.forEach(x -> x.setSnPrefix(initVO.getStoreId() + String.format("%08d", x.getId()))); - this.prodColorSizeMapper.updateById(prodColorSizeList); - - // 步骤3: 准备数据,新建客户 - List storeCusList = this.initStoreCusList(initVO); - - // 步骤4: 客户与货号的优惠关系 及 商品颜色的库存 - this.initStoreCusProdDiscAndProdStock(initVO, storeProdList, storeCusList, prodColorList, multiSameTyMap); - - }*/ - - /** * 初始化系统颜色 * * @param storeId 档口ID * @param userId GT用户ID - * @return */ - private Map initStoreColorList(Long storeId, Integer userId) { + private void initStoreColorList(Long storeId, Integer userId) { // TY商品缓存 List cacheList = redisCache.getCacheObject(CacheConstants.MIGRATION_TY_PROD_KEY + userId); if (CollectionUtils.isEmpty(cacheList)) { @@ -677,7 +504,7 @@ public class GtAndTyBizController extends BaseController { storeColorList.add(new StoreColor().setStoreId(storeId).setColorName(tyColorList.get(i)).setOrderNum(i + 1)); } this.storeColorMapper.insert(storeColorList); - return storeColorList.stream().collect(Collectors.toMap(StoreColor::getColorName, x -> x)); + storeColorList.stream().collect(Collectors.toMap(StoreColor::getColorName, x -> x)); } /**