Authored by saihide

fix

package com.yoho.search.dal;
import com.yoho.search.dal.model.CsBrandKeyword;
import java.util.Collection;
import java.util.List;
public interface CsBrandKeywordMapper {
int insert(CsBrandKeyword record);
int deleteByPrimaryKey(Integer id);
int updateByPrimaryKey(CsBrandKeyword record);
CsBrandKeyword selectByPrimaryKey(Integer id);
List<CsBrandKeyword> selectByPrimaryKeys(Collection<Integer> ids);
}
... ...
<?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.CsBrandKeywordMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.CsBrandKeyword">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="brand_id" property="brandId" jdbcType="INTEGER"/>
<result column="keyword" property="keyword" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, brand_id, keyword, status, update_time
</sql>
<insert id="insert" parameterType="com.yoho.search.dal.model.CsBrandKeyword" timeout="20000">
insert ignore into cs_brand_keyword (id, brand_id, keyword, status, update_time)
values (#{id,jdbcType=INTEGER},#{brandId,jdbcType=INTEGER}, #{keyword,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR},#{updateTime,jdbcType=VARCHAR})
</insert>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" timeout="20000">
delete from cs_brand_keyword
where id = #{id,jdbcType=INTEGER}
</delete>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.CsBrandKeyword" timeout="20000">
update cs_brand_keyword
<set>
<if test="keyword != null">
keyword = #{keyword,jdbcType=VARCHAR},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" timeout="20000">
select
<include refid="Base_Column_List"/>
from cs_brand_keyword
where id = #{id,jdbcType=INTEGER}
LIMIT 1
</select>
<select id="selectByPrimaryKeys" resultMap="BaseResultMap" parameterType="java.lang.Integer" timeout="20000">
select
<include refid="Base_Column_List"/>
from cs_brand_keyword
where id IN
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.increment.productIndex;
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.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.CsBrandKeywordMapper;
import com.yoho.search.dal.model.CsBrandKeyword;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@SearchMqConsumerListerner(tableName = "activity_product")
public class CsBrandKeywordMqListener extends AbstractMqListener {
@Autowired
private CsBrandKeywordMapper csBrandKeywordMapper;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.CSBRANDKEYWORDMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
if (StringUtils.isNotBlank(id)) {
csBrandKeywordMapper.deleteByPrimaryKey(Integer.valueOf(id));
}
}
@Override
protected void updateData(JSONObject data) throws Exception {
CsBrandKeyword csBrandKeyword = ConvertUtils.toJavaObject(CsBrandKeyword.class, data);
if (csBrandKeyword == null || csBrandKeyword.getId() == null) {
return;
}
if (csBrandKeywordMapper.selectByPrimaryKey(csBrandKeyword.getId()) == null) {
csBrandKeywordMapper.insert(csBrandKeyword);
}else {
csBrandKeywordMapper.updateByPrimaryKey(csBrandKeyword);
}
}
}
... ...