Authored by wangnan9279

ufo addscore

package com.yoho.search.dal;
import com.yoho.search.dal.model.UfoScoreProductRule;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UfoScoreProductRuleMapper {
int deleteByPrimaryKey(Integer id);
int insert(UfoScoreProductRule record);
int insertSelective(UfoScoreProductRule record);
UfoScoreProductRule selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UfoScoreProductRule record);
int updateByPrimaryKey(UfoScoreProductRule record);
List<Integer> selectByIdList(@Param(value = "idList") List<Integer> idList);
}
\ 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.UfoScoreProductRuleMapper">
<resultMap id="BaseResultMap" type="com.yoho.search.dal.model.UfoScoreProductRule">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="product_id" property="productId" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id, product_id, update_time, create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List"/>
from ufo_score_product_rule
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from ufo_score_product_rule
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
insert into ufo_score_product_rule (id, product_id, update_time,
create_time)
values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
insert into ufo_score_product_rule
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="productId != null">
product_id,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="productId != null">
#{productId,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
update ufo_score_product_rule
<set>
<if test="productId != null">
product_id = #{productId,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
update ufo_score_product_rule
set product_id = #{productId,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByIdList" resultType="java.lang.Integer">
select product_id
from ufo_score_product_rule
where product_id in
<foreach item="item" collection="idList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.search.consumer.index.increment.ufo;
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.UfoScoreProductRuleMapper;
import com.yoho.search.dal.model.UfoScoreProductRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author wangnan
* @version 2018/11/19
*/
@Component
@SearchMqConsumerListerner(tableName = "ufo_score_product_rule")
public class UfoScoreProductRuleMqListener extends AbstractMqListener {
@Autowired
private UfoScoreProductRuleMapper ufoScoreProductRuleMapper;
@Autowired
private UfoIndexHelper ufoIndexHelper;
@Override
protected EventReportEnum getEventReportEnum() {
return EventReportEnum.UFOSCOREPRODUCTRULEMQLISTENER_ONMESSAGE;
}
@Override
protected void deleteData(String id) throws Exception {
UfoScoreProductRule ufoScoreProductRule = ufoScoreProductRuleMapper.selectByPrimaryKey(Integer.valueOf(id));
ufoScoreProductRuleMapper.deleteByPrimaryKey(Integer.valueOf(id));
if (ufoScoreProductRule != null) {
ufoIndexHelper.updateUfoProductIndexByProductId(ufoScoreProductRule.getProductId());
}
}
@Override
protected void updateData(JSONObject data) throws Exception {
UfoScoreProductRule ufoScoreProductRule = ConvertUtils.toJavaObject(UfoScoreProductRule.class, data);
if (ufoScoreProductRule == null || ufoScoreProductRule.getId() == null) {
return;
}
this.saveOrUpdate(ufoScoreProductRule);
ufoIndexHelper.updateUfoProductIndexByProductId(ufoScoreProductRule.getProductId());
}
private int saveOrUpdate(UfoScoreProductRule ufoScoreProductRule) {
if (ufoScoreProductRule.getId() == null || ufoScoreProductRuleMapper.selectByPrimaryKey(ufoScoreProductRule.getId()) == null) {
return ufoScoreProductRuleMapper.insertSelective(ufoScoreProductRule);
} else {
return ufoScoreProductRuleMapper.updateByPrimaryKeySelective(ufoScoreProductRule);
}
}
}
... ...