<?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.TbQwZbpbZqMapper">
    <!--删除值班排班信息-->
    <delete id="deleteByPbId" parameterType="String">
        delete
        from tb_qw_zbpb_zq
        where pb_id = #{pbId}
    </delete>

    <select id="getMyZbpbToday" resultType="com.mosty.base.model.vo.qwzx.TbQwZbpbZqMyVo">
        <![CDATA[
        select b.*, a.id as mrjlid
        from tb_qw_zbpb_zq b,
             tb_qw_zbpb_mrjl a
        where a.pbzq_id = b.id
          and b.xt_scbz = '0'
          and b.xt_sjzt = '1'
          and (b.zbld_id = #{userId}
                or b.zbzhz_id = #{userId}
                or b.zzzhz_id = #{userId}
                or b.fzzb_id = #{userId}
                or b.id in
                   (select ywid
                    from tb_qw_jl c
                    where c.ywid = b.id
                      and c.jl_id = #{userId}
                      and c.xt_scbz = '0'
                      and c.xt_sjzt = '1'
                           )
                )
          and zbkssj BETWEEN DATE_FORMAT(date_add(now(),interval - 2 hour), '%Y-%m-%d %H:%i:%s')
          and DATE_FORMAT(date_add(now(),interval + 2 hour), '%Y-%m-%d %H:%i:%s')
          order by zbkssj
          limit 1
        ]]>
    </select>

    <select id="getMyZbpbByTime" resultType="com.mosty.base.model.entity.qwzx.TbQwZbpbZq">
        select b.*
        from tb_qw_zbpb_zq b,
             tb_qw_zbpb_mrjl a
        where a.pbzq_id = b.id
          and b.xt_scbz = '0'
          and b.xt_sjzt = '1'
          and (b.zbld_id = #{userId} or
               b.zbzhz_id = #{userId} or
               b.zzzhz_id = #{userId} or
               b.fzzb_id = #{userId} or
               b.id in
               (select ywid
                from tb_qw_jl c
                where c.ywid = b.id
                  and c.jl_id = #{userId}
                  and c.xt_scbz = '0'
                  and c.xt_sjzt = '1'
                       )
                )
          and DATE_FORMAT(#{kssj}, '%Y-%m-%d') = DATE_FORMAT(a.zbrq, '%Y-%m-%d')
    </select>

    <select id="getDeptByMonth" resultType="com.mosty.base.model.entity.qwzx.TbQwZbpbZq">
        select b.*
        from tb_qw_zbpb_zq b,
             tb_qw_zbpb_mrjl a
        where a.pbzq_id = b.id
          and b.xt_scbz = '0'
          and b.xt_sjzt = '1'
          and b.ssbmid = #{ssbmid}
          and DATE_FORMAT(#{kssj}, '%Y-%m-%d') = DATE_FORMAT(a.zbrq, '%Y-%m-%d')
    </select>
</mapper>


