Authored by wangnan9279

Merge branch 'wn_ufo_addsocre' into gray1115

  1 +package com.yoho.search.dal;
  2 +
  3 +import com.yoho.search.dal.model.UfoScoreProductRule;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface UfoScoreProductRuleMapper {
  9 + int deleteByPrimaryKey(Integer id);
  10 +
  11 + int insert(UfoScoreProductRule record);
  12 +
  13 + int insertSelective(UfoScoreProductRule record);
  14 +
  15 + UfoScoreProductRule selectByPrimaryKey(Integer id);
  16 +
  17 + int updateByPrimaryKeySelective(UfoScoreProductRule record);
  18 +
  19 + int updateByPrimaryKey(UfoScoreProductRule record);
  20 +
  21 + List<Integer> selectByIdList(@Param(value = "idList") List<Integer> idList);
  22 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.search.dal.UfoScoreProductRuleMapper">
  4 + <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.UfoScoreProductRule">
  5 + <id column="id" property="id" jdbcType="INTEGER"/>
  6 + <result column="product_id" property="productId" jdbcType="INTEGER"/>
  7 + <result column="update_time" property="updateTime" jdbcType="INTEGER"/>
  8 + <result column="create_time" property="createTime" jdbcType="INTEGER"/>
  9 + </resultMap>
  10 + <sql id="Base_Column_List">
  11 + id, product_id, update_time, create_time
  12 + </sql>
  13 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  14 + select
  15 + <include refid="Base_Column_List"/>
  16 + from ufo_score_product_rule
  17 + where id = #{id,jdbcType=INTEGER}
  18 + </select>
  19 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  20 + delete from ufo_score_product_rule
  21 + where id = #{id,jdbcType=INTEGER}
  22 + </delete>
  23 + <insert id="insert" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
  24 + insert into ufo_score_product_rule (id, product_id, update_time,
  25 + create_time)
  26 + values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
  27 + #{createTime,jdbcType=INTEGER})
  28 + </insert>
  29 + <insert id="insertSelective" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
  30 + insert into ufo_score_product_rule
  31 + <trim prefix="(" suffix=")" suffixOverrides=",">
  32 + <if test="id != null">
  33 + id,
  34 + </if>
  35 + <if test="productId != null">
  36 + product_id,
  37 + </if>
  38 + <if test="updateTime != null">
  39 + update_time,
  40 + </if>
  41 + <if test="createTime != null">
  42 + create_time,
  43 + </if>
  44 + </trim>
  45 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  46 + <if test="id != null">
  47 + #{id,jdbcType=INTEGER},
  48 + </if>
  49 + <if test="productId != null">
  50 + #{productId,jdbcType=INTEGER},
  51 + </if>
  52 + <if test="updateTime != null">
  53 + #{updateTime,jdbcType=INTEGER},
  54 + </if>
  55 + <if test="createTime != null">
  56 + #{createTime,jdbcType=INTEGER},
  57 + </if>
  58 + </trim>
  59 + </insert>
  60 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
  61 + update ufo_score_product_rule
  62 + <set>
  63 + <if test="productId != null">
  64 + product_id = #{productId,jdbcType=INTEGER},
  65 + </if>
  66 + <if test="updateTime != null">
  67 + update_time = #{updateTime,jdbcType=INTEGER},
  68 + </if>
  69 + <if test="createTime != null">
  70 + create_time = #{createTime,jdbcType=INTEGER},
  71 + </if>
  72 + </set>
  73 + where id = #{id,jdbcType=INTEGER}
  74 + </update>
  75 + <update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.UfoScoreProductRule">
  76 + update ufo_score_product_rule
  77 + set product_id = #{productId,jdbcType=INTEGER},
  78 + update_time = #{updateTime,jdbcType=INTEGER},
  79 + create_time = #{createTime,jdbcType=INTEGER}
  80 + where id = #{id,jdbcType=INTEGER}
  81 + </update>
  82 + <select id="selectByIdList" resultType="java.lang.Integer">
  83 + select product_id
  84 + from ufo_score_product_rule
  85 + where product_id in
  86 + <foreach item="item" collection="idList" open="(" separator="," close=")">
  87 + #{item}
  88 + </foreach>
  89 + </select>
  90 +</mapper>
  1 +package com.yoho.search.consumer.index.increment.ufo;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.search.base.utils.ConvertUtils;
  5 +import com.yoho.search.base.utils.EventReportEnum;
  6 +import com.yoho.search.consumer.index.increment.AbstractMqListener;
  7 +import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
  8 +import com.yoho.search.dal.UfoScoreProductRuleMapper;
  9 +import com.yoho.search.dal.model.UfoScoreProductRule;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +/**
  14 + * @author wangnan
  15 + * @version 2018/11/19
  16 + */
  17 +@Component
  18 +@SearchMqConsumerListerner(tableName = "ufo_score_product_rule")
  19 +public class UfoScoreProductRuleMqListener extends AbstractMqListener {
  20 + @Autowired
  21 + private UfoScoreProductRuleMapper ufoScoreProductRuleMapper;
  22 + @Autowired
  23 + private UfoIndexHelper ufoIndexHelper;
  24 +
  25 + @Override
  26 + protected EventReportEnum getEventReportEnum() {
  27 + return EventReportEnum.UFOSCOREPRODUCTRULEMQLISTENER_ONMESSAGE;
  28 + }
  29 +
  30 + @Override
  31 + protected void deleteData(String id) throws Exception {
  32 + UfoScoreProductRule ufoScoreProductRule = ufoScoreProductRuleMapper.selectByPrimaryKey(Integer.valueOf(id));
  33 + ufoScoreProductRuleMapper.deleteByPrimaryKey(Integer.valueOf(id));
  34 + if (ufoScoreProductRule != null) {
  35 + ufoIndexHelper.updateUfoProductIndexByProductId(ufoScoreProductRule.getProductId());
  36 + }
  37 + }
  38 +
  39 + @Override
  40 + protected void updateData(JSONObject data) throws Exception {
  41 + UfoScoreProductRule ufoScoreProductRule = ConvertUtils.toJavaObject(UfoScoreProductRule.class, data);
  42 + if (ufoScoreProductRule == null || ufoScoreProductRule.getId() == null) {
  43 + return;
  44 + }
  45 + this.saveOrUpdate(ufoScoreProductRule);
  46 + ufoIndexHelper.updateUfoProductIndexByProductId(ufoScoreProductRule.getProductId());
  47 + }
  48 +
  49 + private int saveOrUpdate(UfoScoreProductRule ufoScoreProductRule) {
  50 + if (ufoScoreProductRule.getId() == null || ufoScoreProductRuleMapper.selectByPrimaryKey(ufoScoreProductRule.getId()) == null) {
  51 + return ufoScoreProductRuleMapper.insertSelective(ufoScoreProductRule);
  52 + } else {
  53 + return ufoScoreProductRuleMapper.updateByPrimaryKeySelective(ufoScoreProductRule);
  54 + }
  55 + }
  56 +}
  57 +