<?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.sfgl.mapper.YyQfmxDzmxMapper">
    <resultMap id="yyQfmxDzmxMap" type="com.tofly.feesapi.sfgl.entity.YyQfmxDzmx">
        <id property="id" column="ID"/>
        <result property="yhbh" column="YHBH"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="ssgs" column="SSGS"/>
        <result property="sscbpq" column="SSCBPQ"/>
        <result property="sscbb" column="SSCBB"/>
        <result property="sjbm" column="SJBM"/>
        <result property="ysyf" column="YSYF"/>
        <result property="cwrq" column="CWRQ"/>
        <result property="sl" column="SL"/>
        <result property="je" column="JE"/>
        <result property="cbrybm" column="CBRYBM"/>
        <result property="cbryxm" column="CBRYXM"/>
        <result property="czrybm" column="CZRYBM"/>
        <result property="czryxm" column="CZRYXM"/>
        <result property="czsj" column="CZSJ"/>
        <result property="bz" column="BZ"/>
        <result property="shry" column="SHRY"/>
        <result property="shyj" column="SHYJ"/>
        <result property="statusId" column="STATUS_ID"/>
        <result property="typeId" column="TYPE_ID"/>
        <result property="modeId" column="MODE_ID"/>
        <result property="isValid" column="IS_VALID"/>
        <result property="ssregion" column="SSREGION"/>
    </resultMap>

    <select id="getYyQfmxDzmxPage" resultType="com.tofly.feesapi.sfgl.entity.vo.YyQfmxDzmxSelect">
        select a.*,
        c.name as yslx
        from yy_qfmx_dzmx a
        left join bm_sj b on a.sjbm = b.code
        left join bm_yslx c on b.yslx = c.code
        <where>
            <if test="filter.searchText!=null">
                and (a.yhbh like '%${filter.searchText}%'
                or a.YHXM like '%${filter.searchText}%'
                or a.YHDZ like '%${filter.searchText}%'
                or a.LXDH like '%${filter.searchText}%'
                or c.name like '%${filter.searchText}%'
                or a.CBRYXM like '%${filter.searchText}%'
                )
            </if>
            <if test="filter.ssgs!=null">
                AND a.ssgs=#{filter.ssgs}
            </if>
            <if test="filter.sscbpq!=null">
                AND a.sscbpq=#{filter.sscbpq}
            </if>
            <if test="filter.sscbb!=null">
                <choose>
                    <when test="filter.sscbb.indexOf(',')!=-1">
                        AND a.sscbb in
                        <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                                 close=")">
                            #{item}
                        </foreach>
                    </when>
                    <otherwise>
                        AND a.sscbb=#{filter.sscbb}
                    </otherwise>
                </choose>
            </if>
            <if test="filter.cbrybm!=null">
                AND a.cbrybm=#{filter.cbrybm}
            </if>
            <if test="filter.qyfzr!=null">
                AND a.sscbb in(select cbbbm from bm_cbb where qyfzr=#{filter.qyfzr})
            </if>
            <if test="filter.yhbhStart!=null">
                <![CDATA[ AND a.yhbh>=#{filter.yhbhStart} ]]>
            </if>
            <if test="filter.yhbhEnd!=null">
                <![CDATA[ AND a.yhbh<=#{filter.yhbhEnd} ]]>
            </if>
            <if test="filter.yslx!=null">
                AND c.code=#{filter.yslx}
            </if>
            <if test="filter.dzzt!=null">
                AND a.type_id=#{filter.dzzt}
            </if>
        </where>
    </select>
</mapper>
