Authored by wangnan

Merge branch 'wn_shops_tbl' into 0110

... ... @@ -22,5 +22,7 @@ public interface ShopsBrandsMapper {
List<ShopsBrands> selectByShopId(Integer ids);
List<ShopsBrands> selectByShopIds(List<Integer> ids);
int count();
}
\ No newline at end of file
... ...
package com.yoho.search.dal;
import com.yoho.search.dal.model.TblBrand;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TblBrandMapper {
int deleteByPrimaryKey(Integer brandid);
... ... @@ -24,4 +23,5 @@ public interface TblBrandMapper {
int selectCount();
List<TblBrand> selectBrandPageList(@Param(value="offset") int offset, @Param(value="pageSize")int pageSize);
}
\ No newline at end of file
... ...
... ... @@ -140,4 +140,14 @@
from shops_brands
where shops_id = #{shopsId,jdbcType=INTEGER}
</select>
<select id="selectByShopIds" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List"/>
from shops_brands
WHERE shops_id in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -214,7 +214,6 @@
<select id="selectCount" resultType="java.lang.Integer" timeout="20000">
select count(*) from tbl_brand
</select>
<select id="selectBrandPageList" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List" />
... ...
package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.base.TblBrandService;
import com.yoho.search.consumer.service.bo.ShopsBO;
import com.yoho.search.consumer.service.logic.TblShopsLogicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by wangnan on 2017/1/4.
*/
@Component
public class TblShopsIndexBuilder extends IIndexBuilder {
@Autowired
private TblBrandService tblBrandService;
@Autowired
private TblShopsLogicService tblShopsLogicService;
@Override
public int getTotalCount() throws Exception {
return tblBrandService.selectCount();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
return tblShopsLogicService.getShopsBOs(offset, limit);
}
@Override
public String getId(Object object) {
return ((ShopsBO) object).getShopsId().toString();
}
}
... ...
... ... @@ -7,9 +7,14 @@ import com.yoho.error.event.SearchLogsEvent;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.service.base.TblBrandService;
import com.yoho.search.consumer.service.bo.ShopsBO;
import com.yoho.search.consumer.service.logic.TblShopsLogicService;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.dal.model.TblBrand;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -19,6 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
... ... @@ -34,6 +41,11 @@ public class TblBrandMqListener extends AbstractMqListener implements ChannelAwa
@Autowired
private TblBrandService tblBrandService;
@Autowired
private TblShopsLogicService tblShopsLogicService;
@Autowired
private IYohoIndexService indexService;
protected ApplicationEventPublisher publisher;
... ... @@ -76,6 +88,16 @@ public class TblBrandMqListener extends AbstractMqListener implements ChannelAwa
return;
}
tblBrandService.saveOrUpdate(tblBrand);
List<Integer> ids = new ArrayList<>();
ids.add(tblBrand.getBrandId());
List<ShopsBO> shopsBOS = tblShopsLogicService.getShopsBOs(ids);
if(CollectionUtils.isNotEmpty(shopsBOS)){
ShopsBO shopsBO = shopsBOS.get(0);
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(JSONObject.toJSONString(this.beanToMap(shopsBO)), shopsBO.getShopsId().toString(), ISearchConstants.INDEX_NAME_SHOPS, ISearchConstants.INDEX_NAME_SHOPS, false));
indexService.bulk(results);
}
String idValue = data.get(idField).toString();
logger.info("[func=updateData][step=success][tableName=tblBrand][id={}][cost={}ms]", idValue, (System.currentTimeMillis() - begin));
}
... ... @@ -86,7 +108,15 @@ public class TblBrandMqListener extends AbstractMqListener implements ChannelAwa
}
long begin = System.currentTimeMillis();
tblBrandService.delete(Integer.valueOf(id));
List<ESBluk> results = new ArrayList<ESBluk>();
results.add(new ESBluk(null, "-"+id, ISearchConstants.INDEX_NAME_SHOPS, ISearchConstants.INDEX_NAME_SHOPS, true));
indexService.bulk(results);
logger.info("[func=deleteData][step=success][tableName=tblBrand][id={}][cost={}ms]", id, (System.currentTimeMillis() - begin));
}
private Map<String, Object> beanToMap(ShopsBO shopsBO) {
JSONObject josnoJsonObject = (JSONObject) JSONObject.toJSON(shopsBO);
return josnoJsonObject;
}
}
... ...
... ... @@ -11,8 +11,17 @@
"type": "integer"
},
"shopName": {
"type": "string",
"analyzer": "ik_complex"
"fields": {
"shopName": {
"type": "string",
"analyzer": "ik_complex"
},
"shopName_fullMatch": {
"type": "string",
"analyzer": "lowercase_keyword"
}
},
"type": "multi_field"
},
"shopDomain": {
"type": "string"
... ...
... ... @@ -50,4 +50,5 @@ public class TblBrandService {
public List<TblBrand> selectBrandPageList(int start, int batchSize) {
return tblBrandMapper.selectBrandPageList(start, batchSize);
}
}
... ...
... ... @@ -15,6 +15,7 @@ public class ShopsBO extends Shops {
private String brandNameEn;
private String isGlobal = "N";
public String getBrandName() {
return brandName;
... ... @@ -49,4 +50,11 @@ public class ShopsBO extends Shops {
this.brandNameEn = brandNameEn;
}
public String getIsGlobal() {
return isGlobal;
}
public void setIsGlobal(String isGlobal) {
this.isGlobal = isGlobal;
}
}
... ...
... ... @@ -12,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2016/12/1.
... ... @@ -58,16 +61,40 @@ public class ShopsLogicService {
*/
private List<ShopsBO> generateShopsBOs(List<Shops> shopss) {
List<ShopsBO> shopsBOs = new ArrayList<>();
//brandMap
List<Brand> brands = brandMapper.getAll();
Map<Integer, Brand> brandMap = brands.stream().parallel().collect(Collectors.toMap(Brand::getId, (p) -> p));
//shopsBrandsMap
List<Integer> shopsIds = shopss.stream().parallel().map(Shops::getShopsId).collect(Collectors.toList());
List<ShopsBrands> shopsBrandss = shopsBrandsMapper.selectByShopIds(shopsIds);
Map<Integer,List<ShopsBrands>> shopsBrandsMap = new HashMap<>();
for(ShopsBrands shopsBrands:shopsBrandss){
if(shopsBrandsMap.containsKey(shopsBrands.getShopsId())){
List<ShopsBrands> sbs = shopsBrandsMap.get(shopsBrands.getShopsId());
sbs.add(shopsBrands);
}else{
List<ShopsBrands> sbs = new ArrayList<>();
sbs.add(shopsBrands);
shopsBrandsMap.put(shopsBrands.getShopsId(),sbs);
}
}
//tblBrandMap
for (Shops shop : shopss) {
List<ShopsBrands> shopsBrandss = shopsBrandsMapper.selectByShopId(shop.getShopsId());
List<ShopsBrands> sbs = shopsBrandsMap.get(shop.getShopsId());
ShopsBO shopsBO = new ShopsBO();
if(!CollectionUtils.isEmpty(shopsBrandss)){
if(!CollectionUtils.isEmpty(sbs)){
StringBuilder brandName = new StringBuilder();
StringBuilder brandNameCn = new StringBuilder();
StringBuilder brandNameEn = new StringBuilder();
StringBuilder brandDomain = new StringBuilder();
for (ShopsBrands shopsBrand : shopsBrandss) {
Brand brand = brandMapper.selectByPrimaryKey(shopsBrand.getBrandId());
for (ShopsBrands shopsBrand : sbs) {
Brand brand = brandMap.get(shopsBrand.getBrandId());
if (brand != null) {
brandName.append(brand.getBrandName() + ",");
brandNameCn.append(brand.getBrandNameCn() + ",");
... ... @@ -97,9 +124,7 @@ public class ShopsLogicService {
shopsBO.setCreateTime(shop.getCreateTime());
shopsBO.setUpdateTime(shop.getUpdateTime());
shopsBO.setBlkStatus(shop.getBlkStatus());
//shopsBO.setShopIntro(shop.getShopIntro());
//shopsBO.setShopIntro(shop.getShopIntro()); 数据太大不保存
shopsBOs.add(shopsBO);
}
return shopsBOs;
... ...
... ... @@ -23,495 +23,509 @@ 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;
}
public final static Map<Integer, String> countryFieldMap = new HashMap<Integer, String>() {{
put(374, "美国");
put(44, "英国");
put(46, "瑞典");
put(81, "日本");
put(82, "韩国");
put(852, "香港");
put(49, "德国");
put(86, "国内现货");
}};
/**
* 增量构建
*
* @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 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;
}
/**
* 构建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;
}
/**
* 增量构建
*
* @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;
}
/**
* 获取品牌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;
}
/**
* 构建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;
}
/**
* 获取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;
}
/**
* 获取品牌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;
}
/**
* 获取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;
}
/**
* 获取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;
}
/**
* 获取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;
}
/**
* 获取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;
}
/**
* 获取品类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;
}
/**
* 获取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;
}
/**
* 处理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);
}
return productIndexBO;
}
/**
* 获取品类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());
productIndexBO.setShopId(tblBrand.getBrandId()*(-1));
} else {
// 增量当品牌删除的时候
productIndexBO.setBrandName(null);
productIndexBO.setBrandNameEn(null);
productIndexBO.setBrandNameCn(null);
}
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);
//处理国家id和名称
//productIndexBO.setTblCountryId(tblProduct.getCountryId());
//productIndexBO.setTblCountryName(countryFieldMap.get(tblProduct.getCountryId()));
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);
}
}
... ...
package com.yoho.search.consumer.service.logic;
import com.yoho.search.consumer.service.base.TblBrandService;
import com.yoho.search.consumer.service.bo.ShopsBO;
import com.yoho.search.dal.BrandMapper;
import com.yoho.search.dal.ShopMapper;
import com.yoho.search.dal.ShopsBrandsMapper;
import com.yoho.search.dal.model.TblBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Created by wangnan on 2017/1/4.
*/
@Component
public class TblShopsLogicService {
@Autowired
private ShopMapper shopMapper;
@Autowired
private ShopsBrandsMapper shopsBrandsMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
private TblBrandService tblBrandService;
/**
* 增量
*
* @param ids
* @return
*/
public List<ShopsBO> getShopsBOs(List<Integer> ids) {
List<TblBrand> tblBrands = tblBrandService.selectByIds(ids);
return generateShopsBOs(tblBrands);
}
/**
* 全量
*
* @param start
* @param limit
* @return
*/
public List<ShopsBO> getShopsBOs(int start, int limit) {
List<TblBrand> tblBrands = tblBrandService.selectBrandPageList(start, limit);
return generateShopsBOs(tblBrands);
}
/**
* 生成BO
*
* @return
*/
private List<ShopsBO> generateShopsBOs(List<TblBrand> tblBrands) {
List<ShopsBO> shopsBOs = new ArrayList<>();
for (TblBrand tblBrand : tblBrands) {
ShopsBO shopsBO = new ShopsBO();
shopsBO.setBrandName(tblBrand.getBrandNameEn());
shopsBO.setBrandNameCn(tblBrand.getBrandNameCn());
shopsBO.setBrandNameEn(tblBrand.getBrandNameEn());
shopsBO.setBrandDomain("");
shopsBO.setShopsId(tblBrand.getBrandId() * (-1));
shopsBO.setShopName(tblBrand.getBrandNameEn());
shopsBO.setShopDomain("");
shopsBO.setShopNature(0);
shopsBO.setShopLogo(tblBrand.getLogo());
shopsBO.setWebsiteUrl("");
shopsBO.setOtherUrl("");
shopsBO.setShopAddress("");
shopsBO.setCreatePid(0);
shopsBO.setShopsType(1);
shopsBO.setOperationStatus(2);
shopsBO.setExamineStatus(1);
if (tblBrand.getStatus().equals("1")) {
shopsBO.setStatus(0);
}
if (tblBrand.getStatus().equals("2")) {
shopsBO.setStatus(1);
}
shopsBO.setCheckStatus(0);
shopsBO.setCreateTime(tblBrand.getCreateTime());
shopsBO.setUpdateTime(tblBrand.getUpdateTime());
shopsBO.setBlkStatus(0);
shopsBO.setIsGlobal("Y");
//shopsBO.setShopIntro(shop.getShopIntro()); 数据太大不保存
shopsBOs.add(shopsBO);
}
return shopsBOs;
}
}
... ...
... ... @@ -181,7 +181,7 @@
<property key="refresh_interval" value="1s"/>
<property key="translog.flush_threshold_ops" value="5000"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ShopsIndexBuilder</builderClass>
<builderClass>com.yoho.search.consumer.index.fullbuild.ShopsIndexBuilder,com.yoho.search.consumer.index.fullbuild.TblShopsIndexBuilder</builderClass>
<mappingFile>esmapping/shops.json</mappingFile>
</index>
... ...
... ... @@ -159,7 +159,7 @@
<property key="refresh_interval" value="${search.index.refresh_interval}"/>
<property key="translog.flush_threshold_ops" value="${search.index.translog.flush_threshold_ops}"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ShopsIndexBuilder</builderClass>
<builderClass>com.yoho.search.consumer.index.fullbuild.ShopsIndexBuilder,com.yoho.search.consumer.index.fullbuild.TblShopsIndexBuilder</builderClass>
<mappingFile>esmapping/shops.json</mappingFile>
</index>
... ...