<?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.znbgl.mapper.ZnbYhdaMapper">

    <resultMap id="znbYhdaMap" type="com.tofly.feesapi.znbgl.entity.ZnbYhda">
        <id property="yhbh" column="YHBH"/>
        <result property="bjwz" column="BJWZ"/>
        <result property="bjkj" column="BJKJ"/>
        <result property="bjlc" column="BJLC"/>
        <result property="cbpl" column="CBPL"/>
        <result property="bjqd" column="BJQD"/>
        <result property="bjzd" column="BJZD"/>
        <result property="bjbh" column="BJBH"/>
        <result property="jdrq" column="JDRQ"/>
        <result property="jdpch" column="JDPCH"/>
        <result property="czry" column="CZRY"/>
        <result property="czrq" column="CZRQ"/>
        <result property="yhzt" column="YHZT"/>
        <result property="fmzt" column="FMZT"/>
        <result property="bjzt" column="BJZT"/>
        <result property="bjmsg" column="BJMSG"/>
        <result property="bjye" column="BJYE"/>
        <result property="tbbz" column="TBBZ"/>
        <result property="jdlx" column="JDLX"/>
        <result property="yhxm" column="YHXM"/>
        <result property="yhdz" column="YHDZ"/>
        <result property="lxdh" column="LXDH"/>
        <result property="ssgs" column="SSGS"/>
        <result property="sspq" column="SSPQ"/>
        <result property="sscbb" column="SSCBB"/>
        <result property="yhlx" column="YHLX"/>
        <result property="jgbm" column="JGBM"/>
        <result property="bjcj" column="BJCJ"/>
        <result property="bjxh" column="BJXH"/>
        <result property="bjlb" column="BJLB"/>
    </resultMap>

    <!--自定义智能表档案分页查询 -->
    <select id="getPage" resultType="com.tofly.feesapi.znbgl.entity.vo.ZnbYhdaSelect">
        SELECT a.yhbh, a.yhxm, a.yhdz, a.jgbm,a.bjye,a.tbbz,a.bjbh, a.fmzt, a.lxdh,
               f.cbbmc AS sscbbmc,
               g.cbpqmc AS sscbpqmc,
               d.name AS sblbmc,
               h.name AS bjcjmc
        FROM znb_yhda a
        LEFT JOIN bm_sblb d ON a.bjlb = d.code
        LEFT JOIN bm_cbb f ON a.sscbb = f.cbbbm
        LEFT JOIN bm_cbpq g ON a.sspq = g.cbpqbm
        LEFT JOIN bm_sbsccj h on a.bjcj=h.code
        WHERE 1=1
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND (c.yhbh like '%${filter.searchText}%'
            OR c.yhxm like '%${filter.searchText}%'
            OR c.yhdz like '%${filter.searchText}%'
            OR c.lxdh like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND c.ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sscbpq!=null">
            AND c.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>
    </select>

    <select id="getPage2" resultType="com.tofly.feesapi.znbgl.entity.vo.ZnbYhdaSelect">
        SELECT a.yhbh, a.yhxm, a.yhdz, a.jgbm,a.bjye,a.tbbz,a.bjbh, a.fmzt, a.lxdh,
        f.cbbmc AS sscbbmc,
        g.cbpqmc AS sscbpqmc,
        d.name AS sblbmc,
        h.name AS bjcjmc
        FROM yh_khjbxx a
        LEFT JOIN bm_sblb d ON a.bjlb = d.code
        LEFT JOIN bm_cbb f ON a.sscbb = f.cbbbm
        LEFT JOIN bm_cbpq g ON a.sspq = g.cbpqbm
        LEFT JOIN bm_sbsccj h on a.bjcj=h.code
        WHERE 1=1
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND (c.yhbh like '%${filter.searchText}%'
            OR c.yhxm like '%${filter.searchText}%'
            OR c.yhdz like '%${filter.searchText}%'
            OR c.lxdh like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND c.ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sscbpq!=null">
            AND c.sscbpq=#{filter.sscbpq}
        </if>
        <!--所属抄表本-->
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND c.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND c.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
    </select>


</mapper>
