set identity_insert RecyclingItem ON;
insert into RecyclingItem(id,amount,basketName,isApplyEntireTousse,isCleanedEntirely,isThereIdentificationCard,isTraceable,tousseDefinitionId,tousseName,tousseType,urgentAmount,recyclingRecord_id) 
select i.id,i.amount,i.basketName,i.isApplyEntireTousse,i.isCleanedEntirely,i.isThereIdentificationCard,i.isTraceable,i.tousseDefinitionId,i.tousseName,i.tousseType,i.urgentAmount,i.recyclingRecord_id 
from TousseItem i where i.recyclingRecord_id is not null;
set identity_insert RecyclingItem OFF;

insert into MaterialErrorDamageDetail(additionalAmount,additionalPerson,additionalTime,amount,amountPerTousse,damageErrorDepartType,damageErrorMaterialType,departCodeForId,errorType,idCardInstanceId,linkType,lostIDCardInstanceBarcode,materialCost,materialDefinitionId,materialName,packingTaskId,settlementPrice,tousseDefinitionId,recyclingItemId,tousseName,type,classifyBasket_id,depart,departCode,handleDepartCode,handleDepartName,operationTime,operator,warehouseId,warehouseName) 
 (select r.additionalAmount,'',r.additionalTime,r.amount,0,r.damageErrorDepartType,r.damageErrorMaterialType,r.departCodeForId,r.errorType,r.idCardInstanceID,'',r.lostIDCardInstanceBarcode,r.materialCost,r.materialDefinitionId,r.materialName,r.packingTask_ID,r.settlementPrice,r.tousseDefinitionId,r.tousseItem_ID,r.tousseName,'回收误差',r.classifyBasket_id,r.depart,r.departCode,r.handleDepartCode,r.handleDepartName,r.missTime,'',r.warehouseId,r.warehouseName from RecyclingError r 
 union all 
 select i.additionalAmount,i.additionalPerson,i.additionalTime,i.amount,0,i.damageErrorDepartType,i.damageErrorMaterialType,'','',null,i.linkType,'',i.materialCost,i.materialDefinitionId,i.materialName,i.packingTask_ID,i.settlementPrice,i.tousseDefinitionId,i.tousseItem_ID,i.tousseName,'器械报损',i.classifyBasket_id,i.depart,i.departCoding,i.handleDepartCode,i.handleDepartName,i.time,i.damageOfPeople,i.warehouseId,i.warehouseName from RecyclingDamageItem i 
 );
insert into recyclingItem_errorDamage(recyclingItem_id,errorDamageDetail_id) select i.recyclingItemId,i.id from MaterialErrorDamageDetail i where i.recyclingItemId is not null;