SysDeptMapper.xml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.admin.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="financialReviewType" column="financial_review_type"/>
  22. <result property="taxCode" column="tax_code"/>
  23. </resultMap>
  24. <resultMap id="sysEntRelMap" type="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseRelationVO">
  25. <id property="relId" column="rel_id"/>
  26. <result property="entId" column="ent_id"/>
  27. <result property="entName" column="ent_name"/>
  28. <result property="rootId" column="root_id"/>
  29. <result property="rootName" column="root_name"/>
  30. <result property="entType" column="ent_type"/>
  31. <result property="productLine" column="product_line"/>
  32. <result property="entLevel" column="ent_level"/>
  33. <collection property="serviceCharges" ofType="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseServiceChargeVO"
  34. select="com.qunzhixinxi.hnqz.admin.mapper.SysDeptSubMapper.listSysEnterpriseServiceCharge"
  35. column="ent_id"/>
  36. </resultMap>
  37. <select id="selectDistinctDeptId" resultMap="sysDeptMap">
  38. SELECT DISTINCT dept_id,
  39. level
  40. FROM sys_dept
  41. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  42. ORDER BY level
  43. LIMIT 1
  44. </select>
  45. <select id="selectDeptList" resultMap="sysDeptMap">
  46. SELECT dept_id,
  47. sort,
  48. name
  49. FROM sys_dept
  50. </select>
  51. <select id="selectDeptByIds" resultMap="sysDeptMap">
  52. SELECT *
  53. FROM sys_dept
  54. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  55. </select>
  56. <select id="selectDeptByName" resultMap="sysDeptMap">
  57. SELECT dept_id,
  58. name
  59. FROM sys_dept
  60. WHERE dept_id = #{query.deptId,jdbcType=INTEGER}
  61. </select>
  62. <select id="selectDept" resultMap="sysDeptMap">
  63. SELECT *
  64. FROM sys_dept
  65. WHERE dept_id = #{deptId,jdbcType=INTEGER}
  66. </select>
  67. <select id="selectListByDept" resultMap="sysDeptMap">
  68. SELECT dept_id,
  69. name
  70. FROM sys_dept
  71. WHERE del_flag = 0
  72. </select>
  73. <select id="selectDeptById" resultType="java.util.HashMap">
  74. SELECT d.dept_id AS deptId,
  75. d.name,
  76. d.level,
  77. CASE WHEN a.zj_number IS NULL THEN e.entcode ELSE a.zj_number END entcode
  78. FROM sys_dept d
  79. LEFT JOIN wm_da_agent a ON d.dept_id = a.dept_id
  80. LEFT JOIN wm_da_drug_ent e ON d.dept_id = e.dept_id
  81. WHERE d.dept_id = #{query.deptId,jdbcType=INTEGER}
  82. </select>
  83. <select id="getAllParentDept" resultMap="sysDeptMap">
  84. SELECT DISTINCT dept_id,
  85. `name`,
  86. `level`
  87. FROM sys_dept
  88. WHERE dept_id IN
  89. (SELECT d.dept_id
  90. FROM sys_dept d
  91. WHERE d.dept_id = #{query.deptId}
  92. UNION
  93. SELECT r.up_id
  94. FROM sys_dept d
  95. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  96. WHERE d.dept_id = #{query.deptId}
  97. UNION
  98. SELECT r2.up_id
  99. 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. FROM sys_dept
  110. WHERE name = #{name,jdbcType=VARCHAR}
  111. </select>
  112. <select id="selectEntCodeByLevelId" resultType="string">
  113. <choose>
  114. <when test="level = 1">
  115. SELECT `entcode` FROM `wm_da_drug_ent`
  116. </when>
  117. <otherwise>
  118. SELECT `zj_number` FROM `wm_da_agent`
  119. </otherwise>
  120. </choose>
  121. WHERE `id` = #{levelId}
  122. </select>
  123. <update id="updateByPrimaryKeySelective" parameterType="com.qunzhixinxi.hnqz.admin.api.entity.SysDept">
  124. update sys_dept
  125. <set>
  126. <if test="abbr != null and abbr != ''">
  127. abbr = #{abbr,jdbcType=VARCHAR},
  128. </if>
  129. <if test="provAbbr != null and provAbbr != ''">
  130. prov_abbr = #{provAbbr,jdbcType=VARCHAR},
  131. </if>
  132. <if test="delFlag != null">
  133. del_flag = #{delFlag,jdbcType=VARCHAR},
  134. </if>
  135. <if test="name != null">
  136. name = #{name,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. <if test="financialReviewType != null">
  145. financial_review_type = #{financialReviewType.type, jdbcType=CHAR}
  146. </if>
  147. </set>
  148. where dept_id = #{deptId,jdbcType=BIGINT}
  149. </update>
  150. <select id="getParentDept" resultType="map">
  151. SELECT DISTINCT dept_id deptId,
  152. `name`
  153. FROM sys_dept
  154. WHERE dept_id IN
  155. (
  156. SELECT r.up_id
  157. FROM sys_dept d
  158. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  159. WHERE d.dept_id = #{query.deptId}
  160. UNION
  161. SELECT r2.up_id
  162. FROM sys_dept d
  163. LEFT JOIN wm_relation r ON d.dept_id = r.down_id
  164. LEFT JOIN wm_relation r2 ON r.up_id = r2.down_id
  165. WHERE d.dept_id = #{query.deptId}
  166. )
  167. AND del_flag = 0
  168. AND dept_id NOT IN (1)
  169. </select>
  170. <select id="getChildDept" resultType="map">
  171. SELECT DISTINCT dept_id deptId,
  172. `name`
  173. FROM sys_dept
  174. WHERE dept_id IN
  175. (
  176. SELECT r.down_id
  177. FROM sys_dept d
  178. LEFT JOIN wm_relation r ON d.dept_id = r.up_id
  179. WHERE d.dept_id = #{query.deptId}
  180. UNION
  181. SELECT r2.down_id
  182. FROM sys_dept d
  183. LEFT JOIN wm_relation r ON d.dept_id = r.up_id
  184. LEFT JOIN wm_relation r2 ON r.down_id = r2.up_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="getDeptConvertToName" resultType="map">
  191. SELECT dept_id deptId, `name`
  192. FROM sys_dept
  193. </select>
  194. <!-- 查询所有dept -->
  195. <select id="listAllDept" resultMap="sysDeptMap">
  196. SELECT *
  197. FROM sys_dept
  198. </select>
  199. <!-- 分页查询所有dept -->
  200. <select id="pageAllDept" resultMap="sysDeptMap">
  201. SELECT *
  202. FROM sys_dept
  203. <where>
  204. <if test="ew != null">
  205. <if test="ew.nonEmptyOfWhere">
  206. AND
  207. </if>
  208. ${ew.sqlSegment}
  209. </if>
  210. </where>
  211. </select>
  212. <!-- 根据id批量查询 -->
  213. <select id="selectByIds" resultMap="sysDeptMap">
  214. select * from sys_dept where dept_id in
  215. <foreach item="item" index="index" collection="ids" open="(" separator="," close=")">
  216. #{item}
  217. </foreach>
  218. </select>
  219. <select id="pageEntRels" resultMap="sysEntRelMap">
  220. SELECT el.rel_id,
  221. d.dept_id AS `ent_id`,
  222. d.name AS `ent_name`,
  223. d1.dept_id AS `root_id`,
  224. d1.name AS `root_name`,
  225. el.e_type AS `ent_type`,
  226. el.pro_line AS `product_line`,
  227. el.e_level AS `ent_level`
  228. FROM sys_dept d
  229. LEFT JOIN sys_ent_rel el ON el.ent_id = d.dept_id
  230. LEFT JOIN sys_dept d1 ON el.root_id = d1.dept_id
  231. <where>
  232. d.del_flag = 0
  233. <if test="entName != null and entName != ''">
  234. AND d.name like CONCAT('%', #{entName},'%')
  235. </if>
  236. </where>
  237. </select>
  238. </mapper>