12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046 |
- <?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.dao.UserDao">
- <!-- <resultMap id="userResult" type="User">
- <id property="id" column="id" />
- <result property="company.id" column="company.id" />
- <result property="office.id" column="office.id" />
- <result property="loginName" column="login_name" />
- <result property="password" column="password" />
- <result property="no" column="no" />
- <result property="name" column="name" />
- <result property="email" column="email" />
- <result property="phone" column="phone" />
- <result property="mobile" column="mobile" />
- <result property="userType" column="user_type" />
- <result property="loginIp" column="login_ip" />
- <result property="loginDate" column="login_date" />
- <result property="remarks" column="remarks" />
- <result property="loginFlag" column="loginFlag" />
- <result property="photo" column="photo" />
- <result property="createBy.id" column="createBy.id" />
- <result property="createDate" column="create_date" />
- <result property="updateBy.id" column="updateBy.id" />
- <result property="updateDate" column="update_date" />
- <result property="company.name" column="company.name" />
- <result property="company.parentId" column="company.parentId" />
- <result property="company.parentIds" column="company.parentIds" />
- <result property="company.area.id" column="company.area.id" />
- <result property="company.area.name" column="company.area.name" />
- <result property="company.area.parentId" column="company.area.parentId" />
- <result property="company.area.parentIds" column="company.area.parentIds" />
- <result property="company.primaryPerson.id" column="company.primaryPerson.id" />
- <result property="company.primaryPerson.name" column="company.primaryPerson.name" />
- <result property="company.deputyPerson.id" column="company.deputyPerson.id" />
- <result property="company.deputyPerson.name" column="company.deputyPerson.name" />
- <result property="office.name" column="office.name" />
- <result property="office.parentId" column="office.parentId" />
- <result property="office.parentIds" column="office.parentIds" />
- <result property="office.area.id" column="office.area.id" />
- <result property="office.area.name" column="office.area.name" />
- <result property="office.area.parentId" column="office.area.parentId" />
- <result property="office.area.parentIds" column="office.area.parentIds" />
- <result property="office.primaryPerson.id" column="office.primaryPerson.id" />
- <result property="office.primaryPerson.name" column="office.primaryPerson.name" />
- <result property="office.deputyPerson.id" column="office.deputyPerson.id" />
- <result property="office.deputyPerson.name" column="office.deputyPerson.name" />
- <collection property="roleList" ofType="Role">
- <id property="id" column="roleList.id" />
- <result property="office.id" column="roleList.office.id" />
- <result property="name" column="roleList.name" />
- <result property="enname" column="roleList.enname" />
- <result property="roleType" column="roleList.roleType" />
- <result property="dataScope" column="roleList.dataScope" />
- <collection property="officeList" ofType="Office">
- <id property="id" column="roleList.officeList.id" />
- </collection>
- </collection>
- </resultMap> -->
- <sql id="userColumns">
- a.id,
- a.com_id AS "comId",
- a.company_id AS "company.id",
- a.office_id AS "office.id",
- a.login_name,
- a.password,
- a.password_remake AS "passwordRemake",
- a.no,
- a.name,
- a.sex,
- a.email,
- a.phone,
- a.mobile,
- a.ishide,
- a.user_type,
- a.login_ip,
- a.login_date,
- a.remarks,
- a.login_flag,
- a.photo,
- a.default_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.first_flag AS "firstFlag",
- s.name AS "company.name",
- s.parent_id AS "company.parent.id",
- s.parent_ids AS "company.parentIds",
- s.group_id AS "company.groupId",
- s.group_name AS "company.groupName",
- s.useable AS "company.useable",
- o.name AS "office.name",
- o.top_company AS "office.topCompany",
- o.parent_id AS "office.parent.id",
- o.parent_ids AS "office.parentIds",
- bo.id AS "branchOffice.id",
- bo.name AS "branchOffice.name",
- bo.parent_ids AS "branchOffice.parentIds",
- bo.parent_id AS "branchOffice.parent.id"<!-- ,
- r.id AS "role.id",
- r.office_id AS "role.office.id",
- r.name AS "role.name",
- r.enname AS "role.enname",
- r.role_type AS "role.roleType",
- r.data_scope AS "role.dataScope" -->
- </sql>
- <sql id="userJoins">
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id
- <if test="company != null and company.id != null and company.id != ''">
- AND uo.company_id = #{company.id}
- </if>
- AND uo.status = '3' AND uo.del_flag = #{DEL_FLAG_NORMAL}
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- -->
- </sql>
- <!-- 根据编号获得用户 -->
- <select id="get" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id"
- r.id AS "role.id",
- r.office_id AS "role.office.id",
- r.name AS "role.name",
- r.enname AS "role.enname",
- r.role_type AS "role.roleType",
- r.data_scope AS "role.dataScope" -->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- LEFT JOIN sys_role_office ro ON ro.role_id = r.id
- inner JOIN sys_user_role ur ON ur.user_id = a.id
- inner JOIN sys_role r ON r.id = ur.role_id and r.company_id = a.company_id -->
- WHERE a.id = #{id}
- </select>
- <!-- 根据编号获得用户 -->
- <select id="getByCompanyAndUserId" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- WHERE a.id = #{id}
- </select>
- <!-- 根据编号获得用户 -->
- <select id="findUserByRoleId" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- LEFT JOIN sys_user_role ur ON ur.user_id = a.id
- WHERE ur.role_id = #{roleId} and a.company_id = #{companyId}
- </select>
- <!-- 根据编号获得用户 -->
- <select id="getByUserId" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id"-->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
- WHERE a.id = #{id}
- </select>
- <!-- 根据编号获得用户 -->
- <select id="findUserByNo" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id"-->
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id
- AND uo.company_id = #{companyId} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
- WHERE a.no =#{no} and a.company_id = #{companyId}
- </select>
- <!-- 根据登录名查询用户 -->
- <select id="getByLoginName" resultType="User" parameterType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
- WHERE a.login_name = #{loginName} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
- <!-- 根据登录名查询用户 -->
- <select id="getByName" resultType="User" parameterType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!--
- LEFT JOIN sys_role_office ro ON ro.role_id = r.id -->
- WHERE a.name = #{name} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </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 (s.id = #{company.id} OR s.parent_ids LIKE
- <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
- <if test="dbName == 'mysql'">CONCAT('%,', #{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>
- <if test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
- AND (o.id = #{branchOffice.id} OR o.parent_ids LIKE
- <if test="dbName == 'oracle'">'%,'||#{branchOffice.id}||',%')</if>
- <if test="dbName == 'mysql'">CONCAT('%,', #{branchOffice.id}, ',%'))</if>
- </if>
- <!-- 如果不是超级管理员,则不显示超级管理员用户 -->
- <!-- <if test="!currentUser.admin">
- AND a.id != '1'
- </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>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- AND a.mobile = #{mobile}
- </if>
- <!-- 数据范围过滤 -->
- ${sqlMap.dsf}
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY a.update_date DESC
- </otherwise>
- </choose>
- </select>
- <!-- 分页查询用户信息 -->
- <select id="findListByComany" resultType="User">
- SELECT
- a.id,
- a.com_id AS "comId",
- uo.company_id AS "company.id",
- uo.office_id AS "office.id",
- a.login_name,
- a.password,
- a.password_remake AS "passwordRemake",
- a.name,
- a.email,
- a.mobile,
- a.photo,
- a.create_by AS "createBy.id",
- a.create_date,
- a.update_by AS "updateBy.id",
- a.update_date,
- a.del_flag
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = #{DEL_FLAG_NORMAL}
- <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>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- AND a.mobile = #{mobile}
- </if>
- <!-- 数据范围过滤 -->
- ${sqlMap.dsf}
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY a.update_date DESC
- </otherwise>
- </choose>
- </select>
- <!-- 分页查询用户信息 -->
- <!--<select id="findListByRoleOffice" resultType="User">
- SELECT DISTINCT
- a.id AS "id",
- a.name AS "name"
- FROM sys_user a
- JOIN sys_office s ON s.id = a.company_id
- JOIN sys_user_role ur ON ur.user_id = a.id
- JOIN sys_role r ON r.id = ur.role_id
- JOIN sys_office o ON ur.office_id = o.id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- <if test="company != null and company.id != null and company.id != ''">
- AND (s.id = #{company.id} OR s.parent_ids LIKE
- <if test="dbName == 'oracle'">'%,'||#{company.id}||',%')</if>
- <if test="dbName == 'mysql'">CONCAT('%,', #{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>
- <!– 如果不是超级管理员,则不显示超级管理员用户 –>
- <!– <if test="!currentUser.admin">
- AND a.id != '1'
- </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>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <!– 数据范围过滤 –>
- ${sqlMap.dsf}
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- ORDER BY s.code, o.code, a.name
- </otherwise>
- </choose>
- </select>-->
- <!-- 根据部门查询用户信息 -->
- <select id="findListByOffice" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- <if test="company != null and company.id != null and company.id != ''">
- AND s.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>
- <if test="name != null and name != ''">
- AND a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <!-- 数据范围过滤 -->
- ${sqlMap.dsf}
- <!-- 排序 -->
- ORDER BY a.name
- </select>
- <!-- 根据OfficeId获取用户(树查询用户时用) -->
- <select id="findUserByOfficeId" resultType="User" useCache="true">
- SELECT
- a.id, a.name, a.login_name,a.photo
- FROM sys_user a
- LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- AND o.del_flag = #{DEL_FLAG_NORMAL}
- <if test="office != null and office.id != null and office.id !='' ">
- AND uo.office_id = #{office.id}
- </if>
- <if test="company != null and company.id != null and company.id !='' ">
- AND uo.company_id = #{company.id}
- </if>
- AND uo.status IN ('试用','正式','劳务')
- ORDER BY a.name
- </select>
- <!-- 根据OfficeId获取用户(树查询用户时用) -->
- <select id="findUserByOffices" resultType="User" useCache="true">
- SELECT
- a.id, a.name, a.login_name,a.photo
- FROM sys_user a
- LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- AND uo.del_flag = #{DEL_FLAG_NORMAL}
- AND o.useable = '1'
- AND o.del_flag = #{DEL_FLAG_NORMAL}
- AND uo.status IN ('试用','正式','劳务')
- 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>
- 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 s.code, o.code, 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,
- com_id,
- company_id,
- office_id,
- login_name,
- password,
- no,
- name,
- sex,
- email,
- phone,
- mobile,
- ishide,
- user_type,
- create_by,
- create_date,
- update_by,
- update_date,
- remarks,
- login_flag,
- photo,
- default_photo,
- qrcode,
- password_remake,
- del_flag,
- first_flag
- ) VALUES (
- #{id},
- #{comId},
- #{company.id},
- #{office.id},
- #{loginName},
- #{password},
- #{no},
- #{name},
- #{sex},
- #{email},
- #{phone},
- #{mobile},
- #{ishide},
- #{userType},
- #{createBy.id},
- #{createDate},
- #{updateBy.id},
- #{updateDate},
- #{remarks},
- #{loginFlag},
- #{photo},
- #{defaultPhoto},
- #{qrCode},
- #{passwordRemake},
- #{delFlag},
- #{firstFlag}
- )
- </insert>
- <!-- 更新用户 -->
- <update id="update">
- UPDATE sys_user SET
- com_id = #{comId},
- company_id = #{company.id},
- office_id = #{office.id},
- login_name = #{loginName},
- password = #{password},
- no = #{no},
- name = #{name},
- sex = #{sex},
- email = #{email},
- phone = #{phone},
- mobile = #{mobile},
- ishide = #{ishide},
- user_type = #{userType},
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- remarks = #{remarks},
- login_flag = #{loginFlag},
- photo = #{photo},
- default_photo = #{defaultPhoto},
- password_remake = #{passwordRemake},
- qrcode = #{qrCode}
- WHERE id = #{id}
- </update>
- <update id="updateUserState">
- UPDATE sys_user SET
- com_id = #{comId},
- company_id = #{company.id},
- office_id = #{office.id},
- update_by = #{updateBy.id},
- update_date = #{updateDate}
- WHERE id = #{id}
- </update>
- <!-- 删除用户和岗位关联表数据 -->
- <delete id="deleteUserRole">
- DELETE FROM sys_user_role WHERE user_id = #{id}
- <if test="role != null and role.id != null and role.id != ''">
- AND role_id = #{role.id}
- </if>
- </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} FROM dual
- </foreach>
- </insert>
- <!-- 更新用户信息 -->
- <update id="updateUserInfo">
- UPDATE sys_user SET
- com_id=#{comId},
- company_id = #{company.id},
- office_id = #{office.id},
- login_name = #{loginName},
- name = #{name},
- sex = #{sex},
- email = #{email},
- phone = #{phone},
- mobile = #{mobile},
- ishide = #{ishide},
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- password_remake = #{passwordRemake},
- remarks = #{remarks},
- photo = #{photo},
- default_photo = #{defaultPhoto},
- qrcode = #{qrCode},
- sign = #{sign}
- WHERE id = #{id}
- </update>
- <update id="updateLoginFlag">
- UPDATE sys_user SET
- update_by = #{updateBy.id},
- update_date = #{updateDate},
- login_flag = #{loginFlag}
- WHERE id = #{id}
- </update>
- <!-- 更新手机号 -->
- <update id="updateMo">
- UPDATE sys_user SET
- login_name = #{loginName},
- phone = #{phone},
- mobile = #{mobile}
- WHERE id = #{id}
- </update>
- <!-- 更新用户密码 -->
- <update id="updatePasswordById">
- UPDATE sys_user SET
- password = #{password},
- password_remake = #{passwordRemake},
- first_flag = #{firstFlag}
- WHERE id = #{id}
- </update>
- <!-- 更新登录信息,如登录IP、登录时间 -->
- <update id="updateLoginInfo">
- UPDATE sys_user SET
- login_ip = #{loginIp},
- login_Date = #{loginDate}
- 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,
- status,
- type,
- read_status,
- create_date
- ) VALUES (
- #{id},
- #{userId},
- #{friendId},
- #{status},
- #{type},
- 0,
- now()
- )
- </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} and p.status = '1'
- </select>
- <!-- 根据用户id和好友id获取唯一记录 -->
- <select id="findFriendInfo" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- ,p.status AS "auditStatus"
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- LEFT JOIN sys_user_friend p ON p.friendId = a.id
- WHERE p.userId = #{userId} and p.friendId = #{friendId} and p.type = '1'
- </select>
- <!-- 根据用户id和好友id获取唯一记录 -->
- <select id="findFriendByStatus" 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} and p.status != '2'
- </select>
- <!-- 删除好友 -->
- <select id="deleteFriend">
- DELETE FROM sys_user_friend WHERE userId = #{userId} and friendId = #{friendId}
- </select>
- <update id="friendAudit">
- UPDATE sys_user_friend SET status = '1',create_date = now() WHERE userId = #{userId} and friendId = #{friendId}
- </update>
- <update id="updateUserRead">
- UPDATE sys_user_friend SET read_status = '1' WHERE userId = #{userId} and status != '0' and friendId = #{friendId}
- </update>
- <update id="updateUserReadAll">
- UPDATE sys_user_friend SET read_status = '1' WHERE userId = #{userId} and status != '0'
- </update>
- <update id="friendAuditNo">
- UPDATE sys_user_friend SET status = '2',create_date = now() WHERE userId = #{userId} and friendId = #{friendId}
- </update>
- <!-- 查询我的好友列表 -->
- <select id="findFriends" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- LEFT JOIN sys_user_friend p ON p.friendId = a.id
- WHERE p.userId = #{id} and p.status = '1'
- </select>
- <!-- 查询我的待审批列表 -->
- <select id="findFriendsAudit" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->,
- p.type AS "friendType"
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- LEFT JOIN sys_user_friend p ON p.friendId = a.id
- WHERE p.userId = #{id} and p.status = '0'
- </select>
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="searchUsers" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where 1=1
- <if test="name != null and name != ''">
- and a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- and a.mobile like
- <if test="dbName == 'oracle'">'%'||#{mobile}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{mobile}, '%')</if>
- </if>
- <if test="company != null and company.id != null and company.id !='' ">
- AND a.company_id = #{company.id}
- </if>
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="findFriendByMobileOrName" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where 1=1
- <if test="name != null and name != ''">
- and a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- and a.mobile = #{mobile}
- </if>
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="findFriendByMobileOrUserName" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- LEFT JOIN sys_user_office uo ON uo.user_id = a.id AND uo.company_id = #{company.id} AND uo.status = '3' AND uo.del_flag = '0'
- LEFT JOIN sys_office s ON s.id = uo.company_id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where 1=1
- <if test="name != null and name != ''">
- and a.name = #{name}
- </if>
- <if test="mobile != null and mobile != ''">
- and a.mobile = #{mobile}
- </if>
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="findUserByMobileOrName" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- JOIN sys_user_friend f ON f.friendId = a.id AND f.status = '1' AND f.userId = #{id}
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where 1=1
- <if test="name != null and name != ''">
- and a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- and a.mobile = #{mobile}
- </if>
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据条件检索用户,添加到好友列表 -->
- <select id="findFriendAll" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- ,f.status AS "auditStatus"
- FROM sys_user a
- JOIN sys_user_friend f ON f.friendId = a.id AND f.type = '1' AND f.userId = #{id}
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where 1=1
- <if test="name != null and name != ''">
- and a.name like
- <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
- <if test="dbName == 'mysql'">CONCAT('%', #{name}, '%')</if>
- </if>
- <if test="mobile != null and mobile != ''">
- and a.mobile = #{mobile}
- </if>
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据条件检索用户,查询申请的好友列表 -->
- <select id="findUserByStatus" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- FROM sys_user a
- JOIN sys_user_friend f ON f.friendId = a.id AND f.status = '0' AND f.userId = #{id} AND f.type = '1'
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- <!-- 根据手机号查询 -->
- </select>
- <select id="findUserByStatusAudit" resultType="User">
- SELECT
- <include refid="userColumns"/><!-- ,
- ro.office_id AS "roleList.officeList.id" -->
- ,f.status AS "auditStatus"
- FROM sys_user a
- JOIN sys_user_friend f ON f.friendId = a.id AND f.status != '0' AND f.userId = #{id} AND f.type = '0' AND f.read_status = 0
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- ORDER BY f.create_date DESC
- <!-- 根据手机号查询 -->
- </select>
- <!-- 根据role查询user -->
- <select id="findUserByRole" resultType="User" parameterType="Role">
- SELECT
- a.*
- FROM sys_user a
- LEFT JOIN sys_user_role ur ON ur.user_id = a.id
- WHERE ur.role_id = #{id} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
- <select id="findUserByMobile" resultType="User">
- SELECT
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- FROM sys_user a
- <include refid="userJoins"/>
- WHERE a.mobile=#{mobile} AND a.del_flag = #{DEL_FLAG_NORMAL}
- </select>
- <select id="getUserById" resultType="User">
- SELECT
- a.id,
- a.com_id AS "comId",
- a.company_id AS "company.id",
- a.office_id AS "office.id",
- a.login_name,
- a.password,
- a.password_remake AS "passwordRemake",
- a.no,
- a.name,
- a.sex,
- a.email,
- a.phone,
- a.mobile,
- a.ishide,
- a.user_type,
- a.login_ip,
- a.login_date,
- a.remarks,
- a.login_flag,
- a.photo,
- a.default_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.first_flag AS "firstFlag"
- FROM sys_user a
- WHERE a.id = #{id}
- </select>
- <select id="findListByRoleList" resultType="User">
- SELECT
- a.id,a.name,a.photo,a.login_name AS "loginName"
- FROM sys_user a
- JOIN sys_user_role ur ON ur.user_id = a.id
- JOIN sys_role r ON ur.role_id = r.id
- WHERE a.office_id is not null and find_in_set(r.id,#{roleIds})
- </select>
- <!-- 依据部门编号查询岗位 -->
- <select id="queryRole" parameterType="java.lang.String" resultType="java.util.HashMap">
- select * from sys_role where company_id = #{officeId}
- </select>
- <select id="queryListByIds" resultType="User">
- SELECT * FROM sys_user
- WHERE id IN
- <foreach collection="array" index="index" item="item"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </select>
- <select id="findUserRole" resultType="java.util.HashMap" parameterType="java.lang.String">
- SELECT * FROM sys_user_role
- WHERE user_id=#{userId} and role_id=#{roleId}
- </select>
- <select id="findUserByRoles" resultType="User" parameterType="java.lang.String">
- select
- <include refid="userColumns"/>
- from sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where a.id in (
- select r.user_id from sys_user_role r where r.role_id in (
- SELECT
- s.role_id
- FROM
- sys_role_activity_relation s
- WHERE
- s.role_activity_id IN (
- SELECT
- w.role_id
- FROM
- sys_warning_role w
- WHERE
- w.warning_id =#{id}
- )))
- </select>
- <select id="findUserByUser" resultType="User" parameterType="java.lang.String">
- select
- <include refid="userColumns"/>
- from sys_user a
- LEFT JOIN sys_office s ON s.id = a.company_id
- LEFT JOIN sys_office o ON o.id = a.office_id
- LEFT JOIN sys_office bo ON bo.id = o.branch_office
- where a.id in ( SELECT
- w.user_id
- FROM
- sys_warning_user w
- WHERE
- w.warning_id =#{id})
- </select>
- <select id="userCount" resultType="java.lang.Integer" >
- SELECT
- count(*)
- FROM sys_user a
- WHERE a.office_id = #{officeId} AND a.del_flag = 0
- </select>
- <select id="countByOffice" resultType="int">
- SELECT
- count(*)
- FROM sys_user a
- LEFT JOIN work_staff_achives uo ON uo.user_id = a.id
- LEFT JOIN sys_office o ON o.id = uo.office_id
- WHERE a.del_flag = #{DEL_FLAG_NORMAL}
- AND uo.del_flag = #{DEL_FLAG_NORMAL}
- AND o.useable = '1'
- AND o.del_flag = #{DEL_FLAG_NORMAL}
- AND uo.status IN ('试用','正式','劳务')
- AND (o.id = #{office.id} OR find_in_set(#{office.id},o.parent_ids))
- </select>
- <select id="findUserByOfficeRole" resultType="User">
- SELECT DISTINCT ur.user_id as 'id' FROM sys_role a
- LEFT JOIN sys_user_role ur ON ur.role_id = a.id
- LEFT JOIN sys_office o ON o.id = a.office_id
- WHERE o.id = #{id} or find_in_set(#{id},o.parent_ids)
- </select>
- <update id="updateUserCompanyId">
- UPDATE sys_user SET com_id = '1',company_id = '1',office_id='5' WHERE company_id=#{companyId}
- </update>
- </mapper>
|