调解系统后端服务

SysDeptMapper.xml 9.3KB

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