<?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.SmartAuthorGroupMapper">
    <resultMap type="com.template.model.pojo.SmartAuthorGroup" id="smartAuthorGroupMap">
        <result property="id" column="id"/>
        <result property="parentId" column="parent_id"/>
        <result property="name" column="name"/>
        <result property="userId" column="user_id"/>
        <result property="applyId" column="apply_id"/>
    </resultMap>

    <resultMap type="com.template.model.pojo.SmartAuthorGroupManager" id="smartAuthorGroupManager">
        <result property="groupId" column="group_id"/>
        <result property="userId" column="user_id"/>
        <result property="cardNo" column="card_no"/>
        <result property="userName" column="user_name"/>
        <result property="departmentManage" column="department_manage"/>
        <result property="departmentView" column="department_view"/>
    </resultMap>

    <select id="smartAuthorGroup" resultType="com.template.model.pojo.SmartAuthorGroup" resultMap="smartAuthorGroupMap">
        SELECT * FROM `smart_author_group`
        where deleted = 0
        <if test="userId != null and userId != ''">
            and FIND_IN_SET(#{userId},user_id)
        </if>
    </select>

    <select id="smartAuthorGroupSuperAdmin" resultType="com.template.model.pojo.SmartAuthorGroup" resultMap="smartAuthorGroupMap">
        SELECT * FROM `smart_author_group`
        where deleted = 0 and parent_id = 0
        <if test="userId != null and userId != ''">
            and FIND_IN_SET(#{userId},user_id)
        </if>
    </select>


    <select id="getSmartAuthorGroupManager" resultType="com.template.model.pojo.SmartAuthorGroupManager" resultMap="smartAuthorGroupManager">
        select a.`id`,a.`group_id`,a.`user_id`,b.card_no,b.`name` as user_name,a.`department_manage`,a.`department_view`
            from `smart_authority` a left join `smart_user` b on a.`user_id`=b.id
            where group_id=#{groupId} and a.deleted=0 and b.deleted=0
    </select>
</mapper>
