RoleDao.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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.jeeplus.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="number" column="number" />
  8. <result property="enname" column="enname" />
  9. <result property="branchCompany.id" column="branchCompany.id" />
  10. <result property="roleType" column="roleType" />
  11. <result property="dataScope" column="dataScope" />
  12. <result property="remarks" column="remarks" />
  13. <result property="useable" column="useable" />
  14. <result property="office.id" column="office.id" />
  15. <result property="office.name" column="office.name" />
  16. <result property="office.topCompany" column="office.topCompany" />
  17. <result property="company.id" column="company.id" />
  18. <result property="company.name" column="company.name" />
  19. <result property="company.logo" column="company.logo" />
  20. <result property="company.master" column="company.master" />
  21. <result property="company.useable" column="company.useable" />
  22. <result property="company.companyQrcode" column="company.companyQrcode" />
  23. <result property="sysData" column="sysData" /><!--
  24. <collection property="userList" ofType="User">
  25. <id property="id" column="userList.id" />
  26. <id property="loginName" column="userList.loginName" />
  27. <id property="name" column="userList.name" />
  28. <id property="email" column="userList.email" />
  29. <id property="phone" column="userList.phone" />
  30. <id property="mobile" column="userList.mobile" />
  31. <id property="office.name" column="userList.office.name" />
  32. <id property="company.name" column="userList.company.name" />
  33. </collection> -->
  34. <collection property="menuList" ofType="Menu">
  35. <id property="id" column="menuList.id" />
  36. </collection>
  37. <collection property="roleActivityList" ofType="SysRoleActivity">
  38. <id property="id" column="roleActivityList.id" />
  39. <id property="name" column="roleActivityList.name" />
  40. <id property="type" column="roleActivityList.type" />
  41. <id property="remarks" column="roleActivityList.remarks" />
  42. <id property="enname" column="roleActivityList.enname" />
  43. </collection>
  44. </resultMap>
  45. <resultMap id="roleResults" type="Role">
  46. <id property="id" column="id" />
  47. <result property="name" column="name" />
  48. <result property="office.id" column="office.id" />
  49. <result property="office.name" column="office.name" />
  50. <result property="office.parentIds" column="office.parentIds" />
  51. </resultMap>
  52. <sql id="roleColumns">
  53. a.id,
  54. a.office_id AS "office.id",
  55. a.company_id AS "company.id",
  56. com.name AS "company.name",
  57. a.branch_company AS "branchCompany.id",
  58. a.name,
  59. a.number,
  60. a.enname,
  61. a.role_type AS roleType,
  62. a.data_scope AS dataScope,
  63. a.remarks,
  64. a.create_by AS "createBy.id",
  65. a.create_date,
  66. a.update_by AS "updateBy.id",
  67. a.update_date,
  68. a.del_flag,
  69. o.name AS "office.name",
  70. o.code,
  71. o.top_company AS "office.topCompany",
  72. com.logo AS "company.logo",
  73. com.company_qrcode AS "company.companyQrcode",
  74. com.master AS "company.master",
  75. com.useable AS "company.useable",
  76. a.useable AS useable,
  77. a.is_sys AS sysData
  78. </sql>
  79. <sql id="roleJoins">
  80. LEFT JOIN sys_office com ON com.id = a.company_id
  81. </sql>
  82. <select id="get" resultMap="roleResult">
  83. SELECT
  84. <include refid="roleColumns"/><!--
  85. ur.user_id AS "userList.id",
  86. u.login_name AS "userList.loginName",
  87. u.name AS "userList.name",
  88. u.email AS "userList.email",
  89. u.phone AS "userList.phone",
  90. u.mobile AS "userList.mobile",
  91. uc.name AS "userList.company.name",
  92. uo.name AS "userList.office.name",
  93. rm.menu_id AS "menuList.id", -->
  94. FROM sys_role a
  95. <include refid="roleJoins"/>
  96. LEFT JOIN sys_office o ON o.id = a.office_id <!--
  97. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  98. LEFT JOIN sys_user u ON u.id = ur.user_id
  99. LEFT JOIN sys_office uc ON uc.id = u.company_id
  100. LEFT JOIN sys_office uo ON uo.id = u.office_id
  101. LEFT JOIN sys_role_menu rm ON rm.role_id = a.id-->
  102. WHERE a.id = #{id} and a.del_flag='0'
  103. </select>
  104. <select id="getActivityByRole" resultType="Role">
  105. SELECT
  106. <include refid="roleColumns"/>
  107. FROM sys_role a
  108. <include refid="roleJoins"/>
  109. LEFT JOIN sys_office o ON o.id = a.office_id
  110. LEFT JOIN sys_role_activity_relation ar ON ar.role_id = a.id
  111. LEFT JOIN sys_role_activity ra ON ra.id = ar.role_activity_id
  112. WHERE a.del_flag='0' AND a.company_id = #{company.id} AND ra.id = #{activityId}
  113. </select>
  114. <select id="getByRoleActivity" resultMap="roleResult">
  115. SELECT
  116. <include refid="roleColumns"/>,
  117. ra.id AS "roleActivityList.id",
  118. ra.name AS "roleActivityList.name",
  119. ra.type AS "roleActivityList.type",
  120. ra.remarks AS "roleActivityList.remarks",
  121. ra.enname AS "roleActivityList.enname"
  122. FROM sys_role a
  123. <include refid="roleJoins"/>
  124. LEFT JOIN sys_office o ON o.id = a.office_id
  125. LEFT JOIN sys_role_activity_relation ar ON ar.role_id = a.id
  126. LEFT JOIN sys_role_activity ra ON ra.id = ar.role_activity_id
  127. WHERE a.id = #{id} and a.del_flag='0'
  128. </select>
  129. <select id="getByRoleActivityEnname" resultMap="roleResult">
  130. SELECT
  131. a.id
  132. FROM sys_role a
  133. JOIN sys_role_activity_relation ar ON ar.role_id = a.id
  134. JOIN sys_role_activity ra ON ra.id = ar.role_activity_id
  135. WHERE ra.enname = #{enname} and a.del_flag='0'
  136. <if test="office != null and office.id != null and office.id != ''">
  137. AND a.office_id = #{office.id}
  138. </if>
  139. <if test="branchCompany != null and branchCompany.id != null and branchCompany.id != ''">
  140. AND a.branch_company = #{branchCompany.id}
  141. </if>
  142. <if test="branchCompany != null and branchCompany.name != null and branchCompany.name != ''">
  143. AND a.branch_company IS NULL
  144. </if>
  145. </select>
  146. <select id="getMenuList" resultMap="roleResult">
  147. SELECT
  148. <include refid="roleColumns"/>,
  149. ur.user_id AS "userList.id",
  150. u.login_name AS "userList.loginName",
  151. u.name AS "userList.name",
  152. u.email AS "userList.email",
  153. u.phone AS "userList.phone",
  154. u.mobile AS "userList.mobile",
  155. uc.name AS "userList.company.name",
  156. uo.name AS "userList.office.name",
  157. rm.menu_id AS "menuList.id"
  158. FROM sys_role a
  159. <include refid="roleJoins"/>
  160. LEFT JOIN sys_office o ON o.id = a.office_id
  161. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  162. LEFT JOIN sys_user u ON u.id = ur.user_id
  163. LEFT JOIN sys_office uc ON uc.id = u.company_id
  164. LEFT JOIN sys_office uo ON uo.id = u.office_id
  165. LEFT JOIN sys_role_menu rm ON rm.role_id = a.id
  166. WHERE a.id = #{id} and a.del_flag='0'
  167. </select>
  168. <select id="getRolesByMenu" resultType="Role">
  169. SELECT
  170. a.id,
  171. a.office_id AS "office.id",
  172. a.company_id AS "company.id",
  173. a.branch_company AS "branchCompany.id",
  174. a.name,
  175. a.number,
  176. a.enname,
  177. a.role_type AS roleType,
  178. a.data_scope AS dataScope,
  179. a.remarks,
  180. a.create_by AS "createBy.id",
  181. a.create_date,
  182. a.update_by AS "updateBy.id",
  183. a.update_date,
  184. a.del_flag,
  185. a.useable AS useable,
  186. a.is_sys AS sysData,
  187. com.parent_ids AS "company.parentIds",
  188. o.parent_ids AS "office.parentIds",
  189. br.parent_ids AS "branchCompany.parentIds"
  190. FROM sys_role a
  191. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  192. LEFT JOIN sys_role_menu rm ON rm.role_id = a.id
  193. LEFT JOIN sys_office com ON com.id = a.company_id
  194. LEFT JOIN sys_office o ON o.id = a.office_id
  195. LEFT JOIN sys_office br ON br.id = a.branch_company
  196. WHERE ur.user_id = #{userId} AND rm.menu_id = #{menuId} AND a.company_id = #{companyId} AND a.del_flag='0';
  197. </select>
  198. <select id="getByName" resultType="Role">
  199. SELECT
  200. <include refid="roleColumns"/>
  201. FROM sys_role a
  202. <include refid="roleJoins"/>
  203. JOIN sys_office o ON o.id = a.office_id
  204. WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL} AND a.company_id = #{company.id}
  205. </select>
  206. <select id="getByGlyCount" resultType="java.lang.Integer">
  207. SELECT COUNT(*)
  208. FROM sys_role a
  209. LEFT JOIN sys_user_role ur ON a.id = ur.role_id
  210. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.enname in ('gly','fgly') AND a.company_id = a.company_id
  211. AND a.company_id = #{company.id}
  212. AND ur.user_id = #{user.id}
  213. </select>
  214. <select id="getMaxNumberByOffice" resultType="java.lang.Integer">
  215. SELECT MAX(number)
  216. FROM sys_role
  217. WHERE del_flag = #{DEL_FLAG_NORMAL} AND office_id = #{office.id}
  218. </select>
  219. <select id="getByEnname" resultType="Role">
  220. SELECT
  221. <include refid="roleColumns"/>
  222. FROM sys_role a
  223. <include refid="roleJoins"/>
  224. JOIN sys_office o ON o.id = a.office_id
  225. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.company_id = #{company.id}
  226. <if test="office!=null and office.id!=null and office.id!=''">
  227. AND a.office_id = #{office.id}
  228. </if>
  229. <if test="enname!=null and enname!=''">
  230. AND a.enname = #{enname}
  231. </if>
  232. </select>
  233. <select id="findList" resultMap="roleResult">
  234. SELECT <!-- DISTINCT -->
  235. <include refid="roleColumns"/>
  236. FROM sys_role a
  237. <include refid="roleJoins"/>
  238. LEFT JOIN sys_office o ON o.id = a.office_id
  239. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  240. LEFT JOIN sys_user u ON u.id = ur.user_id
  241. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable} and o.useable = '1'
  242. <if test="user != null and user.id != null and user.id != ''">
  243. AND u.id = #{user.id}
  244. </if>
  245. <if test="company != null and company.id != null and company.id != ''">
  246. AND a.company_id = #{company.id}
  247. </if>
  248. <if test="office != null and office.id != null and office.id != ''">
  249. AND a.office_id = #{office.id}
  250. </if>
  251. <if test="user != null and user.loginName != null and user.loginName != ''">
  252. AND u.login_name = #{user.loginName}
  253. </if>
  254. <if test="name != null and name != ''">
  255. AND a.name like
  256. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  257. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  258. </if>
  259. <if test="enname != null and enname != ''">
  260. AND a.enname like
  261. <if test="dbName == 'oracle'">'%'||#{enname}||'%'</if>
  262. <if test="dbName == 'mysql'">CONCAT('%', #{enname}, '%')</if>
  263. </if>
  264. <!-- 数据范围过滤 -->
  265. ${sqlMap.dsf}
  266. ORDER BY a.number
  267. </select>
  268. <select id="getRoleListByCompanys" resultMap="roleResults">
  269. SELECT
  270. DISTINCT
  271. a.id AS "id",
  272. a.name AS "name",
  273. a.number AS "number",
  274. o.id AS "office.id",
  275. o.name AS "office.name",
  276. o.top_company AS "office.topCompany",
  277. o.parent_ids AS "office.parentIds"
  278. FROM sys_role a
  279. LEFT JOIN sys_office o ON o.id = a.office_id
  280. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  281. LEFT JOIN sys_user u ON u.id = ur.user_id
  282. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable} and o.USEABLE = '1'
  283. <if test="user != null and user.id != null and user.id != ''">
  284. AND u.id = #{user.id}
  285. </if>
  286. <if test="company != null and company.id != null and company.id != ''">
  287. AND a.company_id = #{company.id}
  288. </if>
  289. <if test="office != null and office.id != null and office.id != ''">
  290. AND a.office_id = #{office.id}
  291. </if>
  292. <if test="branchCompany != null and branchCompany.id != null and branchCompany.id != ''">
  293. AND (find_in_set(#{branchCompany.id},o.parent_ids) OR a.branch_company = #{branchCompany.id})
  294. </if>
  295. <if test="user != null and user.loginName != null and user.loginName != ''">
  296. AND u.login_name = #{user.loginName}
  297. </if>
  298. <if test="name != null and name != ''">
  299. AND a.name like
  300. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  301. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  302. </if>
  303. <if test="enname != null and enname != ''">
  304. AND a.enname like
  305. <if test="dbName == 'oracle'">'%'||#{enname}||'%'</if>
  306. <if test="dbName == 'mysql'">CONCAT('%', #{enname}, '%')</if>
  307. </if>
  308. <!-- 数据范围过滤 -->
  309. ${sqlMap.dsf}
  310. ORDER BY a.number ASC
  311. </select>
  312. <select id="findListRole" resultType="Role">
  313. SELECT <!-- DISTINCT -->
  314. <include refid="roleColumns"/>
  315. FROM sys_role a
  316. <include refid="roleJoins"/>
  317. LEFT JOIN sys_office o ON o.id = a.office_id
  318. <where>
  319. a.del_flag = #{DEL_FLAG_NORMAL}
  320. AND a.useable=#{useable}
  321. and o.USEABLE = '1'
  322. <if test="company != null and company.id != null and company.id != ''">
  323. AND a.company_id = #{company.id}
  324. </if>
  325. <if test="office != null and office.id != null and office.id != ''">
  326. AND a.office_id = #{office.id}
  327. </if>
  328. <if test="name != null and name != ''">
  329. AND a.name like
  330. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  331. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  332. </if>
  333. <if test="enname != null and enname != ''">
  334. AND a.enname like
  335. <if test="dbName == 'oracle'">'%'||#{enname}||'%'</if>
  336. <if test="dbName == 'mysql'">CONCAT('%', #{enname}, '%')</if>
  337. </if>
  338. <!-- 数据范围过滤 -->
  339. ${sqlMap.dsf}
  340. </where>
  341. <choose>
  342. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  343. ORDER BY ${page.orderBy}
  344. </when>
  345. <otherwise>
  346. ORDER BY a.number
  347. </otherwise>
  348. </choose>
  349. </select>
  350. <select id="findRoleList" resultMap="roleResult">
  351. SELECT <!-- DISTINCT -->
  352. <include refid="roleColumns"/>
  353. FROM sys_role a
  354. <include refid="roleJoins"/>
  355. LEFT JOIN sys_office o ON o.id = a.office_id
  356. LEFT JOIN sys_user_role ur ON ur.role_id = a.id
  357. LEFT JOIN sys_user u ON u.id = ur.user_id
  358. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.useable=#{useable} and o.USEABLE = '1'
  359. <if test="user != null and user.id != null and user.id != ''">
  360. AND u.id = #{user.id}
  361. </if>
  362. <if test=" userId != null and userId != ''">
  363. AND u.id = #{userId}
  364. </if>
  365. <if test="user != null and user.comId != null and user.comId != ''">
  366. AND a.company_id= #{user.comId}
  367. </if>
  368. <if test="company != null and company.id != null and company.id != ''">
  369. AND a.company_id = #{company.id}
  370. </if>
  371. <if test="branchCompany != null and branchCompany.id != null and branchCompany.id != ''">
  372. AND a.branch_company = #{branchCompany.id}
  373. </if>
  374. <if test="user != null and user.loginName != null and user.loginName != ''">
  375. AND u.login_name = #{user.loginName}
  376. </if>
  377. <if test="name != null and name != ''">
  378. AND a.name like
  379. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  380. <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
  381. </if>
  382. <if test="enname != null and enname != ''">
  383. AND a.enname like
  384. <if test="dbName == 'oracle'">'%'||#{enname}||'%'</if>
  385. <if test="dbName == 'mysql'">CONCAT('%', #{enname}, '%')</if>
  386. </if>
  387. <!-- 数据范围过滤 -->
  388. ${sqlMap.dsf}
  389. ORDER BY a.number
  390. </select>
  391. <select id="findAllList" resultType="Role">
  392. SELECT
  393. <include refid="roleColumns"/>
  394. FROM sys_role a
  395. <include refid="roleJoins"/>
  396. LEFT JOIN sys_office o ON o.id = a.office_id
  397. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  398. ORDER BY a.number
  399. </select>
  400. <select id="getRoleByCompanyId" resultMap="roleResult">
  401. SELECT <include refid="roleColumns"/>
  402. FROM sys_role a <include refid="roleJoins"/>
  403. LEFT JOIN sys_office o ON o.id = a.office_id
  404. WHERE
  405. a.del_flag = '0' and o.USEABLE = '1'
  406. <if test="roleId !=null and roleId !=''">
  407. AND a.id = #{roleId}
  408. </if>
  409. <if test="companyId != null and companyId !=''">
  410. AND a.company_id = #{companyId}
  411. </if>
  412. </select>
  413. <insert id="insert">
  414. INSERT INTO sys_role(
  415. id,
  416. office_id,
  417. company_id,
  418. name,
  419. enname,
  420. role_type,
  421. data_scope,
  422. create_by,
  423. create_date,
  424. update_by,
  425. update_date,
  426. remarks,
  427. del_flag,
  428. is_sys,
  429. branch_company,
  430. number,
  431. useable
  432. ) VALUES (
  433. #{id},
  434. #{office.id},
  435. #{company.id},
  436. #{name},
  437. #{enname},
  438. #{roleType},
  439. #{dataScope},
  440. #{createBy.id},
  441. #{createDate},
  442. #{updateBy.id},
  443. #{updateDate},
  444. #{remarks},
  445. #{delFlag},
  446. #{sysData},
  447. #{branchCompany.id},
  448. #{number},
  449. #{useable}
  450. )
  451. </insert>
  452. <update id="update">
  453. UPDATE sys_role SET
  454. office_id = #{office.id},
  455. company_id = #{company.id},
  456. name = #{name},
  457. role_type = #{roleType},
  458. data_scope = #{dataScope},
  459. update_by = #{updateBy.id},
  460. update_date = #{updateDate},
  461. remarks = #{remarks},
  462. is_sys = #{sysData},
  463. useable = #{useable},
  464. number = #{number},
  465. branch_company = #{branchCompany.id}
  466. WHERE id = #{id}
  467. </update>
  468. <delete id="deleteRoleMenu">
  469. DELETE FROM sys_role_menu WHERE role_id = #{id}
  470. </delete>
  471. <insert id="insertRoleMenu">
  472. INSERT INTO sys_role_menu(role_id, menu_id)
  473. <foreach collection="menuList" item="menu" separator=" union all ">
  474. SELECT #{id}, #{menu.id} FROM dual
  475. </foreach>
  476. </insert>
  477. <!--<delete id="deleteRoleOffice">
  478. DELETE FROM sys_role_office WHERE role_id = #{id}
  479. </delete>
  480. <insert id="insertRoleOffice">
  481. INSERT INTO sys_role_office(role_id, office_id)
  482. <foreach collection="officeList" item="office" separator=" union all ">
  483. SELECT #{id}, #{office.id} FROM dual
  484. </foreach>
  485. </insert>-->
  486. <delete id="deleteRoleActivity">
  487. DELETE FROM sys_role_activity_relation WHERE role_id = #{id}
  488. </delete>
  489. <delete id="deleteRoleActivityOne">
  490. DELETE FROM sys_role_activity_relation WHERE role_id = #{id} AND role_activity_id = #{roleActivityId}
  491. </delete>
  492. <insert id="insertRoleActivity">
  493. INSERT INTO sys_role_activity_relation(role_id, role_activity_id)
  494. <foreach collection="roleActivityList" item="roleActivity" separator=" union all ">
  495. SELECT #{id}, #{roleActivity.id} FROM dual
  496. </foreach>
  497. </insert>
  498. <delete id="deleteUserRole">
  499. DELETE FROM sys_user_role WHERE role_id = #{id}
  500. </delete>
  501. <update id="delete">
  502. DELETE FROM sys_role
  503. WHERE id = #{id}
  504. </update>
  505. <update id="deleteByLogic">
  506. UPDATE sys_role SET
  507. del_flag = #{DEL_FLAG_DELETE}
  508. WHERE id = #{id}
  509. </update>
  510. <select id="checkRole" resultType="Role">
  511. select * from sys_role where id in (
  512. select role_id from sys_user_role where user_id = #{0} and role_id in
  513. (select id from sys_role where company_id =#{1})
  514. ) ORDER BY data_scope ASC
  515. </select>
  516. <select id="getRoleUserId" resultType="java.lang.String" >
  517. select user_id from sys_user_role where role_id=(select id from sys_role where company_id=#{0} and del_flag=0 and RIGHT(enname,4)='bmzg')
  518. and user_id in (select user_id from sys_user_office where company_id=#{0}) and user_id != #{1}
  519. </select>
  520. <select id="queryRoleEnameByOfficeId" resultType="Role">
  521. SELECT * FROM sys_role where company_id = #{officeId} and del_flag = 0 limit 1
  522. </select>
  523. <select id="findUserRoleCount" resultType="java.lang.Integer">
  524. SELECT count(1) FROM sys_user_role where role_id = #{id}
  525. </select>
  526. <select id="queryMasterByEnameAndOfficeId" resultType="java.lang.String" parameterType="java.util.HashMap">
  527. select * from (select a.id from sys_user a ,sys_role b,sys_user_role c
  528. where a.id = c.user_id and b.id = c.role_id
  529. and b.enname like concat('%',#{ename},'%') and b.company_id = #{companyId}) dt
  530. ,sys_user_office su where dt.id = su.user_id and su.office_id = #{officeId} and su.del_flag = 0 and su.status = 3
  531. </select>
  532. <!--部门调整用-->
  533. <select id="getRoleByOfficeId" resultType="Role">
  534. SELECT * FROM sys_role r where r.office_id = #{office.id} and r.name = #{name} and role_type = #{roleType}
  535. </select>
  536. <update id="deleteByOffice">
  537. UPDATE sys_role a LEFT JOIN sys_office o ON o.id=a.office_id
  538. SET a.del_flag = '1' WHERE o.id = #{id} or find_in_set(#{id},o.parent_ids)
  539. </update>
  540. <select id="getManagerRoleList" resultType="Role">
  541. SELECT
  542. r.id,
  543. r.enname,
  544. r.office_id AS "office.id",
  545. r.company_id AS "company.id",
  546. o.name AS "office.name"
  547. FROM sys_role r LEFT JOIN sys_office o ON o.id = r.office_id AND o.del_flag = '0'
  548. INNER JOIN sys_user_role ur ON ur.role_id = r.id AND ur.user_id = #{userId}
  549. where (r.enname = 'gly' or r.enname = 'fgly') AND (find_in_set(#{companyId},o.parent_ids) OR o.id=#{companyId})
  550. and r.del_flag = '0'
  551. </select>
  552. <select id="getByOfficeId" resultType="Role" parameterType="String">
  553. select id ,
  554. -- office_id as office.id,
  555. name
  556. from sys_role
  557. <where>
  558. office_id = #{officeId} and useable = '1' and del_flag = '0'
  559. </where>
  560. </select>
  561. <select id="getRoleIdByUserId" resultType="String">
  562. select role_id
  563. from sys_user_role
  564. where user_id = #{userId,jdbcType=VARCHAR}
  565. </select>
  566. <select id="getRoleByUserId" parameterType="String" resultType="Role">
  567. select r.*
  568. from sys_role r left join sys_user_role ur
  569. on r.id = ur.role_id
  570. where ur.user_id = #{userId}
  571. </select>
  572. <update id="updateRoleByUserId">
  573. update sys_user_role
  574. set role_id = #{roleId}
  575. where user_id = #{userId}
  576. </update>
  577. </mapper>