SysDeptMapper.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ~
  4. ~ Copyright (c) 2018-2025, hnqz All rights reserved.
  5. ~
  6. ~ Redistribution and use in source and binary forms, with or without
  7. ~ modification, are permitted provided that the following conditions are met:
  8. ~
  9. ~ Redistributions of source code must retain the above copyright notice,
  10. ~ this list of conditions and the following disclaimer.
  11. ~ Redistributions in binary form must reproduce the above copyright
  12. ~ notice, this list of conditions and the following disclaimer in the
  13. ~ documentation and/or other materials provided with the distribution.
  14. ~ Neither the name of the pig4cloud.com developer nor the names of its
  15. ~ contributors may be used to endorse or promote products derived from
  16. ~ this software without specific prior written permission.
  17. ~ Author: hnqz
  18. ~
  19. -->
  20. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  21. <mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.SysDeptMapper">
  22. <resultMap id="sysDeptMap" type="com.qunzhixinxi.hnqz.admin.api.entity.SysDept">
  23. <id property="deptId" column="dept_id"/>
  24. <result property="name" column="name"/>
  25. <result property="sort" column="sort"/>
  26. <result property="createTime" column="create_time"/>
  27. <result property="updateTime" column="update_time"/>
  28. <result property="delFlag" column="del_flag"/>
  29. <result property="parentId" column="parent_id"/>
  30. <result property="tenantId" column="tenant_id"/>
  31. <result property="deptCode" column="dept_code"/>
  32. <result property="level" column="level"/>
  33. <result property="level1Name" column="level1_name"/>
  34. <result property="level1Id" column="level1_id"/>
  35. <result property="level2Name" column="level2_name"/>
  36. <result property="level2Id" column="level2_id"/>
  37. <result property="level3Name" column="level3_name"/>
  38. <result property="level3Id" column="level3_id"/>
  39. <result property="appId" column="app_id"/>
  40. <result property="appSecret" column="app_secret"/>
  41. <result property="rsaPublicKey" column="rsa_public_key"/>
  42. <result property="queryUrl" column="query_url"/>
  43. <result property="subjectName" column="subject_name"/>
  44. <result property="subjectType" column="subject_type"/>
  45. <result property="taxCode" column="tax_code"/>
  46. </resultMap>
  47. <select id="selectDistinctDeptId" resultMap="sysDeptMap">
  48. select
  49. DISTINCT dept_id,
  50. level
  51. from
  52. sys_dept
  53. where
  54. dept_id = #{query.deptId,jdbcType=INTEGER}
  55. order by level
  56. limit 1
  57. </select>
  58. <select id="selectDeptList" resultMap="sysDeptMap">
  59. select
  60. dept_id,
  61. sort,
  62. name
  63. from
  64. sys_dept
  65. </select>
  66. <select id="selectDeptByIds" resultMap="sysDeptMap">
  67. select
  68. *
  69. from
  70. sys_dept
  71. where
  72. dept_id = #{query.deptId,jdbcType=INTEGER}
  73. </select>
  74. <select id="selectDeptByName" resultMap="sysDeptMap">
  75. select
  76. dept_id,name
  77. from
  78. sys_dept
  79. where
  80. dept_id = #{query.deptId,jdbcType=INTEGER}
  81. </select>
  82. <select id="selectDept" resultMap="sysDeptMap">
  83. select
  84. *
  85. from
  86. sys_dept
  87. where
  88. dept_id = #{deptId,jdbcType=INTEGER}
  89. </select>
  90. <select id="selectListByDept" resultMap="sysDeptMap">
  91. select
  92. dept_id,
  93. name
  94. from
  95. sys_dept
  96. where del_flag = 0
  97. </select>
  98. <select id="selectDeptById" resultType="java.util.HashMap">
  99. SELECT
  100. d.dept_id as deptId,d.name,d.level,
  101. CASE WHEN a.zj_number IS NULL THEN e.entcode ELSE a.zj_number END entcode
  102. FROM
  103. sys_dept d
  104. LEFT JOIN wm_da_agent a ON d.dept_id = a.dept_id
  105. LEFT JOIN wm_da_drug_ent e ON d.dept_id = e.dept_id
  106. WHERE
  107. d.dept_id = #{query.deptId,jdbcType=INTEGER}
  108. </select>
  109. <select id="getAllParentDept" resultMap="sysDeptMap">
  110. select DISTINCT
  111. dept_id,
  112. `name`,
  113. `level`
  114. from sys_dept
  115. where dept_id IN
  116. (select d.dept_id from sys_dept d
  117. where d.dept_id=#{query.deptId}
  118. union
  119. select r.up_id from sys_dept d
  120. left join wm_relation r on d.dept_id=r.down_id
  121. where d.dept_id=#{query.deptId}
  122. union
  123. select r2.up_id from sys_dept d
  124. left join wm_relation r on d.dept_id=r.down_id
  125. left join wm_relation r2 on r.up_id=r2.down_id
  126. where d.dept_id=#{query.deptId}
  127. )
  128. and del_flag=0
  129. AND dept_id NOT in(1)
  130. </select>
  131. <select id="selectByName" resultMap="sysDeptMap">
  132. select
  133. *
  134. from
  135. sys_dept
  136. where
  137. name = #{name,jdbcType=VARCHAR}
  138. </select>
  139. <select id="selectEntCodeByLevelId" resultType="string">
  140. <choose>
  141. <when test="level = 1">
  142. SELECT `entcode` FROM `wm_da_drug_ent`
  143. </when>
  144. <otherwise>
  145. SELECT `zj_number` FROM `wm_da_agent`
  146. </otherwise>
  147. </choose>
  148. WHERE `id` = #{levelId}
  149. </select>
  150. <update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.api.entity.SysDept" >
  151. update sys_dept
  152. <set >
  153. <if test="delFlag != null" >
  154. del_flag = #{delFlag,jdbcType=VARCHAR},
  155. </if>
  156. <if test="name != null" >
  157. name = #{name,jdbcType=VARCHAR},
  158. </if>
  159. <if test="subjectType != null" >
  160. subject_type = #{subjectType,jdbcType=VARCHAR},
  161. </if>
  162. <if test="taxCode != null" >
  163. tax_code = #{taxCode,jdbcType=VARCHAR},
  164. </if>
  165. <if test="deptPermissions != null and deptPermissions != ''">
  166. dept_permissions = #{deptPermissions, jdbcType=VARCHAR}
  167. </if>
  168. </set>
  169. where dept_id = #{deptId,jdbcType=BIGINT}
  170. </update>
  171. <select id="getParentDept" resultType="map">
  172. select DISTINCT
  173. dept_id deptId,
  174. `name`
  175. from sys_dept
  176. where dept_id IN
  177. (
  178. select r.up_id from sys_dept d
  179. left join wm_relation r on d.dept_id=r.down_id
  180. where d.dept_id=#{query.deptId}
  181. union
  182. select r2.up_id from sys_dept d
  183. left join wm_relation r on d.dept_id=r.down_id
  184. left join wm_relation r2 on r.up_id=r2.down_id
  185. where d.dept_id=#{query.deptId}
  186. )
  187. and del_flag=0
  188. AND dept_id NOT in(1)
  189. </select>
  190. <select id="getChildDept" resultType="map">
  191. select DISTINCT
  192. dept_id deptId,
  193. `name`
  194. from sys_dept
  195. where dept_id IN
  196. (
  197. select r.down_id from sys_dept d
  198. left join wm_relation r on d.dept_id=r.up_id
  199. where d.dept_id=#{query.deptId}
  200. union
  201. select r2.down_id from sys_dept d
  202. left join wm_relation r on d.dept_id=r.up_id
  203. left join wm_relation r2 on r.down_id=r2.up_id
  204. where d.dept_id=#{query.deptId}
  205. )
  206. and del_flag=0
  207. AND dept_id NOT in(1)
  208. </select>
  209. <select id="getDeptConvertToName" resultType="map">
  210. select dept_id deptId, `name` from sys_dept
  211. </select>
  212. <!-- 查询所有dept -->
  213. <select id="listAllDept" resultMap="sysDeptMap">
  214. select * from sys_dept
  215. </select>
  216. <!-- 根据id批量查询 -->
  217. <select id="selectByIds" resultMap="sysDeptMap">
  218. select * from sys_dept where dept_id in
  219. <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
  220. #{item}
  221. </foreach>
  222. </select>
  223. </mapper>