update invoicePlan set recyclingStatus = '待接收' where id in (select id from ForeignTousseApplication f where f.packagestatus = '待接收') and type = '外来器械包申请单' and endStatus is null; update invoicePlan set recyclingStatus = '已接收' where id in (select id from ForeignTousseApplication f where f.packagestatus = '已接收') and type = '外来器械包申请单' and deliverstatus = '待发货' and endStatus is null; update invoicePlan set recyclingStatus = '待回收' where id in (select id from ForeignTousseApplication f where f.packagestatus = '已接收') and type = '外来器械包申请单' and deliverstatus = '已发货' and endStatus is null and (recyclingStatus is null or recyclingStatus<>'已回收' and recyclingStatus<>'待回收'); update invoicePlan set recyclingStatus = '已回收' where id in (select id from ForeignTousseApplication f where (f.packagestatus = '已回收' or f.packagestatus = '已归还')) and type = '外来器械包申请单' and deliverstatus = '已发货' and endStatus is null; update tousseitem set toussedefinitionid = (select min(t.id) from toussedefinition t where t.invoiceplanid = tousseitem.recyclingapplication_id) where toussetype = '外来器械包' and toussedefinitionid is null;