平台规格切分问题修复

This commit is contained in:
liyj 2025-07-31 18:21:57 +08:00
parent 8418c2823c
commit c74de207d7
13 changed files with 72 additions and 76 deletions

View File

@ -21,7 +21,6 @@ public interface ShopBaseProductSpecService extends IBaseService<ShopBaseProduct
List<ShopBaseProductSpec> getSpecsByIds(String type_spec_ids, Integer store_id);
Map getShopBaseProductSpecMap(Integer store_id);
Map<String,ShopBaseProductSpec> getShopBaseProductSpecMap(Integer store_id);
void clearShopBaseProductSpecMap(Integer store_id);
}

View File

@ -92,28 +92,15 @@ public class ShopBaseProductSpecServiceImpl extends BaseServiceImpl<ShopBaseProd
}
@Override
public Map getShopBaseProductSpecMap(Integer store_id) {
Map map=new HashMap<>();
String redisKey=RedisKey.STOREDATASHOPBASEPRODUCTSPEC+":"+store_id;
if(null!=redisService.get(redisKey)){
map= (Map) redisService.get(redisKey);
}else {
QueryWrapper<ShopBaseProductSpec> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("store_id",store_id);
List<ShopBaseProductSpec> shopBaseProductSpecList=this.list(queryWrapper);
for(ShopBaseProductSpec spec:shopBaseProductSpecList){
map.put(String.valueOf(spec.getSpec_category_id()),spec);
}
if (CollUtil.isNotEmpty(map)) redisService.set(redisKey, map, 60 * 60);
public Map<String,ShopBaseProductSpec> getShopBaseProductSpecMap(Integer store_id) {
Map<String,ShopBaseProductSpec> map=new HashMap<>();
QueryWrapper<ShopBaseProductSpec> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("store_id",store_id);
List<ShopBaseProductSpec> shopBaseProductSpecList=this.list(queryWrapper);
for(ShopBaseProductSpec spec:shopBaseProductSpecList){
map.put(String.valueOf(spec.getSpec_category_id()),spec);
}
return map;
}
@Override
public void clearShopBaseProductSpecMap(Integer store_id) {
String redisKey=RedisKey.STOREDATASHOPBASEPRODUCTSPEC+":"+store_id;
if(null!=redisService.get(redisKey)){
redisService.del(redisKey);
}
}
}

View File

@ -33,4 +33,7 @@ public interface ShopProductItemMapper extends BaseMapper<ShopProductItem> {
int lockSkuStock(@Param("item_id") Long itemId, @Param("cart_quantity") int cart_quantity);
void updateBatchByProductId(List<ShopProductItem> list,Integer itemEnable);
List<ShopProductItem> getLimitFirstByProductId(@Param("productIds") List<Long> productIds);
}

View File

@ -290,8 +290,7 @@ public interface ShopProductBaseService extends IBaseService<ShopProductBase> {
List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList,
List<ShopProductImage> shopProductImageList,
List<ShopProductValidPeriod> shopProductValidPeriodList,
List<ShopProductAssistIndex> shopProductAssistIndexList,String priorityMode,
Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice);
List<ShopProductAssistIndex> shopProductAssistIndexList);
/**
* 加载商品

View File

@ -92,4 +92,6 @@ public interface ShopProductItemService extends IBaseService<ShopProductItem> {
* @param: ShopProductItem
*/
CommonResult editQuantity(List<ShopProductItem> shopProductItemList);
List<ShopProductItem> getLimitFirstByProductId(List<Long> productIds);
}

View File

@ -21,5 +21,4 @@ public interface ShopProductSpecItemService extends IBaseService<ShopProductSpec
Map<String,Integer> getExistItem(Integer storeId);
void clearExistItem(Integer storeId);
}

View File

