You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
11 KiB

  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.iformall.mapper.MallUserInfoMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallUserInfo">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="username" jdbcType="VARCHAR" property="username"/>
  8. <result column="name" jdbcType="VARCHAR" property="name"/>
  9. <result column="password" jdbcType="VARCHAR" property="password"/>
  10. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  11. <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime"/>
  12. <result column="status" jdbcType="INTEGER" property="status"/>
  13. <result column="is_admin" jdbcType="INTEGER" property="isAdmin"/>
  14. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  15. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  16. <result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/>
  17. <result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/>
  18. <result column="email" property="email"/>
  19. </resultMap>
  20. <sql id="allSafeColumns">
  21. `id`,`tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`nick_name`,`phone`,`web_open_id`,email
  22. </sql>
  23. <sql id="allColumns">
  24. `id`,`tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`nick_name`,`phone`,
  25. `bopen_id`,`web_open_id`,email
  26. </sql>
  27. <sql id="dynamicWhereConditions">
  28. where 1 = 1
  29. <if test=" null != id ">
  30. and `id` = #{id}
  31. </if>
  32. <if test=" null != tenantId ">
  33. and `tenant_id` = #{tenantId}
  34. </if>
  35. <if test=" null != username ">
  36. and `username` like concat('%', #{username},'%')
  37. </if>
  38. <if test=" null != nickName ">
  39. and `nick_name` like concat('%', #{nickName},'%')
  40. </if>
  41. <if test=" null != name ">
  42. and `name` like concat('%', #{name},'%')
  43. </if>
  44. <if test=" null != password ">
  45. and `password` like concat('%', #{password},'%')
  46. </if>
  47. <if test=" null != createTime ">
  48. and `create_time` = #{createTime}
  49. </if>
  50. <if test=" null != lastLoginTime ">
  51. and `last_login_time` = #{lastLoginTime}
  52. </if>
  53. <if test=" null != status ">
  54. and `status` = #{status}
  55. </if>
  56. <if test=" null != isAdmin ">
  57. and `is_admin` = #{isAdmin}
  58. </if>
  59. <if test=" null != phone and ''!=phone">
  60. and `phone` = #{phone}
  61. </if>
  62. <if test=" null != bopenId ">
  63. and `bopen_id` = #{bopenId}
  64. </if>
  65. <if test=" null != webOpenId ">
  66. and `web_open_id` = #{webOpenId}
  67. </if>
  68. <if test=" null != email ">
  69. and `email` = #{email}
  70. </if>
  71. <if test="null != withWechatForQuery ">
  72. <if test="0 == withWechatForQuery ">
  73. and `web_open_id` is not null
  74. </if>
  75. <if test="1 == withWechatForQuery ">
  76. and `web_open_id` is null
  77. </if>
  78. </if>
  79. <if test=" null != ids ">
  80. and id in
  81. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  82. #{idItem}
  83. </foreach>
  84. </if>
  85. <if test=" null != sortColumns">order by ${sortColumns}</if>
  86. </sql>
  87. <select id="findList" parameterType="com.iformall.domain.po.MallUserInfo" resultMap="BaseResultMap">
  88. select
  89. <include refid="allSafeColumns"/>
  90. from mall_user_info
  91. <include refid="dynamicWhereConditions"/>
  92. </select>
  93. <select id="selectByUserName" resultMap="BaseResultMap">
  94. select
  95. <include refid="allColumns"/>
  96. from mall_user_info
  97. where 1=1
  98. <if test=" null != username ">
  99. and username=#{username}
  100. </if>
  101. </select>
  102. <select id="getById" resultMap="BaseResultMap">
  103. select
  104. <include refid="allSafeColumns"/>
  105. from mall_user_info
  106. where 1=1
  107. <if test=" null != id ">
  108. and id=#{id}
  109. </if>
  110. </select>
  111. <select id="selectByUserNameWebOpen" resultMap="BaseResultMap">
  112. select
  113. <include refid="allColumns"/>
  114. from mall_user_info
  115. where 1=1
  116. <if test=" null != username ">
  117. and username=#{username}
  118. </if>
  119. <if test=" null != webOpenId ">
  120. and `web_open_id`=#{webOpenId}
  121. </if>
  122. </select>
  123. <select id="selectByBOpenId" resultMap="BaseResultMap">
  124. select
  125. <include refid="allSafeColumns"/>
  126. from mall_user_info
  127. where 1=1
  128. <if test=" null != tenantId ">
  129. and `tenant_id`=#{tenantId}
  130. </if>
  131. <if test=" null != bopenId ">
  132. and `bopen_id`=#{bopenId}
  133. </if>
  134. </select>
  135. <select id="selectByWebOpenId" resultMap="BaseResultMap">
  136. select
  137. <include refid="allColumns"/>
  138. from mall_user_info
  139. where 1=1
  140. <if test=" null != webOpenId ">
  141. and `web_open_id`=#{webOpenId}
  142. </if>
  143. </select>
  144. <update id="removeWebOpenId" >
  145. update mall_user_info
  146. set `web_open_id` = null
  147. where 1=1
  148. <if test=" null != tenantId ">
  149. and `tenant_id`=#{tenantId}
  150. </if>
  151. <if test=" null != username ">
  152. and username=#{username}
  153. </if>
  154. <if test=" null != id ">
  155. and `id` = #{id}
  156. </if>
  157. </update>
  158. <update id="removeAllOpenId" >
  159. update mall_user_info
  160. set `web_open_id` = null, `bopen_id` = null
  161. where 1=1
  162. <if test=" null != tenantId ">
  163. and `tenant_id`=#{tenantId}
  164. </if>
  165. <if test=" null != username ">
  166. and username=#{username}
  167. </if>
  168. <if test=" null != id ">
  169. and `id` = #{id}
  170. </if>
  171. </update>
  172. <select id="selectByPhone" resultMap="BaseResultMap">
  173. select
  174. <include refid="allColumns"/>
  175. from mall_user_info
  176. where 1=1
  177. <if test=" null != tenantId ">
  178. and `tenant_id`=#{tenantId}
  179. </if>
  180. <if test=" null != phone ">
  181. and `phone`=#{phone}
  182. </if>
  183. </select>
  184. <select id="hasButtonPermission" resultType="java.lang.Integer">
  185. SELECT 1
  186. FROM mall_user_role ur, mall_user_role_permission rp, mall_permission p
  187. WHERE rp.role_id = ur.role_id
  188. AND rp.permission_id = p.id
  189. AND p.resource_type = 1
  190. AND ur.uid = #{userId}
  191. AND p.permission = #{permission}
  192. </select>
  193. <select id="cntByUserName" resultType="java.lang.Integer">
  194. select count(*) from mall_user_info where status = 1
  195. <if test=" null != username ">
  196. and username=#{username}
  197. </if>
  198. <if test=" null != phone ">
  199. and `phone` = #{phone}
  200. </if>
  201. <if test=" null != id ">
  202. and `id` != #{id}
  203. </if>
  204. </select>
  205. <!-- 查询用户的所有权限 -->
  206. <select id="queryAllMenu" resultType="com.iformall.domain.po.MallPermission">
  207. select p.*
  208. from mall_permission p
  209. LEFT JOIN mall_role_permission rp on rp.permission_id = p.id
  210. LEFT JOIN mall_user_role ur on ur.role_id = rp.role_id
  211. where ur.uid = #{userId}
  212. </select>
  213. <!-- 查询用户的所有权限 -->
  214. <select id="queryAllPerms" resultType="string">
  215. select p.permission from mall_user_role ur
  216. LEFT JOIN mall_role_permission rp on ur.role_id = rp.role_id
  217. LEFT JOIN mall_permission p on rp.permission_id = p.id
  218. where ur.uid = #{userId}
  219. </select>
  220. <!-- 查询用户的所有菜单ID -->
  221. <select id="queryAllMenuId" resultType="long">
  222. select distinct rp.permission_id from mall_user_role ur
  223. LEFT JOIN mall_role_permission rp on ur.role_id = rp.role_id
  224. where ur.uid = #{userId}
  225. </select>
  226. <resultMap id="VBaseResultMap" type="com.iformall.domain.vo.MallUserInfoVo">
  227. <id column="id" jdbcType="BIGINT" property="id"/>
  228. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  229. <result column="username" jdbcType="VARCHAR" property="username"/>
  230. <result column="name" jdbcType="VARCHAR" property="name"/>
  231. <result column="password" jdbcType="VARCHAR" property="password"/>
  232. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  233. <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime"/>
  234. <result column="status" jdbcType="INTEGER" property="status"/>
  235. <result column="is_admin" jdbcType="INTEGER" property="isAdmin"/>
  236. <result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
  237. <result column="phone" jdbcType="VARCHAR" property="phone"/>
  238. <result column="bopen_id" jdbcType="VARCHAR" property="bopenId"/>
  239. <result column="web_open_id" jdbcType="VARCHAR" property="webOpenId"/>
  240. <result column="email" property="email"/>
  241. <result column="mall_name" jdbcType="VARCHAR" property="mallName"/>
  242. <result column="mall_group" jdbcType="VARCHAR" property="mallGroup"/>
  243. <result column="img_url" jdbcType="VARCHAR" property="imgUrl"/>
  244. <result column="img_url_h" jdbcType="VARCHAR" property="imgUrlH"/>
  245. </resultMap>
  246. <sql id="allSafeVColumns">
  247. u.`id`,u.`tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`nick_name`,u.`phone`,
  248. m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,email
  249. </sql>
  250. <sql id="allVColumns">
  251. u.`id`,u.`tenant_id`,u.`username`,u.`name`,u.`password`,u.`create_time`,u.`last_login_time`,u.`status`,u.`is_admin`,u.`nick_name`,u.`phone`,
  252. u.`bopen_id`,u.`web_open_id`,
  253. m.`name` as mall_name, m.`group` as mall_group, m.`img_url`, m.`img_url_h`,email
  254. </sql>
  255. <select id="selectUsersByPhone" resultMap="VBaseResultMap">
  256. select
  257. <include refid="allSafeVColumns"/>
  258. from mall_user_info u
  259. left join wx_mall m on m.`tenant_id` = u.`tenant_id`
  260. where 1=1
  261. <if test=" null != phone ">
  262. and u.`phone` = #{phone}
  263. </if>
  264. </select>
  265. <select id="selectUsersByWebOpenId" resultMap="VBaseResultMap">
  266. select
  267. <include refid="allSafeVColumns"/>
  268. from mall_user_info u
  269. left join wx_mall m on m.`tenant_id` = u.`tenant_id`
  270. where 1=1
  271. <if test=" null != webOpenId ">
  272. and u.`web_open_id` = #{webOpenId}
  273. </if>
  274. </select>
  275. </mapper>