店铺索引新增shopDesc和shopBackImg字段
Showing
6 changed files
with
96 additions
and
53 deletions
@@ -3,6 +3,8 @@ package com.yoho.search.dal.model; | @@ -3,6 +3,8 @@ package com.yoho.search.dal.model; | ||
3 | public class ShopsAdditionalImageBO extends Shops{ | 3 | public class ShopsAdditionalImageBO extends Shops{ |
4 | 4 | ||
5 | private String searchShowImage; | 5 | private String searchShowImage; |
6 | + private String shopDesc; | ||
7 | + private String shopBackImg; | ||
6 | 8 | ||
7 | public String getSearchShowImage() { | 9 | public String getSearchShowImage() { |
8 | return searchShowImage; | 10 | return searchShowImage; |
@@ -11,4 +13,20 @@ public class ShopsAdditionalImageBO extends Shops{ | @@ -11,4 +13,20 @@ public class ShopsAdditionalImageBO extends Shops{ | ||
11 | public void setSearchShowImage(String searchShowImage) { | 13 | public void setSearchShowImage(String searchShowImage) { |
12 | this.searchShowImage = searchShowImage; | 14 | this.searchShowImage = searchShowImage; |
13 | } | 15 | } |
16 | + | ||
17 | + public String getShopDesc() { | ||
18 | + return shopDesc; | ||
19 | + } | ||
20 | + | ||
21 | + public void setShopDesc(String shopDesc) { | ||
22 | + this.shopDesc = shopDesc; | ||
23 | + } | ||
24 | + | ||
25 | + public String getShopBackImg() { | ||
26 | + return shopBackImg; | ||
27 | + } | ||
28 | + | ||
29 | + public void setShopBackImg(String shopBackImg) { | ||
30 | + this.shopBackImg = shopBackImg; | ||
31 | + } | ||
14 | } | 32 | } |
1 | <?xml version="1.0" encoding="UTF-8" ?> | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
3 | -<mapper namespace="com.yoho.search.dal.ShopAdditionalImageMapper" > | 3 | +<mapper namespace="com.yoho.search.dal.ShopAdditionalImageMapper"> |
4 | 4 | ||
5 | - <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ShopAdditionalImage" > | 5 | + <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.ShopAdditionalImage"> |
6 | <id column="id" property="id" jdbcType="INTEGER"/> | 6 | <id column="id" property="id" jdbcType="INTEGER"/> |
7 | <result column="shop_id" property="shopId" jdbcType="INTEGER"/> | 7 | <result column="shop_id" property="shopId" jdbcType="INTEGER"/> |
8 | - <result column="search_show_image" property="searchShowImage" jdbcType="VARCHAR" /> | ||
9 | - <result column="create_time" property="createTime" jdbcType="INTEGER" /> | ||
10 | - <result column="update_time" property="updateTime" jdbcType="INTEGER" /> | 8 | + <result column="search_show_image" property="searchShowImage" jdbcType="VARCHAR"/> |
9 | + <result column="create_time" property="createTime" jdbcType="INTEGER"/> | ||
10 | + <result column="update_time" property="updateTime" jdbcType="INTEGER"/> | ||
11 | + <result column="shop_desc" property="shopDesc" jdbcType="VARCHAR"/> | ||
12 | + <result column="shop_back_img" property="shopBackImg" jdbcType="VARCHAR"/> | ||
11 | </resultMap> | 13 | </resultMap> |
12 | 14 | ||
13 | - <sql id="Base_Column_List" > | ||
14 | - id, shop_id, search_show_image, create_time, update_time | 15 | + <sql id="Base_Column_List"> |
16 | + id, shop_id, search_show_image, create_time, update_time, shop_desc, shop_back_img | ||
15 | </sql> | 17 | </sql> |
16 | 18 | ||
17 | - <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | ||
18 | - delete from shop_additional_image | ||
19 | - where id = #{id,jdbcType=INTEGER} | 19 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> |
20 | + delete from shop_additional_image where id = #{id,jdbcType=INTEGER} | ||
20 | </delete> | 21 | </delete> |
21 | 22 | ||
22 | - <insert id="insert" parameterType="com.yoho.search.dal.model.ShopAdditionalImage" > | ||
23 | - insert into shop_additional_image (id, shop_id, search_show_image, create_time, update_time) | ||
24 | - values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{searchShowImage,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}) | 23 | + <insert id="insert" parameterType="com.yoho.search.dal.model.ShopAdditionalImage"> |
24 | + insert into shop_additional_image (id, shop_id, search_show_image, create_time, update_time, shop_desc, shop_back_img) | ||
25 | + values (#{id,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{searchShowImage,jdbcType=VARCHAR}, | ||
26 | + #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, | ||
27 | + #{shopDesc,jdbcType=VARCHAR}, #{shopBackImg,jdbcType=VARCHAR}) | ||
25 | </insert> | 28 | </insert> |
26 | 29 | ||
27 | <select id="selectByShopIds" resultMap="BaseResultMap"> | 30 | <select id="selectByShopIds" resultMap="BaseResultMap"> |
28 | select | 31 | select |
29 | - <include refid="Base_Column_List" /> | 32 | + <include refid="Base_Column_List"/> |
30 | from shop_additional_image where shop_id in | 33 | from shop_additional_image where shop_id in |
31 | <foreach item="item" index="index" collection="shopsIds" | 34 | <foreach item="item" index="index" collection="shopsIds" |
32 | open="(" separator="," close=")"> | 35 | open="(" separator="," close=")"> |
@@ -35,30 +38,36 @@ | @@ -35,30 +38,36 @@ | ||
35 | </select> | 38 | </select> |
36 | 39 | ||
37 | 40 | ||
38 | - <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 41 | + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer"> |
39 | select | 42 | select |
40 | - <include refid="Base_Column_List" /> | 43 | + <include refid="Base_Column_List"/> |
41 | from shop_additional_image | 44 | from shop_additional_image |
42 | where id = #{id,jdbcType=INTEGER} | 45 | where id = #{id,jdbcType=INTEGER} |
43 | limit 1 | 46 | limit 1 |
44 | </select> | 47 | </select> |
45 | 48 | ||
46 | 49 | ||
47 | - <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ShopAdditionalImage" > | 50 | + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.ShopAdditionalImage"> |
48 | update shop_additional_image | 51 | update shop_additional_image |
49 | - <set > | ||
50 | - <if test="shopId != null" > | 52 | + <set> |
53 | + <if test="shopId != null"> | ||
51 | shop_id = #{shopId,jdbcType=INTEGER}, | 54 | shop_id = #{shopId,jdbcType=INTEGER}, |
52 | </if> | 55 | </if> |
53 | - <if test="searchShowImage != null" > | 56 | + <if test="searchShowImage != null"> |
54 | search_show_image = #{searchShowImage,jdbcType=VARCHAR}, | 57 | search_show_image = #{searchShowImage,jdbcType=VARCHAR}, |
55 | </if> | 58 | </if> |
56 | - <if test="createTime != null" > | 59 | + <if test="createTime != null"> |
57 | create_time = #{createTime,jdbcType=INTEGER}, | 60 | create_time = #{createTime,jdbcType=INTEGER}, |
58 | </if> | 61 | </if> |
59 | - <if test="updateTime != null" > | 62 | + <if test="updateTime != null"> |
60 | update_time = #{updateTime,jdbcType=INTEGER}, | 63 | update_time = #{updateTime,jdbcType=INTEGER}, |
61 | </if> | 64 | </if> |
65 | + <if test="shopDesc != null"> | ||
66 | + shop_desc = #{shopDesc,jdbcType=VARCHAR}, | ||
67 | + </if> | ||
68 | + <if test="shopBackImg != null"> | ||
69 | + shop_back_img = #{shopBackImg,jdbcType=VARCHAR}, | ||
70 | + </if> | ||
62 | </set> | 71 | </set> |
63 | where id = #{id, jdbcType=INTEGER} | 72 | where id = #{id, jdbcType=INTEGER} |
64 | </update> | 73 | </update> |
@@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild; | @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild; | ||
2 | 2 | ||
3 | import com.yoho.search.consumer.service.daoService.ShopService; | 3 | import com.yoho.search.consumer.service.daoService.ShopService; |
4 | import com.yoho.search.dal.model.Shops; | 4 | import com.yoho.search.dal.model.Shops; |
5 | +import com.yoho.search.dal.model.ShopsAdditionalImageBO; | ||
5 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
6 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
7 | 8 | ||
@@ -27,7 +28,7 @@ public class ShopsIndexBuilder extends IIndexBuilder { | @@ -27,7 +28,7 @@ public class ShopsIndexBuilder extends IIndexBuilder { | ||
27 | 28 | ||
28 | @Override | 29 | @Override |
29 | public String getId(Object object) { | 30 | public String getId(Object object) { |
30 | - return ((Shops)object).getShopsId().toString(); | 31 | + return ((ShopsAdditionalImageBO)object).getShopsId().toString(); |
31 | } | 32 | } |
32 | 33 | ||
33 | } | 34 | } |
@@ -5,7 +5,6 @@ import com.yoho.search.base.utils.ConvertUtils; | @@ -5,7 +5,6 @@ import com.yoho.search.base.utils.ConvertUtils; | ||
5 | import com.yoho.search.base.utils.ISearchConstants; | 5 | import com.yoho.search.base.utils.ISearchConstants; |
6 | import com.yoho.search.consumer.common.IYohoIndexService; | 6 | import com.yoho.search.consumer.common.IYohoIndexService; |
7 | import com.yoho.search.consumer.index.increment.AbstractMqListener; | 7 | import com.yoho.search.consumer.index.increment.AbstractMqListener; |
8 | -import com.yoho.search.core.es.model.ESBluk; | ||
9 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; | 8 | import com.yoho.search.core.message.beans.SearchMqConsumerListerner; |
10 | import com.yoho.search.dal.ShopAdditionalImageMapper; | 9 | import com.yoho.search.dal.ShopAdditionalImageMapper; |
11 | import com.yoho.search.dal.model.ShopAdditionalImage; | 10 | import com.yoho.search.dal.model.ShopAdditionalImage; |
@@ -13,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -13,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
14 | import org.springframework.util.CollectionUtils; | 13 | import org.springframework.util.CollectionUtils; |
15 | 14 | ||
16 | -import java.util.*; | 15 | +import java.util.Arrays; |
16 | +import java.util.HashMap; | ||
17 | +import java.util.List; | ||
18 | +import java.util.Map; | ||
17 | 19 | ||
18 | @Component | 20 | @Component |
19 | @SearchMqConsumerListerner(dbName = "erp_product", tableName = "shop_additional_image") | 21 | @SearchMqConsumerListerner(dbName = "erp_product", tableName = "shop_additional_image") |
@@ -32,10 +34,11 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener { | @@ -32,10 +34,11 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener { | ||
32 | @Override | 34 | @Override |
33 | protected void deleteData(String id) throws Exception { | 35 | protected void deleteData(String id) throws Exception { |
34 | ShopAdditionalImage shopAdditionalImage = shopAdditionalImageMapper.selectByPrimaryKey(Integer.valueOf(id)); | 36 | ShopAdditionalImage shopAdditionalImage = shopAdditionalImageMapper.selectByPrimaryKey(Integer.valueOf(id)); |
35 | - if (shopAdditionalImage != null) { | ||
36 | - shopAdditionalImageMapper.deleteByPrimaryKey(Integer.valueOf(id)); | ||
37 | - updateIndex(shopAdditionalImage.getShopId()); | 37 | + if (shopAdditionalImage == null) { |
38 | + return; | ||
38 | } | 39 | } |
40 | + shopAdditionalImageMapper.deleteByPrimaryKey(Integer.valueOf(id)); | ||
41 | + updateIndex(shopAdditionalImage.getShopId()); | ||
39 | } | 42 | } |
40 | 43 | ||
41 | @Override | 44 | @Override |
@@ -52,23 +55,19 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener { | @@ -52,23 +55,19 @@ public class ShopAdditionalImageMqListener extends AbstractMqListener { | ||
52 | updateIndex(shopAdditionalImage.getShopId()); | 55 | updateIndex(shopAdditionalImage.getShopId()); |
53 | } | 56 | } |
54 | 57 | ||
55 | - private void updateIndex(Integer shopId) { | 58 | + private void updateIndex(Integer shopId) throws Exception { |
56 | List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(Arrays.asList(shopId)); | 59 | List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(Arrays.asList(shopId)); |
57 | - | ||
58 | Map<String, Object> indexData = new HashMap<>(); | 60 | Map<String, Object> indexData = new HashMap<>(); |
59 | - List<ESBluk> results = new ArrayList<>(); | ||
60 | - if (CollectionUtils.isEmpty(shopAdditionalImages)) { | ||
61 | - indexData.put("searchShowImage", ""); | ||
62 | - results.add(new ESBluk(JSONObject.toJSONString(indexData), shopId.toString(), getIndexName(), getIndexName(), false)); | ||
63 | - } else { | 61 | + indexData.put("searchShowImage", ""); |
62 | + indexData.put("shopDesc", ""); | ||
63 | + indexData.put("shopBackImg", ""); | ||
64 | + if (!CollectionUtils.isEmpty(shopAdditionalImages)) { | ||
64 | ShopAdditionalImage shopAdditionalImage = shopAdditionalImages.get(0); | 65 | ShopAdditionalImage shopAdditionalImage = shopAdditionalImages.get(0); |
65 | - if (shopAdditionalImage != null) { | ||
66 | - String image = shopAdditionalImage.getSearchShowImage(); | ||
67 | - indexData.put("searchShowImage", image); | ||
68 | - results.add(new ESBluk(JSONObject.toJSONString(indexData), shopId.toString(), getIndexName(), getIndexName(), false)); | ||
69 | - } | 66 | + indexData.put("searchShowImage", shopAdditionalImage.getSearchShowImage()); |
67 | + indexData.put("shopDesc", shopAdditionalImage.getShopDesc()); | ||
68 | + indexData.put("shopBackImg",shopAdditionalImage.getShopBackImg()); | ||
70 | } | 69 | } |
71 | - indexService.bulk(results); | 70 | + indexService.updateIndexData(this.getIndexName(),shopId.toString(),indexData); |
72 | } | 71 | } |
73 | } | 72 | } |
74 | 73 |
@@ -10,7 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -10,7 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
10 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
11 | import org.springframework.util.CollectionUtils; | 11 | import org.springframework.util.CollectionUtils; |
12 | 12 | ||
13 | -import java.util.*; | 13 | +import java.util.ArrayList; |
14 | +import java.util.List; | ||
15 | +import java.util.Map; | ||
16 | +import java.util.Objects; | ||
14 | import java.util.stream.Collectors; | 17 | import java.util.stream.Collectors; |
15 | 18 | ||
16 | /** | 19 | /** |
@@ -54,21 +57,28 @@ public class ShopService { | @@ -54,21 +57,28 @@ public class ShopService { | ||
54 | 57 | ||
55 | public List<ShopsAdditionalImageBO> getshopAdditionalImagePageLists(int start, int limit) { | 58 | public List<ShopsAdditionalImageBO> getshopAdditionalImagePageLists(int start, int limit) { |
56 | List<Shops> shops = shopMapper.selectPageLists(start, limit); | 59 | List<Shops> shops = shopMapper.selectPageLists(start, limit); |
57 | - Map<Integer, String> shopImageMap = new HashMap<>(); | ||
58 | - List<ShopsAdditionalImageBO> shopsAdditionalImageBOS = new ArrayList<>(); | ||
59 | - if (!CollectionUtils.isEmpty(shops)) { | ||
60 | - List<Integer> shopIds = shops.stream().map(Shops::getShopsId).filter(Objects::nonNull).distinct().collect(Collectors.toList()); | ||
61 | - if (!CollectionUtils.isEmpty(shopIds)) { | ||
62 | - List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(shopIds); | ||
63 | - if (!CollectionUtils.isEmpty(shopAdditionalImages)) { | ||
64 | - shopImageMap = shopAdditionalImages.stream().collect(Collectors.toMap(ShopAdditionalImage::getShopId, ShopAdditionalImage::getSearchShowImage, (k1, k2) -> k1)); | ||
65 | - } | ||
66 | - } | 60 | + if (CollectionUtils.isEmpty(shops)) { |
61 | + return new ArrayList<>(); | ||
67 | } | 62 | } |
63 | + List<Integer> shopIds = shops.stream().map(Shops::getShopsId).filter(Objects::nonNull).distinct().collect(Collectors.toList()); | ||
64 | + // 获取店铺装修信息 | ||
65 | + List<ShopAdditionalImage> shopAdditionalImages = shopAdditionalImageMapper.selectByShopIds(shopIds); | ||
66 | + Map<Integer, ShopAdditionalImage> shopAdditionalImageMap = shopAdditionalImages.stream().collect(Collectors.toMap(ShopAdditionalImage::getId, a -> a, (k1, k2) -> k1)); | ||
67 | + // 构造结果 | ||
68 | + List<ShopsAdditionalImageBO> shopsAdditionalImageBOS = new ArrayList<>(); | ||
68 | for (Shops shop : shops) { | 69 | for (Shops shop : shops) { |
69 | ShopsAdditionalImageBO shopsAdditionalImageBO = new ShopsAdditionalImageBO(); | 70 | ShopsAdditionalImageBO shopsAdditionalImageBO = new ShopsAdditionalImageBO(); |
70 | BeanUtils.copyProperties(shop, shopsAdditionalImageBO); | 71 | BeanUtils.copyProperties(shop, shopsAdditionalImageBO); |
71 | - shopsAdditionalImageBO.setSearchShowImage(shopImageMap.get(shop.getShopsId())); | 72 | + ShopAdditionalImage shopAdditionalImage = shopAdditionalImageMap.get(shop.getShopsId()); |
73 | + if (shopAdditionalImage != null) { | ||
74 | + shopsAdditionalImageBO.setSearchShowImage(shopAdditionalImage.getSearchShowImage()); | ||
75 | + shopsAdditionalImageBO.setShopBackImg(shopAdditionalImage.getShopBackImg()); | ||
76 | + shopsAdditionalImageBO.setShopDesc(shopAdditionalImage.getShopDesc()); | ||
77 | + } else { | ||
78 | + shopsAdditionalImageBO.setSearchShowImage(""); | ||
79 | + shopsAdditionalImageBO.setShopBackImg(""); | ||
80 | + shopsAdditionalImageBO.setShopDesc(""); | ||
81 | + } | ||
72 | shopsAdditionalImageBOS.add(shopsAdditionalImageBO); | 82 | shopsAdditionalImageBOS.add(shopsAdditionalImageBO); |
73 | } | 83 | } |
74 | return shopsAdditionalImageBOS; | 84 | return shopsAdditionalImageBOS; |
-
Please register or login to post a comment