19626
2023-10-31 fd9df05c48c09b4d7f39a3b401882bda226dedea
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
public with sharing class lexLostCancelReportController {
    @AuraEnabled
    public static InitData initSubmitReportButton(String recordId){
        InitData res = new InitData();
        try {
            Lost_Cancel_Report__c report = [
                select
                Opportunity__c
                from Lost_Cancel_Report__c where Id =: recordId
            ];
            Opportunity opp = [
                select
                Cnt_Lost_cancel_report__c,
                Cnt_Lost_cancel_Draft__c
                from Opportunity where Id =: report.Opportunity__c
            ];
            res.cntLostCancelDraft = opp.Cnt_Lost_cancel_Draft__c;
            res.cntLostCancelReport = opp.Cnt_Lost_cancel_report__c;
        } catch (Exception e) {
        }
        return res;
    }
    @AuraEnabled
    public static InitData initForEditCancelReport(String recordId){
        InitData res = new InitData();
        try {
            Lost_cancel_report__c report = [
                select Id,
                RecordTypeId, 
                Opportunity__c, 
                LostType__c , 
                Report_Status__c from Lost_cancel_report__c  where id =: recordId
            ];
            res.recordTypeId = report.RecordTypeId;
            res.lostType = report.LostType__c;
            res.reportStatus = report.Report_Status__c;
        } catch (Exception e) {
        }
        return res;
    }
    @AuraEnabled
    public static string updateSubmitReportButton(String recordId){
        Savepoint sp = Database.setSavepoint();
        Lost_cancel_report__c report = new Lost_cancel_report__c();
        try { 
            report.Id = recordId;
            report.Report_Status__c = '提交';
            update report;
            // Approval.ProcessSubmitRequest psr = new Approval.ProcessSubmitRequest();
            // psr.setObjectId(report.Id);
            // Approval.ProcessResult submitResult = Approval.process(psr);
            return null;
        } catch (Exception e) {
            Database.rollback(sp);
            if (e.getMessage().contains(',')) {
                System.debug(LoggingLevel.INFO, '*** e: ' + e);
                String exc = '' + e.getMessage();
                Integer left = exc.indexOf(':') + 1;
                Integer right = exc.lastIndexOf(':');
                String str = exc.substring(left,right);
                left = str.indexOf(',') +  1;
                String newStr = str.substring(left);
                return newStr;
            }else {
                return e.getMessage();   
            }
        }
    }
    public class InitData {
        @AuraEnabled
        public Decimal cntLostCancelReport;
        @AuraEnabled
        public Decimal cntLostCancelDraft;
        @AuraEnabled
        public String recordTypeId;
        @AuraEnabled
        public String lostType;
        @AuraEnabled
        public String reportStatus;
    }
}