123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- <?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.liang.dao.SysUserInfoDao">
- <resultMap type="com.liang.entity.SysUserInfo" id="SysUserInfoMap">
- <result property="userId" column="user_id" jdbcType="INTEGER"/>
- <result property="account" column="account" jdbcType="VARCHAR"/>
- <result property="password" column="password" jdbcType="VARCHAR"/>
- <result property="name" column="name" jdbcType="VARCHAR"/>
- <result property="deptId" column="dept_id" jdbcType="INTEGER"/>
- <result property="phone" column="phone" jdbcType="VARCHAR"/>
- <result property="email" column="email" jdbcType="VARCHAR"/>
- <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
- <result property="sex" column="sex" jdbcType="VARCHAR"/>
- <result property="status" column="status" jdbcType="VARCHAR"/>
- <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
- <result property="createUser" column="create_user" jdbcType="INTEGER"/>
- <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
- <result property="updateUser" column="update_user" jdbcType="INTEGER"/>
- <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
- <result property="bz" column="bz" jdbcType="VARCHAR"/>
- </resultMap>
- <!--查询单个-->
- <select id="queryById" resultMap="SysUserInfoMap">
- select u.*, d.dept_name as deptName, d1.dept_name as deptName1, d2.dept_name as deptName2,u.bz
- from sys_user_info u
- left join sys_dept_info d on d.dept_id = u.dept_id
- left join sys_dept_info d1 on d1.dept_id = d.parent_id
- left join sys_dept_info d2 on d2.dept_id = d1.parent_id
- where user_id = #{userId}
- </select>
- <!--查询指定行数据-->
- <select id="queryAllByLimit" resultMap="SysUserInfoMap">
- select
- user_id, account, password, name, dept_id, phone, email, avatar, sex, status, del_flag, create_user,
- create_time, update_user, update_time
- from sys_user_info
- <where>
- <if test="userId != null">
- and user_id = #{userId}
- </if>
- <if test="account != null and account != ''">
- and account = #{account}
- </if>
- <if test="password != null">
- and password = #{password}
- </if>
- <if test="name != null and name != ''">
- and name = #{name}
- </if>
- <if test="deptId != null and deptId != ''">
- and dept_id = #{deptId}
- </if>
- <if test="phone != null">
- and phone = #{phone}
- </if>
- <if test="email != null">
- and email = #{email}
- </if>
- <if test="avatar != null">
- and avatar = #{avatar}
- </if>
- <if test="sex != null and sex != ''">
- and sex = #{sex}
- </if>
- <if test="status != null and status != ''">
- and status = #{status}
- </if>
- <if test="delFlag != null and delFlag != ''">
- and del_flag = #{delFlag}
- </if>
- <if test="createUser != null">
- and create_user = #{createUser}
- </if>
- <if test="createTime != null">
- and create_time = #{createTime}
- </if>
- <if test="updateUser != null">
- and update_user = #{updateUser}
- </if>
- <if test="updateTime != null">
- and update_time = #{updateTime}
- </if>
- </where>
- limit #{pageable.offset}, #{pageable.pageSize}
- </select>
- <!--统计总行数-->
- <select id="count" resultType="java.lang.Long">
- select count(1)
- from sys_user_info
- where del_flag = 0
- <if test="userId != null">
- and user_id = #{userId}
- </if>
- <if test="account != null and account != ''">
- and account = #{account}
- </if>
- <if test="password != null">
- and password = #{password}
- </if>
- <if test="name != null and name != ''">
- and name = #{name}
- </if>
- <if test="deptId != null and deptId != ''">
- and dept_id = #{deptId}
- </if>
- <if test="phone != null">
- and phone = #{phone}
- </if>
- <if test="email != null">
- and email = #{email}
- </if>
- <if test="avatar != null">
- and avatar = #{avatar}
- </if>
- <if test="sex != null and sex != ''">
- and sex = #{sex}
- </if>
- <if test="status != null and status != ''">
- and status = #{status}
- </if>
- <if test="delFlag != null and delFlag != ''">
- and del_flag = #{delFlag}
- </if>
- <if test="createUser != null">
- and create_user = #{createUser}
- </if>
- <if test="createTime != null">
- and create_time = #{createTime}
- </if>
- <if test="updateUser != null">
- and update_user = #{updateUser}
- </if>
- <if test="updateTime != null">
- and update_time = #{updateTime}
- </if>
- </select>
- <!--新增所有列-->
- <insert id="insert" keyProperty="userId" useGeneratedKeys="true">
- if
- not exists (select * from sys_user_info where account =
- #{account}
- and
- del_flag
- =
- 0
- )
- insert
- into
- sys_user_info
- (
- account,
- password,
- name,
- dept_id,
- phone,
- email,
- avatar,
- sex,
- create_user,
- create_time
- )
- values
- (
- #{account},
- #{password},
- #{name},
- #{deptId},
- #{phone},
- #{email},
- #{avatar},
- #{sex},
- #{createUser},
- GETDATE
- (
- )
- )
- </insert>
- <insert id="insertBatch" keyProperty="userId" useGeneratedKeys="true">
- insert into sys_user_info(account, password, name, dept_id, phone, email, avatar, sex, status, del_flag,
- create_user, create_time, update_user, update_time)
- values
- <foreach collection="entities" item="entity" separator=",">
- (#{entity.account}, #{entity.password}, #{entity.name}, #{entity.deptId}, #{entity.phone}, #{entity.email},
- #{entity.avatar}, #{entity.sex}, #{entity.status}, #{entity.delFlag}, #{entity.createUser},
- #{entity.createTime}, #{entity.updateUser}, #{entity.updateTime})
- </foreach>
- </insert>
- <insert id="insertOrUpdateBatch" keyProperty="userId" useGeneratedKeys="true">
- insert into sys_user_info(account, password, name, dept_id, phone, email, avatar, sex, status, del_flag,
- create_user, create_time, update_user, update_time)
- values
- <foreach collection="entities" item="entity" separator=",">
- (#{entity.account}, #{entity.password}, #{entity.name}, #{entity.deptId}, #{entity.phone}, #{entity.email},
- #{entity.avatar}, #{entity.sex}, #{entity.status}, #{entity.delFlag}, #{entity.createUser},
- #{entity.createTime}, #{entity.updateUser}, #{entity.updateTime})
- </foreach>
- on duplicate key update
- account = values(account),
- password = values(password),
- name = values(name),
- dept_id = values(dept_id),
- phone = values(phone),
- email = values(email),
- avatar = values(avatar),
- sex = values(sex),
- status = values(status),
- del_flag = values(del_flag),
- create_user = values(create_user),
- create_time = values(create_time),
- update_user = values(update_user),
- update_time = values(update_time)
- </insert>
- <!--通过主键修改数据-->
- <update id="update">
- update sys_user_info
- <set>
- <if test="account != null and account != ''">
- account = #{account},
- </if>
- <if test="password != null">
- password = #{password},
- </if>
- <if test="name != null and name != ''">
- name = #{name},
- </if>
- <if test="deptId != null and deptId != ''">
- dept_id = #{deptId},
- </if>
- <if test="phone != null">
- phone = #{phone},
- </if>
- <if test="email != null">
- email = #{email},
- </if>
- <if test="avatar != null">
- avatar = #{avatar},
- </if>
- <if test="sex != null and sex != ''">
- sex = #{sex},
- </if>
- <if test="status != null and status != ''">
- status = #{status},
- </if>
- update_user = #{updateUser},
- update_time = GETDATE(),
- bz = #{bz}
- </set>
- where user_id = #{userId}
- </update>
- <!--通过主键删除-->
- <delete id="deleteById">
- update sys_user_info
- set del_flag = 1,
- update_user = #{updateUser},
- update_time = GETDATE()
- where user_id = #{userId}
- </delete>
- <!--查询所有用户-->
- <select id="getSysUserInfoList" resultMap="SysUserInfoMap" parameterType="map">
- WITH RankedData AS (
- SELECT
- u.user_id,
- u.account,
- u.create_time,
- u.sex,
- u.name,
- u.phone,
- u.status,
- d.dept_name AS deptName,
- p.post_name,
- ROW_NUMBER() OVER (PARTITION BY u.user_id ORDER BY u.user_id) AS rn
- FROM
- sys_user_info u
- LEFT JOIN
- sys_dept_info d ON d.dept_id = u.dept_id
- LEFT JOIN
- sys_user_post up ON up.user_id = u.user_id
- LEFT JOIN
- sys_post_info p ON p.post_id = up.post_id
- WHERE
- u.del_flag = 0
- <if test="account != null and account != ''">
- and u.account like '%'+#{account}+'%'
- </if>
- <if test="name != null and name != ''">
- and u.name like '%'+#{name}+'%'
- </if>
- <if test="deptName != null and deptName != ''">
- and d.dept_name like '%'+#{deptName}+'%'
- </if>
- <if test="status != null and status != ''">
- and u.status = #{status}
- </if>
- <if test="id != null and id != ''">
- and u.user_id = #{id}
- </if>
- <if test="postName != null and postName != ''">
- and p.post_name like '%'+#{postName}+'%'
- </if>
- <if test="ssbm != null and ssbm != ''">
- and d.dept_id = #{ssbm}
- </if>
- )
- SELECT
- user_id,
- account,
- status,
- deptName,
- phone,
- create_time,
- sex,
- name,
- STUFF((SELECT '、' + post_name
- FROM RankedData sub
- WHERE sub.user_id = main.user_id
- AND sub.rn > 0
- FOR XML PATH('')), 1, 1, '') AS userPostName
- FROM
- RankedData main
- WHERE
- rn = 1;
- </select>
- <select id="getGw" resultMap="SysUserInfoMap" parameterType="map">
- select u.*, d.dept_name as deptName, p.post_name as userPostName
- from sys_user_info u
- left join sys_dept_info d on d.dept_id = u.dept_id
- left join sys_user_post up on up.user_id = u.user_id
- left join sys_post_info p on p.post_id = up.post_id
- where u.del_flag = 0
- <if test="account != null and account != ''">
- and u.account = #{account}
- </if>
- <if test="name != null and name != ''">
- and u.name like '%'+#{name}+'%'
- </if>
- <if test="deptName != null and deptName != ''">
- and d.dept_name like '%'+#{deptName}+'%'
- </if>
- <if test="status != null and status != ''">
- and u.status = #{status}
- </if>
- <if test="id != null and id != ''">
- and u.user_id = #{id}
- </if>
- <if test="postName != null and postName != ''">
- and p.post_name like '%'+#{postName}+'%'
- </if>
- <if test="ssbm != null and ssbm != ''">
- and d.dept_id = #{ssbm}
- </if>
- <choose>
- <when test="sortName != null and sortName != '' and sortOrder != null and sortOrder != ''">
- order by ${sortName} ${sortOrder}
- </when>
- <otherwise>
- order by u.user_id asc
- </otherwise>
- </choose>
- </select>
- <!--查询用户-->
- <select id="getSysUserInfo" resultMap="SysUserInfoMap" parameterType="map">
- select * from sys_user_info
- where del_flag = 0
- <if test="post_name != null and post_name != ''">
- and post_name = #{postName}
- </if>
- </select>
- <!--批量删除系统用户-->
- <delete id="batchDelete">
- update sys_user_info
- set del_flag = 1,
- update_user = #{updateUser},
- update_time = GETDATE()
- where user_id in
- <foreach item="item" index="index" collection="userIdList" open="(" separator="," close=")">
- #{item}
- </foreach>
- </delete>
- <!--删除一个系统用户-->
- <delete id="delete" parameterType="java.lang.Integer">
- delete
- from sys_user_info
- where user_id = #{_parameter}
- </delete>
- <!--校验用户账号是否唯一-->
- <select id="checkUserNameUnique" resultType="java.lang.Integer" parameterType="java.lang.String">
- select count(*)
- from sys_user_info
- where account = #{account}
- </select>
- <!--新增系统用户-->
- <insert id="doAdd" parameterType="com.liang.entity.SysUserInfo">
- insert into sys_user_info (
- <if test="name != null and name != ''">name,</if>
- <if test="deptId != null and deptId != ''">dept_id,</if>
- <if test="phone != null and phone != ''">phone,</if>
- <if test="email != null and email != ''">email,</if>
- <if test="avatar != null and avatar != ''">avatar,</if>
- <if test="sex != null and sex != ''">sex,</if>
- <if test="status != null and status != ''">status,</if>
- <if test="delFlag != null and delFlag != ''">del_flag,</if>
- <if test="createUser != nul">create_user,</if>
- user_id,
- account,
- password
- ) values (
- <if test="name != null and name != ''">#{name},</if>
- <if test="deptId != null and deptId != ''">#{deptId},</if>
- <if test="phone != null and phone != ''">#{phone},</if>
- <if test="email != null and email != ''">#{email},</if>
- <if test="avatar != null and avatar != ''">#{avatar},</if>
- <if test="sex != null and sex != ''">#{sex},</if>
- <if test="status != null and status != ''">#{status},</if>
- <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
- <if test="createUser != null">#{createUser},</if>
- #{userId},
- #{account},
- #{password}
- )
- </insert>
- <!--修改系统用户-->
- <update id="doUpdate" parameterType="com.liang.entity.SysUserInfo">
- update sys_user_info
- set name = #{name},
- sex = #{sex},
- dept_id = #{deptId},
- status = #{status},
- phone = #{phone},
- email = #{email},
- avatar = #{avatar},
- update_user = #{updateUser}
- where user_id = #{userId}
- </update>
- <!--用户密码重置-->
- <update id="resetPass" parameterType="com.liang.entity.SysUserInfo">
- update sys_user_info
- set password = #{password}
- where user_id = #{userId}
- </update>
- <!--通过id获取一条记录-->
- <select id="getOneById" resultMap="SysUserInfoMap" parameterType="java.lang.Integer">
- select *
- from sys_user_info
- where user_id = #{userId}
- </select>
- <!--获取创建人-->
- <select id="getCJR" resultType="map">
- select user_id as code, account as name
- from sys_user_info
- </select>
- <!--获取一条记录通过用户账号一-->
- <select id="getUserByAccount" resultType="com.liang.entity.SysUserInfo" parameterType="java.lang.String">
- select u.*, p.post_id userPost, p.post_name userPostName
- from sys_user_info u
- left join sys_user_post up on up.user_id = u.user_id
- left join sys_post_info p on p.post_id = up.post_id
- where account = #{account}
- and del_flag = 0
- </select>
- <!--根据登录信息查询所属部门名称 -->
- <select id="getDeptNameByAccount" resultType="java.lang.String">
- SELECT dept_name
- FROM sys_dept_info
- WHERE dept_id = #{dept_id}
- </select>
- <!-- 根据登录人员查询所在岗位名称 -->
- <select id="getPostNameByUserId" resultType="java.lang.String">
- select p.post_name
- from sys_user_info u
- left join sys_dept_info d on d.dept_id = u.dept_id
- left join sys_user_post up on up.user_id = u.user_id
- left join sys_post_info p on p.post_id = up.post_id
- where u.user_id = #{userId}
- </select>
- <select id="getDept" resultMap="SysUserInfoMap">
- select u.*, d.dept_name as deptName, d1.dept_name as deptName1, d2.dept_name as deptName2, p.post_name as userPostName
- from sys_user_info u
- left join sys_dept_info d on d.dept_id = u.dept_id
- left join sys_dept_info d1 on d1.dept_id = d.parent_id
- left join sys_dept_info d2 on d2.dept_id = d1.parent_id
- left join sys_user_post up on up.user_id = u.user_id
- left join sys_post_info p on p.post_id = up.post_id
- where u.user_id = #{id}
- </select>
- <select id="getDeptName" resultType="com.liang.entity.SysUserInfo">
- SELECT * FROM sys_dept_info WHERE del_flag != 1
- </select>
- <select id="getBzs" resultType="String">
- select bz from
- sys_user_info
- where user_id = #{id}
- </select>
- </mapper>
|