YZ_MES/报表sql/Excel/EqpOnStoveStatus.sql

136 lines
4.2 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

DROP TABLE IF EXISTS `eqponstovestatustmp`;
create table eqponstovestatustmp
(
area varchar(50),
area1 varchar(50),
eqpid varchar(50),
mesmoname varchar(50),
eqpmodel varchar(50),
eqpstatus varchar(50),
crusize varchar(50),
subprod varchar(50),
lastreporttime datetime,
laststovetime datetime,
lastopentime datetime,
lastouttime datetime,
finishtime datetime,
lastchaiqingtime datetime
);
replace into eqponstovestatustmp(area, area1, eqpid, eqpmodel)
select area, area1, eqpid, eqpmodel
from reportdata.equipment;
###
update eqponstovestatustmp es
left join
(select eqpid, substring(eventid, 1, 10) mesmoname, max(eventtime)
from eqponstatuslogs
group by eqpid) b on (es.eqpid = b.eqpid)
set es.mesmoname = b.mesmoname;
##1 2 3 4 5
update eqponstovestatustmp eqs
left join
(select es.eqpid,
epl.mesmoname,
max(case when eventtype = '1' then eventtime end) lastreporttime,
max(case when eventtype = '2' then eventtime end) laststovetime,
max(case when eventtype = '3' then eventtime end) lastopentime,
max(case when eventtype = '3' then eventtime end) lastouttime,
max(case when eventtype = '3' then eventtime end) lastchaiqingtime,
case when substring(eventid,13,1) = 'W' then eventtime end finishtime
from eqponstatuslogs es
inner join eqponstovestatustmp epl on (substring(es.eventid, 1, 10) = epl.mesmoname)
group by es.eqpid) b on (eqs.eqpid = b.eqpid)
set eqs.lastreporttime = b.lastreporttime,
eqs.laststovetime = b.laststovetime,
eqs.lastopentime = b.lastopentime,
eqs.lastouttime = b.lastouttime,
eqs.lastchaiqingtime = b.lastchaiqingtime,
eqs.finishtime = b.finishtime;
###
update eqponstovestatustmp
set eqpstatus = '投料后未产出'
where 1 = 1
and laststovetime is not null
and lastouttime is null
and mesmoname is not null
and laststovetime >= date_format(date_sub(now(), interval 20 day), '%Y-%m-%d');
###
update eqponstovestatustmp
set eqpstatus = '完结后未报料'
where 1 = 1
and laststovetime is null
and lastouttime is null
and mesmoname is null;
###
update eqponstovestatustmp
set eqpstatus = '循环段产出中'
where 1 = 1
and laststovetime is not null
and lastouttime is not null
and mesmoname is not null
and lastouttime >= date_format(date_sub(now(), interval 4 day), '%Y-%m-%d');
###
update eqponstovestatustmp
set eqpstatus = '工单异常'
where 1 = 1
and lastouttime <= date_format(date_sub(now(), interval 25 day), '%Y-%m-%d');
###
update eqponstovestatustmp
set eqpstatus = '报料未投炉'
where 1 = 1
and lastreporttime is not null
and mesmoname is not null
and lastouttime is null
and laststovetime is null;
###
update eqponstovestatustmp
set eqpstatus = '报料异常'
where 1 = 1
and lastreporttime is not null
and laststovetime is null
and lastreporttime <= date_format(date_sub(now(), interval 3 day), '%Y-%m-%d');;
###
update eqponstovestatustmp
set eqpstatus = '拆清异常'
where 1 = 1
and lastouttime is not null
and lastchaiqingtime is null
and lastouttime <= date_format(date_sub(now(), interval 5 day), '%Y-%m-%d');
###
update eqponstovestatustmp
set eqpstatus = '拉棒时间超3天'
where 1 = 1
and laststovetime is not null
and laststovetime <= date_format(date_sub(now(), interval 3 day), '%Y-%m-%d');
update eqponstovestatustmp esp
inner join mes_sync.mes_crystal_order mco on (esp.mesmoname = mco.order_no)
inner join reportdata.mostatus mo on (esp.mesmoname = mo.MESmoname)
set esp.crusize = mco.thermal_field,esp.subprod = mo.subprod;
insert into eqponstovestatus
select *
from eqponstovestatustmp;
update eqponstovestatus set savedate = now() where savedate is null;
update eqponstovestatus set mfgdate = date_format(now()-8.5/24,'%Y-%m-%d') where mfgdate is null;
#drop table eqponstovestatustmp