GroupMemberMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  4. <mapper namespace="com.zhyc.xps.sys.mapper.GroupMemberMapper">
  5. <resultMap id="BaseResultMap" type="com.zhyc.xps.sys.entity.GroupMember">
  6. <result column="gm_id" property="gmId" jdbcType="BIGINT" /><!--群组成员ID-->
  7. <result column="oc_id" property="ocId" jdbcType="BIGINT" /><!--公司机构ID-->
  8. <result column="group_id" property="groupId" jdbcType="BIGINT" /><!--群组ID-->
  9. <result column="account_id" property="accountId" jdbcType="BIGINT" /><!--帐号ID-->
  10. <result column="is_fixed" property="isFixed" jdbcType="BIGINT" /><!--帐号ID-->
  11. </resultMap>
  12. <resultMap id="GroupMemberDtoResultMap" type="com.zhyc.xps.sys.dto.GroupMemberDto" extends="BaseResultMap">
  13. <result column="group_name" property="groupName" jdbcType="VARCHAR" />
  14. <result column="node_left" property="nodeLeft" jdbcType="BIGINT" />
  15. <result column="node_right" property="nodeRight" jdbcType="BIGINT" />
  16. <result column="node_level" property="nodeLevel" jdbcType="BIGINT" />
  17. </resultMap>
  18. <resultMap id="GroupMemberDetailsDtoResultMap" type="com.zhyc.xps.sys.dto.GroupMemberDetailsDto" extends="GroupMemberDtoResultMap">
  19. <result column="account_id" property="accountId" jdbcType="BIGINT" />
  20. <result column="account_name" property="accountName" jdbcType="VARCHAR" />
  21. <result column="account_type" property="accountType" jdbcType="BIGINT" />
  22. <result column="account_staff_no" property="accountStaffNo" jdbcType="VARCHAR" />
  23. <result column="account_phone" property="accountPhone" jdbcType="VARCHAR" />
  24. <result column="account_last_ip" property="accountLastIp" jdbcType="VARCHAR" />
  25. <result column="account_loc" property="accountLoc" jdbcType="VARCHAR" />
  26. <result column="status" property="status" jdbcType="BIGINT" />
  27. <result column="account_avatar" property="accountAvatar" jdbcType="VARCHAR" />
  28. <result column="account_real_name" property="accountRealName" jdbcType="VARCHAR" />
  29. <result column="account_intro" property="accountIntro" jdbcType="VARCHAR" />
  30. <result column="is_fixed" property="isFixed" jdbcType="BIGINT" />
  31. <result column="gmp_id" property="gmpId" jdbcType="BIGINT" />
  32. <result column="position_id" property="positionId" jdbcType="BIGINT" />
  33. <result column="position_name" property="positionName" jdbcType="VARCHAR" />
  34. <result column="gmpg_id" property="gmpgId" jdbcType="BIGINT" />
  35. <result column="grant_group_id" property="grantGroupId" jdbcType="BIGINT" />
  36. <result column="grant_group_name" property="grantGroupName" jdbcType="VARCHAR" />
  37. </resultMap>
  38. <sql id="GroupMemberDto_Cols">
  39. A.gm_id,
  40. A.oc_id,
  41. A.group_id,
  42. B.group_name,
  43. B.node_left ,
  44. B.node_right,
  45. A.account_id
  46. </sql>
  47. <!--根据账户id获取第一群组-->
  48. <select id="getById" resultMap="GroupMemberDetailsDtoResultMap">
  49. SELECT A.gm_id,
  50. A.oc_id,
  51. A.group_id,
  52. A.account_id,
  53. B.account_name,
  54. B.account_real_name,
  55. B.account_staff_no,
  56. B.account_phone,
  57. B.account_type,
  58. B.account_avatar,
  59. B.account_photo,
  60. B.account_loc,
  61. B.status,
  62. B.is_fixed,
  63. C.group_name,
  64. C.node_left,
  65. C.node_right,
  66. E.gmp_id,
  67. E.position_id,
  68. H.position_name,
  69. F.gmpg_id,
  70. F.grant_group_id,
  71. G.group_name AS grant_group_name
  72. FROM s_group_member AS A
  73. LEFT JOIN account AS B ON ( A.oc_id = B.oc_id AND A.account_id = B.account_id )
  74. LEFT JOIN s_group AS C ON ( A.oc_id = C.oc_id AND A.group_id = C.group_id )
  75. LEFT JOIN s_group_member_position AS E ON ( A.oc_id = E.oc_id AND A.account_id = E.account_id AND E.group_id= #{groupId ,jdbcType=BIGINT} )
  76. LEFT JOIN s_group_member_position_grant AS F ON ( E.oc_id = F.oc_id AND E.account_id = F.account_id AND E.position_id = F.position_id AND F.group_id = #{groupId ,jdbcType=BIGINT} )
  77. LEFT JOIN s_group AS G ON ( G.oc_id = F.oc_id AND G.group_id = F.grant_group_id )
  78. LEFT JOIN s_position AS H ON ( A.oc_id = E.oc_id AND H.position_id = E.position_id )
  79. WHERE B.deleted_flag = 0
  80. <if test="ocId != null">
  81. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  82. </if>
  83. <if test="accountId != null">
  84. AND A.account_id = #{accountId ,jdbcType=BIGINT}
  85. </if>
  86. LIMIT 1
  87. </select>
  88. <!--根据账户id获取第一群组-->
  89. <select id="getFirstGroupByAccountId" resultMap="GroupMemberDtoResultMap">
  90. SELECT
  91. <include refid="GroupMemberDto_Cols"/>
  92. FROM s_group_member AS A
  93. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  94. WHERE B.deleted_flag = 0
  95. <if test="ocId != null">
  96. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  97. </if>
  98. <if test="accountId != null">
  99. AND A.account_id = #{accountId ,jdbcType=BIGINT}
  100. </if>
  101. LIMIT 1
  102. </select>
  103. <!--根据左右树结点,获取群组所有下级成员,包括所有子群组成员-->
  104. <select id="getByList" parameterType="java.util.Map" resultMap="GroupMemberDetailsDtoResultMap">
  105. SELECT
  106. DISTINCT(A.account_id),
  107. A.gm_id,
  108. A.oc_id,
  109. A.group_id,
  110. B.account_name,
  111. B.account_real_name,
  112. B.account_staff_no,
  113. B.account_phone,
  114. B.account_avatar,
  115. B.status,
  116. B.is_fixed,
  117. C.group_name,
  118. C.node_left,
  119. C.node_right,
  120. D.gmp_id,
  121. D.position_id,
  122. D.position_name,
  123. E.gmpg_id,
  124. E.grant_group_id,
  125. F.group_name as grant_group_name
  126. FROM s_group_member AS A
  127. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.account_id = B.account_id)
  128. LEFT JOIN s_group AS C ON (A.oc_id = C.oc_id AND A.group_id = C.group_id)
  129. LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id = E.account_id)
  130. LEFT JOIN s_group AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id)
  131. LEFT JOIN (
  132. SELECT
  133. M.oc_id,
  134. M.account_id,
  135. M.gmp_id,
  136. M.group_id,
  137. M.position_id,
  138. P.position_name,
  139. N.gmpg_id,
  140. N.grant_group_id,
  141. GP.group_name as grant_group_name
  142. FROM s_group_member_position AS M
  143. LEFT JOIN s_group_member_position_grant AS N ON (
  144. M.oc_id = N.oc_id
  145. AND M.account_id = N.account_id
  146. AND M.group_id = N.group_id
  147. AND M.position_id = N.position_id )
  148. LEFT JOIN s_position AS P ON(M.oc_id = P.oc_id AND M.position_id = P.position_id)
  149. LEFT JOIN s_group AS GP ON(M.oc_id = GP.oc_id AND N.grant_group_id = GP.group_id)
  150. ) AS D ON (A.oc_id = D.oc_id AND A.account_id = D.account_id AND A.group_id = D.group_id)
  151. WHERE B.deleted_flag = 0
  152. <if test="ocId != null">
  153. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  154. </if>
  155. <if test="nodeLeft != null and nodeRight != null">
  156. <![CDATA[
  157. AND C.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  158. AND C.node_right <= #{nodeRight,jdbcType=BIGINT}
  159. ]]>
  160. </if>
  161. <if test="keywords != null and keywords != ''">
  162. AND (
  163. B.account_real_name LIKE "%"#{keywords}"%"
  164. OR B.account_name LIKE "%"#{keywords}"%"
  165. OR B.account_phone LIKE "%"#{keywords}"%"
  166. OR B.account_staff_no LIKE "%"#{keywords}"%"
  167. OR D.position_name LIKE "%"#{keywords}"%"
  168. )
  169. </if>
  170. ORDER BY A.account_id ,A.group_id
  171. </select>
  172. <!--根据左右树结点,获取群组所有下级成员,包括所有子群组成员-->
  173. <select id="getByPage" parameterType="java.util.Map" resultMap="GroupMemberDetailsDtoResultMap">
  174. SELECT
  175. DISTINCT(A.account_id),
  176. A.gm_id,
  177. A.oc_id,
  178. A.group_id,
  179. B.account_name,
  180. B.account_real_name,
  181. B.account_phone,
  182. B.account_staff_no,
  183. B.account_avatar,
  184. B.status,
  185. B.is_fixed,
  186. C.group_name,
  187. C.node_left,
  188. C.node_right,
  189. D.gmp_id,
  190. D.position_id,
  191. D.position_name,
  192. E.gmpg_id,
  193. E.grant_group_id,
  194. F.group_name as grant_group_name
  195. FROM
  196. s_group_member AS A
  197. LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.account_id = B.account_id)
  198. LEFT JOIN s_group AS C ON (A.oc_id = C.oc_id AND A.group_id = C.group_id )
  199. LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id = E.account_id)
  200. LEFT JOIN s_group AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id )
  201. LEFT JOIN (
  202. SELECT
  203. M.oc_id,
  204. M.account_id,
  205. M.gmp_id,
  206. M.group_id,
  207. M.position_id,
  208. P.position_name,
  209. N.gmpg_id,
  210. N.grant_group_id,
  211. GP.group_name as grant_group_name
  212. FROM
  213. s_group_member_position AS M
  214. LEFT JOIN s_group_member_position_grant AS N ON (
  215. M.oc_id = N.oc_id
  216. AND M.account_id = N.account_id
  217. AND M.group_id = N.group_id
  218. AND M.position_id = N.position_id )
  219. LEFT JOIN s_position AS P ON(M.oc_id = P.oc_id AND M.position_id = P.position_id)
  220. LEFT JOIN s_group AS GP ON(M.oc_id = GP.oc_id AND N.grant_group_id = GP.group_id )
  221. ) AS D ON (A.oc_id= D.oc_id AND A.account_id = D.account_id AND A.group_id = D.group_id)
  222. WHERE B.deleted_flag = 0
  223. <if test="ocId != null">
  224. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  225. </if>
  226. <if test="nodeLeft != null and nodeRight != null">
  227. <![CDATA[
  228. AND C.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  229. AND C.node_right <= #{nodeRight,jdbcType=BIGINT}
  230. ]]>
  231. </if>
  232. <if test="keywords != null and keywords != ''">
  233. AND (
  234. B.account_real_name LIKE "%"#{keywords}"%"
  235. OR B.account_name LIKE "%"#{keywords}"%"
  236. OR B.account_phone LIKE "%"#{keywords}"%"
  237. OR B.account_staff_no LIKE "%"#{keywords}"%"
  238. OR D.position_name LIKE "%"#{keywords}"%"
  239. )
  240. </if>
  241. ORDER BY A.account_id, A.group_id
  242. </select>
  243. <!--新增INSERT-->
  244. <insert id="create" parameterType="com.zhyc.xps.sys.entity.GroupMember">
  245. INSERT INTO s_group_member
  246. <trim prefix="(" suffix=")" suffixOverrides=",">
  247. <if test="ocId != null">
  248. oc_id,
  249. </if>
  250. <if test="gmId != null">
  251. gm_id,
  252. </if>
  253. <if test="groupId != null">
  254. group_id,
  255. </if>
  256. <if test="accountId != null">
  257. account_id,
  258. </if>
  259. <if test="createdBy != null">
  260. created_by,
  261. </if>
  262. <if test="createdAt != null">
  263. created_at,
  264. </if>
  265. </trim>
  266. <trim prefix="values (" suffix=")" suffixOverrides=",">
  267. <if test="ocId != null">
  268. #{ocId ,jdbcType=BIGINT},
  269. </if>
  270. <if test="gmId != null">
  271. #{gmId ,jdbcType=BIGINT},
  272. </if>
  273. <if test="groupId != null">
  274. #{groupId,jdbcType=BIGINT},
  275. </if>
  276. <if test="accountId != null">
  277. #{accountId,jdbcType=BIGINT},
  278. </if>
  279. <if test="createdBy != null">
  280. #{createdBy ,jdbcType=BIGINT},
  281. </if>
  282. <if test="createdAt != null">
  283. #{createdAt ,jdbcType=TIMESTAMP},
  284. </if>
  285. </trim>
  286. </insert>
  287. <!--update更新GroupMember-->
  288. <update id="update" parameterType="com.zhyc.xps.sys.entity.GroupMember">
  289. UPDATE s_group_member
  290. <trim suffixOverrides=",">
  291. <set>
  292. <if test="groupId != null">
  293. group_id = #{groupId,jdbcType=BIGINT},
  294. </if>
  295. <if test="accountId != null">
  296. account_id = #{accountId,jdbcType=BIGINT},
  297. </if>
  298. <if test="updatedBy != null">
  299. updated_by = #{updatedBy,jdbcType=BIGINT},
  300. </if>
  301. <if test="updatedAt != null">
  302. updated_at = #{updatedAt,jdbcType=TIMESTAMP},
  303. </if>
  304. </set>
  305. </trim>
  306. WHERE gm_id = #{gmId,jdbcType=BIGINT}
  307. AND oc_id = #{ocId,jdbcType=BIGINT}
  308. </update>
  309. <!--删除-->
  310. <update id="delete" parameterType="java.util.Map">
  311. UPDATE s_group_member
  312. <trim suffixOverrides=",">
  313. <set>
  314. <if test="deletedFlag != null">
  315. deleted_flag = #{deletedFlag,jdbcType=BIGINT},
  316. </if>
  317. <if test="deletedAt != null">
  318. deleted_at = #{deletedAt ,jdbcType=DATE},
  319. </if>
  320. <if test="deletedBy != null">
  321. deleted_by = #{deletedBy,jdbcType=BIGINT},
  322. </if>
  323. </set>
  324. </trim>
  325. WHERE 1 = 1
  326. <if test="gmId != null">
  327. AND gm_id = #{gmId ,jdbcType=BIGINT}
  328. </if>
  329. <if test="ocId != null">
  330. AND oc_id = #{ocId ,jdbcType=BIGINT}
  331. </if>
  332. <if test="groupId != null">
  333. AND group_id = #{groupId ,jdbcType=BIGINT}
  334. </if>
  335. <if test="accountId != null">
  336. AND account_id = #{accountId ,jdbcType=BIGINT}
  337. </if>
  338. </update>
  339. <!--获取群组成员数目-->
  340. <select id="getMembersCountOfGroup" parameterType="java.util.Map" resultType="java.lang.Long">
  341. SELECT
  342. count(*)
  343. FROM
  344. s_group_member AS A
  345. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  346. WHERE A.deleted_flag = 0
  347. <if test="ocId != null">
  348. AND A.oc_id = #{ocId ,jdbcType=BIGINT}
  349. </if>
  350. <if test="nodeLeft != null and nodeRight != null">
  351. <![CDATA[
  352. AND B.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  353. AND B.node_right <= #{nodeRight,jdbcType=BIGINT}
  354. ]]>
  355. </if>
  356. </select>
  357. </mapper>