123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?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.jeeplus.modules.sys.mapper.UserMapper">
- <sql id="userColumns">
- a.id,
- a.company_id AS "company.id",
- a.office_id AS "office.id",
- a.login_name AS "loginName",
- a.type AS "type",
- a.password,
- a.no,
- a.name,
- a.email,
- a.phone,
- a.mobile,
- a.login_ip,
- a.login_date,
- a.remarks,
- a.login_flag,
- a.photo,
- a.qrcode,
- a.sign,
- a.create_by AS "createBy.id",
- a.create_date,
- a.update_by AS "updateBy.id",
- a.update_date,
- a.del_flag,
- a.leader_id as "leaderId",
- a.village_id as "villageId",
- a.ifapppermission,
- o.dept_name AS "office.deptName",
- o.name AS "office.name",
- o.parent_id AS "office.parent.id",
- o.parent_ids AS "office.parentIds",
- o.type AS "office.type"
- </sql>
- <sql id="userJoins">
- <!--LEFT JOIN sys_office c ON c.id = a.company_id
- LEFT JOIN sys_area ca ON ca.id = c.area_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_area oa ON oa.id = o.area_id-->
- LEFT JOIN leader_org_no o ON o.id = a.office_id
- <!--
- LEFT JOIN sys_user cu ON cu.id = c.primary_person
- LEFT JOIN sys_user cu2 ON cu2.id = c.deputy_person
- LEFT JOIN sys_user ou ON ou.id = o.primary_person
- LEFT JOIN sys_user ou2 ON ou2.id = o.deputy_person
- LEFT JOIN sys_user_role ur ON ur.user_id = a.id
- LEFT JOIN sys_role r ON r.id = ur.role_id -->
- </sql>
-
- <!-- 根据编号获得用户 -->
- <select id="get" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- WHERE a.id = #{id}
- </select>
-
- <!-- 根据登录名查询用户 -->
- <select id="getByLoginName" resultType="User" parameterType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- WHERE a.login_name = #{loginName} AND a.del_flag = #{DEL_FLAG_NORMAL}
- <!--<if test="type != null and type != ''">
- AND a.type = #{type}
- </if>-->
- </select>
- <!-- 分页查询用户信息 -->
- <select id="findList" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- <if test="role != null and role.id != null and role.id != ''">
- JOIN sys_user_role ur ON ur.user_id = a.id AND ur.role_id = #{role.id}
- </if>
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- <!--<if test="company != null and company.id != null and company.id != ''">
- AND (c.id = #{company.id} OR c.parent_ids LIKE
- <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
- <if test="dbName == 'mysql'">CONCAT('%,', #{company.id}, ',%'))</if>
- <if test="dbName == 'mssql'">'%'+#{company.id}+'%')</if>
- </if>-->
- <if test="office != null and office.id != null and office.id != ''">
- AND (o.id = #{office.id} OR o.parent_ids LIKE
- <if test="dbName == 'oracle'">'%,'||#{office.id}||',%')</if>
- <if test="dbName == 'mysql'">CONCAT('%,', #{office.id}, ',%'))</if>
- <if test="dbName == 'mssql'">'%'+#{office.id}+'%')</if>
- </if>
- <!-- 如果不是超级管理员,则不显示超级管理员用户 -->
- <if test="!currentUser.admin">
- AND a.id != '1'
- </if>
- <!--<if test="officeId != null and officeId != ''">
- AND o.parent_ids LIKE CONCAT('%,', #{officeId}, ',%')
- OR a.office_id = #{officeId}
- </if>-->
- <if test="loginName != null and loginName != ''">
- AND a.login_name like
- <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
- <if test="dbName == 'mssql'">'%'+#{loginName}+'%'</if>
- </if>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
- </if>
- <!-- AND FIND_IN_SET(a.office_id,getChildLst(#{currentUser.office.id})) -->
- <!-- 数据范围过滤 -->
- ${dataScope}
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY o.sort, a.name
- </otherwise>
- </choose>
- </select>
-
-
- <!-- 根据部门查询用户信息 -->
- <select id="findListByOffice" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- <!--<if test="company != null and company.id != null and company.id != ''">
- AND c.id = #{company.id}
- </if>-->
- <if test="office != null and office.id != null and office.id != ''">
- AND o.id = #{office.id}
- </if>
- <if test="office == null">
- AND (o.id = '' or o.id is null)
- </if>
-
- <if test="loginName != null and loginName != ''">
- AND a.login_name like
- <if test="dbName == 'oracle'">'%'||#{loginName}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{loginName}, '%')</if>
- <if test="dbName == 'mssql'">'%'+#{loginName}+'%'</if>
- </if>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
- </if>
- <!-- 数据范围过滤 -->
- ${dataScope}
- <!-- 排序 -->
- ORDER BY a.name
-
- </select>
-
- <!-- 根据OfficeId获取用户(树查询用户时用) -->
- <select id="findUserByOfficeId" resultType="User" useCache="true">
- SELECT
- a.id, a.name, a.login_name
- FROM sys_user a
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- AND a.office_id = #{office.id}
- ORDER BY a.name
- </select>
-
- <!-- 查询全部用户 -->
- <select id="findAllList" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- ORDER BY o.sort, a.name
- </select>
-
- <!-- 查询全部用户数目 -->
- <select id="findAllCount" resultType="long">
- SELECT
- COUNT(1)
- FROM sys_user a
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
-
- <!-- 插入用户 -->
- <insert id="insert">
- INSERT INTO sys_user(
- id,
- company_id,
- office_id,
- login_name,
- password,
- no,
- name,
- email,
- phone,
- mobile,
- create_by,
- create_date,
- update_by,
- update_date,
- remarks,
- login_flag,
- photo,
- qrcode,
- del_flag,
- village_id,
- leader_id,
- type,
- ifapppermission
- ) VALUES (
- #{id},
- #{company.id},
- #{office.id},
- #{loginName},
- #{password},
- #{no},
- #{name},
- #{email},
- #{phone},
- #{mobile},
- #{createBy.id},
- #{createDate},
- #{updateBy.id},
- #{updateDate},
- #{remarks},
- #{loginFlag},
- #{photo},
- #{qrCode},
- #{delFlag},
- #{villageId},
- #{leaderId},
- #{type},
- #{ifapppermission}
- )
- </insert>
- <insert id="register">
- INSERT INTO sys_user(
- id,
- office_id,
- login_name,
- password,
- name,
- mobile,
- login_flag,
- del_flag,
- type,
- create_date
- ) VALUES (
- #{id},
- #{officeId},
- #{loginName},
- #{password},
- #{name},
- #{mobile},
- #{loginFlag},
- #{delFlag},
- #{type},
- #{createDate}
- )
- </insert>
-
- <!-- 更新用户 -->
- <update id="update">
- UPDATE sys_user SET
- company_id = #{company.id},
- office_id = #{office.id},
- login_name = #{loginName},
- password = #{password},
- no = #{no},
- name = #{name},
- email = #{email},
- phone = #{phone},
- mobile = #{mobile},
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- remarks = #{remarks},
- login_flag = #{loginFlag},
- photo = #{photo},
- qrcode = #{qrCode},
- village_id = #{villageId},
- leader_id = #{leaderId},
- type = #{type},
- ifapppermission=#{ifapppermission}
- WHERE id = #{id}
- </update>
-
- <!-- 删除用户和角色关联表数据 -->
- <delete id="deleteUserRole">
- DELETE FROM sys_user_role WHERE user_id = #{id}
- </delete>
-
- <!-- 插入用户和角色关联表数据 -->
- <insert id="insertUserRole">
- INSERT INTO sys_user_role(user_id, role_id)
- <foreach collection="roleList" item="role" separator=" union all ">
- SELECT #{id}, #{role.id} ${dual}
- </foreach>
- </insert>
-
- <!-- 更新用户信息 -->
- <update id="updateUserInfo">
- UPDATE sys_user SET
- name = #{name},
- email = #{email},
- phone = #{phone},
- mobile = #{mobile},
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- remarks = #{remarks},
- photo = #{photo},
- qrcode = #{qrCode},
- sign = #{sign}
- WHERE id = #{id}
- </update>
-
- <!-- 更新用户密码 -->
- <update id="updatePasswordById">
- UPDATE sys_user SET
- password = #{password}
- WHERE id = #{id}
- </update>
-
- <!-- 更新登录信息,如登录IP、登录时间 -->
- <update id="updateLoginInfo">
- UPDATE sys_user SET
- login_ip = #{loginIp},
- login_Date = #{loginDate} ,
- login_times = login_times+1
- WHERE id = #{id}
- </update>
-
- <!-- 物理删除用户 -->
- <update id="delete">
- DELETE FROM sys_user
- WHERE id = #{id}
- </update>
-
- <!-- 逻辑删除用户 -->
- <update id="deleteByLogic">
- UPDATE sys_user SET
- del_flag = #{DEL_FLAG_DELETE}
- WHERE id = #{id}
- </update>
-
- <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
- <select id="findUniqueByProperty" resultType="User" statementType="STATEMENT">
- select * from sys_user where ${propertyName} = '${value}'
- </select>
- <!-- 添加好友 -->
- <insert id="insertFriend">
- INSERT INTO sys_user_friend(
- id,
- userId,
- friendId
- ) VALUES (
- #{id},
- #{userId},
- #{friendId}
- )
- </insert>
-
- <!-- 根据用户id和好友id获取唯一记录 -->
- <select id="findFriend" resultType="User">
- SELECT
- *
- FROM sys_user a
- LEFT JOIN sys_user_friend p ON p.userId = a.id
- WHERE p.userId = #{userId} and p.friendId = #{friendId}
- </select>
-
- <!-- 删除好友 -->
- <select id="deleteFriend">
- DELETE FROM sys_user_friend WHERE userId = #{userId} and friendId = #{friendId}
- </select>
-
- <!-- 查询我的好友列表 -->
- <select id="findFriends" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- LEFT JOIN sys_user_friend p ON p.friendId = a.id
- WHERE p.userId = #{id}
- </select>
-
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="searchUsers" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- <include refid="userJoins"/>
- <if test="name != null and name != ''">
- WHERE a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
- </if>
- <if test="id!=null and id!=''">
- AND a.id = #{id}
- </if>
- </select>
-
- </mapper>
|