DeptMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.project.system.dept.mapper.DeptMapper">
  6. <resultMap type="Dept" id="DeptResult">
  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="parentName" column="parent_name" />
  17. <result property="createBy" column="create_by" />
  18. <result property="createTime" column="create_time" />
  19. <result property="updateBy" column="update_by" />
  20. <result property="updateTime" column="update_time" />
  21. </resultMap>
  22. <sql id="selectDeptVo">
  23. select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status, t.create_by, t.create_time from sys_dept t
  24. </sql>
  25. <select id="selectDeptAll" resultMap="DeptResult">
  26. <include refid="selectDeptVo"/>
  27. </select>
  28. <select id="selectDeptList" parameterType="Dept" resultMap="DeptResult">
  29. <include refid="selectDeptVo"/>
  30. <where>
  31. <if test="parentId != null and parentId != 0">
  32. AND parent_id = #{parentId}
  33. </if>
  34. <if test="deptName != null and deptName != ''">
  35. AND dept_name like concat('%', #{deptName}, '%')
  36. </if>
  37. <if test="status != null and status != ''">
  38. AND status = #{status}
  39. </if>
  40. </where>
  41. </select>
  42. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  43. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  44. </select>
  45. <select id="selectDeptCount" parameterType="Dept" resultType="int">
  46. select count(1) from sys_dept
  47. <where>
  48. <if test="deptId != null and deptId != 0"> and dept_id = #{deptId} </if>
  49. <if test="parentId != null and parentId != 0"> and parent_id = #{parentId} </if>
  50. </where>
  51. </select>
  52. <select id="checkDeptNameUnique" parameterType="String" resultMap="DeptResult">
  53. <include refid="selectDeptVo"/>
  54. where dept_name=#{deptName}
  55. </select>
  56. <select id="selectDeptById" parameterType="Long" resultMap="DeptResult">
  57. select t.dept_id, t.parent_id, t.ancestors, t.dept_name, t.order_num, t.leader, t.phone, t.email, t.status,
  58. (select dept_name from sys_dept where dept_id = t.parent_id) parent_name
  59. from sys_dept t
  60. where dept_id = #{deptId}
  61. </select>
  62. <insert id="insertDept" parameterType="Dept">
  63. insert into sys_dept(
  64. <if test="deptId != null and deptId != 0">dept_id,</if>
  65. <if test="parentId != null and parentId != 0">parent_id,</if>
  66. <if test="deptName != null and deptName != ''">dept_name,</if>
  67. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  68. <if test="orderNum != null and orderNum != ''">order_num,</if>
  69. <if test="leader != null and leader != ''">leader,</if>
  70. <if test="phone != null and phone != ''">phone,</if>
  71. <if test="email != null and email != ''">email,</if>
  72. <if test="status != null">status,</if>
  73. <if test="createBy != null and createBy != ''">create_by,</if>
  74. create_time
  75. )values(
  76. <if test="deptId != null and deptId != 0">#{deptId},</if>
  77. <if test="parentId != null and parentId != 0">#{parentId},</if>
  78. <if test="deptName != null and deptName != ''">#{deptName},</if>
  79. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  80. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  81. <if test="leader != null and leader != ''">#{leader},</if>
  82. <if test="phone != null and phone != ''">#{phone},</if>
  83. <if test="email != null and email != ''">#{email},</if>
  84. <if test="status != null">#{status},</if>
  85. <if test="createBy != null and createBy != ''">#{createBy},</if>
  86. sysdate()
  87. )
  88. </insert>
  89. <update id="updateDept" parameterType="Dept">
  90. update sys_dept
  91. <set>
  92. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  93. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  94. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  95. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  96. <if test="leader != null and leader != ''">leader = #{leader},</if>
  97. <if test="phone != null and phone != ''">phone = #{phone},</if>
  98. <if test="email != null and email != ''">email = #{email},</if>
  99. <if test="status != null and status != ''">status = #{status},</if>
  100. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  101. update_time = sysdate()
  102. </set>
  103. where dept_id = #{deptId}
  104. </update>
  105. <update id="updateDeptChildren" parameterType="java.util.List">
  106. update sys_dept set ancestors =
  107. <foreach collection="depts" item="item" index="index"
  108. separator=" " open="case dept_id" close="end">
  109. when #{item.deptId} then #{item.ancestors}
  110. </foreach>
  111. where dept_id in
  112. <foreach collection="depts" item="item" index="index"
  113. separator="," open="(" close=")">
  114. #{item.deptId}
  115. </foreach>
  116. </update>
  117. <delete id="deleteDeptById" parameterType="Long">
  118. delete from sys_dept where dept_id = #{deptId}
  119. </delete>
  120. </mapper>