<?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.cbgl.mapper.ZnbCbDayMapper">
    <sql id="querySql">
        SELECT a.yhbh, d.yhxm, d.yhdz, g.cbpqmc AS sscbpqmc, f.cbbmc AS sscbbbm, e.name AS sccjmc, a.sbbh, a.scds, a.bcds, a.chzs, a.sl, a.cbrq, a.utime
        FROM znb_cb_day a
        LEFT JOIN yh_khjbxx d on a.yhbh = d.yhbh
        LEFT JOIN bm_sbsccj e on a.sccj = e.code
        LEFT JOIN bm_cbb f on d.sscbb = f.cbbbm
        LEFT JOIN bm_cbpq g on d.sscbpq = g.cbpqbm
        WHERE 1=1
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND (a.yhbh like '%${filter.searchText}%'
            OR d.yhxm like '%${filter.searchText}%'
            OR d.yhdz like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND d.ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sscbpq!=null">
            AND d.sscbpq=#{filter.sscbpq}
        </if>
        <!--所属抄表本-->
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND d.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND d.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <!--生产厂家-->
        <if test="filter.sscj!=null">
            AND a.sscj=#{filter.sscj}
        </if>
        <!-- 录入日期-->
        <if test="filter.utimeStart!=null and filter.utimeEnd!=null">
            AND a.utime BETWEEN #{filter.utimeStart} AND
            #{filter.utimeEnd}
        </if>
    </sql>
    <select id="getPage" resultType="com.tofly.feesapi.cbgl.entity.vo.ZnbCbDaySelect">
        <include refid="querySql"></include>
    </select>
    <select id="getList" resultType="com.tofly.feesapi.cbgl.entity.vo.ZnbCbDaySelect">
        <include refid="querySql"></include>
    </select>
</mapper>
