SysDeptMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.sooka.system.mapper.SysDeptMapper">
  6. <resultMap type="SysDept" id="SysDeptResult">
  7. <id property="deptId" column="dept_id" />
  8. <result property="postId" column="post_id" />
  9. <result property="deptType" column="dept_type" />
  10. <result property="parentId" column="parent_id" />
  11. <result property="ancestors" column="ancestors" />
  12. <result property="deptName" column="dept_name" />
  13. <result property="orderNum" column="order_num" />
  14. <result property="leader" column="leader" />
  15. <result property="phone" column="phone" />
  16. <result property="email" column="email" />
  17. <result property="status" column="status" />
  18. <result property="delFlag" column="del_flag" />
  19. <result property="parentName" column="parent_name" />
  20. <result property="createBy" column="create_by" />
  21. <result property="createTime" column="create_time" />
  22. <result property="updateBy" column="update_by" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="layerId" column="layer_id" />
  25. <result property="datasetName" column="dataset_name" />
  26. <result property="datasourceName" column="datasource_name" />
  27. <result property="centerpointLon" column="centerpoint_lon" />
  28. <result property="centerpointLat" column="centerpoint_lat" />
  29. </resultMap>
  30. <sql id="selectDeptVo">
  31. select d.dept_id, d.post_id, (select post_name from sys_post where post_id = d.post_id) postName, d.dept_type, d.layer_id, d.datasource_name, d.dataset_name, d.centerpoint_lon, d.centerpoint_lat, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
  32. from sys_dept d
  33. </sql>
  34. <select id="selectRoleDeptTree" parameterType="Long" resultType="String">
  35. select concat(d.dept_id, d.dept_name) as dept_name
  36. from sys_dept d
  37. left join sys_role_dept rd on d.dept_id = rd.dept_id
  38. where d.del_flag = '0' and rd.role_id = #{roleId}
  39. order by d.parent_id, d.order_num
  40. </select>
  41. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  42. <include refid="selectDeptVo"/>
  43. where d.del_flag = '0'
  44. <if test="parentId != null and parentId != 0">
  45. AND parent_id = #{parentId}
  46. </if>
  47. <if test="deptName != null and deptName != ''">
  48. AND dept_name like concat('%', #{deptName}, '%')
  49. </if>
  50. <if test="status != null and status != ''">
  51. AND status = #{status}
  52. </if>
  53. <!-- 数据范围过滤 -->
  54. ${params.dataScope}
  55. order by d.parent_id, d.order_num
  56. </select>
  57. <select id="selectDeptTreeList" parameterType="SysDept" resultMap="SysDeptResult">
  58. SELECT
  59. dept_id,
  60. dept_name,
  61. parent_id,
  62. status
  63. FROM
  64. (
  65. SELECT
  66. t1.dept_id,
  67. t1.dept_name,
  68. t1.parent_id,
  69. t1.status,
  70. IF (
  71. find_in_set(parent_id, @pids) > 0,
  72. @pids := concat(@pids, ',', dept_id),
  73. 0
  74. ) AS ischild
  75. FROM
  76. (
  77. SELECT
  78. dept_id,
  79. parent_id,
  80. dept_name,
  81. status
  82. FROM
  83. sys_dept t
  84. WHERE
  85. 1 = 1
  86. ORDER BY
  87. parent_id,
  88. dept_id
  89. ) t1,
  90. (
  91. SELECT
  92. @pids := #{parentId} /**要查询的菜单节点 id**/
  93. ) t2
  94. ) t3
  95. WHERE
  96. ischild != 0
  97. </select>
  98. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  99. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  100. </select>
  101. <select id="selectDeptCount" parameterType="SysDept" resultType="int">
  102. select count(1) from sys_dept
  103. where del_flag = '0'
  104. <if test="deptId != null and deptId != 0"> and dept_id = #{deptId} </if>
  105. <if test="parentId != null and parentId != 0"> and parent_id = #{parentId} </if>
  106. </select>
  107. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  108. <include refid="selectDeptVo"/>
  109. where dept_name=#{deptName} and parent_id = #{parentId}
  110. </select>
  111. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  112. select d.dept_id, d.post_id,
  113. (select post_name from sys_post where post_id = d.post_id) postName,
  114. d.dept_type, d.layer_id, d.datasource_name, d.dataset_name, d.centerpoint_lon, d.centerpoint_lat,
  115. d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
  116. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  117. from sys_dept d
  118. where d.dept_id = #{deptId}
  119. </select>
  120. <select id="selectDeptByIds" parameterType="Long" resultMap="SysDeptResult">
  121. select d.dept_id, d.post_id,
  122. (select post_name from sys_post where post_id = d.post_id) postName,
  123. d.dept_type, d.layer_id, d.datasource_name, d.dataset_name, d.centerpoint_lon, d.centerpoint_lat,
  124. d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
  125. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  126. from sys_dept d
  127. where d.dept_id in
  128. <foreach collection="array" item="deptIds" open="(" separator="," close=")">
  129. #{deptIds}
  130. </foreach>
  131. </select>
  132. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  133. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  134. </select>
  135. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  136. select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  137. </select>
  138. <insert id="insertDept" parameterType="SysDept">
  139. insert into sys_dept(
  140. <if test="deptId != null and deptId != 0">dept_id,</if>
  141. <if test="postId != null and postId != 0">post_id,</if>
  142. <if test="deptType != null and deptType != 0">dept_type,</if>
  143. <if test="layerId != null and layerId != ''">layer_id,</if>
  144. <if test="datasetName != null and datasetName != ''">dataset_name,</if>
  145. <if test="datasourceName != null and datasourceName != ''">datasource_name,</if>
  146. <if test="centerpointLon != null and centerpointLon != ''">centerpoint_lon,</if>
  147. <if test="centerpointLat != null and centerpointLat != ''">centerpoint_lat,</if>
  148. <if test="parentId != null and parentId != 0">parent_id,</if>
  149. <if test="deptName != null and deptName != ''">dept_name,</if>
  150. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  151. <if test="orderNum != null and orderNum != ''">order_num,</if>
  152. <if test="leader != null and leader != ''">leader,</if>
  153. <if test="phone != null and phone != ''">phone,</if>
  154. <if test="email != null and email != ''">email,</if>
  155. <if test="status != null">status,</if>
  156. <if test="createBy != null and createBy != ''">create_by,</if>
  157. create_time
  158. )values(
  159. <if test="deptId != null and deptId != 0">#{deptId},</if>
  160. <if test="postId != null and postId != 0">#{postId},</if>
  161. <if test="deptType != null and deptType != 0">#{deptType},</if>
  162. <if test="layerId != null and layerId != ''">#{layerId},</if>
  163. <if test="datasetName != null and datasetName != ''">#{datasetName},</if>
  164. <if test="datasourceName != null and datasourceName != ''">#{datasourceName},</if>
  165. <if test="centerpointLon != null and centerpointLon != ''">#{centerpointLon},</if>
  166. <if test="centerpointLat != null and centerpointLat != ''">#{centerpointLat},</if>
  167. <if test="parentId != null and parentId != 0">#{parentId},</if>
  168. <if test="deptName != null and deptName != ''">#{deptName},</if>
  169. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  170. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  171. <if test="leader != null and leader != ''">#{leader},</if>
  172. <if test="phone != null and phone != ''">#{phone},</if>
  173. <if test="email != null and email != ''">#{email},</if>
  174. <if test="status != null">#{status},</if>
  175. <if test="createBy != null and createBy != ''">#{createBy},</if>
  176. sysdate()
  177. )
  178. </insert>
  179. <update id="updateDept" parameterType="SysDept">
  180. update sys_dept
  181. <set>
  182. <if test="postId != null and postId != 0">post_id = #{postId},</if>
  183. <if test="deptType != null and deptType != 0">dept_type = #{deptType},</if>
  184. <if test="layerId != null">layer_id = #{layerId},</if>
  185. <if test="datasetName != null">dataset_name = #{datasetName},</if>
  186. <if test="datasourceName != null">datasource_name = #{datasourceName},</if>
  187. <if test="centerpointLon != null">centerpoint_lon = #{centerpointLon},</if>
  188. <if test="centerpointLat != null">centerpoint_lat = #{centerpointLat},</if>
  189. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  190. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  191. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  192. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  193. <if test="leader != null">leader = #{leader},</if>
  194. <if test="phone != null">phone = #{phone},</if>
  195. <if test="email != null">email = #{email},</if>
  196. <if test="status != null and status != ''">status = #{status},</if>
  197. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  198. update_time = sysdate()
  199. </set>
  200. where dept_id = #{deptId}
  201. </update>
  202. <update id="updateDeptChildren" parameterType="java.util.List">
  203. update sys_dept set ancestors =
  204. <foreach collection="depts" item="item" index="index"
  205. separator=" " open="case dept_id" close="end">
  206. when #{item.deptId} then #{item.ancestors}
  207. </foreach>
  208. where dept_id in
  209. <foreach collection="depts" item="item" index="index"
  210. separator="," open="(" close=")">
  211. #{item.deptId}
  212. </foreach>
  213. </update>
  214. <delete id="deleteDeptById" parameterType="Long">
  215. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  216. </delete>
  217. <update id="updateDeptStatus" parameterType="SysDept">
  218. update sys_dept
  219. <set>
  220. <if test="status != null and status != ''">status = #{status},</if>
  221. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  222. update_time = sysdate()
  223. </set>
  224. where dept_id in (${ancestors})
  225. </update>
  226. <select id="selectPost7" parameterType="Long" resultMap="SysDeptResult">
  227. SELECT
  228. *
  229. FROM
  230. SYS_DEPT
  231. WHERE
  232. PARENT_ID = (
  233. SELECT
  234. PARENT_ID
  235. FROM
  236. SYS_DEPT
  237. WHERE
  238. DEPT_ID = #{deptId}
  239. )
  240. AND POST_ID = 7
  241. LIMIT 1
  242. </select>
  243. <select id="selectPost5" parameterType="Long" resultMap="SysDeptResult">
  244. SELECT
  245. *
  246. FROM
  247. sys_dept
  248. WHERE
  249. parent_id = (
  250. SELECT
  251. parent_id
  252. FROM
  253. sys_dept
  254. WHERE
  255. dept_id = (
  256. SELECT
  257. parent_id
  258. FROM
  259. SYS_DEPT
  260. WHERE
  261. PARENT_ID = (
  262. SELECT
  263. PARENT_ID
  264. FROM
  265. SYS_DEPT
  266. WHERE
  267. DEPT_ID = #{deptId}
  268. )
  269. LIMIT 1
  270. )
  271. )
  272. AND post_id = 5
  273. </select>
  274. <select id="selectParentSiblings" parameterType="Long" resultMap="SysDeptResult">
  275. SELECT
  276. dept_id,
  277. dept_name
  278. FROM
  279. sys_dept
  280. WHERE
  281. parent_id = (
  282. SELECT
  283. parent_id
  284. FROM
  285. sys_dept
  286. WHERE
  287. dept_id = (
  288. SELECT
  289. parent_id
  290. FROM
  291. sys_dept
  292. WHERE
  293. dept_id = #{deptId}
  294. )
  295. )
  296. </select>
  297. </mapper>