Authored by wangnan

fix

... ... @@ -23,498 +23,498 @@ import java.util.stream.Collectors;
*/
@Component
public class TblLogicService {
private final Logger logger = LoggerFactory.getLogger(ProductIndexLogicService.class);
private final Logger logger = LoggerFactory.getLogger(ProductIndexLogicService.class);
@Autowired
private TblProductService tblProductService;
@Autowired
private TblBrandService tblBrandService;
@Autowired
private TblProductSkcService tblProductSkcService;
@Autowired
private TblProductSkuService tblProductSkuService;
@Autowired
private TblSortService tblSortService;
@Autowired
private TblSiteService tblSiteService;
@Autowired
private TblImgUrlLogicService tblImgUrlLogicService;
@Autowired
private TblProductService tblProductService;
@Autowired
private TblBrandService tblBrandService;
@Autowired
private TblProductSkcService tblProductSkcService;
@Autowired
private TblProductSkuService tblProductSkuService;
@Autowired
private TblSortService tblSortService;
@Autowired
private TblSiteService tblSiteService;
@Autowired
private TblImgUrlLogicService tblImgUrlLogicService;
/**
* 全量构建
*
* @param start
* @param limit
* @return
*/
public List<ProductIndexBO> getProductIndex(int start, int limit) {
long begin = System.currentTimeMillis();
List<TblProduct> tblProducts = tblProductService.getPageLists(start, limit);
if (CollectionUtils.isEmpty(tblProducts)) {
return new ArrayList<ProductIndexBO>();
}
List<ProductIndexBO> productIndexBOS = buildProductIndex(tblProducts);
logger.info("tblProduct->productIndex构建完成,[size:{}],[cost: {}]", productIndexBOS.size(), System.currentTimeMillis() - begin);
return productIndexBOS;
}
/**
* 全量构建
*
* @param start
* @param limit
* @return
*/
public List<ProductIndexBO> getProductIndex(int start, int limit) {
long begin = System.currentTimeMillis();
List<TblProduct> tblProducts = tblProductService.getPageLists(start, limit);
if (CollectionUtils.isEmpty(tblProducts)) {
return new ArrayList<ProductIndexBO>();
}
List<ProductIndexBO> productIndexBOS = buildProductIndex(tblProducts);
logger.info("tblProduct->productIndex构建完成,[size:{}],[cost: {}]", productIndexBOS.size(), System.currentTimeMillis() - begin);
return productIndexBOS;
}
/**
* 增量构建
*
* @param skns
* @return
*/
public List<ProductIndexBO> getProductIndex(List<Integer> skns) {
long begin = System.currentTimeMillis();
List<TblProduct> tblProducts = tblProductService.getByskns(skns);
if (CollectionUtils.isEmpty(tblProducts)) {
return new ArrayList<ProductIndexBO>();
}
List<ProductIndexBO> productIndexBOS = buildProductIndex(tblProducts);
logger.info("tblProduct->productIndex构建完成,[size:{}],[cost: {}]", productIndexBOS.size(), System.currentTimeMillis() - begin);
return productIndexBOS;
}
/**
* 增量构建
*
* @param skns
* @return
*/
public List<ProductIndexBO> getProductIndex(List<Integer> skns) {
long begin = System.currentTimeMillis();
List<TblProduct> tblProducts = tblProductService.getByskns(skns);
if (CollectionUtils.isEmpty(tblProducts)) {
return new ArrayList<ProductIndexBO>();
}
List<ProductIndexBO> productIndexBOS = buildProductIndex(tblProducts);
logger.info("tblProduct->productIndex构建完成,[size:{}],[cost: {}]", productIndexBOS.size(), System.currentTimeMillis() - begin);
return productIndexBOS;
}
/**
* 构建ProductIndexBO
*
* @param tblProducts
* @return
*/
public List<ProductIndexBO> buildProductIndex(List<TblProduct> tblProducts) {
List<ProductIndexBO> productIndexBOs = new ArrayList<>();
// 获取brandMap
Map<Integer, TblBrand> brandMap = getBrandMap(tblProducts);
// 获取siteMap
Map<Integer, TblSite> siteMap = getSiteMap(tblProducts);
// 获取tblProductSkcMap
Map<Integer, List<TblProductSkc>> tblProductSkcMap = getTblProductSkcMap(tblProducts);
// 获取tblProductSkuMap
Map<Integer, List<TblProductSku>> tblProductSkuMap = getTblProductSkuMap(tblProducts);
// 获取sortMap
Map<Integer, String> sortMap = getSortMap();
// 生成ProductIndexBO
for (TblProduct tblProduct : tblProducts) {
ProductIndexBO productIndexBO = new ProductIndexBO();
// 全球购标识
productIndexBO.setIsGlobal("Y");
// 名称
productIndexBO.setProductName(tblProduct.getProductName());
// 特殊处理id,productId,productSkn
productIndexBO.setId(tblProduct.getProductSkn() * (-1));
productIndexBO.setProductId(tblProduct.getProductSkn());
productIndexBO.setProductSkn(tblProduct.getProductSkn());
// 处理品牌
TblBrand tblBrand = brandMap.get(tblProduct.getBrandId());
productIndexBO = processBrand(productIndexBO, tblBrand);
// 品类
productIndexBO = processSort(productIndexBO, sortMap, tblProduct);
// showStatus处理逻辑
productIndexBO = processShowStatus(productIndexBO, siteMap, tblProduct, tblBrand);
// 根据skc拼装 Goods color
productIndexBO = processGoods(tblProductSkcMap, productIndexBO, tblProduct);
// 根据sku拼装size
productIndexBO = processSize(tblProductSkuMap, productIndexBO, tblProduct);
// 其他字段
productIndexBO = processSimpleField(productIndexBO, tblProduct);
productIndexBOs.add(productIndexBO);
}
return productIndexBOs;
}
/**
* 构建ProductIndexBO
*
* @param tblProducts
* @return
*/
public List<ProductIndexBO> buildProductIndex(List<TblProduct> tblProducts) {
List<ProductIndexBO> productIndexBOs = new ArrayList<>();
// 获取brandMap
Map<Integer, TblBrand> brandMap = getBrandMap(tblProducts);
// 获取siteMap
Map<Integer, TblSite> siteMap = getSiteMap(tblProducts);
// 获取tblProductSkcMap
Map<Integer, List<TblProductSkc>> tblProductSkcMap = getTblProductSkcMap(tblProducts);
// 获取tblProductSkuMap
Map<Integer, List<TblProductSku>> tblProductSkuMap = getTblProductSkuMap(tblProducts);
// 获取sortMap
Map<Integer, String> sortMap = getSortMap();
// 生成ProductIndexBO
for (TblProduct tblProduct : tblProducts) {
ProductIndexBO productIndexBO = new ProductIndexBO();
// 全球购标识
productIndexBO.setIsGlobal("Y");
// 名称
productIndexBO.setProductName(tblProduct.getProductName());
// 特殊处理id,productId,productSkn
productIndexBO.setId(tblProduct.getProductSkn() * (-1));
productIndexBO.setProductId(tblProduct.getProductSkn());
productIndexBO.setProductSkn(tblProduct.getProductSkn());
// 处理品牌
TblBrand tblBrand = brandMap.get(tblProduct.getBrandId());
productIndexBO = processBrand(productIndexBO, tblBrand);
// 品类
productIndexBO = processSort(productIndexBO, sortMap, tblProduct);
// showStatus处理逻辑
productIndexBO = processShowStatus(productIndexBO, siteMap, tblProduct, tblBrand);
// 根据skc拼装 Goods color
productIndexBO = processGoods(tblProductSkcMap, productIndexBO, tblProduct);
// 根据sku拼装size
productIndexBO = processSize(tblProductSkuMap, productIndexBO, tblProduct);
// 其他字段
productIndexBO = processSimpleField(productIndexBO, tblProduct);
productIndexBOs.add(productIndexBO);
}
return productIndexBOs;
}
/**
* 获取品牌Map
*
* @param tblProducts
* @return
*/
private Map<Integer, TblBrand> getBrandMap(List<TblProduct> tblProducts) {
Map<Integer, TblBrand> brandMap = new HashMap<>();
List<Integer> brandIds = tblProducts.stream().map(TblProduct::getBrandId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(brandIds)) {
List<TblBrand> tblBrands = tblBrandService.selectByIds(brandIds);
if (CollectionUtils.isNotEmpty(tblBrands)) {
brandMap = tblBrands.stream().parallel().collect(Collectors.toMap(TblBrand::getBrandId, (p) -> p));
}
}
return brandMap;
}
/**
* 获取品牌Map
*
* @param tblProducts
* @return
*/
private Map<Integer, TblBrand> getBrandMap(List<TblProduct> tblProducts) {
Map<Integer, TblBrand> brandMap = new HashMap<>();
List<Integer> brandIds = tblProducts.stream().map(TblProduct::getBrandId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(brandIds)) {
List<TblBrand> tblBrands = tblBrandService.selectByIds(brandIds);
if (CollectionUtils.isNotEmpty(tblBrands)) {
brandMap = tblBrands.stream().parallel().collect(Collectors.toMap(TblBrand::getBrandId, (p) -> p));
}
}
return brandMap;
}
/**
* 获取SiteMap
*
* @param tblProducts
* @return
*/
private Map<Integer, TblSite> getSiteMap(List<TblProduct> tblProducts) {
Map<Integer, TblSite> siteMap = new HashMap<>();
List<Integer> siteId = tblProducts.stream().map(TblProduct::getSiteId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(siteId)) {
List<TblSite> tblSites = tblSiteService.getBySiteIds(siteId);
if (CollectionUtils.isNotEmpty(tblSites)) {
siteMap = tblSites.stream().parallel().collect(Collectors.toMap(TblSite::getSiteId, (p) -> p));
}
}
return siteMap;
}
/**
* 获取SiteMap
*
* @param tblProducts
* @return
*/
private Map<Integer, TblSite> getSiteMap(List<TblProduct> tblProducts) {
Map<Integer, TblSite> siteMap = new HashMap<>();
List<Integer> siteId = tblProducts.stream().map(TblProduct::getSiteId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(siteId)) {
List<TblSite> tblSites = tblSiteService.getBySiteIds(siteId);
if (CollectionUtils.isNotEmpty(tblSites)) {
siteMap = tblSites.stream().parallel().collect(Collectors.toMap(TblSite::getSiteId, (p) -> p));
}
}
return siteMap;
}
/**
* 获取TblProductSkcMap
*
* @param tblProducts
* @return
*/
private Map<Integer, List<TblProductSkc>> getTblProductSkcMap(List<TblProduct> tblProducts) {
Map<Integer, List<TblProductSkc>> tblProductSkcMap = new HashMap<>();
List<Integer> productSkns = tblProducts.stream().map(TblProduct::getProductSkn).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productSkns)) {
List<TblProductSkc> tblProductSkcs = tblProductSkcService.getBySkns(productSkns);
if (CollectionUtils.isNotEmpty(tblProductSkcs)) {
for (TblProductSkc tblProductSkc : tblProductSkcs) {
if (tblProductSkcMap.containsKey(tblProductSkc.getProductSkn())) {
List<TblProductSkc> skcs = tblProductSkcMap.get(tblProductSkc.getProductSkn());
skcs.add(tblProductSkc);
tblProductSkcMap.put(tblProductSkc.getProductSkn(), skcs);
} else {
List<TblProductSkc> skcs = new ArrayList<>();
skcs.add(tblProductSkc);
tblProductSkcMap.put(tblProductSkc.getProductSkn(), skcs);
}
}
}
}
return tblProductSkcMap;
}
/**
* 获取TblProductSkcMap
*
* @param tblProducts
* @return
*/
private Map<Integer, List<TblProductSkc>> getTblProductSkcMap(List<TblProduct> tblProducts) {
Map<Integer, List<TblProductSkc>> tblProductSkcMap = new HashMap<>();
List<Integer> productSkns = tblProducts.stream().map(TblProduct::getProductSkn).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productSkns)) {
List<TblProductSkc> tblProductSkcs = tblProductSkcService.getBySkns(productSkns);
if (CollectionUtils.isNotEmpty(tblProductSkcs)) {
for (TblProductSkc tblProductSkc : tblProductSkcs) {
if (tblProductSkcMap.containsKey(tblProductSkc.getProductSkn())) {
List<TblProductSkc> skcs = tblProductSkcMap.get(tblProductSkc.getProductSkn());
skcs.add(tblProductSkc);
tblProductSkcMap.put(tblProductSkc.getProductSkn(), skcs);
} else {
List<TblProductSkc> skcs = new ArrayList<>();
skcs.add(tblProductSkc);
tblProductSkcMap.put(tblProductSkc.getProductSkn(), skcs);
}
}
}
}
return tblProductSkcMap;
}
/**
* 获取TblProductSkuMap
*
* @param tblProducts
* @return
*/
private Map<Integer, List<TblProductSku>> getTblProductSkuMap(List<TblProduct> tblProducts) {
Map<Integer, List<TblProductSku>> tblProductSkuMap = new HashMap<>();
List<Integer> productSkns = tblProducts.stream().map(TblProduct::getProductSkn).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productSkns)) {
List<TblProductSku> tblProductSkus = tblProductSkuService.getBySkns(productSkns);
if (CollectionUtils.isNotEmpty(tblProductSkus)) {
for (TblProductSku tblProductSku : tblProductSkus) {
if (tblProductSkuMap.containsKey(tblProductSku.getProductSkn())) {
List<TblProductSku> skus = tblProductSkuMap.get(tblProductSku.getProductSkn());
skus.add(tblProductSku);
tblProductSkuMap.put(tblProductSku.getProductSkn(), skus);
} else {
List<TblProductSku> skus = new ArrayList<>();
skus.add(tblProductSku);
tblProductSkuMap.put(tblProductSku.getProductSkn(), skus);
}
}
}
}
return tblProductSkuMap;
}
/**
* 获取TblProductSkuMap
*
* @param tblProducts
* @return
*/
private Map<Integer, List<TblProductSku>> getTblProductSkuMap(List<TblProduct> tblProducts) {
Map<Integer, List<TblProductSku>> tblProductSkuMap = new HashMap<>();
List<Integer> productSkns = tblProducts.stream().map(TblProduct::getProductSkn).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productSkns)) {
List<TblProductSku> tblProductSkus = tblProductSkuService.getBySkns(productSkns);
if (CollectionUtils.isNotEmpty(tblProductSkus)) {
for (TblProductSku tblProductSku : tblProductSkus) {
if (tblProductSkuMap.containsKey(tblProductSku.getProductSkn())) {
List<TblProductSku> skus = tblProductSkuMap.get(tblProductSku.getProductSkn());
skus.add(tblProductSku);
tblProductSkuMap.put(tblProductSku.getProductSkn(), skus);
} else {
List<TblProductSku> skus = new ArrayList<>();
skus.add(tblProductSku);
tblProductSkuMap.put(tblProductSku.getProductSkn(), skus);
}
}
}
}
return tblProductSkuMap;
}
/**
* 获取品类Map
*
* @return
*/
private Map<Integer, String> getSortMap() {
Map<Integer, String> sortMap = new HashMap<>();
List<TblSort> tblSorts = tblSortService.getAll();
if (CollectionUtils.isNotEmpty(tblSorts)) {
sortMap = tblSorts.stream().parallel().collect(Collectors.toMap(TblSort::getSortId, TblSort::getSortName));
}
return sortMap;
}
/**
* 获取品类Map
*
* @return
*/
private Map<Integer, String> getSortMap() {
Map<Integer, String> sortMap = new HashMap<>();
List<TblSort> tblSorts = tblSortService.getAll();
if (CollectionUtils.isNotEmpty(tblSorts)) {
sortMap = tblSorts.stream().parallel().collect(Collectors.toMap(TblSort::getSortId, TblSort::getSortName));
}
return sortMap;
}
/**
* 处理brand
*
* @param productIndexBO
* @param tblBrand
* @return
*/
private ProductIndexBO processBrand(ProductIndexBO productIndexBO, TblBrand tblBrand) {
productIndexBO.setBrandId(null);
productIndexBO.setBrandAlif(null);
productIndexBO.setBrandDomain(null);
if (tblBrand != null) {
productIndexBO.setBrandName(tblBrand.getBrandNameEn());
productIndexBO.setBrandNameEn(tblBrand.getBrandNameEn());
productIndexBO.setBrandNameCn(tblBrand.getBrandNameCn());
} else {
// 增量当品牌删除的时候
productIndexBO.setBrandName(null);
productIndexBO.setBrandNameEn(null);
productIndexBO.setBrandNameCn(null);
}
if(tblBrand.getBrandId()!=null){
productIndexBO.setShopId(tblBrand.getBrandId()*(-1));
/**
* 处理brand
*
* @param productIndexBO
* @param tblBrand
* @return
*/
private ProductIndexBO processBrand(ProductIndexBO productIndexBO, TblBrand tblBrand) {
productIndexBO.setBrandId(null);
productIndexBO.setBrandAlif(null);
productIndexBO.setBrandDomain(null);
if (tblBrand != null) {
productIndexBO.setBrandName(tblBrand.getBrandNameEn());
productIndexBO.setBrandNameEn(tblBrand.getBrandNameEn());
productIndexBO.setBrandNameCn(tblBrand.getBrandNameCn());
if (tblBrand.getBrandId() != null) {
productIndexBO.setShopId(tblBrand.getBrandId() * (-1));
}
} else {
// 增量当品牌删除的时候
productIndexBO.setBrandName(null);
productIndexBO.setBrandNameEn(null);
productIndexBO.setBrandNameCn(null);
}
return productIndexBO;
}
return productIndexBO;
}
/**
* 处理ShowStatus
*
* @param productIndexBO
* @param siteMap
* @param tblProduct
* @param tblBrand
* @return
*/
private ProductIndexBO processShowStatus(ProductIndexBO productIndexBO, Map<Integer, TblSite> siteMap, TblProduct tblProduct, TblBrand tblBrand) {
String showStatus = "Y";
TblSite tblSite = siteMap.get(tblProduct.getSiteId());
if (tblProduct.getSource() != null) {
if (tblProduct.getSource().equals("1")) {
if (tblSite != null && tblSite.getStatus().equals("1")) {
showStatus = "N";
}
if (tblBrand != null && tblBrand.getStatus().equals("1")) {
showStatus = "N";
}
}
if (tblProduct.getSource().equals("2")) {
if (tblBrand.getStatus().equals("1")) {
showStatus = "N";
}
}
}
// 判断上架状态
boolean isShow = false;
if ((tblProduct.getStatus() != null && tblProduct.getStatus() == 4 && "Y".equalsIgnoreCase(showStatus))) {
isShow = true;
}
productIndexBO.setStatus(isShow ? 1 : 0);
productIndexBO.setIsSales(productIndexBO.getStatus() == 1 ? "Y" : "N");
productIndexBO.setIssales(productIndexBO.getIsSales().equals("Y") ? 1 : 2);
// 判断库存状态
if (tblProduct.getStockStatus() != null) {
boolean hasStock = tblProduct.getStockStatus().equals("1") ? true : false;
productIndexBO.setStorageNum(isShow && hasStock ? new BigDecimal(100) : BigDecimal.ZERO);
productIndexBO.setIsSoonSoldOut("N");
productIndexBO.setIsSoldOut("N");
productIndexBO.setSoldOut(1);
}
return productIndexBO;
}
/**
* 处理ShowStatus
*
* @param productIndexBO
* @param siteMap
* @param tblProduct
* @param tblBrand
* @return
*/
private ProductIndexBO processShowStatus(ProductIndexBO productIndexBO, Map<Integer, TblSite> siteMap, TblProduct tblProduct, TblBrand tblBrand) {
String showStatus = "Y";
TblSite tblSite = siteMap.get(tblProduct.getSiteId());
if (tblProduct.getSource() != null) {
if (tblProduct.getSource().equals("1")) {
if (tblSite != null && tblSite.getStatus().equals("1")) {
showStatus = "N";
}
if (tblBrand != null && tblBrand.getStatus().equals("1")) {
showStatus = "N";
}
}
if (tblProduct.getSource().equals("2")) {
if (tblBrand.getStatus().equals("1")) {
showStatus = "N";
}
}
}
// 判断上架状态
boolean isShow = false;
if ((tblProduct.getStatus() != null && tblProduct.getStatus() == 4 && "Y".equalsIgnoreCase(showStatus))) {
isShow = true;
}
productIndexBO.setStatus(isShow ? 1 : 0);
productIndexBO.setIsSales(productIndexBO.getStatus() == 1 ? "Y" : "N");
productIndexBO.setIssales(productIndexBO.getIsSales().equals("Y") ? 1 : 2);
// 判断库存状态
if (tblProduct.getStockStatus() != null) {
boolean hasStock = tblProduct.getStockStatus().equals("1") ? true : false;
productIndexBO.setStorageNum(isShow && hasStock ? new BigDecimal(100) : BigDecimal.ZERO);
productIndexBO.setIsSoonSoldOut("N");
productIndexBO.setIsSoldOut("N");
productIndexBO.setSoldOut(1);
}
return productIndexBO;
}
/**
* 处理Sort
*
* @param productIndexBO
* @param sortMap
* @param tblProduct
* @return
*/
private ProductIndexBO processSort(ProductIndexBO productIndexBO, Map<Integer, String> sortMap, TblProduct tblProduct) {
String sortOne = sortMap.get(tblProduct.getSortOne()) == null ? "" : sortMap.get(tblProduct.getSortOne());
String sortTwo = sortMap.get(tblProduct.getSortTwo()) == null ? "" : sortMap.get(tblProduct.getSortTwo());
String sortThree = sortMap.get(tblProduct.getSortThree()) == null ? "" : sortMap.get(tblProduct.getSortThree());
String sortfour = sortMap.get(tblProduct.getSortFour()) == null ? "" : sortMap.get(tblProduct.getSortFour());
/**
* 处理Sort
*
* @param productIndexBO
* @param sortMap
* @param tblProduct
* @return
*/
private ProductIndexBO processSort(ProductIndexBO productIndexBO, Map<Integer, String> sortMap, TblProduct tblProduct) {
String sortOne = sortMap.get(tblProduct.getSortOne()) == null ? "" : sortMap.get(tblProduct.getSortOne());
String sortTwo = sortMap.get(tblProduct.getSortTwo()) == null ? "" : sortMap.get(tblProduct.getSortTwo());
String sortThree = sortMap.get(tblProduct.getSortThree()) == null ? "" : sortMap.get(tblProduct.getSortThree());
String sortfour = sortMap.get(tblProduct.getSortFour()) == null ? "" : sortMap.get(tblProduct.getSortFour());
// 处理大分类
productIndexBO.setMaxSortId(new Integer(0));
productIndexBO.setMaxSortName(sortOne + "," + sortTwo);
productIndexBO.setMaxSort(sortTwo);
// 处理大分类
productIndexBO.setMaxSortId(new Integer(0));
productIndexBO.setMaxSortName(sortOne + "," + sortTwo);
productIndexBO.setMaxSort(sortTwo);
// 处理中分类
productIndexBO.setMiddleSortId(new Integer(0));
productIndexBO.setMiddleSortName(sortThree);
// if(!sortThree.equals(sortTwo)){
productIndexBO.setMiddleSort(sortThree);
// }
// 处理中分类
productIndexBO.setMiddleSortId(new Integer(0));
productIndexBO.setMiddleSortName(sortThree);
// if(!sortThree.equals(sortTwo)){
productIndexBO.setMiddleSort(sortThree);
// }
// 处理小分类
productIndexBO.setSmallSortId(new Integer(0));
productIndexBO.setSmallSortName(sortfour);
// if(!sortfour.equals(sortTwo) && !sortfour.equals(sortThree)){
productIndexBO.setSmallSort(sortfour);
// }
return productIndexBO;
}
// 处理小分类
productIndexBO.setSmallSortId(new Integer(0));
productIndexBO.setSmallSortName(sortfour);
// if(!sortfour.equals(sortTwo) && !sortfour.equals(sortThree)){
productIndexBO.setSmallSort(sortfour);
// }
return productIndexBO;
}
/**
* 处理Goods
*
* @param tblProductSkcMap
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processGoods(Map<Integer, List<TblProductSkc>> tblProductSkcMap, ProductIndexBO productIndexBO, TblProduct tblProduct) {
List<TblProductSkc> tblProductSkcs = tblProductSkcMap.get(tblProduct.getProductSkn());
if (CollectionUtils.isNotEmpty(tblProductSkcs)) {
// 设置skn封面
int defaultCoverPosition = 0;
for (int i = 0; i < tblProductSkcs.size(); i++) {
if (tblProductSkcs.get(i).getIsDefault().equals("1")) {
defaultCoverPosition = i;
}
}
TblProductSkc tblProductSkc = tblProductSkcs.get(defaultCoverPosition);
JSONArray jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
String defaultSknImages = getCover(jsonArray, true);
productIndexBO.setDefaultImages(defaultSknImages);
StringBuilder colorNames = new StringBuilder();
StringBuilder colorIds = new StringBuilder();
JSONArray goodsArray = new JSONArray();
for (TblProductSkc skc : tblProductSkcs) {
// 颜色名称
colorNames.append(skc.getColor() + ",");
colorIds.append(skc.getColorSysId() + ",");
jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
String skcDefaultImages = getCover(jsonArray, false);
JSONObject jsonObj = new JSONObject();
jsonObj.put("goods_id", skc.getProductSkc() == null ? "" : skc.getProductSkc());
jsonObj.put("color_name", skc.getColor() == null ? "" : skc.getColor());
jsonObj.put("color_id", skc.getColorSysId() == null ? "" : skc.getColorSysId());
jsonObj.put("cover_1", "");
jsonObj.put("cover_2", "");
jsonObj.put("status", "1");
jsonObj.put("color_code", "");
jsonObj.put("color_value", "");
jsonObj.put("images_url", skcDefaultImages == null ? "" : skcDefaultImages);
jsonObj.put("is_default", skc.getIsDefault().equals("1") ? "Y" : "N");
jsonObj.put("storage_num", "100");
goodsArray.add(jsonObj);
}
productIndexBO.setColorIds(colorIds.toString());
productIndexBO.setColorNames(colorNames.toString());
productIndexBO.setGoodsList(goodsArray.toString());
} else {
// 增量,skn下的最后一个skc被删除时
productIndexBO.setDefaultImages(null);
productIndexBO.setColorIds(null);
productIndexBO.setColorNames(null);
productIndexBO.setGoodsList(null);
}
return productIndexBO;
}
/**
* 处理Goods
*
* @param tblProductSkcMap
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processGoods(Map<Integer, List<TblProductSkc>> tblProductSkcMap, ProductIndexBO productIndexBO, TblProduct tblProduct) {
List<TblProductSkc> tblProductSkcs = tblProductSkcMap.get(tblProduct.getProductSkn());
if (CollectionUtils.isNotEmpty(tblProductSkcs)) {
// 设置skn封面
int defaultCoverPosition = 0;
for (int i = 0; i < tblProductSkcs.size(); i++) {
if (tblProductSkcs.get(i).getIsDefault().equals("1")) {
defaultCoverPosition = i;
}
}
TblProductSkc tblProductSkc = tblProductSkcs.get(defaultCoverPosition);
JSONArray jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
String defaultSknImages = getCover(jsonArray, true);
productIndexBO.setDefaultImages(defaultSknImages);
StringBuilder colorNames = new StringBuilder();
StringBuilder colorIds = new StringBuilder();
JSONArray goodsArray = new JSONArray();
for (TblProductSkc skc : tblProductSkcs) {
// 颜色名称
colorNames.append(skc.getColor() + ",");
colorIds.append(skc.getColorSysId() + ",");
jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
String skcDefaultImages = getCover(jsonArray, false);
JSONObject jsonObj = new JSONObject();
jsonObj.put("goods_id", skc.getProductSkc() == null ? "" : skc.getProductSkc());
jsonObj.put("color_name", skc.getColor() == null ? "" : skc.getColor());
jsonObj.put("color_id", skc.getColorSysId() == null ? "" : skc.getColorSysId());
jsonObj.put("cover_1", "");
jsonObj.put("cover_2", "");
jsonObj.put("status", "1");
jsonObj.put("color_code", "");
jsonObj.put("color_value", "");
jsonObj.put("images_url", skcDefaultImages == null ? "" : skcDefaultImages);
jsonObj.put("is_default", skc.getIsDefault().equals("1") ? "Y" : "N");
jsonObj.put("storage_num", "100");
goodsArray.add(jsonObj);
}
productIndexBO.setColorIds(colorIds.toString());
productIndexBO.setColorNames(colorNames.toString());
productIndexBO.setGoodsList(goodsArray.toString());
} else {
// 增量,skn下的最后一个skc被删除时
productIndexBO.setDefaultImages(null);
productIndexBO.setColorIds(null);
productIndexBO.setColorNames(null);
productIndexBO.setGoodsList(null);
}
return productIndexBO;
}
/**
* 处理Size
*
* @param tblProductSkuMap
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processSize(Map<Integer, List<TblProductSku>> tblProductSkuMap, ProductIndexBO productIndexBO, TblProduct tblProduct) {
List<TblProductSku> tblProductSkus = tblProductSkuMap.get(tblProduct.getProductSkn());
if (CollectionUtils.isNotEmpty(tblProductSkus)) {
StringBuilder sizeNames = new StringBuilder();
for (TblProductSku tblProductSku : tblProductSkus) {
sizeNames.append(tblProductSku.getSize() + ",");
}
productIndexBO.setSizeNames(sizeNames.toString());
} else {
// 增量,skn下的最后一个sku被删除时
productIndexBO.setSizeNames(null);
}
return productIndexBO;
}
/**
* 处理Size
*
* @param tblProductSkuMap
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processSize(Map<Integer, List<TblProductSku>> tblProductSkuMap, ProductIndexBO productIndexBO, TblProduct tblProduct) {
List<TblProductSku> tblProductSkus = tblProductSkuMap.get(tblProduct.getProductSkn());
if (CollectionUtils.isNotEmpty(tblProductSkus)) {
StringBuilder sizeNames = new StringBuilder();
for (TblProductSku tblProductSku : tblProductSkus) {
sizeNames.append(tblProductSku.getSize() + ",");
}
productIndexBO.setSizeNames(sizeNames.toString());
} else {
// 增量,skn下的最后一个sku被删除时
productIndexBO.setSizeNames(null);
}
return productIndexBO;
}
/**
* 处理其他简单字段
*
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processSimpleField(ProductIndexBO productIndexBO, TblProduct tblProduct) {
if (tblProduct.getIsLimited() != null) {
productIndexBO.setIslimited("1".equals(tblProduct.getIsLimited()) ? "Y" : "N");
}
if (tblProduct.getGender() != null) {
productIndexBO.setGender(tblProduct.getGender());
productIndexBO.setGenderS(tblProduct.getGender().replace("1", "男").replace("2", "女").replace("3", "男/女"));
}
productIndexBO.setIsSpecial("N");
productIndexBO.setIsHot("N");
productIndexBO.setIshot(2);
productIndexBO.setIspromotion(0);
productIndexBO.setIsAdvance("N");
productIndexBO.setIsadvance(2);
productIndexBO.setIsAuditing("N");
productIndexBO.setIsauditing(2);
productIndexBO.setAttribute(1);
productIndexBO.setIsDown("N");
productIndexBO.setIsdown(2);
productIndexBO.setIsrecommend(2);
productIndexBO.setIsOutlets(2);
productIndexBO.setIsnew("N");
if (null != tblProduct.getShelfTime()) {
productIndexBO.setShelveTime(Integer.valueOf(tblProduct.getShelfTime()));
productIndexBO.setFirstShelveTime(productIndexBO.getShelveTime());
productIndexBO.setShelveDay(DateUtil.TimeStamp2DateWithFormat(Long.valueOf(productIndexBO.getShelveTime()), "yyyy-MM-dd"));
}
productIndexBO.setEditTime(null == tblProduct.getUpdateTime() ? null : Integer.valueOf(tblProduct.getUpdateTime()));
productIndexBO.setMarketPrice(null == tblProduct.getOrignPrice() ? new BigDecimal(0) : tblProduct.getOrignPrice());
productIndexBO.setSalesPrice(null == tblProduct.getGoodsPrice() ? new BigDecimal(0) : tblProduct.getGoodsPrice());
if (productIndexBO.getSalesPrice() != null) {
if (productIndexBO.getMarketPrice() != null && productIndexBO.getMarketPrice().doubleValue() != 0d) {
BigDecimal promotionDiscount = productIndexBO.getSalesPrice().divide(productIndexBO.getMarketPrice(), 4, BigDecimal.ROUND_HALF_UP);
productIndexBO.setPromotionDiscount(promotionDiscount);
productIndexBO.setPromotionDiscountInt((promotionDiscount.multiply(BigDecimal.TEN)).longValue());
if (productIndexBO.getSalesPrice().compareTo(productIndexBO.getMarketPrice()) < 0) {
productIndexBO.setIsDiscount("Y");
}
}
productIndexBO.setVip1Price(productIndexBO.getSalesPrice());
productIndexBO.setVip2Price(productIndexBO.getSalesPrice());
productIndexBO.setVip3Price(productIndexBO.getSalesPrice());
productIndexBO.setVipPrice(productIndexBO.getSalesPrice());
productIndexBO.setSpecialPrice(productIndexBO.getSalesPrice());
}
productIndexBO.setSpecialoffer("N");
productIndexBO.setIsDiscount("N");
productIndexBO.setBreakingRate(0d);
productIndexBO.setBasePinRatio(0);
return productIndexBO;
/**
* 处理其他简单字段
*
* @param productIndexBO
* @param tblProduct
* @return
*/
private ProductIndexBO processSimpleField(ProductIndexBO productIndexBO, TblProduct tblProduct) {
if (tblProduct.getIsLimited() != null) {
productIndexBO.setIslimited("1".equals(tblProduct.getIsLimited()) ? "Y" : "N");
}
if (tblProduct.getGender() != null) {
productIndexBO.setGender(tblProduct.getGender());
productIndexBO.setGenderS(tblProduct.getGender().replace("1", "男").replace("2", "女").replace("3", "男/女"));
}
productIndexBO.setIsSpecial("N");
productIndexBO.setIsHot("N");
productIndexBO.setIshot(2);
productIndexBO.setIspromotion(0);
productIndexBO.setIsAdvance("N");
productIndexBO.setIsadvance(2);
productIndexBO.setIsAuditing("N");
productIndexBO.setIsauditing(2);
productIndexBO.setAttribute(1);
productIndexBO.setIsDown("N");
productIndexBO.setIsdown(2);
productIndexBO.setIsrecommend(2);
productIndexBO.setIsOutlets(2);
productIndexBO.setIsnew("N");
if (null != tblProduct.getShelfTime()) {
productIndexBO.setShelveTime(Integer.valueOf(tblProduct.getShelfTime()));
productIndexBO.setFirstShelveTime(productIndexBO.getShelveTime());
productIndexBO.setShelveDay(DateUtil.TimeStamp2DateWithFormat(Long.valueOf(productIndexBO.getShelveTime()), "yyyy-MM-dd"));
}
productIndexBO.setEditTime(null == tblProduct.getUpdateTime() ? null : Integer.valueOf(tblProduct.getUpdateTime()));
productIndexBO.setMarketPrice(null == tblProduct.getOrignPrice() ? new BigDecimal(0) : tblProduct.getOrignPrice());
productIndexBO.setSalesPrice(null == tblProduct.getGoodsPrice() ? new BigDecimal(0) : tblProduct.getGoodsPrice());
if (productIndexBO.getSalesPrice() != null) {
if (productIndexBO.getMarketPrice() != null && productIndexBO.getMarketPrice().doubleValue() != 0d) {
BigDecimal promotionDiscount = productIndexBO.getSalesPrice().divide(productIndexBO.getMarketPrice(), 4, BigDecimal.ROUND_HALF_UP);
productIndexBO.setPromotionDiscount(promotionDiscount);
productIndexBO.setPromotionDiscountInt((promotionDiscount.multiply(BigDecimal.TEN)).longValue());
if (productIndexBO.getSalesPrice().compareTo(productIndexBO.getMarketPrice()) < 0) {
productIndexBO.setIsDiscount("Y");
}
}
productIndexBO.setVip1Price(productIndexBO.getSalesPrice());
productIndexBO.setVip2Price(productIndexBO.getSalesPrice());
productIndexBO.setVip3Price(productIndexBO.getSalesPrice());
productIndexBO.setVipPrice(productIndexBO.getSalesPrice());
productIndexBO.setSpecialPrice(productIndexBO.getSalesPrice());
}
productIndexBO.setSpecialoffer("N");
productIndexBO.setIsDiscount("N");
productIndexBO.setBreakingRate(0d);
productIndexBO.setBasePinRatio(0);
return productIndexBO;
}
}
/**
* 获取封面值
*
* @param jsonArray
* @return
*/
private String getCover(JSONArray jsonArray, boolean needFormatter) {
if (jsonArray == null) {
return "";
}
boolean hasCover = false;
int picPosition = 0;
int minSort = 10000;
int minSortPosition = 0;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String cover = jsonObject.get("cover") == null ? "" : jsonObject.get("cover").toString();
String sortString = jsonObject.get("sort") == null ? "" : jsonObject.get("sort").toString().trim();
if (StringUtils.isNotBlank(sortString)) {
Integer sortNum = Integer.valueOf(sortString);
if (sortNum < minSort) {
minSort = sortNum;
minSortPosition = i;
}
}
if (cover.equals("1")) {
picPosition = i;
hasCover = true;
}
}
String defaultImages = "";
if (hasCover) {
JSONObject jsonObject = jsonArray.getJSONObject(picPosition);
defaultImages = jsonObject.get("src") == null ? "" : jsonObject.get("src").toString();
} else {
JSONObject jsonObject = jsonArray.getJSONObject(minSortPosition);
defaultImages = jsonObject.get("src") == null ? "" : jsonObject.get("src").toString();
}
return tblImgUrlLogicService.getTblImageUrl(defaultImages, needFormatter);
}
/**
* 获取封面值
*
* @param jsonArray
* @return
*/
private String getCover(JSONArray jsonArray, boolean needFormatter) {
if (jsonArray == null) {
return "";
}
boolean hasCover = false;
int picPosition = 0;
int minSort = 10000;
int minSortPosition = 0;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String cover = jsonObject.get("cover") == null ? "" : jsonObject.get("cover").toString();
String sortString = jsonObject.get("sort") == null ? "" : jsonObject.get("sort").toString().trim();
if (StringUtils.isNotBlank(sortString)) {
Integer sortNum = Integer.valueOf(sortString);
if (sortNum < minSort) {
minSort = sortNum;
minSortPosition = i;
}
}
if (cover.equals("1")) {
picPosition = i;
hasCover = true;
}
}
String defaultImages = "";
if (hasCover) {
JSONObject jsonObject = jsonArray.getJSONObject(picPosition);
defaultImages = jsonObject.get("src") == null ? "" : jsonObject.get("src").toString();
} else {
JSONObject jsonObject = jsonArray.getJSONObject(minSortPosition);
defaultImages = jsonObject.get("src") == null ? "" : jsonObject.get("src").toString();
}
return tblImgUrlLogicService.getTblImageUrl(defaultImages, needFormatter);
}
}
... ...