Merge remote-tracking branch 'origin/main'
# Conflicts: # mall-shop/src/main/java/com/suisung/mall/shop/sync/keymanage/RedisKey.java
This commit is contained in:
commit
da771d42f7
@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@ -32,6 +33,7 @@ public class LibraryProduct implements Serializable {
|
|||||||
private String sname;
|
private String sname;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品标题", example = "小米12 Pro")
|
@ApiModelProperty(value = "商品标题", example = "小米12 Pro")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@ApiModelProperty(value = "条形码/Barcode", example = "6923450657713")
|
@ApiModelProperty(value = "条形码/Barcode", example = "6923450657713")
|
||||||
@ -39,9 +41,11 @@ public class LibraryProduct implements Serializable {
|
|||||||
private String barcode;
|
private String barcode;
|
||||||
|
|
||||||
@ApiModelProperty(value = "第一级分类", example = "生鲜")
|
@ApiModelProperty(value = "第一级分类", example = "生鲜")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String category_1st;
|
private String category_1st;
|
||||||
|
|
||||||
@ApiModelProperty(value = "第二级分类", example = "牛肉")
|
@ApiModelProperty(value = "第二级分类", example = "牛肉")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String category_2nd;
|
private String category_2nd;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品分类", example = "牛肉")
|
@ApiModelProperty(value = "商品分类", example = "牛肉")
|
||||||
@ -94,4 +98,11 @@ public class LibraryProduct implements Serializable {
|
|||||||
@ApiModelProperty(value = "更新时间", example = "2023-01-02 15:30:00")
|
@ApiModelProperty(value = "更新时间", example = "2023-01-02 15:30:00")
|
||||||
@TableField(value = "updated_at")
|
@TableField(value = "updated_at")
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
|
|
||||||
|
// @ApiModelProperty(value = "来源ID", example = "vendor_001")
|
||||||
|
// @TableField(value = "product_short_name", updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
|
// private String productShortName;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<LibraryProductImage> product_image_list;
|
||||||
}
|
}
|
||||||
@ -9,6 +9,7 @@
|
|||||||
package com.suisung.mall.common.modules.library;
|
package com.suisung.mall.common.modules.library;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
@ -34,13 +35,16 @@ public class LibraryProductImage implements Serializable {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品ID", position = 2, example = "1001")
|
@ApiModelProperty(value = "商品ID", position = 2, example = "1001")
|
||||||
|
@TableField(value = "product_id")
|
||||||
private Long productId;
|
private Long productId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "图片地址", position = 3,
|
@ApiModelProperty(value = "图片地址", position = 3,
|
||||||
example = "/media/images/product/1001.jpg")
|
example = "/media/images/product/1001.jpg")
|
||||||
|
@TableField(value = "image_url")
|
||||||
private String imageUrl;
|
private String imageUrl;
|
||||||
|
|
||||||
@ApiModelProperty(value = "是否主图 1-主图 0-副图", position = 4, example = "1")
|
@ApiModelProperty(value = "是否主图 1-主图 0-副图", position = 4, example = "1")
|
||||||
|
@TableField(value = "is_main")
|
||||||
private Boolean isMain;
|
private Boolean isMain;
|
||||||
|
|
||||||
@ApiModelProperty(value = "排序值,越小越前面", position = 5, example = "10")
|
@ApiModelProperty(value = "排序值,越小越前面", position = 5, example = "10")
|
||||||
@ -50,8 +54,10 @@ public class LibraryProductImage implements Serializable {
|
|||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间", position = 7, example = "2023-01-01 12:30:00")
|
@ApiModelProperty(value = "创建时间", position = 7, example = "2023-01-01 12:30:00")
|
||||||
|
@TableField(value = "created_at")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
|
|
||||||
@ApiModelProperty(value = "更新时间", position = 8, example = "2023-01-01 13:15:00")
|
@ApiModelProperty(value = "更新时间", position = 8, example = "2023-01-01 13:15:00")
|
||||||
|
@TableField(value = "updated_at")
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
}
|
}
|
||||||
@ -80,6 +80,6 @@ public class ShopPageApp implements Serializable {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String tpl_label;
|
private String tpl_label;
|
||||||
|
|
||||||
@ApiModelProperty(value = "市场展示图片,用,隔开")
|
@ApiModelProperty(value = "市场展示图片,[{'imageUrl:'','description':''}")
|
||||||
private String app_market_images;
|
private String app_market_images;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,4 +142,8 @@ public class StoreDbConfig implements Serializable {
|
|||||||
@TableField(value = "automatic",updateStrategy = FieldStrategy.NOT_EMPTY)
|
@TableField(value = "automatic",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
@ApiModelProperty(value = "默认次日补全库存(思迅同步时配置)")
|
@ApiModelProperty(value = "默认次日补全库存(思迅同步时配置)")
|
||||||
private Integer automatic;
|
private Integer automatic;
|
||||||
|
|
||||||
|
@TableField(value = "client_version",updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
|
@ApiModelProperty(value = "客户端版本:1商云10,2商瑞9.7,3商祺")
|
||||||
|
private String clientVersion;
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ public class LibraryProductDTO implements Serializable {
|
|||||||
if (this.product_image_list != null) {
|
if (this.product_image_list != null) {
|
||||||
for (ProductImage image : this.product_image_list) {
|
for (ProductImage image : this.product_image_list) {
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
image.image_url = addDomainPrefix(imageDomain, image.getImage_url());
|
image.imageUrl = addDomainPrefix(imageDomain, image.getImageUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,9 +66,10 @@ public class LibraryProductDTO implements Serializable {
|
|||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@ApiModel(value = "商品库的商品图片", description = "商品库的商品图片")
|
@ApiModel(value = "商品库的商品图片", description = "商品库的商品图片")
|
||||||
public static class ProductImage implements Serializable {
|
public static class ProductImage implements Serializable {
|
||||||
private Long product_id;
|
private Long id;
|
||||||
private String image_url;
|
private Long productId;
|
||||||
private Integer is_main;
|
private String imageUrl;
|
||||||
|
private Integer isMain;
|
||||||
private Integer seq;
|
private Integer seq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,5 +8,8 @@
|
|||||||
|
|
||||||
package com.suisung.mall.shop.library.service;
|
package com.suisung.mall.shop.library.service;
|
||||||
|
|
||||||
public interface LibraryProductImageService {
|
import com.suisung.mall.common.modules.library.LibraryProductImage;
|
||||||
|
import com.suisung.mall.core.web.service.IBaseService;
|
||||||
|
|
||||||
|
public interface LibraryProductImageService extends IBaseService<LibraryProductImage> {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,4 +38,7 @@ public interface LibraryProductService extends IBaseService<LibraryProduct> {
|
|||||||
Page<LibraryProduct> findLibraryProductPage(Integer pageNum, Integer pageSize);
|
Page<LibraryProduct> findLibraryProductPage(Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products);
|
CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products);
|
||||||
|
|
||||||
|
|
||||||
|
CommonResult shopImportToLib(Integer storeId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,9 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2025. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
||||||
* Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
|
|
||||||
* Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
|
|
||||||
* Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
|
|
||||||
* Vestibulum commodo. Ut rhoncus gravida arcu.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.suisung.mall.shop.library.service.impl;
|
package com.suisung.mall.shop.library.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.suisung.mall.common.feignService.AccountService;
|
import com.suisung.mall.common.feignService.AccountService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
@ -18,25 +12,44 @@ import com.suisung.mall.common.api.CommonResult;
|
|||||||
import com.suisung.mall.common.domain.UserDto;
|
import com.suisung.mall.common.domain.UserDto;
|
||||||
import com.suisung.mall.common.exception.ApiException;
|
import com.suisung.mall.common.exception.ApiException;
|
||||||
import com.suisung.mall.common.modules.library.LibraryProduct;
|
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||||
|
import com.suisung.mall.common.modules.library.LibraryProductImage;
|
||||||
|
import com.suisung.mall.common.modules.product.ShopProductBase;
|
||||||
|
import com.suisung.mall.common.modules.product.ShopProductImage;
|
||||||
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
||||||
import com.suisung.mall.common.utils.ContextUtil;
|
import com.suisung.mall.common.utils.ContextUtil;
|
||||||
|
import com.suisung.mall.common.utils.FilePathUtils;
|
||||||
import com.suisung.mall.core.consts.ConstantRedis;
|
import com.suisung.mall.core.consts.ConstantRedis;
|
||||||
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;
|
||||||
import com.suisung.mall.shop.library.mapper.LibraryProductMapper;
|
import com.suisung.mall.shop.library.mapper.LibraryProductMapper;
|
||||||
|
import com.suisung.mall.shop.library.service.LibraryProductImageService;
|
||||||
import com.suisung.mall.shop.library.service.LibraryProductService;
|
import com.suisung.mall.shop.library.service.LibraryProductService;
|
||||||
|
import com.suisung.mall.shop.number.service.ShopNumberSeqService;
|
||||||
|
import com.suisung.mall.shop.page.service.OssService;
|
||||||
|
import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
||||||
|
import com.suisung.mall.shop.product.service.ShopProductImageService;
|
||||||
|
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.List;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional
|
||||||
public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, LibraryProduct> implements LibraryProductService {
|
public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, LibraryProduct> implements LibraryProductService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -49,6 +62,29 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ShopProductImageService shopProductImageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ShopProductBaseService shopProductBaseService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LibraryProductImageService libraryProductImageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ShopNumberSeqService shopNumberSeqService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PlatformTransactionManager transactionManager;
|
||||||
|
|
||||||
|
private final Integer limitSize = 300;
|
||||||
|
|
||||||
|
private final String LIBRARY_PATH="/media/images/goods_library/";//通用路径
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OssService ossService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 匹配商品
|
* 匹配商品
|
||||||
* 如果 barcode 匹配到数据,其他条件不会被匹配
|
* 如果 barcode 匹配到数据,其他条件不会被匹配
|
||||||
@ -109,8 +145,30 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
Page<LibraryProduct> page= this.lists(queryWrapper,pageNum, pageSize);
|
Page<LibraryProduct> page= this.lists(queryWrapper,pageNum, pageSize);
|
||||||
|
|
||||||
List<LibraryProduct> libraryProductList= page.getRecords();
|
List<LibraryProduct> libraryProductList= page.getRecords();
|
||||||
|
|
||||||
|
List<Long> libraryProductIds= libraryProductList.stream().map(LibraryProduct::getId).collect(Collectors.toList());
|
||||||
|
QueryWrapper<LibraryProductImage> queryWrapperImage = new QueryWrapper<>();
|
||||||
|
queryWrapperImage.in("product_id", libraryProductIds);
|
||||||
|
List<LibraryProductImage> libraryProductImageList= libraryProductImageService.list(queryWrapperImage);
|
||||||
|
|
||||||
|
Map<Long,List<LibraryProductImage>> listMap=new HashMap<>();
|
||||||
|
libraryProductImageList.forEach(libraryProductImage -> {
|
||||||
|
libraryProductImage.setImageUrl(staticDomain+libraryProductImage.getImageUrl());
|
||||||
|
List<LibraryProductImage> productImageList=listMap.get(libraryProductImage.getProductId());
|
||||||
|
if(null==productImageList){
|
||||||
|
productImageList=new ArrayList<>();
|
||||||
|
}
|
||||||
|
productImageList.add(libraryProductImage);
|
||||||
|
listMap.put(libraryProductImage.getProductId(),productImageList);
|
||||||
|
});
|
||||||
|
|
||||||
libraryProductList.forEach(libraryProduct->{
|
libraryProductList.forEach(libraryProduct->{
|
||||||
libraryProduct.setThumb(staticDomain+libraryProduct.getThumb());
|
libraryProduct.setThumb(staticDomain+libraryProduct.getThumb());
|
||||||
|
if(null==listMap.get(libraryProduct.getId())){
|
||||||
|
libraryProduct.setProduct_image_list(Collections.emptyList());
|
||||||
|
}else {
|
||||||
|
libraryProduct.setProduct_image_list(listMap.get(libraryProduct.getId()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
page.setRecords(libraryProductList);
|
page.setRecords(libraryProductList);
|
||||||
return page;
|
return page;
|
||||||
@ -131,6 +189,7 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
throw new ApiException("权限不足");
|
throw new ApiException("权限不足");
|
||||||
}
|
}
|
||||||
List<String> updateTableIds=new ArrayList<>();
|
List<String> updateTableIds=new ArrayList<>();
|
||||||
|
List<LibraryProductImage> updateProductImageList=new ArrayList<>();
|
||||||
products.forEach(product->{
|
products.forEach(product->{
|
||||||
if (null==product.getId()){
|
if (null==product.getId()){
|
||||||
throw new ApiException("id is null");
|
throw new ApiException("id is null");
|
||||||
@ -138,11 +197,26 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
LibraryProduct libraryProduct=new LibraryProduct();
|
LibraryProduct libraryProduct=new LibraryProduct();
|
||||||
libraryProduct.setId(product.getId());
|
libraryProduct.setId(product.getId());
|
||||||
libraryProduct.setName(product.getName());
|
libraryProduct.setName(product.getName());
|
||||||
|
libraryProduct.setThumb(product.getThumb());
|
||||||
libraryProduct.setBarcode(product.getBarcode());
|
libraryProduct.setBarcode(product.getBarcode());
|
||||||
|
if(null!=product.getProduct_image_list()&&!product.getProduct_image_list().isEmpty()){
|
||||||
|
for(LibraryProductDTO.ProductImage productImage: product.getProduct_image_list()){
|
||||||
|
LibraryProductImage libraryProductImage=new LibraryProductImage();
|
||||||
|
libraryProductImage.setId(productImage.getId());
|
||||||
|
libraryProductImage.setImageUrl(productImage.getImageUrl());
|
||||||
|
libraryProductImage.setProductId(productImage.getProductId());
|
||||||
|
updateProductImageList.add(libraryProductImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
updateProductList.add(libraryProduct);
|
updateProductList.add(libraryProduct);
|
||||||
updateTableIds.add(ConstantRedis.Cache_NameSpace+"library_product:"+product.getId());
|
updateTableIds.add(ConstantRedis.Cache_NameSpace+"library_product:"+product.getId());
|
||||||
});
|
});
|
||||||
boolean result=this.updateBatchById(updateProductList,updateProductList.size());
|
boolean result=this.updateBatchById(updateProductList,updateProductList.size());
|
||||||
|
|
||||||
|
if(!updateProductImageList.isEmpty()){
|
||||||
|
libraryProductImageService.updateBatchById(updateProductImageList,updateProductImageList.size());
|
||||||
|
}
|
||||||
|
|
||||||
if(result){
|
if(result){
|
||||||
redisService.del(updateTableIds);
|
redisService.del(updateTableIds);
|
||||||
return CommonResult.success("保存成功");
|
return CommonResult.success("保存成功");
|
||||||
@ -150,5 +224,255 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
return CommonResult.failed("保存失败");
|
return CommonResult.failed("保存失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从商品表导入上架的图片到图库
|
||||||
|
* 先同步路径字段,再复制文件
|
||||||
|
* @param storeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CommonResult shopImportToLib(Integer storeId) {
|
||||||
|
QueryWrapper<ShopProductBase> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("store_id", storeId);
|
||||||
|
queryWrapper.eq("product_state_id",1001);
|
||||||
|
long total= shopProductBaseService.count(queryWrapper);
|
||||||
|
if(total<0){
|
||||||
|
return CommonResult.failed("暂无同步数据");
|
||||||
|
}
|
||||||
|
int pages= CommonUtil.getPagesCount((int) total,limitSize);
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||||
|
List<Future<?>> futures = new ArrayList<>();
|
||||||
|
for (int i=1;i<=pages;i++){
|
||||||
|
List<ShopProductBase> shopProductBaseList= shopProductBaseService.lists(queryWrapper,i,limitSize).getRecords();
|
||||||
|
QueryWrapper<ShopProductImage> queryWrapper1 = new QueryWrapper<>();
|
||||||
|
Map<Long,ShopProductBase> shopProductBaseMap=new HashMap<>();
|
||||||
|
shopProductBaseList.forEach(m->{
|
||||||
|
shopProductBaseMap.put(m.getProduct_id(),m);
|
||||||
|
});
|
||||||
|
List<Long> productIds = shopProductBaseList.stream().map(ShopProductBase::getProduct_id).collect(Collectors.toList());
|
||||||
|
queryWrapper1.in("product_id",productIds);
|
||||||
|
List<ShopProductImage> shopProductImageList=shopProductImageService.list(queryWrapper1);
|
||||||
|
int finalI=i;
|
||||||
|
futures.add(executor.submit(() -> {
|
||||||
|
saveBatchLib(shopProductImageList,shopProductBaseMap);
|
||||||
|
return "成功" + finalI;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
// 等待所有任务完成
|
||||||
|
for (Future<?> future : futures) {
|
||||||
|
try {
|
||||||
|
log.info("同步图库任务结果: {}", future.get());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("同步图库任务执行异常: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
executor.shutdown();
|
||||||
|
copyToLib();//异步执行复制
|
||||||
|
return CommonResult.success("导入成功:路径复制中...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存到图库
|
||||||
|
* @param shopProductImageList
|
||||||
|
* @param shopProductBaseMap
|
||||||
|
*/
|
||||||
|
public void saveBatchLib(List<ShopProductImage> shopProductImageList,Map<Long,ShopProductBase> shopProductBaseMap){
|
||||||
|
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||||
|
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||||
|
transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
|
||||||
|
transactionTemplate.setTimeout(60); // 60秒超时
|
||||||
|
transactionTemplate.execute(status->{
|
||||||
|
try {
|
||||||
|
List<LibraryProduct> addLibraryProductList=new ArrayList<>();
|
||||||
|
List<LibraryProductImage> addLibraryProductImageList=new ArrayList<>();
|
||||||
|
Map<String,String> existMap=checkedIsExist(shopProductBaseMap);
|
||||||
|
List<ShopProductImage> filterShopProductImages = filterExistLibrary(shopProductImageList,shopProductBaseMap,existMap);
|
||||||
|
// redis获取id
|
||||||
|
List<Integer> libraryIds= shopNumberSeqService.getBatchLibraryProductId(filterShopProductImages.size());
|
||||||
|
for(int i=0;i<filterShopProductImages.size();i++){
|
||||||
|
ShopProductImage shopProductImage=filterShopProductImages.get(i);
|
||||||
|
ShopProductBase shopProductBase=shopProductBaseMap.get(shopProductImage.getProduct_id());
|
||||||
|
String key=shopProductBase.getProduct_number()+"_"+shopProductBase.getProduct_name();
|
||||||
|
if(existMap.containsKey(key)){//存在则去除
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String imageUrls=shopProductImage.getItem_image_default();
|
||||||
|
if(StringUtils.isEmpty(imageUrls)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String[] imageUrlArray=imageUrls.split(",");
|
||||||
|
LibraryProduct libraryProduct=new LibraryProduct();
|
||||||
|
long libraryProductId=Long.valueOf(libraryIds.get(i));
|
||||||
|
libraryProduct.setId(libraryProductId);
|
||||||
|
libraryProduct.setBarcode(shopProductBase.getProduct_number());
|
||||||
|
libraryProduct.setStatus(2);
|
||||||
|
libraryProduct.setName(shopProductBase.getProduct_name());
|
||||||
|
libraryProduct.setTitle(shopProductBase.getProduct_name());
|
||||||
|
//libraryProduct.setProductShortName(shopProductBase.getProduct_name());
|
||||||
|
|
||||||
|
libraryProduct.setThumb(imageUrlArray[0]);
|
||||||
|
libraryProduct.setSource("001");//本系统同步
|
||||||
|
libraryProduct.setPrice(shopProductBase.getProduct_unit_price());
|
||||||
|
addLibraryProductList.add(libraryProduct);
|
||||||
|
|
||||||
|
LibraryProductImage libraryProductImage=new LibraryProductImage();
|
||||||
|
libraryProductImage.setProductId(libraryProductId);
|
||||||
|
libraryProductImage.setStatus(2);
|
||||||
|
libraryProductImage.setImageUrl(imageUrlArray[0]);
|
||||||
|
libraryProductImage.setIsMain(true);
|
||||||
|
addLibraryProductImageList.add(libraryProductImage);
|
||||||
|
}
|
||||||
|
if(!addLibraryProductList.isEmpty()){
|
||||||
|
this.saveBatch(addLibraryProductList,addLibraryProductList.size());
|
||||||
|
}
|
||||||
|
if(!addLibraryProductImageList.isEmpty()){
|
||||||
|
libraryProductImageService.saveBatch(addLibraryProductImageList,addLibraryProductList.size());
|
||||||
|
}
|
||||||
|
return "成功";
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info("报错:{}",e.getMessage());
|
||||||
|
status.setRollbackOnly();
|
||||||
|
return "失败";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
log.info("商品保存成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量复制路径和数据
|
||||||
|
*/
|
||||||
|
@Async
|
||||||
|
public void copyToLib(){
|
||||||
|
clearCacheData();
|
||||||
|
QueryWrapper<LibraryProductImage> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("status",2);
|
||||||
|
long total=libraryProductImageService.count(queryWrapper);
|
||||||
|
if(total<0){
|
||||||
|
log.info("暂无同步数据");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Integer pages = CommonUtil.getPagesCount((int) total,limitSize);
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||||
|
List<Future<?>> futures = new ArrayList<>();
|
||||||
|
for (int i=1;i<=pages;i++){
|
||||||
|
int finalI=i;
|
||||||
|
List<LibraryProductImage> libraryProductImageList= libraryProductImageService.lists(queryWrapper,i,limitSize).getRecords();
|
||||||
|
futures.add(executor.submit(() -> {
|
||||||
|
cosCopyUrl(libraryProductImageList);
|
||||||
|
return "成功:"+finalI;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
for (Future<?> future : futures) {
|
||||||
|
try {
|
||||||
|
log.info("商品从店铺复制到图库成功:{}", future.get());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("商品从店铺复制到图库执行异常:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cos的文件复制
|
||||||
|
* @param libraryProductImageList
|
||||||
|
*/
|
||||||
|
public void cosCopyUrl(List<LibraryProductImage> libraryProductImageList){
|
||||||
|
// TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||||
|
// transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||||
|
// transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
|
||||||
|
// transactionTemplate.setTimeout(60); // 60秒超时
|
||||||
|
// transactionTemplate.execute(status->{
|
||||||
|
try {
|
||||||
|
|
||||||
|
List<LibraryProduct> updateLibraryProductList=new ArrayList<>();
|
||||||
|
List<LibraryProductImage> updateLibraryProductImagetList=new ArrayList<>();
|
||||||
|
for(LibraryProductImage libraryProductImage:libraryProductImageList){
|
||||||
|
//文件复制
|
||||||
|
FilePathUtils.FilePath filePath=new FilePathUtils().splitPathWithString(libraryProductImage.getImageUrl());
|
||||||
|
String ossTargetUrl=LIBRARY_PATH+ DateUtil.format(libraryProductImage.getCreatedAt(),"yyyyMMdd")+"/"+filePath.getFilename();
|
||||||
|
boolean result=ossService.copyFileUrl(filePath.getPath()+filePath.getFilename(),ossTargetUrl);
|
||||||
|
if (result){
|
||||||
|
LibraryProduct libraryProduct=new LibraryProduct();
|
||||||
|
libraryProduct.setId(libraryProductImage.getProductId());
|
||||||
|
libraryProduct.setThumb(ossTargetUrl);
|
||||||
|
libraryProduct.setStatus(1);
|
||||||
|
updateLibraryProductList.add(libraryProduct);
|
||||||
|
|
||||||
|
libraryProductImage.setProductId(libraryProduct.getId());
|
||||||
|
libraryProductImage.setStatus(1);
|
||||||
|
libraryProductImage.setImageUrl(ossTargetUrl);
|
||||||
|
updateLibraryProductImagetList.add(libraryProductImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!updateLibraryProductList.isEmpty()){//更新主图路径
|
||||||
|
this.updateBatchById(updateLibraryProductList,updateLibraryProductList.size());
|
||||||
|
}
|
||||||
|
if(!updateLibraryProductImagetList.isEmpty()){//更新副图路径
|
||||||
|
libraryProductImageService.updateBatchById(updateLibraryProductImagetList,updateLibraryProductImagetList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
//return "成功";
|
||||||
|
}catch (Exception e){
|
||||||
|
// status.setRollbackOnly();
|
||||||
|
log.info("处理数据异常:{}",e.getMessage());
|
||||||
|
//return "失败";
|
||||||
|
}
|
||||||
|
//});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验是否存在,存在则去除
|
||||||
|
* @param shopProductBaseMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Map<String,String> checkedIsExist(Map<Long,ShopProductBase> shopProductBaseMap){
|
||||||
|
QueryWrapper<LibraryProduct> queryWrapper = new QueryWrapper<>();
|
||||||
|
shopProductBaseMap.forEach((k,shopProductBase)->{
|
||||||
|
if(StringUtils.isNotEmpty(shopProductBase.getProduct_number())
|
||||||
|
&& StringUtils.isNotEmpty(shopProductBase.getProduct_name())){
|
||||||
|
queryWrapper.or(q->q.eq("barcode", shopProductBase.getProduct_number()).
|
||||||
|
eq("name",shopProductBase.getProduct_name()));
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(shopProductBase.getProduct_number())) {
|
||||||
|
queryWrapper.or(q->q.eq("name", shopProductBase.getProduct_name()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Map<String,String> resultMap=new HashMap<>();
|
||||||
|
List<LibraryProduct> libraryProducts= this.list(queryWrapper);
|
||||||
|
for(LibraryProduct libraryProduct:libraryProducts){
|
||||||
|
resultMap.put(libraryProduct.getBarcode()+"_"+libraryProduct.getName(),libraryProduct.getName());
|
||||||
|
}
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去除存在的图片
|
||||||
|
* @param shopProductImageList
|
||||||
|
* @param shopProductBaseMap
|
||||||
|
* @param existMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<ShopProductImage> filterExistLibrary(List<ShopProductImage> shopProductImageList,Map<Long,ShopProductBase> shopProductBaseMap, Map<String,String> existMap){
|
||||||
|
Iterator<ShopProductImage> iterator = shopProductImageList.iterator();
|
||||||
|
while(iterator.hasNext()){
|
||||||
|
ShopProductImage shopProductImage = iterator.next();
|
||||||
|
ShopProductBase shopProductBase=shopProductBaseMap.get(shopProductImage.getProduct_id());
|
||||||
|
String key=shopProductBase.getProduct_number()+"_"+shopProductBase.getProduct_name();
|
||||||
|
if(existMap.containsKey(key)){//存在则去除
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shopProductImageList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除缓存数据
|
||||||
|
*/
|
||||||
|
private void clearCacheData(){
|
||||||
|
Set<String> item_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"library_product_image"+ "*");
|
||||||
|
redisService.del(item_keys);
|
||||||
|
Set<String> base_keys = redisService.keys(ConstantRedis.Cache_NameSpace +"library_product"+ "*");
|
||||||
|
redisService.del(base_keys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -176,10 +176,30 @@ public class ShopPageAppController extends BaseControllerImpl {
|
|||||||
|
|
||||||
data.put("items", items);
|
data.put("items", items);
|
||||||
data.put("current_tpl", current_tpl);
|
data.put("current_tpl", current_tpl);
|
||||||
|
|
||||||
return CommonResult.success(data);
|
return CommonResult.success(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取空白的编辑app模版", notes = "获取空白的编辑app模版")
|
||||||
|
@RequestMapping(value = "/getBlankTpl", method = RequestMethod.GET)
|
||||||
|
public CommonResult getBlankTpl() {
|
||||||
|
UserDto user = ContextUtil.getCurrentUser();
|
||||||
|
if (user == null) {
|
||||||
|
throw new ApiUserException(I18nUtil._("用户信息异常!"));
|
||||||
|
}
|
||||||
|
Map blankTpl = new HashMap();
|
||||||
|
blankTpl.put("tpl_id",107);
|
||||||
|
blankTpl.put("tpl_label","shop7");
|
||||||
|
blankTpl.put("tpl_cat_name","");
|
||||||
|
blankTpl.put("tpl_name","DIY模板");
|
||||||
|
blankTpl.put("user_id",0);
|
||||||
|
blankTpl.put("tpl_buildin",0);
|
||||||
|
blankTpl.put("tpl_type",3);
|
||||||
|
blankTpl.put("tpl_image","https:\\/\\/static.shopsuite.cn\\/xcxfile\\/preview\\/diy.png");
|
||||||
|
blankTpl.put("app_id",0);
|
||||||
|
blankTpl.put("id",107);
|
||||||
|
return CommonResult.success(blankTpl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "店铺风格表-编辑app模版", notes = "店铺风格表-编辑app模版")
|
@ApiOperation(value = "店铺风格表-编辑app模版", notes = "店铺风格表-编辑app模版")
|
||||||
@RequestMapping(value = "/editApp", method = RequestMethod.GET)
|
@RequestMapping(value = "/editApp", method = RequestMethod.GET)
|
||||||
|
|||||||
@ -73,4 +73,5 @@ public interface OssService {
|
|||||||
*/
|
*/
|
||||||
COSObjectSummary findNewestFile(String folder);
|
COSObjectSummary findNewestFile(String folder);
|
||||||
|
|
||||||
|
boolean copyFileUrl(String s, String ossTargetUrl);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -666,4 +666,32 @@ public class OssServiceImpl implements OssService {
|
|||||||
return localFolder;
|
return localFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cos文件复制
|
||||||
|
* @param ossSourcUrl
|
||||||
|
* @param ossTargetUrl
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean copyFileUrl(String ossSourcUrl, String ossTargetUrl) {
|
||||||
|
int i=3;
|
||||||
|
while (i>0) {
|
||||||
|
try {
|
||||||
|
i--;
|
||||||
|
COSClient ossCli = initCOSClient();
|
||||||
|
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(
|
||||||
|
TENGXUN_BUCKET_NAME, ossSourcUrl, TENGXUN_BUCKET_NAME, ossTargetUrl);
|
||||||
|
CopyObjectResult result = ossCli.copyObject(copyObjectRequest);
|
||||||
|
return true;
|
||||||
|
//logger.info("文件复制成功:{}",ossTargetUrl);
|
||||||
|
//logger.info("result:{}",result);
|
||||||
|
}catch (Exception e){
|
||||||
|
if(i==0){
|
||||||
|
logger.error("腾讯云复制出错:{}",e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -4,31 +4,30 @@ public class RedisKey {
|
|||||||
|
|
||||||
//public static final String SXCLIENTKEYVERSION="sxclientKey:version";//客户端版本
|
//public static final String SXCLIENTKEYVERSION="sxclientKey:version";//客户端版本
|
||||||
|
|
||||||
public static final String STOREDATARELEASE = "shopQuality:release";
|
public static final String STOREDATARELEASE="shopQuality:release";
|
||||||
|
|
||||||
public static final String STOREDATAPRODUCTMAPING = "storedata:productMaping";
|
public static final String STOREDATAPRODUCTMAPING="storedata:productMaping";
|
||||||
|
|
||||||
public static final String STOREDATASHOPBASEPRODUCTSPEC = "storedata:shopBaseProductSpec";
|
public static final String STOREDATASHOPBASEPRODUCTSPEC="storedata:shopBaseProductSpec";
|
||||||
|
|
||||||
|
|
||||||
public static final String STOREDATASPECITEMID = "storedata:SpecItemId";
|
public static final String STOREDATASPECITEMID="storedata:SpecItemId";
|
||||||
|
|
||||||
public static final String STOREDATAPRODUCTSPECITEM = "storedata:ProductSpecItem";
|
public static final String STOREDATAPRODUCTSPECITEM="storedata:ProductSpecItem";
|
||||||
|
|
||||||
|
|
||||||
public static final String STOREDBDATAPRIORITYMODEKEY = "storedbdata:priorityModeKey";
|
public static final String STOREDBDATAPRIORITYMODEKEY="storedbdata:priorityModeKey";
|
||||||
|
|
||||||
|
|
||||||
public static final String STOREDATACCOUNTBASEID = "storedata:accountBaseId";
|
public static final String STOREDATACCOUNTBASEID="storedata:accountBaseId";
|
||||||
|
|
||||||
|
|
||||||
public static final String STOREDATASPECID = "storedata:SpecId";
|
public static final String STOREDATASPECID="storedata:SpecId";
|
||||||
|
|
||||||
|
|
||||||
public static final String STOREDATALIBRARYID = "storedata:libraryId";
|
public static final String STOREDATALIBRARYID="storedata:libraryId";
|
||||||
|
|
||||||
public static final String STOREDATAGOODBATCHLOCK = "store:data:goodsbatchLock";
|
public static final String STOREDATAGOODBATCHLOCK="store:data:goodsbatchLock";
|
||||||
|
|
||||||
|
public static final String STOREDATASHOPBASEPAGE="storedata:ShopBasePage";
|
||||||
public static final String STOREDATASHOPBASEPAGE = "store:data:shop:base:page";
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
sql/shop/dev/20251122_dml.sql
Normal file
1
sql/shop/dev/20251122_dml.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
alter table store_db_config add client_version char(10) NOT NULL DEFAULT '1' COMMENT '客户端版本:1商云10,2商瑞9.7,3商祺';
|
||||||
3
sql/shop/dev/20251124_ddl.sql
Normal file
3
sql/shop/dev/20251124_ddl.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/shop-page-app/getBlankTpl', 'index', 'master', '', '0', '/admin/shop/shop-page-app/getBlankTpl','dy空白模板');
|
||||||
|
update shop_page_app set app_market_images='[]';
|
||||||
|
alter table shop_page_app modify column app_market_images json COMMENT '市场展示图片';
|
||||||
Loading…
Reference in New Issue
Block a user