You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
11 KiB

2 months ago
<?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.example.web.mapper.UsersMapper">
<select id="findWithPagination" resultType="com.example.web.entity.Users">
SELECT u.*, um.userName as managerName FROM users u
2 months ago
JOIN usermanagements um ON u.userId = um.userId
<where>
<if test="followup != null and followup != ''">
AND u.followup = #{followup}
</if>
<if test="type != null and type != ''">
AND u.type = #{type}
</if>
<if test="userName != null and userName != ''">
AND um.userName = #{userName}
</if>
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
2 months ago
<if test="managercompany != null and managercompany != ''">
AND um.managercompany = #{managercompany}
</if>
<if test="managerdepartment != null and managerdepartment != ''">
AND um.managerdepartment = #{managerdepartment}
</if>
<if test="organization != null and organization != ''">
AND um.organization = #{organization}
</if>
<if test="role != null and role != ''">
AND um.role = #{role}
</if>
AND (u.sync_statuss IS NULL OR u.sync_statuss NOT IN (0, 1))
AND u.type != 'Colleague'
2 months ago
</where>
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="count" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
JOIN usermanagements um ON u.userId = um.userId
<where>
<if test="followup != null and followup != ''">
AND u.followup = #{followup}
</if>
<if test="type != null and type != ''">
AND u.type = #{type}
</if>
<if test="userName != null and userName != ''">
AND um.userName = #{userName}
</if>
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
2 months ago
<if test="managercompany != null and managercompany != ''">
AND um.managercompany = #{managercompany}
</if>
<if test="managerdepartment != null and managerdepartment != ''">
AND um.managerdepartment = #{managerdepartment}
</if>
<if test="organization != null and organization != ''">
AND um.organization = #{organization}
</if>
<if test="role != null and role != ''">
AND um.role = #{role}
</if>
AND (u.sync_statuss IS NULL OR u.sync_statuss NOT IN (0, 1))
AND u.type != 'Colleague'
2 months ago
</where>
</select>
<select id="findByUserIds" resultType="com.example.web.entity.Users">
SELECT u.*, (SELECT um.userName FROM usermanagements um WHERE um.userId = u.userId LIMIT 1) as managerName
FROM users u
WHERE u.userId IN
2 months ago
(
SELECT userId FROM usermanagements
WHERE userName = #{userName}
AND managercompany = #{managercompany}
AND managerdepartment = #{managerdepartment}
AND organization = #{organization}
AND role = #{role}
)
AND u.type != 'Colleague'
<if test="managerName != null and managerName != ''">
AND EXISTS (SELECT 1 FROM usermanagements um WHERE um.userId = u.userId AND um.userName = #{managerName})
</if>
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="countByUserIds" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
WHERE u.userId IN
2 months ago
(
SELECT userId FROM usermanagements
WHERE userName = #{userName}
AND managercompany = #{managercompany}
AND managerdepartment = #{managerdepartment}
AND organization = #{organization}
AND role = #{role}
)
AND u.type != 'Colleague'
<if test="managerName != null and managerName != ''">
AND EXISTS (SELECT 1 FROM usermanagements um WHERE um.userId = u.userId AND um.userName = #{managerName})
</if>
2 months ago
</select>
<select id="findPublicWithPagination" resultType="com.example.web.entity.Users">
SELECT u.* FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND (um.managercompany IS NULL OR um.managercompany = '')
2 months ago
AND (um.managerdepartment IS NULL OR um.managerdepartment = '')
AND (um.organization IS NULL OR um.organization = '')
AND (um.role IS NULL OR um.role = '')
AND (um.userName IS NULL OR um.userName = '')
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="countPublic" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND (um.managercompany IS NULL OR um.managercompany = '')
2 months ago
AND (um.managerdepartment IS NULL OR um.managerdepartment = '')
AND (um.organization IS NULL OR um.organization = '')
AND (um.role IS NULL OR um.role = '')
AND (um.userName IS NULL OR um.userName = '')
</select>
<select id="findAllWithPagination" resultType="com.example.web.entity.Users">
SELECT u.*, um.userName as managerName FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND ((um.managercompany IS NOT NULL AND um.managercompany != '')
OR (um.managerdepartment IS NOT NULL AND um.managerdepartment != '')
OR (um.organization IS NOT NULL AND um.organization != '')
OR (um.role IS NOT NULL AND um.role != '')
OR (um.userName IS NOT NULL AND um.userName != ''))
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="countAll" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND ((um.managercompany IS NOT NULL AND um.managercompany != '')
OR (um.managerdepartment IS NOT NULL AND um.managerdepartment != '')
OR (um.organization IS NOT NULL AND um.organization != '')
OR (um.role IS NOT NULL AND um.role != '')
OR (um.userName IS NOT NULL AND um.userName != ''))
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
2 months ago
</select>
<select id="findPersonalWithPagination" resultType="com.example.web.entity.Users">
SELECT u.*, um.userName as managerName FROM users u
JOIN usermanagements um ON u.userId = um.userId
2 months ago
WHERE followup IS NOT NULL AND followup != ''
AND (u.sync_statuss IS NULL OR u.sync_statuss NOT IN (0, 1))
AND u.type != 'Colleague'
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="countPersonal" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.followup IS NOT NULL AND u.followup != ''
AND (u.sync_statuss IS NULL OR u.sync_statuss NOT IN (0, 1))
<if test="managerName != null and managerName != ''">
AND um.userName = #{managerName}
</if>
2 months ago
</select>
<select id="findPublicAllWithPagination" resultType="com.example.web.entity.Users">
SELECT u.* FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND (um.managercompany IS NULL OR um.managercompany = '')
2 months ago
AND (um.managerdepartment IS NULL OR um.managerdepartment = '')
AND (um.organization IS NULL OR um.organization = '')
AND (um.role IS NULL OR um.role = '')
AND (um.userName IS NULL OR um.userName = '')
ORDER BY u.created_at DESC
2 months ago
LIMIT #{offset}, #{limit}
</select>
<select id="countPublicAll" resultType="java.lang.Integer">
SELECT COUNT(*) FROM users u
JOIN usermanagements um ON u.userId = um.userId
WHERE u.type != 'Colleague'
AND (um.managercompany IS NULL OR um.managercompany = '')
2 months ago
AND (um.managerdepartment IS NULL OR um.managerdepartment = '')
AND (um.organization IS NULL OR um.organization = '')
AND (um.role IS NULL OR um.role = '')
AND (um.userName IS NULL OR um.userName = '')
</select>
<update id="updateFollowup" parameterType="java.util.Map">
UPDATE users
SET followup = #{followup},
followup_at = NOW(),
type = #{type},
level = #{level},
detailedaddress = #{detailedaddress},
company = #{company},
demand = #{demand},
region = #{region}
2 months ago
WHERE userId = #{userId}
</update>
<update id="updateUsersManagements" parameterType="java.util.Map">
INSERT INTO usermanagements (userId, userName, managercompany, managerdepartment, organization, role, managerId)
VALUES (#{userId}, #{userName}, #{managercompany}, #{managerdepartment}, #{organization}, #{role}, #{userId})
ON DUPLICATE KEY UPDATE
userName = #{userName},
managercompany = #{managercompany},
managerdepartment = #{managerdepartment},
organization = #{organization},
role = #{role},
managerId = #{userId}
</update>
<update id="updateSyncStatus" parameterType="java.util.Map">
UPDATE users
SET sync_statuss = NULL
2 months ago
WHERE userId = #{userId}
</update>
<update id="updateSyncStatusToZero" parameterType="java.util.Map">
UPDATE users
SET sync_statuss = 0
WHERE userId = #{userId}
</update>
2 months ago
<update id="updateUserTypeAndClearFollowup" parameterType="java.util.Map">
UPDATE users
SET type = #{type},
sync_statuss = NULL
2 months ago
WHERE userId = #{userId}
</update>
<update id="clearUsersManagements" parameterType="java.util.Map">
UPDATE usermanagements
SET managercompany = '',
managerdepartment = '',
organization = '',
role = '',
userName = ''
2 months ago
WHERE userId = #{userId}
</update>
<select id="findByUserId" parameterType="String" resultType="com.example.web.entity.Users">
SELECT * FROM users WHERE userId = #{userId}
</select>
2 months ago
</mapper>