<?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.pcloud.book.pcloudkeyword.dao.impl.PcloudTdRecordDaoImpl" >
  <resultMap id="BaseResultMap" type="PcloudTdRecord" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="robot_wx_id" jdbcType="VARCHAR" property="robotWxId" />
    <result column="user_wx_id" jdbcType="VARCHAR" property="userWxId" />
    <result column="td_state" jdbcType="INTEGER" property="tdState" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, robot_wx_id, user_wx_id, td_state, create_time, update_time
  </sql>

    <insert id="insert"  parameterType="PcloudTdRecord" useGeneratedKeys="true" keyProperty="id">
        insert into pcloud_td_record (
        robot_wx_id,
        user_wx_id,
        td_state,
        create_time,
        update_time
        )
        values
        (
        #{robotWxId,jdbcType=VARCHAR},
        #{userWxId,jdbcType=VARCHAR},
        #{tdState,jdbcType=INTEGER},
        NOW(),
        NOW()
        )
    </insert>

    <update id="updateUserTdState" parameterType="PcloudTdRecord">
        update pcloud_td_record
        set
        td_state = #{tdState,jdbcType=INTEGER},
        update_time = NOW()
        where
        robot_wx_id = #{robotWxId,jdbcType=VARCHAR}
        and user_wx_id = #{userWxId,jdbcType=VARCHAR}
    </update>

    <select id="getUserTdState" resultType="int">
        select td_state
        from pcloud_td_record
        where
        robot_wx_id = #{robotWxId,jdbcType=VARCHAR}
        and user_wx_id = #{userWxId,jdbcType=VARCHAR}
    </select>

    <select id="getByUserAndRobotWxId"  parameterType="map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from pcloud_td_record
        where
        robot_wx_id = #{robotWxId}
        and user_wx_id = #{userWxId,}
    </select>

</mapper>