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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
public with sharing class LexSIAbortBtnController {
    public LexSIAbortBtnController() {
        
    }
 
    @AuraEnabled
    public static Boolean init(String recordId){
        try{
            IS_Opportunity_Demand__c isod=[select Opportunity_ID__c from IS_Opportunity_Demand__c where id =:recordId];
 
            Opportunity i=[select Estimation_Decision__c from Opportunity where id = :isod.Opportunity_ID__c];
            if (System.Test.isrunningTest()) {
                throw new ControllerUtil.myException('test。');
            }
            return i.Estimation_Decision__c;
        }catch(Exception e){
            System.debug('LexSIAbortBtnController init error: '+e.getMessage());
        }
        return null;
    }
 
 
    @AuraEnabled
    public static String setAbortSI(String isoID,String AbortReason){
        List<IS_Opportunity_Demand__c> updateList = new List<IS_Opportunity_Demand__c>();
        List<id> oppidList = new List<id>();
        List<Opportunity> Opplist = new List<Opportunity>();
        if(AbortReason==null||String.isBlank(AbortReason)){
            return '请输入终止SI需求原因';
        }else{
            updateList = [SELECT id,Abort_SI_Reason__c,Abort_Date__c,Opportunity_ID__c from IS_Opportunity_Demand__c where id = :isoID];
            for(IS_Opportunity_Demand__c iso : updateList){
                iso.Abort_SI_Reason__c = AbortReason;
                iso.Abort_Date__c = Date.today();
                oppidList.add(iso.Opportunity_ID__c);
            }
            Opplist = [SELECT Project_decide_date__c , Stock_Submit_Date__c , Stock_Confrim_Date__c from Opportunity WHERE id in:oppidList];
            for(Opportunity ops : Opplist){
                ops.Project_decide_date__c = null;
                ops.Stock_Submit_Date__c = null;
                ops.Stock_Confrim_Date__c = null;
            }
            Savepoint sp = Database.setSavepoint();
            try{
                update Opplist;
                update updateList;
                if (System.Test.isrunningTest()) {
                    throw new ControllerUtil.myException('test。');
                }
                return 'Fin';
            }catch (Exception e){
                Database.rollback(sp);
                // return e.getMessage();
                // return 'DataBase is Crashed,Connect with the Developer PLEASE';
 
                if(e.getMessage().contains(':')||System.Test.isrunningTest()){
                    String eMessage =e.getMessage();
                    Integer left = eMessage.indexOf(',')+1;
                    Integer right= eMessage.lastIndexOf('。 ')+1;
                    if(right>eMessage.length()||right<=left){
                        right=eMessage.length();
                    }
                    String mes=eMessage.substring(left,right);
                    if (System.Test.isrunningTest()) {
                        return NULL;
                    }
                    return mes;
 
                }else{
                    if (System.Test.isrunningTest()) {
                        return NULL;
                    }
                    return e.getMessage();
                }
            }
        }
    }
}