123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?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.tld.mapper.UserMapper">
- <sql id="userField">
- id,code,user_name,password,real_name,email,landline,phone,department,role
- </sql>
- <!-- 登录 -->
- <select id="login" resultType="com.tld.model.User">
- select
- a.id,
- a.code,
- a.user_name,
- a.password,
- a.real_name,
- a.email,
- a.landline,
- a.phone,
- a.department,
- a.role,
- b.menu
- from tld_user a
- left join tld_role b on a.role = b.id
- where a.user_name = #{userName} and a.password = #{password}
- </select>
- <!-- 查询所有用户 -->
- <select id="getAllUser" resultType="com.tld.model.User">
- select
- a.id,
- a.code,
- a.user_name,
- a.password,
- a.real_name,
- a.email,
- a.landline,
- a.phone,
- a.create_time,
- c.name as department,
- b.role_name as role,
- a.role as roleId,
- a.department as departmentId,
- a.modify_time as modifyTime,
- f.user_name as modifyUser
- from tld_user a
- left join tld_user f on a.modify_user = f.id
- left join tld_role b on a.role = b.id
- left join tld_department c on a.department = c.code
- <trim prefix="WHERE" prefixOverrides="and |or">
- <if test="code != null and code != ''">
- and a.code like CONCAT(CONCAT('%', #{code}), '%')
- </if>
- <if test="userName != null and userName != ''">
- and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
- </if>
- <if test="realName != null and realName != ''">
- and a.real_name like CONCAT(CONCAT('%', #{realName}), '%')
- </if>
- <if test="modifyUser != null and modifyUser != ''">
- and f.user_name like CONCAT(CONCAT('%', #{modifyUser}), '%')
- </if>
- <if test="role != null and role != ''">
- and b.role_name like CONCAT(CONCAT('%', #{role}), '%')
- </if>
- <if test="email != null and email != ''">
- and a.email like CONCAT(CONCAT('%', #{email}), '%')
- </if>
- <if test="landline != null and landline != ''">
- and a.landline like CONCAT(CONCAT('%', #{landline}), '%')
- </if>
- <if test="phone != null and phone != ''">
- and a.phone like CONCAT(CONCAT('%', #{phone}), '%')
- </if>
- <if test="department != null and department != ''">
- and a.department = #{department}
- </if>
- <if test="id != null and id != ''">
- and a.id = #{id}
- </if>
- </trim>
- order by a.id desc
- </select>
- <!-- 新增用户 -->
- <insert id="addUser">
- <selectKey resultType="java.lang.String" order="AFTER" keyProperty="id">
- select LAST_INSERT_ID()
- </selectKey>
- insert into tld_user(user_name,password,real_name,email,landline,phone,department,role,create_time,modify_user,modify_time)
- values(#{userName},#{password},#{realName},#{email},#{landline},#{phone},#{department},#{role},NOW(),#{modifyUser},now())
- </insert>
- <!-- 修改指定用户信息 -->
- <update id="updateUser">
- update tld_user
- <set>
- <trim suffixOverrides=",">
- <if test="code != null">
- code = #{code},
- </if>
- <if test="userName != null">
- user_name = #{userName},
- </if>
- <if test="password != null">
- password = #{password},
- </if>
- <if test="realName != null">
- real_name = #{realName},
- </if>
- <if test="email != null">
- email = #{email},
- </if>
- <if test="landline != null">
- landline = #{landline},
- </if>
- <if test="phone != null">
- phone = #{phone},
- </if>
- <if test="department != null">
- department = #{department},
- </if>
- <if test="role != null">
- role = #{role},
- </if>
- modify_user = #{modifyUser},modify_time=now(),
- </trim>
- </set>
- where id = #{id}
- </update>
- <!-- 删除用户 -->
- <delete id="delUser">
- delete from tld_user where id = #{id}
- </delete>
- <!-- 查询用户名是否存在 -->
- <select id="getUserIsNot" resultType="int">
- select count(*) from tld_user where user_name = #{userName} and id != #{id}
- </select>
- <!-- 查询导出数据 -->
- <select id="getUserExportData" resultType="java.util.LinkedHashMap">
- select
- a.code,
- a.user_name,
- if(a.real_name = '', null , a.real_name) as real_name,
- if(a.email = '', null , a.email) as email,
- if(a.landline = '', null , a.landline) as landline,
- if(a.phone = '', null , a.phone) as phone,
- c.name as department,
- b.role_name as role
- from tld_user a
- left join tld_role b on a.role = b.id
- left join tld_department c on a.department = c.code
- left join tld_user f on a.modify_user = f.id
- <trim prefix="WHERE" prefixOverrides="and |or">
- <if test="code != null and code != ''">
- and a.code like CONCAT(CONCAT('%', #{code}), '%')
- </if>
- <if test="userName != null and userName != ''">
- and a.user_name like CONCAT(CONCAT('%', #{userName}), '%')
- </if>
- <if test="realName != null and realName != ''">
- and a.real_name like CONCAT(CONCAT('%', #{realName}), '%')
- </if>
- <if test="role != null and role != ''">
- and b.role_name like CONCAT(CONCAT('%', #{role}), '%')
- </if>
- <if test="email != null and email != ''">
- and a.email like CONCAT(CONCAT('%', #{email}), '%')
- </if>
- <if test="landline != null and landline != ''">
- and a.landline like CONCAT(CONCAT('%', #{landline}), '%')
- </if>
- <if test="phone != null and phone != ''">
- and a.phone like CONCAT(CONCAT('%', #{phone}), '%')
- </if>
- <if test="modifyUser != null and modifyUser != ''">
- and f.user_name like CONCAT(CONCAT('%', #{modifyUser}), '%')
- </if>
- <if test="department != null and department != ''">
- and a.department = #{department}
- </if>
- </trim>
- order by a.id desc
- </select>
- <!-- 查询指定用户内容 -->
- <select id="getUser" resultType="com.tld.model.User">
- select
- id,
- code,
- user_name,
- password,
- real_name,
- email,
- landline,
- phone,
- department,
- role
- from tld_user
- where id = #{id}
- </select>
- </mapper>
|