SysDeptMapper.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.yijia.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="jiBie" column="ji_bie" />
  23. <result property="deptAddress" column="dept_address" />
  24. <result property="oilGunNum" column="oil_gun_num" />
  25. <result property="stationPic" column="station_pic" />
  26. <result property="stationLongitude" column="station_longitude" />
  27. <result property="stationLatitude" column="station_latitude" />
  28. <result property="mno" column="mno" />
  29. <result property="appId" column="app_id" />
  30. <result property="appSecret" column="app_secret" />
  31. </resultMap>
  32. <sql id="selectDeptVo">
  33. 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.ji_bie, d.dept_address, d.oil_gun_num, d.station_pic, d.station_longitude, d.station_latitude, d.mno, d.app_id, d.app_secret
  34. from sys_dept d
  35. </sql>
  36. <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
  37. <include refid="selectDeptVo"/>
  38. where d.del_flag = '0'
  39. <if test="jiBie != null">
  40. AND ji_bie = #{jiBie}
  41. </if>
  42. <if test="parentId != null and parentId != 0">
  43. AND parent_id = #{parentId}
  44. </if>
  45. <if test="deptName != null and deptName != ''">
  46. AND dept_name like concat('%', #{deptName}, '%')
  47. </if>
  48. <if test="status != null and status != ''">
  49. AND status = #{status}
  50. </if>
  51. <!-- 数据范围过滤 -->
  52. ${params.dataScope}
  53. order by d.parent_id, d.order_num
  54. </select>
  55. <select id="selectDeptListByRoleId" resultType="Integer">
  56. select d.dept_id
  57. from sys_dept d
  58. left join sys_role_dept rd on d.dept_id = rd.dept_id
  59. where rd.role_id = #{roleId}
  60. <if test="deptCheckStrictly">
  61. 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})
  62. </if>
  63. order by d.parent_id, d.order_num
  64. </select>
  65. <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
  66. <include refid="selectDeptVo"/>
  67. where dept_id = #{deptId}
  68. </select>
  69. <select id="checkDeptExistUser" parameterType="Long" resultType="int">
  70. select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
  71. </select>
  72. <select id="hasChildByDeptId" parameterType="Long" resultType="int">
  73. select count(1) from sys_dept
  74. where del_flag = '0' and parent_id = #{deptId} limit 1
  75. </select>
  76. <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
  77. select * from sys_dept where find_in_set(#{deptId}, ancestors)
  78. </select>
  79. <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
  80. select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
  81. </select>
  82. <select id="checkDeptNameUnique" resultMap="SysDeptResult">
  83. <include refid="selectDeptVo"/>
  84. where dept_name=#{deptName} and parent_id = #{parentId} limit 1
  85. </select>
  86. <!--调用存储过程-->
  87. <select id="selectDeptListTree" statementType="CALLABLE" useCache="false">
  88. {call deptinfo()};
  89. </select>
  90. <insert id="insertDept" parameterType="SysDept">
  91. insert into sys_dept(
  92. <if test="deptId != null and deptId != 0">dept_id,</if>
  93. <if test="parentId != null and parentId != 0">parent_id,</if>
  94. <if test="deptName != null and deptName != ''">dept_name,</if>
  95. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  96. <if test="orderNum != null and orderNum != ''">order_num,</if>
  97. <if test="leader != null and leader != ''">leader,</if>
  98. <if test="phone != null and phone != ''">phone,</if>
  99. <if test="email != null and email != ''">email,</if>
  100. <if test="status != null">status,</if>
  101. <if test="createBy != null and createBy != ''">create_by,</if>
  102. <if test="jiBie != null">ji_bie,</if>
  103. <if test="deptAddress != null">dept_address,</if>
  104. <if test="oilGunNum != null">oil_gun_num,</if>
  105. <if test="stationPic != null">station_pic,</if>
  106. <if test="stationLongitude!= null">station_longitude,</if>
  107. <if test="stationLatitude != null">station_latitude,</if>
  108. <if test="mno != null">mno,</if>
  109. <if test="appId != null">app_id,</if>
  110. <if test="appSecret != null">app_secret,</if>
  111. create_time
  112. )values(
  113. <if test="deptId != null and deptId != 0">#{deptId},</if>
  114. <if test="parentId != null and parentId != 0">#{parentId},</if>
  115. <if test="deptName != null and deptName != ''">#{deptName},</if>
  116. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  117. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  118. <if test="leader != null and leader != ''">#{leader},</if>
  119. <if test="phone != null and phone != ''">#{phone},</if>
  120. <if test="email != null and email != ''">#{email},</if>
  121. <if test="status != null">#{status},</if>
  122. <if test="createBy != null and createBy != ''">#{createBy},</if>
  123. <if test="jiBie != null">#{jiBie},</if>
  124. <if test="deptAddress != null">#{deptAddress},</if>
  125. <if test="oilGunNum != null">#{oilGunNum},</if>
  126. <if test="stationPic != null">#{stationPic},</if>
  127. <if test="stationLongitude!= null">#{stationLongitude},</if>
  128. <if test="stationLatitude != null">#{stationLatitude},</if>
  129. <if test="mno != null">#{mno},</if>
  130. <if test="appId != null">#{appId},</if>
  131. <if test="appSecret != null">#{appSecret},</if>
  132. sysdate()
  133. )
  134. </insert>
  135. <update id="updateDept" parameterType="SysDept">
  136. update sys_dept
  137. <set>
  138. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  139. <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
  140. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  141. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  142. <if test="leader != null">leader = #{leader},</if>
  143. <if test="phone != null">phone = #{phone},</if>
  144. <if test="email != null">email = #{email},</if>
  145. <if test="status != null and status != ''">status = #{status},</if>
  146. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  147. <if test="jiBie != null">ji_bie = #{jiBie},</if>
  148. <if test="deptAddress!= null">dept_address = #{deptAddress},</if>
  149. <if test="oilGunNum != null">oil_gun_num = #{oilGunNum},</if>
  150. <if test="stationPic != null">station_pic = #{stationPic},</if>
  151. <if test="stationLongitude!= null">station_longitude = #{stationLongitude},</if>
  152. <if test="stationLatitude != null">station_latitude = #{stationLatitude},</if>
  153. <if test="mno != null">mno = #{mno},</if>
  154. <if test="appId != null">app_id = #{appId},</if>
  155. <if test="appSecret != null">app_secret = #{appSecret},</if>
  156. update_time = sysdate()
  157. </set>
  158. where dept_id = #{deptId}
  159. </update>
  160. <update id="updateDeptChildren" parameterType="java.util.List">
  161. update sys_dept set ancestors =
  162. <foreach collection="depts" item="item" index="index"
  163. separator=" " open="case dept_id" close="end">
  164. when #{item.deptId} then #{item.ancestors}
  165. </foreach>
  166. where dept_id in
  167. <foreach collection="depts" item="item" index="index"
  168. separator="," open="(" close=")">
  169. #{item.deptId}
  170. </foreach>
  171. </update>
  172. <update id="updateDeptStatus" parameterType="SysDept">
  173. update sys_dept
  174. <set>
  175. <if test="status != null and status != ''">status = #{status},</if>
  176. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  177. update_time = sysdate()
  178. </set>
  179. where dept_id in (${ancestors})
  180. </update>
  181. <delete id="deleteDeptById" parameterType="Long">
  182. update sys_dept set del_flag = '2' where dept_id = #{deptId}
  183. </delete>
  184. </mapper>