DeptMapper.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="org.springblade.system.mapper.DeptMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="deptResultMap" type="org.springblade.system.entity.Dept">
  6. <id column="id" property="id"/>
  7. <result column="parent_id" property="parentId"/>
  8. <result column="dept_name" property="deptName"/>
  9. <result column="full_name" property="fullName"/>
  10. <result column="ancestors" property="ancestors"/>
  11. <result column="dept_category" property="deptCategory"/>
  12. <result column="sort" property="sort"/>
  13. <result column="remark" property="remark"/>
  14. <result column="is_deleted" property="isDeleted"/>
  15. <result column="dept_type" property="deptType"/>
  16. </resultMap>
  17. <resultMap id="deptVOResultMap" type="org.springblade.system.vo.DeptVO">
  18. <id column="id" property="id"/>
  19. <result column="parent_id" property="parentId"/>
  20. <result column="dept_name" property="deptName"/>
  21. <result column="full_name" property="fullName"/>
  22. <result column="ancestors" property="ancestors"/>
  23. <result column="dept_category" property="deptCategory"/>
  24. <result column="sort" property="sort"/>
  25. <result column="remark" property="remark"/>
  26. <result column="is_deleted" property="isDeleted"/>
  27. <result column="dept_type" property="deptType"/>
  28. <result column="has_children" property="hasChildren"/>
  29. <result column="minLevel" property="minLevel"/>
  30. </resultMap>
  31. <resultMap id="treeNodeResultMap" type="org.springblade.manager.vo.TreeNodeVO">
  32. <id column="id" property="id"/>
  33. <result column="parent_id" property="parentId"/>
  34. <result column="title" property="title"/>
  35. <result column="value" property="value"/>
  36. <result column="key" property="key"/>
  37. <result column="deptName" property="deptName"/>
  38. <result column="fullName" property="fullName"/>
  39. <result column="has_children" property="hasChildren"/>
  40. <result column="type" property="type"/>
  41. <result column="deptType" property="deptType"/>
  42. <result column="tenantId" property="tenantId"/>
  43. </resultMap>
  44. <select id="lazyList" resultMap="deptVOResultMap">
  45. SELECT
  46. dept.* ,
  47. (
  48. SELECT
  49. CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
  50. FROM
  51. blade_dept
  52. WHERE
  53. parent_id = dept.id and is_deleted = 0
  54. ) AS "has_children"
  55. FROM
  56. blade_dept dept
  57. WHERE dept.is_deleted = 0
  58. <if test="param1!=null and param1!=''">
  59. and dept.tenant_id = #{param1}
  60. </if>
  61. <if test="param2!=null">
  62. and dept.parent_id = #{param2}
  63. </if>
  64. <if test="param3.deptName!=null and param3.deptName!=''">
  65. and dept.dept_name like concat(concat('%', #{param3.deptName}),'%')
  66. </if>
  67. <if test="param3.fullName!=null and param3.fullName!=''">
  68. and dept.full_name like concat(concat('%', #{param3.fullName}),'%')
  69. </if>
  70. ORDER BY dept.sort
  71. </select>
  72. <select id="tree" resultMap="treeNodeResultMap">
  73. select id, parent_id,dept_name as deptName,full_name as fullName, dept_name as title, id as "value", id as
  74. "key",dept_type as type,dept_type as deptType from blade_dept where is_deleted = 0
  75. <if test="_parameter!=null and _parameter!=''">
  76. and tenant_id = #{_parameter}
  77. </if>
  78. ORDER BY sort
  79. </select>
  80. <select id="lazyTree" resultMap="treeNodeResultMap">
  81. SELECT
  82. dept.id,
  83. dept.parent_id,
  84. dept.dept_name AS title,
  85. dept.id AS "value",
  86. dept.id AS "key",
  87. dept.tenant_id AS "tenantId",
  88. (
  89. SELECT
  90. CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
  91. FROM
  92. blade_dept
  93. WHERE
  94. parent_id = dept.id and is_deleted = 0
  95. ) AS "has_children"
  96. FROM
  97. blade_dept dept
  98. WHERE
  99. dept.parent_id = #{param2} AND dept.is_deleted = 0
  100. <if test="param1!=null and param1!=''">
  101. and dept.tenant_id = #{param1}
  102. </if>
  103. ORDER BY dept.sort
  104. </select>
  105. <select id="getDeptNames" resultType="java.lang.String">
  106. SELECT
  107. dept_name
  108. FROM
  109. blade_dept
  110. WHERE
  111. id IN
  112. <foreach collection="array" item="ids" index="index" open="(" close=")" separator=",">
  113. #{ids}
  114. </foreach>
  115. and is_deleted = 0
  116. </select>
  117. <select id="getUserDeptTreeInfo" resultMap="treeNodeResultMap">
  118. select id, parent_id,dept_name as deptName, dept_name as title, id as "value", id as "key" from blade_view_postuser where 1=1
  119. <if test="param1!=null and param1!=''">
  120. and tenant_id = #{param1}
  121. </if>
  122. <if test="param2!=null and param2!=''">
  123. and dept_type = #{param2}
  124. </if>
  125. --ORDER BY sort
  126. </select>
  127. <select id="listAllByType" resultMap="deptVOResultMap">
  128. select *,
  129. (
  130. SELECT
  131. CASE WHEN count(1) > 0 THEN 0 ELSE 1 END
  132. FROM
  133. blade_view_postuser
  134. WHERE
  135. parent_id = a.id
  136. and tenant_id = #{param1}
  137. and dept_type = #{param2}
  138. ) AS "minLevel"
  139. from blade_view_postuser a where 1=1
  140. <if test="param1!=null and param1!='' and param1!='null'">
  141. and tenant_id = #{param1}
  142. </if>
  143. <if test="param2!=null and param2!='' and param2!='null'">
  144. and dept_type = #{param2}
  145. </if>
  146. <if test="param3!=null and param3!='' and param3!='null' ">
  147. and parent_id = #{param3}
  148. </if>
  149. --ORDER BY sort
  150. </select>
  151. </mapper>