buli
2022-05-14 ead4df22dca33a867279471821ca675f91dec760
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * Author: Su cuiping
 * Created Date: 03/01/2022
 * Purpose: Utility class for describe layouts
 * Test Class: NewAndEditOrderController
 * 
 * */
global class NewAndEditOrderController extends NewAndEditBaseController {
 
    public String PIPL_Input_Account_Error_Msg{set;get;}
    public String contactId{set;get;}//For Lookup field
    public String staticResourceContact {get; set;}
    // 查找联系人解密
    public String contactAWSDataId{set;get;}
    public String contactName{set;get;}
    public String endUserDAWSDataId{set;get;}
    public String endUserDName{set;get;}
    public String contact2AWSDataId{set;get;}
    public String contact2Name{set;get;}
    public String contact2DAWSDataId{set;get;}
    public String contact2DName{set;get;}
    public NewAndEditOrderController(ApexPages.StandardController controller){
        
        
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Order').getDescribe().fields.getMap().keyset());  
        
        // Add fields to controller. This is to avoid the SOQL error in visualforce page
        //Get Account Id from url param
    
        // System.debug('accountType = ' + );
        if(!Test.isRunningTest()){
            controller.addFields(fieldList);
        }
        LookUpOverrideFields.add('EndUserD__c');
        LookUpOverrideFields.add('EndUser__c');
        // LookUpOverrideFields.add('ShipToContact');
        LookUpOverrideFields.add('SpecialDeliveryContact2__c');
        LookUpOverrideFields.add('SpecialDeliveryContact2_D__c');
        Init(controller.getRecord());
        
        SObject obj = controller.getRecord();
        if(obj.Id == null){
            //初始化加载值
            obj.put('OwnerId',UserInfo.getUserId());
        } else {
             //联系人的Id
            Order order = [Select EndUser__c, EndUserD__c, SpecialDeliveryContact2__c, SpecialDeliveryContact2_D__c From Order  where id=:obj.Id];
            System.debug('order: ' + order);
            if(order != null){
                if (order.EndUser__c != null) {
                    List<Contact> contact = [select AWS_Data_Id__c, Name from Contact where id=:order.EndUser__c];
                    if(contact.size()>0){
                        if (contact[0].AWS_Data_Id__c != null && contact[0].AWS_Data_Id__c != '') {
                            contactAWSDataId = contact[0].AWS_Data_Id__c;
                        }else {
                            contactName = contact[0].Name;
                        }
                    }
                }
                if (order.EndUserD__c != null) {
                    List<Contact> contact = [select AWS_Data_Id__c, Name from Contact where id=:order.EndUserD__c];
                    if(contact.size()>0){
                        if (contact[0].AWS_Data_Id__c != null && contact[0].AWS_Data_Id__c != '') {
                            endUserDAWSDataId = contact[0].AWS_Data_Id__c;
                        }else {
                            endUserDName = contact[0].Name;
                        }
                    }
                }
                if (order.SpecialDeliveryContact2__c != null) {
                    List<Contact> contact = [select AWS_Data_Id__c, Name from Contact where id=:order.SpecialDeliveryContact2__c];
                    if(contact.size()>0){
                        if (contact[0].AWS_Data_Id__c != null && contact[0].AWS_Data_Id__c != '') {
                            contact2AWSDataId = contact[0].AWS_Data_Id__c;
                        }else {
                            contact2Name = contact[0].Name;
                        }
                    }
                }
                if (order.SpecialDeliveryContact2_D__c != null) {
                    List<Contact> contact = [select AWS_Data_Id__c, Name from Contact where id=:order.SpecialDeliveryContact2_D__c];
                    if(contact.size()>0){
                        if (contact[0].AWS_Data_Id__c != null && contact[0].AWS_Data_Id__c != '') {
                            contact2DAWSDataId = contact[0].AWS_Data_Id__c;
                        }else {
                            contact2DName = contact[0].Name;
                        }
                    }
                }
            }else {
                contactAWSDataId = '无';
                contactName = '无';
            }
        }
        //contact信息(搜索查询query url用)
        staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));
        //客户名oid
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        if(mso.containsKey('oid')){
            String oid = mso.get('oid');
            List<Opportunity> opportunity = [select Account.Id from Opportunity where Id=:oid];
            if(opportunity.size()>0){
                String AccountId = opportunity[0].Account.Id;
                controller.getRecord().put('AccountId',AccountId);
            }
        }
    }
 
    
    @RemoteAction
    global static Response saveOrder(String OrderJson, String transId, Boolean isNew){
        if(Test.isRunningTest()){
            return new Response();
        }
        return save(new Order(), OrderJson, transId, isNew);
    }
}