<?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.community.huiju.dao.TpTransactionReplyMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpTransactionReply" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="uuid" property="uuid" jdbcType="INTEGER" />
    <result column="uuid_type" property="uuidType" jdbcType="VARCHAR" />
    <result column="uuid_name" property="uuidName" jdbcType="VARCHAR" />
    <result column="uuid_role" property="uuidRole" jdbcType="VARCHAR" />
    <result column="reply_uuid" property="replyUuid" jdbcType="INTEGER" />
    <result column="reply_uuid_type" property="replyUuidType" jdbcType="VARCHAR" />
    <result column="reply_uuid_name" property="replyUuidName" jdbcType="VARCHAR" />
    <result column="reply_uuid_role" property="replyUuidRole" jdbcType="VARCHAR" />
    <result column="transaction_id" property="transactionId" jdbcType="INTEGER" />
    <result column="reply_content" property="replyContent" jdbcType="VARCHAR" />
    <result column="publish_type" property="publishType" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
    <result column="release_identity" property="releaseIdentity" jdbcType="VARCHAR" />
    <result column="room_no_name" property="roomNoName" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, transaction_id,uuid,uuid_type,uuid_role,reply_uuid_role,
      uuid_name, reply_content,
      reply_uuid, reply_uuid_type,reply_uuid_name, create_date,release_identity,publish_type
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from tp_transaction_reply
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_transaction_reply
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpTransactionReply" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
    insert into tp_transaction_reply (id, community_id, transaction_id,uuid,uuid_type,uuid_role,reply_uuid_role,
      uuid_name, reply_content,
      reply_uuid, reply_uuid_type,reply_uuid_name, create_date,release_identity,publish_type
      )
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{transactionId,jdbcType=INTEGER},#{uuid},#{uuidType},#{uuidRole},#{replyUuidRole},
      #{uuidName,jdbcType=VARCHAR}, #{replyContent,jdbcType=VARCHAR}, #{replyUuid,jdbcType=INTEGER},
      #{replyUuidType,jdbcType=VARCHAR}, #{replyUuidName,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP},#{releaseIdentity,jdbcType=VARCHAR},#{publishType,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpTransactionReply" >
    insert into tp_transaction_reply
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="transactionId != null" >
        transaction_id,
      </if>
      <if test="taUserId != null" >
        ta_user_id,
      </if>
      <if test="taUserName != null" >
        ta_user_name,
      </if>
      <if test="replyContent != null" >
        reply_content,
      </if>
      <if test="replyTaUserId != null" >
        reply_ta_user_id,
      </if>
      <if test="replyTaUserName != null" >
        reply_ta_user_name,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="releaseIdentity != null" >
        release_identity,
      </if>
      <if test="taUserVerifyId != null" >
        ta_user_verify_id,
      </if>
      <if test="roomNoName != null" >
        room_no_name
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="transactionId != null" >
        #{transactionId,jdbcType=INTEGER},
      </if>
      <if test="taUserId != null" >
        #{taUserId,jdbcType=INTEGER},
      </if>
      <if test="taUserName != null" >
        #{taUserName,jdbcType=VARCHAR},
      </if>
      <if test="replyContent != null" >
        #{replyContent,jdbcType=VARCHAR},
      </if>
      <if test="replyTaUserId != null" >
        #{replyTaUserId,jdbcType=INTEGER},
      </if>
      <if test="replyTaUserName != null" >
        #{replyTaUserName,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="releaseIdentity != null" >
        #{releaseIdentity},
      </if>
      <if test="taUserVerifyId != null" >
        #{taUserVerifyId},
      </if>
      <if test="roomNoName != null" >
        #{roomNoName}
      </if>

    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpTransactionReply" >
    update tp_transaction_reply
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="transactionId != null" >
        transaction_id = #{transactionId,jdbcType=INTEGER},
      </if>
      <if test="taUserId != null" >
        ta_user_id = #{taUserId,jdbcType=INTEGER},
      </if>``
      <if test="taUserName != null" >
        ta_user_name = #{taUserName,jdbcType=VARCHAR},
      </if>
      <if test="replyContent != null" >
        reply_content = #{replyContent,jdbcType=VARCHAR},
      </if>
      <if test="replyTaUserId != null" >
        reply_ta_user_id = #{replyTaUserId,jdbcType=INTEGER},
      </if>
      <if test="replyTaUserName != null" >
        reply_ta_user_name = #{replyTaUserName,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpTransactionReply" >
    update tp_transaction_reply
    set community_id = #{communityId,jdbcType=INTEGER},
      transaction_id = #{transactionId,jdbcType=INTEGER},
      ta_user_id = #{taUserId,jdbcType=INTEGER},
      ta_user_name = #{taUserName,jdbcType=VARCHAR},
      reply_content = #{replyContent,jdbcType=VARCHAR},
      reply_ta_user_id = #{replyTaUserId,jdbcType=INTEGER},
      reply_ta_user_name = #{replyTaUserName,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="getCommunityIdAndTransactionId" resultMap="BaseResultMap">
    SELECT
      *
    FROM
    tp_transaction_reply  tr
    WHERE
	tr.community_id = #{communityId}
    and tr.transaction_id=#{transactionId}
      <if test="type == 2" >
        AND (tr.uuid_type = 'prop' or tr.reply_uuid_type = 'prop')
      </if>
      <if test="type == 1" >
        AND (tr.uuid = #{uuid} OR tr.reply_uuid = #{uuid})
        AND (tr.uuid_type =  #{uuidType} or tr.reply_uuid_type =  #{uuidType})
      </if>
      <if test="type == 0" >
        AND (tr.uuid = #{userID} OR tr.reply_uuid = #{userID})
        AND (tr.uuid_type = 'app' or tr.reply_uuid_type = 'app')
      </if>
   </select>
   <select id="selectUserTransactionReply" resultMap="BaseResultMap">
     select
     <include refid="Base_Column_List" />
     from tp_transaction_reply
     where  ta_user_id = #{id}
     GROUP BY transaction_id
   </select>
</mapper>