SysDeptMapper.xml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. <if test="financialReviewType != null">
  165. financial_review_type = #{financialReviewType.type, jdbcType=CHAR}
  166. </if>
  167. </set>
  168. where dept_id = #{deptId,jdbcType=BIGINT}
  169. </update>
  170. <select id="getParentDept" resultType="map">
  171. SELECT DISTINCT dept_id deptId,
  172. `name`
  173. FROM sys_dept
  174. WHERE dept_id IN
  175. (
  176. SELECT r.up_id
  177. FROM sys_dept d
  178. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  179. WHERE d.dept_id = #{query.deptId}
  180. UNION
  181. SELECT r2.up_id
  182. 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 dept_id deptId,
  192. `name`
  193. FROM sys_dept
  194. WHERE dept_id IN
  195. (
  196. SELECT r.down_id
  197. 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
  202. FROM sys_dept d
  203. LEFT JOIN wm_relation r ON d.dept_id = r.up_id
  204. LEFT JOIN wm_relation r2 ON r.down_id = r2.up_id
  205. WHERE d.dept_id = #{query.deptId}
  206. )
  207. AND del_flag = 0
  208. AND dept_id NOT IN (1)
  209. </select>
  210. <select id="getDeptConvertToName" resultType="map">
  211. SELECT dept_id deptId, `name`
  212. FROM sys_dept
  213. </select>
  214. <!-- 查询所有dept -->
  215. <select id="listAllDept" resultMap="sysDeptMap">
  216. SELECT *
  217. FROM sys_dept
  218. </select>
  219. <!-- 根据id批量查询 -->
  220. <select id="selectByIds" resultMap="sysDeptMap">
  221. select * from sys_dept where dept_id in
  222. <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
  223. #{item}
  224. </foreach>
  225. </select>
  226. <select id="pageEntRels" resultMap="sysEntRelMap">
  227. SELECT el.rel_id,
  228. d.dept_id AS `ent_id`,
  229. d.name AS `ent_name`,
  230. d1.dept_id AS `root_id`,
  231. d1.name AS `root_name`,
  232. el.e_type AS `ent_type`,
  233. el.pro_line AS `product_line`,
  234. el.e_level AS `ent_level`
  235. FROM sys_dept d
  236. LEFT JOIN sys_ent_rel el ON el.ent_id = d.dept_id
  237. LEFT JOIN sys_dept d1 ON el.root_id = d1.dept_id
  238. <where>
  239. d.del_flag = 0
  240. <if test="entName != null and entName != ''">
  241. AND d.name like CONCAT('%', #{entName},'%')
  242. </if>
  243. </where>
  244. </select>
  245. </mapper>