<?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.wxgl.wechatofficalacctmgt.mapper.WxRkssqMapper">

    <resultMap id="wxRkssqMap" type="com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.WxRkssq">
        <id property="id" column="ID"/>
        <result property="bh" column="BH"/>
        <result property="registerOpenid" column="REGISTER_OPENID"/>
        <result property="registerYhbh" column="REGISTER_YHBH"/>
        <result property="registerName" column="REGISTER_NAME"/>
        <result property="registerAddress" column="REGISTER_ADDRESS"/>
        <result property="registerPhone" column="REGISTER_PHONE"/>
        <result property="registerZjhm" column="REGISTER_ZJHM"/>
        <result property="registerContext" column="REGISTER_CONTEXT"/>
        <result property="registerYrks" column="REGISTER_YRKS"/>
        <result property="registerZxrks" column="REGISTER_ZXRKS"/>
        <result property="registerDate" column="REGISTER_DATE"/>
        <result property="handleName" column="HANDLE_NAME"/>
        <result property="handleDate" column="HANDLE_DATE"/>
        <result property="handleResult" column="HANDLE_RESULT"/>
        <result property="state" column="STATE"/>
        <result property="handleJl" column="HANDLE_JL"/>
    </resultMap>

    <select id="SelectRkstj" resultType="com.tofly.feesapi.wxgl.wechatofficalacctmgt.entity.vo.RkstjVo">
        select a.register_yhbh yhbh,
        b.yhxm,
        b.yhdz,
        b.lxdh,
        c.cbpqmc,
        d.cbbmc,
        b.rks,
        d.cby,
        f.name yslx,
        a.register_date czsj
        from wx_rkssq a
        left join yh_khjbxx b on a.register_yhbh = b.yhbh
        left join bm_cbpq c on b.sscbpq = c.cbpqbm
        left join bm_cbb d on b.sscbb = d.cbbbm
        left join yh_cbkxx e on b.yhbh = e.yhbh
        left join bm_yslx f on e.yslx = f.code
        where state = '0'
        <!--模糊查询 -->
        <if test="filter.searchText!=null">
            AND ( b.yhbh like '%${filter.searchText}%'
            OR b.yhxm like '%${filter.searchText}%'
            OR b.yhdz like '%${filter.searchText}%'
            OR b.lxdh like '%${filter.searchText}%')
        </if>
        <!--所属公司-->
        <if test="filter.ssgs!=null">
            AND b.ssgs=#{filter.ssgs}
        </if>
        <!--所属片区-->
        <if test="filter.sscbpq!=null">
            AND b.sscbpq=#{filter.sscbpq}
        </if>
        <if test="filter.sscbb!=null">
            <choose>
                <when test="filter.sscbb.indexOf(',')!=-1">
                    AND b.sscbb in
                    <foreach item="item" index="index" collection="filter.sscbb.split(',')" open="(" separator=","
                             close=")">
                        #{item}
                    </foreach>
                </when>
                <otherwise>
                    AND b.sscbb=#{filter.sscbb}
                </otherwise>
            </choose>
        </if>
        <if test="filter.cby!=null">
            AND d.cby=#{filter.cby}
        </if>
        <if test="filter.qyfzr!=null">
            and b.sscbb in(select cbbbm from bm_cbb where qyfzr=#{qyfzr})
        </if>
        <if test="filter.rks!=null">
            AND b.rks=#{filter.rks}
        </if>
        <if test="filter.yhbhStart!=null">
            <![CDATA[ AND a.register_yhbh>=#{filter.yhbhStart} ]]>
        </if>
        <if test="filter.yhbhEnd!=null">
            <![CDATA[ AND a.register_yhbh<=#{filter.yhbhEnd} ]]>
        </if>
        <if test="filter.czsjStart!=null">
            <![CDATA[ and a.register_date >= #{filter.czsjStart}+0]]>
        </if>
        <if test="filter.czsjEnd!=null">
            <![CDATA[ and a.register_date <= #{filter.czsjEnd}+0]]>
        </if>
    </select>

</mapper>
