CommunityMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.jeeplus.modules.sys.mapper.CommunityMapper">
  4. <resultMap id="areaResult" type="Community">
  5. <id property="id" column="id" />
  6. <result property="parentIds" column="parentIds" />
  7. <result property="name" column="name" />
  8. <result property="sort" column="sort" />
  9. <result property="code" column="code" />
  10. <result property="type" column="type" />
  11. <association property="hasChildren" column="id" select="hasChildren" />
  12. </resultMap>
  13. <sql id="areaColumns">
  14. a.id,
  15. a.parent_id AS "parent.id",
  16. a.parent_ids,
  17. a.code,
  18. a.name,
  19. a.sort,
  20. a.type,
  21. a.remarks,
  22. a.create_by AS "createBy.id",
  23. a.create_date,
  24. a.update_by AS "updateBy.id",
  25. a.update_date,
  26. a.del_flag,
  27. p.name AS "parent.name"
  28. </sql>
  29. <sql id="areaJoins">
  30. LEFT JOIN sys_office p ON p.id = a.parent_id
  31. </sql>
  32. <select id="get" resultType="Community">
  33. SELECT
  34. <include refid="areaColumns"/>
  35. FROM sys_community a
  36. <include refid="areaJoins"/>
  37. WHERE a.id = #{id}
  38. </select>
  39. <select id="getChildren" parameterType="String" resultMap="areaResult">
  40. select * from sys_community where parent_id = #{id} ORDER BY code
  41. </select>
  42. <select id="hasChildren" parameterType="String" resultType="Boolean">
  43. select case when exists(select 1 from sys_community where parent_id = #{id}) then 1 else 0 end ${dual}
  44. </select>
  45. <select id="findList" resultType="Community">
  46. SELECT
  47. <include refid="areaColumns"/>
  48. FROM sys_community a
  49. <include refid="areaJoins"/>
  50. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  51. <!-- 数据范围过滤 -->
  52. ${dataScope}
  53. OR a.id = #{currentUser.office.area.id}
  54. ORDER BY a.code
  55. </select>
  56. <select id="findAllList" resultType="Community">
  57. SELECT
  58. <include refid="areaColumns"/>
  59. FROM sys_community a
  60. <include refid="areaJoins"/>
  61. WHERE a.del_flag = #{DEL_FLAG_NORMAL}
  62. ORDER BY a.code
  63. </select>
  64. <select id="findByParentIdsLike" resultType="Community">
  65. SELECT
  66. a.id,
  67. a.parent_id AS "parent.id",
  68. a.parent_ids
  69. FROM sys_community a
  70. WHERE a.del_flag = #{DEL_FLAG_NORMAL} AND a.parent_ids LIKE #{parentIds}
  71. ORDER BY a.code
  72. </select>
  73. <insert id="insert">
  74. INSERT INTO sys_community(
  75. id,
  76. parent_id,
  77. parent_ids,
  78. code,
  79. name,
  80. sort,
  81. type,
  82. create_by,
  83. create_date,
  84. update_by,
  85. update_date,
  86. remarks,
  87. del_flag
  88. ) VALUES (
  89. #{id},
  90. #{parent.id},
  91. #{parentIds},
  92. #{code},
  93. #{name},
  94. #{sort},
  95. #{type},
  96. #{createBy.id},
  97. #{createDate},
  98. #{updateBy.id},
  99. #{updateDate},
  100. #{remarks},
  101. #{delFlag}
  102. )
  103. </insert>
  104. <update id="update">
  105. UPDATE sys_community SET
  106. parent_id = #{parent.id},
  107. parent_ids = #{parentIds},
  108. code = #{code},
  109. name = #{name},
  110. sort = #{sort},
  111. type = #{type},
  112. update_by = #{updateBy.id},
  113. update_date = #{updateDate},
  114. remarks = #{remarks}
  115. WHERE id = #{id}
  116. </update>
  117. <update id="updateParentIds">
  118. UPDATE sys_community SET
  119. parent_id = #{parent.id},
  120. parent_ids = #{parentIds}
  121. WHERE id = #{id}
  122. </update>
  123. <update id="delete">
  124. DELETE FROM sys_community
  125. WHERE id = #{id} OR parent_ids LIKE
  126. <if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
  127. <if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
  128. <if test="dbName == 'mssql'">'%'+#{id}+'%'</if>
  129. </update>
  130. <update id="deleteByLogic">
  131. UPDATE sys_community SET
  132. del_flag = #{DEL_FLAG_DELETE}
  133. WHERE id = #{id} OR parent_ids LIKE
  134. <if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
  135. <if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
  136. <if test="dbName == 'mssql'">'%'+#{id}+'%'</if>
  137. </update>
  138. </mapper>