调解系统后端服务

SysDeptMapper.xml 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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="deptType" column="dept_type" />
  12. <result property="orderNum" column="order_num" />
  13. <result property="leader" column="leader" />
  14. <result property="phone" column="phone" />
  15. <result property="email" column="email" />
  16. <result property="status" column="status" />
  17. <result property="delFlag" column="del_flag" />
  18. <result property="parentName" column="parent_name" />
  19. <result property="createBy" column="create_by" />
  20. <result property="createTime" column="create_time" />
  21. <result property="updateBy" column="update_by" />
  22. <result property="updateTime" column="update_time" />
  23. </resultMap>
  24. <sql id="selectDeptVo">
  25. select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_type,d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time
  26. from ms_sys_dept d
  27. </sql>
  28. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  29. <include refid="selectDeptVo"/>
  30. where d.del_flag = '0'
  31. <if test="deptId != null and deptId != 0">
  32. AND dept_id = #{deptId}
  33. </if>
  34. <if test="parentId != null and parentId != 0">
  35. AND parent_id = #{parentId}
  36. </if>
  37. <if test="deptName != null and deptName != ''">
  38. AND dept_name like concat('%', #{deptName}, '%')
  39. </if>
  40. <if test="status != null and status != ''">
  41. AND status = #{status}
  42. </if>
  43. <!-- 数据范围过滤 -->
  44. ${params.dataScope}
  45. order by d.parent_id, d.order_num
  46. </select>
  47. <select id="selectDeptListByRoleId" resultType="Long">
  48. select d.dept_id
  49. from ms_sys_dept d
  50. left join ms_sys_role_dept rd on d.dept_id = rd.dept_id
  51. where rd.role_id = #{roleId}
  52. <if test="deptCheckStrictly">
  53. and d.dept_id not in (select d.parent_id from ms_sys_dept d inner join ms_sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
  54. </if>
  55. order by d.parent_id, d.order_num
  56. </select>
  57. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  58. select d.dept_id, d.parent_id, d.ancestors, d.dept_name,d.dept_type, d.order_num, d.leader, d.phone, d.email, d.status,
  59. (select dept_name from ms_sys_dept where dept_id = d.parent_id) parent_name
  60. from ms_sys_dept d
  61. where d.dept_id = #{deptId}
  62. </select>
  63. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  64. select count(1) from ms_sys_user where dept_id = #{deptId} and del_flag = '0'
  65. </select>
  66. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  67. select count(1) from ms_sys_dept
  68. where del_flag = '0' and parent_id = #{deptId} limit 1
  69. </select>
  70. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  71. select * from ms_sys_dept where find_in_set(#{deptId}, ancestors)
  72. </select>
  73. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  74. select count(*) from ms_sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  75. </select>
  76. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  77. <include refid="selectDeptVo"/>
  78. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  79. </select>
  80. <select id="selectUserDeptListByRoleId" resultType="java.lang.Long">
  81. select u.dept_id from ms_sys_user_role r
  82. join ms_sys_user u on r.role_id=#{roleId} and r.user_id=u.user_id
  83. </select>
  84. <insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyColumn="dept_id" keyProperty="deptId">
  85. insert into ms_sys_dept(
  86. <if test="deptId != null and deptId != 0">dept_id,</if>
  87. <if test="parentId != null and parentId != 0">parent_id,</if>
  88. <if test="deptName != null and deptName != ''">dept_name,</if>
  89. <if test="deptType != null">dept_type,</if>
  90. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  91. <if test="orderNum != null">order_num,</if>
  92. <if test="leader != null and leader != ''">leader,</if>
  93. <if test="phone != null and phone != ''">phone,</if>
  94. <if test="email != null and email != ''">email,</if>
  95. <if test="status != null">status,</if>
  96. <if test="createBy != null and createBy != ''">create_by,</if>
  97. create_time
  98. )values(
  99. <if test="deptId != null and deptId != 0">#{deptId},</if>
  100. <if test="parentId != null and parentId != 0">#{parentId},</if>
  101. <if test="deptName != null and deptName != ''">#{deptName},</if>
  102. <if test="deptType != null">#{deptType},</if>
  103. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  104. <if test="orderNum != null">#{orderNum},</if>
  105. <if test="leader != null and leader != ''">#{leader},</if>
  106. <if test="phone != null and phone != ''">#{phone},</if>
  107. <if test="email != null and email != ''">#{email},</if>
  108. <if test="status != null">#{status},</if>
  109. <if test="createBy != null and createBy != ''">#{createBy},</if>
  110. sysdate()
  111. );
  112. </insert>
  113. <insert id="batchSave">
  114. insert into ms_sys_dept(
  115. dept_id,
  116. parent_id,
  117. dept_name,
  118. dept_type,
  119. ancestors,
  120. order_num,
  121. leader,
  122. phone,
  123. email,
  124. status,
  125. create_by,
  126. create_time
  127. )values
  128. <foreach item="item" index="index" collection="list" separator=",">
  129. (
  130. #{item.deptId},
  131. #{item.parentId},
  132. #{item.deptName},
  133. #{item.deptType},
  134. #{item.ancestors},
  135. #{item.orderNum},
  136. #{item.leader},
  137. #{item.phone},
  138. #{item.email},
  139. #{item.status},
  140. #{item.createBy},
  141. sysdate()
  142. )
  143. </foreach>;
  144. </insert>
  145. <update id="updateDept" parameterType="SysDept">
  146. update ms_sys_dept
  147. <set>
  148. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  149. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  150. <if test="deptType != null">dept_type = #{deptType},</if>
  151. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  152. <if test="orderNum != null">order_num = #{orderNum},</if>
  153. <if test="leader != null">leader = #{leader},</if>
  154. <if test="phone != null">phone = #{phone},</if>
  155. <if test="email != null">email = #{email},</if>
  156. <if test="status != null and status != ''">status = #{status},</if>
  157. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  158. update_time = sysdate()
  159. </set>
  160. where dept_id = #{deptId}
  161. </update>
  162. <update id="updateDeptChildren" parameterType="java.util.List">
  163. update ms_sys_dept set ancestors =
  164. <foreach collection="depts" item="item" index="index"
  165. separator=" " open="case dept_id" close="end">
  166. when #{item.deptId} then #{item.ancestors}
  167. </foreach>
  168. where dept_id in
  169. <foreach collection="depts" item="item" index="index"
  170. separator="," open="(" close=")">
  171. #{item.deptId}
  172. </foreach>
  173. </update>
  174. <update id="updateDeptStatusNormal" parameterType="Long">
  175. update ms_sys_dept set status = '0' where dept_id in
  176. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  177. #{deptId}
  178. </foreach>
  179. </update>
  180. <delete id="deleteDeptById" parameterType="Long">
  181. update ms_sys_dept set del_flag = '2' where dept_id = #{deptId}
  182. </delete>
  183. </mapper>