liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
global class AccountServiceOfTarget1Hto2HBatch implements Database.Batchable<sObject> {
    public String query;
    public List<String> hospId;
    global AccountServiceOfTarget1Hto2HBatch() {
        this.query = query;
    }
    global AccountServiceOfTarget1Hto2HBatch(List<String> 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<Account_Service_Of_Target__c> asotList) {
            Map<String,Account_Service_Of_Target__c> map1 = new Map<String,Account_Service_Of_Target__c>();
            Map<String,Account_Service_Of_Target__c> map2 = new Map<String,Account_Service_Of_Target__c>();
            List<Account_Service_Of_Target__c> asotUPList = new List<Account_Service_Of_Target__c>();
             List<Account_Service_Of_Target__c> 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) {
 
    }
}