<?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.njzscloud.dispose.finance.mapper.MoneyFlowMapper">
    <resultMap id="BaseResultMap" type="com.njzscloud.dispose.finance.pojo.result.MoneyFlowResult" autoMapping="true">
        <id column="id" property="id"/>
        <result column="file_url" property="fileUrl" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
    </resultMap>

    <sql id="SearchMoneyFlowResultSql">
        SELECT fmf.id,
               fmf.order_id,
               fmf.order_sn,
               fmf.train_num,
               fmf.money_account_id,
               fmf.before_balance,
               fmf.delta,
               fmf.after_balance,
               fmf.money_change_category,
               fmf.memo,
               fmf.file_url,
               fmf.creator_id,
               fmf.modifier_id,
               fmf.create_time,
               fmf.modify_time,
               fmf.deleted,
               CASE fma.account_type
                   WHEN 'GeRen' THEN cc.customer_name
                   WHEN 'QiYe' THEN co.org_name
                   ELSE NULL
                   END AS account_name,
               fma.account_type
        FROM fin_money_flow fmf
                 LEFT JOIN fin_money_account fma ON fma.id = fmf.money_account_id
                 LEFT JOIN cst_customer cc ON cc.id = fma.customer_id
                 LEFT JOIN cst_org co ON co.id = fma.org_id
    </sql>

    <select id="paging" resultMap="BaseResultMap">
        <include refid="SearchMoneyFlowResultSql"/>
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
</mapper>
