SysDeptMapper.xml 8.9 KB

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