Authored by hugufei

删除GoodsCoverImageMapper

package com.yoho.search.dal;
import com.yoho.search.dal.model.GoodsCoverImage;
import java.util.List;
/**
* Created by wangnan on 2016/11/10.
*/
public interface GoodsCoverImageMapper {
List<GoodsCoverImage> selectGoodsCoverImage(List<Integer> Ids);
}
package com.yoho.search.dal.model;
/**
* Created by wangnan on 2016/6/30.
*/
public class GoodsCoverImage{
private Integer id;
private Integer goodsId;
private String cover_1;
private String cover_2;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getCover_2() {
return cover_2;
}
public void setCover_2(String cover_2) {
this.cover_2 = cover_2;
}
public String getCover_1() {
return cover_1;
}
public void setCover_1(String cover_1) {
this.cover_1 = cover_1;
}
}
package com.yoho.search.dal.model;
/**
* Created by wangnan on 2016/6/30.
*/
public class GoodsCoverImage{
private Integer goodsId;
private String cover_1;
private String cover_2;
public GoodsCoverImage() {
}
public GoodsCoverImage(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getCover_2() {
return cover_2;
}
public void setCover_2(String cover_2) {
this.cover_2 = cover_2;
}
public String getCover_1() {
return cover_1;
}
public void setCover_1(String cover_1) {
this.cover_1 = cover_1;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.search.dal.GoodsCoverImageMapper">
<resultMap id="GoodsCoverImage" type="com.yoho.search.dal.model.GoodsCoverImage">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="goods_id" property="goodsId" jdbcType="INTEGER"/>
<result column="cover_1" property="cover_1" jdbcType="VARCHAR"/>
<result column="cover_2" property="cover_2" jdbcType="VARCHAR"/>
</resultMap>
<select id="selectGoodsCoverImage" resultMap="GoodsCoverImage">
<![CDATA[
SELECT
`a`.`id` AS `id`,
`a`.`goods_id` AS `goods_id`,
(
CASE `a`.`gender_cover`
WHEN 1 THEN
`a`.`image_url`
END
) AS `cover_1`,
(
CASE `a`.`gender_cover`
WHEN 2 THEN
`a`.`image_url`
END
) AS `cover_2`
FROM
`goods_images` `a`
where
(`a`.`gender_cover` <> 0)
AND goods_id in]]>
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
package com.yoho.search.consumer.service.logicService;
import com.yoho.search.dal.GoodsImagesMapper;
import com.yoho.search.dal.model.GoodsCoverImage;
import com.yoho.search.dal.model.GoodsImages;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class GoodsCoverImageLogicService {
@Autowired
private GoodsImagesMapper goodsImagesMapper;
public Map<Integer, GoodsCoverImage> selectGoodsCoverImagesByProductIds(List<Integer> productIds) {
List<GoodsImages> goodsImages = goodsImagesMapper.selectListByProductIds(productIds);
if(goodsImages==null || goodsImages.isEmpty()){
return new HashMap<>();
}
return this.selectGoodsCoverImage(goodsImages);
}
public Map<Integer, GoodsCoverImage> selectGoodsCoverImage(List<GoodsImages> goodsImages) {
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = new HashMap<>();
// 构建goodsCoverImagesMap
List<GoodsImages> validGoodsImages = goodsImages.stream().filter(a -> a.getGenderCover() != null && a.getGenderCover() > 0).collect(Collectors.toList());
for (GoodsImages coverImage : validGoodsImages) {
String cover1 = coverImage.getGenderCover() == 1 ? coverImage.getImageUrl() : null;
String cover2 = coverImage.getGenderCover() == 2 ? coverImage.getImageUrl() : null;
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.computeIfAbsent(coverImage.getGoodsId(), a -> new GoodsCoverImage(coverImage.getGoodsId()));
if (StringUtils.isBlank(goodsCoverImage.getCover_1()) && !StringUtils.isBlank(cover1)) {
goodsCoverImage.setCover_1(cover1);
}
if (StringUtils.isBlank(goodsCoverImage.getCover_2()) && !StringUtils.isBlank((cover2))) {
goodsCoverImage.setCover_2(cover2);
}
}
return goodsCoverImagesMap;
}
}
... ...
package com.yoho.search.consumer.service.logicService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.consumer.service.bo.ProductGoodBO;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.daoService.StorageService;
import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
import com.yoho.search.dal.GoodsCoverImageMapper;
import com.yoho.search.dal.GoodsMapper;
import com.yoho.search.dal.model.Goods;
import com.yoho.search.dal.model.GoodsCoverImage;
import com.yoho.search.dal.model.Storage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2016/6/30.
*/
@Component
public class ProductGoodsLogicService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsCoverImageMapper goodsCoverImageMapper;
@Autowired
private StorageService storageService;
@Autowired
private BasicDataCacheService basicDataCacheService;
/**
* 全量增量都有调用
*/
public List<ProductGoodsBO> getProductGoodsBOList(List<Integer> productIds) {
// 构建productColorsMap
try {
if (productIds == null || productIds.isEmpty()) {
return new ArrayList<ProductGoodsBO>();
}
List<Goods> goodsList = goodsMapper.selectListByProductIds(productIds);
List<Integer> goodsIds = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
List<GoodsCoverImage> goodsCoverImageList = new ArrayList<GoodsCoverImage>();
List<Storage> storageList = new ArrayList<>();
if (goodsIds != null && !goodsIds.isEmpty()) {
goodsCoverImageList = goodsCoverImageMapper.selectGoodsCoverImage(goodsIds);
storageList = storageService.getStoragesByGoodsIds(goodsIds);
}
// 构建goodStorageMap
Map<Integer, Integer> goodStorageMap = new HashMap<>();
if (!CollectionUtils.isEmpty(storageList)) {
for (Storage storage : storageList) {
if (goodStorageMap.containsKey(storage.getGoodsId())) {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum() + goodStorageMap.get(storage.getGoodsId()));
} else {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum());
}
}
}
// 构建goodsCoverImagesMap
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = new HashMap<>();
for (GoodsCoverImage coverImage : goodsCoverImageList) {
if (goodsCoverImagesMap.containsKey(coverImage.getGoodsId())) {
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(coverImage.getGoodsId());
if (StringUtils.isBlank(goodsCoverImage.getCover_1()) && !StringUtils.isBlank((coverImage.getCover_1()))) {
goodsCoverImage.setCover_1(coverImage.getCover_1());
}
if (StringUtils.isBlank(goodsCoverImage.getCover_2()) && !StringUtils.isBlank((coverImage.getCover_2()))) {
goodsCoverImage.setCover_2(coverImage.getCover_2());
}
} else {
goodsCoverImagesMap.put(coverImage.getGoodsId(), coverImage);
}
}
// 根据productId分组
List<ProductGoodBO> productGoodBOs = new ArrayList<>();
for (Goods goods : goodsList) {
ProductGoodBO productGoodBO = new ProductGoodBO();
productGoodBO.setProduct_id(goods.getProductId());
JSONObject goodsJSONObject = this.fillGoodJSONObject(goods, basicDataCacheService.getColor(), goodsCoverImagesMap, goodStorageMap);
productGoodBO.setGoodJSONObject(goodsJSONObject);
productGoodBOs.add(productGoodBO);
}
Map<Integer, JSONArray> productGoodsMap = new HashMap<>();
for (ProductGoodBO productGoodBO : productGoodBOs) {
if (productGoodsMap.containsKey(productGoodBO.getProduct_id())) {
if (productGoodBO.getGoodJSONObject() != null) {
JSONArray jsonArray = productGoodsMap.get(productGoodBO.getProduct_id());
jsonArray.add(productGoodBO.getGoodJSONObject());
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
}
} else {
JSONArray jsonArray = new JSONArray();
jsonArray.add(productGoodBO.getGoodJSONObject());
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
}
}
List<ProductGoodsBO> productGoodsBOs = new ArrayList<>();
for (Map.Entry<Integer, JSONArray> entry : productGoodsMap.entrySet()) {
ProductGoodsBO pg = new ProductGoodsBO();
pg.setProductId(entry.getKey());
pg.setGoodsList(entry.getValue());
productGoodsBOs.add(pg);
}
return productGoodsBOs;
} catch (ExecutionException e) {
logger.error(e.getMessage(),e);
}
return new ArrayList<>();
}
/**
* 获取有库存且状态正常的color
*/
public void getColorSet(JSONArray goodsListJsonArray, Set<String> colorIdSet, Set<String> colorNameSet) {
for (int i = 0; i < goodsListJsonArray.size(); i++) {
JSONObject jsonObject = goodsListJsonArray.getJSONObject(i);
// 去除无库存和非正常状态的
if (!jsonObject.containsKey("status") || !jsonObject.get("status").toString().equals("1")) {
continue;
}
if (!jsonObject.containsKey("storage_num") || ((Integer) jsonObject.get("storage_num")) < 1) {
continue;
}
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
}
/**
* 转成good对象
*/
private JSONObject fillGoodJSONObject(Goods goods, Map<Integer, String> productColorsMap, Map<Integer, GoodsCoverImage> goodsCoverImagesMap, Map<Integer, Integer> goodStorageMap) {
JSONObject goodJSONObject = new JSONObject();
// 来自Goods
goodJSONObject.put("goods_id", String.valueOf(goods.getId()));
goodJSONObject.put("color_name", StringUtils.isBlank(goods.getColorName()) ? "" : goods.getColorName());
goodJSONObject.put("images_url", StringUtils.isBlank(goods.getColorImage()) ? "" : goods.getColorImage());
goodJSONObject.put("is_default", StringUtils.isBlank(goods.getIsDefault()) ? "" : goods.getIsDefault());
goodJSONObject.put("color_id", goods.getColorId() == null ? "" : goods.getColorId().toString());
goodJSONObject.put("status", goods.getStatus() == null ? "" : goods.getStatus().toString());
goodJSONObject.put("product_skc", goods.getProductSkc() == null ? "" : goods.getProductSkc());
goodJSONObject.put("color_value", "");
// 来自productColorsMap
String colorCode = productColorsMap.get(goods.getColorId());
goodJSONObject.put("color_code", StringUtils.isBlank(colorCode) ? "" : colorCode);
// 来自goodsCoverImagesMap
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(goods.getId());
String cover_1 = "";
String cover_2 = "";
if (goodsCoverImage != null) {
cover_1 = goodsCoverImage.getCover_1();
cover_2 = goodsCoverImage.getCover_2();
}
goodJSONObject.put("cover_1", StringUtils.isBlank(cover_1) ? "" : cover_1);
goodJSONObject.put("cover_2", StringUtils.isBlank(cover_2) ? "" : cover_2);
// 来自storageMap
Integer storage_num = goodStorageMap.get(goods.getId());
goodJSONObject.put("storage_num", storage_num == null ? 0 : storage_num);
return goodJSONObject;
}
}
package com.yoho.search.consumer.service.logicService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.consumer.service.bo.ProductGoodBO;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.daoService.StorageService;
import com.yoho.search.consumer.service.logicService.cache.BasicDataCacheService;
import com.yoho.search.dal.GoodsMapper;
import com.yoho.search.dal.model.Goods;
import com.yoho.search.dal.model.GoodsCoverImage;
import com.yoho.search.dal.model.Storage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
* Created by wangnan on 2016/6/30.
*/
@Component
public class ProductGoodsLogicService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsCoverImageLogicService goodsCoverImageLogicService;
@Autowired
private StorageService storageService;
@Autowired
private BasicDataCacheService basicDataCacheService;
/**
* 全量增量都有调用
*/
public List<ProductGoodsBO> getProductGoodsBOList(List<Integer> productIds) {
// 构建productColorsMap
try {
if (productIds == null || productIds.isEmpty()) {
return new ArrayList<ProductGoodsBO>();
}
List<Goods> goodsList = goodsMapper.selectListByProductIds(productIds);
List<Integer> goodsIds = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
List<Storage> storageList = new ArrayList<>();
if (goodsIds != null && !goodsIds.isEmpty()) {
storageList = storageService.getStoragesByGoodsIds(goodsIds);
}
// 构建goodStorageMap
Map<Integer, Integer> goodStorageMap = new HashMap<>();
if (!CollectionUtils.isEmpty(storageList)) {
for (Storage storage : storageList) {
if (goodStorageMap.containsKey(storage.getGoodsId())) {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum() + goodStorageMap.get(storage.getGoodsId()));
} else {
goodStorageMap.put(storage.getGoodsId(), storage.getStorageNum());
}
}
}
// 构建goodsCoverImagesMap
Map<Integer, GoodsCoverImage> goodsCoverImagesMap = goodsCoverImageLogicService.selectGoodsCoverImagesByProductIds(productIds);
// 根据productId分组
List<ProductGoodBO> productGoodBOs = new ArrayList<>();
for (Goods goods : goodsList) {
ProductGoodBO productGoodBO = new ProductGoodBO();
productGoodBO.setProduct_id(goods.getProductId());
JSONObject goodsJSONObject = this.fillGoodJSONObject(goods, basicDataCacheService.getColor(), goodsCoverImagesMap, goodStorageMap);
productGoodBO.setGoodJSONObject(goodsJSONObject);
productGoodBOs.add(productGoodBO);
}
Map<Integer, JSONArray> productGoodsMap = new HashMap<>();
for (ProductGoodBO productGoodBO : productGoodBOs) {
if (productGoodsMap.containsKey(productGoodBO.getProduct_id())) {
if (productGoodBO.getGoodJSONObject() != null) {
JSONArray jsonArray = productGoodsMap.get(productGoodBO.getProduct_id());
jsonArray.add(productGoodBO.getGoodJSONObject());
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
}
} else {
JSONArray jsonArray = new JSONArray();
jsonArray.add(productGoodBO.getGoodJSONObject());
productGoodsMap.put(productGoodBO.getProduct_id(), jsonArray);
}
}
List<ProductGoodsBO> productGoodsBOs = new ArrayList<>();
for (Map.Entry<Integer, JSONArray> entry : productGoodsMap.entrySet()) {
ProductGoodsBO pg = new ProductGoodsBO();
pg.setProductId(entry.getKey());
pg.setGoodsList(entry.getValue());
productGoodsBOs.add(pg);
}
return productGoodsBOs;
} catch (ExecutionException e) {
logger.error(e.getMessage(),e);
}
return new ArrayList<>();
}
/**
* 获取有库存且状态正常的color
*/
public void getColorSet(JSONArray goodsListJsonArray, Set<String> colorIdSet, Set<String> colorNameSet) {
for (int i = 0; i < goodsListJsonArray.size(); i++) {
JSONObject jsonObject = goodsListJsonArray.getJSONObject(i);
// 去除无库存和非正常状态的
if (!jsonObject.containsKey("status") || !jsonObject.get("status").toString().equals("1")) {
continue;
}
if (!jsonObject.containsKey("storage_num") || ((Integer) jsonObject.get("storage_num")) < 1) {
continue;
}
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
}
/**
* 转成good对象
*/
private JSONObject fillGoodJSONObject(Goods goods, Map<Integer, String> productColorsMap, Map<Integer, GoodsCoverImage> goodsCoverImagesMap, Map<Integer, Integer> goodStorageMap) {
JSONObject goodJSONObject = new JSONObject();
// 来自Goods
goodJSONObject.put("goods_id", String.valueOf(goods.getId()));
goodJSONObject.put("color_name", StringUtils.isBlank(goods.getColorName()) ? "" : goods.getColorName());
goodJSONObject.put("images_url", StringUtils.isBlank(goods.getColorImage()) ? "" : goods.getColorImage());
goodJSONObject.put("is_default", StringUtils.isBlank(goods.getIsDefault()) ? "" : goods.getIsDefault());
goodJSONObject.put("color_id", goods.getColorId() == null ? "" : goods.getColorId().toString());
goodJSONObject.put("status", goods.getStatus() == null ? "" : goods.getStatus().toString());
goodJSONObject.put("product_skc", goods.getProductSkc() == null ? "" : goods.getProductSkc());
goodJSONObject.put("color_value", "");
// 来自productColorsMap
String colorCode = productColorsMap.get(goods.getColorId());
goodJSONObject.put("color_code", StringUtils.isBlank(colorCode) ? "" : colorCode);
// 来自goodsCoverImagesMap
GoodsCoverImage goodsCoverImage = goodsCoverImagesMap.get(goods.getId());
String cover_1 = "";
String cover_2 = "";
if (goodsCoverImage != null) {
cover_1 = goodsCoverImage.getCover_1();
cover_2 = goodsCoverImage.getCover_2();
}
goodJSONObject.put("cover_1", StringUtils.isBlank(cover_1) ? "" : cover_1);
goodJSONObject.put("cover_2", StringUtils.isBlank(cover_2) ? "" : cover_2);
// 来自storageMap
Integer storage_num = goodStorageMap.get(goods.getId());
goodJSONObject.put("storage_num", storage_num == null ? 0 : storage_num);
return goodJSONObject;
}
}
... ...
package com.yoho.search.consumer.service.logicService;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
/**
* 特殊逻辑处理类
*
* @author gufei.hu
*
*/
@Service
public class SpecialDealLogicService {
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
public void specialDealForProductIBO(ProductIBO productIBO) {
// 1、特殊处理ageLevel
String ageLevel = productIBO.getAgeLevel();
if (!StringUtils.isBlank(ageLevel)) {
ageLevel = ageLevel.replace('|', ',');
productIBO.setAgeLevel(ageLevel);
}
// 2、处理物理分类对应的销售分类
if ("Y".equals(productIBO.getIsGlobal())) {
productIBO.setPhysicalChannels("1,2,3,4");
} else {
List<Integer> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
}
// 3、处理specialSearchField
String specialSearchField = this.getSpecialSearchField(productIBO);
productIBO.setSpecialSearchField(specialSearchField);
}
/**
* 构造ProductIBO相关的特殊搜索逻辑
*
* @param productIBO
* @return
*/
private String getSpecialSearchField(ProductIBO productIBO) {
StringBuilder specialSearchField = new StringBuilder();
if ("1".equalsIgnoreCase(productIBO.getIsInstalment())) {
specialSearchField.append("分期,fenqi,分期支付,fenqizhifu,有货分期,youhuofenqi,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsAdvance())) {
specialSearchField.append("预售,yushou,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsLimitbuy())) {
specialSearchField.append("限定发售,xiandingfashou,");
}
if ("Y".equalsIgnoreCase(productIBO.getIslimited())) {
specialSearchField.append("限购,xiangou,限量,xianliang");
}
if ("Y".equalsIgnoreCase(productIBO.getIsSeckill())) {
specialSearchField.append("秒杀,miaosha,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsGlobal())) {
specialSearchField.append("全球购,quanqiugou,");
}
if (productIBO.getBundleType() != null) {
// 处理折扣类型 0:正常商品 1:套餐 2:量贩 3:搭配
switch (productIBO.getBundleType()) {
case 1:
specialSearchField.append("套餐,taocan,");
break;
case 2:
specialSearchField.append("量贩,liangfan,");
break;
case 3:
specialSearchField.append("搭配,dapei,");
break;
default:
break;
}
}
return specialSearchField.toString();
}
/**
* 构造价格相关的特殊搜索逻辑
*
* @param productIBO
* @return
*/
public String getSpecialSearchFieldPrice(ProductPriceBO productPriceBO) {
StringBuilder specialSearchFieldPrice = new StringBuilder();
if ("Y".equalsIgnoreCase(productPriceBO.getIsDiscount())) {
specialSearchFieldPrice.append("折扣,zhekou,优惠,youhui,打折,dazhe,");
}
if ("Y".equalsIgnoreCase(productPriceBO.getIsStudentPrice())) {
specialSearchFieldPrice.append("学生,xuesheng,学生价,xueshengjia,");
}
return specialSearchFieldPrice.toString();
}
/**
* 构造视频相关的特殊搜索逻辑
*
* @param productIBO
* @return
*/
public String getSpecialSearchFieldVideo(boolean hasVideo) {
StringBuilder specialSearchFieldVideo = new StringBuilder();
if (hasVideo) {
specialSearchFieldVideo.append("视频,shipin,");
}
return specialSearchFieldVideo.toString();
}
}
package com.yoho.search.consumer.service.logicService;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductPriceBO;
/**
* 特殊逻辑处理类
*
* @author gufei.hu
*
*/
@Service
public class SpecialDealLogicService {
@Autowired
private SalesCategoryLogicService salesCategoryLogicService;
public void specialDealForProductIBO(ProductIBO productIBO) {
// 1、特殊处理ageLevel
String ageLevel = productIBO.getAgeLevel();
if (!StringUtils.isBlank(ageLevel)) {
ageLevel = ageLevel.replace('|', ',');
productIBO.setAgeLevel(ageLevel);
}
// 2、处理物理分类对应的销售分类
if ("Y".equals(productIBO.getIsGlobal())) {
productIBO.setPhysicalChannels("1,2,3,4");
} else {
List<Integer> physicalChannels = salesCategoryLogicService.getPhysicalChannelsBySmallSortId(productIBO.getSmallSortId());
productIBO.setPhysicalChannels(StringUtils.join(physicalChannels, ","));
}
// 3、处理specialSearchField
String specialSearchField = this.getSpecialSearchField(productIBO);
productIBO.setSpecialSearchField(specialSearchField);
}
/**
* 构造ProductIBO相关的特殊搜索逻辑
*
* @param productIBO
* @return
*/
private String getSpecialSearchField(ProductIBO productIBO) {
StringBuilder specialSearchField = new StringBuilder();
if ("1".equalsIgnoreCase(productIBO.getIsInstalment())) {
specialSearchField.append("分期,fenqi,分期支付,fenqizhifu,有货分期,youhuofenqi,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsAdvance())) {
specialSearchField.append("预售,yushou,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsLimitbuy())) {
specialSearchField.append("限定发售,xiandingfashou,");
}
if ("Y".equalsIgnoreCase(productIBO.getIslimited())) {
specialSearchField.append("限购,xiangou,限量,xianliang");
}
if ("Y".equalsIgnoreCase(productIBO.getIsSeckill())) {
specialSearchField.append("秒杀,miaosha,");
}
if ("Y".equalsIgnoreCase(productIBO.getIsGlobal())) {
specialSearchField.append("全球购,quanqiugou,");
}
if (productIBO.getBundleType() != null) {
// 处理折扣类型 0:正常商品 1:套餐 2:量贩 3:搭配
switch (productIBO.getBundleType()) {
case 1:
specialSearchField.append("套餐,taocan,");
break;
case 2:
specialSearchField.append("量贩,liangfan,");
break;
case 3:
specialSearchField.append("搭配,dapei,");
break;
default:
break;
}
}
return specialSearchField.toString();
}
/**
* 构造价格相关的特殊搜索逻辑
*
* @param productIBO
* @return
*/
public String getSpecialSearchFieldPrice(ProductPriceBO productPriceBO) {
StringBuilder specialSearchFieldPrice = new StringBuilder();
if ("Y".equalsIgnoreCase(productPriceBO.getIsDiscount())) {
specialSearchFieldPrice.append("折扣,zhekou,优惠,youhui,打折,dazhe,");
}
if ("Y".equalsIgnoreCase(productPriceBO.getIsStudentPrice())) {
specialSearchFieldPrice.append("学生,xuesheng,学生价,xueshengjia,");
}
return specialSearchFieldPrice.toString();
}
/**
* 构造视频相关的特殊搜索逻辑
*
* @param hasVideo
* @return
*/
public String getSpecialSearchFieldVideo(boolean hasVideo) {
StringBuilder specialSearchFieldVideo = new StringBuilder();
if (hasVideo) {
specialSearchFieldVideo.append("视频,shipin,");
}
return specialSearchFieldVideo.toString();
}
}
... ...