<?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.dayou.mapper.BusinessReplyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.BusinessReply">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="biz_type" property="bizType" />
        <result column="biz_table_id" property="bizTableId" />
        <result column="parent_id" property="parentId" />
        <result column="content" property="content" />
        <result column="replier_id" property="replierId" />
        <result column="receiver_id" property="receiverId" />
        <result column="state" property="state" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        br.id,
        br.deleted,
        br.created,
        br.modified,
        br.biz_type, br.biz_table_id, br.parent_id, br.content, br.replier_id, br.receiver_id, br.state
    </sql>

    <select id="getPage" parameterType="com.dayou.entity.BusinessReply" resultType="com.dayou.vo.BusinessReplyVO">
        select <include refid="Base_Column_List"/> , u1.name as replier,u2.name as receiver
        from business_reply br
        left join user u1 on br.replier_id = u1.id left join user u2 on br.receiver_id = u2.id
        where u1.deleted = 0 and u2.deleted = 0 and br.deleted = 0 and br.biz_type = #{businessReply.bizType} and br.biz_table_id = #{businessReply.bizTableId}
        order by br.created DESC
    </select>

    <update id="updateState">
        update business_reply set state = 1 where biz_type = #{bizType} and biz_table_id = #{bizTableId} and receiver_id = #{currentId}
    </update>
</mapper>
