DepartInfoMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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.DepartInfoMapper">
  4. <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.DepartInfo">
  5. <id column="id" property="id" jdbcType="INTEGER"/>
  6. <result column="depart_name" property="departName" jdbcType="VARCHAR"/>
  7. <result column="parent_id" property="parentId" jdbcType="INTEGER"/>
  8. <result column="all_parent_id" property="allParentId" jdbcType="VARCHAR"/>
  9. <result column="description" property="description" jdbcType="VARCHAR"/>
  10. <result column="depart_code" property="departCode" jdbcType="VARCHAR"/>
  11. <result column="org_code" property="orgCode" jdbcType="VARCHAR"/>
  12. <result column="type" property="type" jdbcType="INTEGER"/>
  13. <result column="remark" property="remark" jdbcType="VARCHAR"/>
  14. <result column="sort" property="sort" jdbcType="INTEGER"/>
  15. <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
  16. <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
  17. <result column="permission" property="permission" jdbcType="VARCHAR"/>
  18. <result column="mis_org_code" property="misOrgCode" jdbcType="VARCHAR"/>
  19. <result column="mis_org_name" property="misOrgName" jdbcType="VARCHAR"/>
  20. <result column="mis_include" property="misInclude" jdbcType="CHAR"/>
  21. <result column="mis_child" property="misChild" jdbcType="VARCHAR"/>
  22. </resultMap>
  23. <sql id="Base_Column_List">
  24. id, depart_name, parent_id, all_parent_id, description, depart_code,
  25. org_code, type, remark, sort, del_flag, create_time, permission,
  26. mis_org_code, mis_org_name, mis_include, mis_child
  27. </sql>
  28. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  29. select
  30. <include refid="Base_Column_List"/>
  31. from sys_depart
  32. where id = #{id,jdbcType=INTEGER}
  33. </select>
  34. <select id="selectByPrimaryKeys" resultMap="BaseResultMap" parameterType="java.lang.String">
  35. select
  36. <include refid="Base_Column_List"/>
  37. from sys_depart
  38. where FIND_IN_SET(id, #{ids,jdbcType=INTEGER}) and del_flag = 'N'
  39. </select>
  40. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  41. delete from sys_depart
  42. where id = #{id,jdbcType=INTEGER}
  43. </delete>
  44. <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.DepartInfo" useGeneratedKeys="true"
  45. keyProperty="id">
  46. insert into sys_depart
  47. <trim prefix="(" suffix=")" suffixOverrides=",">
  48. <if test="id != null">
  49. id,
  50. </if>
  51. <if test="departName != null">
  52. depart_name,
  53. </if>
  54. <if test="parentId != null">
  55. parent_id,
  56. </if>
  57. <if test="allParentId != null">
  58. all_parent_id,
  59. </if>
  60. <if test="description != null">
  61. description,
  62. </if>
  63. <if test="departCode != null">
  64. depart_code,
  65. </if>
  66. <if test="orgCode != null">
  67. org_code,
  68. </if>
  69. <if test="type != null">
  70. type,
  71. </if>
  72. <if test="remark != null">
  73. remark,
  74. </if>
  75. <if test="sort != null">
  76. sort,
  77. </if>
  78. <if test="delFlag != null">
  79. del_flag,
  80. </if>
  81. <if test="createTime != null">
  82. create_time,
  83. </if>
  84. <if test="permission != null">
  85. permission,
  86. </if>
  87. <if test="misOrgCode != null">
  88. mis_org_code,
  89. </if>
  90. <if test="misOrgName != null">
  91. mis_org_name,
  92. </if>
  93. <if test="misInclude != null">
  94. mis_include,
  95. </if>
  96. <if test="misChild != null">
  97. mis_child,
  98. </if>
  99. </trim>
  100. <trim prefix="values (" suffix=")" suffixOverrides=",">
  101. <if test="id != null">
  102. #{id,jdbcType=INTEGER},
  103. </if>
  104. <if test="departName != null">
  105. #{departName,jdbcType=VARCHAR},
  106. </if>
  107. <if test="parentId != null">
  108. #{parentId,jdbcType=INTEGER},
  109. </if>
  110. <if test="allParentId != null">
  111. #{allParentId,jdbcType=VARCHAR},
  112. </if>
  113. <if test="description != null">
  114. #{description,jdbcType=VARCHAR},
  115. </if>
  116. <if test="departCode != null">
  117. #{departCode,jdbcType=VARCHAR},
  118. </if>
  119. <if test="orgCode != null">
  120. #{orgCode,jdbcType=VARCHAR},
  121. </if>
  122. <if test="type != null">
  123. #{type,jdbcType=INTEGER},
  124. </if>
  125. <if test="remark != null">
  126. #{remark,jdbcType=VARCHAR},
  127. </if>
  128. <if test="sort != null">
  129. #{sort,jdbcType=INTEGER},
  130. </if>
  131. <if test="delFlag != null">
  132. #{delFlag,jdbcType=CHAR},
  133. </if>
  134. <if test="createTime != null">
  135. #{createTime,jdbcType=TIMESTAMP},
  136. </if>
  137. <if test="permission != null">
  138. #{permission,jdbcType=VARCHAR},
  139. </if>
  140. <if test="misOrgCode != null">
  141. #{misOrgCode,jdbcType=VARCHAR},
  142. </if>
  143. <if test="misOrgName != null">
  144. #{misOrgName,jdbcType=VARCHAR},
  145. </if>
  146. <if test="misInclude != null">
  147. #{misInclude,jdbcType=CHAR},
  148. </if>
  149. <if test="misChild != null">
  150. #{misChild,jdbcType=VARCHAR},
  151. </if>
  152. </trim>
  153. </insert>
  154. <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.DepartInfo">
  155. UPDATE sys_depart
  156. <set>
  157. <if test="departName != null">
  158. depart_name = #{departName,jdbcType=VARCHAR},
  159. </if>
  160. <if test="parentId != null">
  161. parent_id = #{parentId,jdbcType=INTEGER},
  162. </if>
  163. <if test="allParentId != null">
  164. all_parent_id = #{allParentId,jdbcType=VARCHAR},
  165. </if>
  166. <if test="description != null">
  167. description = #{description,jdbcType=VARCHAR},
  168. </if>
  169. <if test="departCode != null">
  170. depart_code = #{departCode,jdbcType=VARCHAR},
  171. </if>
  172. <if test="orgCode != null">
  173. org_code = #{orgCode,jdbcType=VARCHAR},
  174. </if>
  175. <if test="type != null">
  176. type = #{type,jdbcType=INTEGER},
  177. </if>
  178. <if test="remark != null">
  179. remark = #{remark,jdbcType=VARCHAR},
  180. </if>
  181. <if test="sort != null">
  182. sort = #{sort,jdbcType=INTEGER},
  183. </if>
  184. <if test="delFlag != null">
  185. del_flag = #{delFlag,jdbcType=CHAR},
  186. </if>
  187. <if test="createTime != null">
  188. create_time = #{createTime,jdbcType=TIMESTAMP},
  189. </if>
  190. <if test="permission != null">
  191. permission = #{permission,jdbcType=VARCHAR},
  192. </if>
  193. <if test="misOrgCode != null">
  194. mis_org_code = #{misOrgCode,jdbcType=VARCHAR},
  195. </if>
  196. <if test="misOrgName != null">
  197. mis_org_name = #{misOrgName,jdbcType=VARCHAR},
  198. </if>
  199. <if test="misInclude != null">
  200. mis_include = #{misInclude,jdbcType=CHAR},
  201. </if>
  202. <if test="misChild != null">
  203. mis_child = #{misChild,jdbcType=VARCHAR},
  204. </if>
  205. </set>
  206. where id = #{id,jdbcType=INTEGER}
  207. </update>
  208. <select id="queryDepartInfosByPage" parameterType="java.util.Map"
  209. resultType="com.izouma.awesomeadmin.model.DepartInfo">
  210. select
  211. <include refid="Base_Column_List"/>
  212. from sys_depart
  213. <where>
  214. and del_flag = 'N'
  215. <if test="record.id != null and !&quot;&quot;.equals(record.id)">
  216. and id = #{record.id}
  217. </if>
  218. <if test="record.departName != null and !&quot;&quot;.equals(record.departName)">
  219. and depart_name = #{record.departName}
  220. </if>
  221. <if test="record.parentId != null and !&quot;&quot;.equals(record.parentId)">
  222. and parent_id = #{record.parentId}
  223. </if>
  224. <if test="record.allParentId != null and !&quot;&quot;.equals(record.allParentId)">
  225. and all_parent_id = #{record.allParentId}
  226. </if>
  227. <if test="record.description != null and !&quot;&quot;.equals(record.description)">
  228. and description = #{record.description}
  229. </if>
  230. <if test="record.departCode != null and !&quot;&quot;.equals(record.departCode)">
  231. and depart_code = #{record.departCode}
  232. </if>
  233. <if test="record.orgCode != null and !&quot;&quot;.equals(record.orgCode)">
  234. and org_code = #{record.orgCode}
  235. </if>
  236. <if test="record.type != null and !&quot;&quot;.equals(record.type)">
  237. and type = #{record.type}
  238. </if>
  239. <if test="record.remark != null and !&quot;&quot;.equals(record.remark)">
  240. and remark = #{record.remark}
  241. </if>
  242. <if test="record.sort != null and !&quot;&quot;.equals(record.sort)">
  243. and sort = #{record.sort}
  244. </if>
  245. <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
  246. and del_flag = #{record.delFlag}
  247. </if>
  248. <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">
  249. and create_time = #{record.createTime}
  250. </if>
  251. <if test="record.permission != null and !&quot;&quot;.equals(record.permission)">
  252. and permission = #{record.permission}
  253. </if>
  254. </where>
  255. order by id desc
  256. </select>
  257. <select id="queryAllDepartInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DepartInfo">
  258. select
  259. <include refid="Base_Column_List"/>
  260. from sys_depart
  261. <where>
  262. and del_flag = 'N'
  263. <if test="id != null and !&quot;&quot;.equals(id)">
  264. and id = #{id}
  265. </if>
  266. <if test="idStr != null and !&quot;&quot;.equals(idStr)">
  267. and id in (${idStr})
  268. </if>
  269. <if test="departName != null and !&quot;&quot;.equals(departName)">
  270. and depart_name = #{departName}
  271. </if>
  272. <if test="parentId != null and !&quot;&quot;.equals(parentId)">
  273. and parent_id = #{parentId}
  274. </if>
  275. <if test="allParentId != null and !&quot;&quot;.equals(allParentId)">
  276. and all_parent_id = #{allParentId}
  277. </if>
  278. <if test="description != null and !&quot;&quot;.equals(description)">
  279. and description = #{description}
  280. </if>
  281. <if test="departCode != null and !&quot;&quot;.equals(departCode)">
  282. and depart_code = #{departCode}
  283. </if>
  284. <if test="orgCode != null and !&quot;&quot;.equals(orgCode)">
  285. and org_code = #{orgCode}
  286. </if>
  287. <if test="type != null and !&quot;&quot;.equals(type)">
  288. and type = #{type}
  289. </if>
  290. <if test="remark != null and !&quot;&quot;.equals(remark)">
  291. and remark = #{remark}
  292. </if>
  293. <if test="sort != null and !&quot;&quot;.equals(sort)">
  294. and sort = #{sort}
  295. </if>
  296. <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
  297. and del_flag = #{delFlag}
  298. </if>
  299. <if test="createTime != null and !&quot;&quot;.equals(createTime)">
  300. and create_time = #{createTime}
  301. </if>
  302. <if test="permission != null and !&quot;&quot;.equals(permission)">
  303. and permission = #{permission}
  304. </if>
  305. </where>
  306. order by id desc
  307. </select>
  308. <select id="queryDepartInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DepartInfo">
  309. select
  310. <include refid="Base_Column_List"/>
  311. from sys_depart
  312. <where>
  313. and del_flag = 'N'
  314. <if test="id != null and !&quot;&quot;.equals(id)">
  315. and id = #{id}
  316. </if>
  317. <if test="departName != null and !&quot;&quot;.equals(departName)">
  318. and depart_name = #{departName}
  319. </if>
  320. <if test="parentId != null and !&quot;&quot;.equals(parentId)">
  321. and parent_id = #{parentId}
  322. </if>
  323. <if test="allParentId != null and !&quot;&quot;.equals(allParentId)">
  324. and all_parent_id = #{allParentId}
  325. </if>
  326. <if test="description != null and !&quot;&quot;.equals(description)">
  327. and description = #{description}
  328. </if>
  329. <if test="departCode != null and !&quot;&quot;.equals(departCode)">
  330. and depart_code = #{departCode}
  331. </if>
  332. <if test="orgCode != null and !&quot;&quot;.equals(orgCode)">
  333. and org_code = #{orgCode}
  334. </if>
  335. <if test="type != null and !&quot;&quot;.equals(type)">
  336. and type = #{type}
  337. </if>
  338. <if test="remark != null and !&quot;&quot;.equals(remark)">
  339. and remark = #{remark}
  340. </if>
  341. <if test="sort != null and !&quot;&quot;.equals(sort)">
  342. and sort = #{sort}
  343. </if>
  344. <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
  345. and del_flag = #{delFlag}
  346. </if>
  347. <if test="createTime != null and !&quot;&quot;.equals(createTime)">
  348. and create_time = #{createTime}
  349. </if>
  350. <if test="permission != null and !&quot;&quot;.equals(permission)">
  351. and permission = #{permission}
  352. </if>
  353. </where>
  354. LIMIT 1
  355. </select>
  356. <select id="findPower" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DepartInfo">
  357. select * from sys_depart where all_parent_id LIKE '${allParentId}%' and id= #{parentId}
  358. </select>
  359. <update id="delete">
  360. UPDATE sys_depart SET del_flag = 'Y'
  361. <where>
  362. AND id = #{id}
  363. </where>
  364. </update>
  365. <select id="getParentList" resultType="departInfo" parameterType="integer">
  366. SELECT * from sys_depart WHERE FIND_IN_SET(id,(SELECT all_parent_id from sys_depart WHERE id = #{id})) AND del_flag = 'N'
  367. </select>
  368. <select id="getUserDeparts" resultType="com.izouma.awesomeadmin.model.DepartInfo">
  369. select
  370. <include refid="Base_Column_List"/>
  371. from sys_depart
  372. where id in (select depart_id from sys_user_depart where user_id = #{userId})
  373. and del_flag = 'N'
  374. </select>
  375. <insert id="setUserDeparts">
  376. insert into sys_user_depart (user_id, depart_id)
  377. values
  378. <foreach collection="departs" item="departId" separator=",">
  379. (#{userId}, #{departId})
  380. </foreach>
  381. </insert>
  382. <delete id="clearUserDeparts">
  383. delete from sys_user_depart where user_id = #{userId}
  384. </delete>
  385. <select id="getUserDepartId" resultType="java.lang.String">
  386. SELECT group_concat(depart_id) FROM sys_user_depart WHERE user_id = #{id}
  387. </select>
  388. <select id="getDepartUsers" resultType="com.izouma.awesomeadmin.model.UserInfo">
  389. select * from sys_user where id in (select user_id from sys_user_depart where depart_id = #{departId}) and del_flag = 'N'
  390. </select>
  391. <select id="getChildDepartsByUserId" resultType="com.izouma.awesomeadmin.model.DepartInfo">
  392. SELECT
  393. *
  394. FROM
  395. sys_depart
  396. WHERE
  397. sys_depart.del_flag = 'N'
  398. AND (
  399. FIND_IN_SET(
  400. sys_depart.id,
  401. (
  402. SELECT
  403. sys_user.mis_child
  404. FROM
  405. sys_user
  406. WHERE
  407. sys_user.del_flag = 'N'
  408. AND sys_user.id = #{userId}
  409. )
  410. )
  411. OR FIND_IN_SET(
  412. sys_depart.id,
  413. (
  414. SELECT
  415. child_depart.mis_child
  416. FROM
  417. sys_depart child_depart
  418. WHERE
  419. child_depart.id = (
  420. SELECT
  421. sys_user_depart.depart_id
  422. FROM
  423. sys_user_depart,
  424. sys_user
  425. WHERE
  426. sys_user_depart.user_id = #{userId}
  427. AND sys_user.inherit_flag = 'Y'
  428. AND sys_user.id = #{userId}
  429. ORDER BY
  430. sys_user_depart.id DESC
  431. LIMIT 1
  432. )
  433. )
  434. )
  435. )
  436. </select>
  437. </mapper>