longz
2026-07-08 700f9d0da314a4ea701fe9f68d305b67d72ec5fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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.ApprovalInstanceMapper">
 
    <select id="countDashboardByCreateTime" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM approval_instance ai
        INNER JOIN appointment_order o ON o.id = ai.order_id AND o.del_flag = 0
        WHERE ai.del_flag = 0
          AND ai.status = #{status}
          AND ai.create_time <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
          AND ai.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>
    </select>
 
    <select id="listDashboardFinishedTrend" resultType="com.sinata.appointment.dto.DashboardDailyTotalVo">
        SELECT DATE(ai.finished_at) AS statDate,
               COUNT(*) AS totalCount
        FROM approval_instance ai
        INNER JOIN appointment_order o ON o.id = ai.order_id AND o.del_flag = 0
        WHERE ai.del_flag = 0
          AND ai.status = #{status}
          AND ai.finished_at IS NOT NULL
          AND ai.finished_at <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00')
          AND ai.finished_at <![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(ai.finished_at)
        ORDER BY DATE(ai.finished_at)
    </select>
 
    <select id="listDashboardInProgressInstances" resultType="com.sinata.appointment.entity.ApprovalInstance">
        SELECT ai.*
        FROM approval_instance ai
        INNER JOIN appointment_order o ON o.id = ai.order_id AND o.del_flag = 0
        WHERE ai.del_flag = 0
          AND ai.status = 'IN_PROGRESS'
          AND ai.create_time <![CDATA[<]]> DATE_ADD(CONCAT(#{endDate}, ' 00:00:00'), INTERVAL 1 DAY)
          AND (ai.finished_at IS NULL OR ai.finished_at <![CDATA[>=]]> CONCAT(#{startDate}, ' 00:00:00'))
        <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>
    </select>
 
</mapper>