SysUnitMapper.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.jiayue.system.mapper.SysUnitMapper">
  6. <resultMap type="SysUnit" id="SysUnitResult">
  7. <id property="unitId" column="unit_id"/>
  8. <result property="parentId" column="parent_id"/>
  9. <result property="ancestors" column="ancestors"/>
  10. <result property="unitNo" column="unit_no"/>
  11. <result property="unitName" column="unit_name"/>
  12. <result property="unitCategory" column="unit_category"/>
  13. <result property="orderNum" column="order_num"/>
  14. <result property="leader" column="leader"/>
  15. <result property="phone" column="phone"/>
  16. <result property="email" column="email"/>
  17. <result property="status" column="status"/>
  18. <result property="delFlag" column="del_flag"/>
  19. <result property="parentName" column="parent_name"/>
  20. <result property="createBy" column="create_by"/>
  21. <result property="createTime" column="create_time"/>
  22. <result property="updateBy" column="update_by"/>
  23. <result property="updateTime" column="update_time"/>
  24. <result property="remark" column="remark"/>
  25. </resultMap>
  26. <sql id="selectUnitVo">
  27. select d.unit_id, d.parent_id, d.ancestors, d.unit_no, d.unit_name, d.unit_category, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time, d.update_by, d.update_time, d.remark
  28. from sys_unit d
  29. </sql>
  30. <select id="selectUnitList" parameterType="SysUnit" resultMap="SysUnitResult">
  31. <include refid="selectUnitVo"/>
  32. where d.del_flag = '0'
  33. <if test="unitId != null and unitId != 0">
  34. AND unit_id = #{unitId}
  35. </if>
  36. <if test="parentId != null and parentId != 0">
  37. AND parent_id = #{parentId}
  38. </if>
  39. <if test="unitNo != null and unitNo != ''">
  40. AND unit_no = #{unitNo}
  41. </if>
  42. <if test="unitName != null and unitName != ''">
  43. AND unit_name like concat('%', #{unitName}, '%')
  44. </if>
  45. <if test="unitCategory != null and unitCategory != ''">
  46. AND unit_category = #{unitCategory}
  47. </if>
  48. <if test="status != null and status != ''">
  49. AND status = #{status}
  50. </if>
  51. <!-- 数据范围过滤 -->
  52. ${params.dataScope}
  53. order by d.parent_id, d.order_num
  54. </select>
  55. <select id="selectUnitListByRoleId" resultType="Long">
  56. select d.unit_id
  57. from sys_unit d
  58. left join sys_role_unit rd on d.unit_id = rd.unit_id
  59. where rd.role_id = #{roleId}
  60. <if test="unitCheckStrictly">
  61. and d.unit_id not in (select d.parent_id from sys_unit d inner join sys_role_unit rd on
  62. d.unit_id = rd.unit_id and rd.role_id = #{roleId})
  63. </if>
  64. order by d.parent_id, d.order_num
  65. </select>
  66. <select id="selectUnitById" parameterType="Long" resultMap="SysUnitResult">
  67. <include refid="selectUnitVo"/>
  68. where unit_id = #{unitId}
  69. </select>
  70. <select id="checkUnitExistUser" parameterType="Long" resultType="int">
  71. select count(1) from sys_user where unit_id = #{unitId} and del_flag = '0'
  72. </select>
  73. <select id="hasChildByUnitId" parameterType="Long" resultType="int">
  74. select count(1) from sys_unit
  75. where del_flag = '0' and parent_id = #{unitId} limit 1
  76. </select>
  77. <select id="selectChildrenUnitById" parameterType="Long" resultMap="SysUnitResult">
  78. select * from sys_unit where find_in_set(#{unitId}, ancestors)
  79. </select>
  80. <select id="selectNormalChildrenUnitById" parameterType="Long" resultType="int">
  81. select count(*) from sys_unit where status = 0 and del_flag = '0' and find_in_set(#{unitId}, ancestors)
  82. </select>
  83. <select id="checkUnitNameUnique" resultMap="SysUnitResult">
  84. <include refid="selectUnitVo"/>
  85. where unit_name = #{unitName} and parent_id = #{parentId} limit 1
  86. </select>
  87. <insert id="insertUnit" parameterType="SysUnit">
  88. insert into sys_unit(
  89. <if test="unitId != null and unitId != 0">unit_id,</if>
  90. <if test="parentId != null and parentId != 0">parent_id,</if>
  91. <if test="unitNo != null and unitNo != ''">unit_no,</if>
  92. <if test="unitName != null and unitName != ''">unit_name,</if>
  93. <if test="unitCategory != null and unitCategory != ''">unit_category,</if>
  94. <if test="ancestors != null and ancestors != ''">ancestors,</if>
  95. <if test="orderNum != null">order_num,</if>
  96. <if test="leader != null and leader != ''">leader,</if>
  97. <if test="phone != null and phone != ''">phone,</if>
  98. <if test="email != null and email != ''">email,</if>
  99. <if test="status != null">status,</if>
  100. <if test="delFlag != null">del_flag,</if>
  101. <if test="createBy != null and createBy != ''">create_by,</if>
  102. <if test="updateBy != null and updateBy != ''">update_by,</if>
  103. <if test="remark != null and remark != ''">remark,</if>
  104. create_time,
  105. update_time
  106. )values(
  107. <if test="unitId != null and unitId != 0">#{unitId},</if>
  108. <if test="parentId != null and parentId != 0">#{parentId},</if>
  109. <if test="unitNo != null and unitNo != ''">#{unitNo},</if>
  110. <if test="unitName != null and unitName != ''">#{unitName},</if>
  111. <if test="unitCategory != null and unitCategory != ''">#{unitCategory},</if>
  112. <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
  113. <if test="orderNum != null">#{orderNum},</if>
  114. <if test="leader != null and leader != ''">#{leader},</if>
  115. <if test="phone != null and phone != ''">#{phone},</if>
  116. <if test="email != null and email != ''">#{email},</if>
  117. <if test="status != null">#{status},</if>
  118. <if test="delFlag != null">#{delFlag},</if>
  119. <if test="createBy != null and createBy != ''">#{createBy},</if>
  120. <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
  121. <if test="remark != null and remark != ''">#{remark},</if>
  122. sysdate(),
  123. sysdate()
  124. )
  125. </insert>
  126. <update id="updateUnit" parameterType="SysUnit">
  127. update sys_unit
  128. <set>
  129. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  130. <if test="unitNo != null and unitNo != ''">unit_no = #{unitNo},</if>
  131. <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
  132. <if test="unitCategory != null and unitCategory != ''">
  133. unit_category = #{unitCategory},
  134. </if>
  135. <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
  136. <if test="orderNum != null">order_num = #{orderNum},</if>
  137. <if test="leader != null">leader = #{leader},</if>
  138. <if test="phone != null">phone = #{phone},</if>
  139. <if test="email != null">email = #{email},</if>
  140. <if test="status != null and status != ''">status = #{status},</if>
  141. <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
  142. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  143. <if test="remark != null">remark = #{remark},</if>
  144. update_time = sysdate()
  145. </set>
  146. where unit_id = #{unitId}
  147. </update>
  148. <update id="updateUnitChildren" parameterType="java.util.List">
  149. update sys_unit set ancestors =
  150. <foreach collection="units" item="item" index="index"
  151. separator=" " open="case unit_id" close="end">
  152. when #{item.unitId} then #{item.ancestors}
  153. </foreach>
  154. where unit_id in
  155. <foreach collection="units" item="item" index="index"
  156. separator="," open="(" close=")">
  157. #{item.unitId}
  158. </foreach>
  159. </update>
  160. <update id="updateUnitStatusNormal" parameterType="Long">
  161. update sys_unit set status = '0' where unit_id in
  162. <foreach collection="array" item="unitId" open="(" separator="," close=")">
  163. #{unitId}
  164. </foreach>
  165. </update>
  166. <delete id="deleteUnitById" parameterType="Long">
  167. update sys_unit set del_flag = '2' where unit_id = #{unitId}
  168. </delete>
  169. <select id="selectUnitListByNo" parameterType="java.util.List" resultMap="SysUnitResult">
  170. <include refid="selectUnitVo"/>
  171. where d.unit_no IN
  172. <foreach collection="unitNoList" index="index" item="unitNo" open="(" separator=","
  173. close=")">
  174. #{unitNo}
  175. </foreach>
  176. </select>
  177. </mapper>