123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?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.thinkgem.jeesite.modules.sys.dao.RoleDao">
-
- <resultMap id="roleResult" type="Role">
- <id property="id" column="id" />
- <result property="name" column="name" />
- <result property="enname" column="enname" />
- <result property="roleType" column="roleType" />
- <result property="dataScope" column="dataScope" />
- <result property="remarks" column="remarks" />
- <result property="useable" column="useable" />
- <result property="sysData" column="sysData" /><!--
- <collection property="userList" ofType="User">
- <id property="id" column="userList.id" />
- <id property="loginName" column="userList.loginName" />
- <id property="name" column="userList.name" />
- <id property="email" column="userList.email" />
- <id property="phone" column="userList.phone" />
- <id property="mobile" column="userList.mobile" />
- <id property="office.name" column="userList.office.name" />
- <id property="company.name" column="userList.company.name" />
- </collection> -->
- <collection property="menuList" ofType="Menu">
- <id property="id" column="menuList.id" />
- </collection>
- <collection property="officeList" ofType="Office">
- <id property="id" column="officeList.id" />
- </collection>
- </resultMap>
-
- <sql id="roleColumns">
- a.id,
- a.office_id AS "office.id",
- a.name,
- a.enname,
- a.role_type AS roleType,
- a.data_scope AS dataScope,
- a.remarks,
- a.create_by AS "createBy.id",
- a.create_date,
- a.update_by AS "updateBy.id",
- a.update_date,
- a.del_flag,
- o.name AS "office.name",
- o.code,
- a.useable AS useable,
- a.is_sys AS sysData
- </sql>
-
- <select id="get" resultMap="roleResult">
- SELECT
- <include refid="roleColumns"/>,<!--
- ur.user_id AS "userList.id",
- u.login_name AS "userList.loginName",
- u.name AS "userList.name",
- u.email AS "userList.email",
- u.phone AS "userList.phone",
- u.mobile AS "userList.mobile",
- uc.name AS "userList.company.name",
- uo.name AS "userList.office.name", -->
- rm.menu_id AS "menuList.id",
- ro.office_id AS "officeList.id"
- FROM sys_role a
- JOIN sys_office o ON o.id = a.office_id<!--
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_user u ON u.id = ur.user_id
- LEFT JOIN sys_office uc ON uc.id = u.company_id
- LEFT JOIN sys_office uo ON uo.id = u.office_id -->
- LEFT JOIN sys_role_menu rm ON rm.role_id = a.id
- LEFT JOIN sys_role_office ro ON ro.role_id = a.id
- WHERE a.id = #{id}
- </select>
-
- <select id="getByName" resultType="Role">
- SELECT
- <include refid="roleColumns"/>
- FROM sys_role a
- JOIN sys_office o ON o.id = a.office_id
- WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
-
- <select id="getByEnname" resultType="Role">
- SELECT
- <include refid="roleColumns"/>
- FROM sys_role a
- JOIN sys_office o ON o.id = a.office_id
- WHERE a.enname = #{enname} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
-
- <select id="findList" resultMap="roleResult">
- SELECT <!-- DISTINCT -->
- <include refid="roleColumns"/>,
- ro.office_id AS "officeList.id"
- FROM sys_role a
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_user u ON u.id = ur.user_id
- LEFT JOIN sys_role_office ro ON ro.role_id = a.id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable}
- <if test="user != null and user.id != null and user.id != ''">
- AND u.id = #{user.id}
- </if>
- <if test="user != null and user.loginName != null and user.loginName != ''">
- AND u.login_name = #{user.loginName}
- </if>
- <!-- 数据范围过滤 -->
- ${sqlMap.dsf}
- ORDER BY o.code, a.name
- </select>
-
- <select id="findAllList" resultType="Role">
- SELECT
- <include refid="roleColumns"/>
- FROM sys_role a
- LEFT JOIN sys_office o ON o.id = a.office_id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- ORDER BY o.code, a.name
- </select>
-
- <insert id="insert" parameterType="role" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO sys_role(
- office_id,
- name,
- enname,
- role_type,
- data_scope,
- create_by,
- create_date,
- update_by,
- update_date,
- remarks,
- del_flag,
- is_sys,
- useable
- ) VALUES (
- #{office.id},
- #{name},
- #{enname},
- #{roleType},
- #{dataScope},
- #{createBy.id},
- #{createDate},
- #{updateBy.id},
- #{updateDate},
- #{remarks},
- #{delFlag},
- #{sysData},
- #{useable}
- )
- </insert>
-
- <update id="update">
- UPDATE sys_role SET
- office_id = #{office.id},
- name = #{name},
- enname = #{enname},
- role_type = #{roleType},
- data_scope = #{dataScope},
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- remarks = #{remarks},
- is_sys = #{sysData},
- useable = #{useable}
- WHERE id = #{id}
- </update>
-
- <delete id="deleteRoleMenu">
- DELETE FROM sys_role_menu WHERE role_id = #{id}
- </delete>
-
- <insert id="insertRoleMenu">
- INSERT INTO sys_role_menu(role_id, menu_id)
- <foreach collection="menuList" item="menu" separator=" union all ">
- SELECT #{id}, #{menu.id}
- <if test="dbName != 'mssql'">
- FROM dual
- </if>
- </foreach>
- </insert>
-
- <delete id="deleteRoleOffice">
- DELETE FROM sys_role_office WHERE role_id = #{id}
- </delete>
-
- <insert id="insertRoleOffice">
- INSERT INTO sys_role_office(role_id, office_id)
- <foreach collection="officeList" item="office" separator=" union all ">
- SELECT #{id}, #{office.id}
- <if test="dbName != 'mssql'">
- FROM dual
- </if>
- </foreach>
- </insert>
-
- <update id="delete">
- DELETE FROM sys_role WHERE id = #{id}
- </update>
-
- </mapper>
|