<?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.TpTransactionMapper">
    <select id="selectListByParams" resultType="com.community.huiju.model.TpTransaction">
        SELECT
        t.id,
        t.community_id AS communityId,
        t.transaction_title AS transactionTitle,
        t.view_count AS viewCount,
        t.`status`,
        t.type,
        t.create_user,
        t.is_reported AS isReported,
        t.create_date AS createDate,
        t.uuid_name AS uuidName,
        COUNT( li.transaction_id ) AS transactionLikeSum,
        COUNT( re.transaction_id ) AS replySum
        FROM
        tp_transaction t
        LEFT JOIN tp_transaction_like li ON t.id = li.transaction_id
        AND li.like_status = 1
        LEFT JOIN tp_transaction_reply re ON t.id = re.transaction_id
        WHERE t.community_id =#{communityId}
        <if test="id != null and id != '' or id ==0">
            and t.id like concat('%',#{id},'%')
        </if>
        <if test="transactionTitle != null and transactionTitle != ''">
            and t.transaction_title like concat('%',#{transactionTitle,jdbcType=VARCHAR},'%')
        </if>
        <if test="status != null and status != ''">
            and t.type = #{status,jdbcType=VARCHAR}
        </if>
        <if test="userName != null and userName != ''">
            and t.uuid_name like concat('%',#{userName,jdbcType=VARCHAR},'%')
        </if>
        GROUP BY
        t.id
        ORDER BY t.create_date desc
    </select>
</mapper>
