java后端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

270 řádky
10 KiB

  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.ruoyi.system.mapper.SysDeptMapper">
  6. <resultMap type="SysDept" id="SysDeptResult">
  7. <id property="deptId" column="dept_id" />
  8. <result property="parentId" column="parent_id" />
  9. <result property="ancestors" column="ancestors" />
  10. <result property="deptName" column="dept_name" />
  11. <result property="orderNum" column="order_num" />
  12. <result property="leader" column="leader" />
  13. <result property="phone" column="phone" />
  14. <result property="email" column="email" />
  15. <result property="status" column="status" />
  16. <result property="delFlag" column="del_flag" />
  17. <result property="parentName" column="parent_name" />
  18. <result property="importCode" column="import_code" />
  19. <result property="orgCode" column="org_code" />
  20. <result property="longitude" column="longitude" />
  21. <result property="latitude" column="latitude" />
  22. <result property="createBy" column="create_by" />
  23. <result property="createTime" column="create_time" />
  24. <result property="updateBy" column="update_by" />
  25. <result property="updateTime" column="update_time" />
  26. </resultMap>
  27. <sql id="selectDeptVo">
  28. select d.dept_id, 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,
  29. d.import_code, d.org_code, d.longitude, d.latitude
  30. from sys_dept d
  31. </sql>
  32. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  33. <include refid="selectDeptVo"/>
  34. where d.del_flag = '0'
  35. <if test="deptId != null and deptId != 0">
  36. AND dept_id = #{deptId}
  37. </if>
  38. <if test="parentId != null and parentId != 0">
  39. AND parent_id = #{parentId}
  40. </if>
  41. <if test="deptName != null and deptName != ''">
  42. AND dept_name like concat('%', #{deptName}, '%')
  43. </if>
  44. <if test="orgCode != null and orgCode != ''">
  45. AND org_code like concat(#{orgCode}, '%')
  46. </if>
  47. <if test="status != null and status != ''">
  48. AND status = #{status}
  49. </if>
  50. <!-- 数据范围过滤 -->
  51. ${params.dataScope}
  52. </select>
  53. <select id="selectDeptListByRoleId" resultType="Long">
  54. select d.dept_id
  55. from sys_dept d
  56. left join sys_role_dept rd on d.dept_id = rd.dept_id
  57. where rd.role_id = #{roleId}
  58. <if test="deptCheckStrictly">
  59. and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
  60. </if>
  61. order by d.parent_id, d.order_num
  62. </select>
  63. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  64. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.import_code, d.org_code, d.longitude, d.latitude, d.del_flag,
  65. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  66. from sys_dept d
  67. where d.dept_id = #{deptId}
  68. </select>
  69. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  70. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  71. </select>
  72. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  73. select count(1) from sys_dept
  74. where del_flag = '0' and parent_id = #{deptId} limit 1
  75. </select>
  76. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  77. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  78. </select>
  79. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  80. select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  81. </select>
  82. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  83. <include refid="selectDeptVo"/>
  84. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  85. </select>
  86. <insert id="insertDept" parameterType="SysDept">
  87. insert into sys_dept(
  88. <if test="deptId != null and deptId != 0">dept_id,</if>
  89. <if test="parentId != null and parentId != 0">parent_id,</if>
  90. <if test="deptName != null and deptName != ''">dept_name,</if>
  91. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  92. <if test="orderNum != null">order_num,</if>
  93. <if test="leader != null and leader != ''">leader,</if>
  94. <if test="phone != null and phone != ''">phone,</if>
  95. <if test="email != null and email != ''">email,</if>
  96. <if test="status != null">status,</if>
  97. <if test="importCode != null">import_code,</if>
  98. <if test="orgCode != null">org_code,</if>
  99. <if test="longitude != null">longitude,</if>
  100. <if test="latitude != null">latitude,</if>
  101. <if test="createBy != null and createBy != ''">create_by,</if>
  102. create_time
  103. )values(
  104. <if test="deptId != null and deptId != 0">#{deptId},</if>
  105. <if test="parentId != null and parentId != 0">#{parentId},</if>
  106. <if test="deptName != null and deptName != ''">#{deptName},</if>
  107. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  108. <if test="orderNum != null">#{orderNum},</if>
  109. <if test="leader != null and leader != ''">#{leader},</if>
  110. <if test="phone != null and phone != ''">#{phone},</if>
  111. <if test="email != null and email != ''">#{email},</if>
  112. <if test="status != null">#{status},</if>
  113. <if test="importCode != null">#{importCode},</if>
  114. <if test="orgCode != null">#{orgCode},</if>
  115. <if test="longitude != null">#{longitude},</if>
  116. <if test="latitude != null">#{latitude},</if>
  117. <if test="createBy != null and createBy != ''">#{createBy},</if>
  118. sysdate()
  119. )
  120. </insert>
  121. <update id="updateDept" parameterType="SysDept">
  122. update sys_dept
  123. <set>
  124. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  125. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  126. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  127. <if test="orderNum != null">order_num = #{orderNum},</if>
  128. <if test="leader != null">leader = #{leader},</if>
  129. <if test="phone != null">phone = #{phone},</if>
  130. <if test="email != null">email = #{email},</if>
  131. <if test="status != null and status != ''">status = #{status},</if>
  132. <if test="importCode != null and importCode != ''">import_code = #{importCode},</if>
  133. <if test="orgCode != null and orgCode != ''">org_code = #{orgCode},</if>
  134. <if test="longitude != null and longitude != ''">longitude = #{longitude},</if>
  135. <if test="latitude != null and latitude != ''">latitude = #{latitude},</if>
  136. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  137. update_time = sysdate()
  138. </set>
  139. where dept_id = #{deptId}
  140. </update>
  141. <update id="updateDeptChildren" parameterType="java.util.List">
  142. update sys_dept set ancestors =
  143. <foreach collection="depts" item="item" index="index"
  144. separator=" " open="case dept_id" close="end">
  145. when #{item.deptId} then #{item.ancestors}
  146. </foreach>
  147. where dept_id in
  148. <foreach collection="depts" item="item" index="index"
  149. separator="," open="(" close=")">
  150. #{item.deptId}
  151. </foreach>
  152. </update>
  153. <update id="updateDeptStatusNormal" parameterType="Long">
  154. update sys_dept set status = '0' where dept_id in
  155. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  156. #{deptId}
  157. </foreach>
  158. </update>
  159. <delete id="deleteDeptById" parameterType="Long">
  160. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  161. </delete>
  162. <insert id="insertSysDeptBatch" parameterType="list" useGeneratedKeys="true" keyProperty="deptId">
  163. insert into sys_dept
  164. <trim prefix="(" suffix=")" suffixOverrides=",">
  165. parent_id,
  166. ancestors,
  167. dept_name,
  168. order_num,
  169. leader,
  170. phone,
  171. email,
  172. status,
  173. del_flag,
  174. import_code,
  175. org_code,
  176. longitude,
  177. latitude,
  178. create_by,
  179. create_time,
  180. </trim>
  181. values
  182. <foreach item="item" collection="list" separator="," >
  183. <trim prefix="(" suffix=")" suffixOverrides=",">
  184. #{item.parentId},
  185. #{item.ancestors},
  186. #{item.deptName},
  187. #{item.orderNum},
  188. #{item.leader},
  189. #{item.phone},
  190. #{item.email},
  191. #{item.status},
  192. #{item.delFlag},
  193. #{item.importCode},
  194. #{item.orgCode},
  195. #{item.longitude},
  196. #{item.latitude},
  197. #{item.createBy},
  198. #{item.createTime},
  199. </trim>
  200. </foreach>
  201. </insert>
  202. <!--批量更新-->
  203. <update id="updateSysDeptBatch" parameterType="list" >
  204. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  205. update sys_dept
  206. <set>
  207. <if test="item.parentId != null">parent_id = #{item.parentId},</if>
  208. <if test="item.ancestors != null">ancestors = #{item.ancestors},</if>
  209. <if test="item.deptName != null">dept_name = #{item.deptName},</if>
  210. <if test="item.orderNum != null">order_num = #{item.orderNum},</if>
  211. <if test="item.leader != null">leader = #{item.leader},</if>
  212. <if test="item.phone != null">phone = #{item.phone},</if>
  213. <if test="item.email != null">email = #{item.email},</if>
  214. <if test="item.status != null">status = #{item.status},</if>
  215. <if test="item.delFlag != null">del_flag = #{item.delFlag},</if>
  216. <if test="item.importCode != null and item.importCode != ''">import_code = #{item.importCode},</if>
  217. <if test="item.orgCode != null and item.orgCode != ''">org_code = #{item.orgCode},</if>
  218. <if test="item.longitude != null">longitude = #{item.longitude},</if>
  219. <if test="item.latitude != null">latitude = #{item.latitude},</if>
  220. <if test="item.updateBy != null">update_by = #{item.updateBy},</if>
  221. <if test="item.updateTime != null">update_time = #{item.updateTime},</if>
  222. </set>
  223. where dept_id = #{item.deptId}
  224. </foreach>
  225. </update>
  226. <delete id="deleteAllDept">
  227. delete from sys_dept
  228. </delete>
  229. <select id="selectDeptByOrgCode" parameterType="String" resultMap="SysDeptResult">
  230. <include refid="selectDeptVo"/>
  231. where d.org_code = #{orgCode}
  232. </select>
  233. <select id="selectDeptByImportCode" parameterType="String" resultMap="SysDeptResult">
  234. <include refid="selectDeptVo"/>
  235. where d.import_code = #{importCode}
  236. </select>
  237. <select id="selectDeptNextOrderNum" parameterType="SysDept" resultType="Long">
  238. SELECT
  239. IFNULL(MAX(order_num), 0) + 1
  240. FROM
  241. sys_dept
  242. where
  243. `parent_id` = #{parentId}
  244. </select>
  245. </mapper>