<?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.thhy.usercore.modules.sys.sysusers.mapper.SysUsersMapper">
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
user_id as userId,
|
username as username,
|
password as password,
|
real_name as realName,
|
telphone as telphone,
|
photo_url as photoUrl,
|
create_user as createUser,
|
create_time as createTime,
|
is_use as isUse,
|
sex as sex,
|
email as email,
|
version as version,
|
sub_admin as subAdmin,
|
is_plat as isPlat,
|
plat_id as platId,
|
is_app as isApp
|
</sql>
|
|
<!-- 排除密码列 -->
|
<sql id="Without_Pass_Column_List">
|
user_id as userId,
|
username as username,
|
real_name as realName,
|
telphone as telphone,
|
photo_url as photoUrl,
|
create_user as createUser,
|
create_time as createTime,
|
is_use as isUse,
|
sex as sex,
|
email as email,
|
version as version
|
</sql>
|
|
<sql id="condition_query">
|
<where>
|
<trim suffixOverrides=" AND " >
|
is_use = 1 AND
|
<if test="username!=null and username!=''">
|
username LIKE concat('%',#{username},'%') AND
|
</if>
|
<if test="realName!=null and realName!=''">
|
real_name = #{realName} AND
|
</if>
|
<if test="telphone!=null and telphone!=''">
|
telphone LIKE concat('%',#{telphone},'%') AND
|
</if>
|
<if test="createTime!=null">
|
create_time = #{createTime} AND
|
</if>
|
<!--<if test="isUse!=null">
|
is_use = #{isUse} AND
|
</if>-->
|
<if test="sex!=null">
|
sex = #{sex} AND
|
</if>
|
<if test="email!=null and email!=''">
|
email = #{email} AND
|
</if>
|
</trim>
|
</where>
|
</sql>
|
|
<select id="queryById" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
select <include refid="Base_Column_List" />
|
from sys_users where user_id = #{userId}
|
</select>
|
|
<select id="queryByPhone" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
select <include refid="Base_Column_List" />
|
from sys_users where telphone = #{telphone}
|
</select>
|
|
<select id="queryVersionById" resultType="integer">
|
select version from sys_users where user_id = #{userId}
|
</select>
|
|
<!--查询列表-->
|
<select id="findList" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
SELECT
|
<include refid="Without_Pass_Column_List" />
|
from sys_users
|
<where>
|
<trim suffixOverrides=" AND " >
|
is_use = 1 AND
|
<if test="username!=null and username!=''">
|
username LIKE concat('%',#{username},'%') AND
|
</if>
|
<if test="realName!=null and realName!=''">
|
real_name = #{realName} AND
|
</if>
|
<if test="telphone!=null and telphone!=''">
|
telphone LIKE concat('%',#{telphone},'%') AND
|
</if>
|
<if test="createTime!=null">
|
create_time = #{createTime} AND
|
</if>
|
<!--<if test="isUse!=null">
|
is_use = #{isUse} AND
|
</if>-->
|
<if test="sex!=null">
|
sex = #{sex} AND
|
</if>
|
<if test="email!=null and email!=''">
|
email = #{email} AND
|
</if>
|
</trim>
|
</where>
|
order by create_time desc
|
</select>
|
|
<!--查询列表-->
|
<select id="findListWithAccess" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
SELECT
|
su.user_id as userId,
|
su.username as username,
|
su.real_name as realName,
|
su.telphone as telphone,
|
su.photo_url as photoUrl,
|
su.create_user as createUser,
|
su.create_time as createTime,
|
su.is_use as isUse,
|
su.sex as sex,
|
su.email as email,
|
su.version as version
|
from sys_users su
|
left join sys_plat_user spu on spu.user_id = su.plat_id
|
left join sys_depart_user sdu on spu.user_id = sdu.user_id
|
left join sys_com_depart scd on scd.depart_id = sdu.depart_id
|
left join sys_com_su scs on scs.user_id = su.user_id
|
left join sys_plat_position_user ppu on ppu.user_id = spu.user_id
|
left join sys_position sp on sp.pos_id = ppu.position_id
|
<where>
|
<trim suffixOverrides=" AND " >
|
su.is_use = 1 AND (scd.company_id = #{companyId} or scs.company_id = #{companyId} or sp.company_id = #{companyId}) AND
|
<if test="username!=null and username!=''">
|
su.username LIKE concat('%',#{username},'%') AND
|
</if>
|
<if test="realName!=null and realName!=''">
|
su.real_name = #{realName} AND
|
</if>
|
<if test="telphone!=null and telphone!=''">
|
su.telphone LIKE concat('%',#{telphone},'%') AND
|
</if>
|
<if test="createTime!=null">
|
su.create_time = #{createTime} AND
|
</if>
|
<!--<if test="isUse!=null">
|
is_use = #{isUse} AND
|
</if>-->
|
<if test="sex!=null">
|
su.sex = #{sex} AND
|
</if>
|
<if test="email!=null and email!=''">
|
su.email = #{email} AND
|
</if>
|
</trim>
|
</where>
|
order by su.create_time desc
|
</select>
|
|
<!--插入操作-->
|
<insert id="insert">
|
insert into sys_users
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="userId != null">
|
user_id,
|
</if>
|
<if test="username != null">
|
username,
|
</if>
|
<if test="password != null">
|
password,
|
</if>
|
<if test="realName != null">
|
real_name,
|
</if>
|
<if test="telphone != null">
|
telphone,
|
</if>
|
<if test="photoUrl != null">
|
photo_url,
|
</if>
|
<if test="createUser != null">
|
create_user,
|
</if>
|
<if test="createTime != null">
|
create_time,
|
</if>
|
<if test="isUse != null">
|
is_use,
|
</if>
|
<if test="sex != null">
|
sex,
|
</if>
|
<if test="email != null">
|
email,
|
</if>
|
<if test="isPlat != null">
|
is_plat,
|
</if>
|
<if test="subAdmin != null">
|
sub_admin,
|
</if>
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="userId != null">
|
#{userId},
|
</if>
|
<if test="username != null">
|
#{username},
|
</if>
|
<if test="password != null">
|
#{password},
|
</if>
|
<if test="realName != null">
|
#{realName},
|
</if>
|
<if test="telphone != null">
|
#{telphone},
|
</if>
|
<if test="photoUrl != null">
|
#{photoUrl},
|
</if>
|
<if test="createUser != null">
|
#{createUser},
|
</if>
|
<if test="createTime != null">
|
#{createTime},
|
</if>
|
<if test="isUse != null">
|
#{isUse},
|
</if>
|
<if test="sex != null">
|
#{sex},
|
</if>
|
<if test="email != null">
|
#{email},
|
</if>
|
<if test="isPlat != null">
|
#{isPlat},
|
</if>
|
<if test="subAdmin != null">
|
#{subAdmin},
|
</if>
|
</trim>
|
</insert>
|
|
|
<!--更新操作-->
|
<update id="update">
|
update sys_users
|
<set>
|
version = version+1,
|
<if test="username != null">
|
username=#{username},
|
</if>
|
<if test="password != null">
|
password=#{password},
|
</if>
|
<if test="realName != null">
|
real_name=#{realName},
|
</if>
|
<if test="telphone != null">
|
telphone=#{telphone},
|
</if>
|
<if test="photoUrl != null">
|
photo_url=#{photoUrl},
|
</if>
|
<if test="createUser != null">
|
create_user=#{createUser},
|
</if>
|
<if test="createTime != null">
|
create_time=#{createTime},
|
</if>
|
<if test="isUse != null">
|
is_use=#{isUse},
|
</if>
|
<if test="sex != null">
|
sex=#{sex},
|
</if>
|
<if test="email != null">
|
email=#{email},
|
</if>
|
</set>
|
where user_id=#{userId}
|
</update>
|
|
<!--更新操作-->
|
<update id="deletelogic">
|
update sys_users
|
SET is_use = 0
|
where user_id=#{id}
|
</update>
|
|
<!--根据ID删除-->
|
<!--<delete id="deleteById">
|
Delete from sys_users where id = #{id}
|
</delete>-->
|
|
<!--<select id="login" resultType="boolean" parameterType="SysUserDto">
|
SELECT CASE WHEN count(user_id) = 1 THEN true else false end as isExist
|
FROM sys_users
|
WHERE (username = #{username} OR email = #{email} OR telphone = #{telphone}) AND password = #{password}
|
AND sys_users.is_use = 1
|
</select>-->
|
|
<select id="queryByUsername" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
SELECT
|
su.user_id as userId,
|
su.username as username,
|
su.real_name as realName,
|
su.password,
|
su.telphone as telphone,
|
su.photo_url as photoUrl,
|
su.create_user as createUser,
|
su.create_time as createTime,
|
su.is_use as isUse,
|
su.sex as sex,
|
su.email as email,
|
su.sub_admin as subAdmin,
|
su.is_plat as isPlat
|
FROM sys_users su
|
WHERE (su.username = #{username} OR su.email = #{username} OR su.telphone = #{username})
|
AND su.is_use = 1
|
</select>
|
|
<select id="queryByUsernameIsPlat" resultType="com.thhy.usercore.modules.sys.sysusers.entity.SysUsers">
|
SELECT
|
su.user_id as userId,
|
su.username as username,
|
su.real_name as realName,
|
su.password,
|
su.telphone as telphone,
|
su.photo_url as photoUrl,
|
su.create_user as createUser,
|
su.create_time as createTime,
|
su.is_use as isUse,
|
su.sex as sex,
|
su.email as email,
|
su.sub_admin as subAdmin,
|
su.is_plat as isPlat,
|
su.plat_id as platId,
|
spu.user_type as userType
|
FROM sys_users su
|
left join sys_plat_user spu on spu.user_id = su.plat_id
|
WHERE (su.username = #{username} OR su.email = #{username} OR su.telphone = #{username})
|
AND su.is_use = 1 and is_plat = 1
|
</select>
|
|
<select id="queryUserUrls" resultType="string">
|
select su.url_path as urlpath
|
from sys_user_role sur
|
left join sys_roles sr on sr.role_id = sur.role_id
|
left join sys_role_url srurl on srurl.role_id = sur.role_id
|
left join sys_url su on su.url_id = srurl.url_id
|
where sur.user_id = #{userId} and sur.is_use = 1
|
</select>
|
|
<select id="queryUserButtons" resultType="string">
|
select GROUP_CONCAT(sb.button_html_id)
|
from sys_user_role sur
|
left join sys_role_button srb on srb.role_id = sur.role_id
|
left join sys_button sb on sb.button_id = srb.button_id
|
where sur.user_id = #{userId} and sur.is_use = 1
|
GROUP BY user_id
|
</select>
|
|
<update id="updateUserPass">
|
update sys_users
|
set password = #{password}
|
where user_id = #{userId}
|
</update>
|
|
<select id="queryCompanyByComAdmin" resultType="hashmap">
|
select sc.company_id as companyId,sc.company_name as companyName
|
from sys_com_su scs
|
left join sys_company sc on sc.company_id = scs.company_id
|
where scs.user_id = #{userId}
|
</select>
|
|
<select id="queryCompanyByUser" resultType="hashmap">
|
select sc.company_id as companyId,
|
sc.company_name as companyName
|
from sys_com_depart scd
|
left join sys_company sc on sc.company_id = scd.company_id
|
where scd.depart_id = (
|
select depart_id
|
from sys_depart_user du
|
left join sys_plat_user spu on spu.user_id = du.user_id
|
left join sys_users su on su.plat_id = spu.user_id
|
where su.user_id = #{userId} limit 1)
|
</select>
|
|
<select id="queryCompanyByPosition" resultType="hashmap">
|
select sc.company_id as companyId,sc.company_name as companyName
|
from sys_plat_position_user ppu
|
left join sys_users su on su.plat_id = ppu.user_id
|
left join sys_position sp on sp.pos_id = ppu.position_id
|
left join sys_company sc on sc.company_id = sp.company_id
|
where su.user_id = #{userId}
|
limit 1
|
</select>
|
|
<!--插入操作-->
|
<insert id="insertCompanyUser" parameterType="com.thhy.usercore.modules.sys.sysusers.entity.CompanySu">
|
insert into sys_com_su
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="id != null">
|
id,
|
</if>
|
<if test="companyId != null">
|
company_id,
|
</if>
|
<if test="userId != null">
|
user_id,
|
</if>
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="id != null">
|
#{id},
|
</if>
|
<if test="companyId != null">
|
#{companyId},
|
</if>
|
<if test="userId != null">
|
#{userId},
|
</if>
|
</trim>
|
</insert>
|
|
<select id="queryPlatUser" resultType="com.thhy.usercore.modules.sys.sysusers.entity.PlatUserVo">
|
select user_type as userType from sys_plat_user where user_id = #{userId}
|
</select>
|
|
<update id="nologin">
|
update sys_plat_user set is_login = 2 where user_id = #{platId}
|
</update>
|
|
<delete id="deleteApplyHistory">
|
delete from t_user_apply_history where plat_user_id = #{platId} or user_id = #{platId}
|
</delete>
|
</mapper>
|