GroupMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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.GroupMapper">
  5. <resultMap id="GetResultMap" type="com.zhyc.xps.sys.dto.GroupDto" >
  6. <result column="oc_id" property="ocId" jdbcType="BIGINT" /><!--ID-->
  7. <result column="group_id" property="groupId" jdbcType="BIGINT" /><!--群组ID-->
  8. <result column="group_name" property="groupName" jdbcType="VARCHAR" /><!--群组Name-->
  9. <result column="group_code" property="groupCode" jdbcType="VARCHAR" /><!--群组Code-->
  10. <result column="group_cat_id" property="groupCatId" jdbcType="BIGINT" /><!--群组类别ID-->
  11. <result column="parent_id" property="parentId" jdbcType="BIGINT" /><!--父群组-->
  12. <result column="root_id" property="rootId" jdbcType="BIGINT" /><!--根群组ID-->
  13. <result column="node_left" property="nodeLeft" jdbcType="BIGINT" /><!--Node Left-->
  14. <result column="node_right" property="nodeRight" jdbcType="BIGINT" /><!--Node Right-->
  15. <result column="node_level" property="nodeLevel" jdbcType="BIGINT" /><!--Node Leve-->
  16. <result column="is_leaf" property="isLeaf" jdbcType="BIGINT" /><!--Leaf-->
  17. <result column="is_fixed" property="isFixed" jdbcType="BIGINT" /><!--是否可删除-->
  18. <result column="group_desc" property="groupDesc" jdbcType="VARCHAR" /><!--描述-->
  19. <result column="group_select" property="groupSelect" jdbcType="VARCHAR" /><!--供首字母等检索用-->
  20. <result column="parent_name" property="parentName" jdbcType="VARCHAR" />
  21. <result column="group_cat_title" property="groupCatTitle" jdbcType="VARCHAR" />
  22. </resultMap>
  23. <sql id="GroupDto_Cols">
  24. A.oc_id,
  25. A.group_id,
  26. A.group_name,
  27. A.group_code,
  28. A.group_cat_id,
  29. C.group_cat_title,
  30. A.node_left,
  31. A.node_right,
  32. A.parent_id,
  33. A.root_id,
  34. B.group_name as parent_name,
  35. A.node_level,
  36. A.is_leaf,
  37. A.is_fixed,
  38. A.group_desc
  39. </sql>
  40. <!--根据ID获取群组信息-->
  41. <select id="getById" resultMap="GetResultMap">
  42. SELECT
  43. <include refid="GroupDto_Cols"/>
  44. FROM s_group AS A
  45. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.parent_id = B.group_id )
  46. LEFT JOIN s_group_cat AS C ON (A.oc_id = C.oc_id AND A.group_cat_id = C.group_cat_id)
  47. WHERE A.oc_id = #{ocId ,jdbcType=BIGINT} AND A.deleted_flag = 0 AND A.group_id = #{groupId ,jdbcType=BIGINT}
  48. </select>
  49. <!--根据条件返回相应的群组列表-->
  50. <select id="getByList" parameterType="java.util.Map" resultMap="GetResultMap">
  51. SELECT
  52. <include refid="GroupDto_Cols"/>
  53. FROM s_group AS A
  54. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.parent_id = B.group_id)
  55. LEFT JOIN s_group_cat AS C ON (A.oc_id = C.oc_id AND A.group_cat_id = C.group_cat_id)
  56. WHERE A.oc_id = #{ocId,jdbcType=BIGINT} AND A.deleted_flag = 0
  57. <if test="nodeLeft != null and nodeRight != null">
  58. <![CDATA[
  59. AND A.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  60. AND A.node_right <= #{nodeRight ,jdbcType=BIGINT}
  61. ]]>
  62. </if>
  63. <if test="groupCatId!=null">
  64. AND A.group_cat_id = #{groupCatId ,jdbcType=BIGINT}
  65. </if>
  66. <if test="groupId !=null">
  67. AND A.group_id = #{groupId,jdbcType=BIGINT}
  68. </if>
  69. <if test="parentId != null">
  70. AND A.parent_id = #{parentId, jdbcType=BIGINT}
  71. </if>
  72. <if test="keywords != null and keywords != ''">
  73. AND ( A.group_name LIKE "%"#{keywords}"%"
  74. </if>
  75. </select>
  76. <!--获取某个群组的所有下级群组列表-->
  77. <select id="getGroupChildren" parameterType="java.util.Map" resultMap="GetResultMap">
  78. SELECT
  79. <include refid="GroupDto_Cols"/>
  80. FROM s_group AS A
  81. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.parent_id = B.group_id )
  82. LEFT JOIN s_group_cat AS C ON (A.oc_id = C.oc_id AND A.group_cat_id = C.group_cat_id)
  83. WHERE A.oc_id = #{ocId ,jdbcType=BIGINT} AND A.deleted_flag = 0
  84. <if test="nodeLeft != null and nodeRight != null">
  85. <![CDATA[
  86. AND A.node_left >= #{nodeLeft ,jdbcType=BIGINT}
  87. AND A.node_right <= #{nodeRight ,jdbcType=BIGINT}
  88. ]]>
  89. </if>
  90. <if test="groupCatId!=null">
  91. AND A.group_cat_id = #{groupCatId ,jdbcType=BIGINT}
  92. </if>
  93. <if test="groupIds !=null and groupIds.length > 0">
  94. AND A.group_id in
  95. <foreach collection="groupIds" item="groupId" open="(" separator="," close=")">
  96. #{groupId}
  97. </foreach>
  98. </if>
  99. <if test="groupId !=null">
  100. AND A.group_id = #{groupId,jdbcType=BIGINT}
  101. </if>
  102. <if test="parentId != null">
  103. AND A.parent_id = #{parentId, jdbcType=BIGINT}
  104. </if>
  105. ORDER BY A.group_id
  106. </select>
  107. <!--根据名称获取群组信息-->
  108. <select id="getGroupByName" parameterType="java.util.Map" resultMap="GetResultMap">
  109. SELECT
  110. <include refid="GroupDto_Cols"/>
  111. FROM s_group AS A
  112. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.parent_id = B.group_id )
  113. LEFT JOIN s_group_cat AS C ON (A.oc_id = C.oc_id AND A.group_cat_id = C.group_cat_id)
  114. WHERE A.oc_id = #{ocId,jdbcType=BIGINT} AND A.deleted_flag = 0
  115. <if test="groupName != null and groupName != ''">
  116. AND A.group_name = #{groupName,jdbcType=VARCHAR}
  117. </if>
  118. </select>
  119. <!--insert新增-->
  120. <insert id="create" parameterType="com.zhyc.xps.sys.entity.Group" useGeneratedKeys="true" keyProperty="groupId">
  121. INSERT INTO s_group
  122. <trim prefix="(" suffix=")" suffixOverrides=",">
  123. <if test="ocId != null">
  124. oc_id,
  125. </if>
  126. <if test="groupId != null">
  127. group_id,
  128. </if>
  129. <if test="groupName != null and groupName != ''">
  130. group_name,
  131. </if>
  132. <if test="groupCode != null and groupCode != ''">
  133. group_code,
  134. </if>
  135. <if test="groupCatId != null">
  136. group_cat_id,
  137. </if>
  138. <if test="nodeLeft != null">
  139. node_left,
  140. </if>
  141. <if test="nodeRight != null">
  142. node_right,
  143. </if>
  144. <if test="parentId != null">
  145. parent_id,
  146. </if>
  147. <if test="rootId != null">
  148. root_id,
  149. </if>
  150. <if test="nodeLevel != null">
  151. node_level,
  152. </if>
  153. <if test="isLeaf != null">
  154. is_leaf,
  155. </if>
  156. <if test="isFixed != null">
  157. is_fixed,
  158. </if>
  159. <if test="groupDesc != null and groupDesc != ''">
  160. group_desc,
  161. </if>
  162. <if test="groupSelect != null and groupSelect != ''">
  163. group_select,
  164. </if>
  165. <if test="createdBy != null">
  166. created_by,
  167. </if>
  168. <if test="createdAt != null">
  169. created_at,
  170. </if>
  171. </trim>
  172. <trim prefix="values (" suffix=")" suffixOverrides=",">
  173. <if test="ocId != null">
  174. #{ocId,jdbcType=BIGINT},
  175. </if>
  176. <if test="groupId != null">
  177. #{groupId,jdbcType=BIGINT},
  178. </if>
  179. <if test="groupName != null and groupName != ''">
  180. #{groupName,jdbcType=VARCHAR},
  181. </if>
  182. <if test="groupCode != null and groupCode != ''">
  183. #{groupCode,jdbcType=VARCHAR},
  184. </if>
  185. <if test="groupCatId != null">
  186. #{groupCatId,jdbcType=BIGINT},
  187. </if>
  188. <if test="nodeLeft != null">
  189. #{nodeLeft,jdbcType=BIGINT},
  190. </if>
  191. <if test="nodeRight != null">
  192. #{nodeRight,jdbcType=BIGINT},
  193. </if>
  194. <if test="parentId != null">
  195. #{parentId,jdbcType=BIGINT},
  196. </if>
  197. <if test="rootId != null">
  198. #{rootId,jdbcType=BIGINT},
  199. </if>
  200. <if test="nodeLevel != null">
  201. #{nodeLevel,jdbcType=BIGINT},
  202. </if>
  203. <if test="isLeaf != null">
  204. #{isLeaf,jdbcType=BIGINT},
  205. </if>
  206. <if test="isFixed != null">
  207. #{isFixed,jdbcType=BIGINT},
  208. </if>
  209. <if test="groupDesc != null and groupDesc != ''">
  210. #{groupDesc,jdbcType=VARCHAR},
  211. </if>
  212. <if test="groupSelect != null and groupSelect != ''">
  213. #{groupSelect,jdbcType=VARCHAR},
  214. </if>
  215. <if test="createdBy != null">
  216. #{createdBy,jdbcType=BIGINT},
  217. </if>
  218. <if test="createdAt != null">
  219. #{createdAt,jdbcType=TIMESTAMP},
  220. </if>
  221. </trim>
  222. </insert>
  223. <!--更新群组-->
  224. <update id="update" parameterType="com.zhyc.xps.sys.entity.Group">
  225. UPDATE s_group
  226. <trim suffixOverrides=",">
  227. <set>
  228. <if test="groupName != null and groupName != ''">
  229. group_name = #{groupName,jdbcType=VARCHAR},
  230. </if>
  231. <if test="groupCode != null and groupCode != ''">
  232. group_code = #{groupCode,jdbcType=VARCHAR},
  233. </if>
  234. <if test="groupCatId != null">
  235. group_cat_id = #{groupCatId,jdbcType=BIGINT},
  236. </if>
  237. <if test="nodeLeft != null">
  238. node_left = #{nodeLeft,jdbcType=BIGINT},
  239. </if>
  240. <if test="nodeRight != null">
  241. node_right = #{nodeRight,jdbcType=BIGINT},
  242. </if>
  243. <if test="parentId != null">
  244. parent_id = #{parentId,jdbcType=BIGINT},
  245. </if>
  246. <if test="nodeLevel != null">
  247. node_level = #{nodeLevel,jdbcType=BIGINT},
  248. </if>
  249. <if test="groupDesc != null and groupDesc != ''">
  250. group_desc = #{groupDesc,jdbcType=VARCHAR},
  251. </if>
  252. <if test="isLeaf != null">
  253. is_leaf = #{isLeaf,jdbcType=BIGINT},
  254. </if>
  255. <if test="ocId != null">
  256. oc_id = #{ocId,jdbcType=BIGINT},
  257. </if>
  258. <if test="groupSelect != null and groupSelect != ''">
  259. group_select =#{groupSelect,jdbcType=VARCHAR},
  260. </if>
  261. <if test="updatedBy != null">
  262. updated_by = #{updatedBy,jdbcType=BIGINT},
  263. </if>
  264. <if test="updatedAt != null">
  265. updated_at = #{updatedAt,jdbcType=TIMESTAMP},
  266. </if>
  267. </set>
  268. </trim>
  269. WHERE oc_id = #{ocId,jdbcType=BIGINT} AND group_id = #{groupId ,jdbcType=BIGINT}
  270. </update>
  271. <!--删除角色 -->
  272. <update id="delete" parameterType="java.util.Map">
  273. UPDATE s_group
  274. <trim suffixOverrides=",">
  275. <set>
  276. <if test="deletedBy != null">
  277. deleted_by = #{deletedBy ,jdbcType=BIGINT},
  278. </if>
  279. <if test="deletedAt != null">
  280. deleted_at = #{deletedAt ,jdbcType=DATE},
  281. </if>
  282. <if test="deletedFlag != null">
  283. deleted_flag = #{deletedFlag ,jdbcType=BIGINT},
  284. </if>
  285. </set>
  286. </trim>
  287. WHERE deleted_flag = 0 AND oc_id = #{ocId,jdbcType=BIGINT}
  288. <if test="groupId != null ">
  289. AND group_id = #{groupId ,jdbcType=BIGINT}
  290. </if>
  291. <if test="nodeLeft != null">
  292. <![CDATA[
  293. AND node_left >= #{nodeLeft ,jdbcType=BIGINT}
  294. AND node_right <= #{nodeRight ,jdbcType=BIGINT}
  295. ]]>
  296. </if>
  297. </update>
  298. </mapper>