...
|
...
|
@@ -5,28 +5,17 @@ import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.HttpClientUtils;
|
|
|
import com.yoho.search.base.utils.MD5Util;
|
|
|
import com.yoho.search.consumer.service.logicService.common.ConsumerConfiger;
|
|
|
import com.yoho.search.consumer.index.common.IIndexBuilder;
|
|
|
import com.yoho.search.consumer.index.fullbuild.tblProductNew.TblProductSkcMapBuilder;
|
|
|
import com.yoho.search.consumer.index.fullbuild.tblProductNew.TblProductSkuMapBuilder;
|
|
|
import com.yoho.search.consumer.service.daoService.TblBrandService;
|
|
|
import com.yoho.search.consumer.service.daoService.TblProductService;
|
|
|
import com.yoho.search.consumer.service.daoService.TblProductSkcService;
|
|
|
import com.yoho.search.consumer.service.daoService.TblSiteService;
|
|
|
import com.yoho.search.consumer.service.logicService.tbl.TblAdaptorLogicService;
|
|
|
import com.yoho.search.consumer.service.logicService.tbl.util.ImagesUtils;
|
|
|
import com.yoho.search.dal.model.*;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import com.yoho.search.consumer.service.logicService.common.ConsumerConfiger;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* tblproduct索引,使用调用接口的方式重建。
|
...
|
...
|
@@ -38,290 +27,15 @@ public class TblProductIndexBuilder extends IIndexBuilder { |
|
|
|
|
|
@Autowired
|
|
|
private ConsumerConfiger configurer;
|
|
|
@Autowired
|
|
|
private TblProductService tblProductService;
|
|
|
@Autowired
|
|
|
private TblProductSkcService tblProductSkcService;
|
|
|
@Autowired
|
|
|
private TblSiteService tblSiteService;
|
|
|
@Autowired
|
|
|
private TblBrandService tblBrandService;
|
|
|
@Autowired
|
|
|
private TblProductSkcMapBuilder tblProductSkcMapBuilder;
|
|
|
@Autowired
|
|
|
private TblProductSkuMapBuilder tblProductSkuMapBuilder;
|
|
|
@Autowired
|
|
|
private TblAdaptorLogicService tblAdaptorLogicService;
|
|
|
|
|
|
@Override
|
|
|
public int getTotalCount() throws Exception {
|
|
|
//走接口构建,否则用表数据构建
|
|
|
if (configurer.getTblRebuildUseUrl()) {
|
|
|
return getCount();
|
|
|
}
|
|
|
return tblProductService.count();
|
|
|
return getCount();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<?> getPageLists(int offset, int limit) throws Exception {
|
|
|
//走接口构建,否则用表数据构建
|
|
|
if (configurer.getTblRebuildUseUrl()) {
|
|
|
return getPageList(offset, limit);
|
|
|
}
|
|
|
|
|
|
//查询tblProduct列表
|
|
|
List<TblProduct> tblProductList = tblProductService.getPageLists(offset, limit);
|
|
|
//构建tblSiteMap
|
|
|
Map<Integer, TblSite> tblSiteMap = getSiteMap();
|
|
|
//构建tblBrandMap
|
|
|
Map<Integer, TblBrand> tblBrandMap = getTblBrandMap();
|
|
|
//skc
|
|
|
Map<Integer, List<TblProductSkc>> tblProductSkcMap = tblProductSkcMapBuilder.build(tblProductList);
|
|
|
//sku
|
|
|
Map<Integer, List<TblProductSku>> tblProductSkuMap = tblProductSkuMapBuilder.build(tblProductList);
|
|
|
//构建ColorIds字段Map
|
|
|
Map<Integer, String> colorIdsMap = getColorIdsMap(tblProductList);
|
|
|
|
|
|
//构建TblProductBO
|
|
|
List<TblProductBO> tblProductBOList = new ArrayList<>();
|
|
|
for (TblProduct tblProduct : tblProductList) {
|
|
|
//拼装与skc有关的字段,获取skn下面的skc列表
|
|
|
List<TblProductSkc> tblProductSkcList = tblProductSkcMap.get(tblProduct.getProductSkn());
|
|
|
//如果某个skn下不包含skc则跳过
|
|
|
if (CollectionUtils.isEmpty(tblProductSkcList)) {
|
|
|
continue;
|
|
|
}
|
|
|
String sizeList = "";
|
|
|
String url = "";
|
|
|
List<JSONObject> skc = new ArrayList<>();
|
|
|
//遍历skc列表
|
|
|
for (TblProductSkc tblProductSkc : tblProductSkcList) {
|
|
|
//构建cover和url
|
|
|
JSONArray jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
|
|
|
String cover = "";
|
|
|
String imageUrl = "";
|
|
|
if (jsonArray != null) {
|
|
|
//默认的cover和url是第一个skc的
|
|
|
JSONObject pic1 = (JSONObject) jsonArray.get(0);
|
|
|
cover = pic1.get("src").toString();
|
|
|
//满足条件重新设置cover
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
JSONObject pic = (JSONObject) jsonArray.get(i);
|
|
|
if (pic.get("cover") != null && pic.get("cover").equals("1")) {
|
|
|
cover = pic.get("src").toString();
|
|
|
}
|
|
|
}
|
|
|
imageUrl = ImagesUtils.getImageUrl(cover, 112, 154);
|
|
|
//满足条件设置url
|
|
|
if ("1".equals(tblProductSkc.getIsDefault()) && !"1".equals(tblProductSkc.getIsDeleted())) {
|
|
|
imageUrl = ImagesUtils.getImageUrl(cover, 112, 154);
|
|
|
url = imageUrl.substring(0, imageUrl.indexOf("?"));
|
|
|
}
|
|
|
}
|
|
|
//拼装size_List
|
|
|
List<TblProductSku> tblProductSkuList = tblProductSkuMap.get(tblProduct.getProductSkn());
|
|
|
if (CollectionUtils.isNotEmpty(tblProductSkuList)) {
|
|
|
for (TblProductSku tblProductSku : tblProductSkuList) {
|
|
|
if (tblProductSku.getProductSkc().intValue() == tblProductSkc.getProductSkc().intValue()) {
|
|
|
if (!"1".equals(tblProductSku.getIsDeleted())) {
|
|
|
sizeList += tblProductSku.getSize() + ",";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//拼装skc列表
|
|
|
JSONObject skcObject = new JSONObject();
|
|
|
skcObject.put("product_skc", tblProductSkc.getProductSkc());
|
|
|
skcObject.put("color_sys_id", tblProductSkc.getColorSysId());
|
|
|
skcObject.put("color", tblProductSkc.getColor());
|
|
|
skcObject.put("cover", imageUrl.substring(0, imageUrl.indexOf("?")));
|
|
|
skcObject.put("format_cover", ImagesUtils.template2(imageUrl.substring(0, imageUrl.indexOf("?")), "global", "center", "d2hpdGU="));
|
|
|
skc.add(skcObject);
|
|
|
}
|
|
|
|
|
|
//设置默认url
|
|
|
if (StringUtils.isBlank(url)) {
|
|
|
TblProductSkc tblProductSkc = tblProductSkcList.get(0);
|
|
|
JSONArray jsonArray = JSONArray.parseArray(tblProductSkc.getPics());
|
|
|
JSONObject pic1 = (JSONObject) jsonArray.get(0);
|
|
|
String cover = pic1.get("src").toString();
|
|
|
String imageUrl = ImagesUtils.getImageUrl(cover, 112, 154);
|
|
|
url = imageUrl.substring(0, imageUrl.indexOf("?"));
|
|
|
}
|
|
|
|
|
|
//拼装TblProductBO数据
|
|
|
TblProductBO tblProductBO = new TblProductBO();
|
|
|
//简单字段:productSkn,productName,brandId,countryId,currencyId,siteId,gender,isLimited,sortOne,sortTwo,sortThree,sortFour,status,stockStatus,updateTime,shelfTime
|
|
|
BeanUtils.copyProperties(tblProduct, tblProductBO);
|
|
|
//colorIds
|
|
|
String colorIds = colorIdsMap.get(tblProduct.getProductSkn());
|
|
|
tblProductBO.setColorIds(colorIds);
|
|
|
//goodsPrice,tagPrice,orignPrice
|
|
|
if (tblProductBO.getGoodsPrice() != null) {
|
|
|
tblProductBO.setGoodsPrice(tblProductBO.getGoodsPrice().setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
}
|
|
|
if (tblProductBO.getTagPrice() != null) {
|
|
|
tblProductBO.setTagPrice(tblProductBO.getTagPrice().setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
}
|
|
|
if (tblProductBO.getOrignPrice() != null) {
|
|
|
tblProductBO.setOrignPrice(tblProductBO.getOrignPrice().setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
}
|
|
|
//isPlane
|
|
|
if (tblProductBO.getCountryId() == 86) {
|
|
|
tblProductBO.setIsPlane("N");
|
|
|
}
|
|
|
//showStatus
|
|
|
String showStatus = this.buildShowStatus(tblProduct, tblSiteMap, tblBrandMap);
|
|
|
tblProductBO.setShowStatus(showStatus);
|
|
|
//cover
|
|
|
tblProductBO.setCover(url);
|
|
|
//formatCover
|
|
|
tblProductBO.setFormatCover(ImagesUtils.template2(url, null, "center", "d2hpdGU="));
|
|
|
//skc
|
|
|
tblProductBO.setSkc(skc);
|
|
|
//sizeLIst
|
|
|
tblProductBO.setSizeList(sizeList.substring(0, sizeList.length() - 1));
|
|
|
|
|
|
//塞入列表
|
|
|
tblProductBOList.add(tblProductBO);
|
|
|
}
|
|
|
|
|
|
//融合进有货的商品
|
|
|
if (offset == 0) {
|
|
|
List<Integer> brandIdList = this.getBrandIdList();
|
|
|
if (CollectionUtils.isEmpty(brandIdList)) {
|
|
|
return tblProductBOList;
|
|
|
}
|
|
|
Map<Integer, List<TblBrand>> brandMap = this.getBrandMap();
|
|
|
if (brandMap.isEmpty()) {
|
|
|
return tblProductBOList;
|
|
|
}
|
|
|
List<TplProductBo> tplProductBoList = tblAdaptorLogicService.convertYohoToTplProduct(brandIdList);
|
|
|
if (CollectionUtils.isEmpty(tplProductBoList)) {
|
|
|
return tblProductBOList;
|
|
|
}
|
|
|
for (TplProductBo tplProductBo : tplProductBoList) {
|
|
|
if (StringUtils.isBlank(tplProductBo.getOrignPrice()) || StringUtils.isBlank(tplProductBo.getGoodsPrice())) {
|
|
|
continue;
|
|
|
}
|
|
|
TblProductBO tblProductBO = new TblProductBO();
|
|
|
BeanUtils.copyProperties(tplProductBo, tblProductBO);
|
|
|
//brandId
|
|
|
List<TblBrand> tblBrandList = brandMap.get(tplProductBo.getBrandId());
|
|
|
if (CollectionUtils.isNotEmpty(tblBrandList)) {
|
|
|
TblBrand tblBrand = tblBrandList.get(0);
|
|
|
tblProductBO.setBrandId(tblBrand.getBrandId());
|
|
|
}
|
|
|
tblProductBO.setIsGlobal("N");
|
|
|
tblProductBO.setIsPlane("N");
|
|
|
tblProductBO.setStatus(4);
|
|
|
tblProductBO.setFormatCover("");
|
|
|
tblProductBO.setSkc(new ArrayList<>());
|
|
|
tblProductBO.setSizeList("");
|
|
|
tblProductBO.setCountryId(0);
|
|
|
tblProductBO.setShowStatus("Y");
|
|
|
tblProductBO.setGoodsPrice(new BigDecimal(tplProductBo.getOrignPrice()).setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
tblProductBO.setOrignPrice(new BigDecimal(tplProductBo.getOrignPrice()).setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
tblProductBO.setTagPrice(new BigDecimal(0.00).setScale(2, BigDecimal.ROUND_DOWN));
|
|
|
tblProductBOList.add(tblProductBO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return tblProductBOList;
|
|
|
|
|
|
}
|
|
|
|
|
|
private String buildShowStatus(TblProduct tblProduct, Map<Integer, TblSite> tblSiteMap, Map<Integer, TblBrand> tblBrandMap) {
|
|
|
TblBrand tblBrand = tblBrandMap.get(tblProduct.getBrandId());
|
|
|
TblSite tblSite = tblSiteMap.get(tblProduct.getSiteId());
|
|
|
String showStatus = "Y";
|
|
|
if (tblProduct.getSource() == null) {
|
|
|
return showStatus;
|
|
|
}
|
|
|
//爬虫商品检查品牌网站是否关闭
|
|
|
if (tblProduct.getSource().equals("1")) {
|
|
|
if (tblBrand == null || tblSite == null) {
|
|
|
showStatus = "N";
|
|
|
}
|
|
|
}
|
|
|
//采购商品查看 品牌是否关闭
|
|
|
if (tblProduct.getSource().equals("2")) {
|
|
|
if (tblBrand == null) {
|
|
|
showStatus = "N";
|
|
|
}
|
|
|
}
|
|
|
return showStatus;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, String> getColorIdsMap(List<TblProduct> tblProductList) {
|
|
|
Map<Integer, String> colorIdsMap = new HashMap<>();
|
|
|
List<Integer> productSknList = tblProductList.stream().map(TblProduct::getProductSkn).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isNotEmpty(productSknList)) {
|
|
|
List<TblProductSkc> tblProductSkcList = tblProductSkcService.getBySkns(productSknList);
|
|
|
if (CollectionUtils.isNotEmpty(tblProductSkcList)) {
|
|
|
for (TblProductSkc tblProductSkc : tblProductSkcList) {
|
|
|
if (colorIdsMap.containsKey(tblProductSkc.getProductSkn())) {
|
|
|
String colorIds = colorIdsMap.get(tblProductSkc.getProductSkn());
|
|
|
colorIds += tblProductSkc.getColorSysId() + ",";
|
|
|
colorIdsMap.put(tblProductSkc.getProductSkn(), colorIds);
|
|
|
} else {
|
|
|
String colorIds;
|
|
|
colorIds = tblProductSkc.getColorSysId().toString();
|
|
|
colorIdsMap.put(tblProductSkc.getProductSkn(), colorIds);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return colorIdsMap;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, TblSite> getSiteMap() {
|
|
|
Map<Integer, TblSite> siteMap = new HashMap<>();
|
|
|
List<TblSite> tblSites = tblSiteService.selectPageList(0, Integer.MAX_VALUE);
|
|
|
if (CollectionUtils.isNotEmpty(tblSites)) {
|
|
|
siteMap = tblSites.stream().filter(p -> p.getStatus().equals("2")).collect(Collectors.toMap(TblSite::getSiteId, (p) -> p));
|
|
|
}
|
|
|
return siteMap;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, TblBrand> getTblBrandMap() {
|
|
|
Map<Integer, TblBrand> tblBrandMap = new HashMap<>();
|
|
|
List<TblBrand> tblBrands = tblBrandService.selectBrandPageList(0, Integer.MAX_VALUE);
|
|
|
if (CollectionUtils.isNotEmpty(tblBrands)) {
|
|
|
tblBrandMap = tblBrands.stream().filter(p -> p.getStatus().equals("2")).collect(Collectors.toMap(TblBrand::getBrandId, (p) -> p));
|
|
|
}
|
|
|
return tblBrandMap;
|
|
|
}
|
|
|
|
|
|
|
|
|
private List<Integer> getBrandIdList() {
|
|
|
List<Integer> brandIdList = new ArrayList<>();
|
|
|
List<TblBrand> tblBrands = tblBrandService.selectBrandPageList(0, Integer.MAX_VALUE);
|
|
|
if (CollectionUtils.isNotEmpty(tblBrands)) {
|
|
|
brandIdList = tblBrands.stream().filter(p -> p.getStatus().equals("2")).filter(p -> p.getYohoBrandId() != null).map(TblBrand::getYohoBrandId).collect(Collectors.toList());
|
|
|
}
|
|
|
return brandIdList;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, List<TblBrand>> getBrandMap() {
|
|
|
Map<Integer, List<TblBrand>> brandMap = new HashMap<>();
|
|
|
List<TblBrand> tblBrands = tblBrandService.selectBrandPageList(0, Integer.MAX_VALUE);
|
|
|
if (CollectionUtils.isNotEmpty(tblBrands)) {
|
|
|
for (TblBrand tblBrand : tblBrands) {
|
|
|
if (tblBrand.getYohoBrandId() == null || tblBrand.getYohoBrandId() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
if (brandMap.containsKey(tblBrand.getYohoBrandId())) {
|
|
|
List<TblBrand> tblBrandList = brandMap.get(tblBrand.getYohoBrandId());
|
|
|
tblBrandList.add(tblBrand);
|
|
|
} else {
|
|
|
List<TblBrand> tblBrandList = new ArrayList<>();
|
|
|
tblBrandList.add(tblBrand);
|
|
|
brandMap.put(tblBrand.getYohoBrandId(), tblBrandList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return brandMap;
|
|
|
return getPageList(offset, limit);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|