buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
public with sharing class RentalApplyControllerLWT {
    public RentalApplyControllerLWT() {
        
    }
    @AuraEnabled
    public static Rental_Apply__c initFromCancelSubmitButton(String recordId){
        InitData res = new InitData();
        try{
            Rental_Apply__c report=[select 
             Status__c,Yi_loaner_arranged__c,Id,RA_Status__c,
            demo_purpose2__c,Follow_UP_Opp__c,Statu_Achievements__c,Statu_Achievements_ID__c,
            Request_shipping_day__c,Demo_purpose1__c,Repair__c,RecordTypeId,SupplementCreated__c,
            OPDPlan__c,Campaign__c,QIS_number__c,OwnerId,
            // QIS_numberId__c,CampaignId__c,applyUserId__c,
            Re_repair__c,
            QIS_ID_Line__c,
            applyUser__c
             from Rental_Apply__c where Id= :recordId];
            return report;
            // res.StatusC=report.Status__c;
            // res.Id=report.Id;
            // res.YiLoanerArrangedC=report.Yi_loaner_arranged__c;
            // res.RAStatusC=report.RA_Status__c;
            // res.DemoPurpose2C=report.demo_purpose2__c;
            // res.FollowUPOppC=report.Follow_UP_Opp__c;
            // res.StatuAchievementsC=report.Statu_Achievements__c;
            // res.StatuAchievementsIDC=report.Statu_Achievements_ID__c;
            // res.RequestShippingDayC=report.Request_shipping_day__c;
            // res.DemoPurpose1C=report.Demo_purpose1__c;
            // res.RepairC=report.Repair__c;
            // res.RecordTypeId=report.RecordTypeId;
            // res.SupplementCreatedC=report.SupplementCreated__c;
            // res.OPDPlanC=report.OPDPlan__c;
            // res.CampaignC=report.Campaign__c;
            // res.QISNumberC=report.QIS_number__c;
            // res.QISNumberIdc=report.QIS_numberId__c;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
 
    @AuraEnabled
    public static list<Rental_Apply_Equipment_Set_Detail__c> selectRentalApplyEquipmentSetDetailByRacId(String recordId){
        InitData res = new InitData();
        try{
            list<Rental_Apply_Equipment_Set_Detail__c> report=[select 
            Id, Fixture_Model_No_F__c, Product_Status_Flag_F__c 
            from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply__c = :recordId]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
    @AuraEnabled
    public static list<QIS_Report__c> selectQISReportById(String recordId){
        InitData res = new InitData();
        try{
            list<QIS_Report__c> report=[select 
            Id, nonyushohin__r.Product2.Fixture_Model_No_T__c 
            from QIS_Report__c 
            where id = :recordId
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
    
    @AuraEnabled
    public static list<Repair__c> selectRepairById(String recordId){
        InitData res = new InitData();
        try{
            list<Repair__c> report=[select Id, Repair_Rank__c, DW_Sign_Txt__c, FSE_ApplyForRepair_Day__c, Delivered_Product__r.Product2.Fixture_Model_No_T__c
                 , ReRepairObject_F__c,Status1__c,Agreed_Date__c,Repair_Estimated_date_formula__c,Repair_Ordered_Date__c
                 , IfCheckFixture__c
                 , Repair_Final_Inspection_Date__c,Repair_Shipped_Date__c,Number_of_EffectiveContract__c, NewProductGuaranteeObject__c, Delivered_Product__r.Product2.Asset_Model_No__c
                 from Repair__c where id = :recordId
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
    @AuraEnabled
    public static list<Campaign> selectCampaignById(String recordId){
        InitData res = new InitData();
        try{
            list<Campaign> report=[select 
            Status, Rental_Apply_Flag__c ,IF_Approved__c,Meeting_Approved_No__c,Approved_Status__c 
            from Campaign where id =:recordId
 
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
    @AuraEnabled
    public static list<Rental_Apply_Equipment_Set__c> selectRentalApplyEquipmentSetByRacId(String recordId){
        InitData res = new InitData();
        try{
            list<Rental_Apply_Equipment_Set__c> report=[select Id 
                from Rental_Apply_Equipment_Set__c 
                where RetalFSetDetail_Cnt__c = 0 AND Rental_Apply__c = :recordId
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
    @AuraEnabled
    public static list<Rental_Apply__c> selectRentalApplyById(String recordId){
        InitData res = new InitData();
        try{
            list<Rental_Apply__c> report=[select 
            id,OPDPlan__c,OPDPlan__r.SalesManager_Txt__c,OPDPlan__r.BuchangApprovalManagerSales_Txt__c 
            from Rental_Apply__c where id = :recordId
 
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
    @AuraEnabled
    public static list<User> selectUserById(String recordId){
        InitData res = new InitData();
        try{
            list<User> report=[select 
            id,JingliEquipmentManager__c,JingliEquipmentManager__r.Name,Buzhang_Equipment_Manager__c,
            Buzhang_Equipment_Manager__r.Name 
            from User where id = :recordId
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
    @AuraEnabled
    public static list<QIS_report__c> selectQISreportById2(String recordId){
        InitData res = new InitData();
        try{
            list<QIS_report__c> report=[select id,next_action__c 
            from QIS_report__c where id =:recordId
            ]; 
            return report;
        }catch(Exception e){
            System.debug(LoggingLevel.INFO,'Rental_Apply__c Cancel Error : ' + e);
        }
        return null;
    }
 
         
    @AuraEnabled
    public static String getUserId(){
        
        return UserInfo.getUserId();
    }
 
    @AuraEnabled
    public static String getProfileId(){
        return UserInfo.getProfileId();
    }   
 
    @AuraEnabled
    public static String setSObjectShare(String sobjectName, String rowCause, String parentId, List<String> userAccess, String ownerId) {
 
        try {
            List<SObject> sObjList = new List<SObject>();
            for (String ua : userAccess) {
                String userid = ua.split('_')[0];
                String access = ua.split('_')[1];
                SObject sObj = Schema.getGlobalDescribe().get(sobjectName).newSObject();
                if (String.isBlank(userid) == false && userid.substring(0, 15) != ownerId.substring(0, 15)) {
                    sObj.put('RowCause', rowCause);
                    sObj.put('ParentId', parentId);
                    sObj.put('UserOrGroupId', userid);
                    sObj.put('AccessLevel', access);
                    sObjList.add(sObj);
                }
            }
            if (sObjList.size() > 0) insert sObjList;
            return 'OK';
        } catch (Exception e) {
            return e.getMessage();
        }   
    }
 
    @AuraEnabled
    public static UpdateResult updateRentalApplyC(        
        String recordId,
        String SalesManagerSubmitC,
        String StatusC,
        String OPDManagerApproverC,
        String BuchangApprovalManagerSalesSubmitC,
        String OPDBuchangApproverC
    ) {
        UpdateResult result = new UpdateResult();
        result.recordId = recordId;
        try{
            // 更新记录并获取结果
            if(recordId==null) return null;
            Rental_Apply__c rac = new Rental_Apply__c( id=recordId);
 
            if(SalesManagerSubmitC!=null&& SalesManagerSubmitC != ''){
                rac.SalesManagerSubmit__c=SalesManagerSubmitC;
            }
            if(StatusC!=null&&StatusC!=''){
                rac.Status__c=StatusC;
            }
            if(OPDManagerApproverC!=null&&OPDManagerApproverC!=''){
                rac.OPDManagerApprover__c=OPDManagerApproverC;
            }
            if(BuchangApprovalManagerSalesSubmitC!=null&&BuchangApprovalManagerSalesSubmitC!=''){
                rac.BuchangApprovalManagerSalesSubmit__c=BuchangApprovalManagerSalesSubmitC;
            }
            if(OPDBuchangApproverC!=null&&OPDBuchangApproverC!=''){
                rac.OPDBuchangApprover__c=OPDBuchangApproverC;
            }
            if(rac.id==null)return null;
            update rac;
            result.success = true;
            result.errors = new List<String>();
            // 定义字符串列表,其中包含若干 sObject 的 API 名称
            //List<String> objTypeList = new List<String>{'Account', 'ExampleCustomObj__c'};
            // 得到 Account 和 ExampleCustomObj__c 的信息
            //Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objTypeList);
            return result;
        }catch(Exception e){
            result.success = false;
            result.errors = new List<String>();
            result.errors.add(e.getMessage());
            System.debug(LoggingLevel.INFO,'Rental_Apply__c update Error : ' + e);
        }
        return result;
    }
 
    public class UpdateResult {
        @AuraEnabled public String recordId {get;set;}
        @AuraEnabled public Boolean success {get;set;}
        @AuraEnabled public List<String> errors {get;set;}
    }
    public class InitData{
        @AuraEnabled
        public String StatusC;
        @AuraEnabled
        public Decimal YiLoanerArrangedC;
        @AuraEnabled
        public String Id;
        @AuraEnabled
        public String RAStatusC;
 
        @AuraEnabled
        public String DemoPurpose2C;
        @AuraEnabled
        public String FollowUPOppC;
        @AuraEnabled
        public String StatuAchievementsC;
        @AuraEnabled
        public String StatuAchievementsIDC;
        @AuraEnabled
        public Date RequestShippingDayC;
        @AuraEnabled
        public String DemoPurpose1C;
        @AuraEnabled
        public String RepairC;
        @AuraEnabled
        public String RecordTypeId;
        @AuraEnabled
        public Boolean SupplementCreatedC;
        @AuraEnabled
        public String OPDPlanC;
        @AuraEnabled
        public String CampaignC;
        @AuraEnabled
        public String QISNumberC;
        @AuraEnabled
        public String QISNumberIdc;
    }
}