TenantMapper.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.huaxu.dao.TenantMapper">
  4. <sql id="Base_Column_List">
  5. t.id as "id"
  6. ,t.TENANT_NAME as "tenantName"
  7. ,u.id as "userId"
  8. ,u.USERNAME as "userName"
  9. ,u.PHONE as "phone"
  10. ,t.`CODE` as "code"
  11. ,t.`tenant_type` as "tenantType"
  12. ,t.LOGO as "logo"
  13. ,t.WEB_URL as "webUrl"
  14. ,t.DATE_CREATE as "dateCreate"
  15. ,dict.DICT_VALUE as "tenantTypeValue"
  16. </sql>
  17. <sql id="tenantJoins">
  18. left join uims_user u on t.code=u.TENANT_ID and u.USER_TYPE='-999' and u.status =1
  19. left join (
  20. select d.DICT_CODE,d.DICT_VALUE
  21. from uims_dict p
  22. left join uims_dict d on d.PARENT_DICT_ID=p.id and d.status =1
  23. where p.DICT_CODE = 'SYSTEM_TENANT_TYPE'and p.status =1
  24. )dict on dict .DICT_CODE= t.TENANT_TYPE
  25. </sql>
  26. <select id="selectById" resultType="com.huaxu.dto.TenantDto">
  27. select
  28. <include refid="Base_Column_List"/>
  29. from uims_tenant t
  30. <include refid="tenantJoins"/>
  31. where t.ID = #{id} and t.status = 1
  32. </select>
  33. <!-- 查询全部 -->
  34. <select id="selectAll" resultType="com.huaxu.dto.TenantDto">
  35. select
  36. <include refid="Base_Column_List"/>
  37. from uims_tenant t
  38. <include refid="tenantJoins"/>
  39. where t.status = 1
  40. </select>
  41. <!--通过实体作为筛选条件查询-->
  42. <select id="selectList" resultType="com.huaxu.dto.TenantDto">
  43. select
  44. <include refid="Base_Column_List"/>
  45. from uims_tenant t
  46. <include refid="tenantJoins"/>
  47. <where>
  48. t.status = 1
  49. <if test="tenantName != null and tenantName != ''">
  50. and TENANT_NAME like concat('%',#{tenantName},'%')
  51. </if>
  52. </where>
  53. </select>
  54. <!-- 新增所有列 -->
  55. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  56. insert into uims_tenant(TENANT_NAME,tenant_type ,CODE ,LOGO ,WEB_URL ,START_DATE ,END_DATE ,TENANT_STATE ,REMARK ,STATUS ,DATE_CREATE ,CREATE_BY ,DATE_UPDATE ,UPDATE_BY)
  57. values ( #{tenantName},#{tenantType}, #{code}, #{logo}, #{webUrl}, #{startDate}, #{endDate}, #{tenantState}, #{remark}, #{status},#{dateCreate},#{createBy},#{dateUpdate},#{updateBy})
  58. </insert>
  59. <!-- 批量新增 -->
  60. <insert id="batchInsert">
  61. insert into uims_tenant(ID ,TENANT_NAME ,CODE ,LOGO ,WEB_URL ,START_DATE ,END_DATE ,TENANT_STATE ,REMARK ,STATUS ,DATE_CREATE ,CREATE_BY ,DATE_UPDATE ,UPDATE_BY)
  62. values
  63. <foreach collection="tenants" item="item" index="index" separator=",">
  64. (
  65. #{item.id}, #{item.tenantName}, #{item.code}, #{item.logo}, #{item.webUrl}, #{item.startDate},#{item.endDate},
  66. #{item.tenantState}, #{item.remark}, #{item.status}, #{item.dateCreate}, #{item.createBy}, #{item.dateUpdate}, #{item.updateBy} )
  67. </foreach>
  68. </insert>
  69. <!-- 通过主键修改数据 -->
  70. <update id="update">
  71. update uims.uims_tenant
  72. <set>
  73. <if test="tenantName != null and tenantName != ''">
  74. TENANT_NAME = #{tenantName},
  75. </if>
  76. <if test="tenantType != null and tenantType != ''">
  77. tenant_type = #{tenantType},
  78. </if>
  79. <if test="code != null and code != ''">
  80. CODE = #{code},
  81. </if>
  82. <if test="logo != null and logo != ''">
  83. LOGO = #{logo},
  84. </if>
  85. <if test="webUrl != null and webUrl != ''">
  86. WEB_URL = #{webUrl},
  87. </if>
  88. <if test="startDate != null">
  89. START_DATE = #{startDate},
  90. </if>
  91. <if test="endDate != null ">
  92. END_DATE = #{tenantState},
  93. </if>
  94. <if test="tenantState != null">
  95. TENANT_STATE = #{tenantState},
  96. </if>
  97. <if test="remark != null and remark != ''">
  98. REMARK = #{remark},
  99. </if>
  100. <if test="status != null">
  101. STATUS = #{status},
  102. </if>
  103. <if test="dateUpdate != null">
  104. DATE_UPDATE = #{dateUpdate},
  105. </if>
  106. <if test="updateBy != null and remark != ''">
  107. UPDATE_BY = #{updateBy},
  108. </if>
  109. </set>
  110. where ID = #{id}
  111. </update>
  112. <!--通过主键删除-->
  113. <delete id="deleteById">
  114. update uims_tenant set status = 0 where ID = #{id}
  115. </delete>
  116. <delete id="deleteUserByTenantId">
  117. update uims_user u
  118. left join uims_tenant t on u.TENANT_ID=t.code
  119. set u.status = 1
  120. where t.id=#{id}
  121. </delete>
  122. <!-- 总数 -->
  123. <select id="count" resultType="int">
  124. select count(*) from uims_tenant and status =1
  125. </select>
  126. <select id="countIds" resultType="java.lang.Integer">
  127. select id from uims_tenant
  128. where TENANT_NAME =#{tenantName} and status =1
  129. </select>
  130. <!-- 分页查询 -->
  131. <select id="selectPage" resultType="com.huaxu.dto.TenantDto">
  132. select
  133. <include refid="Base_Column_List"/>
  134. from uims_tenant t
  135. <include refid="tenantJoins"/>
  136. <where>
  137. t.status = 1
  138. <if test="tenantDto.tenantName != null and tenantDto.tenantName != ''">
  139. and t.TENANT_NAME like concat('%',#{tenantDto.tenantName},'%')
  140. </if>
  141. </where>
  142. order by t.dateCreate desc
  143. </select>
  144. <!-- 生成租户菜单 -->
  145. <insert id="createTenantMenu">
  146. insert into uims_tenant_menu (TENANT_ID ,MENU_ID ,MENU_NAME ,MENU_IMAGE ,MENU_SEQ ,LINK_PATH ,STATUS
  147. ,DATE_CREATE ,CREATE_BY ,DATE_UPDATE ,UPDATE_BY)
  148. select
  149. #{tenantId},
  150. id,
  151. name,
  152. menu_image,
  153. seq,
  154. LINK_PATH,
  155. 1,
  156. now(),
  157. #{userName},
  158. now(),
  159. #{userName}
  160. from uims_menu
  161. where id in (
  162. <foreach collection="menuIds" item="item" index="index" separator=",">
  163. #{item}
  164. </foreach>
  165. )
  166. </insert>
  167. <!-- 通过租户id查询租户菜单id -->
  168. <select id="selectTenantMenuIds" resultType="java.lang.Integer">
  169. select MENU_ID from uims_tenant_menu where TENANT_ID = #{tenantId} and status =1
  170. </select>
  171. <delete id="deleteTenantMenuIds">
  172. delete from uims_tenant_menu
  173. where TENANT_ID=#{tenantId}
  174. <if test="menuIds != null">
  175. and MENU_ID in (
  176. <foreach collection="menuIds" item="item" index="index" separator=",">
  177. #{item}
  178. </foreach>
  179. )
  180. </if>
  181. </delete>
  182. </mapper>