SysDeptMapper.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. <resultMap id="sysEntRelMap" type="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseRelationVO">
  48. <id property="relId" column="rel_id"/>
  49. <result property="entId" column="ent_id"/>
  50. <result property="entName" column="ent_name"/>
  51. <result property="rootId" column="root_id"/>
  52. <result property="rootName" column="root_name"/>
  53. <result property="entType" column="ent_type"/>
  54. <result property="productLine" column="product_line"/>
  55. <result property="entLevel" column="ent_level"/>
  56. <collection property="serviceCharges" ofType="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseServiceChargeVO"
  57. select="com.qunzhixinxi.hnqz.admin.mapper.SysDeptSubMapper.listSysEnterpriseServiceCharge"
  58. column="ent_id"/>
  59. </resultMap>
  60. <select id="selectDistinctDeptId" resultMap="sysDeptMap">
  61. SELECT DISTINCT dept_id,
  62. level
  63. FROM sys_dept
  64. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  65. ORDER BY level
  66. LIMIT 1
  67. </select>
  68. <select id="selectDeptList" resultMap="sysDeptMap">
  69. SELECT dept_id,
  70. sort,
  71. name
  72. FROM sys_dept
  73. </select>
  74. <select id="selectDeptByIds" resultMap="sysDeptMap">
  75. SELECT *
  76. FROM sys_dept
  77. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  78. </select>
  79. <select id="selectDeptByName" resultMap="sysDeptMap">
  80. SELECT dept_id,
  81. name
  82. FROM sys_dept
  83. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  84. </select>
  85. <select id="selectDept" resultMap="sysDeptMap">
  86. SELECT *
  87. FROM sys_dept
  88. WHERE dept_id = #{deptId,jdbcType=INTEGER}
  89. </select>
  90. <select id="selectListByDept" resultMap="sysDeptMap">
  91. SELECT dept_id,
  92. name
  93. FROM sys_dept
  94. WHERE del_flag = 0
  95. </select>
  96. <select id="selectDeptById" resultType="java.util.HashMap">
  97. SELECT d.dept_id AS deptid,
  98. d.name,
  99. d.level,
  100. CASE WHEN a.zj_number IS NULL THEN e.entcode ELSE a.zj_number END entcode
  101. FROM sys_dept d
  102. LEFT JOIN wm_da_agent a ON d.dept_id = a.dept_id
  103. LEFT JOIN wm_da_drug_ent e ON d.dept_id = e.dept_id
  104. WHERE d.dept_id = #{query.deptId,jdbcType=INTEGER}
  105. </select>
  106. <select id="getAllParentDept" resultMap="sysDeptMap">
  107. SELECT DISTINCT dept_id,
  108. `name`,
  109. `level`
  110. FROM sys_dept
  111. WHERE dept_id IN
  112. (SELECT d.dept_id
  113. FROM sys_dept d
  114. WHERE d.dept_id = #{query.deptId}
  115. UNION
  116. SELECT r.up_id
  117. FROM sys_dept d
  118. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  119. WHERE d.dept_id = #{query.deptId}
  120. UNION
  121. SELECT r2.up_id
  122. FROM sys_dept d
  123. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  124. LEFT JOIN wm_relation r2 ON r.up_id = r2.down_id
  125. WHERE d.dept_id = #{query.deptId}
  126. )
  127. AND del_flag = 0
  128. AND dept_id NOT IN (1)
  129. </select>
  130. <select id="selectByName" resultMap="sysDeptMap">
  131. SELECT *
  132. FROM sys_dept
  133. WHERE name = #{name,jdbcType=VARCHAR}
  134. </select>
  135. <select id="selectEntCodeByLevelId" resultType="string">
  136. <choose>
  137. <when test="level = 1">
  138. SELECT `entcode` FROM `wm_da_drug_ent`
  139. </when>
  140. <otherwise>
  141. SELECT `zj_number` FROM `wm_da_agent`
  142. </otherwise>
  143. </choose>
  144. WHERE `id` = #{levelId}
  145. </select>
  146. <update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.api.entity.SysDept">
  147. update sys_dept
  148. <set>
  149. <if test="delFlag != null">
  150. del_flag = #{delFlag,jdbcType=VARCHAR},
  151. </if>
  152. <if test="name != null">
  153. name = #{name,jdbcType=VARCHAR},
  154. </if>
  155. <if test="subjectType != null">
  156. subject_type = #{subjectType,jdbcType=VARCHAR},
  157. </if>
  158. <if test="taxCode != null">
  159. tax_code = #{taxCode,jdbcType=VARCHAR},
  160. </if>
  161. <if test="deptPermissions != null and deptPermissions != ''">
  162. dept_permissions = #{deptPermissions, jdbcType=VARCHAR}
  163. </if>
  164. </set>
  165. where dept_id = #{deptId,jdbcType=BIGINT}
  166. </update>
  167. <select id="getParentDept" resultType="map">
  168. SELECT DISTINCT dept_id deptid,
  169. `name`
  170. FROM sys_dept
  171. WHERE dept_id IN
  172. (
  173. SELECT r.up_id
  174. FROM sys_dept d
  175. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  176. WHERE d.dept_id = #{query.deptId}
  177. UNION
  178. SELECT r2.up_id
  179. FROM sys_dept d
  180. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  181. LEFT JOIN wm_relation r2 ON r.up_id = r2.down_id
  182. WHERE d.dept_id = #{query.deptId}
  183. )
  184. AND del_flag = 0
  185. AND dept_id NOT IN (1)
  186. </select>
  187. <select id="getChildDept" resultType="map">
  188. SELECT DISTINCT dept_id deptid,
  189. `name`
  190. FROM sys_dept
  191. WHERE dept_id IN
  192. (
  193. SELECT r.down_id
  194. FROM sys_dept d
  195. LEFT JOIN wm_relation r ON d.dept_id = r.up_id
  196. WHERE d.dept_id = #{query.deptId}
  197. UNION
  198. SELECT r2.down_id
  199. FROM sys_dept d
  200. LEFT JOIN wm_relation r ON d.dept_id = r.up_id
  201. LEFT JOIN wm_relation r2 ON r.down_id = r2.up_id
  202. WHERE d.dept_id = #{query.deptId}
  203. )
  204. AND del_flag = 0
  205. AND dept_id NOT IN (1)
  206. </select>
  207. <select id="getDeptConvertToName" resultType="map">
  208. SELECT dept_id deptid, `name`
  209. FROM sys_dept
  210. </select>
  211. <!-- 查询所有dept -->
  212. <select id="listAllDept" resultMap="sysDeptMap">
  213. SELECT *
  214. 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. <select id="pageEntRels" resultMap="sysEntRelMap">
  224. SELECT el.rel_id,
  225. d.dept_id AS `ent_id`,
  226. d.name AS `ent_name`,
  227. d1.dept_id AS `root_id`,
  228. d1.name AS `root_name`,
  229. el.e_type AS `ent_type`,
  230. el.pro_line AS `product_line`,
  231. el.e_level AS `ent_level`
  232. FROM sys_dept d
  233. LEFT JOIN sys_ent_rel el ON el.ent_id = d.dept_id
  234. LEFT JOIN sys_dept d1 ON el.root_id = d1.dept_id
  235. <where>
  236. d.del_flag = 0
  237. <if test="entName != null and entName != ''">
  238. AND d.name like CONCAT('%', #{entName},'%')
  239. </if>
  240. </where>
  241. </select>
  242. </mapper>