<?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.TbQwXfpbZqMapper">
    <!--删除值班排班信息-->
    <delete id="deleteByPbId" parameterType="String">

                delete
                from tb_qw_xfpb_zq
                where pb_id = #{pbId}

    </delete>

    <!--APP获取我的排班信息-->
    <select id="getMyXfpbToday" resultType="com.mosty.base.model.vo.qwzx.TbQwXfpbZqMyVo" parameterType="String">
        <![CDATA[
        select b.*,a.id as mrjlid
        from tb_qw_xfpb_zq b,tb_qw_xfpb_mrjl a
        where a.pbzq_id = b.id
          and b.xt_scbz = '0'
          and b.xt_sjzt = '1'
          and (b.fzr_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 a.xfkssj 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 a.xfkssj
                limit 1
        ]]>
    </select>

    <select id="getMyXfpbByTime" resultType="com.mosty.base.model.entity.qwzx.TbQwXfpbZq">

                select b.* from tb_qw_xfpb_zq b,tb_qw_xfpb_mrjl a
                where a.pbzq_id = b.id
                and b.xt_scbz = '0'
                and b.xt_sjzt = '1'
                and (b.fzr_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.xfrq, '%Y-%m-%d')

    </select>

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


