123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.kmall.common.dao.SysUserDao">
- <select id="queryObject" resultType="com.kmall.common.entity.SysUserEntity">
- SELECT
- u.*, ( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName, ur.role_id
- FROM
- sys_user u
- LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
- where u.user_id = #{value}
- </select>
-
- <select id="queryList" resultType="com.kmall.common.entity.SysUserEntity">
- SELECT
- u.*,
- ( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName,
- ur.role_id
- FROM
- sys_user u
- LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
- <where>
- <if test="createUserId != null">
- and `create_user_id` = #{createUserId}
- </if>
- <if test="username != null and username.trim() != ''">
- and u.`username` like concat('%',#{username},'%')
- </if>
- </where>
- <choose>
- <when test="sidx != null and sidx.trim() != ''">
- order by u.${sidx} ${order}
- </when>
- <otherwise>
- order by u.user_id desc
- </otherwise>
- </choose>
- <if test="offset != null and limit != null">
- limit #{offset}, #{limit}
- </if>
- </select>
-
- <select id="queryTotal" resultType="int">
- select count(*) from sys_user
- <where>
- <if test="createUserId != null">
- and `create_user_id` = #{createUserId}
- </if>
- <if test="username != null and username.trim() != ''">
- and `username` like concat('%',#{username},'%')
- </if>
- <if test="status != null and status.trim() != ''">
- and `status` = #{status}
- </if>
- </where>
- </select>
-
- <!-- 查询用户的所有权限 -->
- <select id="queryAllPerms" resultType="string">
- select m.perms from sys_user_role ur
- LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
- LEFT JOIN sys_menu m on rm.menu_id = m.menu_id
- where ur.user_id = #{userId}
- </select>
-
- <!-- 查询用户的所有菜单ID -->
- <select id="queryAllMenuId" resultType="long">
- select distinct rm.menu_id from sys_user_role ur
- LEFT JOIN sys_role_menu rm on ur.role_id = rm.role_id
- where ur.user_id = #{userId}
- </select>
-
- <select id="queryByUserName" resultType="com.kmall.common.entity.SysUserEntity">
- select * from sys_user where username = #{username}
- </select>
-
- <insert id="save" parameterType="com.kmall.common.entity.SysUserEntity" useGeneratedKeys="true" keyProperty="userId">
- insert into sys_user
- (
- `user_id`,
- `username`,
- `password`,
- `email`,
- `mobile`,
- `status`,
- `create_user_id`,
- `dept_id`,
- `store_id`,
- `role_type`,
- `create_time`
- )
- values
- (
- #{userId},
- #{username},
- #{password},
- #{email},
- #{mobile},
- #{status},
- #{createUserId},
- #{deptId},
- #{storeId},
- #{roleType},
- #{createTime}
- )
- </insert>
-
- <update id="update" parameterType="com.kmall.common.entity.SysUserEntity">
- update sys_user
- <set>
- <if test="username != null">`username` = #{username}, </if>
- <if test="email != null">`email` = #{email}, </if>
- <if test="mobile != null">`mobile` = #{mobile}, </if>
- <if test="status != null">`status` = #{status}, </if>
- <if test="deptId != null">`dept_id` = #{deptId}, </if>
- <if test="storeId != null">`store_id` = #{storeId}, </if>
- <if test="roleType != null">`role_type` = #{roleType}, </if>
- </set>
- where user_id = #{userId}
- <if test="createUserId != null">
- and `create_user_id` = #{createUserId}
- </if>
- </update>
-
- <update id="updatePassword" parameterType="map">
- update sys_user set `password` = #{newPassword}
- where user_id = #{userId} and password = #{password}
- </update>
-
- <delete id="deleteBatch">
- delete from sys_user where user_id in
- <foreach item="userId" collection="array" open="(" separator="," close=")">
- #{userId}
- </foreach>
- ;
- delete from sys_user_role where user_id in
- <foreach item="userId" collection="array" open="(" separator="," close=")">
- #{userId}
- </foreach>
- </delete>
- </mapper>
|