Authored by hugufei

店铺索引新增shopDesc和shopBackImg字段

... ... @@ -3,6 +3,8 @@ package com.yoho.search.dal.model;
public class ShopsAdditionalImageBO extends Shops{
private String searchShowImage;
private String shopDesc;
private String shopBackImg;
public String getSearchShowImage() {
return searchShowImage;
... ... @@ -11,4 +13,20 @@ public class ShopsAdditionalImageBO extends Shops{
public void setSearchShowImage(String searchShowImage) {
this.searchShowImage = searchShowImage;
}
public String getShopDesc() {
return shopDesc;
}
public void setShopDesc(String shopDesc) {
this.shopDesc = shopDesc;
}
public String getShopBackImg() {
return shopBackImg;
}
public void setShopBackImg(String shopBackImg) {
this.shopBackImg = shopBackImg;
}
}
... ...
<?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.ShopAdditionalImageMapper" >
<mapper namespace="com.yoho.search.dal.ShopAdditionalImageMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ShopAdditionalImage" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ShopAdditionalImage">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="shop_id" property="shopId" jdbcType="INTEGER"/>
<result column="search_show_image" property="searchShowImage" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="search_show_image" property="searchShowImage" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="INTEGER"/>
<result column="shop_desc" property="shopDesc" jdbcType="VARCHAR"/>
<result column="shop_back_img" property="shopBackImg" jdbcType="VARCHAR"/>
</resultMap>
<sql id="Base_Column_List" >
id, shop_id, search_show_image, create_time, update_time
<sql id="Base_Column_List">
id, shop_id, search_show_image, create_time, update_time, shop_desc, shop_back_img
</sql>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from shop_additional_image
where id = #{id,jdbcType=INTEGER}
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from shop_additional_image where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.ShopAdditionalImage" >
insert into shop_additional_image (id, shop_id, search_show_image, create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{searchShowImage,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
<insert id="insert" parameterType="com.yoho.search.dal.model.ShopAdditionalImage">
insert into shop_additional_image (id, shop_id, search_show_image, create_time, update_time, shop_desc, shop_back_img)
values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{searchShowImage,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{shopDesc,jdbcType=VARCHAR}, #{shopBackImg,jdbcType=VARCHAR})
</insert>
<select id="selectByShopIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from shop_additional_image where shop_id in
<foreach item="item" index="index" collection="shopsIds"
open="(" separator="," close=")">
... ... @@ -35,30 +38,36 @@
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from shop_additional_image
where id = #{id,jdbcType=INTEGER}
limit 1
</select>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ShopAdditionalImage" >
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ShopAdditionalImage">
update shop_additional_image
<set >
<if test="shopId != null" >
<set>
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER},
</if>
<if test="searchShowImage != null" >
<if test="searchShowImage != null">
search_show_image = #{searchShowImage,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
<if test="shopDesc != null">
shop_desc = #{shopDesc,jdbcType=VARCHAR},
</if>
<if test="shopBackImg != null">
shop_back_img = #{shopBackImg,jdbcType=VARCHAR},
</if>
</set>
where id = #{id, jdbcType=INTEGER}
</update>
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.service.daoService.ShopService;
import com.yoho.search.dal.model.Shops;
import com.yoho.search.dal.model.ShopsAdditionalImageBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -27,7 +28,7 @@ public class ShopsIndexBuilder extends IIndexBuilder {
@Override
public String getId(Object object) {
return ((Shops)object).getShopsId().toString();
return ((ShopsAdditionalImageBO)object).getShopsId().toString();
}
}
... ...
... ... @@ -5,7 +5,6 @@ import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.common.IYohoIndexService;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.ShopAdditionalImageMapper;
import com.yoho.search.dal.model.ShopAdditionalImage;
... ... @@ -13,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@SearchMqConsumerListerner(dbName = "erp_product", tableName = "shop_additional_image")
... ... @@ -32,10 +34,11 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
ShopAdditionalImage shopAdditionalImage = shopAdditionalImageMapper.selectByPrimaryKey(Integer.valueOf(id));
if (shopAdditionalImage != null) {
shopAdditionalImageMapper.deleteByPrimaryKey(Integer.valueOf(id));
updateIndex(shopAdditionalImage.getShopId());
if (shopAdditionalImage == null) {
return;
}
shopAdditionalImageMapper.deleteByPrimaryKey(Integer.valueOf(id));
updateIndex(shopAdditionalImage.getShopId());
}
@Override
... ... @@ -52,23 +55,19 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener {
updateIndex(shopAdditionalImage.getShopId());
}
private void updateIndex(Integer shopId) {
private void updateIndex(Integer shopId) throws Exception {
List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(Arrays.asList(shopId));
Map<String, Object> indexData = new HashMap<>();
List<ESBluk> results = new ArrayList<>();
if (CollectionUtils.isEmpty(shopAdditionalImages)) {
indexData.put("searchShowImage", "");
results.add(new ESBluk(JSONObject.toJSONString(indexData), shopId.toString(), getIndexName(), getIndexName(), false));
} else {
indexData.put("searchShowImage", "");
indexData.put("shopDesc", "");
indexData.put("shopBackImg", "");
if (!CollectionUtils.isEmpty(shopAdditionalImages)) {
ShopAdditionalImage shopAdditionalImage = shopAdditionalImages.get(0);
if (shopAdditionalImage != null) {
String image = shopAdditionalImage.getSearchShowImage();
indexData.put("searchShowImage", image);
results.add(new ESBluk(JSONObject.toJSONString(indexData), shopId.toString(), getIndexName(), getIndexName(), false));
}
indexData.put("searchShowImage", shopAdditionalImage.getSearchShowImage());
indexData.put("shopDesc", shopAdditionalImage.getShopDesc());
indexData.put("shopBackImg",shopAdditionalImage.getShopBackImg());
}
indexService.bulk(results);
indexService.updateIndexData(this.getIndexName(),shopId.toString(),indexData);
}
}
... ...
... ... @@ -75,6 +75,12 @@
},
"searchShowImage": {
"type": "keyword"
},
"shopDesc": {
"type": "keyword"
},
"shopBackImg": {
"type": "keyword"
}
}
}
... ...
... ... @@ -10,7 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
... ... @@ -54,21 +57,28 @@ public class ShopService {
public List<ShopsAdditionalImageBO> getshopAdditionalImagePageLists(int start, int limit) {
List<Shops> shops = shopMapper.selectPageLists(start, limit);
Map<Integer, String> shopImageMap = new HashMap<>();
List<ShopsAdditionalImageBO> shopsAdditionalImageBOS = new ArrayList<>();
if (!CollectionUtils.isEmpty(shops)) {
List<Integer> shopIds = shops.stream().map(Shops::getShopsId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (!CollectionUtils.isEmpty(shopIds)) {
List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(shopIds);
if (!CollectionUtils.isEmpty(shopAdditionalImages)) {
shopImageMap = shopAdditionalImages.stream().collect(Collectors.toMap(ShopAdditionalImage::getShopId, ShopAdditionalImage::getSearchShowImage, (k1, k2) -> k1));
}
}
if (CollectionUtils.isEmpty(shops)) {
return new ArrayList<>();
}
List<Integer> shopIds = shops.stream().map(Shops::getShopsId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
// 获取店铺装修信息
List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(shopIds);
Map<Integer, ShopAdditionalImage> shopAdditionalImageMap = shopAdditionalImages.stream().collect(Collectors.toMap(ShopAdditionalImage::getId, a -> a, (k1, k2) -> k1));
// 构造结果
List<ShopsAdditionalImageBO> shopsAdditionalImageBOS = new ArrayList<>();
for (Shops shop : shops) {
ShopsAdditionalImageBO shopsAdditionalImageBO = new ShopsAdditionalImageBO();
BeanUtils.copyProperties(shop, shopsAdditionalImageBO);
shopsAdditionalImageBO.setSearchShowImage(shopImageMap.get(shop.getShopsId()));
ShopAdditionalImage shopAdditionalImage = shopAdditionalImageMap.get(shop.getShopsId());
if (shopAdditionalImage != null) {
shopsAdditionalImageBO.setSearchShowImage(shopAdditionalImage.getSearchShowImage());
shopsAdditionalImageBO.setShopBackImg(shopAdditionalImage.getShopBackImg());
shopsAdditionalImageBO.setShopDesc(shopAdditionalImage.getShopDesc());
} else {
shopsAdditionalImageBO.setSearchShowImage("");
shopsAdditionalImageBO.setShopBackImg("");
shopsAdditionalImageBO.setShopDesc("");
}
shopsAdditionalImageBOS.add(shopsAdditionalImageBO);
}
return shopsAdditionalImageBOS;
... ...