<?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.ruoyi.ibs.grid.mapper.VirtualUserMapper">
    
    <resultMap type="VirtualUser" id="GridVirtualUserResult">
        <result property="id"    column="id"    />
        <result property="gridId"    column="grid_id"    />
        <result property="relateType"    column="relate_type"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="relateDeptId"    column="relate_dept_id"    />
        <result property="relateDeptName"    column="relate_dept_name"    />
        <result property="relateDeptType"    column="relate_dept_type"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleteFlag"    column="delete_flag"    />
    </resultMap>

    <sql id="selectGridVirtualUserVo">
        select id, grid_id, relate_type, user_id, user_name, relate_dept_id, relate_dept_name, relate_dept_type, create_by, create_time, update_by, update_time, delete_flag from grid_virtual_user
    </sql>

    <select id="selectDeptNameByGridId" resultType="java.lang.String" >
        select user_name, group_concat(relate_dept_name)
        from grid_virtual_user
        where grid_id = #{gridId} and relate_dept_type = #{deptType} order by user_name
    </select>

    <select id="selectCustManagerByGridId" parameterType="Long" resultType="java.lang.String" >
        select group_concat(distinct b.nick_name) from grid_virtual_user a ,sys_user b
        where a.user_name = b.user_name and a.grid_id = #{gridId}
    </select>

</mapper>