Authored by Gino Zhang

修改consumer单条修改的API

... ... @@ -11,6 +11,8 @@ public interface SuggestConversionCustomMapper {
List<SuggestConversionCustom> selectPageList(@Param(value = "offset") Integer offset, @Param(value = "pageSize") Integer pageSize);
SuggestConversionCustom selectBySource(String source);
int deleteByPrimaryKey(Integer id);
int insert(SuggestConversionCustom record);
... ...
<?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.SuggestConversionCustomMapper" >
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.SuggestConversionCustom">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.com.yoho.search.dal.model.SuggestConversionCustom">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="source" property="source" jdbcType="VARCHAR" />
<result column="dest" property="dest" jdbcType="VARCHAR" />
... ... @@ -22,6 +22,12 @@
from suggest_conversion_custom limit #{offset},#{pageSize}
</select>
<select id="selectBySource" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List" />
from suggest_conversion_custom where source = #{source,jdbcType=VARCHAR}
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
... ... @@ -32,13 +38,13 @@
delete from suggest_conversion_custom
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="model.SuggestConversionCustom" >
<insert id="insert" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" >
insert into suggest_conversion_custom (id, source, dest,
update_time, status)
values (#{id,jdbcType=INTEGER}, #{source,jdbcType=VARCHAR}, #{dest,jdbcType=VARCHAR},
#{updateTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="model.SuggestConversionCustom" >
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" >
insert into suggest_conversion_custom
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
... ... @@ -75,7 +81,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="model.SuggestConversionCustom" >
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" >
update suggest_conversion_custom
<set >
<if test="source != null" >
... ... @@ -93,7 +99,7 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="model.SuggestConversionCustom" >
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.SuggestConversionCustom" >
update suggest_conversion_custom
set source = #{source,jdbcType=VARCHAR},
dest = #{dest,jdbcType=VARCHAR},
... ...
... ... @@ -6,10 +6,7 @@ import com.yoho.search.dal.model.SuggestConversionCustom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Created by ginozhang on 2016/12/6.
... ... @@ -28,5 +25,7 @@ public class SuggestConversionCustomService {
return suggestConversionCustomMapper.selectPageList(offset, pageSize);
}
public SuggestConversionCustom selectBySource(String source){
return suggestConversionCustomMapper.selectBySource(source);
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.spider.conversation;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.consumer.index.common.AnalyzerHelper;
import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.service.base.*;
... ... @@ -50,19 +51,24 @@ public class SuggestConvertorService {
private SuggestConversionService suggestConversionService;
@Autowired
private SuggestConversionCustomService suggestConversionCustomService;
@Autowired
private IYohoIndexService indexService;
public void insertOrUpdateConversion(String source, String dest){
SuggestConversion suggestConversion = suggestConversionService.selectBySource(source);
if(suggestConversion == null){
suggestConversion = new SuggestConversion();
public void insertOrUpdateConversion(String source, String dest) {
SuggestConversionCustom suggestConversion = suggestConversionCustomService.selectBySource(source);
if (suggestConversion == null) {
suggestConversion = new SuggestConversionCustom();
suggestConversion.setSource(source);
suggestConversion.setDest(dest);
suggestConversion.setUpdateTime(DateUtil.getCurrentTimeSecond());
suggestConversion.setStatus(1);
suggestConversionService.insertBatch(Arrays.asList(suggestConversion));
}
else{
} else {
suggestConversion.setDest(dest);
suggestConversion.setUpdateTime(DateUtil.getCurrentTimeSecond());
suggestConversion.setStatus(1);
suggestConversionService.updateByPrimaryKey(suggestConversion);
}
}
... ... @@ -235,21 +241,31 @@ public class SuggestConvertorService {
public boolean addOrUpdateIndex(String keyword) {
Assert.notNull(keyword);
SuggestConversion suggestConversion = suggestConversionService.selectBySource(keyword);
if (suggestConversion == null) {
return false;
}
try {
Map<String, String> dataMap = new HashMap<>();
Map<String, Object> dataMap = new HashMap<>();
SuggestConversion suggestConversion;
SuggestConversionCustom suggestConversionCustom = suggestConversionCustomService.selectBySource(keyword);
if (suggestConversionCustom != null) {
dataMap.put("source", suggestConversionCustom.getSource());
dataMap.put("dest", suggestConversionCustom.getDest());
dataMap.put("updateTime", suggestConversionCustom.getUpdateTime());
dataMap.put("status", suggestConversionCustom.getStatus());
} else if ((suggestConversion = suggestConversionService.selectBySource(keyword)) != null) {
dataMap.put("source", suggestConversion.getSource());
dataMap.put("dest", suggestConversion.getDest());
indexService.updateIndexData(ISearchConstants.INDEX_NAME_CONVERSION, suggestConversion.getId().toString(), dataMap);
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
dataMap.put("updateTime", suggestConversion.getUpdateTime());
dataMap.put("status", Integer.valueOf(1));
}
if (!dataMap.isEmpty()) {
try {
indexService.updateIndexData(ISearchConstants.INDEX_NAME_CONVERSION, MD5Util.string2MD5(dataMap.get("source").toString().trim().toLowerCase()), dataMap);
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return false;
}
public Map<String, Object> explainConversion(String keyword) {
... ...