<?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.hanserwei.hannote.count.biz.domain.mapper.UserCountDOMapper">
  <resultMap id="BaseResultMap" type="com.hanserwei.hannote.count.biz.domain.dataobject.UserCountDO">
    <!--@mbg.generated-->
    <!--@Table t_user_count-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="fans_total" jdbcType="BIGINT" property="fansTotal" />
    <result column="following_total" jdbcType="BIGINT" property="followingTotal" />
    <result column="note_total" jdbcType="BIGINT" property="noteTotal" />
    <result column="like_total" jdbcType="BIGINT" property="likeTotal" />
    <result column="collect_total" jdbcType="BIGINT" property="collectTotal" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, user_id, fans_total, following_total, note_total, like_total, collect_total
  </sql>

    <insert id="insertOrUpdateFansTotalByUserId" parameterType="map">
        INSERT INTO t_user_count (user_id, fans_total)
        VALUES (#{userId}, #{count})
        ON DUPLICATE KEY UPDATE fans_total = fans_total + (#{count});
    </insert>

  <insert id="insertOrUpdateFollowingTotalByUserId">
      INSERT INTO t_user_count (user_id, following_total)
      VALUES (#{userId}, #{count})
      ON DUPLICATE KEY UPDATE following_total = following_total + (#{count});
  </insert>

  <insert id="insertOrUpdateLikeTotalByUserId" parameterType="map">
      INSERT INTO t_user_count (user_id, like_total)
      VALUES (#{userId}, #{count})
      ON DUPLICATE KEY UPDATE like_total = like_total + (#{count});
  </insert>

  <insert id="insertOrUpdateCollectTotalByUserId" parameterType="map">
      INSERT INTO t_user_count (user_id, collect_total)
      VALUES (#{userId}, #{count})
      ON DUPLICATE KEY UPDATE collect_total = collect_total + (#{count});
  </insert>

  <insert id="insertOrUpdateNoteTotalByUserId" parameterType="map">
      INSERT INTO t_user_count (user_id, note_total)
      VALUES (#{userId}, #{count})
      ON DUPLICATE KEY UPDATE note_total = note_total + (#{count});
  </insert>
</mapper>