<?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.sinata.appointment.mapper.AppointmentOrderMapper">
|
|
<sql id="AdminOrderWhere">
|
o.del_flag = 0
|
<if test="visitedUserName != null and visitedUserName != ''">
|
AND o.visited_user_name LIKE CONCAT('%', #{visitedUserName}, '%')
|
</if>
|
<if test="visitedDeptId != null">
|
AND o.visited_dept_id = #{visitedDeptId}
|
</if>
|
<if test="accessAreaIds != null and accessAreaIds.size() > 0">
|
AND (
|
<foreach collection="accessAreaIds" item="areaId" separator=" OR ">
|
o.pass_access_area_ids = CONCAT('[', #{areaId}, ']')
|
OR o.pass_access_area_ids LIKE CONCAT('[', #{areaId}, ',%')
|
OR o.pass_access_area_ids LIKE CONCAT('%,', #{areaId}, ',%')
|
OR o.pass_access_area_ids LIKE CONCAT('%,', #{areaId}, ']')
|
</foreach>
|
)
|
</if>
|
<if test="(accessAreaIds == null or accessAreaIds.size() == 0) and accessArea != null and accessArea != ''">
|
AND o.pass_access_area_names LIKE CONCAT('%', #{accessArea}, '%')
|
</if>
|
<if test="localUnit != null and localUnit != ''">
|
AND o.pass_local_unit_names LIKE CONCAT('%', #{localUnit}, '%')
|
</if>
|
<if test="visitReasonCode != null and visitReasonCode != ''">
|
AND o.visit_reason_code = #{visitReasonCode}
|
</if>
|
<if test="visitDateEnd != null">
|
AND o.visit_start_date <= #{visitDateEnd}
|
</if>
|
<if test="visitDateStart != null">
|
AND o.visit_end_date >= #{visitDateStart}
|
</if>
|
<if test="visitorKeyword != null and visitorKeyword != ''">
|
AND EXISTS (
|
SELECT 1
|
FROM appointment_visitor av
|
WHERE av.del_flag = 0
|
AND av.order_id = o.id
|
AND av.name LIKE CONCAT('%', #{visitorKeyword}, '%')
|
)
|
</if>
|
<if test="displayStatus != null and displayStatus != ''">
|
<choose>
|
<when test="displayStatus == 'PENDING_VISIT'">
|
AND (
|
o.status = 'PENDING_APPROVAL'
|
OR (o.status = 'APPROVED' AND CURDATE() < o.visit_start_date)
|
)
|
</when>
|
<when test="displayStatus == 'EFFECTIVE'">
|
AND o.status = 'APPROVED'
|
AND o.visit_start_date IS NOT NULL
|
AND o.visit_end_date IS NOT NULL
|
AND CURDATE() >= o.visit_start_date
|
AND CURDATE() <= o.visit_end_date
|
</when>
|
<otherwise>
|
AND NOT (
|
o.status = 'PENDING_APPROVAL'
|
OR (o.status = 'APPROVED' AND CURDATE() < o.visit_start_date)
|
OR (
|
o.status = 'APPROVED'
|
AND o.visit_start_date IS NOT NULL
|
AND o.visit_end_date IS NOT NULL
|
AND CURDATE() >= o.visit_start_date
|
AND CURDATE() <= o.visit_end_date
|
)
|
)
|
</otherwise>
|
</choose>
|
</if>
|
<if test="approvalStatus != null and approvalStatus != ''">
|
<choose>
|
<when test="approvalStatus == 'APPROVED'">
|
AND o.status IN ('APPROVED', 'VISITED', 'EXPIRED')
|
</when>
|
<when test="approvalStatus == 'REJECTED'">
|
AND o.status = 'REJECTED'
|
</when>
|
<when test="approvalStatus == 'CANCELLED'">
|
AND o.status = 'CANCELLED'
|
</when>
|
<when test="approvalStatus == 'PENDING_APPROVAL'">
|
AND o.status = 'PENDING_APPROVAL'
|
AND (ai.current_node_code IS NULL OR ai.current_node_code = '')
|
</when>
|
<otherwise>
|
AND o.status = 'PENDING_APPROVAL'
|
AND ai.current_node_code = #{approvalStatus}
|
</otherwise>
|
</choose>
|
</if>
|
</sql>
|
|
<select id="pageAdminOrders" resultType="com.sinata.appointment.entity.AppointmentOrder">
|
SELECT o.*
|
FROM appointment_order o
|
LEFT JOIN (
|
SELECT ai1.order_id, ai1.current_node_code
|
FROM approval_instance ai1
|
INNER JOIN (
|
SELECT order_id, MAX(id) AS max_id
|
FROM approval_instance
|
WHERE del_flag = 0
|
GROUP BY order_id
|
) latest ON latest.max_id = ai1.id
|
WHERE ai1.del_flag = 0
|
) ai ON ai.order_id = o.id
|
WHERE
|
<include refid="AdminOrderWhere"/>
|
ORDER BY o.create_time DESC, o.id DESC
|
</select>
|
|
<select id="pageMiniVisitRecords" resultType="com.sinata.appointment.entity.AppointmentOrder">
|
SELECT o.*
|
FROM appointment_order o
|
WHERE o.del_flag = 0
|
AND o.status = 'APPROVED'
|
AND o.visited_user_id = #{visitedUserId}
|
<if test="futureOnly">
|
AND (
|
CASE
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'PM'
|
THEN TIMESTAMP(o.visit_start_date, '12:00:00')
|
ELSE TIMESTAMP(o.visit_end_date, '23:59:59')
|
END
|
) > NOW()
|
</if>
|
<if test="visitDate != null">
|
AND o.visit_start_date IS NOT NULL
|
AND o.visit_end_date IS NOT NULL
|
AND #{visitDate} >= o.visit_start_date
|
AND #{visitDate} <= o.visit_end_date
|
</if>
|
<if test="visitorNameKeyword != null and visitorNameKeyword != ''">
|
AND EXISTS (
|
SELECT 1
|
FROM appointment_visitor av
|
WHERE av.del_flag = 0
|
AND av.order_id = o.id
|
AND av.name LIKE CONCAT('%', #{visitorNameKeyword}, '%')
|
)
|
</if>
|
<choose>
|
<when test="futureOnly">
|
ORDER BY ABS(TIMESTAMPDIFF(
|
SECOND,
|
NOW(),
|
CASE
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'PM'
|
THEN TIMESTAMP(o.visit_start_date, '12:00:00')
|
ELSE TIMESTAMP(o.visit_start_date, '00:00:00')
|
END
|
)) ASC,
|
o.visit_start_date ASC,
|
CASE
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'AM' THEN 1
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'PM' THEN 2
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'ALL_DAY' THEN 3
|
ELSE 4
|
END ASC,
|
o.id DESC
|
</when>
|
<otherwise>
|
ORDER BY o.visit_end_date DESC,
|
CASE
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'ALL_DAY' THEN 3
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'PM' THEN 2
|
WHEN o.visit_time_mode = 'SINGLE' AND o.visit_time_slot = 'AM' THEN 1
|
ELSE 0
|
END DESC,
|
o.create_time DESC,
|
o.id DESC
|
</otherwise>
|
</choose>
|
</select>
|
|
<select id="pageMiniMyOrders" resultType="com.sinata.appointment.entity.AppointmentOrder">
|
SELECT o.*
|
FROM appointment_order o
|
LEFT JOIN biz_visit_reason bvr
|
ON bvr.del_flag = 0
|
AND bvr.reason_code = o.visit_reason_code
|
WHERE o.del_flag = 0
|
AND o.submitter_id = #{submitterId}
|
AND o.submitter_visible_flag = 1
|
<if test="status != null and status != ''">
|
<choose>
|
<when test="status == 'PENDING_VISIT'">
|
AND (
|
o.status = 'PENDING_APPROVAL'
|
OR (o.status = 'APPROVED' AND CURDATE() < o.visit_start_date)
|
)
|
</when>
|
<when test="status == 'EFFECTIVE'">
|
AND o.status = 'APPROVED'
|
AND o.visit_start_date IS NOT NULL
|
AND o.visit_end_date IS NOT NULL
|
AND CURDATE() >= o.visit_start_date
|
AND CURDATE() <= o.visit_end_date
|
</when>
|
<otherwise>
|
AND NOT (
|
o.status = 'PENDING_APPROVAL'
|
OR (o.status = 'APPROVED' AND CURDATE() < o.visit_start_date)
|
OR (
|
o.status = 'APPROVED'
|
AND o.visit_start_date IS NOT NULL
|
AND o.visit_end_date IS NOT NULL
|
AND CURDATE() >= o.visit_start_date
|
AND CURDATE() <= o.visit_end_date
|
)
|
)
|
</otherwise>
|
</choose>
|
</if>
|
<if test="keyword != null and keyword != ''">
|
AND (
|
o.visited_user_name LIKE CONCAT('%', #{keyword}, '%')
|
OR o.visit_reason_code LIKE CONCAT('%', #{keyword}, '%')
|
OR o.visit_reason_other LIKE CONCAT('%', #{keyword}, '%')
|
OR bvr.reason_name LIKE CONCAT('%', #{keyword}, '%')
|
)
|
</if>
|
ORDER BY o.create_time DESC, o.id DESC
|
</select>
|
|
<select id="selectMiniVisibleOrderById" resultType="com.sinata.appointment.entity.AppointmentOrder">
|
SELECT o.*
|
FROM appointment_order o
|
WHERE o.del_flag = 0
|
AND o.id = #{id}
|
AND o.submitter_id = #{submitterId}
|
AND o.submitter_visible_flag = 1
|
LIMIT 1
|
</select>
|
|
<select id="listDashboardTrend" resultType="com.sinata.appointment.dto.DashboardTrendPointVo">
|
SELECT DATE(o.create_time) AS statDate,
|
COUNT(*) AS appointmentCount,
|
0 AS inProgressCount,
|
SUM(CASE WHEN o.status = 'REJECTED' THEN 1 ELSE 0 END) AS rejectedCount,
|
SUM(CASE WHEN o.status = 'CANCELLED' THEN 1 ELSE 0 END) AS cancelledCount
|
FROM appointment_order o
|
WHERE o.del_flag = 0
|
AND o.create_time <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
|
AND o.create_time <![CDATA[<]]> DATE_ADD(CONCAT(#{endDate}, ' 00:00:00'), INTERVAL 1 DAY)
|
<if test="deptIds != null and deptIds.size() > 0">
|
AND o.visited_dept_id IN
|
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
|
#{deptId}
|
</foreach>
|
</if>
|
GROUP BY DATE(o.create_time)
|
ORDER BY DATE(o.create_time)
|
</select>
|
|
</mapper>
|