<?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.qwzx.mapper.TbQwJlMapper">

    <resultMap type="com.mosty.base.model.entity.qwzx.TbQwJl" id="TbQwJlMap">
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="ywid" column="ywid" jdbcType="VARCHAR"/>
        <result property="jllx" column="jllx" jdbcType="VARCHAR"/>
        <result property="jlId" column="jl_id" jdbcType="VARCHAR"/>
        <result property="jlxm" column="jlxm" jdbcType="VARCHAR"/>
        <result property="sfzh" column="sfzh" jdbcType="VARCHAR"/>
        <result property="lxdh" column="lxdh" jdbcType="VARCHAR"/>
        <result property="xbdm" column="xbdm" jdbcType="VARCHAR"/>
        <result property="nl" column="nl" jdbcType="INTEGER"/>
        <result property="jlzt" column="jlzt" jdbcType="VARCHAR"/>
        <result property="zblx" column="zblx" jdbcType="VARCHAR"/>
        <result property="ssbm" column="ssbm" jdbcType="VARCHAR"/>
        <result property="ssbmdm" column="ssbmdm" jdbcType="VARCHAR"/>
        <result property="ssxgaj" column="ssxgaj" jdbcType="VARCHAR"/>
        <result property="ssxgajdm" column="ssxgajdm" jdbcType="VARCHAR"/>
        <result property="sssgaj" column="sssgaj" jdbcType="VARCHAR"/>
        <result property="sssgajdm" column="sssgajdm" 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"/>
    </resultMap>

    <!--查询所有-->
    <select id="queryAll" resultMap="TbQwJlMap">
        select id,
               ywid,
               jllx,
               jl_id,
               jlxm,
               sfzh,
               xbdm,
               nl,
               jlzt,
               zblx,
               ssbm,
               ssbmdm,
               ssxgaj,
               ssxgajdm,
               sssgaj,
               sssgajdm,
               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
        from tb_qw_jl
    </select>

    <!--查询单个-->
    <select id="queryById" resultMap="TbQwJlMap">
        select id,
               ywid,
               jllx,
               jl_id,
               jlxm,
               sfzh,
               xbdm,
               nl,
               jlzt,
               zblx,
               ssbm,
               ssbmdm,
               ssxgaj,
               ssxgajdm,
               sssgaj,
               sssgajdm,
               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
        from tb_qw_jl
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TbQwJlMap">
        select
        id, ywid, jllx, jl_id, jlxm, sfzh, xbdm, nl, jlzt, zblx, ssbm, ssbmdm, ssxgaj, ssxgajdm, sssgaj, sssgajdm,
        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
        from tb_qw_jl
        <where>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="ywid != null and ywid != ''">
                and ywid = #{ywid}
            </if>
            <if test="jllx != null and jllx != ''">
                and jllx = #{jllx}
            </if>
            <if test="jlId != null and jlId != ''">
                and jl_id = #{jlId}
            </if>
            <if test="jlxm != null and jlxm != ''">
                and jlxm = #{jlxm}
            </if>
            <if test="sfzh != null and sfzh != ''">
                and sfzh = #{sfzh}
            </if>
            <if test="xbdm != null and xbdm != ''">
                and xbdm = #{xbdm}
            </if>
            <if test="nl != null">
                and nl = #{nl}
            </if>
            <if test="jlzt != null and jlzt != ''">
                and jlzt = #{jlzt}
            </if>
            <if test="zblx != null and zblx != ''">
                and zblx = #{zblx}
            </if>
            <if test="ssbm != null and ssbm != ''">
                and ssbm = #{ssbm}
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                and ssbmdm = #{ssbmdm}
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                and ssxgaj = #{ssxgaj}
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                and ssxgajdm = #{ssxgajdm}
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                and sssgaj = #{sssgaj}
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                and sssgajdm = #{sssgajdm}
            </if>
            <if test="xtSjly != null and xtSjly != ''">
                and xt_sjly = #{xtSjly}
            </if>
            <if test="xtSjzt != null and xtSjzt != ''">
                and xt_sjzt = #{xtSjzt}
            </if>
            <if test="xtScbz != null and xtScbz != ''">
                and xt_scbz = #{xtScbz}
            </if>
            <if test="xtCjip != null and xtCjip != ''">
                and xt_cjip = #{xtCjip}
            </if>
            <if test="xtCjsj != null">
                and xt_cjsj = #{xtCjsj}
            </if>
            <if test="xtCjrId != null and xtCjrId != ''">
                and xt_cjr_id = #{xtCjrId}
            </if>
            <if test="xtCjr != null and xtCjr != ''">
                and xt_cjr = #{xtCjr}
            </if>
            <if test="xtCjbmdm != null and xtCjbmdm != ''">
                and xt_cjbmdm = #{xtCjbmdm}
            </if>
            <if test="xtCjbmmc != null and xtCjbmmc != ''">
                and xt_cjbmmc = #{xtCjbmmc}
            </if>
            <if test="xtZhgxip != null and xtZhgxip != ''">
                and xt_zhgxip = #{xtZhgxip}
            </if>
            <if test="xtZhgxsj != null">
                and xt_zhgxsj = #{xtZhgxsj}
            </if>
            <if test="xtZhgxrid != null and xtZhgxrid != ''">
                and xt_zhgxrid = #{xtZhgxrid}
            </if>
            <if test="xtZhgxr != null and xtZhgxr != ''">
                and xt_zhgxr = #{xtZhgxr}
            </if>
            <if test="xtZhgxbmdm != null and xtZhgxbmdm != ''">
                and xt_zhgxbmdm = #{xtZhgxbmdm}
            </if>
            <if test="xtZhgxbm != null and xtZhgxbm != ''">
                and xt_zhgxbm = #{xtZhgxbm}
            </if>
            <if test="bz != null and bz != ''">
                and bz = #{bz}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from tb_qw_jl
        <where>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="ywid != null and ywid != ''">
                and ywid = #{ywid}
            </if>
            <if test="jllx != null and jllx != ''">
                and jllx = #{jllx}
            </if>
            <if test="jlId != null and jlId != ''">
                and jl_id = #{jlId}
            </if>
            <if test="jlxm != null and jlxm != ''">
                and jlxm = #{jlxm}
            </if>
            <if test="sfzh != null and sfzh != ''">
                and sfzh = #{sfzh}
            </if>
            <if test="xbdm != null and xbdm != ''">
                and xbdm = #{xbdm}
            </if>
            <if test="nl != null">
                and nl = #{nl}
            </if>
            <if test="jlzt != null and jlzt != ''">
                and jlzt = #{jlzt}
            </if>
            <if test="zblx != null and zblx != ''">
                and zblx = #{zblx}
            </if>
            <if test="ssbm != null and ssbm != ''">
                and ssbm = #{ssbm}
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                and ssbmdm = #{ssbmdm}
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                and ssxgaj = #{ssxgaj}
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                and ssxgajdm = #{ssxgajdm}
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                and sssgaj = #{sssgaj}
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                and sssgajdm = #{sssgajdm}
            </if>
            <if test="xtSjly != null and xtSjly != ''">
                and xt_sjly = #{xtSjly}
            </if>
            <if test="xtSjzt != null and xtSjzt != ''">
                and xt_sjzt = #{xtSjzt}
            </if>
            <if test="xtScbz != null and xtScbz != ''">
                and xt_scbz = #{xtScbz}
            </if>
            <if test="xtCjip != null and xtCjip != ''">
                and xt_cjip = #{xtCjip}
            </if>
            <if test="xtCjsj != null">
                and xt_cjsj = #{xtCjsj}
            </if>
            <if test="xtCjrId != null and xtCjrId != ''">
                and xt_cjr_id = #{xtCjrId}
            </if>
            <if test="xtCjr != null and xtCjr != ''">
                and xt_cjr = #{xtCjr}
            </if>
            <if test="xtCjbmdm != null and xtCjbmdm != ''">
                and xt_cjbmdm = #{xtCjbmdm}
            </if>
            <if test="xtCjbmmc != null and xtCjbmmc != ''">
                and xt_cjbmmc = #{xtCjbmmc}
            </if>
            <if test="xtZhgxip != null and xtZhgxip != ''">
                and xt_zhgxip = #{xtZhgxip}
            </if>
            <if test="xtZhgxsj != null">
                and xt_zhgxsj = #{xtZhgxsj}
            </if>
            <if test="xtZhgxrid != null and xtZhgxrid != ''">
                and xt_zhgxrid = #{xtZhgxrid}
            </if>
            <if test="xtZhgxr != null and xtZhgxr != ''">
                and xt_zhgxr = #{xtZhgxr}
            </if>
            <if test="xtZhgxbmdm != null and xtZhgxbmdm != ''">
                and xt_zhgxbmdm = #{xtZhgxbmdm}
            </if>
            <if test="xtZhgxbm != null and xtZhgxbm != ''">
                and xt_zhgxbm = #{xtZhgxbm}
            </if>
            <if test="bz != null and bz != ''">
                and bz = #{bz}
            </if>
        </where>
    </select>

    <select id="countReportPolice" resultType="Map">
        select count(*) bb, zblx
        from tb_qw_jl
        where zblx is not null
          and xt_sjzt = '1'
          and DATE_FORMAT(xt_cjsj, '%Y-%m-%d') = DATE_FORMAT(now(), '%Y-%m-%d')
            ${sql}
        GROUP BY zblx
    </select>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tb_qw_jl(id, ywid, jllx, jl_id, jlxm, sfzh, xbdm, nl, jlzt, zblx, ssbm, ssbmdm, ssxgaj, ssxgajdm,
        sssgaj, sssgajdm, 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)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.ywid}, #{entity.jllx}, #{entity.jlId}, #{entity.jlxm}, #{entity.sfzh}, #{entity.xbdm},
            #{entity.nl}, #{entity.jlzt}, #{entity.zblx}, #{entity.ssbm}, #{entity.ssbmdm}, #{entity.ssxgaj},
            #{entity.ssxgajdm}, #{entity.sssgaj}, #{entity.sssgajdm}, #{entity.xtSjly}, #{entity.xtSjzt},
            #{entity.xtScbz}, #{entity.xtCjip}, #{entity.xtCjsj}, #{entity.xtCjrId}, #{entity.xtCjr},
            #{entity.xtCjbmdm}, #{entity.xtCjbmmc}, #{entity.xtZhgxip}, #{entity.xtZhgxsj}, #{entity.xtZhgxrid},
            #{entity.xtZhgxr}, #{entity.xtZhgxbmdm}, #{entity.xtZhgxbm}, #{entity.bz})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into tb_qw_jl(ywid, jllx, jl_id, jlxm, sfzh, xbdm, nl, jlzt, zblx, ssbm, ssbmdm, ssxgaj, ssxgajdm,
        sssgaj, sssgajdm, 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)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.ywid}, #{entity.jllx}, #{entity.jlId}, #{entity.jlxm}, #{entity.sfzh}, #{entity.xbdm},
            #{entity.nl}, #{entity.jlzt}, #{entity.zblx}, #{entity.ssbm}, #{entity.ssbmdm}, #{entity.ssxgaj},
            #{entity.ssxgajdm}, #{entity.sssgaj}, #{entity.sssgajdm}, #{entity.xtSjly}, #{entity.xtSjzt},
            #{entity.xtScbz}, #{entity.xtCjip}, #{entity.xtCjsj}, #{entity.xtCjrId}, #{entity.xtCjr},
            #{entity.xtCjbmdm}, #{entity.xtCjbmmc}, #{entity.xtZhgxip}, #{entity.xtZhgxsj}, #{entity.xtZhgxrid},
            #{entity.xtZhgxr}, #{entity.xtZhgxbmdm}, #{entity.xtZhgxbm}, #{entity.bz})
        </foreach>
        on duplicate key update
        ywid = values(ywid),
        jllx = values(jllx),
        jl_id = values(jl_id),
        jlxm = values(jlxm),
        sfzh = values(sfzh),
        xbdm = values(xbdm),
        nl = values(nl),
        jlzt = values(jlzt),
        zblx = values(zblx),
        ssbm = values(ssbm),
        ssbmdm = values(ssbmdm),
        ssxgaj = values(ssxgaj),
        ssxgajdm = values(ssxgajdm),
        sssgaj = values(sssgaj),
        sssgajdm = values(sssgajdm),
        xt_sjly = values(xt_sjly),
        xt_sjzt = values(xt_sjzt),
        xt_scbz = values(xt_scbz),
        xt_cjip = values(xt_cjip),
        xt_cjsj = values(xt_cjsj),
        xt_cjr_id = values(xt_cjr_id),
        xt_cjr = values(xt_cjr),
        xt_cjbmdm = values(xt_cjbmdm),
        xt_cjbmmc = values(xt_cjbmmc),
        xt_zhgxip = values(xt_zhgxip),
        xt_zhgxsj = values(xt_zhgxsj),
        xt_zhgxrid = values(xt_zhgxrid),
        xt_zhgxr = values(xt_zhgxr),
        xt_zhgxbmdm = values(xt_zhgxbmdm),
        xt_zhgxbm = values(xt_zhgxbm),
        bz = values(bz)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tb_qw_jl
        <set>
            <if test="ywid != null and ywid != ''">
                ywid = #{ywid},
            </if>
            <if test="jllx != null and jllx != ''">
                jllx = #{jllx},
            </if>
            <if test="jlId != null and jlId != ''">
                jl_id = #{jlId},
            </if>
            <if test="jlxm != null and jlxm != ''">
                jlxm = #{jlxm},
            </if>
            <if test="sfzh != null and sfzh != ''">
                sfzh = #{sfzh},
            </if>
            <if test="xbdm != null and xbdm != ''">
                xbdm = #{xbdm},
            </if>
            <if test="nl != null">
                nl = #{nl},
            </if>
            <if test="jlzt != null and jlzt != ''">
                jlzt = #{jlzt},
            </if>
            <if test="zblx != null and zblx != ''">
                zblx = #{zblx},
            </if>
            <if test="ssbm != null and ssbm != ''">
                ssbm = #{ssbm},
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                ssbmdm = #{ssbmdm},
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                ssxgaj = #{ssxgaj},
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                ssxgajdm = #{ssxgajdm},
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                sssgaj = #{sssgaj},
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                sssgajdm = #{sssgajdm},
            </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="bz != null and bz != ''">
                bz = #{bz},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">

    </update>
    <update id="deleteByYwid">
        delete
        from tb_qw_jl
        where ywid = #{ywid}
    </update>

    <select id="queryListByYwid" resultType="com.mosty.base.model.entity.qwzx.TbQwJl">
        select a.* from tb_qw_jl a
        where a.xt_scbz = '0'
        and a.ywid in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <!--查询今日报备警力数量-->
    <select id="getCount" resultType="Integer" parameterType="Map">
        select count(1) from tb_qw_jl a where a.xt_scbz = '0' and a.xt_sjzt = '1'
        and a.zblx = '3'
        <if test="dto.jllx != null and dto.jllx != ''">
            and a.jllx = #{dto.jllx}
        </if>
        <if test="dto.jlxm != null and dto.jlxm != ''">
            and a.jlxm like concat('%',#{dto.jlxm},'%')
        </if>
        and a.ywid in (
        select id from tb_qw_xfbb b where b.xt_scbz = '0' and b.xt_sjzt = '1' and b.bbzt = '0'
        <if test="dto.xfbmdm != null and dto.xfbmdm != ''">
            and b.xfbmdm like concat(#{dto.xfbmdm},'%')
        </if>
        )
    </select>

    <!--查询今日报备警力集合-->
    <select id="getList" resultMap="TbQwJlMap" parameterType="Map">
        select * from tb_qw_jl a where a.xt_scbz = '0' and a.xt_sjzt = '1'
        and a.zblx = '3'
        <if test="dto.jllx != null and dto.jllx != ''">
            and a.jllx = #{dto.jllx}
        </if>
        <if test="dto.jlxm != null and dto.jlxm != ''">
            and a.jlxm like concat('%',#{dto.jlxm},'%')
        </if>
        and a.ywid in (
        select id from tb_qw_xfbb b where b.xt_scbz = '0' and b.xt_sjzt = '1' and b.bbzt = '0'
        <if test="dto.xfbmdm != null and dto.xfbmdm != ''">
            and b.xfbmdm like concat(#{dto.xfbmdm},'%')
        </if>

<!--        ${useSql}-->
        )
        limit #{pageIndex},#{pageSize}
    </select>

</mapper>


