SysDeptMapper.xml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.ozs.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. </resultMap>
  23. <sql id="selectDeptVo">
  24. 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,d.remarks
  25. ,d.address,d.project_contact,d.bank_account_name,d.bank_of_deposit,d.account_number
  26. from 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 sys_dept d
  50. left join 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 sys_dept d inner join sys_role_dept rd on d.dept_id =
  54. rd.dept_id and rd.role_id = #{roleId})
  55. </if>
  56. order by d.parent_id, d.order_num
  57. </select>
  58. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  59. select d.dept_id,
  60. d.parent_id,
  61. d.ancestors,
  62. d.dept_name,
  63. d.order_num,
  64. d.leader,
  65. d.phone,
  66. d.email,
  67. d.status,
  68. d.remarks,
  69. d.address
  70. ,
  71. d.project_contact,
  72. d.bank_account_name,
  73. d.bank_of_deposit,
  74. d.account_number,
  75. d.purchase_services,
  76. (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
  77. from sys_dept d
  78. where d.dept_id = #{deptId}
  79. </select>
  80. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  81. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  82. </select>
  83. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  84. select count(1) from sys_dept
  85. where del_flag = '0' and parent_id = #{deptId} limit 1
  86. </select>
  87. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  88. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  89. </select>
  90. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  91. select count(*)
  92. from sys_dept
  93. where status = 0
  94. and del_flag = '0'
  95. and find_in_set(#{deptId}, ancestors)
  96. </select>
  97. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  98. <include refid="selectDeptVo"/>
  99. where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
  100. </select>
  101. <select id="checkDeptNameOnlyOne" resultType="com.ozs.common.core.domain.entity.SysDept"
  102. parameterType="java.lang.String">
  103. select dept_id
  104. from sys_dept
  105. where dept_name = #{deptName}
  106. </select>
  107. <insert id="insertDept" parameterType="SysDept">
  108. insert into sys_dept(
  109. <if test="deptId != null and deptId != 0">dept_id,</if>
  110. <if test="parentId != null and parentId != 0">parent_id,</if>
  111. <if test="deptName != null and deptName != ''">dept_name,</if>
  112. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  113. <if test="orderNum != null">order_num,</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="address != null and address != ''">address,</if>
  118. <if test="purchaseServices != null and purchaseServices != ''">purchase_services,</if>
  119. <if test="remarks != null and remarks != ''">remarks,</if>
  120. <if test="projectContact != null and projectContact != ''">project_contact,</if>
  121. <if test="bankAccountName != null and bankAccountName != ''">bank_account_name,</if>
  122. <if test="bankOfDeposit != null and bankOfDeposit != ''">bank_of_deposit,</if>
  123. <if test="accountNumber != null and accountNumber != ''">account_number,</if>
  124. <if test="status != null">status,</if>
  125. <if test="createBy != null and createBy != ''">create_by,</if>
  126. create_time
  127. )values(
  128. <if test="deptId != null and deptId != 0">#{deptId},</if>
  129. <if test="parentId != null and parentId != 0">#{parentId},</if>
  130. <if test="deptName != null and deptName != ''">#{deptName},</if>
  131. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  132. <if test="orderNum != null">#{orderNum},</if>
  133. <if test="leader != null and leader != ''">#{leader},</if>
  134. <if test="phone != null and phone != ''">#{phone},</if>
  135. <if test="email != null and email != ''">#{email},</if>
  136. <if test="purchaseServices != null and purchaseServices != ''">#{purchaseServices},</if>
  137. <if test="address != null and address != ''">#{address},</if>
  138. <if test="remarks != null and remarks != ''">#{remarks},</if>
  139. <if test="projectContact != null and projectContact != ''">#{projectContact},</if>
  140. <if test="bankAccountName != null and bankAccountName != ''">#{bankAccountName},</if>
  141. <if test="bankOfDeposit != null and bankOfDeposit != ''">#{bankOfDeposit},</if>
  142. <if test="accountNumber != null and accountNumber != ''">#{accountNumber},</if>
  143. <if test="status != null">#{status},</if>
  144. <if test="createBy != null and createBy != ''">#{createBy},</if>
  145. sysdate()
  146. )
  147. </insert>
  148. <update id="updateDept" parameterType="SysDept">
  149. update sys_dept
  150. <set>
  151. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  152. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  153. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  154. <if test="address != null and address != ''">address = #{address},</if>
  155. <if test="remarks != null and remarks != ''">remarks = #{remarks},</if>
  156. <if test="purchaseServices != null and purchaseServices != ''">purchase_services = #{purchaseServices},</if>
  157. <if test="projectContact != null and projectContact != ''">project_contact = #{projectContact},</if>
  158. <if test="bankAccountName != null and bankAccountName != ''">bank_account_name = #{bankAccountName},</if>
  159. <if test="bankOfDeposit != null and bankOfDeposit != ''">bank_of_deposit = #{bankOfDeposit},</if>
  160. <if test="accountNumber != null and accountNumber != ''">account_number = #{accountNumber},</if>
  161. <if test="orderNum != null">order_num = #{orderNum},</if>
  162. <if test="leader != null">leader = #{leader},</if>
  163. <if test="phone != null">phone = #{phone},</if>
  164. <if test="email != null">email = #{email},</if>
  165. <if test="status != null and status != ''">status = #{status},</if>
  166. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  167. update_time = sysdate()
  168. </set>
  169. where dept_id = #{deptId}
  170. </update>
  171. <update id="updateDeptChildren" parameterType="java.util.List">
  172. update sys_dept set ancestors =
  173. <foreach collection="depts" item="item" index="index"
  174. separator=" " open="case dept_id" close="end">
  175. when #{item.deptId} then #{item.ancestors}
  176. </foreach>
  177. where dept_id in
  178. <foreach collection="depts" item="item" index="index"
  179. separator="," open="(" close=")">
  180. #{item.deptId}
  181. </foreach>
  182. </update>
  183. <update id="updateDeptStatusNormal" parameterType="Long">
  184. update sys_dept set status = '0' where dept_id in
  185. <foreach collection="array" item="deptId" open="(" separator="," close=")">
  186. #{deptId}
  187. </foreach>
  188. </update>
  189. <delete id="deleteDeptById" parameterType="Long">
  190. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  191. </delete>
  192. </mapper>