RoleDao.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.thinkgem.jeesite.modules.sys.dao.RoleDao">
  4. <resultMap id="roleResult" type="Role">
  5. <id property="id" column="id" />
  6. <result property="name" column="name" />
  7. <result property="enname" column="enname" />
  8. <result property="roleType" column="roleType" />
  9. <result property="dataScope" column="dataScope" />
  10. <result property="remarks" column="remarks" />
  11. <result property="useable" column="useable" />
  12. <result property="sysData" column="sysData" /><!--
  13. <collection property="userList" ofType="User">
  14. <id property="id" column="userList.id" />
  15. <id property="loginName" column="userList.loginName" />
  16. <id property="name" column="userList.name" />
  17. <id property="email" column="userList.email" />
  18. <id property="phone" column="userList.phone" />
  19. <id property="mobile" column="userList.mobile" />
  20. <id property="office.name" column="userList.office.name" />
  21. <id property="company.name" column="userList.company.name" />
  22. </collection> -->
  23. <collection property="menuList" ofType="Menu">
  24. <id property="id" column="menuList.id" />
  25. </collection>
  26. <collection property="officeList" ofType="Office">
  27. <id property="id" column="officeList.id" />
  28. </collection>
  29. </resultMap>
  30. <sql id="roleColumns">
  31. a.id,
  32. a.office_id AS "office.id",
  33. a.name,
  34. a.enname,
  35. a.role_type AS roleType,
  36. a.data_scope AS dataScope,
  37. a.remarks,
  38. a.create_by AS "createBy.id",
  39. a.create_date,
  40. a.update_by AS "updateBy.id",
  41. a.update_date,
  42. a.del_flag,
  43. o.name AS "office.name",
  44. o.code,
  45. a.useable AS useable,
  46. a.is_sys AS sysData
  47. </sql>
  48. <select id="get" resultMap="roleResult">
  49. SELECT
  50. <include refid="roleColumns"/>,<!--
  51. ur.user_id AS "userList.id",
  52. u.login_name AS "userList.loginName",
  53. u.name AS "userList.name",
  54. u.email AS "userList.email",
  55. u.phone AS "userList.phone",
  56. u.mobile AS "userList.mobile",
  57. uc.name AS "userList.company.name",
  58. uo.name AS "userList.office.name", -->
  59. rm.menu_id AS "menuList.id",
  60. ro.office_id AS "officeList.id"
  61. FROM sys_role a
  62. JOIN sys_office o ON o.id = a.office_id<!--
  63. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  64. LEFT JOIN sys_user u ON u.id = ur.user_id
  65. LEFT JOIN sys_office uc ON uc.id = u.company_id
  66. LEFT JOIN sys_office uo ON uo.id = u.office_id -->
  67. LEFT JOIN sys_role_menu rm ON rm.role_id = a.id
  68. LEFT JOIN sys_role_office ro ON ro.role_id = a.id
  69. WHERE a.id = #{id}
  70. </select>
  71. <select id="getByName" resultType="Role">
  72. SELECT
  73. <include refid="roleColumns"/>
  74. FROM sys_role a
  75. JOIN sys_office o ON o.id = a.office_id
  76. WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL}
  77. </select>
  78. <select id="getByEnname" resultType="Role">
  79. SELECT
  80. <include refid="roleColumns"/>
  81. FROM sys_role a
  82. JOIN sys_office o ON o.id = a.office_id
  83. WHERE a.enname = #{enname} AND a.del_flag = #{DEL_FLAG_NORMAL}
  84. </select>
  85. <select id="findList" resultMap="roleResult">
  86. SELECT <!-- DISTINCT -->
  87. <include refid="roleColumns"/>,
  88. ro.office_id AS "officeList.id"
  89. FROM sys_role a
  90. LEFT JOIN sys_office o ON o.id = a.office_id
  91. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  92. LEFT JOIN sys_user u ON u.id = ur.user_id
  93. LEFT JOIN sys_role_office ro ON ro.role_id = a.id
  94. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable}
  95. <if test="user != null and user.id != null and user.id != ''">
  96. AND u.id = #{user.id}
  97. </if>
  98. <if test="user != null and user.loginName != null and user.loginName != ''">
  99. AND u.login_name = #{user.loginName}
  100. </if>
  101. <!-- 数据范围过滤 -->
  102. ${sqlMap.dsf}
  103. ORDER BY o.code, a.name
  104. </select>
  105. <select id="findAllList" resultType="Role">
  106. SELECT
  107. <include refid="roleColumns"/>
  108. FROM sys_role a
  109. LEFT JOIN sys_office o ON o.id = a.office_id
  110. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  111. ORDER BY o.code, a.name
  112. </select>
  113. <insert id="insert" parameterType="role" keyProperty="id" useGeneratedKeys="true">
  114. INSERT INTO sys_role(
  115. office_id,
  116. name,
  117. enname,
  118. role_type,
  119. data_scope,
  120. create_by,
  121. create_date,
  122. update_by,
  123. update_date,
  124. remarks,
  125. del_flag,
  126. is_sys,
  127. useable
  128. ) VALUES (
  129. #{office.id},
  130. #{name},
  131. #{enname},
  132. #{roleType},
  133. #{dataScope},
  134. #{createBy.id},
  135. #{createDate},
  136. #{updateBy.id},
  137. #{updateDate},
  138. #{remarks},
  139. #{delFlag},
  140. #{sysData},
  141. #{useable}
  142. )
  143. </insert>
  144. <update id="update">
  145. UPDATE sys_role SET
  146. office_id = #{office.id},
  147. name = #{name},
  148. enname = #{enname},
  149. role_type = #{roleType},
  150. data_scope = #{dataScope},
  151. update_by = #{updateBy.id},
  152. update_date = #{updateDate},
  153. remarks = #{remarks},
  154. is_sys = #{sysData},
  155. useable = #{useable}
  156. WHERE id = #{id}
  157. </update>
  158. <delete id="deleteRoleMenu">
  159. DELETE FROM sys_role_menu WHERE role_id = #{id}
  160. </delete>
  161. <insert id="insertRoleMenu">
  162. INSERT INTO sys_role_menu(role_id, menu_id)
  163. <foreach collection="menuList" item="menu" separator=" union all ">
  164. SELECT #{id}, #{menu.id}
  165. <if test="dbName != 'mssql'">
  166. FROM dual
  167. </if>
  168. </foreach>
  169. </insert>
  170. <delete id="deleteRoleOffice">
  171. DELETE FROM sys_role_office WHERE role_id = #{id}
  172. </delete>
  173. <insert id="insertRoleOffice">
  174. INSERT INTO sys_role_office(role_id, office_id)
  175. <foreach collection="officeList" item="office" separator=" union all ">
  176. SELECT #{id}, #{office.id}
  177. <if test="dbName != 'mssql'">
  178. FROM dual
  179. </if>
  180. </foreach>
  181. </insert>
  182. <update id="delete">
  183. DELETE FROM sys_role WHERE id = #{id}
  184. </update>
  185. </mapper>