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

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id
        , yw_id, zllx, zlly, zlzxlx, zlbt, zlnr, zlzxqk, zlfqrq, zlfqsj, zldj, zlyxsj, zljsdx, qszt, qssj, ddxczt,
        ddxcsj, zlwjzt, zlwjsj, zlwjsm, zlzxzt, jd, wd, zb, 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
    </sql>

    <select id="rwzttjxx" resultType="com.mosty.base.model.vo.yjzl.TbYjzltjxxVo">
        select count(1) total,zlwjzt from tb_zlxx c where c.xt_sjzt = '1' and c.xt_scbz = '0' and c.id in (
            select zl_id from 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 zlwjzt
    </select>

    <select id="rwphtjxx" resultType="com.mosty.base.model.vo.yjzl.TbYjzltjphVo">
        select count,ssbmdm,ssbm name,YTotal,NTotal,(IFNULL(YTotal, 0) / (IFNULL(YTotal, 0) + IFNULL(NTotal, 0))) wcl
        from (
        select count(1) count,a.ssbmdm,a.ssbm,
        (select count(1) from tb_zlxx_zxr b ,tb_zlxx d where b.zl_id = d.id
        <if test="kssj != null and kssj != '' and jssj != null and jssj != jssj">
            d.zlfqrq &gt;= #{kssj} and zlfqrq &lt;= #{jssj}
        </if>
        and a.ssbmdm = b.ssbmdm and b.dqzt in ('92','93')) YTotal,
        (select count(1) from tb_zlxx_zxr b ,tb_zlxx d where b.zl_id = d.id
        <if test="kssj != null and kssj != '' and jssj != null and jssj != jssj">
            d.zlfqrq &gt;= #{kssj} and zlfqrq &lt;= #{jssj}
        </if>
        and a.ssbmdm = b.ssbmdm and b.dqzt not in ('92','93')) NTotal
        from tb_zlxx_zxr a ,tb_zlxx c where a.zl_id = c.id
        <if test="kssj != null and kssj != '' and jssj != null and jssj != jssj">
            c.zlfqrq &gt;= #{kssj} and zlfqrq &lt;= #{jssj}
        </if>
        group by a.ssbmdm,a.ssbm
        ) t
        limit 10
    </select>

    <select id="zlZqtjxx" resultType="Map" parameterType="map">
        select IFNULL(count(1),0) count,zllx
        from tb_zlxx
        where xt_sjzt = '1'
        and xt_scbz = '0'
        <if test="kssj != null and kssj != '' and jssj != null and jssj != ''">
            and zlfqsj &gt;= #{kssj} and zlfqsj &lt;= #{jssj}
        </if>
        <if test="start != null and start != '' and end != null and end != ''">
            and zlfqrq &gt;= #{start} and zlfqrq &lt;= #{end}
        </if>
        group by zllx
    </select>

    <select id="zlDjtjxx" resultType="com.mosty.base.model.vo.yjzl.TbYzzlDjtjVo" parameterType="map">
        SELECT count(1) total,
        zldj
        FROM tb_zlxx
        WHERE xt_sjzt = '1'
        AND xt_scbz = '0'
        <if test="kssj != null and kssj != '' and jssj != null and jssj != ''">
            AND zlfqrq &gt;= #{kssj} and zlfqsj &lt;= #{jssj}
        </if>
        GROUP BY zldj
    </select>
</mapper>
