Authored by hugufei

Merge branch 'zj' into 6.2

Conflicts:
	pom.xml
package com.yoho.search.dal;
import com.yoho.search.dal.model.PageRecallStrategyDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface PageRecallStrategyDetailMapper {
int deleteByPrimaryKey(@Param("id") Integer id);
int insert(@Param("record") PageRecallStrategyDetail record);
int update(@Param("record")PageRecallStrategyDetail record);
PageRecallStrategyDetail selectByPrimaryKey(@Param("id") Integer id);
List<PageRecallStrategyDetail> getAllExistStrategies();
}
... ...
package com.yoho.search.dal;
import com.yoho.search.dal.model.PageRecallType;
import org.apache.ibatis.annotations.Param;
public interface PageRecallTypeMapper {
int deleteByPrimaryKey(@Param("id") Integer id);
int insert(@Param("record") PageRecallType record);
int update(@Param("record")PageRecallType record);
PageRecallType selectByPrimaryKey(@Param("id")Integer id);
}
... ...
<?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.PageRecallStrategyDetailMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.PageRecallStrategyDetail">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="page_id" property="pageId" jdbcType="TINYINT" />
<result column="recall_type" property="recallType" jdbcType="INTEGER" />
<result column="recall_percent" property="recallPercent" jdbcType="INTEGER" />
<result column="value_type" property="valueType" jdbcType="TINYINT" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
</resultMap>
<sql id="Base_Column_List" >
id, page_id, recall_type, recall_percent, value_type, update_time, status
</sql>
<delete id="deleteByPrimaryKey">
delete from page_recall_strategy_detail where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert">
insert ignore into page_recall_strategy_detail (id, page_id, recall_type, recall_percent, value_type, update_time, status)
values (#{record.id,jdbcType=INTEGER},
#{record.pageId,jdbcType=TINYINT},
#{record.recallType,jdbcType=INTEGER},
#{record.recallPercent,jdbcType=INTEGER},
#{record.valueType,jdbcType=TINYINT},
#{record.updateTime,jdbcType=INTEGER},
#{record.status,jdbcType=TINYINT})
</insert>
<update id="update">
update page_recall_strategy_detail
set page_id = #{record.pageId,jdbcType=TINYINT},
recall_type = #{record.recallType,jdbcType=INTEGER},
recall_percent = #{record.recallPercent,jdbcType=INTEGER},
value_type = #{record.valueType,jdbcType=TINYINT},
update_time = #{record.updateTime,jdbcType=INTEGER},
status = #{record.status,jdbcType=TINYINT}
where id = #{record.id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from page_recall_strategy_detail
where id = #{id,jdbcType=INTEGER}
</select>
<select id="getAllExistStrategies" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" /> FROM page_recall_strategy_detail where status =1
</select>
</mapper>
\ No newline at end of file
... ...
<?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.PageRecallTypeMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.PageRecallType" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="page_id" property="pageId" jdbcType="TINYINT" />
<result column="recall_type_list" property="recallTypeList" jdbcType="VARCHAR" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
</resultMap>
<sql id="Base_Column_List" >
id, page_id, recall_type_list, update_time, status
</sql>
<delete id="deleteByPrimaryKey">
delete from page_recall_type where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert">
insert ignore into page_recall_type (id, page_id, recall_type_list, update_time, status)
values (#{record.id,jdbcType=INTEGER},
#{record.pageId,jdbcType=TINYINT},
#{record.recallTypeList,jdbcType=VARCHAR},
#{record.updateTime,jdbcType=INTEGER},
#{record.status,jdbcType=TINYINT})
</insert>
<update id="update">
update page_recall_type
set page_id = #{record.pageId,jdbcType=TINYINT},
recall_type_list = #{record.recallTypeList,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=INTEGER},
status = #{record.status,jdbcType=TINYINT}
where id = #{record.id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/> from page_recall_type
where id = #{id,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.increment.database;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.PageRecallTypeService;
import com.yoho.search.consumer.service.logicService.RecallStrategyLogicService;
import com.yoho.search.dal.model.PageRecallStrategyDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PageRecallStrategyDetailMqListener extends AbstractMqListener {
@Autowired
private PageRecallTypeService pageRecallTypeService;
@Autowired
private RecallStrategyLogicService recallStrategyLogicService;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.PAGERECALLSTRATEGYDETAILMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
pageRecallTypeService.deleteDetail(Integer.valueOf(id));
recallStrategyLogicService.setRecallStrategyConfigToZk();
}
@Override
protected void updateData(JSONObject data) throws Exception {
PageRecallStrategyDetail detail = ConvertUtils.toJavaObject(PageRecallStrategyDetail.class, data);
if (detail == null || detail.getId() == null) {
return;
}
pageRecallTypeService.saveOrUpdate(detail);
recallStrategyLogicService.setRecallStrategyConfigToZk();
}
}
... ...
package com.yoho.search.consumer.index.increment.database;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.daoService.PageRecallTypeService;
import com.yoho.search.dal.model.PageRecallType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PageRecallTypeMqListener extends AbstractMqListener {
@Autowired
private PageRecallTypeService pageRecallTypeService;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.PAGERECALLTYPEMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
pageRecallTypeService.deleteType(Integer.valueOf(id));
}
@Override
protected void updateData(JSONObject data) throws Exception {
PageRecallType type = ConvertUtils.toJavaObject(PageRecallType.class, data);
if (type == null || type.getId() == null) {
return;
}
pageRecallTypeService.saveOrUpdate(type);
}
}
... ...
package com.yoho.search.consumer.service.daoService;
import com.yoho.search.dal.PageRecallStrategyDetailMapper;
import com.yoho.search.dal.PageRecallTypeMapper;
import com.yoho.search.dal.model.PageRecallStrategyDetail;
import com.yoho.search.dal.model.PageRecallType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class PageRecallTypeService {
@Autowired
private PageRecallTypeMapper pageRecallTypeMapper;
@Autowired
private PageRecallStrategyDetailMapper pageRecallStrategyDetailMapper;
public int saveOrUpdate(PageRecallType type) {
PageRecallType db = pageRecallTypeMapper.selectByPrimaryKey(type.getId());
if (db == null) {
//新增
return pageRecallTypeMapper.insert(type);
} else {
//修改
return pageRecallTypeMapper.update(type);
}
}
public int saveOrUpdate(PageRecallStrategyDetail detail) {
PageRecallStrategyDetail db = pageRecallStrategyDetailMapper.selectByPrimaryKey(detail.getId());
if (db == null) {
//新增
return pageRecallStrategyDetailMapper.insert(detail);
} else {
//修改
return pageRecallStrategyDetailMapper.update(detail);
}
}
public void deleteType(Integer id) {
pageRecallTypeMapper.deleteByPrimaryKey(id);
}
public void deleteDetail(Integer id) {
pageRecallStrategyDetailMapper.deleteByPrimaryKey(id);
}
public List<PageRecallStrategyDetail> getAllExistStrategies() {
List<PageRecallStrategyDetail> details = pageRecallStrategyDetailMapper.getAllExistStrategies();
return details == null ? Collections.emptyList() : details;
}
}
... ...
package com.yoho.search.consumer.service.logicService;
import com.yoho.search.base.models.PageRecallStrategyBO;
import com.yoho.search.base.utils.JsonUtil;
import com.yoho.search.consumer.service.common.ZkConfigService;
import com.yoho.search.consumer.service.daoService.PageRecallTypeService;
import com.yoho.search.dal.model.PageRecallStrategyDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class RecallStrategyLogicService {
private static final Logger LOGGER = LoggerFactory.getLogger(RecallStrategyLogicService.class);
private static final String RECALL_STRATEGY_CONFIGKEY= "search.recallstrategy.values";
@Autowired
private PageRecallTypeService pageRecallTypeService;
@Autowired
private ZkConfigService zkConfigService;
@PostConstruct
public void setRecallStrategyConfigToZk() {
List<PageRecallStrategyDetail> details = pageRecallTypeService.getAllExistStrategies();
Map<Integer, List<PageRecallStrategyDetail>> detailsMap = details.stream().collect(Collectors.groupingBy(PageRecallStrategyDetail::getPageId));
List<PageRecallStrategyBO> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(detailsMap)) {
detailsMap.forEach((pageId, recallStrategyList) -> {
PageRecallStrategyBO pageRecall = new PageRecallStrategyBO();
list.add(pageRecall);
pageRecall.setPageId(pageId);
List<PageRecallStrategyBO.RecallStrategyBO> strategyList = new ArrayList<>();
pageRecall.setStrategies(strategyList);
if (!CollectionUtils.isEmpty(recallStrategyList)) {
recallStrategyList.forEach(e -> {
if (e != null) {
PageRecallStrategyBO.RecallStrategyBO strategy = new PageRecallStrategyBO.RecallStrategyBO();
strategy.setRecallType(e.getRecallType());
strategy.setRecallValue(e.getRecallPercent());
strategy.setValueType(e.getValueType());
strategyList.add(strategy);
}
});
}
});
}
String configStr = "";
try {
configStr = JsonUtil.toJson(list);
LOGGER.info("publish recall strategy data " + configStr + " to zk");
zkConfigService.addStringValueToZk(RECALL_STRATEGY_CONFIGKEY, configStr);
} catch (Exception e) {
LOGGER.error("publish recall strategy data " + configStr + " to zk failed!", e);
}
}
public String getRecallStrategyConfigInZk() {
return zkConfigService.getStringValueFromZk(RECALL_STRATEGY_CONFIGKEY);
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.test;
import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
import com.yoho.search.consumer.job.CleanDataJob;
import com.yoho.search.consumer.service.logicService.RecallStrategyLogicService;
import com.yoho.search.dal.SknImageVectorsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -80,4 +81,15 @@ public class TestApiController {
// JSONObject jsonObject = new JSONObject(indexData);
// commonBulkService.add(new ESBluk(jsonObject.toJSONString(), skn, "images_test", "images_test", false));
// }
@Autowired
private RecallStrategyLogicService recallStrategyLogicService;
@RequestMapping(value = "/test2")
@ResponseBody
public String test2() {
String result = recallStrategyLogicService.getRecallStrategyConfigInZk();
return result;
}
}
... ...
... ... @@ -88,7 +88,8 @@
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_videos" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_activitytag" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_promotiontype" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_pagerecalltype" />
<rabbit:queue durable="true" exclusive="false" name="data_update_channel_pagerecallstrategydetail" />
<rabbit:template exchange="${search.mq.exchange}" id="amqpTemplate"
connection-factory="connectionFactory" message-converter="jsonMessageConverter" />
<bean id="jsonMessageConverter" class="com.yoho.search.consumer.common.FastJsonMessageConverter"></bean>
... ... @@ -177,5 +178,7 @@
<rabbit:listener queue-names="data_update_channel_videos" ref="videosMqListener" />
<rabbit:listener queue-names="data_update_channel_activitytag" ref="activityTagMqListener" />
<rabbit:listener queue-names="data_update_channel_promotiontype" ref="promotionTypeMqListener" />
<rabbit:listener queue-names="data_update_channel_pagerecalltype" ref="pageRecallTypeMqListener" />
<rabbit:listener queue-names="data_update_channel_pagerecallstrategydetail" ref="pageRecallStrategyDetailMqListener" />
</rabbit:listener-container>
</beans>
\ No newline at end of file
... ...
... ... @@ -20,7 +20,7 @@ bigDataRedis-search.proxy.port=16379
bigDataRedis-search.proxy.auth=
#mq
search.mq.server=192.168.102.216
search.mq.server=192.168.102.224
search.mq.port=5672
search.mq.username=admin1
search.mq.password=123qwe
... ...