TenantMapper.xml 6.9 KB

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