批量切割规格去掉名称
This commit is contained in:
parent
e11cf54167
commit
555771a0bb
@ -48,6 +48,10 @@ public class ProductMapping implements Serializable {
|
||||
@ApiModelProperty(value = "店铺名称")
|
||||
private String storeName;
|
||||
|
||||
@TableField(value ="product_number",updateStrategy=NOT_EMPTY)
|
||||
@ApiModelProperty(value = "商品货架号")
|
||||
private String productNumber;
|
||||
|
||||
@TableField(value ="spec_value",updateStrategy=NOT_EMPTY)
|
||||
@ApiModelProperty("规格数据")
|
||||
@NotNull(message="规格数据不能为空")
|
||||
|
||||
@ -366,6 +366,31 @@ public class CommonUtil {
|
||||
return t -> seen.add(keyExtractor.apply(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* 双字段去重工具
|
||||
* @param list
|
||||
* @param keyExtractor1
|
||||
* @param keyExtractor2
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> List<T> distinctByTwoFields(
|
||||
List<T> list,
|
||||
Function<T, ?> keyExtractor1,
|
||||
Function<T, ?> keyExtractor2) {
|
||||
|
||||
Set<List<Object>> seen = new HashSet<>();
|
||||
return list.stream()
|
||||
.filter(item -> {
|
||||
List<Object> keys = Arrays.asList(
|
||||
keyExtractor1.apply(item),
|
||||
keyExtractor2.apply(item)
|
||||
);
|
||||
return seen.add(keys);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照指定比例计算分账金额
|
||||
* 分配优先级: 商家 > 平台 > 代理商
|
||||
|
||||
@ -37,4 +37,8 @@ public interface ShopNumberSeqService extends IBaseService<ShopNumberSeq> {
|
||||
List<Integer> getBatchSpecId(int batchSize);
|
||||
|
||||
void clearKeyStoreSepcId();
|
||||
|
||||
List<Integer> getBatchLibraryProductId(int batchSize);
|
||||
|
||||
void clearKeyLibraryProductId();
|
||||
}
|
||||
|
||||
@ -4,11 +4,13 @@ import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.suisung.mall.common.feignService.AccountService;
|
||||
import com.suisung.mall.common.modules.base.ShopBaseProductSpec;
|
||||
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||
import com.suisung.mall.common.modules.number.ShopNumberSeq;
|
||||
import com.suisung.mall.common.modules.product.ShopProductSpecItem;
|
||||
import com.suisung.mall.core.web.service.RedisService;
|
||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||
import com.suisung.mall.shop.base.service.ShopBaseProductSpecService;
|
||||
import com.suisung.mall.shop.library.service.LibraryProductService;
|
||||
import com.suisung.mall.shop.number.mapper.ShopNumberSeqMapper;
|
||||
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||
import com.suisung.mall.shop.product.service.ShopProductSpecItemService;
|
||||
@ -52,6 +54,9 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
||||
@Autowired
|
||||
private AccountService accountService;
|
||||
|
||||
@Autowired
|
||||
private LibraryProductService libraryProductService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.printf(IntStream.rangeClosed(1, 1).boxed().collect(Collectors.toList()).toString());
|
||||
}
|
||||
@ -337,4 +342,39 @@ public class ShopNumberSeqServiceImpl extends BaseServiceImpl<ShopNumberSeqMappe
|
||||
return IntStream.rangeClosed(start + 1, start + batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存的是最大值,取的是范围,如存最大值1,批量是2,则取范围【1+1,1+2】,如果没有则从1开始算即取范围[0+1,0+2]
|
||||
*
|
||||
* @param batchSize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public synchronized List<Integer> getBatchLibraryProductId(int batchSize) {
|
||||
int start = 0;
|
||||
if (null != redisService.get(RedisKey.STOREDATALIBRARYID)) {
|
||||
start = (Integer) redisService.get(RedisKey.STOREDATALIBRARYID);
|
||||
redisService.set(RedisKey.STOREDATALIBRARYID, start + batchSize);
|
||||
return IntStream.rangeClosed(start + 1, start + batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
QueryWrapper<LibraryProduct> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("max(id) as id");
|
||||
LibraryProduct libraryProduct = libraryProductService.getOne(queryWrapper);
|
||||
if (null != libraryProduct) {
|
||||
start = Math.toIntExact(libraryProduct.getId());
|
||||
redisService.set(RedisKey.STOREDATALIBRARYID, start + batchSize);
|
||||
}
|
||||
if (start == 0) {
|
||||
redisService.set(RedisKey.STOREDATALIBRARYID, start + batchSize);
|
||||
return IntStream.rangeClosed(start + 1, start + batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
return IntStream.rangeClosed(start + 1, start + batchSize).boxed().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearKeyLibraryProductId() {
|
||||
redisService.del(RedisKey.STOREDATALIBRARYID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -36,4 +36,10 @@ public interface ShopProductBaseMapper extends BaseMapper<ShopProductBase> {
|
||||
*/
|
||||
Map getProductBasicInfo(@Param("product_id") Long product_id, @Param("store_id") Integer store_id);
|
||||
|
||||
|
||||
int countFindMapping(@Param("storeId") Integer storeId);
|
||||
|
||||
List<ShopProductBase> findPageMapping(@Param("storeId") Integer storeId, @Param("offset") Integer offset, @Param("limit") Integer limit);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -301,4 +301,7 @@ public interface ShopProductBaseService extends IBaseService<ShopProductBase> {
|
||||
Map<String, Long> getProductBasicIdByStore(Integer store_id, List<String> productNumberList);
|
||||
|
||||
|
||||
int countFindMapping(Integer store_id);
|
||||
|
||||
List<ShopProductBase> findPageMapping(Integer store_id, Integer pageNum, Integer pageSize);
|
||||
}
|
||||
|
||||
@ -6449,4 +6449,16 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int countFindMapping(Integer store_id) {
|
||||
return shopProductBaseMapper.countFindMapping(store_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopProductBase> findPageMapping(Integer store_id, Integer pageNum, Integer pageSize) {
|
||||
return shopProductBaseMapper.findPageMapping(store_id,(pageNum-1)*pageSize,pageSize);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class ShopProductSpecItemServiceImpl extends BaseServiceImpl<ShopProductS
|
||||
queryWrapper.eq("store_id",storeId);
|
||||
List<ShopProductSpecItem> list= list(queryWrapper);
|
||||
for(ShopProductSpecItem shopProductSpecItem:list){
|
||||
map.put(shopProductSpecItem.getSpec_item_name(),shopProductSpecItem.getSpec_item_id());
|
||||
map.put(shopProductSpecItem.getSpec_item_name()+"_"+shopProductSpecItem.getCategory_id(),shopProductSpecItem.getSpec_item_id());
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
@ -11,28 +11,32 @@ public class ProductMappingExcel {
|
||||
@ExcelProperty(value = "商品名称", index = 0)
|
||||
private String productName;
|
||||
|
||||
@ExcelProperty(value = "店铺编号", index = 1)
|
||||
@ExcelProperty(value = "商品货号", index = 1)
|
||||
private String productNumber;
|
||||
|
||||
@ExcelProperty(value = "店铺编号", index = 2)
|
||||
private Integer storeId;
|
||||
|
||||
@ExcelProperty(value = "店铺名称", index = 2)
|
||||
@ExcelProperty(value = "店铺名称", index = 3)
|
||||
private String storeName;
|
||||
|
||||
@ExcelProperty(value = "规格数据", index = 3)
|
||||
@ExcelProperty(value = "规格数据", index = 4)
|
||||
private BigDecimal specValue;
|
||||
|
||||
@ExcelProperty(value = "规格单位", index = 4)
|
||||
@ExcelProperty(value = "规格单位", index = 5)
|
||||
private String specUnit;
|
||||
|
||||
@ExcelProperty(value = "商品描述", index = 5)
|
||||
@ExcelProperty(value = "商品描述", index = 6)
|
||||
private String description;
|
||||
|
||||
@ExcelProperty(value = "排序值", index = 6)
|
||||
@ExcelProperty(value = "排序值", index = 7)
|
||||
private Integer sortOrder;
|
||||
|
||||
// 转换为实体对象
|
||||
public ProductMapping toEntity() {
|
||||
ProductMapping entity = new ProductMapping();
|
||||
entity.setProductName(this.productName);
|
||||
entity.setProductNumber(this.productNumber);
|
||||
entity.setStoreId(this.storeId);
|
||||
entity.setStoreName(this.storeName);
|
||||
entity.setSpecValue(this.specValue);
|
||||
@ -46,6 +50,7 @@ public class ProductMappingExcel {
|
||||
public static ProductMappingExcel fromEntity(ProductMapping entity) {
|
||||
ProductMappingExcel excel = new ProductMappingExcel();
|
||||
excel.setProductName(entity.getProductName());
|
||||
excel.setProductNumber(entity.getProductNumber());
|
||||
excel.setStoreId(entity.getStoreId());
|
||||
excel.setStoreName(entity.getStoreName());
|
||||
excel.setSpecValue(entity.getSpecValue());
|
||||
@ -59,8 +64,9 @@ public class ProductMappingExcel {
|
||||
* 生成唯一键:productName + storeId + specValue + specUnit
|
||||
*/
|
||||
public String getUniqueKey() {
|
||||
return String.format("%s|%d|%s|%s",
|
||||
return String.format("%s|%s|%d|%s|%s",
|
||||
productName,
|
||||
productNumber,
|
||||
storeId,
|
||||
specValue.stripTrailingZeros().toPlainString(),
|
||||
specUnit);
|
||||
|
||||
@ -23,4 +23,7 @@ public class RedisKey {
|
||||
|
||||
|
||||
public static final String STOREDATASPECID="storedata:SpecId";
|
||||
|
||||
|
||||
public static final String STOREDATALIBRARYID="storedata:libraryId";
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ public interface ProductMappingService extends IBaseService<ProductMapping> {
|
||||
* @param isUpdate
|
||||
*/
|
||||
void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,
|
||||
Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,
|
||||
Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map<String,ProductMapping> productMappingMap,
|
||||
boolean isUpdate,String isPubish);
|
||||
|
||||
Map getProductMapping(Integer storeId);
|
||||
|
||||
@ -67,9 +67,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@ -113,6 +110,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@Override
|
||||
public CommonResult findPageProductMapping(ProductMapping productMapping,Integer pageNum,Integer pageSize) {
|
||||
QueryWrapper<ProductMapping> queryWrapper = new QueryWrapper<>();
|
||||
@ -129,7 +127,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeProductMapping(List<ShopProductBase> shopProductBaseList,Integer storeId,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdate,String isPubish) {
|
||||
public void computeProductMapping(List<ShopProductBase> shopProductBaseList, Integer storeId, Map shopProductSpecItemMap, Map ShopBaseProductSpecMap, Map<String,ProductMapping> productMappingMap, boolean isUpdate, String isPubish) {
|
||||
shopProductBaseList= shopProductBaseList.stream().filter(base ->ObjectUtil.isNotEmpty(base.getUnit_name())).collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(shopProductBaseList)) {
|
||||
log.info("没有规格数据要处理");
|
||||
@ -146,11 +144,59 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
queryWrapper.and(m->m.eq("store_id",storeId).or().eq("store_id",0)).orderByDesc("sort_order");
|
||||
List<ProductMapping> list= this.list(queryWrapper);
|
||||
for (ProductMapping productMapping:list){
|
||||
map.put(productMapping.getProductName(),productMapping);
|
||||
map.put(productMapping.getProductNumber(),productMapping);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理规格数据
|
||||
* @param shopProductSpecItemMap
|
||||
* @param ShopBaseProductSpecMap
|
||||
* @param productMappingMap
|
||||
*/
|
||||
public void saveProductSpecItem(Map shopProductSpecItemMap,Map ShopBaseProductSpecMap,Map<String,ProductMapping> productMappingMap,Map<String,Integer> shopProductItemCategoryIdMap){
|
||||
List<ShopProductSpecItem> addShopProductSpecItemList=new ArrayList<>();
|
||||
List<ShopProductSpecItem> finalAddShopProductSpecItemList = addShopProductSpecItemList;
|
||||
productMappingMap.forEach((k, productMapping)->{
|
||||
Integer categoryId=shopProductItemCategoryIdMap.get(k);
|
||||
if(categoryId==null){
|
||||
return;
|
||||
}
|
||||
ShopBaseProductSpec shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(categoryId);
|
||||
ShopProductSpecItem addShopProductSpecItem=new ShopProductSpecItem();
|
||||
if(null==shopBaseProductSpec){
|
||||
shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(String.valueOf(categoryId));
|
||||
}
|
||||
String Spec_item_name=BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
|
||||
String Spec_item_name_categoryId=Spec_item_name+"_"+categoryId;//存在的item
|
||||
if(ObjectUtil.isNotEmpty(shopProductSpecItemMap.get(Spec_item_name_categoryId))){
|
||||
return;
|
||||
}
|
||||
Integer specId= shopBaseProductSpec.getSpec_id();
|
||||
addShopProductSpecItem.setStore_id(productMapping.getStoreId());
|
||||
addShopProductSpecItem.setCategory_id(categoryId);
|
||||
addShopProductSpecItem.setSpec_id(specId);//根据规格获取
|
||||
addShopProductSpecItem.setSpec_item_name(Spec_item_name);
|
||||
addShopProductSpecItem.setSpec_item_enable(1);//上架
|
||||
addShopProductSpecItem.setSpec_item_order(String.valueOf(productMapping.getSortOrder()));
|
||||
finalAddShopProductSpecItemList.add(addShopProductSpecItem);
|
||||
});
|
||||
if(!finalAddShopProductSpecItemList.isEmpty()){
|
||||
//去重
|
||||
addShopProductSpecItemList=com.suisung.mall.common.utils.CommonUtil.distinctByTwoFields(addShopProductSpecItemList,ShopProductSpecItem::getSpec_item_name,ShopProductSpecItem::getCategory_id);
|
||||
|
||||
List<Integer> integers= shopNumberSeqService.getBatchSpecItemId(addShopProductSpecItemList.size());
|
||||
for (int i = 0; i < addShopProductSpecItemList.size(); i++){
|
||||
addShopProductSpecItemList.get(i).setSpec_item_id(integers.get(i));
|
||||
}
|
||||
if(!addShopProductSpecItemList.isEmpty()){
|
||||
shopProductSpecItemService.saveBatch(addShopProductSpecItemList,addShopProductSpecItemList.size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据,生成规格列表
|
||||
* @param shopProductBaseList
|
||||
@ -158,10 +204,18 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
* @param ShopBaseProductSpecMap
|
||||
* @param productMappingMap
|
||||
*/
|
||||
public void dealData(List<ShopProductBase> shopProductBaseList,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,boolean isUpdate,String isPublish){
|
||||
@Transactional
|
||||
public void dealData(List<ShopProductBase> shopProductBaseList,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map<String,ProductMapping> productMappingMap,boolean isUpdate,String isPublish){
|
||||
List<ShopProductItem> shopProductItems=findShopProductItemsList(shopProductBaseList);
|
||||
Map<String,Integer> shopProductItemCategoryIdMap=new HashMap<>();
|
||||
shopProductItemCategoryIdMap=shopProductItems.stream().collect(Collectors.toMap(ShopProductItem::getItem_number,ShopProductItem::getCategory_id,
|
||||
(existingValue,newValue)->existingValue));
|
||||
saveProductSpecItem(shopProductSpecItemMap, ShopBaseProductSpecMap, productMappingMap,shopProductItemCategoryIdMap);//保存规格数据
|
||||
Set<String> item_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_spec_item"+ "*");
|
||||
redisService.del(item_keys);
|
||||
shopProductSpecItemMap= shopProductSpecItemService.getExistItem(shopProductBaseList.get(0).getStore_id());
|
||||
List<ShopProductInfo> shopProductInfoList=findShopProductInfoList(shopProductBaseList);
|
||||
List<ShopProductSpecItem> addShopProductSpecItemList=new ArrayList<>();
|
||||
// List<ShopProductSpecItem> addShopProductSpecItemList=new ArrayList<>();
|
||||
List<ShopProductSpecItem> updateShopProductSpecItemList=new ArrayList<>();
|
||||
|
||||
List<ShopProductBase> updateShopProductBaseList=new ArrayList<>();
|
||||
@ -171,7 +225,8 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
|
||||
//找出需要更新的列表
|
||||
for (int i = 0; i < shopProductBaseList.size(); i++){
|
||||
ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,null);
|
||||
ShopProductBase shopProductBase=shopProductBaseList.get(i);
|
||||
ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBase,shopProductItemCategoryIdMap.get(shopProductBase.getProduct_number()),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,null);
|
||||
if(shopProductSpecItem!=null){
|
||||
ShopProductIndex shopProductIndex=new ShopProductIndex();
|
||||
shopProductIndex.setProduct_id(shopProductBaseList.get(i).getProduct_id());
|
||||
@ -197,11 +252,12 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
if(shopProductSpecItem.isUpdate()){
|
||||
shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice());
|
||||
updateShopProductSpecItemList.add(shopProductSpecItem);
|
||||
}else {
|
||||
shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice());
|
||||
shopProductBaseList.get(i).setProduct_market_price(shopProductSpecItem.getItemPrice());
|
||||
addShopProductSpecItemList.add(shopProductSpecItem);
|
||||
}
|
||||
// else {
|
||||
// shopProductBaseList.get(i).setProduct_unit_price(shopProductSpecItem.getItemPrice());
|
||||
// shopProductBaseList.get(i).setProduct_market_price(shopProductSpecItem.getItemPrice());
|
||||
// addShopProductSpecItemList.add(shopProductSpecItem);
|
||||
// }
|
||||
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
|
||||
shopProductBaseList.get(i).setProduct_unit_price(shopProductItems.get(i).getItem_unit_price());
|
||||
updateShopProductBaseList.add(shopProductBaseList.get(i));
|
||||
@ -212,27 +268,29 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
}
|
||||
}
|
||||
//再次变量根据addShopProductSpecItemList算出id,这样防止多次链接redis
|
||||
if(!addShopProductSpecItemList.isEmpty()){
|
||||
List<Integer> integers= shopNumberSeqService.getBatchSpecItemId(addShopProductSpecItemList.size());
|
||||
int index=0;
|
||||
for (int i = 0; i < shopProductBaseList.size(); i++){
|
||||
if(index==integers.size()){
|
||||
break;
|
||||
}
|
||||
ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,integers.get(index));
|
||||
if(shopProductSpecItem!=null){
|
||||
if(!shopProductSpecItem.isUpdate()){
|
||||
addShopProductSpecItemList.set(index,shopProductSpecItem);
|
||||
index++;
|
||||
}
|
||||
proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(!addShopProductSpecItemList.isEmpty()){
|
||||
// //去重
|
||||
// addShopProductSpecItemList= addShopProductSpecItemList.stream().filter(com.suisung.mall.common.utils.CommonUtil.distinctByKey(ShopProductSpecItem::getSpec_item_name)).collect(Collectors.toList());
|
||||
// List<Integer> integers= shopNumberSeqService.getBatchSpecItemId(addShopProductSpecItemList.size());
|
||||
// int index=0;
|
||||
// for (int i = 0; i < shopProductBaseList.size(); i++){
|
||||
// if(index==integers.size()){
|
||||
// break;
|
||||
// }
|
||||
// ShopProductSpecItem shopProductSpecItem=processShopProductSpecItem(shopProductBaseList.get(i),shopProductItems.get(i).getCategory_id(),shopProductSpecItemMap,ShopBaseProductSpecMap,productMappingMap,integers.get(index));
|
||||
// if(shopProductSpecItem!=null){
|
||||
// if(!shopProductSpecItem.isUpdate()){
|
||||
// addShopProductSpecItemList.set(index,shopProductSpecItem);
|
||||
// index++;
|
||||
// }
|
||||
// proccessItemAndInfo(shopProductItems.get(i),shopProductInfoList.get(i),shopProductSpecItem,isUpdate);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if(CollUtil.isNotEmpty(addShopProductSpecItemList)){
|
||||
shopProductSpecItemService.saveBatch(addShopProductSpecItemList,addShopProductSpecItemList.size());
|
||||
}
|
||||
// if(CollUtil.isNotEmpty(addShopProductSpecItemList)){
|
||||
// shopProductSpecItemService.saveBatch(addShopProductSpecItemList,addShopProductSpecItemList.size());
|
||||
// }
|
||||
synchronized (this){
|
||||
if(CollUtil.isNotEmpty(updateShopProductSpecItemList)){
|
||||
shopProductSpecItemService.updateBatchById(updateShopProductSpecItemList,updateShopProductSpecItemList.size());
|
||||
@ -351,29 +409,32 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
* @return
|
||||
*/
|
||||
private ShopProductSpecItem processShopProductSpecItem(ShopProductBase base,Integer categoryId,Map shopProductSpecItemMap,Map ShopBaseProductSpecMap, Map productMappingMap,Integer specItemId){
|
||||
String productName=base.getProduct_name();
|
||||
if(null!=productMappingMap.get(productName)){
|
||||
String productNumber=base.getProduct_number();
|
||||
if(null!=productMappingMap.get(productNumber)){
|
||||
ShopBaseProductSpec shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(categoryId);
|
||||
if(null==shopBaseProductSpec){
|
||||
shopBaseProductSpec= (ShopBaseProductSpec) ShopBaseProductSpecMap.get(String.valueOf(categoryId));
|
||||
}
|
||||
Integer specId= shopBaseProductSpec.getSpec_id();
|
||||
ShopProductSpecItem addShopProductSpecItem=new ShopProductSpecItem();
|
||||
ProductMapping productMapping= (ProductMapping) productMappingMap.get(productName);
|
||||
String Spec_item_name=productMapping.getProductName()+ BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
|
||||
ProductMapping productMapping= (ProductMapping) productMappingMap.get(productNumber);
|
||||
//String Spec_item_name=productMapping.getProductName()+ BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
|
||||
String Spec_item_name=BigDecimalFormatter.formatWithoutTrailingZeros(productMapping.getSpecValue())+productMapping.getSpecUnit();
|
||||
//计算价格
|
||||
BigDecimal[] bigDecimals= ProductPriceCalculator.calculatePriceAndQuantity(base.getUnit_price(),base.getShop_weight(),productMapping.getSpecValue(),productMapping.getSpecUnit());
|
||||
addShopProductSpecItem.setItemPrice(bigDecimals[0]);
|
||||
addShopProductSpecItem.setItemQuantity(bigDecimals[1]);
|
||||
Integer Spec_item_id = null;
|
||||
addShopProductSpecItem.setUpdate(true);
|
||||
if(ObjectUtil.isNotEmpty(shopProductSpecItemMap.get(Spec_item_name))){
|
||||
Spec_item_id= (Integer) shopProductSpecItemMap.get(Spec_item_name);
|
||||
String Spec_item_name_categoryId=Spec_item_name+"_"+categoryId;//存在的item
|
||||
if(ObjectUtil.isNotEmpty(shopProductSpecItemMap.get(Spec_item_name_categoryId))){
|
||||
Spec_item_id= (Integer) shopProductSpecItemMap.get(Spec_item_name_categoryId);
|
||||
}else {
|
||||
if(ObjectUtil.isNotEmpty(specItemId)){
|
||||
Spec_item_id=specItemId;
|
||||
}
|
||||
addShopProductSpecItem.setUpdate(false);
|
||||
return null;
|
||||
// if(ObjectUtil.isNotEmpty(specItemId)){
|
||||
// Spec_item_id=specItemId;
|
||||
// }
|
||||
// addShopProductSpecItem.setUpdate(false);
|
||||
}
|
||||
addShopProductSpecItem.setStore_id(base.getStore_id());
|
||||
addShopProductSpecItem.setCategory_id(categoryId);
|
||||
@ -405,6 +466,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
|
||||
@Override
|
||||
public CommonResult syncAllProductMapping(Integer storeId,String isPublish) {
|
||||
clearCacheData();
|
||||
if(ObjectUtil.isEmpty(storeId)){
|
||||
storeId= Integer.valueOf(Objects.requireNonNull(ContextUtil.getCurrentUser()).getStore_id());
|
||||
}
|
||||
@ -419,39 +481,44 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
return CommonResult.failed("请设置优先方式为自动更新");
|
||||
}
|
||||
//找出范围内的规格产品
|
||||
QueryWrapper<ShopProductBase> queryWrapper= new QueryWrapper<>();
|
||||
queryWrapper.eq("product_state_id", StateCode.PRODUCT_STATE_OFF_THE_SHELF_UNCHECK);
|
||||
queryWrapper.eq("store_id", storeId);
|
||||
queryWrapper.gt("unit_price", BigDecimal.ZERO);
|
||||
queryWrapper.orderByAsc("product_id");
|
||||
long total=shopProductBaseService.count(queryWrapper);
|
||||
int total = shopProductBaseService.countFindMapping(storeId);
|
||||
|
||||
int pages= CommonUtil.getPagesCount(Math.toIntExact(total),SHOPBASEPAGE);
|
||||
int pages= CommonUtil.getPagesCount(total,SHOPBASEPAGE);
|
||||
//ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
//List<Future<?>> futures = new ArrayList<>();
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
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;
|
||||
Integer finalStoreId = storeId;
|
||||
List<ShopProductBase> shopProductBaseList=shopProductBaseService.lists(queryWrapper, finalI,SHOPBASEPAGE).getRecords();
|
||||
futures.add(executor.submit(() -> {
|
||||
this.computeProductMapping(shopProductBaseList, finalStoreId,shopProductSpecItemMap,ShopBaseProductSpecMap, productMappingMap,isUpDatePrice,isPublish);
|
||||
return "成功" + finalI;
|
||||
}));
|
||||
//int finalI = i;
|
||||
// Integer finalStoreId = storeId;
|
||||
Map<String,Integer> shopProductSpecItemMap = shopProductSpecItemService.getExistItem(storeId);
|
||||
List<ShopProductBase> shopProductBaseList=shopProductBaseService.findPageMapping(storeId,i,SHOPBASEPAGE);
|
||||
//List<ShopProductBase> shopProductBaseList=shopProductBaseService.lists(queryWrapper, i,SHOPBASEPAGE).getRecords();
|
||||
// futures.add(executor.submit(() -> {
|
||||
this.computeProductMapping(shopProductBaseList, i,shopProductSpecItemMap,ShopBaseProductSpecMap, productMappingMap,isUpDatePrice,isPublish);
|
||||
// return "成功" + finalI;
|
||||
// }));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<?> future : futures) {
|
||||
try {
|
||||
System.out.println("任务结果: " + future.get());
|
||||
} catch (Exception e) {
|
||||
System.err.println("任务执行异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
executor.shutdown();
|
||||
// for (Future<?> future : futures) {
|
||||
// try {
|
||||
// System.out.println("任务结果: " + future.get());
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("任务执行异常: " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// executor.shutdown();
|
||||
log.info("--------批量匹配规格结束-----");
|
||||
clearCacheData();
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存数据
|
||||
*/
|
||||
private void clearCacheData(){
|
||||
shopNumberSeqService.clearKeyStoreItemSepcId();
|
||||
Set<String> item_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_item"+ "*");
|
||||
redisService.del(item_keys);
|
||||
@ -461,7 +528,7 @@ public class ProductMappingServiceImpl extends BaseServiceImpl<ProductMappingMap
|
||||
redisService.del(index_keys);
|
||||
Set<String> info_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"shop_product_info"+ "*");
|
||||
redisService.del(info_keys);
|
||||
return CommonResult.success(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -2,6 +2,17 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.suisung.mall.shop.product.mapper.ShopProductBaseMapper">
|
||||
|
||||
<resultMap id="shopProductBaseMap" type="com.suisung.mall.common.modules.product.ShopProductBase">
|
||||
<id property="product_id" column="product_id" />
|
||||
<result property="product_name" column="product_name" />
|
||||
<result property="product_number" column="product_number" />
|
||||
<result property="store_id" column="store_id" />
|
||||
<result property="store_name" column="store_name" />
|
||||
<result property="unit_price" column="unit_price" />
|
||||
<result property="shop_weight" column="shop_weight" />
|
||||
<result property="unit_name" column="unit_name" />
|
||||
</resultMap>
|
||||
|
||||
<select id="listItem" resultType="java.lang.Long">
|
||||
|
||||
SELECT
|
||||
@ -74,4 +85,18 @@
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="countFindMapping" resultType="java.lang.Integer">
|
||||
SELECT count(1) from shop_product_base spb
|
||||
inner join
|
||||
product_mapping pm on spb.product_number =pm.product_number and spb.store_id=pm.store_id
|
||||
where spb.store_id =#{storeId} and spb.product_state_id=1003 and unit_price>0
|
||||
</select>
|
||||
|
||||
<select id="findPageMapping" resultMap="shopProductBaseMap">
|
||||
SELECT spb.* from shop_product_base spb
|
||||
inner join
|
||||
product_mapping pm on spb.product_number =pm.product_number and spb.store_id=pm.store_id
|
||||
where spb.store_id =#{storeId} and spb.product_state_id=1003 and unit_price>0 order by spb.product_id asc limit #{offset},#{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@ -229,7 +229,7 @@
|
||||
</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 product_id,store_id,item_id,item_unit_price,item_unit_price,item_market_price,category_id,item_number 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
|
||||
|
||||
1
sql/shop/dev/20251016_ddl.sql
Normal file
1
sql/shop/dev/20251016_ddl.sql
Normal file
@ -0,0 +1 @@
|
||||
alter table product_mapping add column product_number varchar(50) not null default 1 comment '商品货架号';
|
||||
Loading…
Reference in New Issue
Block a user