<?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.mosty.yjzl.mapper.TbZlxxMapper">
    <resultMap type="com.mosty.base.model.entity.yjzl.TbZlxx" id="tbZlxx">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="ywId" column="yw_id" jdbcType="VARCHAR"/>
        <result property="zllx" column="zllx" jdbcType="VARCHAR"/>
        <result property="zlly" column="zlly" jdbcType="VARCHAR"/>
        <result property="zlzxlx" column="zlzxlx" jdbcType="VARCHAR"/>
        <result property="zlbt" column="zlbt" jdbcType="VARCHAR"/>
        <result property="zlnr" column="zlnr" jdbcType="VARCHAR"/>
        <result property="zlzxqk" column="zlzxqk" jdbcType="VARCHAR"/>
        <result property="zlfqrq" column="zlfqrq" jdbcType="TIMESTAMP"/>
        <result property="zlfqsj" column="zlfqsj" jdbcType="TIMESTAMP"/>
        <result property="zldj" column="zldj" jdbcType="VARCHAR"/>
        <result property="qsyxsj" column="qsyxsj" jdbcType="TIMESTAMP"/>
        <result property="zljsdx" column="zljsdx" jdbcType="VARCHAR"/>
        <result property="qszt" column="qszt" jdbcType="VARCHAR"/>
        <result property="qssj" column="qssj" jdbcType="TIMESTAMP"/>
        <result property="ddxczt" column="ddxczt" jdbcType="VARCHAR"/>
        <result property="ddxcsj" column="ddxcsj" jdbcType="TIMESTAMP"/>
        <result property="ddxcyxsj" column="ddxcyxsj" jdbcType="TIMESTAMP"/>
        <result property="zlwjzt" column="zlwjzt" jdbcType="VARCHAR"/>
        <result property="zlwjsj" column="zlwjsj" jdbcType="TIMESTAMP"/>
        <result property="zlwjsm" column="zlwjsm" jdbcType="VARCHAR"/>
        <result property="zlwjyxsj" column="zlwjyxsj" jdbcType="TIMESTAMP"/>
        <result property="zlzxzt" column="zlzxzt" jdbcType="VARCHAR"/>
        <result property="jd" column="jd" jdbcType="NUMERIC"/>
        <result property="wd" column="wd" jdbcType="NUMERIC"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.PointTypeHandler"/>
        <result property="zbhash" column="zbhash" jdbcType="VARCHAR"/>
        <result property="zlfsddxzqh" column="zlfsddxzqh" jdbcType="VARCHAR"/>
        <result property="zlfsdd" column="zlfsdd" jdbcType="VARCHAR"/>
        <result property="zlfqrId" column="zlfqr_id" jdbcType="VARCHAR"/>
        <result property="zlfqr" column="zlfqr" jdbcType="VARCHAR"/>
        <result property="zlfqrSfzh" column="zlfqr_sfzh" jdbcType="VARCHAR"/>
        <result property="zlfqrDh" column="zlfqr_dh" jdbcType="VARCHAR"/>
        <result property="fjId" column="fj_id" jdbcType="VARCHAR"/>
        <result property="zljsrs" column="zljsrs" jdbcType="INTEGER"/>
        <result property="zltp" column="zltp" jdbcType="VARCHAR"/>
        <result property="ssbm" column="ssbm" jdbcType="VARCHAR"/>
        <result property="ssbmdm" column="ssbmdm" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
        <result property="ssxgaj" column="ssxgaj" jdbcType="VARCHAR"/>
        <result property="ssxgajdm" column="ssxgajdm" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="sssgaj" column="sssgaj" jdbcType="VARCHAR"/>
        <result property="sssgajdm" column="sssgajdm" jdbcType="VARCHAR"/>
        <result property="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="xtSjly" column="xt_sjly" jdbcType="VARCHAR"/>
        <result property="xtSjzt" column="xt_sjzt" jdbcType="VARCHAR"/>
        <result property="xtScbz" column="xt_scbz" jdbcType="VARCHAR"/>
        <result property="xtCjip" column="xt_cjip" jdbcType="VARCHAR"/>
        <result property="xtCjsj" column="xt_cjsj" jdbcType="VARCHAR"/>
        <result property="xtCjrId" column="xt_cjr_id" jdbcType="VARCHAR"/>
        <result property="xtCjr" column="xt_cjr" jdbcType="VARCHAR"/>
        <result property="xtCjbmdm" column="xt_cjbmdm" jdbcType="VARCHAR"/>
        <result property="xtCjbmmc" column="xt_cjbmmc" jdbcType="VARCHAR"/>
        <result property="xtZhgxip" column="xt_zhgxip" jdbcType="VARCHAR"/>
        <result property="xtZhgxsj" column="xt_zhgxsj" jdbcType="VARCHAR"/>
        <result property="xtZhgxrid" column="xt_zhgxrid" jdbcType="VARCHAR"/>
        <result property="xtZhgxr" column="xt_zhgxr" jdbcType="VARCHAR"/>
        <result property="xtZhgxbmdm" column="xt_zhgxbmdm" jdbcType="VARCHAR"/>
        <result property="xtZhgxbm" column="xt_zhgxbm" jdbcType="VARCHAR"/>
        <result property="bz" column="bz" jdbcType="VARCHAR"/>
        <result property="zlxflx" column="zlxflx" jdbcType="VARCHAR"/>
        <result property="distance" column="distance" jdbcType="NUMERIC"/>
    </resultMap>

    <sql id="base_column_list">
        id,yw_id,zllx,zlly,zlzxlx,zlbt,zlnr,zlzxqk,zlfqrq,zlfqsj,zldj,qsyxsj,zljsdx,qszt,qssj,ddxcyxsj,zlwjyxsj,
                        ddxczt,ddxcsj,zlwjzt,zlwjsj,zlwjsm,zlzxzt,jd,wd,zbhash,zlfsddxzqh,zlfsdd,zlfqr_id,
                        zlfqr,zlfqr_sfzh,zlfqr_dh,fj_id,zljsrs,zltp,ssbm,ssbmdm,ssbmid,ssxgaj, ssxgajdm,ssxgajid,
                        sssgaj,sssgajdm,sssgajid,xt_sjly, xt_sjzt, xt_scbz,
                        xt_cjip, xt_cjsj, xt_cjr_id, xt_cjr, xt_cjbmdm, xt_cjbmmc, xt_zhgxip, xt_zhgxsj,
                        xt_zhgxrid,xt_zhgxr, xt_zhgxbmdm, xt_zhgxbm, bz,zlxflx
    </sql>

    <sql id="Blob_Column_List">
        ST_ASWKT
                (zb)
                as zb
    </sql>

    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.yjzl.TbZlxx">
        insert into tb_zlxx(id, yw_id, zllx, zlly, zlzxlx, zlbt, zlnr, zlzxqk, zlfqrq, zlfqsj, zldj, qsyxsj, zljsdx,
                            qszt, qssj,
                            ddxczt, ddxcsj, zlwjzt, zlwjsj, zlwjsm, zlzxzt, jd, wd, zb, zbhash, zlfsddxzqh, zlfsdd,
                            zlfqr_id, ddxcyxsj, zlwjyxsj,
                            zlfqr, zlfqr_sfzh, zlfqr_dh, fj_id, zljsrs, zltp, ssbm, ssbmdm, ssbmid, ssxgaj, ssxgajdm,
                            ssxgajid,
                            sssgaj, sssgajdm, sssgajid, xt_sjly, xt_sjzt, xt_scbz,
                            xt_cjip, xt_cjsj, xt_cjr_id, xt_cjr, xt_cjbmdm, xt_cjbmmc, xt_zhgxip, xt_zhgxsj,
                            xt_zhgxrid, xt_zhgxr, xt_zhgxbmdm, xt_zhgxbm, bz, zlxflx)
        values (#{id}, #{ywId}, #{zllx}, #{zlly}, #{zlzxlx}, #{zlbt}, #{zlnr}, #{zlzxqk}, #{zlfqrq}, #{zlfqsj}, #{zldj},
                #{qsyxsj}, #{zljsdx}, #{qszt}, #{qssj},
                #{ddxczt}, #{ddxcsj}, #{zlwjzt}, #{zlwjsj}, #{zlwjsm}, #{zlzxzt}, #{jd}, #{wd},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.PointTypeHandler}),
                #{zbhash}, #{zlfsddxzqh}, #{zlfsdd}, #{zlfqrId}, #{ddxcyxsj}, #{zlwjyxsj},
                #{zlfqr}, #{zlfqrSfzh}, #{zlfqrDh}, #{fjId}, #{zljsrs}, #{zltp}, #{ssbm}, #{ssbmdm}, #{ssbmid},
                #{ssxgaj}, #{ssxgajdm}, #{ssxgajid},
                #{sssgaj}, #{sssgajdm}, #{sssgajid}, #{xtSjly}, #{ xtSjzt}, #{ xtScbz},
                #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr}, #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip}, #{xtZhgxsj},
                #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz}, #{zlxflx})
    </insert>

    <!--查询指令数量-->
    <select id="getCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_zlxx where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.zllx != null and dto.zllx != ''">
            and zllx = #{dto.zllx}
        </if>
        <if test="zllyList != null and zllyList.size > 0">
            and zlly in
            <foreach collection="zllyList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.zlbt != null and dto.zlbt != ''">
            and zlbt like concat('%',#{dto.zlbt},'%')
        </if>
        <if test="dto.zlnr != null and dto.zlnr != ''">
            and zlnr like concat('%',#{dto.zlnr},'%')
        </if>
        <if test="dto.zldj != null and dto.zldj != ''">
            and zldj = #{dto.zldj}
        </if>
        <if test="dto.ssbmid != null and dto.ssbmid != ''">
            and ssbmid = #{dto.ssbmid}
        </if>
        <if test="dto.sfcl != null and dto.sfcl != ''">
            and sfcl = #{dto.sfcl}
        </if>

        <if test="dto.zlxflx != null and dto.zlxflx != ''">
            and zlxflx = #{dto.zlxflx}
        </if>

        <if test="dto.zlwjzt != null and dto.zlwjzt != ''">
            and zlwjzt = #{dto.zlwjzt}
        </if>

        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and zlfqrq between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[and st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) <= #{dto.radius}]]>
        </if>
        ${useSql}
    </select>

    <!--查询指令列表-->
    <select id="getListPage" resultMap="tbZlxx" parameterType="Map">
        select
        <include refid="base_column_list"/>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            ,st_distance_sphere(POINT(jd,wd),POINT(#{dto.jd},#{dto.wd})) as distance
        </if>
        from tb_zlxx where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.zllx != null and dto.zllx != ''">
            and zllx = #{dto.zllx}
        </if>
        <if test="zllyList != null and zllyList.size > 0">
            and zlly in
            <foreach collection="zllyList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="dto.zlbt != null and dto.zlbt != ''">
            and zlbt like concat('%',#{dto.zlbt},'%')
        </if>
        <if test="dto.zlnr != null and dto.zlnr != ''">
            and zlnr like concat('%',#{dto.zlnr},'%')
        </if>
        <if test="dto.zldj != null and dto.zldj != ''">
            and zldj = #{dto.zldj}
        </if>
        <if test="dto.sfcl != null and dto.sfcl != ''">
            and sfcl = #{dto.sfcl}
        </if>
        <if test="dto.ssbmid != null and dto.ssbmid != ''">
            and ssbmid = #{dto.ssbmid}
        </if>

        <if test="dto.zlxflx != null and dto.zlxflx != ''">
            and zlxflx = #{dto.zlxflx}
        </if>

        <if test="dto.zlwjzt != null and dto.zlwjzt != ''">
            and zlwjzt = #{dto.zlwjzt}
        </if>

        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>
        <if test="dto.startTime != null and dto.startTime != '' and dto.endTime != null and dto.endTime != ''">
            and zlfqrq between #{dto.startTime} and #{dto.endTime}
        </if>
        <if test="dto.jd != null and dto.wd != null and dto.radius != null">
            <![CDATA[having distance <= #{dto.radius}]]>
        </if>
<!--        ${useSql}-->
        order by zlfqsj desc
        limit #{pageIndex},#{pageSize}
    </select>

    <select id="selectInstructCount" resultType="java.util.Map">
        SELECT count(*) zlzs,(SELECT count(*) zlzs FROM `tb_zlxx`
        where xt_sjzt = '1' and xt_scbz = '0'
        and zlwjzt = '91'
        <if test="startTime != null and endTime != null">
            and zlfqrq between #{startTime} and #{endTime}
        </if>
        <if test="ssbmdm != null and ssbmdm != ''">
            and ssbmdm like concat(#{ssbmdm},'%')
        </if>
        ) zlzxs
        FROM `tb_zlxx`
        where xt_sjzt = '1' and xt_scbz = '0'
        <if test="startTime != null and endTime != null">
            and zlfqrq between #{startTime} and #{endTime}
        </if>
        <if test="ssbmdm != null and ssbmdm != ''">
            and ssbmdm like concat(#{ssbmdm},'%')
        </if>
    </select>

    <!--修改-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.yjzl.TbZlxx">
        update tb_zlxx
        <set>
            <if test="ywId != null and ywId != ''">
                yw_id = #{ywId},
            </if>
            <if test="zllx != null and zllx != ''">
                zllx = #{zllx},
            </if>
            <if test="zlly != null and zlly != ''">
                zlly = #{zlly},
            </if>
            <if test="zlzxlx != null and zlzxlx != ''">
                zlzxlx = #{zlzxlx},
            </if>
            <if test="zlbt != null and zlbt != ''">
                zlbt = #{zlbt},
            </if>
            <if test="zlnr != null and zlnr != ''">
                zlnr = #{zlnr},
            </if>
            <if test="zlzxqk != null and zlzxqk != ''">
                zlzxqk = #{zlzxqk},
            </if>
            <if test="zlfqrq != null">
                zlfqrq = #{zlfqrq},
            </if>
            <if test="zlfqsj != null">
                zlfqsj = #{zlfqsj},
            </if>
            <if test="zldj != null and zldj != ''">
                zldj = #{zldj},
            </if>
            <if test="qsyxsj != null">
                qsyxsj = #{qsyxsj},
            </if>
            <if test="ddxcyxsj != null">
                ddxcyxsj = #{ddxcyxsj},
            </if>
            <if test="zlwjyxsj != null">
                zlwjyxsj = #{zlwjyxsj},
            </if>
            <if test="zljsdx != null and zljsdx != ''">
                zljsdx = #{zljsdx},
            </if>
            <if test="qszt != null and qszt != ''">
                qszt = #{qszt},
            </if>
            <if test="qssj != null">
                qssj = #{qssj},
            </if>
            <if test="ddxczt != null and ddxczt != ''">
                ddxczt = #{ddxczt},
            </if>
            <if test="ddxcsj != null">
                ddxcsj = #{ddxcsj},
            </if>
            <if test="zlwjzt != null and zlwjzt != ''">
                zlwjzt = #{zlwjzt},
            </if>
            <if test="zlwjsj != null">
                zlwjsj = #{zlwjsj},
            </if>
            <if test="zlwjsm != null and zlwjsm != ''">
                zlwjsm = #{zlwjsm},
            </if>
            <if test="zlzxzt != null and zlzxzt != ''">
                zlzxzt = #{zlzxzt},
            </if>
            <if test="jd != null">
                jd = #{jd},
            </if>
            <if test="wd != null">
                wd = #{wd},
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.PointTypeHandler}),
            </if>
            <if test="zbhash != null and zbhash != ''">
                zbhash = #{zbhash},
            </if>
            <if test="zlfsddxzqh != null and zlfsddxzqh != ''">
                zlfsddxzqh = #{zlfsddxzqh},
            </if>
            <if test="zlfsdd != null and zlfsdd != ''">
                zlfsdd = #{zlfsdd},
            </if>
            <if test="zlfqrId != null and zlfqrId != ''">
                zlfqr_id = #{zlfqrId},
            </if>
            <if test="zlfqr != null and zlfqr != ''">
                zlfqr = #{zlfqr},
            </if>
            <if test="zlfqrSfzh != null and zlfqrSfzh != ''">
                zlfqr_sfzh = #{zlfqrSfzh},
            </if>
            <if test="zlfqrDh != null and zlfqrDh != ''">
                zlfqr_dh = #{zlfqrDh},
            </if>
            <if test="fjId != null and fjId != ''">
                fj_id = #{fjId},
            </if>
            <if test="zljsrs != null">
                zljsrs = #{zljsrs},
            </if>
            <if test="zltp != null and zltp != ''">
                zltp = #{zltp},
            </if>
            <if test="ssbm != null and ssbm != ''">
                ssbm = #{ssbm},
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                ssbmdm = #{ssbmdm},
            </if>
            <if test="ssbmid != null and ssbmid != ''">
                ssbmid = #{ssbmid},
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                ssxgaj = #{ssxgaj},
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                ssxgajdm = #{ssxgajdm},
            </if>
            <if test="ssxgajid != null and ssxgajid != ''">
                ssxgajid = #{ssxgajid},
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                sssgaj = #{sssgaj},
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                sssgajdm = #{sssgajdm},
            </if>
            <if test="sssgajid != null and sssgajid != ''">
                sssgajid = #{sssgajid},
            </if>
            <if test="xtSjly != null and xtSjly != ''">
                xt_sjly = #{xtSjly},
            </if>
            <if test="xtSjzt != null and xtSjzt != ''">
                xt_sjzt = #{xtSjzt},
            </if>
            <if test="xtScbz != null and xtScbz != ''">
                xt_scbz = #{xtScbz},
            </if>
            <if test="xtCjip != null and xtCjip != ''">
                xt_cjip = #{xtCjip},
            </if>
            <if test="xtCjsj != null">
                xt_cjsj = #{xtCjsj},
            </if>
            <if test="xtCjrId != null and xtCjrId != ''">
                xt_cjr_id = #{xtCjrId},
            </if>
            <if test="xtCjr != null and xtCjr != ''">
                xt_cjr = #{xtCjr},
            </if>
            <if test="xtCjbmdm != null and xtCjbmdm != ''">
                xt_cjbmdm = #{xtCjbmdm},
            </if>
            <if test="xtCjbmmc != null and xtCjbmmc != ''">
                xt_cjbmmc = #{xtCjbmmc},
            </if>
            <if test="xtZhgxip != null and xtZhgxip != ''">
                xt_zhgxip = #{xtZhgxip},
            </if>
            <if test="xtZhgxsj != null">
                xt_zhgxsj = #{xtZhgxsj},
            </if>
            <if test="xtZhgxrid != null and xtZhgxrid != ''">
                xt_zhgxrid = #{xtZhgxrid},
            </if>
            <if test="xtZhgxr != null and xtZhgxr != ''">
                xt_zhgxr = #{xtZhgxr},
            </if>
            <if test="xtZhgxbmdm != null and xtZhgxbmdm != ''">
                xt_zhgxbmdm = #{xtZhgxbmdm},
            </if>
            <if test="xtZhgxbm != null and xtZhgxbm != ''">
                xt_zhgxbm = #{xtZhgxbm},
            </if>
            <if test="zlxflx != null and zlxflx != ''">
                zlxflx = #{zlxflx},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="getMyZlCount" resultType="Map" parameterType="Map">
        select count(1) count, zllx
        from mosty_yjzl.tb_zlxx_zxr a
        where a.xt_sjzt = '1'
          and a.xt_scbz = '0'
          and case
                when a.zxr_lx = '01' then
                        a.zxr_sfz = #{sfz}
                when a.zxr_lx = '03' then
                        a.zxr_xzid in (select b.id
                                       from mosty_qwgl.tb_qw_xfbb b,
                                            mosty_qwgl.tb_qw_jl c
                                       where b.id = c.ywid
                                         and b.xt_sjzt = '1'
                                         and b.xt_scbz = '0'
                                         and c.xt_sjzt = '1'
                                         and c.xt_scbz = '0'
                                         and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
                when a.zxr_lx = '02' then
                        a.ssbmid = #{ssbmid}
                end
        group by a.zllx
    </select>

    <select id="getMyZlCountBy" resultType="Integer">
        select count(1) from tb_zlxx_zxr a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        <if test="zlnr != null and zlnr != ''">
            <!-- and match(a.zlnr) against (#{zlnr})-->
            and a.zlnr like concat('%',#{zlnr},'%')
        </if>
        <if test="kssj != null and jssj != null and kssj != '' and jssj != ''">
            and DATE_FORMAT(a.zlfqsj,'%Y-%m-%d %H:%i:%s') between #{kssj} and #{jssj}
        </if>

        <if test="time != null and time != null">
            and a.zlfqsj > #{time}
        </if>
        <if test="ztList != null and ztList.size > 0">
            and a.zlzxzt in
            <foreach collection="ztList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="lxList != null and lxList.size > 0">
            and a.zllx in
            <foreach collection="lxList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="zllyList != null and zllyList.size > 0">
            and a.zlly in
            <foreach collection="zllyList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        and case
        when a.zxr_lx = '01' then
        a.zxr_sfz = #{sfz}
        when a.zxr_lx = '03' then
        a.zxr_xzid in (select b.id from mosty_qwgl.tb_qw_xfbb b,mosty_qwgl.tb_qw_jl c where b.id = c.ywid and b.xt_sjzt
        = '1'
        and b.xt_scbz = '0' and c.xt_sjzt = '1' and c.xt_scbz = '0' and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
        when a.zxr_lx = '02' then
        a.ssbmid = #{ssbmid}
        end
    </select>

    <select id="getMyZlList" resultType="com.mosty.base.model.vo.yjzl.TbZlxxZxrVo" parameterType="Map">
        select * from tb_zlxx_zxr a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        <if test="zlnr != null and zlnr != ''">
            <!-- and match(a.zlnr) against (#{zlnr})-->
            and a.zlnr like concat('%',#{zlnr},'%')
        </if>
        <if test="kssj != null and jssj != null and kssj != '' and jssj != ''">
            and DATE_FORMAT(a.zlfqsj,'%Y-%m-%d %H:%i:%s') between #{kssj} and #{jssj}
        </if>
        <if test="time != null and time != null">
            and a.zlfqsj > #{time}
        </if>
        <if test="ztList != null and ztList.size > 0">
            and a.dqzt in
            <foreach collection="ztList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="lxList != null and lxList.size > 0">
            and a.zllx in
            <foreach collection="lxList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="zllyList != null and zllyList.size > 0">
            and a.zlly in
            <foreach collection="zllyList" item="item" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        and case
        when a.zxr_lx = '01' then
        a.zxr_sfz = #{sfz}
        when a.zxr_lx = '03' then
        a.zxr_xzid in (select b.id from mosty_qwgl.tb_qw_xfbb b,mosty_qwgl.tb_qw_jl c where b.id = c.ywid and b.xt_sjzt
        = '1'
        and b.xt_scbz = '0' and c.xt_sjzt = '1' and c.xt_scbz = '0' and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
        when a.zxr_lx = '02' then
        a.ssbmid = #{ssbmid}
        end
        order by a.zlfqsj desc
        limit #{pageIndex},#{pageSize}
    </select>

    <select id="selectZxr" resultType="com.mosty.base.model.entity.yjzl.TbZlxxZxr">
        select *
        from mosty_yjzl.tb_zlxx_zxr a
        where a.xt_sjzt = '1'
          and a.xt_scbz = '0'
          and zl_id = #{zlId}
          and case
                when a.zxr_lx = '01' then
                        a.zxr_sfz = #{sfz}
                when a.zxr_lx = '03' then
                        a.zxr_xzid in (select b.id
                                       from mosty_qwgl.tb_qw_xfbb b,
                                            mosty_qwgl.tb_qw_jl c
                                       where b.id = c.ywid
                                         and b.xt_sjzt
                                               = '1'
                                         and b.xt_scbz = '0'
                                         and c.xt_sjzt = '1'
                                         and c.xt_scbz = '0'
                                         and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
                when a.zxr_lx = '02' then
                        a.ssbmid = #{ssbmid}
                end
    </select>

    <select id="getTjOfZllx" resultType="java.util.Map">
        select count(zllx) count, zllx
        from tb_zlxx
        where xt_scbz = '0'
        and xt_sjzt = '1'
        <if test="kssj != null and kssj != '' and jssj != null and jssj != jssj">
            zlfqrq &gt;= #{kssj} and zlfqrq &lt;= #{jssj}
        </if>
        <if test="ssbmdm != null and ssbmdm != ''">
            and ssbmdm like concat(#{ssbmdm},'%')
        </if>
        group by zllx
    </select>

    <select id="getStatisticsByStatus" resultType="int">
        select count(1) from tb_zlxx d where d.xt_sjzt = '1' and d.xt_scbz = '0'
        and d.id in (
        select zl_id from mosty_yjzl.tb_zlxx_zxr a where a.xt_sjzt = '1' and a.xt_scbz = '0'
        and case
        when a.zxr_lx = '01' then
        a.zxr_sfz = #{sfz}
        when a.zxr_lx = '03' then
        a.zxr_xzid in (select b.id from mosty_qwgl.tb_qw_xfbb b,mosty_qwgl.tb_qw_jl c where b.id = c.ywid and b.xt_sjzt
        = '1'
        and b.xt_scbz = '0' and c.xt_sjzt = '1' and c.xt_scbz = '0' and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
        when a.zxr_lx = '02' then
        a.ssbmid = #{ssbmid}
        end
        <if test='type == "2"'>
            and dqzt != '92' and dqzt != '93'
        </if>
        )
    </select>

    <select id="getStatistics" resultType="java.util.Map">
        select count(1) count, zlzxzt
        from mosty_yjzl.tb_zlxx_zxr a
        where a.xt_sjzt = '1'
          and a.xt_scbz = '0'
          and case
                when a.zxr_lx = '01' then
                        a.zxr_sfz = #{sfz}
                when a.zxr_lx = '03' then
                        a.zxr_xzid in (select b.id
                                       from mosty_qwgl.tb_qw_xfbb b,
                                            mosty_qwgl.tb_qw_jl c
                                       where b.id = c.ywid
                                         and b.xt_sjzt = '1'
                                         and b.xt_scbz = '0'
                                         and c.xt_sjzt = '1'
                                         and c.xt_scbz = '0'
                                         and (b.fzr_sfzh = #{sfz} or c.sfzh = #{sfz}))
                when a.zxr_lx = '02' then
                        a.ssbmid = #{ssbmid}
                end
        group by a.zlzxzt
    </select>
</mapper>
