123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- <?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.aidex.system.mapper.SysUserMapper">
- <sql id="userColumns">
- t.id as "id",
- t.dept_id AS "deptId",
- t.name AS "name",
- t.name_en AS "nameEn",
- t.no AS "no",
- t.user_name AS "userName",
- t.nick_name AS "nickName",
- t.user_type AS "userType",
- t.email AS "email",
- t.phonenumber AS "phonenumber",
- t.sex AS "sex",
- t.avatar AS "avatar",
- t.password AS "password",
- t.birthday AS "birthday",
- t.nation AS "nation",
- t.birth_address AS "birthAddress",
- t.polity AS "polity",
- t.title AS "title",
- t.office_tel AS "officeTel",
- t.fax AS "fax",
- t.work_space AS "workSpace",
- t.sort AS "sort",
- t.user_pinyin AS "userPinyin",
- t.login_ip AS "loginIp",
- t.login_date AS "loginDate",
- t.status AS "status",
- t.create_by AS "createBy",
- t.create_dept AS "createDept",
- t.create_time AS "createTime",
- t.update_by AS "updateBy",
- t.update_time AS "updateTime",
- t.update_ip AS "updateIp",
- t.remark AS "remark",
- t.version AS "version",
- t.del_flag AS "delFlag"
- </sql>
- <!--用户返回对象集合时使用-->
- <resultMap type="SysUser" id="SysUserResult">
- <id property="id" column="id" />
- <result property="deptId" column="dept_id" />
- <result property="userName" column="user_name" />
- <result property="name" column="name" />
- <result property="nickName" column="nick_name" />
- <result property="userType" column="user_type" />
- <result property="email" column="email" />
- <result property="phonenumber" column="phonenumber" />
- <result property="officeTel" column="office_tel" />
- <result property="sex" column="sex" />
- <result property="avatar" column="avatar" />
- <result property="password" column="password" />
- <result property="status" column="status" />
- <result property="delFlag" column="del_flag" />
- <result property="loginIp" column="login_ip" />
- <result property="loginDate" column="login_date" />
- <result property="createBy" column="create_by" />
- <result property="createTime" column="create_time" />
- <result property="updateBy" column="update_by" />
- <result property="updateTime" column="update_time" />
- <result property="remark" column="remark" />
- <association property="sysDept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
- <collection property="sysRoles" javaType="java.util.List" resultMap="RoleResult" />
- </resultMap>
- <resultMap id="deptResult" type="SysDept">
- <id property="id" column="dept_id" />
- <result property="parentId" column="parent_id" />
- <result property="deptName" column="dept_name" />
- <result property="treeSort" column="tree_sort" />
- <result property="leader" column="leader" />
- <result property="status" column="dept_status" />
- </resultMap>
- <resultMap id="RoleResult" type="SysRole">
- <id property="id" column="id" />
- <result property="roleName" column="role_name" />
- <result property="roleKey" column="role_key" />
- <result property="sort" column="sort" />
- <result property="dataScope" column="data_scope" />
- <result property="status" column="role_status" />
- </resultMap>
- <sql id="columnWhere">
- <if test="userName != null and userName != ''">
- AND t.user_name like concat('%', #{userName}, '%')
- </if>
- <if test="name != null and name != ''">
- AND t.name like concat('%', #{name}, '%')
- </if>
- <if test="status != null and status != ''">
- AND t.status = #{status}
- </if>
- <if test="phonenumber != null and phonenumber != ''">
- AND t.phonenumber like concat('%', #{phonenumber}, '%')
- </if>
- <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
- AND date_format(t.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
- </if>
- <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
- AND date_format(t.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
- </if>
- <if test="deptId != null and deptId != ''">
- AND t.dept_id IN (select d.id from sys_dept d where concat(d.parent_ids, '/') like concat('%', #{deptId}, '/%') )
- </if>
- </sql>
- <select id="get" resultType="SysUser">
- SELECT
- <include refid="userColumns"/>,
- d.dept_name AS "sysDept.deptName", d.leader AS "sysDept.leader"
- FROM sys_user t
- left join sys_dept d on t.dept_id = d.id
- where t.id = #{id}
- </select>
- <select id="findList" resultType="SysUser">
- select
- <include refid="userColumns"/>,
- d.dept_name AS "sysDept.deptName", d.leader AS "sysDept.leader"
- from sys_user t
- left join sys_dept d on t.dept_id = d.id
- where t.del_flag = #{DEL_FLAG_NORMAL}
- <include refid="columnWhere"/>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY t.update_time DESC
- </otherwise>
- </choose>
- </select>
- <select id="findListWithUnique" resultType="SysUser">
- SELECT
- 1
- FROM sys_user t
- where t.del_flag = #{DEL_FLAG_NORMAL}
- <if test="userName != null and userName != ''">
- AND t.user_name = #{userName}
- </if>
- <if test="name != null and name != ''">
- AND t.name = #{name}
- </if>
- <if test="no != null and no != ''">
- AND t.no = #{no}
- </if>
- <if test="email != null and email != ''">
- AND t.email = #{email}
- </if>
- <if test="phonenumber != null and phonenumber != ''">
- AND t.phonenumber = #{phonenumber}
- </if>
- <if test="notEqualId != null and notEqualId != ''">
- AND t.id != #{notEqualId}
- </if>
- </select>
- <insert id="insert" >
- insert into sys_user(
- id,
- dept_id,
- name,
- name_en,
- no,
- user_name,
- nick_name,
- user_type,
- email,
- phonenumber,
- sex,
- avatar,
- password,
- birthday,
- nation,
- birth_address,
- polity,
- title,
- office_tel,
- fax,
- work_space,
- sort,
- user_pinyin,
- login_ip,
- login_date,
- status,
- create_by,
- create_dept,
- create_time,
- update_by,
- update_time,
- update_ip,
- remark,
- version,
- del_flag
- )values(
- #{id},
- #{deptId},
- #{name},
- #{nameEn},
- #{no},
- #{userName},
- #{nickName},
- #{userType},
- #{email},
- #{phonenumber},
- #{sex},
- #{avatar},
- #{password},
- #{birthday},
- #{nation},
- #{birthAddress},
- #{polity},
- #{title},
- #{officeTel},
- #{fax},
- #{workSpace},
- #{sort},
- #{userPinyin},
- #{loginIp},
- #{loginDate},
- #{status},
- #{createBy},
- #{createDept},
- #{createTime},
- #{updateBy},
- #{updateTime},
- #{updateIp},
- #{remark},
- 1,
- #{DEL_FLAG_NORMAL}
- )
- </insert>
- <update id="update">
- update sys_user
- <set>
- <if test="deptId != null"> dept_id = #{deptId}, </if>
- <if test="name != null"> name = #{name}, </if>
- <if test="nameEn != null"> name_en = #{nameEn}, </if>
- <if test="no != null"> no = #{no}, </if>
- <if test="userName != null"> user_name = #{userName}, </if>
- <if test="nickName != null"> nick_name = #{nickName}, </if>
- <if test="userType != null">user_type = #{userType}, </if>
- <if test="email != null">email = #{email}, </if>
- <if test="phonenumber != null">phonenumber = #{phonenumber}, </if>
- <if test="sex != null">sex = #{sex}, </if>
- <if test="avatar != null">avatar = #{avatar}, </if>
- <if test="password != null">password = #{password}, </if>
- <if test="birthday != null">birthday = #{birthday}, </if>
- <if test="nation != null">nation = #{nation}, </if>
- <if test="birthAddress != null">birth_address = #{birthAddress}, </if>
- <if test="polity != null">polity = #{polity}, </if>
- <if test="title != null">title = #{title}, </if>
- <if test="officeTel != null">office_tel = #{officeTel}, </if>
- <if test="fax != null">fax = #{fax}, </if>
- <if test="workSpace != null">work_space = #{workSpace}, </if>
- <if test="sort != null">sort = #{sort}, </if>
- <if test="userPinyin != null">user_pinyin = #{userPinyin}, </if>
- <if test="loginIp != null">login_ip = #{loginIp}, </if>
- <if test="loginDate != null">login_date = #{loginDate}, </if>
- <if test="status != null">status = #{status}, </if>
- <if test="updateBy != null">update_by = #{updateBy}, </if>
- <if test="updateTime != null">update_time = #{updateTime}, </if>
- <if test="updateIp != null">update_ip = #{updateIp}, </if>
- <if test="remark != null">remark = #{remark}, </if>
- version = version + 1
- </set>
- where id = #{id} and version = #{version}
- </update>
- <sql id="selectUserVo">
- select
- t.id,
- t.dept_id,
- t.user_name,
- t.name,
- t.nick_name,
- t.user_type,
- t.email,
- t.avatar,
- t.phonenumber,
- t.office_tel,
- t.password,
- t.sex,
- t.status,
- t.del_flag,
- t.login_ip,
- t.login_date,
- t.create_by,
- t.create_time,
- t.remark,
- d.id as dept_id,
- d.parent_id,
- d.dept_name,
- d.tree_sort,
- d.leader,
- d.status as dept_status,
- r.id,
- r.role_name,
- r.role_key,
- r.sort,
- r.data_scope,
- r.status as role_status
- from sys_user t
- left join sys_dept d on t.dept_id = d.id
- left join sys_user_role ur on t.id = ur.user_id
- left join sys_role r on r.id = ur.role_id
- </sql>
- <select id="selectUserByUserName" parameterType="java.util.Map" resultMap="SysUserResult">
- <include refid="selectUserVo"/>
- where t.user_name = #{userName} and t.del_flag = #{DEL_FLAG_NORMAL}
- </select>
- <select id="selectUserById" parameterType="String" resultMap="SysUserResult">
- <include refid="selectUserVo"/>
- where t.id = #{userId}
- </select>
- <select id="checkUserNameUnique" parameterType="String" resultType="int">
- select count(1) from sys_user where user_name = #{userName} and del_flag = '0' limit 1
- </select>
- <select id="checkPhoneUnique" parameterType="String" resultType="SysUser">
- select id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1
- </select>
- <select id="checkEmailUnique" parameterType="String" resultType="SysUser">
- select id, email from sys_user where email = #{email} and del_flag = '0' limit 1
- </select>
- <update id="updateUserStatus" parameterType="SysUser">
- update sys_user set status = #{status} where id = #{id}
- </update>
- <update id="updateUserAvatar" parameterType="SysUser">
- update sys_user set avatar = #{avatar} where user_name = #{userName}
- </update>
- <update id="updateUserLoginInfo" parameterType="SysUser">
- update sys_user set
- login_ip = #{loginIp},
- login_date = #{loginDate}
- where id = #{id}
- </update>
- <update id="resetUserPwd" parameterType="SysUser">
- update sys_user set password = #{password} where user_name = #{userName}
- </update>
- <delete id="delete">
- UPDATE sys_user SET
- del_flag = #{DEL_FLAG_DELETE}
- WHERE id = #{id}
- </delete>
- <delete id="deleteUserByIds" parameterType="java.util.Map">
- UPDATE sys_user SET
- del_flag = #{DEL_FLAG_DELETE}
- WHERE id in
- <foreach collection="array" item="ids" open="(" separator="," close=")">
- #{ids}
- </foreach>
- </delete>
- <delete id="deleteBatch" parameterType="java.util.List">
- <foreach collection="list" item="item" index="index" open="" close="" separator=";">
- UPDATE sys_user SET
- del_flag = #{DEL_FLAG_DELETE}
- WHERE id = #{item.id}
- </foreach>
- </delete>
- <select id="getUserInfoByIds" parameterType="java.util.List" resultType="java.util.HashMap">
- SELECT
- t.id,
- concat(d.parent_ids,'/',t.id) as 'parentIds',
- t.name,
- d.dept_name as 'subtitle',
- 'user' as 'icon'
- FROM
- sys_user t
- left join sys_dept d on t.dept_id = d.id
- <where>
- t.del_flag = 0
- and ( 1 != 1
- <foreach collection="ids" item="idsItem">
- or t.id in
- <foreach collection="idsItem" item="id" open="(" separator="," close=")">
- #{id}
- </foreach>
- </foreach>
- )
- </where>
- </select>
- <select id="findRoleUserList" resultType="SysUser">
- SELECT
- <include refid="userColumns"/>
- FROM
- sys_user_role r
- LEFT JOIN sys_user t ON r.user_id = t.id
- WHERE
- t.del_flag = #{DEL_FLAG_NORMAL}
- AND r.role_id = #{roleId}
- AND t.id IS NOT NULL
- <if test="userNameOrName != null and userNameOrName != ''">
- AND (t.user_name like concat('%', #{userNameOrName}, '%') or t.name like concat('%', #{userNameOrName}, '%'))
- </if>
- </select>
- </mapper>
|