<?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.tofly.feesapi.yhgl.mapper.YhGhLogMapper">

    <select id="selectDaCustomerGhPage" resultType="com.tofly.feesapi.yhgl.entity.vo.YhGhLogSelect">
        SELECT
            *
        FROM (
            SELECT
                a.*,
                cbpq.cbpqmc as sscbpqname,
                cbb.cbbmc as sscbbname,
                (
                    select
                        LISTAGG(File_NEW_FN, ',') WITHIN GROUP (ORDER BY TABLE_BH)
                    FROM
                        sys_upfiles files
                    WHERE
                        files.table_bh = a.bh
                ) AS fileurl
            FROM
                yh_gh_log a
            LEFT JOIN
                bm_cbpq cbpq on a.sscbpq=cbpq.cbpqbm
            LEFT JOIN
                bm_cbb cbb on a.sscbb=cbb.cbbbm
            WHERE
                1=1
        <!--模糊查询 -->
            <if test="filter.searchText != null and filter.searchText != ''">
                and ( a.yhbh like '%${filter.searchText}%' or
                a.old_yhxm like '%${filter.searchText}%' or
                a.old_yhdz like '%${filter.searchText}%' or
                old_lxdh like '%${filter.searchText}%' )
            </if>
            <!--公司 -->
            <if test="filter.ssgs!=null and filter.ssgs!='' and filter.ssgs!='all'">
                and a.ssgs=#{filter.ssgs}
            </if>
            <!--片区 -->
            <if test="filter.sscbpq !=null and filter.sscbpq!='' and filter.sscbpq!='all' ">
                and a.sscbpq=#{filter.sscbpq}
            </if>
            <!--抄表本 -->
            <if test="filter.sscbb !=null and filter.sscbb!='' and filter.sscbb!='all'">
                and a.sscbb=#{filter.sscbb}
            </if>
            <if test="filter.qyfzr!=null">
                and a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
            </if>
            <!--建档日期-->
            <if test="filter.ksrq!=null and filter.ksrq!='' and filter.jsrq!=null and filter.jsrq!='' ">
                and a.ghsj between to_date(#{filter.ksrq},'yyyy-mm-dd hh24:mi:ss') and
                to_date(#{filter.jsrq},'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="filter.czry!=null and filter.czry!=''">
                and a.czrybm=#{filter.czry}
            </if>
        )
    </select>
    <resultMap id="yhGhLogMap" type="com.tofly.feesapi.yhgl.entity.YhGhLog">
        <id property="bh" column="BH"/>
        <result property="ssgs" column="SSGS"/>
        <result property="yhbh" column="YHBH"/>
        <result property="oldYhdz" column="OLD_YHDZ"/>
        <result property="oldYhxm" column="OLD_YHXM"/>
        <result property="oldLxdh" column="OLD_LXDH"/>
        <result property="oldZjlb" column="OLD_ZJLB"/>
        <result property="oldZjhm" column="OLD_ZJHM"/>
        <result property="newYhxm" column="NEW_YHXM"/>
        <result property="newLxdh" column="NEW_LXDH"/>
        <result property="newZjlb" column="NEW_ZJLB"/>
        <result property="newZjhm" column="NEW_ZJHM"/>
        <result property="ghsj" column="GHSJ"/>
        <result property="czrybm" column="CZRYBM"/>
        <result property="czryxm" column="CZRYXM"/>
        <result property="bz" column="BZ"/>
        <result property="type" column="TYPE"/>
        <result property="oldFpNsrsbh" column="OLD_FP_NSRSBH"/>
        <result property="oldFpDz" column="OLD_FP_DZ"/>
        <result property="oldFpName" column="OLD_FP_NAME"/>
        <result property="oldFpLxdh" column="OLD_FP_LXDH"/>
        <result property="oldFpBankname" column="OLD_FP_BANKNAME"/>
        <result property="oldFpBz" column="OLD_FP_BZ"/>
        <result property="oldFpBankcode" column="OLD_FP_BANKCODE"/>
        <result property="newFpNsrsbh" column="NEW_FP_NSRSBH"/>
        <result property="newFpDz" column="NEW_FP_DZ"/>
        <result property="newFpName" column="NEW_FP_NAME"/>
        <result property="newFpLxdh" column="NEW_FP_LXDH"/>
        <result property="newFpBankname" column="NEW_FP_BANKNAME"/>
        <result property="newFpBz" column="NEW_FP_BZ"/>
        <result property="newFpBankcode" column="NEW_FP_BANKCODE"/>
        <result property="newYhdz" column="NEW_YHDZ"/>
        <result property="sscbpq" column="SSCBPQ"/>
        <result property="sscbb" column="SSCBB"/>
        <result property="newFplx" column="NEW_FPLX"/>
    </resultMap>


</mapper>
