btxtgxq-system-city/src/main/resources/mybatis/mapper/usersignin/usersignin-mapper.xml
2021-10-18 18:07:55 +08:00

684 lines
24 KiB
XML
Executable File

<?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.cm.systemcity.dao.usersignin.IUserSigninDao">
<resultMap id="userSigninDTO" type="com.cm.systemcity.pojo.dtos.usersignin.UserSigninDTO">
<id property="userSigninId" column="user_signin_id"/>
<result property="userName" column="user_name"/>
<result property="signinLongitude" column="signin_longitude"/>
<result property="signinLatitude" column="signin_latitude"/>
<result property="isLate" column="is_late"/>
<result property="isOutside" column="is_outside"/>
<result property="amPm" column="am_pm"/>
<result property="creator" column="creator"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="userPhone" column="user_phone"/>
<result property="userAvatar" column="user_avatar"/>
</resultMap>
<resultMap id="userSigninDetailDTO" type="com.cm.systemcity.pojo.dtos.usersignin.UserSigninDetailDTO" extends="userSigninDTO">
<result property="communityBossLevel" column="community_boss_level"/>
<result property="areaId" column="area_id"/>
<result property="areaName" column="area_name"/>
<result property="communityIds" column="community_ids"/>
<result property="communityNames" column="community_names"/>
<result property="departmentIds" column="department_ids"/>
<result property="departmentNames" column="department_names"/>
<result property="positionIds" column="position_ids"/>
<result property="positionNames" column="position_names"/>
</resultMap>
<resultMap id="userUnSigninDetailDTO" type="com.cm.systemcity.pojo.dtos.usersignin.UserUnSigninDetailDTO">
<id property="userId" column="user_id"/>
<result property="userName" column="user_name"/>
<result property="userPhone" column="user_phone"/>
<result property="userAvatar" column="user_avatar"/>
<result property="communityBossLevel" column="community_boss_level"/>
<result property="areaId" column="area_id"/>
<result property="areaName" column="area_name"/>
<result property="departmentIds" column="department_ids"/>
<result property="departmentNames" column="department_names"/>
<result property="positionIds" column="position_ids"/>
<result property="positionNames" column="position_names"/>
<result property="communityIds" column="community_ids"/>
<result property="communityNames" column="community_names"/>
</resultMap>
<resultMap id="userSignDayStatusDTO" type="com.cm.systemcity.pojo.dtos.usersignin.UserSignDayStatusDTO">
<id property="userId" column="user_id"/>
<result property="userName" column="user_name"/>
<result property="userPhone" column="user_phone"/>
<result property="userAvatar" column="user_avatar"/>
<result property="signinCount" column="signin_count"/>
<result property="signoutCount" column="signout_count"/>
<result property="amDayLeaveCount" column="am_day_leave_count"/>
<result property="pmDayLeaveCount" column="pm_day_leave_count"/>
<result property="communityBossLevel" column="community_boss_level"/>
<result property="areaId" column="area_id"/>
<result property="areaName" column="area_name"/>
<result property="departmentIds" column="department_ids"/>
<result property="departmentNames" column="department_names"/>
<result property="positionIds" column="position_ids"/>
<result property="positionNames" column="position_names"/>
<result property="communityIds" column="community_ids"/>
<result property="communityNames" column="community_names"/>
<result property="roleIds" column="role_ids"/>
</resultMap>
<!-- 新增人员签到 -->
<insert id="saveUserSignin" parameterType="map">
INSERT INTO city_user_signin(
user_signin_id,
user_name,
signin_longitude,
signin_latitude,
is_late,
is_outside,
am_pm,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
#{userSigninId},
#{userName},
#{signinLongitude},
#{signinLatitude},
#{isLate},
#{isOutside},
#{amPm},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<!-- 删除人员签到 -->
<update id="removeUserSignin" parameterType="map">
UPDATE
city_user_signin
SET
is_delete = 1,
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
user_signin_id IN
<foreach collection="userSigninIds" index="index" open="(" separator="," close=")">
#{userSigninIds[${index}]}
</foreach>
</update>
<!-- 修改人员签到 -->
<update id="updateUserSignin" parameterType="map">
UPDATE
city_user_signin
SET
<if test="userName != null and userName != ''">
user_name = #{userName},
</if>
<if test="signinLongitude != null and signinLongitude != ''">
signin_longitude = #{signinLongitude},
</if>
<if test="signinLatitude != null and signinLatitude != ''">
signin_latitude = #{signinLatitude},
</if>
<if test="isLate != null">
is_late = #{isLate},
</if>
<if test="isOutside != null">
is_outside = #{isOutside},
</if>
<if test="amPm != null and amPm != ''">
am_pm = #{amPm},
</if>
<if test="gmtCreate != null and gmtCreate != ''">
gmt_create = #{gmtCreate},
</if>
modifier = #{modifier},
gmt_modified = #{gmtModified}
WHERE
user_signin_id = #{userSigninId}
</update>
<!-- 人员签到列表 -->
<select id="listUserSignin" parameterType="map" resultMap="userSigninDTO">
SELECT
t1.user_signin_id,
t1.user_name,
t1.signin_longitude,
t1.signin_latitude,
t1.is_late,
t1.is_outside,
t1.am_pm,
t1.creator,
LEFT(t1.gmt_create, 19) gmt_create,
t2.user_phone,
t2.user_avatar
FROM
city_user_signin t1
INNER JOIN
sys_user t2
ON
t1.creator = t2.user_id
AND
t2.is_delete = 0
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
AND
t1.user_name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="signTime != null and signTime != ''">
AND
LEFT(t1.gmt_create, 10) = #{signTime}
</if><!--
<if test="amPm != null and amPm != ''">
AND
t1.am_pm = #{amPm}
</if>-->
<if test="creator != null and creator != ''">
AND
t1.creator = #{creator}
</if>
<if test="userSigninIds != null and userSigninIds.size > 0">
AND
t1.user_signin_id IN
<foreach collection="userSigninIds" index="index" open="(" separator="," close=")">
#{userSigninIds[${index}]}
</foreach>
</if>
ORDER BY
t1.gmt_create DESC
</select>
<!-- 分页人员签到详细列表 -->
<select id="listUserSigninDetail" parameterType="map" resultMap="userSigninDetailDTO">
SELECT
*
FROM (
SELECT
t1.user_signin_id,
t1.user_name,
t1.signin_longitude,
t1.signin_latitude,
t1.is_late,
t1.is_outside,
t1.am_pm,
t1.creator,
LEFT(t1.gmt_create, 19) gmt_create,
t2.user_phone,
t2.user_avatar,
t3.community_boss_level,
t3.area_id,
t3.area_name,
GROUP_CONCAT(t5.department_id) department_ids,
GROUP_CONCAT(t5.department_name) department_names,
GROUP_CONCAT(t7.position_id) position_ids,
GROUP_CONCAT(t7.position_name) position_names,
GROUP_CONCAT(t9.community_id) community_ids,
GROUP_CONCAT(t9.community_name) community_names,
GROUP_CONCAT(t10.role_id) role_ids
FROM
city_user_signin t1
INNER JOIN
sys_user t2
ON
t1.creator = t2.user_id AND t2.is_delete = 0
LEFT JOIN
city_community_boss t3
ON
t1.creator = t3.community_boss_id AND t3.is_delete = 0
LEFT JOIN
sys_department_user t4
ON
t1.creator = t4.user_id
LEFT JOIN
sys_department t5
ON
t4.department_id = t5.department_id AND t5.is_delete = 0
LEFT JOIN
sys_position_user t6
ON
t1.creator = t6.user_id
LEFT JOIN
sys_position t7
ON
t6.position_id = t7.position_id AND t7.is_delete = 0
LEFT JOIN
city_community_boss_community t8
ON
t3.community_boss_id = t8.community_boss_id
LEFT JOIN
city_community t9
ON
t8.community_id = t9.community_id
LEFT JOIN
sys_role_user t10
ON
t1.creator = t10.user_id
WHERE
t1.is_delete = 0
GROUP BY
t1.user_signin_id,
t1.user_name,
t1.signin_longitude,
t1.signin_latitude,
t1.is_late,
t1.is_outside,
t1.am_pm,
t1.creator,
t1.gmt_create,
t2.user_phone,
t2.user_avatar,
t3.community_boss_level,
t3.area_id,
t3.area_name
) mt1
WHERE
1 = 1
<if test="keywords != null and keywords != ''">
AND
mt1.user_name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(mt1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(mt1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
<if test="signTime != null and signTime != ''">
AND
LEFT(mt1.gmt_create, 10) = #{signTime}
</if>
<if test="amPm != null and amPm != ''">
AND
mt1.am_pm = #{amPm}
</if>
<if test="isLate != null">
AND
mt1.is_late = #{isLate}
</if>
<if test="areaId != null and areaId != ''">
AND
mt1.area_id = #{areaId}
</if>
<if test="communityId != null and communityId != ''">
AND
mt1.community_ids LIKE CONCAT('%', #{communityId}, '%')
</if>
<if test="departmentId != null and departmentId != ''">
AND
mt1.department_ids LIKE CONCAT('%', #{departmentId}, '%')
</if>
<if test="communityBossLevel != null and communityBossLevel != ''">
AND
mt1.community_boss_level = #{communityBossLevel}
</if>
<if test="roleId != null and roleId != ''">
AND
mt1.role_ids LIKE CONCAT('%', #{roleId}, '%')
</if>
<if test="userSigninIds != null and userSigninIds.size > 0">
AND
mt1.user_signin_id IN
<foreach collection="userSigninIds" index="index" open="(" separator="," close=")">
#{userSigninIds[${index}]}
</foreach>
</if>
<if test="userIds != null and userIds.size > 0">
AND
mt1.creator IN
<foreach collection="userIds" index="index" open="(" separator="," close=")">
#{userIds[${index}]}
</foreach>
</if>
ORDER BY
mt1.gmt_create DESC
</select>
<!-- 人员签到详情 -->
<select id="getUserSignin" parameterType="map" resultMap="userSigninDTO">
SELECT
t1.user_signin_id,
t1.user_name,
t1.signin_longitude,
t1.signin_latitude,
t1.is_late,
t1.is_outside,
t1.am_pm,
t1.creator,
LEFT(t1.gmt_create, 19) gmt_create
FROM
city_user_signin t1
WHERE
t1.is_delete = 0
<if test="userSigninId != null and userSigninId != ''">
AND
t1.user_signin_id = #{userSigninId}
</if>
<if test="creator != null and creator != ''">
AND
t1.creator = #{creator}
</if>
<if test="signTime != null and signTime != ''">
AND
LEFT(t1.gmt_create, 10) = #{signTime}
</if>
<if test="amPm != null and amPm != ''">
AND
t1.am_pm = #{amPm}
</if>
</select>
<!-- 人员未签到详细列表 -->
<select id="listUserUnSigninDetail" parameterType="map" resultMap="userUnSigninDetailDTO">
SELECT
*
FROM (
SELECT
t1.user_id,
t1.user_username,
t1.user_name,
t1.user_phone,
t1.user_avatar,
t2.community_boss_level,
t2.area_id,
t2.area_name,
GROUP_CONCAT( t4.department_id ) department_ids,
GROUP_CONCAT( t4.department_name ) department_names,
GROUP_CONCAT( t6.position_id ) position_ids,
GROUP_CONCAT( t6.position_name ) position_names,
GROUP_CONCAT( t8.community_id ) community_ids,
GROUP_CONCAT( t8.community_name ) community_names,
GROUP_CONCAT( t9.role_id ) role_ids
FROM
sys_user t1
LEFT JOIN
city_community_boss t2 ON t1.user_id = t2.community_boss_id
AND
t2.is_delete = 0
LEFT JOIN
sys_department_user t3 ON t1.user_id = t3.user_id
LEFT JOIN
sys_department t4 ON t3.department_id = t4.department_id
AND
t4.is_delete = 0
LEFT JOIN
sys_position_user t5 ON t1.user_id = t5.user_id
LEFT JOIN
sys_position t6 ON t5.position_id = t6.position_id
AND
t6.is_delete = 0
LEFT JOIN
city_community_boss_community t7 ON t2.community_boss_id = t7.community_boss_id
LEFT JOIN
city_community t8 ON t7.community_id = t8.community_id
LEFT JOIN
sys_role_user t9 ON t1.user_id = t9.user_id
WHERE
t1.is_delete = 0
AND
t1.user_id NOT IN (
SELECT
st1.creator
FROM
city_user_signin st1
WHERE
st1.is_delete = 0
<if test="amPm != null and amPm != ''">
AND
st1.am_pm = #{amPm}
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(st1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(st1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
</if>
GROUP BY
st1.creator
)
AND
t1.user_id NOT IN (
SELECT
st2.creator
FROM
city_leave st2
WHERE
st2.is_delete = 0
<if test="showTime != null and showTime != ''">
AND (
LEFT(st2.leave_time, 10) <![CDATA[ <= ]]> #{showTime}
AND
LEFT(st2.leave_time_end, 10) <![CDATA[ >= ]]> #{showTime}
)
</if>
<if test="leaveTimeList != null and leaveTimeList.size > 0">
AND
<foreach collection="leaveTimeList" index="index" open="(" separator="OR" close=")">
st2.leave_time <![CDATA[ <= ]]> #{leaveTimeList[${index}].showTodayStartTime}
AND
st2.leave_time_end <![CDATA[ >= ]]> #{leaveTimeList[${index}].showTodayStartTimeEnd}
</foreach>
</if>
GROUP BY
st2.creator
)
GROUP BY
t1.user_id,
t1.user_username,
t1.user_name,
t1.user_phone,
t1.user_email,
t1.user_avatar,
t2.community_boss_level,
t2.area_id,
t2.area_name
) mt1
WHERE
mt1.user_username != 'admin'
<if test="keywords != null and keywords != ''">
AND
mt1.user_name LIKE CONCAT('%', #{keywords}, '%')
</if>
<if test="areaId != null and areaId != ''">
AND
mt1.area_id = #{areaId}
</if>
<if test="communityId != null and communityId != ''">
AND
mt1.community_ids LIKE CONCAT('%', #{communityId}, '%')
</if>
<if test="departmentId != null and departmentId != ''">
AND
mt1.department_ids LIKE CONCAT('%', #{departmentId}, '%')
</if>
<if test="communityBossLevel != null and communityBossLevel != ''">
AND
mt1.community_boss_level = #{communityBossLevel}
</if>
<if test="roleId != null and roleId != ''">
AND
mt1.role_ids LIKE CONCAT('%', #{roleId}, '%')
</if>
<if test="userIds != null and userIds.size > 0">
AND
mt1.user_id IN
<foreach collection="userIds" index="index" open="(" separator="," close=")">
#{userIds[${index}]}
</foreach>
</if>
</select>
<!-- 日签到状态列表 -->
<select id="listSigninDayStatus" parameterType="map" resultMap="userSignDayStatusDTO">
SELECT
*
FROM (
SELECT
t1.user_id,
t1.user_username,
t1.user_name,
t1.user_phone,
t1.user_avatar,
t2.community_boss_level,
t2.area_id,
t2.area_name,
(
SELECT
COUNT(*)
FROM
city_user_signin st1
WHERE
st1.is_delete = 0
AND
t1.user_id = st1.creator
AND
LEFT(st1.gmt_create, 10) = #{showDay}
) signin_count,
(
SELECT
COUNT(*)
FROM
city_user_signout st2
WHERE
st2.is_delete = 0
AND
t1.user_id = st2.creator
AND
LEFT(st2.gmt_create, 10) = #{showDay}
) signout_count,
(
SELECT
COUNT(*)
FROM
city_leave st3
WHERE
st3.is_delete = 0
AND
t1.user_id = st3.creator
AND (
st3.leave_time <![CDATA[ <= ]]> #{amStartTime}
AND
#{amStartTime} <![CDATA[ <= ]]> #{amEndTime}
AND
#{amEndTime} <![CDATA[ <= ]]> st3.leave_time_end
)
GROUP BY
st3.creator
) am_day_leave_count,
(
SELECT
COUNT(*)
FROM
city_leave st4
WHERE
st4.is_delete = 0
AND
t1.user_id = st4.creator
AND (
st4.leave_time <![CDATA[ <= ]]> #{pmStartTime}
AND
#{pmStartTime} <![CDATA[ <= ]]> #{pmEndTime}
AND
#{pmEndTime} <![CDATA[ <= ]]> st4.leave_time_end
)
GROUP BY
st4.creator
) pm_day_leave_count,
GROUP_CONCAT( t4.department_id ) department_ids,
GROUP_CONCAT( t4.department_name ) department_names,
GROUP_CONCAT( t6.position_id ) position_ids,
GROUP_CONCAT( t6.position_name ) position_names,
GROUP_CONCAT( t8.community_id ) community_ids,
GROUP_CONCAT( t8.community_name ) community_names,
GROUP_CONCAT( t9.role_id ) role_ids
FROM
sys_user t1
LEFT JOIN city_community_boss t2 ON t1.user_id = t2.community_boss_user_id
AND
t2.is_delete = 0
LEFT JOIN
sys_department_user t3 ON t1.user_id = t3.user_id
LEFT JOIN
sys_department t4 ON t3.department_id = t4.department_id
AND
t4.is_delete = 0
LEFT JOIN
sys_position_user t5 ON t1.user_id = t5.user_id
LEFT JOIN
sys_position t6 ON t5.position_id = t6.position_id
AND
t6.is_delete = 0
LEFT JOIN
city_community_boss_community t7 ON t2.community_boss_id = t7.community_boss_id
LEFT JOIN
city_community t8 ON t7.community_id = t8.community_id
LEFT JOIN
sys_role_user t9 ON t1.user_id = t9.user_id
WHERE
t1.is_delete = 0
GROUP BY
t1.user_id,
t1.user_username,
t1.user_name,
t1.user_phone,
t1.user_email,
t1.user_avatar,
t2.community_boss_level,
t2.area_id,
t2.area_name
) mt1
WHERE
mt1.user_username != 'admin'
ORDER BY
mt1.user_id ASC
</select>
<!-- 统计签到数量 -->
<select id="countUserSignin" parameterType="map" resultType="Integer">
SELECT
COUNT(*)
FROM (
SELECT
creator
FROM
city_user_signin
WHERE
is_delete = 0
<if test="showTime != null and showTime != ''">
AND
LEFT(gmt_create, 10) = #{showTime}
</if>
<if test="amPm != null and amPm != ''">
AND
am_pm = #{amPm}
</if>
<if test="userIds != null and userIds.size > 0">
AND
creator IN
<foreach collection="userIds" index="index" open="(" separator="," close=")">
#{userIds[${index}]}
</foreach>
</if>
GROUP BY
creator
) mt
</select>
</mapper>