123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?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.department_name as department,
- b.role_name as role,
- a.role as roleId,
- a.department as departmentId
- from tld_user a
- left join tld_role b on a.role = b.id
- left join tld_department c on a.department = c.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="id != null and id != ''">
- and a.id = #{id}
- </if>
- </trim>
- </select>
- <!-- 新增用户 -->
- <insert id="addUser">
- <selectKey resultType="java.lang.Integer" 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)
- values(#{userName},#{password},#{realName},#{email},#{landline},#{phone},#{department},#{role}, DATE_FORMAT(NOW(), '%Y-%m-%d'))
- </insert>
- <!-- 修改指定用户信息 -->
- <update id="updateUser">
- update tld_user
- <set>
- <trim suffixOverrides=",">
- <if test="code != null and code != ''">
- code = #{code},
- </if>
- <if test="userName != null and userName != ''">
- user_name = #{userName},
- </if>
- <if test="password != null and password != ''">
- password = #{password},
- </if>
- <if test="realName != null and realName != ''">
- real_name = #{realName},
- </if>
- <if test="email != null and email != ''">
- email = #{email},
- </if>
- <if test="landline != null and landline != ''">
- landline = #{landline},
- </if>
- <if test="phone != null and phone != ''">
- phone = #{phone},
- </if>
- <if test="department != null and department != ''">
- department = #{department},
- </if>
- <if test="role != null and role != ''">
- role = #{role},
- </if>
- </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,
- a.real_name,
- a.email,
- a.landline,
- a.phone,
- c.department_name as department,
- b.role_name as role,
- a.create_time
- from tld_user a
- left join tld_role b on a.role = b.id
- left join tld_department c on a.department = c.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>
- </trim>
- </select>
- </mapper>
|