wangfei
2025-05-13 0b41a5c59028a61bff22f60e74cb1d6d53a40e61
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?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>
    <select id="exportDailyProduction" resultType="com.mes.largenscreen.entity.DailyProductionData">
        with edg_storage_history_temp as (
            select t.glass_id_in as glass_id, t.create_time, STR_TO_DATE(t.create_time, '%Y-%m-%d') as product_date
            from edg_storage_device_task_history t
            where t.task_type in
                  (1, 3)
              and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
        )
           , big_storage_cage_history_temp as (
            select t.glass_id, t.create_time, STR_TO_DATE(t.create_time, '%Y-%m-%d') as product_date
            from big_storage_cage_history_task t
            where t.task_type = 2
              and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
        )
           , hollow_big_storage_cage_history_temp as (
            select t.glass_id, t.create_time, STR_TO_DATE(t.create_time, '%Y-%m-%d') as product_date
            from hollow_big_storage_cage_history_task t
            where t.task_type = 5
              and STR_TO_DATE(t.create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
        )
           , engineer_temp as (
            select STR_TO_DATE(create_time, '%Y-%m-%d') as product_date, engineer_id, glass_total, glass_total_area
            from engineering
            where STR_TO_DATE(create_time, '%Y-%m-%d') BETWEEN #{beginDate} and #{endDate}
        )
           , edg_temp as (
            select t.product_date,
                   count(t.glass_id)                             as
                                                                    count_out,
                   round(sum(t1.width * t1.height) / 1000000, 1) as total_area_out
            from edg_storage_history_temp t
                     inner join glass_info t1 on t.glass_id = t1.glass_id
            group by product_date
        )
           , edg_time_one as (
            select product_date,
                   min(create_time)                                          as edg_begin_time,
                   max(create_time)                                          as edg_end_time,
                   TIMESTAMPDIFF(MINUTE, min(create_time), max(create_time)) AS edg_time_total
            from edg_storage_history_temp
            group by product_date
        )
           , edg_time_two as (
            SELECT t1.product_date,
                   sum(TIMESTAMPDIFF(MINUTE, t1.create_time, t2.create_time)) AS edg_time_free
            FROM (SELECT product_date,
                         create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM edg_storage_history_temp
                 ) t1
                     JOIN
                 (SELECT create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM edg_storage_history_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.product_date
        )
           , big_storage_temp as (
            select t.product_date,
                   count(distinct t1.engineer_id, t1.tempering_layout_id) as tempering_layout_count,
                   count(distinct t1.glass_id)                            as tempering_glass_count,
                   round(sum(t1.width * t1.height) / 1000000, 1)          as tempering_area
            from big_storage_cage_history_temp t
                     inner join glass_info t1
                                on t.glass_id = t1.glass_id
            group by t.product_date
        )
           , big_storage_time_base as (
            select distinct product_date, create_time from big_storage_cage_history_temp
        )
           , big_storage_time_one as (select product_date,
                                             min(create_time)                                          as big_begin_time,
                                             max(create_time)                                          as big_end_time,
                                             TIMESTAMPDIFF(MINUTE, min(create_time), max(create_time)) AS big_time_total
                                      from big_storage_time_base
                                      group by product_date)
           , big_storage_time_two as (
            SELECT t1.product_date,
                   IFNULL(sum(TIMESTAMPDIFF(MINUTE, t1.create_time, t2.create_time)), 0) AS big_time_free
            FROM (SELECT product_date,
                         create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM big_storage_time_base) t1
                     JOIN
                 (SELECT create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM big_storage_time_base) t2 ON t1.next_timestamp = t2.create_time
            WHERE TIMESTAMPDIFF(MINUTE, t1.create_time, t2.create_time) between 11 and 500
            group by t1.product_date
        )
           , hollow_big_storage_temp as (
            select t.product_date,
                   count(distinct t1.glass_id)                   as hollow_glass_count,
                   round(sum(t1.width * t1.height) / 1000000, 1) as hollow_area
            from hollow_big_storage_cage_history_temp t
                     inner join glass_info t1
                                on t.glass_id = t1.glass_id
            group by t.product_date
        )
           , hollow_big_storage_time_base as (
            select distinct product_date, create_time from hollow_big_storage_cage_history_temp
        )
           , hollow_big_storage_time_one as (select product_date,
                                                    min(create_time)                                          as hollow_begin_time,
                                                    max(create_time)                                          as hollow_end_time,
                                                    TIMESTAMPDIFF(MINUTE, min(create_time), max(create_time)) AS hollow_time_total
                                             from hollow_big_storage_time_base
                                             group by product_date)
           , hollow_big_storage_time_two as (
            SELECT t1.product_date,
                   IFNULL(sum(TIMESTAMPDIFF(MINUTE, t1.create_time, t2.create_time)), 0) AS hollow_time_free
            FROM (SELECT product_date,
                         create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM hollow_big_storage_time_base) t1
                     JOIN
                 (SELECT create_time,
                         LEAD(create_time) OVER (ORDER BY create_time) AS next_timestamp
                  FROM hollow_big_storage_time_base) t2 ON t1.next_timestamp = t2.create_time
            WHERE TIMESTAMPDIFF(MINUTE, t1.create_time, t2.create_time) between 11 and 500
            group by t1.product_date
        )
           , result as (
            select t.count_out,
                   t.total_area_out,
                   t1.*,
                   t2.edg_time_free,
                   t1.edg_time_total - t2.edg_time_free       as edg_time_diff,
                   t3.tempering_layout_count,
                   t3.tempering_glass_count,
                   t3.tempering_area,
                   t4.big_begin_time,
                   t4.big_end_time,
                   t4.big_time_total,
                   t5.big_time_free,
                   t4.big_time_total - t5.big_time_free       as big_time_diff,
                   t6.hollow_glass_count,
                   t6.hollow_area,
                   t7.hollow_begin_time,
                   t7.hollow_end_time,
                   t7.hollow_time_total,
                   t8.hollow_time_free,
                   t7.hollow_time_total - t8.hollow_time_free as hollow_time_diff,
                   t9.engineer_id,
                   t9.glass_total,
                   t9.glass_total_area
            from edg_temp t
                     LEFT JOIN edg_time_one t1 on t.product_date = t1.product_date
                     LEFT JOIN edg_time_two t2 on t.product_date = t2.product_date
                     LEFT JOIN big_storage_temp t3 on t.product_date = t3.product_date
                     LEFT JOIN big_storage_time_one t4 on t.product_date = t4.product_date
                     LEFT JOIN big_storage_time_two t5 on t.product_date = t5.product_date
                     LEFT JOIN hollow_big_storage_temp t6 on t.product_date = t6.product_date
                     LEFT JOIN hollow_big_storage_time_one t7 on t.product_date = t7.product_date
                     LEFT JOIN hollow_big_storage_time_two t8 on t.product_date = t8.product_date
                     LEFT JOIN engineer_temp t9 on t.product_date = t9.product_date
        )
        select *
        from result
        order by product_date
    </select>
 
 
</mapper>