<?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.zsElectric.boot.business.mapper.FirmAccountLogMapper">

    <!-- 获取企业资金流水分页列表 -->
    <select id="getFirmAccountLogPage" resultType="com.zsElectric.boot.business.model.vo.FirmAccountLogVO">
        SELECT
            a.id,
            a.firm_id,
            IFNULL(b.firm_type, IFNULL(a.firm_type, 1)) AS firmType,
            b.name AS firmName,
            a.project_name,
            a.name,
            a.serial_no,
            a.income_type,
            a.before_change,
            a.after_change,
            a.money_change,
            a.change_type,
            a.child_id,
            a.remark,
            a.create_time
        FROM
            c_firm_account_log a
        LEFT JOIN c_firm_info b ON a.firm_id = b.id
        <where>
            a.is_deleted = 0
            <if test="queryParams.firmType != null">
                AND a.firm_type = #{queryParams.firmType}
            </if>
            <if test="queryParams.firmId != null">
                AND a.firm_id = #{queryParams.firmId}
            </if>
            <if test="queryParams.incomeType != null">
                AND a.income_type = #{queryParams.incomeType}
            </if>
            <if test="queryParams.changeType != null">
                AND a.change_type = #{queryParams.changeType}
            </if>
            <if test="queryParams.serialNo != null and queryParams.serialNo != ''">
                AND a.serial_no LIKE CONCAT('%', #{queryParams.serialNo}, '%')
            </if>
            <if test="queryParams.startTime != null">
                AND a.create_time <![CDATA[>=]]> #{queryParams.startTime}
            </if>
            <if test="queryParams.endTime != null">
                AND a.create_time <![CDATA[<=]]> #{queryParams.endTime}
            </if>
        </where>
        ORDER BY a.create_time DESC
    </select>

</mapper>
