Authored by Gino Zhang

增加一个升级的restful接口

... ... @@ -20,4 +20,6 @@ public interface SuggestWordDefMapper {
void updateBatch(@Param(value = "suggestWordDefList") List<SuggestWordDef> list);
void deleteBatch(List<Integer> idList);
void deleteAllValidKeywords();
}
\ No newline at end of file
... ...
... ... @@ -29,7 +29,7 @@
</foreach>
</insert>
<update id="updateBatch" parameterType="java.util.List">
<update id="updateBatch" parameterType="java.util.List" timeout="20000">
update suggest_word_def
<trim prefix="set" suffixOverrides=",">
<trim prefix="count =case" suffix="end,">
... ... @@ -59,13 +59,17 @@
</foreach>
</update>
<delete id="deleteBatch" parameterType="java.util.List">
<delete id="deleteBatch" parameterType="java.util.List" timeout="20000">
DELETE FROM suggest_word_def WHERE ID in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</delete>
<delete id="deleteAllValidKeywords" timeout="20000">
DELETE FROM suggest_word_def WHERE status=1
</delete>
<select id="selectTotalCount" resultType="java.lang.Integer" timeout="20000">
SELECT count(1) FROM suggest_word_def
</select>
... ...
... ... @@ -54,4 +54,7 @@ public class SuggestWordDefService {
suggestWordDefMapper.deleteBatch(idList);
}
public void deleteAllValidKeywords(){
suggestWordDefMapper.deleteAllValidKeywords();
}
}
... ...
package com.yoho.search.consumer.test;
import com.yoho.search.consumer.job.IndexRebuildJob;
import com.yoho.search.consumer.job.SuggestionCounterJob;
import com.yoho.search.consumer.job.SuggestionDiscoveryJob;
import com.yoho.search.consumer.service.base.SuggestWordDefService;
import com.yoho.search.spider.job.SpiderJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
/**
* Created by ginozhang on 2017/3/10.
*/
@Controller
public class UpgradeSearchConsumerController {
private static final Logger logger = LoggerFactory.getLogger(UpgradeSearchConsumerController.class);
@Autowired
private SuggestWordDefService suggestWordDefService;
@Autowired
private SuggestionDiscoveryJob suggestionDiscoveryJob;
@Autowired
private SuggestionCounterJob suggestionCounterJob;
@Autowired
private IndexRebuildJob indexRebuildJob;
@Autowired
private SpiderJob spiderJob;
@RequestMapping(value = "/proteced/upgrade")
@ResponseBody
public Map<String, Object> upgrade() {
Map<String, Object> rtnMap = new HashMap<String, Object>();
try {
doUpgrade();
rtnMap.put("code", 200);
rtnMap.put("msg", "success");
} catch (Exception e) {
logger.error(e.getMessage(), e);
rtnMap.put("code", 500);
rtnMap.put("msg", e.getMessage());
}
return rtnMap;
}
private void doUpgrade() {
// Important NOTE: 本升级restful 接口为2017.03.13升级所写 升级后可删除
long begin = System.currentTimeMillis();
logger.info("[func=doUpgrade][begin={}]");
// 1. 清除suggest_word_def表
suggestWordDefService.deleteAllValidKeywords();
logger.info("[func=doUpgrade][msg=deleteAllValidKeywords succeed]");
// 2. 执行SuggestionDiscovery
suggestionDiscoveryJob.execute();
logger.info("[func=doUpgrade][msg=suggestionDiscoveryJob succeed]");
// 3. 执行SuggestionCounter
suggestionCounterJob.execute();
logger.info("[func=doUpgrade][msg=suggestionCounterJob succeed]");
// 4. 重建suggest索引
indexRebuildJob.rebuildSuggestIndex();
logger.info("[func=doUpgrade][msg=rebuildSuggestIndex succeed]");
// 5. 执行SuggestConvertor
spiderJob.convertSpiderContents();
logger.info("[func=doUpgrade][msg=convertSpiderContents succeed]");
// 6. 重建conversion索引
indexRebuildJob.rebuildConversionIndex();
logger.info("[func=doUpgrade][msg=rebuildConversionIndex succeed][cost={}]", System.currentTimeMillis() - begin);
}
}
... ...