<?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 <= 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>
|