思迅单机改为分布式商品导入
This commit is contained in:
parent
41dbafffab
commit
645ad45d08
@ -10,10 +10,10 @@ import com.suisung.mall.common.exception.ApiException;
|
|||||||
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
||||||
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
||||||
import com.suisung.mall.common.utils.CheckUtil;
|
import com.suisung.mall.common.utils.CheckUtil;
|
||||||
import com.suisung.mall.common.utils.ContextUtil;
|
|
||||||
import com.suisung.mall.common.utils.FilterUtils;
|
import com.suisung.mall.common.utils.FilterUtils;
|
||||||
import com.suisung.mall.common.utils.I18nUtil;
|
import com.suisung.mall.common.utils.I18nUtil;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
||||||
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -49,7 +49,11 @@ public class ShopBaseProductSpecController {
|
|||||||
private ShopProductSpecItemService shopProductSpecItemService;
|
private ShopProductSpecItemService shopProductSpecItemService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ShopStoreBaseService shopStoreBaseService;
|
private ShopStoreBaseService shopStoreBaseService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopNumberSeqService shopNumberSeqService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
*
|
||||||
@ -105,6 +109,8 @@ public class ShopBaseProductSpecController {
|
|||||||
shopBaseProductSpec.setStore_id(oldSpec.getStore_id());
|
shopBaseProductSpec.setStore_id(oldSpec.getStore_id());
|
||||||
}else {
|
}else {
|
||||||
Integer storeId = Integer.valueOf(userDto.getStore_id());
|
Integer storeId = Integer.valueOf(userDto.getStore_id());
|
||||||
|
List<Integer> specIdList= shopNumberSeqService.getBatchSpecId(1);
|
||||||
|
shopBaseProductSpec.setSpec_id(specIdList.get(0));
|
||||||
shopBaseProductSpec.setStore_id(storeId);
|
shopBaseProductSpec.setStore_id(storeId);
|
||||||
}
|
}
|
||||||
shopBaseProductSpec.setSpec_id(spec_id);
|
shopBaseProductSpec.setSpec_id(spec_id);
|
||||||
|
|||||||
@ -3,11 +3,9 @@ package com.suisung.mall.shop.base.service.impl;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.suisung.mall.common.domain.UserDto;
|
|
||||||
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
import com.suisung.mall.common.modules.base.ShopBaseProductCategory;
|
||||||
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
||||||
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
||||||
import com.suisung.mall.common.utils.ContextUtil;
|
|
||||||
import com.suisung.mall.common.utils.FilterUtils;
|
import com.suisung.mall.common.utils.FilterUtils;
|
||||||
import com.suisung.mall.common.utils.I18nUtil;
|
import com.suisung.mall.common.utils.I18nUtil;
|
||||||
import com.suisung.mall.core.web.service.RedisService;
|
import com.suisung.mall.core.web.service.RedisService;
|
||||||
@ -16,7 +14,6 @@ import com.suisung.mall.shop.base.mapper.ShopBaseProductSpecMapper;
|
|||||||
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|||||||
@ -22,13 +22,11 @@ public interface ShopNumberSeqService extends IBaseService<ShopNumberSeq> {
|
|||||||
List<Long> batchCreateNextNo(String seqName, int batchSize);
|
List<Long> batchCreateNextNo(String seqName, int batchSize);
|
||||||
|
|
||||||
void clearRelateGoodsId();
|
void clearRelateGoodsId();
|
||||||
void clearKey();
|
|
||||||
|
|
||||||
void batchUpdateSeq(List<ShopNumberSeq> shopNumberSeqList);
|
void batchUpdateSeq(List<ShopNumberSeq> shopNumberSeqList);
|
||||||
|
|
||||||
List<Integer> getBatchSpecItemId(int batchSize);
|
List<Integer> getBatchSpecItemId(int batchSize);
|
||||||
|
|
||||||
void clearKeyStoreItemSepcId();
|
|
||||||
|
|
||||||
List<Integer> getBatchUserAccountBaseId(int batchSize);
|
List<Integer> getBatchUserAccountBaseId(int batchSize);
|
||||||
|
|
||||||
@ -36,8 +34,6 @@ public interface ShopNumberSeqService extends IBaseService<ShopNumberSeq> {
|
|||||||
|
|
||||||
List<Integer> getBatchSpecId(int batchSize);
|
List<Integer> getBatchSpecId(int batchSize);
|
||||||
|
|
||||||
void clearKeyStoreSepcId();
|
|
||||||
|
|
||||||
List<Integer> getBatchLibraryProductId(int batchSize);
|
List<Integer> getBatchLibraryProductId(int batchSize);
|
||||||
|
|
||||||
void clearKeyLibraryProductId();
|
void clearKeyLibraryProductId();
|
||||||
|
|||||||
@ -6,6 +6,8 @@ import com.suisung.mall.common.feignService.AccountService;
|
|||||||
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
||||||
import com.suisung.mall.common.modules.library.LibraryProduct;
|
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||||
import com.suisung.mall.common.modules.number.ShopNumberSeq;
|
import com.suisung.mall.common.modules.number.ShopNumberSeq;
|
||||||
|
import com.suisung.mall.common.modules.product.ShopProductBase;
|
||||||
|
import com.suisung.mall.common.modules.product.ShopProductItem;
|
||||||
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
||||||
import com.suisung.mall.core.web.service.RedisService;
|
import com.suisung.mall.core.web.service.RedisService;
|
||||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||||
@ -13,13 +15,17 @@ import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
|||||||
import com.suisung.mall.shop.library.service.LibraryProductService;
|
import com.suisung.mall.shop.library.service.LibraryProductService;
|
||||||
import com.suisung.mall.shop.number.mapper.ShopNumberSeqMapper;
|
import com.suisung.mall.shop.number.mapper.ShopNumberSeqMapper;
|
||||||
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
|
import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
||||||
|
import com.suisung.mall.shop.product.service.ShopProductItemService;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -57,6 +63,15 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LibraryProductService libraryProductService;
|
private LibraryProductService libraryProductService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
private ShopProductBaseService shopProductBaseService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
private ShopProductItemService shopProductItemService;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.printf(IntStream.rangeClosed(1, 1).boxed().collect(Collectors.toList()).toString());
|
System.out.printf(IntStream.rangeClosed(1, 1).boxed().collect(Collectors.toList()).toString());
|
||||||
}
|
}
|
||||||
@ -166,6 +181,7 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
|||||||
}
|
}
|
||||||
long number = 0;
|
long number = 0;
|
||||||
if (null == redisService.get(String.format(CACHE_PREFIX, seqName))) {
|
if (null == redisService.get(String.format(CACHE_PREFIX, seqName))) {
|
||||||
|
syncPrimaryKey();
|
||||||
// 1. 获取当前序列值
|
// 1. 获取当前序列值
|
||||||
QueryWrapper<ShopNumberSeq> wrapper = new QueryWrapper<>();
|
QueryWrapper<ShopNumberSeq> wrapper = new QueryWrapper<>();
|
||||||
wrapper.eq("prefix", seqName);
|
wrapper.eq("prefix", seqName);
|
||||||
@ -207,24 +223,10 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
|||||||
log.info("更新成功{}条数据", count);
|
log.info("更新成功{}条数据", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearKey() {
|
|
||||||
redisService.del(String.format(CACHE_PREFIX, "item_id"));
|
|
||||||
redisService.del(String.format(CACHE_PREFIX, "product_id"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearKeyStoreItemSepcId() {
|
|
||||||
redisService.del(RedisKey.STOREDATASPECITEMID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearKeyStoreAccountBaseId() {
|
public void clearKeyStoreAccountBaseId() {
|
||||||
redisService.del(RedisKey.STOREDATACCOUNTBASEID);
|
redisService.del(RedisKey.STOREDATACCOUNTBASEID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearKeyStoreSepcId() {
|
|
||||||
redisService.del(RedisKey.STOREDATASPECID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除缓存,专门给并发使用,防止redis的缓存没有加载
|
* 清除缓存,专门给并发使用,防止redis的缓存没有加载
|
||||||
*/
|
*/
|
||||||
@ -376,5 +378,38 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
|||||||
redisService.del(RedisKey.STOREDATALIBRARYID);
|
redisService.del(RedisKey.STOREDATALIBRARYID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化主键
|
||||||
|
*/
|
||||||
|
private void syncPrimaryKey(){
|
||||||
|
List<ShopNumberSeq> shopNumberSeqList=new ArrayList<>();
|
||||||
|
QueryWrapper<ShopProductBase> baseWrapper=new QueryWrapper<>();
|
||||||
|
baseWrapper.select("MAX(product_id) as product_id");
|
||||||
|
ShopProductBase shopProductBase= shopProductBaseService.getOne(baseWrapper);
|
||||||
|
Long productId= shopProductBase.getProduct_id();
|
||||||
|
//QueryWrapper<ShopNumberSeq> baseSeWrapper=new QueryWrapper();
|
||||||
|
//baseSeWrapper.eq("prefix", "product_id");
|
||||||
|
ShopNumberSeq shopNumberSeqBase= new ShopNumberSeq();
|
||||||
|
shopNumberSeqBase.setPrefix("product_id");
|
||||||
|
shopNumberSeqBase.setNumber(productId);
|
||||||
|
//shopNumberSeqServiceImpl.edit(shopNumberSeqBase,baseWrapper);
|
||||||
|
//查询产品item
|
||||||
|
QueryWrapper<ShopProductItem> itemQuery=new QueryWrapper<>();
|
||||||
|
itemQuery.select("MAX(item_id) as item_id");
|
||||||
|
ShopProductItem shopProductItem= shopProductItemService.getOne(itemQuery);
|
||||||
|
Long itemtId=1L;
|
||||||
|
if(null!=shopProductItem){
|
||||||
|
itemtId= shopProductItem.getItem_id();
|
||||||
|
}
|
||||||
|
// QueryWrapper<ShopNumberSeq> itemWrapper=new QueryWrapper();
|
||||||
|
//itemWrapper.eq("prefix", "item_id");
|
||||||
|
ShopNumberSeq shopNumberSeqItem= new ShopNumberSeq();
|
||||||
|
shopNumberSeqItem.setNumber(itemtId);
|
||||||
|
shopNumberSeqItem.setPrefix("item_id");
|
||||||
|
shopNumberSeqList.add(shopNumberSeqBase);
|
||||||
|
shopNumberSeqList.add(shopNumberSeqItem);
|
||||||
|
this.batchUpdateSeq(shopNumberSeqList);
|
||||||
|
this.clearRelateGoodsId();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
|||||||
import com.suisung.mall.common.service.impl.BaseControllerImpl;
|
import com.suisung.mall.common.service.impl.BaseControllerImpl;
|
||||||
import com.suisung.mall.common.utils.CheckUtil;
|
import com.suisung.mall.common.utils.CheckUtil;
|
||||||
import com.suisung.mall.common.utils.ContextUtil;
|
import com.suisung.mall.common.utils.ContextUtil;
|
||||||
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
import com.suisung.mall.shop.product.mapper.ShopProductItemMapper;
|
import com.suisung.mall.shop.product.mapper.ShopProductItemMapper;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductItemService;
|
import com.suisung.mall.shop.product.service.ShopProductItemService;
|
||||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||||
@ -21,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 商品规格值表 前端控制器
|
* 商品规格值表 前端控制器
|
||||||
@ -43,6 +46,9 @@ public class ShopProductSpecItemController extends BaseControllerImpl {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ShopProductItemMapper shopProductItemMapper;
|
private ShopProductItemMapper shopProductItemMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopNumberSeqService shopNumberSeqService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页列表查询
|
* 分页列表查询
|
||||||
*
|
*
|
||||||
@ -88,6 +94,10 @@ public class ShopProductSpecItemController extends BaseControllerImpl {
|
|||||||
public CommonResult edit(ShopProductSpecItem shopProductSpecItem) {
|
public CommonResult edit(ShopProductSpecItem shopProductSpecItem) {
|
||||||
UserDto user = ContextUtil.getCurrentUser();
|
UserDto user = ContextUtil.getCurrentUser();
|
||||||
shopProductSpecItem.setStore_id(Integer.valueOf(user.getStore_id()));
|
shopProductSpecItem.setStore_id(Integer.valueOf(user.getStore_id()));
|
||||||
|
if(ObjectUtil.isNull(shopProductSpecItem.getSpec_item_id())){
|
||||||
|
List<Integer> specItemIds= shopNumberSeqService.getBatchSpecItemId(1);
|
||||||
|
shopProductSpecItem.setSpec_item_id(specItemIds.get(0));
|
||||||
|
}
|
||||||
return CommonResult.success(shopProductSpecItemService.saveOrUpdate(shopProductSpecItem));
|
return CommonResult.success(shopProductSpecItemService.saveOrUpdate(shopProductSpecItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -737,7 +737,10 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
String product_image_old = "";
|
String product_image_old = "";
|
||||||
if (productId == null) {
|
if (productId == null) {
|
||||||
// 生成商品ID:product_id
|
// 生成商品ID:product_id
|
||||||
productId = shopNumberSeqService.createNextNo("product_id");
|
List<Long> productIds= shopNumberSeqService.batchCreateNextNo("product_id",1);
|
||||||
|
productId=productIds.get(0);
|
||||||
|
// productId = shopNumberSeqService.createNextNo("product_id");
|
||||||
|
|
||||||
if (null == productId) {
|
if (null == productId) {
|
||||||
return Pair.of(false, I18nUtil._("生成商品编号异常!"));
|
return Pair.of(false, I18nUtil._("生成商品编号异常!"));
|
||||||
} else {
|
} else {
|
||||||
@ -1032,7 +1035,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
field_row.setProduct_item_seq_id(product_item_seq_id);
|
field_row.setProduct_item_seq_id(product_item_seq_id);
|
||||||
|
|
||||||
//这儿应该提前生成编号使用
|
//这儿应该提前生成编号使用
|
||||||
item_id = shopNumberSeqService.createNextNo("item_id");
|
List<Long> itemIds= shopNumberSeqService.batchCreateNextNo("item_id",1);
|
||||||
|
item_id=itemIds.get(0);
|
||||||
|
// item_id = shopNumberSeqService.createNextNo("item_id");
|
||||||
|
|
||||||
if (null == item_id) {
|
if (null == item_id) {
|
||||||
return Pair.of(false, I18nUtil._("生成商品 ItemId 异常!"));
|
return Pair.of(false, I18nUtil._("生成商品 ItemId 异常!"));
|
||||||
@ -1209,8 +1214,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
boolean $flag = false;
|
boolean $flag = false;
|
||||||
List $rs_row = new ArrayList();
|
List $rs_row = new ArrayList();
|
||||||
ShopStoreBase $store_row = shopStoreBaseService.get(store_id);
|
ShopStoreBase $store_row = shopStoreBaseService.get(store_id);
|
||||||
|
List<Long> productIds= shopNumberSeqService.batchCreateNextNo("product_id",1);
|
||||||
Long $product_id = shopNumberSeqService.createNextNo("product_id");
|
Long $product_id = productIds.get(0);
|
||||||
|
//Long $product_id = shopNumberSeqService.createNextNo("product_id");
|
||||||
|
|
||||||
if (null == $product_id) {
|
if (null == $product_id) {
|
||||||
throw new ApiException(I18nUtil._("生成商品编号异常!"));
|
throw new ApiException(I18nUtil._("生成商品编号异常!"));
|
||||||
@ -1383,7 +1389,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
field_row.setProduct_item_seq_id(product_item_seq_id);
|
field_row.setProduct_item_seq_id(product_item_seq_id);
|
||||||
|
|
||||||
//这儿应该提前生成编号使用
|
//这儿应该提前生成编号使用
|
||||||
item_id = shopNumberSeqService.createNextNo("item_id");
|
List<Long> itemIds= shopNumberSeqService.batchCreateNextNo("item_id",1);
|
||||||
|
item_id=itemIds.get(0);
|
||||||
|
//item_id = shopNumberSeqService.createNextNo("item_id");
|
||||||
|
|
||||||
if (null == item_id) {
|
if (null == item_id) {
|
||||||
throw new ApiException(I18nUtil._("生成商品ItemId异常!"));
|
throw new ApiException(I18nUtil._("生成商品ItemId异常!"));
|
||||||
@ -4981,8 +4989,9 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
|||||||
shopProductItemSeq.setProduct_item_seq_id(product_item_seq_id);
|
shopProductItemSeq.setProduct_item_seq_id(product_item_seq_id);
|
||||||
|
|
||||||
//这儿应该提前生成编号使用
|
//这儿应该提前生成编号使用
|
||||||
item_id = shopNumberSeqService.createNextNo("item_id");
|
// item_id = shopNumberSeqService.createNextNo("item_id");
|
||||||
|
List<Long> itemIds= shopNumberSeqService.batchCreateNextNo("item_id",1);
|
||||||
|
item_id=itemIds.get(0);
|
||||||
if (null == item_id) {
|
if (null == item_id) {
|
||||||
throw new ApiException(I18nUtil._("生成商品ItemId异常!"));
|
throw new ApiException(I18nUtil._("生成商品ItemId异常!"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1224,7 +1224,8 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
|||||||
shopProductBase.setProduct_id(product_id);
|
shopProductBase.setProduct_id(product_id);
|
||||||
shopProductIndex.setProduct_id(product_id);
|
shopProductIndex.setProduct_id(product_id);
|
||||||
} else {
|
} else {
|
||||||
shopProductBase.setProduct_id(shopNumberSeqService.createNextNo("product_id"));
|
List<Long> productIds= shopNumberSeqService.batchCreateNextNo("product_id",1);
|
||||||
|
shopProductBase.setProduct_id(productIds.get(0));
|
||||||
shopProductBase.setProduct_add_time(currentDate.getTime());
|
shopProductBase.setProduct_add_time(currentDate.getTime());
|
||||||
shopProductIndex.setProduct_add_time(currentDate.getTime());
|
shopProductIndex.setProduct_add_time(currentDate.getTime());
|
||||||
}
|
}
|
||||||
@ -1295,7 +1296,8 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
|
|||||||
if (item_id != null) {
|
if (item_id != null) {
|
||||||
shopProductItem.setItem_id(item_id);
|
shopProductItem.setItem_id(item_id);
|
||||||
} else {
|
} else {
|
||||||
shopProductItem.setItem_id(shopNumberSeqService.createNextNo("item_id"));
|
List<Long> itemIds= shopNumberSeqService.batchCreateNextNo("item_id",1);
|
||||||
|
shopProductItem.setItem_id(itemIds.get(0));
|
||||||
shopProductItem.setItem_number(IdUtil.simpleUUID());
|
shopProductItem.setItem_number(IdUtil.simpleUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,4 +26,6 @@ public class RedisKey {
|
|||||||
|
|
||||||
|
|
||||||
public static final String STOREDATALIBRARYID="storedata:libraryId";
|
public static final String STOREDATALIBRARYID="storedata:libraryId";
|
||||||
|
|
||||||
|
public static final String STOREDATAGOODBATCHLOCK="store:data:goodsbatchLock";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -537,7 +537,6 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
|||||||
* 清除缓存数据
|
* 清除缓存数据
|
||||||
*/
|
*/
|
||||||
private void clearCacheData(){
|
private void clearCacheData(){
|
||||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
|
||||||
Set<String> item_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_item"+ "*");
|
Set<String> item_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_item"+ "*");
|
||||||
redisService.del(item_keys);
|
redisService.del(item_keys);
|
||||||
Set<String> base_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_base"+ "*");
|
Set<String> base_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_base"+ "*");
|
||||||
|
|||||||
@ -237,9 +237,7 @@ public class ShopSyncImportServiceImpl implements ShopSyncImportService {
|
|||||||
|
|
||||||
private void cleanCache(String storeId){
|
private void cleanCache(String storeId){
|
||||||
syncThirdDataService.syncPrimaryKey();
|
syncThirdDataService.syncPrimaryKey();
|
||||||
shopNumberSeqService.clearKey();
|
|
||||||
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
|
||||||
productBrandService.clearBrandMapByStoreId(storeId);
|
productBrandService.clearBrandMapByStoreId(storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1059,9 +1059,10 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
Map<String, Integer> existIdMap= checkExistingShopBaseProductSpec(shopBaseProductSpecList);
|
Map<String, Integer> existIdMap= checkExistingShopBaseProductSpec(shopBaseProductSpecList);
|
||||||
List<ShopBaseProductSpec> insertShopBaseProductSpecList=new ArrayList<>();
|
List<ShopBaseProductSpec> insertShopBaseProductSpecList=new ArrayList<>();
|
||||||
List<ShopBaseProductSpec> updateShopBaseProductSpecList=new ArrayList<>();
|
List<ShopBaseProductSpec> updateShopBaseProductSpecList=new ArrayList<>();
|
||||||
QueryWrapper<ShopBaseProductSpec> queryWrapper= new QueryWrapper<>();
|
// QueryWrapper<ShopBaseProductSpec> queryWrapper= new QueryWrapper<>();
|
||||||
queryWrapper.select("max(spec_id) as spec_id");
|
// queryWrapper.select("max(spec_id) as spec_id");
|
||||||
int spec_id=shopBaseProductSpecService.getOne(queryWrapper).getSpec_id()+1;
|
// int spec_id=shopBaseProductSpecService.getOne(queryWrapper).getSpec_id()+1;
|
||||||
|
|
||||||
//int i=0;
|
//int i=0;
|
||||||
for(int i=0;i<shopBaseProductSpecList.size();i++){
|
for(int i=0;i<shopBaseProductSpecList.size();i++){
|
||||||
if(existIdMap.containsKey(shopBaseProductSpecList.get(i).getSpec_name())){
|
if(existIdMap.containsKey(shopBaseProductSpecList.get(i).getSpec_name())){
|
||||||
@ -1075,18 +1076,33 @@ public abstract class SyncBaseThirdSxAbstract{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else {
|
}else {
|
||||||
shopBaseProductSpecList.get(i).setSpec_id(spec_id);
|
//shopBaseProductSpecList.get(i).setSpec_id(spec_id);
|
||||||
int finalSpec_id = spec_id;
|
// int finalSpec_id = spec_id;
|
||||||
int finalI1 = i;
|
// int finalI1 = i;
|
||||||
|
// shopBaseProductTypes.forEach(shopBaseProductType -> {
|
||||||
|
// if((shopBaseProductType.getType_name()+"规格").equals(shopBaseProductSpecList.get(finalI1).getSpec_name())){
|
||||||
|
// shopBaseProductType.setType_spec_ids(String.valueOf(finalSpec_id));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
insertShopBaseProductSpecList.add(shopBaseProductSpecList.get(i));
|
||||||
|
}
|
||||||
|
// spec_id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!insertShopBaseProductSpecList.isEmpty()){
|
||||||
|
List<Integer> specIdList=shopNumberSeqService.getBatchSpecId(insertShopBaseProductSpecList.size());
|
||||||
|
for(int i=0;i<specIdList.size();i++){
|
||||||
|
int finalSpec_id = specIdList.get(i);
|
||||||
|
int finalI = i;
|
||||||
shopBaseProductTypes.forEach(shopBaseProductType -> {
|
shopBaseProductTypes.forEach(shopBaseProductType -> {
|
||||||
if((shopBaseProductType.getType_name()+"规格").equals(shopBaseProductSpecList.get(finalI1).getSpec_name())){
|
if((shopBaseProductType.getType_name()+"规格").equals(insertShopBaseProductSpecList.get(finalI).getSpec_name())){
|
||||||
shopBaseProductType.setType_spec_ids(String.valueOf(finalSpec_id));
|
shopBaseProductType.setType_spec_ids(String.valueOf(finalSpec_id));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
insertShopBaseProductSpecList.add(shopBaseProductSpecList.get(i));
|
insertShopBaseProductSpecList.get(i).setSpec_id(finalSpec_id);
|
||||||
}
|
}
|
||||||
spec_id++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CollectionUtil.isNotEmpty(insertShopBaseProductSpecList)){
|
if(CollectionUtil.isNotEmpty(insertShopBaseProductSpecList)){
|
||||||
shopBaseProductSpecService.saveBatch(insertShopBaseProductSpecList,insertShopBaseProductSpecList.size());
|
shopBaseProductSpecService.saveBatch(insertShopBaseProductSpecList,insertShopBaseProductSpecList.size());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,6 @@ public class SyncStoreSpecsServiceImpl extends ServiceImpl<SyncStoreSpecsMapper,
|
|||||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||||
AtomicInteger success=new AtomicInteger(0);
|
AtomicInteger success=new AtomicInteger(0);
|
||||||
AtomicInteger fails=new AtomicInteger(0);
|
AtomicInteger fails=new AtomicInteger(0);
|
||||||
shopNumberSeqService.clearKeyStoreSepcId();
|
|
||||||
List<Future<?>> futures = new ArrayList<>();
|
List<Future<?>> futures = new ArrayList<>();
|
||||||
QueryWrapper<SyncStoreSpecs> wrapper = new QueryWrapper<>();
|
QueryWrapper<SyncStoreSpecs> wrapper = new QueryWrapper<>();
|
||||||
wrapper.eq("store_id", storeId);
|
wrapper.eq("store_id", storeId);
|
||||||
@ -120,7 +119,6 @@ public class SyncStoreSpecsServiceImpl extends ServiceImpl<SyncStoreSpecsMapper,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
shopNumberSeqService.clearKeyStoreSepcId();
|
|
||||||
log.info("处理多规格数据成功:{}批,失败:{}批", success.get(), fails.get());
|
log.info("处理多规格数据成功:{}批,失败:{}批", success.get(), fails.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ import com.suisung.mall.common.pojo.res.ThirdApiRes;
|
|||||||
import com.suisung.mall.common.utils.I18nUtil;
|
import com.suisung.mall.common.utils.I18nUtil;
|
||||||
import com.suisung.mall.common.utils.StringUtils;
|
import com.suisung.mall.common.utils.StringUtils;
|
||||||
import com.suisung.mall.common.utils.TextCompressionUtil;
|
import com.suisung.mall.common.utils.TextCompressionUtil;
|
||||||
|
import com.suisung.mall.core.web.service.RedisService;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductBrandService;
|
||||||
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
import com.suisung.mall.shop.base.service.ShopBaseProductCategoryService;
|
||||||
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
@ -71,6 +72,7 @@ import com.suisung.mall.shop.sync.dto.ActiveShopInfo;
|
|||||||
import com.suisung.mall.shop.sync.dto.BrandModel;
|
import com.suisung.mall.shop.sync.dto.BrandModel;
|
||||||
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
import com.suisung.mall.shop.sync.keymanage.RedisKey;
|
||||||
import com.suisung.mall.shop.sync.service.*;
|
import com.suisung.mall.shop.sync.service.*;
|
||||||
|
import com.sun.corba.se.impl.orbutil.concurrent.Sync;
|
||||||
import io.seata.spring.annotation.GlobalTransactional;
|
import io.seata.spring.annotation.GlobalTransactional;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.collections4.ListUtils;
|
import org.apache.commons.collections4.ListUtils;
|
||||||
@ -106,6 +108,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -186,6 +189,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SyncStoreDataService syncStoreDataService;
|
private SyncStoreDataService syncStoreDataService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
/**
|
/**
|
||||||
* 批量保存商品的分类
|
* 批量保存商品的分类
|
||||||
*
|
*
|
||||||
@ -558,7 +563,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Async
|
@Async
|
||||||
public void SyncReadSxFileData(String appKey, String sign, String syncType, List<String> folders) {
|
public void SyncReadSxFileData(String appKey, String sign, String syncType, List<String> folders){
|
||||||
SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
SyncApp syncApp = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
||||||
.select(SyncApp::getApp_key, SyncApp::getApp_secret, SyncApp::getStore_id)
|
.select(SyncApp::getApp_key, SyncApp::getApp_secret, SyncApp::getStore_id)
|
||||||
.eq(SyncApp::getApp_key, appKey)
|
.eq(SyncApp::getApp_key, appKey)
|
||||||
@ -574,7 +579,13 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
logger.info("没有商品数据");
|
logger.info("没有商品数据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String key=RedisKey.STOREDATAGOODBATCHLOCK+":"+storeId;
|
||||||
|
// redisService.del(key);
|
||||||
|
if(!checkeckIsLock(storeId)){
|
||||||
|
logger.info("批量同步商品等待时间异常结束");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLock(storeId,"true");
|
||||||
List<String> newFolders = new ArrayList<>();
|
List<String> newFolders = new ArrayList<>();
|
||||||
folders.forEach(page -> {
|
folders.forEach(page -> {
|
||||||
String newfolder = new FileUtils().getSyncTypeFlag(syncType, clientPath) + storeId + FileUtils.pathSeparator + page + FileUtils.pathSeparator;
|
String newfolder = new FileUtils().getSyncTypeFlag(syncType, clientPath) + storeId + FileUtils.pathSeparator + page + FileUtils.pathSeparator;
|
||||||
@ -584,10 +595,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
//upLoadZipToOss(newFolders.get(0));//上传文件到cos
|
//upLoadZipToOss(newFolders.get(0));//上传文件到cos
|
||||||
// dowloadAndUnZip(newFolders.get(0));//读取cos文件回本地
|
// dowloadAndUnZip(newFolders.get(0));//读取cos文件回本地
|
||||||
syncPrimaryKey();
|
syncPrimaryKey();
|
||||||
shopNumberSeqService.clearKey();
|
|
||||||
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||||
// shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
|
// shopProductSpecItemService.clearExistItem(Integer.valueOf(storeId));
|
||||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||||
List<Future<?>> futures = new ArrayList<>();
|
List<Future<?>> futures = new ArrayList<>();
|
||||||
// 提交任务
|
// 提交任务
|
||||||
@ -606,9 +615,18 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
// Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(Integer.valueOf(storeId));//切割商品缓存
|
// Map ShopBaseProductSpecMap = baseProductSpecService.getShopBaseProductSpecMap(Integer.valueOf(storeId));//切割商品缓存
|
||||||
// long seconds=System.currentTimeMillis();
|
// long seconds=System.currentTimeMillis();
|
||||||
// Date productSaleTime=Date.from(Instant.now().plusSeconds(seconds));
|
// Date productSaleTime=Date.from(Instant.now().plusSeconds(seconds));
|
||||||
|
|
||||||
|
String fileIndex=folders.get(0);
|
||||||
|
String fileEndFix;
|
||||||
|
if (fileIndex.length()>1){
|
||||||
|
fileEndFix=fileIndex.split("_")[1];
|
||||||
|
} else {
|
||||||
|
fileEndFix = "";
|
||||||
|
}
|
||||||
|
|
||||||
List<String> fileNames=new ArrayList<>();
|
List<String> fileNames=new ArrayList<>();
|
||||||
for(int i=0;i<newFolders.size();i++){
|
for(int i=0;i<newFolders.size();i++){
|
||||||
String fileName = "goods_" + (i + 1) + ".txt";
|
String fileName = "goods_" + (i + 1)+"_"+fileEndFix+ ".txt";
|
||||||
fileNames.add(fileName);
|
fileNames.add(fileName);
|
||||||
}
|
}
|
||||||
QueryWrapper<SyncStoreData> syncStoreDataQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<SyncStoreData> syncStoreDataQueryWrapper = new QueryWrapper<>();
|
||||||
@ -630,7 +648,7 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
while (true) {
|
while (true) {
|
||||||
count++;
|
count++;
|
||||||
// String taskName = newFolders.get(taskId);
|
// String taskName = newFolders.get(taskId);
|
||||||
String fileName = "goods_" + (taskId + 1) + ".txt";
|
String fileName = "goods_" + (taskId + 1) +"_"+fileEndFix+ ".txt";
|
||||||
String sycnDataId=DigestUtils.md5Hex(newFolders.get(taskId) + fileName);
|
String sycnDataId=DigestUtils.md5Hex(newFolders.get(taskId) + fileName);
|
||||||
JSONArray jsonArray = getSyncDataContent(finalSyncDataMap,sycnDataId);
|
JSONArray jsonArray = getSyncDataContent(finalSyncDataMap,sycnDataId);
|
||||||
try {
|
try {
|
||||||
@ -662,8 +680,6 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
//记录到数据库
|
//记录到数据库
|
||||||
syncPrimaryKey();
|
syncPrimaryKey();
|
||||||
shopNumberSeqService.clearKey();
|
|
||||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
|
||||||
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
shopBaseProductCategoryService.clearCategoryCache(storeId);
|
||||||
productBrandService.clearBrandMapByStoreId(storeId);
|
productBrandService.clearBrandMapByStoreId(storeId);
|
||||||
List<SyncFileLog> syncFileLogs = new ArrayList<>();
|
List<SyncFileLog> syncFileLogs = new ArrayList<>();
|
||||||
@ -708,6 +724,8 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
if(ObjectUtil.isNull(storeDbConfig.getRefreshTime())){
|
if(ObjectUtil.isNull(storeDbConfig.getRefreshTime())){
|
||||||
syncShopImages(Integer.valueOf(storeId));//同时商品图库数据
|
syncShopImages(Integer.valueOf(storeId));//同时商品图库数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redisService.del(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -716,6 +734,39 @@ public class SyncThirdDataServiceImpl extends SyncBaseThirdSxAbstract implements
|
|||||||
syncShopImageService.syncMapingShopImages(storeId);
|
syncShopImageService.syncMapingShopImages(storeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保证单线程执行同步数据
|
||||||
|
* @param storeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public synchronized boolean checkeckIsLock(String storeId){
|
||||||
|
logger.info("等待时间开始");
|
||||||
|
String key=RedisKey.STOREDATAGOODBATCHLOCK+":"+storeId;
|
||||||
|
Map isLockMap= (Map) redisService.get(key);
|
||||||
|
if(isLockMap!=null){
|
||||||
|
String result= (String) isLockMap.get("batchGoodIsLock");
|
||||||
|
if("true".equals(result)){
|
||||||
|
try {
|
||||||
|
logger.info("进入等待时间");
|
||||||
|
Thread.sleep(1000 * 60 * 1);//五分钟
|
||||||
|
return checkeckIsLock(storeId);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.info("等待异常:{}",e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info("等待时间结束");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void setLock(String storeId,String value){
|
||||||
|
String key=RedisKey.STOREDATAGOODBATCHLOCK+":"+storeId;
|
||||||
|
Map<String,String> map= new HashMap<>();
|
||||||
|
map.put("batchGoodIsLock",value);
|
||||||
|
redisService.set(key,map,600000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Resource> downloadToClient(String primaryKey, String clienVersionName) {
|
public ResponseEntity<Resource> downloadToClient(String primaryKey, String clienVersionName) {
|
||||||
|
|||||||
1
sql/shop/dev/20251111_dml.sql
Normal file
1
sql/shop/dev/20251111_dml.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
alter table sycn_store_data change `file_path` `file_path` varchar(128) DEFAULT NULL COMMENT '文件全路径';
|
||||||
Loading…
Reference in New Issue
Block a user