SysDeptMapper.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.ydtech.modules.admin.dao.SysDeptMapper">
  6. <resultMap id="BaseResultMap" type="com.ydtech.modules.admin.model.SysDept">
  7. <id property="id" column="id" jdbcType="VARCHAR"/>
  8. <result property="name" column="name" jdbcType="VARCHAR"/>
  9. <result property="parentId" column="parent_id" jdbcType="VARCHAR"/>
  10. <result property="orderNum" column="order_num" jdbcType="INTEGER"/>
  11. <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
  12. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  13. <result property="lastUpdateBy" column="last_update_by" jdbcType="VARCHAR"/>
  14. <result property="lastUpdateTime" column="last_update_time" jdbcType="TIMESTAMP"/>
  15. <result property="delFlag" column="del_flag" jdbcType="TINYINT"/>
  16. <result property="comtype" column="comtype" jdbcType="VARCHAR"/>
  17. <result property="comlevel" column="comlevel" jdbcType="VARCHAR"/>
  18. <result property="address" column="address" jdbcType="VARCHAR"/>
  19. <result property="leadername" column="leadername" jdbcType="VARCHAR"/>
  20. <result property="leaderphone" column="leaderphone" jdbcType="VARCHAR"/>
  21. <result property="comattribute" column="comattribute" jdbcType="VARCHAR"/>
  22. <result property="isstop" column="isstop" jdbcType="VARCHAR"/>
  23. <result property="deptCode" column="dept_code" jdbcType="VARCHAR"/>
  24. <result property="province" column="province" jdbcType="VARCHAR"/>
  25. <result property="city" column="city" jdbcType="VARCHAR"/>
  26. <result property="area" column="area" jdbcType="VARCHAR"/>
  27. <result property="house" column="house" jdbcType="VARCHAR"/>
  28. <result property="deptType" column="dept_type" jdbcType="VARCHAR"/>
  29. <result property="leaderId" column="leader_id" jdbcType="VARCHAR"/>
  30. </resultMap>
  31. <sql id="Base_Column_List">
  32. id,name,parent_id,
  33. order_num,create_by,create_time,
  34. last_update_by,last_update_time,del_flag,
  35. comtype,comlevel,address,
  36. leadername,leaderphone,comattribute,
  37. isstop,dept_code,province,
  38. city,area,house,
  39. dept_type,management_fee,leader_id
  40. </sql>
  41. <select id="getMaxId" resultType="java.lang.String">
  42. SELECT IFNULL(MAX(id), 0) maxid
  43. FROM `sys_dept`
  44. WHERE parent_id = #{deptId}
  45. <if test='comlevel != null and comlevel != ""'>
  46. and comlevel = #{comlevel}
  47. </if>
  48. <!-- <if test='deptType != null and deptType != ""'>-->
  49. <!-- and id NOT LIKE '%M%'-->
  50. <!-- </if>-->
  51. </select>
  52. <select id="queryListByParentId" resultType="com.ydtech.modules.admin.model.SysDept">
  53. SELECT
  54. dept.*
  55. FROM
  56. sys_dept dept
  57. WHERE
  58. dept.del_flag = 0
  59. <if test="level == 0">
  60. AND dept.parent_id = #{parentId}
  61. </if>
  62. <if test='level == "1"'>
  63. AND dept.province IN ( SELECT area_code FROM sys_area WHERE LEVEL = 1 )
  64. AND LENGTH(
  65. IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
  66. IFNULL( dept.area, '' ))=6
  67. AND dept.parent_id = #{parentId}
  68. </if>
  69. <if test='level == "2"'>
  70. AND dept.city IN ( SELECT area_code FROM sys_area WHERE LEVEL = 2 )
  71. AND LENGTH(
  72. IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
  73. IFNULL( dept.area, '' ))= 12
  74. AND dept.parent_id = #{parentId}
  75. </if>
  76. <if test='level == "3"'>
  77. AND dept.area IN ( SELECT area_code FROM sys_area WHERE LEVEL = 3)
  78. AND LENGTH(
  79. IFNULL( dept.province, '' )) + LENGTH( IFNULL( dept.city, '' ) ) + LENGTH(
  80. IFNULL( dept.area, '' ))= 18
  81. AND dept.parent_id = #{parentId}
  82. </if>
  83. <if test='level == "4"'>
  84. AND dept.parent_id = #{parentId}
  85. </if>
  86. </select>
  87. <select id="queryListByQXDept" resultType="com.ydtech.modules.admin.model.SysDept">
  88. SELECT sd.id as id,
  89. sd.name as name,
  90. sd.parent_id as parentId,
  91. sd.comlevel as comlevel,
  92. false as flag
  93. FROM sys_dept sd
  94. WHERE (sd.comlevel = 3)
  95. OR (sd.comlevel = 4)
  96. OR (sd.comlevel > 4 AND sd.id LIKE '%M%')
  97. OR (sd.comlevel > 4 AND sd.id LIKE '%D%')
  98. OR (sd.id LIKE '%M%')
  99. ORDER BY comlevel
  100. </select>
  101. <select id="queryHXDeptTree" resultType="com.ydtech.modules.admin.model.SysDept">
  102. SELECT sd.id AS id,
  103. sd.NAME AS NAME,
  104. sd.parent_id AS parentId,
  105. sd.comlevel AS comlevel,
  106. FALSE AS flag
  107. FROM sys_dept sd
  108. WHERE (sd.comlevel &lt; 4)
  109. OR (sd.id LIKE '%D%' AND sd.id NOT LIKE '%M%')
  110. ORDER BY id
  111. </select>
  112. <select id="getByOrderNoQueryManagementSource" resultType="java.lang.String">
  113. SELECT management_source
  114. FROM sys_dept
  115. WHERE id = (SELECT deptid
  116. FROM ins_orders
  117. WHERE orderno = #{orderNo})
  118. </select>
  119. <select id="getListByIds" resultType="com.ydtech.modules.admin.model.SysDept">
  120. SELECT sd.id AS id,
  121. sd.NAME AS NAME,
  122. sd.parent_id AS parentId,
  123. sd.comlevel AS comlevel,
  124. sd.management_source as managementSource
  125. FROM sys_dept sd
  126. <where>
  127. <if test="ids!=null and ids !='' and ids.size()>0">
  128. sd.id in
  129. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  130. #{item}
  131. </foreach>
  132. </if>
  133. </where>
  134. </select>
  135. <select id="getFiveLevelDept" resultType="com.ydtech.modules.admin.model.SysDept">
  136. select * from
  137. sys_dept sd
  138. <where>
  139. sd.del_flag ='0'
  140. AND sd.id LIKE concat('%','9','%')
  141. AND sd.comlevel is not null
  142. <if test="vo.deptIds !=null and vo.deptIds!='' and vo.deptIds.size()>0">
  143. AND sd.id in
  144. <foreach collection="vo.deptIds" item="item" open="(" close=")" separator=",">
  145. #{item}
  146. </foreach>
  147. </if>
  148. <if test="vo.managementSource !=null and vo.managementSource!='' ">
  149. AND sd.management_source =#{vo.managementSource}
  150. </if>
  151. </where>
  152. </select>
  153. <select id="queryFiveLevelDept" resultType="com.ydtech.modules.admin.model.SysDept">
  154. select * from
  155. sys_dept sd
  156. <where>
  157. sd.del_flag ='0'
  158. AND sd.id LIKE concat('%','9','%')
  159. AND sd.comlevel is not null
  160. <if test="vo.deptIds !=null and vo.deptIds!='' and vo.deptIds.size()>0">
  161. AND sd.id in
  162. <foreach collection="vo.deptIds" item="item" open="(" close=")" separator=",">
  163. #{item}
  164. </foreach>
  165. </if>
  166. </where>
  167. </select>
  168. <select id="getListByIdsByKzt" resultType="com.ydtech.modules.admin.model.SysDept">
  169. SELECT sd.id AS id,
  170. sd.NAME AS NAME,
  171. sd.parent_id AS parentId,
  172. sd.comlevel AS comlevel
  173. FROM sys_dept sd
  174. <where>
  175. (sd.management_source != '1' or sd.management_source is null)
  176. <if test="ids!=null and ids !='' and ids.size()>0">
  177. and sd.id in
  178. <foreach collection="ids" item="item" open="(" close=")" separator=",">
  179. #{item}
  180. </foreach>
  181. </if>
  182. </where>
  183. </select>
  184. <select id="selectMaxId" resultType="java.lang.String">
  185. SELECT id FROM sys_dept WHERE parent_id = #{parentId} and comlevel = #{comlevel}
  186. ORDER BY CAST(SUBSTRING_INDEX(id, 'M', 1) AS UNSIGNED) DESC, CAST(SUBSTRING_INDEX(id, 'M', -1) AS UNSIGNED) DESC LIMIT 1
  187. </select>
  188. </mapper>