181 lines
9.7 KiB
XML
181 lines
9.7 KiB
XML
<?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.nflg.mobilebroken.repository.mapper.AppUserMapper">
|
|
|
|
<select id="search" resultType="com.nflg.mobilebroken.common.pojo.vo.AppUserVO">
|
|
SELECT u.id,c.agency_company_name AS 'companyName',u.`name`,u.email,u.avatar,a.`name` AS 'areaName',u.`state` AS 'userState'
|
|
,u.create_by AS 'createBy',u.create_time AS 'createTime',u.update_by AS 'updateBy',u.update_time AS 'updateTime'
|
|
,u.last_login_time AS 'lastLoginTime',u.expire_time AS 'expireTime',u.is_primary AS 'isPrimary'
|
|
,IF(u.expire_time>now(),1,2) AS 'state',u.type
|
|
FROM app_user u
|
|
INNER JOIN t_base_customer c ON u.company_id=c.id
|
|
INNER JOIN app_area a ON u.area_id=a.id
|
|
WHERE u.is_del=0 AND u.is_primary=false AND u.company_id IN
|
|
<foreach collection="request.companyIds" item="companyId" open="(" separator="," close=")">
|
|
#{companyId}
|
|
</foreach>
|
|
<where>
|
|
<if test="request.state != null">
|
|
AND u.state = #{request.state}
|
|
</if>
|
|
<if test="request.key != null and request.key != ''">
|
|
AND
|
|
(
|
|
u.name LIKE concat('%', #{request.key}, '%')
|
|
OR u.email LIKE concat('%', #{request.key}, '%')
|
|
or u.phone LIKE concat('%', #{request.key}, '%')
|
|
)
|
|
</if>
|
|
</where>
|
|
UNION
|
|
SELECT u.id,c.agency_company_name AS 'companyName',u.user_name AS 'name',u.user_email AS 'email',u.user_avatar AS 'avatar'
|
|
,a.`name` AS 'areaName',0 AS 'userState',u.create_by AS 'createBy',u.create_time AS 'createTime',u.update_by AS 'updateBy'
|
|
,u.update_time AS 'updateTime',null AS 'lastLoginTime',null AS 'expireTime',false AS 'isPrimary',0 AS 'state'
|
|
FROM app_user_applyfor u
|
|
INNER JOIN t_base_customer c ON u.company_id=c.id
|
|
INNER JOIN app_area a ON u.area_id=a.id
|
|
WHERE u.company_id IN
|
|
<foreach collection="request.companyIds" item="companyId" open="(" separator="," close=")">
|
|
#{companyId}
|
|
</foreach>
|
|
</select>
|
|
<select id="getInfo" resultType="com.nflg.mobilebroken.common.pojo.vo.AppUserVO">
|
|
SELECT u.id
|
|
, u.area_id AS 'areaId'
|
|
, c.agency_company_name AS 'companyName'
|
|
, u.`name`
|
|
, u.email
|
|
, u.avatar
|
|
, IF(u.is_primary, a1.area_name, a2.`name`) AS 'areaName'
|
|
, u.state AS 'userState'
|
|
, u.create_by AS 'createBy'
|
|
, u.create_time AS 'createTime'
|
|
, u.update_by AS 'updateBy'
|
|
, u.update_time AS 'updateTime'
|
|
, u.last_login_time AS 'lastLoginTime'
|
|
, u.expire_time AS 'expireTime'
|
|
, u.is_primary AS 'isPrimary'
|
|
, u.login_name AS 'loginName'
|
|
, u.phone
|
|
, u.title_id
|
|
, p.position_name AS 'title'
|
|
, u.type
|
|
FROM app_user u
|
|
LEFT JOIN t_base_customer c ON u.company_id = c.id
|
|
LEFT JOIN t_base_area a1 ON u.area_id = a1.id
|
|
LEFT JOIN app_area a2 ON u.area_id = a2.id
|
|
LEFT JOIN t_base_position p ON u.title_id = p.id
|
|
WHERE u.id = #{userId}
|
|
</select>
|
|
|
|
<select id="searchByCompany" parameterType="com.nflg.mobilebroken.common.pojo.request.UserSearchRequest" resultType="com.nflg.mobilebroken.common.pojo.vo.AppUserVO">
|
|
SELECT u.id,u.phone,u.state AS 'userState',u.title_id AS 'titleId',u.area_id AS 'areaId',u.company_id AS 'companyId'
|
|
,p.position_name AS 'title',u.expire_time AS 'expireTime',c.agency_company_name AS 'companyName',u.login_name AS 'loginName'
|
|
,u.`name`,u.email,u.avatar,a.`name` AS 'areaName',u.create_by AS 'createBy',u.create_time AS 'createTime',u.update_by AS 'updateBy'
|
|
,u.update_time AS 'updateTime',u.last_login_time AS 'lastLoginTime',u.expire_time AS 'expireTime',u.is_primary AS 'isPrimary'
|
|
,IF(u.expire_time>now(),1,2) AS 'state',u.language_code AS 'languageCode',u.type
|
|
FROM app_user u
|
|
INNER JOIN t_base_customer c ON u.company_id=c.id
|
|
INNER JOIN app_area a ON u.area_id=a.id
|
|
LEFT JOIN t_base_position p ON u.title_id=p.id
|
|
WHERE u.is_del=0 AND u.is_primary=false AND u.company_id=#{companyId}
|
|
<if test="state != null">
|
|
AND u.state = #{state}
|
|
</if>
|
|
<if test="key != null and key != ''">
|
|
AND
|
|
(
|
|
u.login_name LIKE concat('%', #{key}, '%')
|
|
OR u.email LIKE concat('%', #{key}, '%')
|
|
or u.name LIKE concat('%', #{key}, '%')
|
|
)
|
|
</if>
|
|
UNION
|
|
SELECT u.id,u.user_phone AS 'phone',0 AS 'userState',u.title_id AS 'titleId',u.area_id AS 'areaId',u.company_id AS 'companyId'
|
|
,p.position_name AS 'title',null AS 'expireTime',c.agency_company_name AS 'companyName',u.user_email AS 'loginName'
|
|
,u.user_name AS 'name',u.user_email AS 'email',u.user_avatar AS 'avatar',a.`name` AS 'areaName',cau.name AS 'createBy'
|
|
,u.create_time AS 'createTime',u.update_by AS 'updateBy',null AS 'updateTime',null AS 'lastLoginTime',null AS 'expireTime'
|
|
,false AS 'isPrimary',0 AS 'state',u.language_code AS 'languageCode',u.type
|
|
FROM app_user_applyfor u
|
|
INNER JOIN t_base_customer c ON u.company_id=c.id
|
|
INNER JOIN app_area a ON u.area_id=a.id
|
|
LEFT JOIN t_base_position p ON u.title_id=p.id
|
|
LEFT JOIN app_user cau ON u.create_by=cau.id
|
|
WHERE u.state=0 AND u.company_id=#{companyId}
|
|
<if test="state > 0">
|
|
AND 1=2
|
|
</if>
|
|
<if test="key != null and key != ''">
|
|
AND
|
|
(
|
|
u.user_email LIKE concat('%', #{key}, '%')
|
|
OR u.user_name LIKE concat('%', #{key}, '%')
|
|
)
|
|
</if>
|
|
</select>
|
|
|
|
<select id="searchAppUserForAdmin" parameterType="com.nflg.mobilebroken.common.pojo.request.SearchAppUserForAdminRequest" resultType="com.nflg.mobilebroken.common.pojo.vo.AppUserForAdminVO">
|
|
SELECT IF(aua.id IS NULL,CONCAT('u-',au.id),CONCAT('f-',aua.id)) AS 'key',au.id,au.avatar,au.login_name
|
|
,au.`name` AS 'userName',fun_getUserCompanys(au.company_id) AS 'companyName',au.`name`,au.email,au.sales_user_name
|
|
,IF(au.is_primary,fun_getPrimaryUserArea(au.company_id),aa.`name`) AS 'areaName',au.state AS 'userState'
|
|
,au.expire_time,IF(aua.id IS NOT NULL,0
|
|
,IF(CONVERT_TZ(NOW(), @@session.time_zone, '+00:00') < au.expire_time,1,2)) AS 'state',au.create_by
|
|
,au.create_time,au.update_by,au.update_time,au.last_login_time,au.is_primary,au.company_id,au.phone,au.area_id
|
|
,au.language_code,p.position_name AS 'title',au.title_id,au.type
|
|
FROM app_user au
|
|
LEFT JOIN app_area aa ON au.area_id=aa.id
|
|
LEFT JOIN app_user_applyfor aua ON aua.user_id=au.id AND aua.state=0
|
|
LEFT JOIN t_base_position p ON au.title_id=p.id
|
|
WHERE au.is_del=0
|
|
<if test="loginName!=null and loginName!=''">
|
|
AND au.login_name LIKE concat('%', #{loginName}, '%')
|
|
</if>
|
|
<if test="name!=null and name!=''">
|
|
AND au.`name` LIKE concat('%', #{name}, '%')
|
|
</if>
|
|
<if test="companyName!=null and companyName!=''">
|
|
AND fun_getUserCompanys(au.company_id) LIKE concat('%', #{companyName}, '%')
|
|
</if>
|
|
<if test="userState!=null">
|
|
AND au.state=#{userState}
|
|
</if>
|
|
<if test="state==0">
|
|
AND aua.id IS NOT NULL
|
|
</if>
|
|
<if test="state==1">
|
|
AND aua.id IS NULL AND CONVERT_TZ(NOW(), @@session.time_zone, '+00:00') < au.expire_time
|
|
</if>
|
|
<if test="state==2">
|
|
AND aua.id IS NULL AND CONVERT_TZ(NOW(), @@session.time_zone, '+00:00') >= au.expire_time
|
|
</if>
|
|
UNION
|
|
SELECT CONCAT('f-',aua.id) AS 'key',aua.id,aua.user_avatar AS 'avatar',aua.user_email AS 'loginName'
|
|
,aua.`user_name` AS 'userName',fun_getUserCompanys(aua.company_id) AS 'companyName',aua.user_name AS 'name'
|
|
,aua.user_email AS 'email',aua.sales_user_name
|
|
,IF(aua.is_primary,fun_getPrimaryUserArea(aua.company_id),aa.`name`) AS 'areaName'
|
|
,null AS 'userState',null AS 'expireTime',0 AS 'state',au.name AS 'createBy',aua.create_time,null AS 'updateBy'
|
|
,null AS 'updateTime',null AS 'lastLoginTime',aua.is_primary,aua.company_id,aua.user_phone AS 'phone',aua.area_id
|
|
,aua.language_code,p.position_name AS 'title',aua.title_id,au.type
|
|
FROM app_user_applyfor aua
|
|
LEFT JOIN app_user au ON au.id=aua.create_by
|
|
LEFT JOIN app_area aa ON aua.area_id=aa.id
|
|
LEFT JOIN t_base_position p ON aua.title_id=p.id
|
|
WHERE aua.type=0 AND aua.state=0
|
|
<if test="loginName!=null and loginName!=''">
|
|
AND aua.user_email LIKE concat('%', #{loginName}, '%')
|
|
</if>
|
|
<if test="name!=null and name!=''">
|
|
AND aua.user_name LIKE concat('%', #{name}, '%')
|
|
</if>
|
|
<if test="companyName!=null and companyName!=''">
|
|
AND fun_getUserCompanys(aua.company_id) LIKE concat('%', #{companyName}, '%')
|
|
</if>
|
|
<if test="userState!=null">
|
|
AND 1=2
|
|
</if>
|
|
<if test="state!=null and state!=0">
|
|
AND 1=2
|
|
</if>
|
|
</select>
|
|
</mapper>
|