<?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.securitycontrol.background.mapper.TaskCheckMapper">
    <insert id="replaceCheck">
        replace into t_class_metting_check
            (class_id,is_xs,user_id,check_time,create_day) values (#{classId},0,#{userId},0,CURRENT_DATE())
    </insert>
    <delete id="delTask">
         DELETE FROM t_class_metting_check WHERE class_id = #{classId} and user_id=#{userId}
    </delete>
    <delete id="delAllTask">
         DELETE FROM t_class_metting_check WHERE   user_id=#{userId}
    </delete>

    <select id="getPageList" resultType="com.securitycontrol.entity.background.vo.ClassCheckVo">
        select su.login_name loginName,su.user_id userId,user_name userName,count(cmc.class_id)  checkNum
				from sys_user su
				left join  sys_role sr on su.role_id=sr.role_id and sr.del_flag=0
				left join t_class_metting_check  cmc on cmc.user_id=su.user_id and cmc.create_day=CURRENT_DATE()
				where sr.role_code='duty'  and su.del_flag=0
				<if test="keyWord!=null and keyWord!='' ">
                 AND   (
                        su.login_name LIKE concat('%',#{keyWord},'%')  or
                        su.user_name LIKE concat('%',#{keyWord},'%')
                    )
                </if>
				GROUP BY  su.login_name,su.user_id,user_name
    </select>
    <select id="getClassList" resultType="com.securitycontrol.entity.background.vo.ClassCheckVo">
        select tcm.user_id userId,cm.class_id classId,cm.bid_name proName,cm.org,cm.work_manager 				workManage,
                  so.city_name cityName
            FROM    t_class_metting cm
            left join  t_class_metting_check tcm  on cm.class_id=tcm.class_id
            left join sys_build so on so.org_id=cm.org
             where  cm.del_flag=0
            <if test='type=="3"'>
                <if test='userId!=null and userId!="" '>
                    and   tcm.user_id=#{userId}
                </if>
            </if>
            <if test='types=="2"'>
                and   tcm.user_id is null
            </if>
            <if test='types=="1"'>
                and  tcm.user_id is not null     and   tcm.user_id!=#{userId}
            </if>
            <if test="keyWord!=null and keyWord!=''">
                AND   (
                    cm.bid_name LIKE concat('%',#{keyWord},'%')  or
                    cm.work_manager LIKE concat('%',#{keyWord},'%') or
                    so.city_name LIKE concat('%',#{keyWord},'%')
                )
            </if>
            <if test="orgId!=null and orgId!=''">
                    AND  cm.org=#{orgId}
            </if>
    </select>
</mapper>