<?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.limap.core.basic.mapper.BasicProfitSharingRecordMapper">

    <select id="getReportData" resultType="java.util.Map">
        SELECT
            SUM(amount) AS total,
            SUM(CASE WHEN status = 1 THEN amount ELSE 0 END) AS fr,
            SUM(CASE WHEN withdrawal_status = 1 THEN amount ELSE 0 END) AS tx
        FROM basic_profit_sharing_record
        <where>
            <if test="params.startDate != null and params.startDate != ''">
                AND generate_time &gt;= #{params.startDate}
            </if>
            <if test="params.endDate != null and params.endDate != ''">
                AND generate_time &lt;= #{params.endDate}
            </if>
            <if test="startDate != null and startDate != ''">
                AND generate_time &gt;= #{startDate}
            </if>
            <if test="endDate != null and endDate != ''">
                AND generate_time &lt;= #{endDate}
            </if>
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
            <if test="deptId != null">
                and dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors ))
            </if>
        </where>
    </select>
</mapper>
