##############################
##@author:gong.chengbo      ##
##@createdate:2023-08-10    ##
##@for:用于归档循环料产出明细   ##
##############################
drop procedure if exists UpdateRecyclematerialouput;
create
    definer = admin@`%` procedure UpdateRecyclematerialouput()
BEGIN
replace into reportdata.recyclematerialouput(lotsn,prodname,proddesc,prodtype,level,
	resistivity,weight,cate1,type,cate2,cate3,update_time,mfgdate,month)
SELECT order_no lotsn,
material_code prodname,
material_name proddesc,
replace(replace(product_type,'（',''),'）','') prodtype,
material_type level,
resistivity,
weight,
pd.cate1,
pd.type,
pd.cate2,
pd.cate3,
update_time,
DATE_FORMAT(DATE_add(ms.update_time,interval -510 MINUTE),'%Y-%m-%d') mfgdate,
CONCAT('M',DATE_FORMAT(DATE_add(ms.update_time,interval -510 MINUTE),'%m')) `month`
FROM mes_sync.mes_recycle_material_storage  ms
left join reportdata.product pd on (ms.material_code = pd.prodname)
and substring(material_code,6,1) = '1'
where `status` = '2';
END;
