global class AccountServiceOfTarget1Hto2HBatch implements Database.Batchable { public String query; public List hospId; global AccountServiceOfTarget1Hto2HBatch() { this.query = query; } global AccountServiceOfTarget1Hto2HBatch(List hospId) { this.query = query; this.hospId = hospId; } global Database.QueryLocator start(Database.BatchableContext bc) { query = 'select id,OCSM_Period_half__c,OCSM_Period__c,Account_HP__c,Account_HP__r.name,' +' Target_Correlation_Lightsource__c,Target_Rigid_Mirror_2__c,Target_Soft_Mirror_2__c,' +' Renew_Target_Correlation_Lightsource__c,Renew_Target_Rigid_Mirror_2__c,Renew_Target_Soft_Mirror_2__c' +' from Account_Service_Of_Target__c where OCSM_Period_half__c = \'2H\' '; if (this.hospId!=null && this.hospId.size()!=0) { query +=' and Account_HP__c in :hospId'; } return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, list asotList) { Map map1 = new Map(); Map map2 = new Map(); List asotUPList = new List(); List asotList2 = [select id,OCSM_Period_half__c,OCSM_Period__c,Account_HP__c,Account_HP__r.name, Target_Correlation_Lightsource__c,Target_Rigid_Mirror_2__c,Target_Soft_Mirror_2__c, Renew_Target_Correlation_Lightsource__c,Renew_Target_Rigid_Mirror_2__c,Renew_Target_Soft_Mirror_2__c from Account_Service_Of_Target__c where OCSM_Period_half__c = '1H']; for (Account_Service_Of_Target__c asot :asotList ) { map2.put(asot.Account_HP__c,asot); system.debug('添加到map2'); } for (Account_Service_Of_Target__c asot :asotList2 ) { map1.put(asot.Account_HP__c,asot); system.debug('添加到map1'); } system.debug('@@@@map1='+map1); system.debug('@@@@map2='+map2); for ( Account_Service_Of_Target__c asot:map1.values()) { system.debug('@@@@2H==='+map2.get(asot.Account_HP__c)); if ( map2.get(asot.Account_HP__c) !=null) { Account_Service_Of_Target__c asotNew = new Account_Service_Of_Target__c(); asotNew.id = map2.get(asot.Account_HP__c).id; asotNew.Target_Correlation_Lightsource__c = asot.Target_Correlation_Lightsource__c; asotNew.Target_Rigid_Mirror_2__c = asot.Target_Rigid_Mirror_2__c; asotNew.Target_Soft_Mirror_2__c = asot.Target_Soft_Mirror_2__c; asotNew.Renew_Target_Correlation_Lightsource__c = asot.Renew_Target_Correlation_Lightsource__c; asotNew.Renew_Target_Rigid_Mirror_2__c = asot.Renew_Target_Rigid_Mirror_2__c; asotNew.Renew_Target_Soft_Mirror_2__c = asot.Renew_Target_Soft_Mirror_2__c; asotUPList.add(asotNew); } } if (asotUPList!=null && asotUPList.size()!=0) { upsert asotUPList; } } global void finish(Database.BatchableContext BC) { } }