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
63
64
65
global class OPDLendSortCopyToSortBeforeBatch implements Database.Batchable<sObject> {
    // SWAG-BYD6DD XHL 2021/02/20 
    public String query;
    List<String> oPDPlanIdList = null;
 
    global OPDLendSortCopyToSortBeforeBatch() {
        this.query = query;
    }
 
    global OPDLendSortCopyToSortBeforeBatch(List<String> oPDPlanIdList) {
        this.oPDPlanIdList = oPDPlanIdList;
    }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
        // 20231217 ljh 备品智能化 优化 start
        // if (oPDPlanIdList <> null) {
        //     return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c,OPDLendSort__c,OPDLendSortDraft__c,OPDLendSortBefore__c,Status__c FROM OPDPlan__c WHERE (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null) AND Status__c = '计划中' AND Id In :oPDPlanIdList]);
        // } else {
        //     return Database.getQueryLocator([SELECT Id, Name, OPDPlan_ImplementDate__c,OPDLendSort__c,OPDLendSortDraft__c,OPDLendSortBefore__c,Status__c FROM OPDPlan__c WHERE Status__c = '计划中' AND (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null)]);
        // }
        // 2024-01-24 ssm 非特殊处理情况下,增加计划实施日<=下月13日的判断 start
        Date endDate = Date.today().addMonths(1).toStartOfMonth().addDays(12);
        if (oPDPlanIdList <> null) {
            return Database.getQueryLocator([SELECT Id, OPDLendSort__c FROM OPDPlan__c WHERE (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null) AND Status__c = '计划中' AND Id In :oPDPlanIdList]);
        } else {
            return Database.getQueryLocator([SELECT Id, OPDLendSort__c FROM OPDPlan__c WHERE Status__c = '计划中' AND (OPDLendSort__c != null OR OPDLendSortDraft__c != null OR OPDLendSortBefore__c != null) AND OPDPlan_ImplementDate__c <= :endDate]);
        }
        // 2024-01-24 ssm 非特殊处理情况下,增加计划实施日<=下月13日的判断 end
        // 20231217 ljh 备品智能化 优化 end
    }
 
    global void execute(Database.BatchableContext BC, List<OPDPlan__c> oPDPlanList) {
        List<OPDPlan__c> upOPDList = new List<OPDPlan__c>();
        for(OPDPlan__c opdp : oPDPlanList) {
            // 20231217 ljh 备品智能化 不需要清空了 start
            // opdp.OPDLendSortBefore__c = null;//备品出借优先度(上月)置空
            // opdp.OPDLendSortBefore__c = opdp.OPDLendSort__c;//备品出借优先度 赋值给 备品出借优先度(上月)
            // opdp.OPDLendSort__c = null;//备品出借优先度 置空
            // opdp.SortSaveDate__c = null;  //20230807 lt DB202308135410 add
            // opdp.OPDLendSortDraft__c = null;//备品出借优先度草案中 置空
            // opdp.SortDate__c = null; //排序日期 置空
            OPDPlan__c temp = new OPDPlan__c();
            temp.Id = opdp.Id;
            temp.OPDLendSortBefore__c = opdp.OPDLendSort__c;//备品出借优先度 赋值给 备品出借优先度(上月)
            temp.Last_Month_Untreated__c = true; // 20231228 dzk 上个月未处理完标识
            upOPDList.add(temp);
            // 20231217 ljh 备品智能化 不需要清空了 end
 
        }
        // 20231217 ljh 备品智能化 优化 start
        // if (oPDPlanList != null && oPDPlanList.size() > 0) {
        //     update oPDPlanList;
        // }
        if (upOPDList != null && upOPDList.size() > 0) {
            update upOPDList;
        }
        // 20231217 ljh 备品智能化 优化 end
    }
 
    global void finish(Database.BatchableContext BC) {
 
    }
 
            
}