@ -5313,8 +5313,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
List<ShopProductData> shopProductDataList, List<ShopProductDetail> shopProductDetailList,
List<ShopProductInfo> shopProductInfoList, List<List<ShopProductItem>> shopProductItemList,
List<ShopProductImage> shopProductImageList, List<ShopProductValidPeriod> shopProductValidPeriodList,
List<ShopProductAssistIndex> shopProductAssistIndexList, String priorityMode,Map shopProductSpecItemMap,
Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice) {
List<ShopProductAssistIndex> shopProductAssistIndexList) {
// 1. 参数校验
if (shopProductBaseList == null || shopProductBaseList.isEmpty()) {
@ -5467,7 +5466,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
newProductDataList, updateProductDataList, newShopProductDetailList, updateShopProductDetailList,
newShopProductInfoList, updateShopProductInfoList, newShopProductItemList, updateShopProductItemList,
newShopProductImageList, updateShopProductImageList, newShopProductValidPeriodList, updateShopProductValidPeriodList,
newShopProductAssistIndexList, updateShopProductAssistIndexList, priorityMode,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice);
newShopProductAssistIndexList, updateShopProductAssistIndexList);
}
/**
@ -5481,8 +5480,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
List<List<ShopProductItem>> newShopProductItemList, List<List<ShopProductItem>> udpateShopProductItemList,
List<ShopProductImage> newShopProductImageList, List<ShopProductImage> udpteShopProductImageList,
List<ShopProductValidPeriod> newShopProductValidPeriodList, List<ShopProductValidPeriod> updateShopProductValidPeriodList,
List<ShopProductAssistIndex> newShopProductAssistIndexList, List<ShopProductAssistIndex> udpateShopProductAssistIndexList,
String priorityMode,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice
List<ShopProductAssistIndex> newShopProductAssistIndexList, List<ShopProductAssistIndex> udpateShopProductAssistIndexList
) {
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

View File

@ -2389,4 +2389,9 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
shopProductItemService.updateBatchById(updateShopProductItem);
return CommonResult.success();
}
@Override
public List<ShopProductItem> getLimitFirstByProductId(List<Long> productIds) {
return shopProductItemMapper.getLimitFirstByProductId(productIds);
}
}

View File

@ -35,31 +35,18 @@ public class ShopProductSpecItemServiceImpl extends BaseServiceImpl<ShopProductS
}
@Override
public Map getExistItem(Integer storeId) {
Map map=new HashMap<>();
String redisKey=RedisKey.STOREDATAPRODUCTSPECITEM+"storeId:"+storeId;
if(null!=redisService.get(redisKey)){
map=(Map)redisService.get(redisKey);
return map;
}
public Map<String,Integer> getExistItem(Integer storeId) {
Map<String,Integer> map=new HashMap<>();
QueryWrapper<ShopProductSpecItem> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("store_id",storeId);
List<ShopProductSpecItem> list= list(queryWrapper);
for(ShopProductSpecItem shopProductSpecItem:list){
map.put(shopProductSpecItem.getSpec_item_name(),shopProductSpecItem.getSpec_item_id());
}
if (CollUtil.isNotEmpty(map)) redisService.set(redisKey, map, 60 * 60);
return map;
}
@Override
public void clearExistItem(Integer storeId) {
String redisKey=RedisKey.STOREDATAPRODUCTSPECITEM+"storeId:"+storeId;
if(null!=redisService.get(redisKey)){
redisService.del(redisKey);
}
}
}

View File

@ -139,8 +139,8 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
}
@Override
public Map getProductMapping(Integer storeId) {
Map map=new HashMap();
public Map<String,ProductMapping> getProductMapping(Integer storeId) {
Map<String,ProductMapping> map=new HashMap<>();
QueryWrapper<ProductMapping> queryWrapper= new QueryWrapper<>();
//queryWrapper.eq("store_id", storeId);
queryWrapper.and(m->m.eq("store_id",storeId).or().eq("store_id",0)).orderByDesc("sort_order");
@ -302,17 +302,25 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
if (CollUtil.isEmpty(shopProductBaseList)) {
return Collections.emptyList();
}
// 使用IN查询优化根据数据库特性可能需要分批
QueryWrapper<ShopProductItem> query = new QueryWrapper<>();
query.select("product_id", "store_id", "item_id","item_unit_price","item_unit_price","item_market_price","category_id");
// 构建OR条件 (store_id=X AND product_number=Y) OR (store_id=A AND product_number=B)...
shopProductBaseList.forEach(base -> {
query.or(q -> q.eq("store_id", base.getStore_id())
.eq("product_id", base.getProduct_id()));
});
query.orderByAsc("product_id");
return shopProductItemService.list(query);
// // 使用IN查询优化根据数据库特性可能需要分批
// QueryWrapper<ShopProductItem> query = new QueryWrapper<>();
// query.select("product_id", "store_id", "item_id","item_unit_price","item_unit_price","item_market_price","category_id");
//
// // 构建OR条件 (store_id=X AND product_number=Y) OR (store_id=A AND product_number=B)...
// shopProductBaseList.forEach(base -> {
// query.or(q -> q.eq("store_id", base.getStore_id())
// .eq("product_id", base.getProduct_id()));
// });
// query.groupBy("product_id");
// query.orderByAsc("product_id");
//
// LambdaQueryWrapper<ShopProductItem> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.groupBy(ShopProductItem::getProduct_id);
List<Long> product_ids = new ArrayList<>();
for (ShopProductBase shopProductBase : shopProductBaseList) {
product_ids.add(shopProductBase.getProduct_id());
}
return shopProductItemService.getLimitFirstByProductId(product_ids);
}
/**
@ -421,9 +429,9 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
ExecutorService executor = Executors.newFixedThreadPool(6);
List<Future<?>> futures = new ArrayList<>();
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map productMappingMap = this.getProductMapping(storeId);
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(storeId);
Map<String,Integer> shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
Map<String,ProductMapping> productMappingMap = this.getProductMapping(storeId);
Map<String,ShopBaseProductSpec> ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(storeId);
boolean isUpDatePrice=ObjectUtil.isNotEmpty(storeDbConfig.getRefreshTime());
for (int i=1;i<=pages;i++){
int finalI = i;

View File

@ -701,8 +701,8 @@ public abstract class SyncBaseThirdSxAbstract{
* @param storeId
* @return
*/
public int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,String priorityMode,
Map<String,Integer> brandMaps,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdatePrice){
public int baseSaveOrUpdateGoodsBatch(JSONArray goodsListJSON,String storeId,String isNegativeAllowed,
Map<String,Integer> brandMaps){
AtomicInteger resultCount = new AtomicInteger();
Map categoryMap= productCategoryService.getCategoryListByStoreId(storeId);//热数据加载
List<ShopProductBase> shopProductBaseList=new ArrayList<>();
@ -904,7 +904,7 @@ public abstract class SyncBaseThirdSxAbstract{
shopProductBaseService.saveProductBatch(shopProductBaseList,shopProductIndexList,shopProductDataList,shopProductDetailList,shopProductInfoList,shopProductItemLists,
shopProductImageList,
new ArrayList<ShopProductValidPeriod>(),
new ArrayList<ShopProductAssistIndex>(),priorityMode,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice);
new ArrayList<ShopProductAssistIndex>());
return resultCount.get();
}

View File

@ -574,8 +574,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
syncPrimaryKey();
shopNumberSeqService.clearKey();
shopBaseProductCategoryService.clearCategoryCache(storeId);
baseProductSpecService.clearShopBaseProductSpecMap(Integer.valueOf(storeId));
shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
// shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
shopNumberSeqService.clearKeyStoreItemSepcId();
ExecutorService executor = Executors.newFixedThreadPool(6);
List<Future<?>> futures = new ArrayList<>();
@ -590,14 +589,14 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
QueryWrapper<StoreDbConfig> storeDbConfigQueryWrapper = new QueryWrapper<>();
storeDbConfigQueryWrapper.eq("store_id", storeId);
StoreDbConfig storeDbConfig = storeDbConfigService.getOne(storeDbConfigQueryWrapper);
Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(Integer.valueOf(storeId));//切割缓存
Map productMappingMap = productMappingService.getProductMapping(Integer.valueOf(storeId));//切割缓存
Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(Integer.valueOf(storeId));//切割商品缓存
// Map shopProductSpecItemMap = shopProductSpecItemService.getExistItem(Integer.valueOf(storeId));//切割缓存
// Map productMappingMap = productMappingService.getProductMapping(Integer.valueOf(storeId));//切割缓存
// Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(Integer.valueOf(storeId));//切割商品缓存
for (int i = 0; i < newFolders.size(); i++) {
final int taskId = i;
final String isNegativeAllowed = storeDbConfig.getIsNegativeAllowed();
String priorityMode = storeDbConfig.getPriorityMode();
boolean isUpdatePrice= ObjectUtil.isNotEmpty(storeDbConfig.getRefreshTime());//是否更新所有切割价格
//String priorityMode = storeDbConfig.getPriorityMode();
//boolean isUpdatePrice= ObjectUtil.isNotEmpty(storeDbConfig.getRefreshTime());//是否更新所有切割价格
threadNum.incrementAndGet();
futures.add(executor.submit(() -> {
int count = 0;//失败重试机制当失败重试一次再次失败则记录到数据库中
@ -607,7 +606,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
String fileName = "good_" + (taskId + 1) + ".txt";
JSONArray jsonArray = new ThreadFileUtils().processFolder(taskName, newFolders.get(taskId));
try {
baseSaveOrUpdateGoodsBatch(jsonArray, storeId, isNegativeAllowed, priorityMode, brandMaps,shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,isUpdatePrice);
baseSaveOrUpdateGoodsBatch(jsonArray, storeId, isNegativeAllowed, brandMaps);
success.getAndIncrement();
threadNum.decrementAndGet();
return "成功" + taskId;
@ -638,8 +637,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
shopNumberSeqService.clearKey();
shopNumberSeqService.clearKeyStoreItemSepcId();
shopBaseProductCategoryService.clearCategoryCache(storeId);
shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
baseProductSpecService.clearShopBaseProductSpecMap(Integer.valueOf(storeId));
productBrandService.clearBrandMapByStoreId(storeId);
List<SyncFileLog> syncFileLogs = new ArrayList<>();
for (int i = 0; i < failFolders.size(); i++) {

View File

@ -228,4 +228,16 @@
</update>
<select id="getLimitFirstByProductId" resultType="com.suisung.mall.common.modules.product.ShopProductItem">
SELECT product_id,store_id,item_id,item_unit_price,item_unit_price,item_market_price,category_id FROM (
SELECT ROW_NUMBER() OVER(partition by s.product_id order by s.product_id asc) rn,s.*
from shop_product_item s
)t where t.rn=1
and product_id in
<foreach item="productId" collection="productIds" open="(" separator="," close=")">
#{productId}
</foreach>
</select>
</mapper>