SysDeptMapper.xml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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="com.qunzhixinxi.hnqz.report.mapper.SysDeptMapper">
  4. <resultMap id="sysDeptMap" type="com.qunzhixinxi.hnqz.admin.api.entity.SysDept">
  5. <id property="deptId" column="dept_id"/>
  6. <result property="name" column="name"/>
  7. <result property="sort" column="sort"/>
  8. <result property="createTime" column="create_time"/>
  9. <result property="updateTime" column="update_time"/>
  10. <result property="delFlag" column="del_flag"/>
  11. <result property="parentId" column="parent_id"/>
  12. <result property="tenantId" column="tenant_id"/>
  13. <result property="deptCode" column="dept_code"/>
  14. <result property="level" column="level"/>
  15. <result property="level1Name" column="level1_name"/>
  16. <result property="level1Id" column="level1_id"/>
  17. <result property="level2Name" column="level2_name"/>
  18. <result property="level2Id" column="level2_id"/>
  19. <result property="level3Name" column="level3_name"/>
  20. <result property="level3Id" column="level3_id"/>
  21. <result property="taxCode" column="tax_code"/>
  22. </resultMap>
  23. <select id="selectDistinctDeptId" resultMap="sysDeptMap">
  24. select
  25. DISTINCT dept_id,
  26. level
  27. from
  28. sys_dept
  29. where
  30. dept_id = #{query.deptId,jdbcType=INTEGER}
  31. order by level
  32. limit 1
  33. </select>
  34. <select id="selectDeptList" resultMap="sysDeptMap">
  35. select
  36. dept_id,
  37. sort,
  38. name
  39. from
  40. sys_dept
  41. </select>
  42. <select id="selectDeptByIds" resultMap="sysDeptMap">
  43. select
  44. *
  45. from
  46. sys_dept
  47. where
  48. dept_id = #{query.deptId,jdbcType=INTEGER}
  49. </select>
  50. <select id="selectDeptByName" resultMap="sysDeptMap">
  51. select
  52. dept_id,name
  53. from
  54. sys_dept
  55. where
  56. dept_id = #{query.deptId,jdbcType=INTEGER}
  57. </select>
  58. <select id="selectDept" resultMap="sysDeptMap">
  59. select
  60. *
  61. from
  62. sys_dept
  63. where
  64. dept_id = #{deptId,jdbcType=INTEGER}
  65. </select>
  66. <select id="selectListByDept" resultMap="sysDeptMap">
  67. select
  68. dept_id,
  69. name
  70. from
  71. sys_dept
  72. where del_flag = 0
  73. </select>
  74. <select id="selectDeptById" resultType="java.util.HashMap">
  75. SELECT
  76. d.dept_id as deptId,d.name,d.level,
  77. CASE WHEN a.zj_number IS NULL THEN e.entcode ELSE a.zj_number END entcode
  78. FROM
  79. sys_dept d
  80. LEFT JOIN wm_da_agent a ON d.dept_id = a.dept_id
  81. LEFT JOIN wm_da_drug_ent e ON d.dept_id = e.dept_id
  82. WHERE
  83. d.dept_id = #{query.deptId,jdbcType=INTEGER}
  84. </select>
  85. <select id="getAllParentDept" resultMap="sysDeptMap">
  86. select DISTINCT
  87. dept_id,
  88. `name`,
  89. `level`
  90. from sys_dept
  91. where dept_id IN
  92. (select d.dept_id from sys_dept d
  93. where d.dept_id=#{query.deptId}
  94. union
  95. select r.up_id from sys_dept d
  96. left join wm_relation r on d.dept_id=r.down_id
  97. where d.dept_id=#{query.deptId}
  98. union
  99. select r2.up_id from sys_dept d
  100. left join wm_relation r on d.dept_id=r.down_id
  101. left join wm_relation r2 on r.up_id=r2.down_id
  102. where d.dept_id=#{query.deptId}
  103. )
  104. and del_flag=0
  105. AND dept_id NOT in(1)
  106. </select>
  107. <select id="selectByName" resultMap="sysDeptMap">
  108. select
  109. *
  110. from
  111. sys_dept
  112. where
  113. name = #{name,jdbcType=VARCHAR}
  114. </select>
  115. <select id="selectEntCodeByLevelId" resultType="string">
  116. <choose>
  117. <when test="level = 1">
  118. SELECT `entcode` FROM `wm_da_drug_ent`
  119. </when>
  120. <otherwise>
  121. SELECT `zj_number` FROM `wm_da_agent`
  122. </otherwise>
  123. </choose>
  124. WHERE `id` = #{levelId}
  125. </select>
  126. <update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.api.entity.SysDept" >
  127. update sys_dept
  128. <set >
  129. <if test="delFlag != null" >
  130. del_flag = #{delFlag,jdbcType=VARCHAR},
  131. </if>
  132. <if test="name != null" >
  133. name = #{name,jdbcType=VARCHAR},
  134. </if>
  135. <if test="subjectType != null" >
  136. subject_type = #{subjectType,jdbcType=VARCHAR},
  137. </if>
  138. <if test="taxCode != null" >
  139. tax_code = #{taxCode,jdbcType=VARCHAR},
  140. </if>
  141. <if test="deptPermissions != null and deptPermissions != ''">
  142. dept_permissions = #{deptPermissions, jdbcType=VARCHAR}
  143. </if>
  144. </set>
  145. where dept_id = #{deptId,jdbcType=BIGINT}
  146. </update>
  147. <select id="getParentDept" resultType="map">
  148. select DISTINCT
  149. dept_id deptId,
  150. `name`
  151. from sys_dept
  152. where dept_id IN
  153. (
  154. select r.up_id from sys_dept d
  155. left join wm_relation r on d.dept_id=r.down_id
  156. where d.dept_id=#{query.deptId}
  157. union
  158. select r2.up_id from sys_dept d
  159. left join wm_relation r on d.dept_id=r.down_id
  160. left join wm_relation r2 on r.up_id=r2.down_id
  161. where d.dept_id=#{query.deptId}
  162. )
  163. and del_flag=0
  164. AND dept_id NOT in(1)
  165. </select>
  166. <select id="getChildDept" resultType="map">
  167. select DISTINCT
  168. dept_id deptId,
  169. `name`
  170. from sys_dept
  171. where dept_id IN
  172. (
  173. select r.down_id from sys_dept d
  174. left join wm_relation r on d.dept_id=r.up_id
  175. where d.dept_id=#{query.deptId}
  176. union
  177. select r2.down_id from sys_dept d
  178. left join wm_relation r on d.dept_id=r.up_id
  179. left join wm_relation r2 on r.down_id=r2.up_id
  180. where d.dept_id=#{query.deptId}
  181. )
  182. and del_flag=0
  183. AND dept_id NOT in(1)
  184. </select>
  185. <select id="getDeptConvertToName" resultType="map">
  186. select dept_id deptId, `name` from sys_dept
  187. </select>
  188. </mapper>