TenantMapper.xml 7.1 KB

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