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
public class DecrptUpsertAgencyContact implements Schedulable {
    private String json_list;
    private String acList;
    private String sobject_name;
 
    public DecrptUpsertAgencyContact(string json_list,string acList,string sobject_name) {
        this.json_list = json_list;
        this.acList = acList;
        this.sobject_name = sobject_name;
    }
 
    public void execute(SchedulableContext sc) {
        // 在这里执行您的定时任务逻辑
        System.debug('success enter DecrptUpsertAgencyContact Schedulable');
        if(!Test.isRunningTest()){
            AwsServiceTool2V2.EncryptPushFutureV2(json_list,acList, sobject_name);
        }
        // 取消任务的后续执行
        System.abortJob(sc.getTriggerId()); 
    }
 
    public static void assignOnceOneMinuteLater(String json_list,String acList,String sobject_name) {
        Datetime oneMinuteLaterTime = Datetime.now().addminutes(1);
        String hour = String.valueOf(oneMinuteLaterTime.hour());
        String min = String.valueOf(oneMinuteLaterTime.minute()); 
        String ss = String.valueOf(oneMinuteLaterTime.second());
        String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';
        DecrptUpsertAgencyContact scheduledJob = new DecrptUpsertAgencyContact(json_list,acList,sobject_name);
        System.debug('延迟一分钟执行');
        //String uuid = generateUUID();
        String year = String.valueOf(Datetime.now().year());
        String month = String.valueOf(Datetime.now().month());
        String day = String.valueOf(Datetime.now().day());
        String t = year + month + day + hour + min;
        String uuid = generateUUID().substring(3);
        System.schedule(('DecrptUpsertAgencyContact' + t + uuid ), nextFireTime, scheduledJob);
    }
 
    public static String generateUUID() {
        String uid = '';
        
        for (Integer i = 0; i < 8; i++) {
            Integer randomInt = Math.abs(Crypto.getRandomInteger());
            uid += String.valueOf(randomInt).substring(0, 4);
        }
        
        return uid;
    }
}