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
82
83
84
85
86
87
88
89
90
91
92
93
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
            ];
            //生产环境bug修改 陈京武 20231105 Start
            RecordType recordType1 = [select Id from RecordType where Name = '询价取消报告'];
            List<Lost_cancel_report__c> repList = [select Id from Lost_cancel_report__c where Opportunity__c =: opp.Id and RecordTypeId !=: recordType1.Id and Report_Status__c != '草案'];
            if(repList.size() > 0){
                res.error = '已经有提交的失单报告,不可提交取消报告';
                return res;
            }
            //生产环境bug修改 陈京武 20231105 End
            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;
        //生产环境bug修改 陈京武 20231105 Start
        @AuraEnabled
        public String error;
        //生产环境bug修改 陈京武 20231105 End
    }
}