<?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="cn.pluss.platform.mapper.JftReceiptInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.JftReceiptInfo">
        <id column="id" property="id" />
        <result column="projectName" property="projectName" />
        <result column="amount" property="amount" />
        <result column="userId" property="userId" />
        <result column="status" property="status" />
        <result column="createTime" property="createTime" />
        <result column="endTime" property="endTime" />
        <result column="token" property="token" />
    </resultMap>

    <select id="pageInfo" parameterType="cn.pluss.platform.entity.JftReceiptInfo" resultType="cn.pluss.platform.vo.JftReceiptInfoVO">
        SELECT a.*,IF(a.payNum > 0,"已收款","未收款") as payStatusDesc FROM (SELECT
             jri.*,
             SUM(IF(jro.`status` = '02',1,0)) AS payNum,
             SUM(IF(jro.`status` = '02',jro.amount,0)) as totalAmount
         FROM
             tb_pluss_jft_receipt_info jri
                 LEFT JOIN tb_pluss_jft_receipt_order jro ON jri.id = jro.rid GROUP BY id ) a
        <where>
            a.status = 1
            <if test="condition != null and condition.userId != null">
                and a.userId = #{condition.userId}
            </if>
            <if test="condition != null and condition.startDate != null and condition.startDate != ''">
                and DATE_FORMAT(a.createTime,'%Y-%m-%d') >= #{condition.startDate}
            </if>
            <if test="condition != null and condition.endDate != null and condition.endDate != ''">
                and DATE_FORMAT(a.createTime,'%Y-%m-%d') <![CDATA[ <= ]]> #{condition.endDate}
            </if>
        </where>
        ORDER BY a.id desc
    </select>
</mapper>
