Authored by wangnan9279

tblproduct索引用表数据重建

... ... @@ -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);
}
... ...
package com.yoho.search.consumer.index.fullbuild;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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 org.apache.commons.lang.StringUtils;
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;
/**
* @Author: wangnan
* @Date: Created in 2018/4/20
*/
@Component
public class TblProductIndexNewBuilder extends IIndexBuilder {
@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 {
return tblProductService.count();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
//查询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;
}
@Override
public String getId(Object object) {
return UUID.randomUUID().toString();
}
}
... ...
... ... @@ -87,6 +87,7 @@ public class IndexRebuildJob implements ApplicationEventPublisherAware {
public void rebuildTblProductIndex() {
long begin = System.currentTimeMillis();
logger.info("indexRebuildJob rebuildTblProductIndex start----[begin={}]", begin);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_TBLPRODUCT_NEW);
this.rebuildIndexWithlog(ISearchConstants.INDEX_NAME_TBLPRODUCT);
logger.info("indexRebuildJob rebuildTblProductIndex end----[end={}][cost={}]", System.currentTimeMillis(), (System.currentTimeMillis() - begin));
}
... ...
index:
analysis:
filter:
dynamic_synonym:
type: dynamic-synonym
synonym_expand: true
synonym_ignore_case: true
synonym_analyzer: ik_smart
dynamic_synonym_rewrite:
type: dynamic-synonym-rewrite
synonym_expand: true
synonym_ignore_case: true
synonym_analyzer: ik_smart
analyzer:
comma_spliter:
type: pattern
pattern: "[,|\\s]+"
ik_complex:
type: custom
tokenizer: ik_smart
filter:
- lowercase
- dynamic_synonym
- trim
- unique
ik_complex_search:
type: custom
tokenizer: ik_smart
filter:
- lowercase
- dynamic_synonym_rewrite
- trim
- unique
index.analysis.analyzer.default.type: keyword
... ...
{
"tblproductnew": {
"_all": {
"enabled": false
},
"_source": {
"enabled": true
},
"properties": {
"product_skn": {
"type": "integer"
},
"product_name": {
"type": "text",
"analyzer": "ik_complex",
"search_analyzer": "ik_complex_search"
},
"goods_price": {
"type": "double"
},
"brand_id": {
"type": "long"
},
"site_id": {
"type": "long"
},
"sort_one": {
"type": "long"
},
"sort_two": {
"type": "long"
},
"sort_three": {
"type": "long"
},
"sort_four": {
"type": "long"
},
"is_limited": {
"type": "long"
},
"country_id": {
"type": "long"
},
"gender": {
"type": "keyword"
},
"currency_id": {
"type": "long"
},
"tag_price": {
"type": "double"
},
"orign_price": {
"type": "double"
},
"status": {
"type": "long"
},
"stock_status": {
"type": "long"
},
"update_time": {
"type": "long"
},
"shelf_time": {
"type": "long"
},
"color_ids": {
"type": "text",
"analyzer": "comma_spliter",
"fielddata": "true"
},
"is_global": {
"type": "keyword"
},
"skc": {
"properties": {
"cover": {
"type": "text"
},
"color": {
"type": "text"
},
"product_skc": {
"type": "text"
},
"format_cover": {
"type": "text"
},
"color_sys_id": {
"type": "text"
}
}
},
"size_list": {
"type": "keyword"
},
"format_cover": {
"type": "text"
},
"cover": {
"type": "text"
},
"is_plane": {
"type": "text"
},
"show_status": {
"type": "text"
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -11,10 +11,6 @@ public class ConsumerConfiger {
private SearchPropertyPlaceholderConfigurer configurer;
/******************************for full build**************************************/
public boolean getTblRebuildUseUrl() {
return configurer.getBoolean("tbl.rebuild.ues.url", false);
}
public int getSearchIndexBatchLimit(){
return configurer.getInt("search.index.batch.limit", 5000);
}
... ...
... ... @@ -18,7 +18,6 @@ search.index.batch.max.thread.size=10
tbl.product.private.key=a85bb0674e08986c6b115d5e3a4884fa
tbl.product.url=http://test.soa.global.yohobuy.com/product/api/v1/detail/
ip.port.search.server = "192.168.102.216:8080"
tbl.rebuild.ues.url = false
#adaptor
tpl.adaptor.valid=true
... ...
datasources:
yhb_search_2016:
yhb_search:
servers:
- 192.168.102.216:3306
- 192.168.102.216:3306
... ...
... ... @@ -127,6 +127,19 @@
</index>
<index>
<name>tblproductnew</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="1"/>
<property key="refresh_interval" value="10s"/>
<property key="translog.flush_threshold_size" value="100mb"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.TblProductIndexNewBuilder</builderClass>
<mappingFile>esmapping/tblproductnew.json</mappingFile>
<analysisFile>analysis/tblproductnew.yml</analysisFile>
</index>
<index>
<name>standard</name>
<properties>
<property key="number_of_shards" value="1"/>
... ...
... ... @@ -18,7 +18,6 @@ search.index.batch.max.thread.size=${search.index.batch.max.thread.size}
tbl.product.private.key=a85bb0674e08986c6b115d5e3a4884fa
tbl.product.url=${tbl.product.url}
ip.port.search.server = ${ip.port.search.server}
tbl.rebuild.ues.url = ${tbl.rebuild.ues.url}
#adaptor
tpl.adaptor.valid=${tpl.adaptor.valid}
... ...
... ... @@ -127,6 +127,19 @@
</index>
<index>
<name>tblproductnew</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="${search.index.number_of_replicas}"/>
<property key="refresh_interval" value="${search.index.refresh_interval}"/>
<property key="translog.flush_threshold_size" value="${search.index.translog.flush_threshold_size}"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.TblProductIndexNewBuilder</builderClass>
<mappingFile>esmapping/tblproductnew.json</mappingFile>
<analysisFile>analysis/tblproductnew.yml</analysisFile>
</index>
<index>
<name>standard</name>
<properties>
<property key="number_of_shards" value="1"/>
... ...
datasources:
yhb_search_2016:
yhb_search:
servers:
- 192.168.102.216:3306
- 192.168.102.216:3306
... ...