SysRoleMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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.izouma.awesomeadmin.dao.SysRoleMapper" >
  4. <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.SysRole" >
  5. <id column="id" property="id" jdbcType="INTEGER" />
  6. <result column="office_id" property="officeId" jdbcType="VARCHAR" />
  7. <result column="name" property="name" jdbcType="VARCHAR" />
  8. <result column="enname" property="enname" jdbcType="VARCHAR" />
  9. <result column="role_type" property="roleType" jdbcType="VARCHAR" />
  10. <result column="is_sys" property="isSys" jdbcType="VARCHAR" />
  11. <result column="useable" property="useable" jdbcType="VARCHAR" />
  12. <result column="create_by" property="createBy" jdbcType="VARCHAR" />
  13. <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  14. <result column="update_by" property="updateBy" jdbcType="VARCHAR" />
  15. <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
  16. <result column="remarks" property="remarks" jdbcType="VARCHAR" />
  17. <result column="del_flag" property="delFlag" jdbcType="CHAR" />
  18. <result column="menu_ids" property="menuIds" jdbcType="VARCHAR" />
  19. <result column="permission" property="permission" jdbcType="VARCHAR" />
  20. </resultMap>
  21. <sql id="Base_Column_List" >
  22. id, office_id, name, enname, role_type, is_sys, useable, create_by, create_date, update_by, update_date, remarks, del_flag,menu_ids,permission
  23. </sql>
  24. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  25. select
  26. <include refid="Base_Column_List" />
  27. from sys_role
  28. where id = #{id,jdbcType=INTEGER}
  29. </select>
  30. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  31. delete from sys_role
  32. where id = #{id,jdbcType=INTEGER}
  33. </delete>
  34. <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.SysRole" useGeneratedKeys="true" keyProperty="id">
  35. insert into sys_role
  36. <trim prefix="(" suffix=")" suffixOverrides="," >
  37. <if test="id != null" >
  38. id,
  39. </if>
  40. <if test="officeId != null" >
  41. office_id,
  42. </if>
  43. <if test="name != null" >
  44. name,
  45. </if>
  46. <if test="enname != null" >
  47. enname,
  48. </if>
  49. <if test="roleType != null" >
  50. role_type,
  51. </if>
  52. <if test="isSys != null" >
  53. is_sys,
  54. </if>
  55. <if test="useable != null" >
  56. useable,
  57. </if>
  58. <if test="createBy != null" >
  59. create_by,
  60. </if>
  61. <if test="createDate != null" >
  62. create_date,
  63. </if>
  64. <if test="updateBy != null" >
  65. update_by,
  66. </if>
  67. <if test="updateDate != null" >
  68. update_date,
  69. </if>
  70. <if test="remarks != null" >
  71. remarks,
  72. </if>
  73. <if test="menuIds != null" >
  74. menu_ids,
  75. </if>
  76. <if test="permission != null" >
  77. permission,
  78. </if>
  79. </trim>
  80. <trim prefix="values (" suffix=")" suffixOverrides="," >
  81. <if test="id != null" >
  82. #{id,jdbcType=INTEGER},
  83. </if>
  84. <if test="officeId != null" >
  85. #{officeId,jdbcType=VARCHAR},
  86. </if>
  87. <if test="name != null" >
  88. #{name,jdbcType=VARCHAR},
  89. </if>
  90. <if test="enname != null" >
  91. #{enname,jdbcType=VARCHAR},
  92. </if>
  93. <if test="roleType != null" >
  94. #{roleType,jdbcType=VARCHAR},
  95. </if>
  96. <if test="isSys != null" >
  97. #{isSys,jdbcType=VARCHAR},
  98. </if>
  99. <if test="useable != null" >
  100. #{useable,jdbcType=VARCHAR},
  101. </if>
  102. <if test="createBy != null" >
  103. #{createBy,jdbcType=VARCHAR},
  104. </if>
  105. <if test="createDate != null" >
  106. #{createDate,jdbcType=TIMESTAMP},
  107. </if>
  108. <if test="updateBy != null" >
  109. #{updateBy,jdbcType=VARCHAR},
  110. </if>
  111. <if test="updateDate != null" >
  112. #{updateDate,jdbcType=TIMESTAMP},
  113. </if>
  114. <if test="remarks != null" >
  115. #{remarks,jdbcType=VARCHAR},
  116. </if>
  117. <if test="menuIds != null" >
  118. #{menuIds,jdbcType=VARCHAR},
  119. </if>
  120. <if test="permission != null" >
  121. #{permission,jdbcType=VARCHAR},
  122. </if>
  123. </trim>
  124. </insert>
  125. <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.SysRole" >
  126. update sys_role
  127. <set >
  128. <if test="officeId != null" >
  129. office_id = #{officeId,jdbcType=VARCHAR},
  130. </if>
  131. <if test="name != null" >
  132. name = #{name,jdbcType=VARCHAR},
  133. </if>
  134. <if test="enname != null" >
  135. enname = #{enname,jdbcType=VARCHAR},
  136. </if>
  137. <if test="roleType != null" >
  138. role_type = #{roleType,jdbcType=VARCHAR},
  139. </if>
  140. <if test="isSys != null" >
  141. is_sys = #{isSys,jdbcType=VARCHAR},
  142. </if>
  143. <if test="useable != null" >
  144. useable = #{useable,jdbcType=VARCHAR},
  145. </if>
  146. <if test="createBy != null" >
  147. create_by = #{createBy,jdbcType=VARCHAR},
  148. </if>
  149. <if test="createDate != null" >
  150. create_date = #{createDate,jdbcType=TIMESTAMP},
  151. </if>
  152. <if test="updateBy != null" >
  153. update_by = #{updateBy,jdbcType=VARCHAR},
  154. </if>
  155. <if test="updateDate != null" >
  156. update_date = #{updateDate,jdbcType=TIMESTAMP},
  157. </if>
  158. <if test="remarks != null" >
  159. remarks = #{remarks,jdbcType=VARCHAR},
  160. </if>
  161. <if test="delFlag != null" >
  162. del_flag = #{delFlag,jdbcType=CHAR},
  163. </if>
  164. <if test="menuIds != null" >
  165. menu_ids = #{menuIds,jdbcType=VARCHAR},
  166. </if>
  167. <if test="permission != null" >
  168. permission = #{permission,jdbcType=VARCHAR},
  169. </if>
  170. </set>
  171. where id = #{id,jdbcType=INTEGER}
  172. </update>
  173. <select id="querySysRolesByPage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.SysRole">
  174. select <include refid="Base_Column_List"/> from sys_role
  175. <where>
  176. and del_flag = 'N'
  177. <if test="record.id != null and !&quot;&quot;.equals(record.id)">
  178. and id = #{record.id}
  179. </if>
  180. <if test="record.officeId != null and !&quot;&quot;.equals(record.officeId)">
  181. and office_id = #{record.officeId}
  182. </if>
  183. <if test="record.name != null and !&quot;&quot;.equals(record.name)">
  184. and name = #{record.name}
  185. </if>
  186. <if test="record.enname != null and !&quot;&quot;.equals(record.enname)">
  187. and enname = #{record.enname}
  188. </if>
  189. <if test="record.roleType != null and !&quot;&quot;.equals(record.roleType)">
  190. and role_type = #{record.roleType}
  191. </if>
  192. <if test="record.isSys != null and !&quot;&quot;.equals(record.isSys)">
  193. and is_sys = #{record.isSys}
  194. </if>
  195. <if test="record.useable != null and !&quot;&quot;.equals(record.useable)">
  196. and useable = #{record.useable}
  197. </if>
  198. <if test="record.createBy != null and !&quot;&quot;.equals(record.createBy)">
  199. and create_by = #{record.createBy}
  200. </if>
  201. <if test="record.createDate != null and !&quot;&quot;.equals(record.createDate)">
  202. and create_date = #{record.createDate}
  203. </if>
  204. <if test="record.updateBy != null and !&quot;&quot;.equals(record.updateBy)">
  205. and update_by = #{record.updateBy}
  206. </if>
  207. <if test="record.updateDate != null and !&quot;&quot;.equals(record.updateDate)">
  208. and update_date = #{record.updateDate}
  209. </if>
  210. <if test="record.remarks != null and !&quot;&quot;.equals(record.remarks)">
  211. and remarks = #{record.remarks}
  212. </if>
  213. <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
  214. and del_flag = #{record.delFlag}
  215. </if>
  216. <if test="record.menuIds != null and !&quot;&quot;.equals(record.menuIds)">
  217. and menu_ids = #{record.menuIds}
  218. </if>
  219. <if test="record.permission != null and !&quot;&quot;.equals(record.permission)">
  220. and permission = #{record.permission}
  221. </if>
  222. </where>
  223. order by id desc
  224. </select>
  225. <select id="queryAllSysRole" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.SysRole">
  226. select <include refid="Base_Column_List"/> from sys_role
  227. <where>
  228. and del_flag = 'N'
  229. <if test="id != null and !&quot;&quot;.equals(id)">
  230. and id = #{id}
  231. </if>
  232. <if test="officeId != null and !&quot;&quot;.equals(officeId)">
  233. and office_id = #{officeId}
  234. </if>
  235. <if test="name != null and !&quot;&quot;.equals(name)">
  236. and name = #{name}
  237. </if>
  238. <if test="enname != null and !&quot;&quot;.equals(enname)">
  239. and enname = #{enname}
  240. </if>
  241. <if test="roleType != null and !&quot;&quot;.equals(roleType)">
  242. and role_type = #{roleType}
  243. </if>
  244. <if test="isSys != null and !&quot;&quot;.equals(isSys)">
  245. and is_sys = #{isSys}
  246. </if>
  247. <if test="useable != null and !&quot;&quot;.equals(useable)">
  248. and useable = #{useable}
  249. </if>
  250. <if test="createBy != null and !&quot;&quot;.equals(createBy)">
  251. and create_by = #{createBy}
  252. </if>
  253. <if test="createDate != null and !&quot;&quot;.equals(createDate)">
  254. and create_date = #{createDate}
  255. </if>
  256. <if test="updateBy != null and !&quot;&quot;.equals(updateBy)">
  257. and update_by = #{updateBy}
  258. </if>
  259. <if test="updateDate != null and !&quot;&quot;.equals(updateDate)">
  260. and update_date = #{updateDate}
  261. </if>
  262. <if test="remarks != null and !&quot;&quot;.equals(remarks)">
  263. and remarks = #{remarks}
  264. </if>
  265. <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
  266. and del_flag = #{delFlag}
  267. </if>
  268. <if test="idStr != null and !&quot;&quot;.equals(idStr)">
  269. and id in (${idStr})
  270. </if>
  271. <if test="menuIds != null and !&quot;&quot;.equals(menuIds)">
  272. and menu_ids = #{menuIds}
  273. </if>
  274. <if test="permission != null and !&quot;&quot;.equals(permission)">
  275. and permission = #{permission}
  276. </if>
  277. </where>
  278. order by id desc
  279. </select>
  280. <select id="querySysRole" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.SysRole">
  281. select <include refid="Base_Column_List"/> from sys_role
  282. <where>
  283. and del_flag = 'N'
  284. <if test="id != null and !&quot;&quot;.equals(id)">
  285. and id = #{id}
  286. </if>
  287. <if test="officeId != null and !&quot;&quot;.equals(officeId)">
  288. and office_id = #{officeId}
  289. </if>
  290. <if test="name != null and !&quot;&quot;.equals(name)">
  291. and name = #{name}
  292. </if>
  293. <if test="enname != null and !&quot;&quot;.equals(enname)">
  294. and enname = #{enname}
  295. </if>
  296. <if test="roleType != null and !&quot;&quot;.equals(roleType)">
  297. and role_type = #{roleType}
  298. </if>
  299. <if test="isSys != null and !&quot;&quot;.equals(isSys)">
  300. and is_sys = #{isSys}
  301. </if>
  302. <if test="useable != null and !&quot;&quot;.equals(useable)">
  303. and useable = #{useable}
  304. </if>
  305. <if test="createBy != null and !&quot;&quot;.equals(createBy)">
  306. and create_by = #{createBy}
  307. </if>
  308. <if test="createDate != null and !&quot;&quot;.equals(createDate)">
  309. and create_date = #{createDate}
  310. </if>
  311. <if test="updateBy != null and !&quot;&quot;.equals(updateBy)">
  312. and update_by = #{updateBy}
  313. </if>
  314. <if test="updateDate != null and !&quot;&quot;.equals(updateDate)">
  315. and update_date = #{updateDate}
  316. </if>
  317. <if test="remarks != null and !&quot;&quot;.equals(remarks)">
  318. and remarks = #{remarks}
  319. </if>
  320. <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
  321. and del_flag = #{delFlag}
  322. </if>
  323. <if test="menuIds != null and !&quot;&quot;.equals(menuIds)">
  324. and menu_ids = #{menuIds}
  325. </if>
  326. <if test="permission != null and !&quot;&quot;.equals(permission)">
  327. and permission = #{permission}
  328. </if>
  329. </where>
  330. LIMIT 1
  331. </select>
  332. <select id="selectByPrimaryKeys" resultType="com.izouma.awesomeadmin.model.SysRole">
  333. select
  334. <include refid="Base_Column_List" />
  335. from sys_role
  336. where id in (${ids})
  337. and del_flag = 'N'
  338. </select>
  339. <select id="getUserRoles" resultType="com.izouma.awesomeadmin.model.SysRole">
  340. select
  341. <include refid="Base_Column_List" />
  342. from sys_role
  343. where id in (select role_id from sys_user_role where user_id = #{userId})
  344. and del_flag = 'N'
  345. </select>
  346. <update id="delete">
  347. UPDATE sys_role SET del_flag = 'Y'
  348. <where>
  349. AND id = #{id}
  350. </where>
  351. </update>
  352. <insert id="setUserRoles">
  353. insert into sys_user_role (user_id, role_id)
  354. values
  355. <foreach collection="roles" item="roleId" separator=",">
  356. (#{userId}, #{roleId})
  357. </foreach>
  358. </insert>
  359. <delete id="clearUserRoles">
  360. delete from sys_user_role where user_id = #{userId}
  361. </delete>
  362. <insert id="addUserRole">
  363. insert into sys_user_role (user_id, role_id) values (#{userId}, #{roleId})
  364. </insert>
  365. <delete id="removeUserRole">
  366. delete from sys_user_role when user_id = #{userId} and role_id = #{roleId}
  367. </delete>
  368. <select id="getUserRoleId" resultType="java.lang.String">
  369. SELECT group_concat(role_id) FROM sys_user_role WHERE user_id = #{id}
  370. </select>
  371. </mapper>