YZ_MES/数据库迁移sql/存储过程&定时任务/存储过程/UpdateSiteOnlineYield.sql

131 lines
5.2 KiB
SQL

##############################
##@author:gong.chengbo ##
##@createdate:2023-08-10 ##
##@for:线 ##
##############################
drop procedure if exists UpdateSiteOnlineYield;
create
definer = admin@`%` procedure UpdateSiteOnlineYield() comment '更新产量表存储过称'
BEGIN
replace into reportdata.siteonlinecrucibleyield(crystalbarno,MESmoname,eqpid,actualprodname,actualproddesc,outweight,outlength,outtime)
SELECT code,order_no,stove_no,product_no,product_name,weight,length,update_time
from mes_sync.mes_production mp
order by update_time;
##
UPDATE reportdata.siteonlinecrucibleyield sy
inner join reportdata.equipment eq on sy.eqpid = eq.eqpid
set sy.area = eq.area,sy.area1= eq.area1,sy.eqpmodel=eq.eqpmodel
where sy.eqpmodel is null;
##
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.mes_crystal_order co
on sy.mesmoname = co.order_no
set sy.erpmoname = co.job_code,sy.moprodname = co.material_code,sy.moproddesc = co.material_name,sy.crusize = co.thermal_field
where sy.crusize is null;
##
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.mostatus mo on (sy.mesmoname = mo.MESmoname)
set sy.crucible = mo.crucible,sy.crunum = mo.cruciblesn,sy.crudesc = mo.crucproddesc,sy.subprod = mo.subprod,sy.stovetime=mo.stovetime
where sy.crucible is null;
###
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.yz_mes_spec yms on(sy.subprod = yms.spec_code)
set sy.hair_rod_coefficient = yms.hair_rod_coefficient,sy.round_rod_coefficient = yms.round_rod_coefficient
where sy.hair_rod_coefficient is null or sy.round_rod_coefficient is null or sy.hair_square_rod_coefficient is null;
###MES中未维护的使用自己维护的补充
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.prod p on(sy.subprod = p.code)
set sy.hair_rod_coefficient = p.round,sy.hair_square_rod_coefficient = p.square
where sy.hair_rod_coefficient is null or sy.round_rod_coefficient is null or sy.hair_square_rod_coefficient is null;
###
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN (
SELECT
production_code,sum(draw_length) qclength
FROM mes_sync.mes_round_bar
where right(code,1) = '0'
group by production_code
)ps on (sy.crystalbarno = ps.production_code)
set sy.qclength = ps.qclength
where sy.qclength is null;
##QC时间及计产日期
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.mes_draw_line_task dlt on (sy.crystalbarno = dlt.hairy_rod_crystal_code and dlt.`status` = '3')
set sy.qctime = dlt.update_time,
sy.mfgdate = DATE_FORMAT(DATE_add(dlt.update_time,interval -510 MINUTE),'%Y-%m-%d')
where sy.qctime is null;
##QC重量
UPDATE reportdata.siteonlinecrucibleyield set qcweight = qclength/hair_rod_coefficient where qcweight is null;
UPDATE reportdata.siteonlinecrucibleyield set squareqcweight = qclength/hair_square_rod_coefficient where squareqcweight is null;
##############################################
DROP TEMPORARY TABLE IF EXISTS crystalbarno;
CREATE TEMPORARY TABLE crystalbarno (
id int,
idd varchar(100),
eqpid VARCHAR(100),
crystalbarno varchar(200),
outtime datetime,
lastcrystalbarno VARCHAR(200),
lastouttime datetime
);
insert into crystalbarno(id,idd,eqpid,crystalbarno,outtime)
SELECT
ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc) id,
CONCAT(stove_no,'-',ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc)) idd,
stove_no,code, UPDATE_time
from mes_sync.mes_production;
UPDATE crystalbarno cy
INNER JOIN
(
SELECT
ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc) -1 id,
CONCAT(stove_no,'-',ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc)-1) idd,
stove_no,code, UPDATE_time
from mes_sync.mes_production
) mp on (cy.idd = mp.idd)
set cy.lastouttime = mp.UPDATE_time,cy.lastcrystalbarno = mp.code;
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN crystalbarno cr on (sy.crystalbarno = cr.crystalbarno)
set sy.lastcrystalbarno = cr.lastcrystalbarno,sy.lastouttime = cr.lastouttime
where sy.lastcrystalbarno is null;
DROP TEMPORARY TABLE crystalbarno;
##############################################
###
UPDATE reportdata.siteonlinecrucibleyield sy
set timeinterval = timestampdiff(second,lastouttime,outtime) / (24 * 60 * 60)
where timeinterval is null;
###
UPDATE reportdata.siteonlinecrucibleyield sy
set timeinterval = timestampdiff(second,stovetime,outtime) / (24 * 60 * 60) + 8/24
where 1=1
and datediff(stovetime,lastouttime) >= 18/24
and crystalbarno like '%11N';
##
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.adjustcruc ac on (sy.mesmoname = ac.mesmoname)
set sy.adjustcrucible = ac.crucible
where sy.adjustcrucible is null;
##
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.dict d on (sy.adjustcrucible = d.dictkey and d.cate = 'cruccode')
set sy.adjustcruciblecode = d.value;
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.dict d on (sy.crucible = d.dictkey and d.cate = 'crucname')
set sy.adjustcruciblecode = d.value,sy.adjustcrucible = d.value1;
END;