Showing
4 changed files
with
50 additions
and
27 deletions
@@ -11,6 +11,8 @@ public interface SuggestConversionCustomMapper { | @@ -11,6 +11,8 @@ public interface SuggestConversionCustomMapper { | ||
11 | 11 | ||
12 | List<SuggestConversionCustom> selectPageList(@Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize); | 12 | List<SuggestConversionCustom> selectPageList(@Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize); |
13 | 13 | ||
14 | + SuggestConversionCustom selectBySource(String source); | ||
15 | + | ||
14 | int deleteByPrimaryKey(Integer id); | 16 | int deleteByPrimaryKey(Integer id); |
15 | 17 | ||
16 | int insert(SuggestConversionCustom record); | 18 | int insert(SuggestConversionCustom record); |
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.SuggestConversionCustomMapper" > | 3 | <mapper namespace="com.yoho.search.dal.SuggestConversionCustomMapper" > |
4 | - <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SuggestConversionCustom"> | 4 | + <resultMap id="BaseResultMap" type="com.yoho.search.dal.com.yoho.search.dal.model.SuggestConversionCustom"> |
5 | <id column="id" property="id" jdbcType="INTEGER" /> | 5 | <id column="id" property="id" jdbcType="INTEGER" /> |
6 | <result column="source" property="source" jdbcType="VARCHAR" /> | 6 | <result column="source" property="source" jdbcType="VARCHAR" /> |
7 | <result column="dest" property="dest" jdbcType="VARCHAR" /> | 7 | <result column="dest" property="dest" jdbcType="VARCHAR" /> |
@@ -22,6 +22,12 @@ | @@ -22,6 +22,12 @@ | ||
22 | from suggest_conversion_custom limit #{offset},#{pageSize} | 22 | from suggest_conversion_custom limit #{offset},#{pageSize} |
23 | </select> | 23 | </select> |
24 | 24 | ||
25 | + <select id="selectBySource" resultMap="BaseResultMap" timeout="20000"> | ||
26 | + select | ||
27 | + <include refid="Base_Column_List" /> | ||
28 | + from suggest_conversion_custom where source = #{source,jdbcType=VARCHAR} | ||
29 | + </select> | ||
30 | + | ||
25 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 31 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > |
26 | select | 32 | select |
27 | <include refid="Base_Column_List" /> | 33 | <include refid="Base_Column_List" /> |
@@ -32,13 +38,13 @@ | @@ -32,13 +38,13 @@ | ||
32 | delete from suggest_conversion_custom | 38 | delete from suggest_conversion_custom |
33 | where id = #{id,jdbcType=INTEGER} | 39 | where id = #{id,jdbcType=INTEGER} |
34 | </delete> | 40 | </delete> |
35 | - <insert id="insert" parameterType="model.SuggestConversionCustom" > | 41 | + <insert id="insert" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" > |
36 | insert into suggest_conversion_custom (id, source, dest, | 42 | insert into suggest_conversion_custom (id, source, dest, |
37 | update_time, status) | 43 | update_time, status) |
38 | values (#{id,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{dest,jdbcType=VARCHAR}, | 44 | values (#{id,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{dest,jdbcType=VARCHAR}, |
39 | #{updateTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}) | 45 | #{updateTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}) |
40 | </insert> | 46 | </insert> |
41 | - <insert id="insertSelective" parameterType="model.SuggestConversionCustom" > | 47 | + <insert id="insertSelective" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" > |
42 | insert into suggest_conversion_custom | 48 | insert into suggest_conversion_custom |
43 | <trim prefix="(" suffix=")" suffixOverrides="," > | 49 | <trim prefix="(" suffix=")" suffixOverrides="," > |
44 | <if test="id != null" > | 50 | <if test="id != null" > |
@@ -75,7 +81,7 @@ | @@ -75,7 +81,7 @@ | ||
75 | </if> | 81 | </if> |
76 | </trim> | 82 | </trim> |
77 | </insert> | 83 | </insert> |
78 | - <update id="updateByPrimaryKeySelective" parameterType="model.SuggestConversionCustom" > | 84 | + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" > |
79 | update suggest_conversion_custom | 85 | update suggest_conversion_custom |
80 | <set > | 86 | <set > |
81 | <if test="source != null" > | 87 | <if test="source != null" > |
@@ -93,7 +99,7 @@ | @@ -93,7 +99,7 @@ | ||
93 | </set> | 99 | </set> |
94 | where id = #{id,jdbcType=INTEGER} | 100 | where id = #{id,jdbcType=INTEGER} |
95 | </update> | 101 | </update> |
96 | - <update id="updateByPrimaryKey" parameterType="model.SuggestConversionCustom" > | 102 | + <update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" > |
97 | update suggest_conversion_custom | 103 | update suggest_conversion_custom |
98 | set source = #{source,jdbcType=VARCHAR}, | 104 | set source = #{source,jdbcType=VARCHAR}, |
99 | dest = #{dest,jdbcType=VARCHAR}, | 105 | dest = #{dest,jdbcType=VARCHAR}, |
@@ -6,10 +6,7 @@ import com.yoho.search.dal.model.SuggestConversionCustom; | @@ -6,10 +6,7 @@ import com.yoho.search.dal.model.SuggestConversionCustom; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
7 | import org.springframework.stereotype.Component; | 7 | import org.springframework.stereotype.Component; |
8 | 8 | ||
9 | -import java.util.HashSet; | ||
10 | import java.util.List; | 9 | import java.util.List; |
11 | -import java.util.Set; | ||
12 | -import java.util.stream.Collectors; | ||
13 | 10 | ||
14 | /** | 11 | /** |
15 | * Created by ginozhang on 2016/12/6. | 12 | * Created by ginozhang on 2016/12/6. |
@@ -28,5 +25,7 @@ public class SuggestConversionCustomService { | @@ -28,5 +25,7 @@ public class SuggestConversionCustomService { | ||
28 | return suggestConversionCustomMapper.selectPageList(offset, pageSize); | 25 | return suggestConversionCustomMapper.selectPageList(offset, pageSize); |
29 | } | 26 | } |
30 | 27 | ||
31 | - | 28 | + public SuggestConversionCustom selectBySource(String source){ |
29 | + return suggestConversionCustomMapper.selectBySource(source); | ||
30 | + } | ||
32 | } | 31 | } |
@@ -2,6 +2,7 @@ package com.yoho.search.spider.conversation; | @@ -2,6 +2,7 @@ package com.yoho.search.spider.conversation; | ||
2 | 2 | ||
3 | import com.yoho.search.base.utils.DateUtil; | 3 | import com.yoho.search.base.utils.DateUtil; |
4 | import com.yoho.search.base.utils.ISearchConstants; | 4 | import com.yoho.search.base.utils.ISearchConstants; |
5 | +import com.yoho.search.base.utils.MD5Util; | ||
5 | import com.yoho.search.consumer.index.common.AnalyzerHelper; | 6 | import com.yoho.search.consumer.index.common.AnalyzerHelper; |
6 | import com.yoho.search.consumer.index.common.IYohoIndexService; | 7 | import com.yoho.search.consumer.index.common.IYohoIndexService; |
7 | import com.yoho.search.consumer.service.base.*; | 8 | import com.yoho.search.consumer.service.base.*; |
@@ -50,19 +51,24 @@ public class SuggestConvertorService { | @@ -50,19 +51,24 @@ public class SuggestConvertorService { | ||
50 | private SuggestConversionService suggestConversionService; | 51 | private SuggestConversionService suggestConversionService; |
51 | 52 | ||
52 | @Autowired | 53 | @Autowired |
54 | + private SuggestConversionCustomService suggestConversionCustomService; | ||
55 | + | ||
56 | + @Autowired | ||
53 | private IYohoIndexService indexService; | 57 | private IYohoIndexService indexService; |
54 | 58 | ||
55 | - public void insertOrUpdateConversion(String source, String dest){ | ||
56 | - SuggestConversion suggestConversion = suggestConversionService.selectBySource(source); | ||
57 | - if(suggestConversion == null){ | ||
58 | - suggestConversion = new SuggestConversion(); | 59 | + public void insertOrUpdateConversion(String source, String dest) { |
60 | + SuggestConversionCustom suggestConversion = suggestConversionCustomService.selectBySource(source); | ||
61 | + if (suggestConversion == null) { | ||
62 | + suggestConversion = new SuggestConversionCustom(); | ||
59 | suggestConversion.setSource(source); | 63 | suggestConversion.setSource(source); |
60 | suggestConversion.setDest(dest); | 64 | suggestConversion.setDest(dest); |
65 | + suggestConversion.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
66 | + suggestConversion.setStatus(1); | ||
61 | suggestConversionService.insertBatch(Arrays.asList(suggestConversion)); | 67 | suggestConversionService.insertBatch(Arrays.asList(suggestConversion)); |
62 | - } | ||
63 | - else{ | 68 | + } else { |
64 | suggestConversion.setDest(dest); | 69 | suggestConversion.setDest(dest); |
65 | suggestConversion.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 70 | suggestConversion.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
71 | + suggestConversion.setStatus(1); | ||
66 | suggestConversionService.updateByPrimaryKey(suggestConversion); | 72 | suggestConversionService.updateByPrimaryKey(suggestConversion); |
67 | } | 73 | } |
68 | } | 74 | } |
@@ -235,21 +241,31 @@ public class SuggestConvertorService { | @@ -235,21 +241,31 @@ public class SuggestConvertorService { | ||
235 | 241 | ||
236 | public boolean addOrUpdateIndex(String keyword) { | 242 | public boolean addOrUpdateIndex(String keyword) { |
237 | Assert.notNull(keyword); | 243 | Assert.notNull(keyword); |
238 | - SuggestConversion suggestConversion = suggestConversionService.selectBySource(keyword); | ||
239 | - if (suggestConversion == null) { | ||
240 | - return false; | ||
241 | - } | ||
242 | - | ||
243 | - try { | ||
244 | - Map<String, String> dataMap = new HashMap<>(); | 244 | + Map<String, Object> dataMap = new HashMap<>(); |
245 | + SuggestConversion suggestConversion; | ||
246 | + SuggestConversionCustom suggestConversionCustom = suggestConversionCustomService.selectBySource(keyword); | ||
247 | + if (suggestConversionCustom != null) { | ||
248 | + dataMap.put("source", suggestConversionCustom.getSource()); | ||
249 | + dataMap.put("dest", suggestConversionCustom.getDest()); | ||
250 | + dataMap.put("updateTime", suggestConversionCustom.getUpdateTime()); | ||
251 | + dataMap.put("status", suggestConversionCustom.getStatus()); | ||
252 | + } else if ((suggestConversion = suggestConversionService.selectBySource(keyword)) != null) { | ||
245 | dataMap.put("source", suggestConversion.getSource()); | 253 | dataMap.put("source", suggestConversion.getSource()); |
246 | dataMap.put("dest", suggestConversion.getDest()); | 254 | dataMap.put("dest", suggestConversion.getDest()); |
247 | - indexService.updateIndexData(ISearchConstants.INDEX_NAME_CONVERSION, suggestConversion.getId().toString(), dataMap); | ||
248 | - return true; | ||
249 | - } catch (Exception e) { | ||
250 | - logger.error(e.getMessage(), e); | ||
251 | - return false; | 255 | + dataMap.put("updateTime", suggestConversion.getUpdateTime()); |
256 | + dataMap.put("status", Integer.valueOf(1)); | ||
257 | + } | ||
258 | + | ||
259 | + if (!dataMap.isEmpty()) { | ||
260 | + try { | ||
261 | + indexService.updateIndexData(ISearchConstants.INDEX_NAME_CONVERSION, MD5Util.string2MD5(dataMap.get("source").toString().trim().toLowerCase()), dataMap); | ||
262 | + return true; | ||
263 | + } catch (Exception e) { | ||
264 | + throw new RuntimeException(e); | ||
265 | + } | ||
252 | } | 266 | } |
267 | + | ||
268 | + return false; | ||
253 | } | 269 | } |
254 | 270 | ||
255 | public Map<String, Object> explainConversion(String keyword) { | 271 | public Map<String, Object> explainConversion(String keyword) { |
-
Please register or login to post a comment