huang
2025-06-13 9c18324b8c3209946429ac60306ddc3c9cdaf1e9
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?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.largenscreen.mapper.LargenScreenMapper">
 
    <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">
        WITH RECURSIVE
            date_series AS (
                SELECT #{beginDate} AS date
                UNION ALL
                SELECT DATE_ADD(date, INTERVAL 1 DAY)
                FROM date_series
                WHERE date &lt;= DATE_SUB(#{endDate}, INTERVAL 1 DAY)
            ),
            one_edg_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       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)
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
                  and device_id = 1
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            ),
            two_edg_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       count(t.glass_id_out)                         as
                                                                        count_out_two,
                       round(sum(t1.width * t1.height) / 1000000, 2) as total_area_out_two
                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)
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
                  and device_id = 2
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            ),
            big_storage_in_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       count(t.glass_id)                             as
                                                                        count_in,
                       round(sum(t1.width * t1.height) / 1000000, 2) as total_area_in
                from big_storage_cage_history_task t
                         INNER JOIN glass_info t1 on t.glass_id = t1.glass_id
                where t.task_type = 1
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d')
                    BETWEEN #{beginDate} and #{endDate}
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            ),
            big_storage_out_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       count(t.glass_id)                             as
                                                                        count_out,
                       round(sum(t1.width * t1.height) / 1000000, 2) as total_area_out
                from big_storage_cage_history_task t
                         INNER JOIN glass_info t1 on t.glass_id = t1.glass_id
                where t.task_type = 2
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d')
                    BETWEEN #{beginDate} and #{endDate}
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            ),
            hollow_out_one_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       count(t.glass_id)                             as
                                                                        hollow_count_out_one,
                       round(sum(t1.width * t1.height) / 1000000, 2) as hollow_total_area_out_one
                from hollow_big_storage_cage_history_task t
                         INNER JOIN glass_info t1 on t.glass_id = t1.glass_id
                where t.task_type =
                      5
                  and t.target_slot = 930
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            ),
            hollow_out_two_temp as (
                select STR_TO_DATE(t.create_time, '%Y-%m-%d')        as product_date,
                       count(t.glass_id)                             as
                                                                        hollow_count_out_two,
                       round(sum(t1.width * t1.height) / 1000000, 2) as hollow_total_area_out_two
                from hollow_big_storage_cage_history_task t
                         INNER JOIN glass_info t1 on t.glass_id = t1.glass_id
                where t.task_type =
                      5
                  and t.target_slot = 931
                  and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
                group by STR_TO_DATE(t.create_time, '%Y-%m-%d')
                order by STR_TO_DATE(t.create_time, '%Y-%m-%d')
            )
        select t.date,
               ifnull(t1.count_out_one, 0)        count_out_one,
               ifnull(t1.total_area_out_one, 0)   total_area_out_one,
               ifnull(t2.count_out_two, 0)        count_out_two,
               ifnull(t2.total_area_out_two, 0)   total_area_out_two,
               ifnull(t3.count_in, 0)             count_in,
               ifnull(t3.total_area_in, 0)        total_area_in,
               ifnull(t4.count_out, 0)            count_out,
               ifnull(t4.total_area_out, 0)       total_area_out,
               ifnull(t5.hollow_count_out_one, 0) hollow_count_out_one,
               ifnull(t5.hollow_total_area_out_one, 0)
                                                  hollow_total_area_out_one,
               ifnull(t6.hollow_count_out_two, 0) hollow_count_out_two,
               ifnull(t6.hollow_total_area_out_two, 0)
                                                  hollow_total_area_out_two
        from date_series t
                 left join one_edg_temp t1 on t.date = t1.product_date
                 left join two_edg_temp t2 on t.date =
                                              t2.product_date
                 left join big_storage_in_temp t3 on t.date = t3.product_date
                 left join big_storage_out_temp t4 on t.date =
                                                      t4.product_date
                 left join hollow_out_one_temp t5 on t.date = t5.product_date
                 left join hollow_out_two_temp t6 on t.date =
                                                     t6.product_date
        order by t.date
    </select>
 
 
</mapper>