<?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.template.mapper.SmartUserMapper">
    <resultMap type="com.template.model.vo.AffiliateUserVo" id="affiliateUserMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="cardNo" column="card_no"/>
        <result property="departmentId" column="department_id"/>
        <result property="headImage" column="head_image"/>
    </resultMap>

    <select id="queryAffiliateUserById" resultType="com.template.model.vo.AffiliateUserVo" resultMap="affiliateUserMap">
        select id,name,card_no,department_id,head_image from smart_user
        where find_in_set(id,(select affiliate from smart_user where
        deleted = 0
        <if test="id != null and id != ''">
            and id = #{id}
        </if>
        )) and deleted = 0
    </select>

    <resultMap type="com.template.model.vo.UserVo" id="smartUserPageMap">
        <result property="id" column="id"/>
        <result property="cardNo" column="card_no"/>
        <result property="name" column="name"/>
        <result property="identityId" column="identity_id"/>
        <result property="idCard" column="id_card"/>
        <result property="sexId" column="sex_id"/>
        <result property="departmentId" column="department_id"/>
        <result property="headImage" column="head_image"/>
        <result property="grade" column="grade"/>
        <result property="college" column="college"/>
        <result property="speciality" column="speciality"/>
        <result property="schoolClass" column="school_class"/>
        <result property="campus" column="campus"/>
        <result property="dormitoryNumber" column="dormitory_number"/>
        <result property="phone" column="phone"/>
        <result property="affiliate" column="affiliate"/>
        <result property="title" column="title"/>
        <result property="address" column="address"/>
        <result property="nation" column="nation"/>
        <result property="ofStudent" column="of_student"/>
        <result property="graduate" column="graduate"/>
        <result property="duties" column="duties"/>
        <result property="timeGroupId" column="time_group_id"/>
    </resultMap>
    <select id="querySmartUserPages" resultType="com.template.model.vo.UserVo" resultMap="smartUserPageMap">
        select
        id,card_no,name,identity_id,id_card,sex_id,department_id,head_image,grade,college,speciality,school_class,campus,dormitory_number,
        phone,affiliate,title,address,nation,of_student,graduate,duties,time_group_id
        from smart_user
        where deleted = 0 and is_cancel = 0
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
                ${departmentId}
            </foreach>
        </if>
        <if test="name != null and name != ''">
            and (name like '%' #{name} '%' or card_no like '%' #{name} '%')
        </if>
    </select>


    <resultMap type="com.template.model.pojo.SmartUser" id="smartUsersMap">
        <result property="cardNo" column="card_no"/>
        <result property="name" column="name"/>
        <result property="identityId" column="identity_id"/>
        <result property="idCard" column="id_card"/>
        <result property="sexId" column="sex_id"/>
        <result property="departmentId" column="department_id"/>
        <result property="headImage" column="head_image"/>
        <result property="grade" column="grade"/>
        <result property="college" column="college"/>
        <result property="speciality" column="speciality"/>
        <result property="schoolClass" column="school_class"/>
        <result property="campus" column="campus"/>
        <result property="dormitoryNumber" column="dormitory_number"/>
        <result property="phone" column="phone"/>
        <result property="affiliate" column="affiliate"/>
        <result property="title" column="title"/>
        <result property="address" column="address"/>
        <result property="nation" column="nation"/>
        <result property="ofStudent" column="of_student"/>
        <result property="graduate" column="graduate"/>
        <result property="duties" column="duties"/>
    </resultMap>
    <select id="querySmartUsers" resultType="com.template.model.pojo.SmartUser" resultMap="smartUsersMap">
        select
        card_no,name,identity_id,id_card,sex_id,department_id,head_image,grade,college,speciality,school_class,campus,dormitory_number,
        phone,affiliate,title,address,nation,of_student,graduate,duties from smart_user
        where deleted = 0 and is_cancel = 0
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
                ${departmentId}
            </foreach>
        </if>
        <if test="name != null and name != ''">
            and name like '%' #{name} '%'
        </if>
    </select>


    <resultMap type="com.template.model.vo.GradeVo" id="smartSecordUserPageMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="grade" column="grade"/>
        <result property="schoolClass" column="school_class"/>
        <result property="cardNo" column="card_no"/>
    </resultMap>
    <select id="querySmartSecordPage" resultType="com.template.model.vo.GradeVo" resultMap="smartSecordUserPageMap">
        select id,name,grade,school_class,card_no from smart_user
        where deleted = 0 and is_cancel = 0 and identity_id = 2
        <if test="name != null and name != ''">
            and name like '%' #{name} '%'
        </if>
    </select>

    <select id="warningUserList" resultType="com.template.model.vo.UserVo">
        select *
        from smart_user
        where deleted = 0 and is_cancel = 0
        <if test="departmentIds != null and departmentIds.size() > 0">
            and department_id in
            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
                ${departmentId}
            </foreach>
        </if>
        <if test="name != null and name != ''">
            and name like '%' #{name} '%'
        </if>
    </select>
    <select id="warningPushList" resultType="com.template.model.pojo.SmartUser">
        SELECT * FROM `smart_user` WHERE is_push=1 and is_cancel=0 and deleted = 0
    </select>


    <resultMap type="com.template.model.vo.AffiliateParentVo" id="affiliateParentMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
    </resultMap>

    <select id="queryAffiliateParents" resultType="com.template.model.vo.AffiliateParentVo" resultMap="affiliateParentMap">
        SELECT id,name FROM `smart_user`
        where deleted = 0 and is_cancel=0
        <if test="userId != null and userId != ''">
            and FIND_IN_SET(#{userId},affiliate)
        </if>
    </select>

</mapper>
