zhoushihao
2025-09-05 dd4778d2cc47467a39473f02513ec5438b5c9512
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?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.mes.opctask.mapper.EdgStorageDeviceTaskHistoryMapper">
 
    <resultMap id="baseMap" type="com.mes.largenscreen.entity.DailyProductionVO">
        <result column="date" property="date"/>
        <result column="count_out_one" property="countOutOne"/>
        <result column="total_area_out_one" property="totalAreaOutOne"/>
        <result column="count_out_two" property="countOutTwo"/>
        <result column="total_area_out_two" property="totalAreaOutTwo"/>
        <result column="count_in" property="countIn"/>
        <result column="total_area_in" property="totalAreaIn"/>
        <result column="count_out" property="countOut"/>
        <result column="total_area_out" property="totalAreaOut"/>
        <result column="hollow_count_out_one" property="hollowCountOutOne"/>
        <result column="hollow_total_area_out_one" property="hollowTotalAreaOutOne"/>
        <result column="hollow_count_out_two" property="hollowCountOutTwo"/>
        <result column="hollow_total_area_out_two" property="hollowTotalAreaOutTwo"/>
    </resultMap>
 
    <select id="queryDailyProduction" resultMap="baseMap">
        SELECT
        count( t.glass_id_out ) AS count_out_one,
        round( sum( t1.width * t1.height )/ 1000000, 2 ) AS total_area_out_one
        FROM
        edg_storage_device_task_history t
        INNER JOIN glass_info t1 ON t.glass_id_out = t1.glass_id
        WHERE
        t.task_type IN ( 2, 3 )
        <if test="beginDate != null and beginDate != ''">
            AND STR_TO_DATE( t.create_time, '%Y-%m-%d' ) BETWEEN #{beginDate}
            AND #{endDate}
        </if>
        <if test="deviceId != null and deviceId != 0">
            AND device_id = #{deviceId}
        </if>
    </select>
    <select id="queryRunTimes" resultType="com.mes.largenscreen.entity.RunTime">
        WITH edg_storage_cage_history_task_temp AS
                 (SELECT DISTINCT create_time
                  FROM edg_storage_device_task_history
                  WHERE task_type IN (1, 3) AND DATE ( create_time ) = '${days}' ),
            time_temp AS (
        SELECT
            date (create_time) AS day_time,
            MIN(create_time) AS start_timestamp,
            MAX(create_time) AS end_timestamp
        FROM
            edg_storage_device_task_history
        WHERE
            Date ( create_time ) = '${days}'
        GROUP BY
            date ( create_time )
            ),
            result_temp AS (
        SELECT
            date ( t1.create_time ) AS day_time,
            t1.create_time AS first_timestamp,
            t2.create_time AS second_timestamp,
            TIMESTAMPDIFF( MINUTE, t1.create_time, t2.create_time ) AS diff_minutes
        FROM
            ( SELECT create_time, LEAD( create_time ) OVER ( ORDER BY create_time ) AS next_timestamp FROM edg_storage_cage_history_task_temp ) t1
            JOIN ( SELECT create_time, LEAD( create_time ) OVER ( ORDER BY create_time ) AS next_timestamp FROM edg_storage_cage_history_task_temp ) t2
        ON t1.next_timestamp = t2.create_time
        WHERE
            TIMESTAMPDIFF( MINUTE
            , t1.create_time
            , t2.create_time ) BETWEEN 6
          AND 500
        GROUP BY
            t1.create_time,
            t2.create_time
            ),
            result AS (
        SELECT first_timestamp, second_timestamp, diff_minutes, start_timestamp, end_timestamp
        FROM time_temp t1 LEFT JOIN result_temp t2
        ON t1.day_time = t2.day_time )
        SELECT *
        FROM result
    </select>
    <select id="queryEdgDailyProduction" resultMap="baseMap">
        SELECT
        count( t.glass_id_out ) AS count_out_one,
        round( sum( t1.width * t1.height )/ 1000000, 2 ) AS total_area_out_one
        FROM
        edg_storage_device_task_history t
        INNER JOIN glass_info t1 ON t.glass_id_out = t1.glass_id
        WHERE
        t.task_type IN ( 2, 3 )
        <if test="beginDate != null and beginDate != ''">
            AND STR_TO_DATE( t.create_time, '%Y-%m-%d' ) BETWEEN #{beginDate}
            AND #{endDate}
        </if>
        <if test="deviceId != null and deviceId != 0">
            AND device_id = #{deviceId}
        </if>
    </select>
 
</mapper>