高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
// RowDataを残すため、@future execute にします
global class NFM105WebService {
    // Integer batchsize = 200;  考量する必要がないと思います。
    global class RepairStatusUpdate {
        webservice NFMUtil.Monitoring Monitoring;
        webservice NFM105WebService.GeneralData[] GeneralData;
    }
    global class GeneralData {
        webservice String SFDCRepairNo;
        webservice String SAPRepairNo;
        webservice String SAPQuotationNo;
        webservice String ReRepairObject;
        webservice String RepairOrderStatusCode;
        webservice String RepairOrderStatusName;
        webservice String StatusUpdateDate;
        webservice String StatusUpdateTime;
        webservice String PlannedRepairFinishDate;
        webservice String StatusUpdatePersonName;
        webservice String CancellationReason;
        webservice String IncorrectDataComment;
        webservice String ReturnType;
        webservice String InspectType;
        webservice NFM105WebService.InspectionResultInformation[] InspectionResultInformation;
        webservice NFM105WebService.FailureInformation[] FailureInformation;
    }
    global class InspectionResultInformation {
        webservice String InspectionResultFlag;
        webservice String InspectionComment;
        webservice String FailureCause;
    }
    global class FailureInformation {
        webservice String LocationGroupName;
        webservice String LocationName;
        webservice String PhenomenonName;
        webservice String CauseName;
        webservice String DescriptionName;
    }
 
    // 非同期を見せかけ、常にreturn void
    webservice static void NFM105(NFM105WebService.RepairStatusUpdate RepairStatusUpdate) {
        if (RepairStatusUpdate == null) {
            return;
        }
        NFMUtil.Monitoring Monitoring = RepairStatusUpdate.Monitoring;
        if (Monitoring == null) {
            return;
        }
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM105', RepairStatusUpdate.GeneralData);
        if (String.isBlank(rowData.Log__c) == false) executefuture(rowData.Id);
    }
 
    @future
    global static void executefuture(String rowData_Id) {
        execute(rowData_Id);
    }
    global static void execute(String rowData_Id) {
        // CHAN-BAW99B 20190410 NFM105Webservice停用,以后使用NFM105Rest
//        Integer batch_retry_max_cnt = Integer.valueOf(System.Label.batch_retry_max_cnt);
//        BatchIF_Log__c rowData = [Select Id, Name, Log__c, ErrorLog__c, Log2__c, Log3__c, Log4__c, Log5__c, Log6__c, Log7__c, Log8__c, Log9__c, Log10__c, Log11__c, Log12__c, MessageGroupNumber__c, TransmissionDateTime__c,retry_cnt__c from BatchIF_Log__c where RowDataFlg__c = true and Id = :rowData_Id];
//        String logstr = rowData.MessageGroupNumber__c + ' start\n';
//        BatchIF_Log__c iflog = new BatchIF_Log__c();
//        iflog.Type__c = 'NFM105';
//        iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
//        iflog.Log__c = logstr;
//        iflog.ErrorLog__c = '';
//        insert iflog;
//        String rowDataStr = NFMUtil.getRowDataStr(rowData);
//        List<GeneralData> generalDataList = (List<GeneralData>) JSON.deserialize(rowDataStr, List<GeneralData>.class);
//        if (generalDataList == null || generalDataList.size() == 0) {
//            return;
//        }
 
//        Savepoint sp = Database.setSavepoint();
//        try {
//            //repairNo list
//            List<String> sapRepairNoList  = new List<String>();
//            List<String> sfdcRepairNoList = new List<String>();
//            List<String> quotationNoList  = new List<String>();
//            for (NFM105WebService.GeneralData quoteInfo : generalDataList) {
//                // 必須項目がない場合、処理と飛ばす
//                if (quoteInfo.SAPRepairNo == null || quoteInfo.SAPRepairNo == '') {
//                    iflog.ErrorLog__c += 'SAPRepairNo is required\n';
//System.debug(Logginglevel.ERROR, 'NFM105_continue');
//                    continue;
//                } else {
//                    sapRepairNoList.add(quoteInfo.SAPRepairNo);
//                }
//                if (quoteInfo.SAPQuotationNo != null && quoteInfo.SAPQuotationNo != '') {
//                    quotationNoList.add(quoteInfo.SAPQuotationNo);
//                }
//                if (quoteInfo.SFDCRepairNo != null && quoteInfo.SFDCRepairNo != '') {
//                    sfdcRepairNoList.add(quoteInfo.SFDCRepairNo.toUpperCase());
//                }
//            }
//            //sapの外部keyで検索
//            List<Repair__c> sapRpairList = [select Id, Name, SAPRepairNo__c, Delivered_Product__c
//                                                , RepairOrderStatusName__c, RepairOrderStatusCode__c
//                                                , CancellationReason__c, IncorrectDataComment__c
//                                                , Repair_Rank__c, Repair_Ordered_Date__c
//                                                , Invalid_check__c, Delete_Flag__c
//                                                , Facility_Return_Receipt_Collection_Date__c, Receipt_received_date__c
//                                                , Return_Without_Repair_IF__c, Return_Without_Repair_Reason__c
//                                                , Repair_Quotation_Id__c, NFM105_MessageGroupNumber__c, Repair_List_Price_formula__c
//                                                , ReturnType__c, InspectType__c
//                                           from Repair__c
//                                          where SAPRepairNo__c in :sapRepairNoList];
//            Map<String, Repair__c> sapRepairsMap = new Map<String, Repair__c>();
//            for (Repair__c rpair : sapRpairList) {
//                sapRepairsMap.put(rpair.SAPRepairNo__c, rpair);
//            }
//            //sfdcのnameで検索
//            List<Repair__c> sfdcRpairList = [select Id, Name, SAPRepairNo__c, Delivered_Product__c
//                                                , RepairOrderStatusName__c, RepairOrderStatusCode__c
//                                                , CancellationReason__c, IncorrectDataComment__c
//                                                , Repair_Rank__c, Repair_Ordered_Date__c
//                                                , Invalid_check__c, Delete_Flag__c
//                                                , Facility_Return_Receipt_Collection_Date__c, Receipt_received_date__c
//                                                , Return_Without_Repair_IF__c, Return_Without_Repair_Reason__c
//                                                , Repair_Quotation_Id__c, NFM105_MessageGroupNumber__c, Repair_List_Price_formula__c
//                                                , ReturnType__c, InspectType__c
//                                           from Repair__c
//                                          where Name in :sfdcRepairNoList];
//            Map<String, Repair__c> sfdcRepairsMap = new Map<String, Repair__c>();
//            for (Repair__c rpair : sfdcRpairList) {
//                sfdcRepairsMap.put(rpair.Name, rpair);
//            }
//            List<Repair_Quotation__c> quotationList = [select Id, Name, Repair_Rank__c, Repair__c, ListPrice__c
//                                                              , InspectionComment__c, InspectionResultFlag__c
//                                                              , InspectionFailureCause__c
//                                                              , LatestQuotationDate__c
//                                                              , FirstQuotationDate__c, TotalPrice__c
//                                                              , DiscountType__c, DiscountAmount__c, Repair_Discount_Date__c
//                                                              , CafeteriaFlag__c, MessageGroupNumber__c
//                                                         from Repair_Quotation__c
//                                                        where Name in :quotationNoList
//                                                      ];
//            Map<String, Repair_Quotation__c> quotationMap = new Map<String, Repair_Quotation__c>();
//            for (Repair_Quotation__c quotation : quotationList) {
//                quotationMap.put(quotation.Name, quotation);
//            }
//            // 更新対応配列をセット
//            Map<String, Repair__c> rprUpdateMap = new Map<String, Repair__c>();                 // SAPRepairNo__c:Repair__c
//            Map<String, Asset> astUpdateMap = new Map<String, Asset>();                         // SAPRepairNo__c:Asset   TODO goto 修理のなかAssetに反映しないフラグはいりますか?超古い修理対応?
//            Map<Id, Repair_Quotation__c> rqUpdateMap = new Map<Id, Repair_Quotation__c>();      // keyも修理の Id にします。複数Quotation_agreement__cの場合後優先にする
//            Map<String, List<Repair_Quotation_reason__c>> quotationReasonsMap = new Map<String, List<Repair_Quotation_reason__c>>();
//            Map<Id, List<Repair_reason__c>> repairReasonsMap = new Map<Id, List<Repair_reason__c>>();
//            for (NFM105WebService.GeneralData quoteInfo : generalDataList) {
//                Repair__c rpr = null;
//                if (quoteInfo.SFDCRepairNo == null || quoteInfo.SFDCRepairNo == '') {
//                    rpr = sapRepairsMap.get(quoteInfo.SAPRepairNo);
//                    if (rpr == null) {
//                        // SAPRepairNo を受信したけど、SFDC側レコードがない
//                        iflog.ErrorLog__c += 'SAPRepairNo[' + quoteInfo.SAPRepairNo + ']NotExist\n';
//                        continue;
//                    }
//                } else {
//System.debug('quoteInfo.SFDCRepairNo=' + quoteInfo.SFDCRepairNo);
//                    rpr = sfdcRepairsMap.get(quoteInfo.SFDCRepairNo.toUpperCase());
//                    if (rpr == null) {
//                        // 修理受付番号 を受信したけど、SFDC側レコードがない
//                        iflog.ErrorLog__c += 'SFDCRepairNo[' + quoteInfo.SFDCRepairNo + ']NotExist(' + quoteInfo.SAPRepairNo + ')';
//                        rpr = sapRepairsMap.get(quoteInfo.SAPRepairNo);
//                        if (rpr == null) {
//                            iflog.ErrorLog__c += 'NotExist\n';
//                        }
//                        continue;
//                    }
//                }
//                // 項目転送のセット
//                rpr.SAPRepairNo__c = quoteInfo.SAPRepairNo;
//                if (rprUpdateMap.get(rpr.SAPRepairNo__c) == null) {
//                    logstr += quoteInfo.SAPRepairNo + ':' + quoteInfo.RepairOrderStatusCode + '(' + quoteInfo.SAPQuotationNo + ')';
//// B95の場合、見積り と 同期取るが、その ステータスの更新は、基本順番を厳密守る必要がない、ステータス更新日をいつでも連携できるようにします。
////                    if (rpr.NFM105_MessageGroupNumber__c > rowData.MessageGroupNumber__c) {
////                        iflog.ErrorLog__c += rpr.NFM105_MessageGroupNumber__c + ' done ';
////                        continue;
////                    }
//                    logstr += ' ';
//                    rprUpdateMap.put(rpr.SAPRepairNo__c, rpr);
//                } else {
//                    logstr += quoteInfo.SAPRepairNo + ':' + quoteInfo.RepairOrderStatusCode + '(' + quoteInfo.SAPQuotationNo + ') ';
//                    rpr = rprUpdateMap.get(rpr.SAPRepairNo__c);
//                }
//                if (String.isBlank(rpr.NFM105_MessageGroupNumber__c) || Integer.valueOf(rpr.NFM105_MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c) ){
//                    // 各ステータスが専用項目に保存してますけど、ここ1つ項目に保存して、履歴を取れるようにします
//                    rpr.RepairOrderStatusName__c  = quoteInfo.RepairOrderStatusName;
//                    rpr.RepairOrderStatusCode__c  = quoteInfo.RepairOrderStatusCode;
//                    if (quoteInfo.RepairOrderStatusCode == 'A95' || quoteInfo.RepairOrderStatusCode == 'A96') {
//                        rpr.Return_Without_Repair_IF__c = true;
//                        if (rpr.Return_Without_Repair_IF__c == true) {
//                            // TODO katsu いる?未修理返却申請 対応時対応するかも。
//                            rpr.Return_Without_Repair_Reason__c = (rpr.Return_Without_Repair_Reason__c == null || rpr.Return_Without_Repair_Reason__c == '') ? 'I/F理由、確認': rpr.Return_Without_Repair_Reason__c;
//                        }
//                    }
//                    if (quoteInfo.RepairOrderStatusCode == 'A99') {
//                        rpr.Delete_Flag__c = true;
//                        rpr.Return_Without_Repair_IF__c = false;
//                    } else {
//                        rpr.Delete_Flag__c = false;
//                    }
//                    if (quoteInfo.RepairOrderStatusCode == 'B95') {
//                        rpr.Return_Without_Repair_IF__c = false;
//                    }
 
//                    if (rpr.CancellationReason__c != null && !String.isBlank(rpr.CancellationReason__c)) {
//                        if (rpr.Repair_Start_Date__c == null) {
//                            rpr.Return_Without_Repair_IF__c = true;
//                        }
//                    }
//                }
//                // B95の場合、Repair_Quotation__c も更新
//                if (quoteInfo.RepairOrderStatusCode == 'B95') {
//                    Repair_Quotation__c rq = quotationMap.get(quoteInfo.SAPQuotationNo);
//                    if (rq == null) {
//                        iflog.ErrorLog__c += 'SAPQuotationNo[' + quoteInfo.SAPQuotationNo + ']NotExist(B95:' + quoteInfo.SAPRepairNo + ')';
//                        rpr = sapRepairsMap.get(quoteInfo.SAPRepairNo);
//                        if (rpr == null) {
//                            iflog.ErrorLog__c += 'NotExist\n';
//                        }
//                        continue;
//                    }
//                    rqUpdateMap.put(rpr.Id, rq);        // keyも修理の Id にします。複数Quotation_agreement__cの場合後優先にする
//                    rpr.Repair_List_Price__c = rq.ListPrice__c;
 
//                    if (String.isBlank(rpr.NFM105_MessageGroupNumber__c) || Integer.valueOf(rpr.NFM105_MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
//                        rpr.Repair_Quotation_Id__c = rq.Id;
//                    }
//                    if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
//                        rq.Quotation_agreement__c = true;
//                        if (quoteInfo.InspectionResultInformation != null && quoteInfo.InspectionResultInformation.size() != 0) {
//                            if (quoteInfo.InspectionResultInformation.size() > 1) {
//                                iflog.ErrorLog__c += 'RepairQuotation[' + quoteInfo.SAPQuotationNo + ']SFDCRepairNo[' + quoteInfo.SFDCRepairNo + '] InspectionResultInformation count is ' + quoteInfo.InspectionResultInformation.size() + '\n';
//                            }
//                            rq.InspectionResultFlag__c    = quoteInfo.InspectionResultInformation[0].InspectionResultFlag == 'X' ? 'OK' : 'NG';
//                            rq.InspectionComment__c       = quoteInfo.InspectionResultInformation[0].InspectionComment;
//                            rq.InspectionFailureCause__c  = quoteInfo.InspectionResultInformation[0].FailureCause;
//                            if (String.isBlank(rpr.NFM105_MessageGroupNumber__c) ||Integer.valueOf( rpr.NFM105_MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
//                                rpr.InspectionResultFlag__c   = rq.InspectionResultFlag__c;
//                                rpr.InspectionComment__c      = rq.InspectionComment__c;
//                                rpr.InspectionFailureCause__c = rq.InspectionFailureCause__c;
//                            }
//                        }
//System.debug('quotationReasonsMap.put(rq.Name):' + rq.Name);
//                        List<Repair_Quotation_reason__c> quotationReasons = new List<Repair_Quotation_reason__c>();
//                        quotationReasonsMap.put(rq.Name, quotationReasons);
//                        List<Repair_reason__c> repairReasons = new List<Repair_reason__c>();
//                        repairReasonsMap.put(rpr.Id, repairReasons);            // 複数見積りの場合後優先にする
//                        if (quoteInfo.FailureInformation != null && quoteInfo.FailureInformation.size() != 0) {
//                            for (NFM105WebService.FailureInformation fi : quoteInfo.FailureInformation) {
//                                Repair_Quotation_reason__c qrsn = new Repair_Quotation_reason__c();
//                                quotationReasons.add(qrsn);
//                                qrsn.LocationGroupName__c    = fi.LocationGroupName;
//                                qrsn.LocationName__c         = fi.LocationName;
//                                qrsn.PhenomenonName__c       = fi.PhenomenonName;
//                                qrsn.CauseName__c            = fi.CauseName;
//                                qrsn.DescriptionName__c      = fi.DescriptionName;
//                                Repair_reason__c rrsn = new Repair_reason__c(Repair__c = rpr.Id);
//                                repairReasons.add(rrsn);
//                                rrsn.LocationGroupName__c    = fi.LocationGroupName;
//                                rrsn.LocationName__c         = fi.LocationName;
//                                rrsn.PhenomenonName__c       = fi.PhenomenonName;
//                                rrsn.CauseName__c            = fi.CauseName;
//                                rrsn.DescriptionName__c      = fi.DescriptionName;
//                            }
//                        }
//                    }
//                    if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c)<= Integer.valueOf(rowData.MessageGroupNumber__c)) {
//                        rq.MessageGroupNumber__c   = rowData.MessageGroupNumber__c;
//                    }
//                }
 
//                // 各状態の更新者、NFM105_MessageGroupNumber__c を見ないこと
//                Datetime statusUpdateDateTime = NFMUtil.parseStr2DateTime(quoteInfo.StatusUpdateDate, quoteInfo.StatusUpdateTime);
//                if (statusUpdateDateTime == null) {
//                    statusUpdateDateTime = NFMUtil.parseStr2DateTimeDate(rowData.TransmissionDateTime__c + '00');
//                }
////                if (quoteInfo.RepairOrderStatusCode == 'A10') {
////                    // A10-分公司受理完成  ==> NFM103にて値を設定
////                    rpr.BranchOfficeRecievedDate__c = statusUpdateDateTime.date();
////                }
//                if (quoteInfo.RepairOrderStatusCode == 'A20') {
//                    // A20-RC受理完成
//                    rpr.Repair_Ordered_Date__c = statusUpdateDateTime.date();
//                    rpr.Repair_Ordered_Date_PersonName__c = quoteInfo.StatusUpdatePersonName;
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'A30') {
//                    // A30-受理检查完成
//                    rpr.Repair_Inspection_Date__c = statusUpdateDateTime.date();
//                    rpr.ReRepairObject_result__c = quoteInfo.ReRepairObject == 'X' ? true : false;
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'A95' || quoteInfo.RepairOrderStatusCode == 'A96') {
//                    // A95-取消修理受理  因没有零件等原因,RC同事不受理修理 (RC为主)
//                    // A96-取消修理    因报价金额高等原因,销售本部申请未修理 (销售本部申请为主)
//                    rpr.Invalid_check__c = true;
//                    rpr.repair_cancel_date__c = statusUpdateDateTime.date();
//                    rpr.CancellationReason__c = quoteInfo.CancellationReason;
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'A99') {
//                    // A99-修理单关闭   因申请内容和实际实物信息由差异,RC驳回此次申请的修理
//                    rpr.SAP_not_accept_repair_result__c = statusUpdateDateTime.date();
//                    rpr.IncorrectDataComment__c = quoteInfo.IncorrectDataComment;
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'B95') {
//                    Asset ast = getAstUpdate(astUpdateMap, rpr);
//                    ast.Agreed_Repair__c = rpr.Id;
//                    // B95-报价同意确认
//                    rpr.Agreed_Date__c = statusUpdateDateTime.date();
//                    rpr.Agreed_Date2__c = statusUpdateDateTime.date();
//                    // rpr.Agreed_Date__c <== TODO goto OFSにて設定するでしょうか?
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'B99') {
//                    // B99-报价同意确认取消
//                    // Agreed_Date2__c は クリアしないで、2回目再度同意されたら、同意日付は上書き。
//                    // Agreed_Date__c は クリアする
//                    Asset ast = getAstUpdate(astUpdateMap, rpr);
//                    ast.Agreed_Repair__c = null;
//                    rpr.Agreed_Date__c = null;
//                    rpr.Agreed_Date_Cancel__c = statusUpdateDateTime.date();
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'X30') {
//                    // X30-全部分配
//                    rpr.part_arrangement_complete__c = statusUpdateDateTime.date();
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'C50') {
//                    // C50-开始修理 
//                    rpr.Repair_Start_Date__c = statusUpdateDateTime.date();
//                    rpr.Planned_Repair_Completed_Date__c = NFMUtil.parseStr2Date(quoteInfo.PlannedRepairFinishDate);
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'C70') {
//                    // C70-修理完成
//                    rpr.Repair_Completed_Date__c = statusUpdateDateTime.date();
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'C90') {
//                    // C90-最终检查
//                    rpr.Repair_Final_Inspection_Date__c = statusUpdateDateTime.date();
//                    Asset ast = getAstUpdate(astUpdateMap, rpr);
//                    ast.LastSFDCRepairReturn_day__c = statusUpdateDateTime.date();
//                    ast.LastSFDCRepairNo__c = rpr.Name;
//                    if (System.Label.Large_Repair_Rank.indexOf(rpr.Repair_Rank__c + ',') >= 0) {
//                        ast.LastSFDCRepairNo_rankA__c = rpr.Name;
//                        ast.LastSFDCArankRepairReturn_day__c = statusUpdateDateTime.date();
//                    }
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'L99') {
//                    // L99-验收单签收复核通过
//                    rpr.InspectType__c = quoteInfo.InspectType;
//                    // 1-验收单
//                    if (quoteInfo.InspectType == '1') {
//                        // 一回目のみ設定
//                        if (rpr.Receipt_received_date__c == null) {
//                            rpr.Receipt_received_date__c = statusUpdateDateTime.date();
//                        }
//                        if (rpr.Facility_Return_Receipt_Collection_Date__c == null) {
//                            rpr.Facility_Return_Receipt_Collection_Date__c = statusUpdateDateTime.date();
//                        }
//                    }
//                    // 2-收款单
//                    if (rpr.Facility_Return_Receipt_Collection_Date__c == null && quoteInfo.InspectType == '2') {
//                        // 一回目のみ設定
//                        rpr.Facility_Return_Receipt_Collection_Date__c = statusUpdateDateTime.date();
//                    }
//                }
//                else if (quoteInfo.RepairOrderStatusCode == 'L60' || quoteInfo.RepairOrderStatusCode == 'L65' || quoteInfo.RepairOrderStatusCode == 'L80') {
//                    // L60-SORC修理品出库
//                    // L65-OGZ修理品出库
//                    // L80-RC修理品出库
//                    Asset ast = getAstUpdate(astUpdateMap, rpr);
//                    if (rpr.Return_Without_Repair_IF__c == true) {
//                        rpr.Return_Without_Repair_Date__c = statusUpdateDateTime.date();
//                        ast.Return_Without_Repair__c = rpr.Id;
//                    } else {
//                        ast.Return_Without_Repair__c = null;
//                    }
//                    ast.Agreed_Repair__c = null;
//                    if (quoteInfo.RepairOrderStatusCode == 'L80') {
//                        rpr.Repair_Shipped_Date__c = statusUpdateDateTime.date();
//                        rpr.ReturnType__c = quoteInfo.ReturnType;
//                        if (quoteInfo.ReturnType == 'A20' || quoteInfo.ReturnType == 'B30') {
//                            // A20-RC/FSE直返医院
//                            // B30-SORC直返医院
//                            rpr.Repair_Returned_To_HP_Date__c = statusUpdateDateTime.date();
//                        }
//                    }
//                }
////                else if (quoteInfo.RepairOrderStatusCode == 'D10') {
////                    // D10-返品
////                    rpr.Return_Without_Repair_Date__c = statusUpdateDateTime.date();
////                    Asset ast = getAstUpdate(astUpdateMap, rpr);
////                    ast.Return_Without_Repair__c = rpr.Id;
////                }
//                else if (quoteInfo.RepairOrderStatusCode == 'E10') {
//                    // E10-修理单完成
//                    rpr.RepairOrder_Complete_Day__c = statusUpdateDateTime.date();
//                }
//                if (String.isBlank(rpr.NFM105_MessageGroupNumber__c) || Integer.valueOf(rpr.NFM105_MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
//                    rpr.NFM105_MessageGroupNumber__c = rowData.MessageGroupNumber__c;
//                }
//            }
            
//            // その他のQuoteationのQuotation_agreement__cをfalseにする
//System.debug(Logginglevel.ERROR, 'rqUpdateMap.keySet=' + rqUpdateMap.keySet());
//            List<Repair_Quotation__c> rqList = [Select Id from Repair_Quotation__c where Quotation_agreement__c = true and Repair__c IN :rqUpdateMap.keySet() and Id Not IN :rqUpdateMap.values()];
//            for (Repair_Quotation__c rqfalse : rqList) {
//                rqfalse.Quotation_agreement__c = false;
//            }
//            rqList.addAll(rqUpdateMap.values());
//            if (rqList.size() > 0) {
//                // TODO update false;
//                upsert rqList;
//            }
//            if (rqUpdateMap.size() > 0) {
//                Map<String, Repair_Quotation__c> rqNameMap = new Map<String, Repair_Quotation__c>();
//                for (Repair_Quotation__c rq : rqUpdateMap.values()) {
//                    rqNameMap.put(rq.Name, rq);
//System.debug('rq.Name=' + rq.Name + ', rq.Repair__c=' + rq.Repair__c);
//                }
//                for (Repair_quotation_reason__c qrsn : [Select ActivityDescription__c, Repair_quotation__r.Name, Repair_quotation__r.Repair__c from Repair_quotation_reason__c
//                        where Repair_quotation__r.Name IN: quotationReasonsMap.keySet() and ActivityDescription__c != null]
//                ) {
//                    List<Repair_reason__c> repairReasons = repairReasonsMap.get(qrsn.Repair_quotation__r.Repair__c);
//                    if (repairReasons == null) {
//                        repairReasons = new List<Repair_reason__c>();
//                        repairReasonsMap.put(qrsn.Repair_quotation__r.Repair__c, repairReasons);
//                    }
//                    repairReasons.add(new Repair_reason__c(Repair__c = qrsn.Repair_quotation__r.Repair__c,
//                        ActivityDescription__c = qrsn.ActivityDescription__c
//                    ));
//                }
//                // CHAN-BAF2VC 20190327 LHJ Start
//                //NFM104WebService.deleteInsertReasons(rqNameMap, quotationReasonsMap, repairReasonsMap);
//                NFM104Rest.deleteInsertReasons(rqNameMap, quotationReasonsMap, repairReasonsMap);
//                // CHAN-BAF2VC 20190327 LHJ End
//            }
//            list<Repair__c> rprList = rprUpdateMap.values();
//            if (rprList.size() > 0) {
//                update rprList;
//            }
//            if (astUpdateMap.size() > 0) {
//                update astUpdateMap.values();
//            }
//            //gzozw-add
//            logstr += '\nend';
//            rowData.retry_cnt__c=0;
//        } catch (Exception ex) {
//            // エラーが発生した場合
//            Database.rollback(sp);
//            System.debug(Logginglevel.ERROR, 'NFM105_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage());
//            System.debug(Logginglevel.ERROR, 'NFM105_' + rowData.MessageGroupNumber__c + ':' + ex.getStackTraceString());
//            logstr += '\n' + ex.getMessage();
//            iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c;
//            /*if (rowData.retry_cnt__c == null) rowData.retry_cnt__c = 0;
//            if (rowData.retry_cnt__c < batch_retry_max_cnt){
//                rowData.retry_cnt__c++;
//                LogAutoSendSchedule.assignOneMinute();
//            }*/
//            if (rowData.retry_cnt__c >= batch_retry_max_cnt){
//                rowData.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + rowData.ErrorLog__c+'错误次数已经超过自动收信设定的最大次数,请手动收信';
//            }
//        }
//        update rowData;
//        iflog.Log__c = logstr;
//        if (iflog.Log__c.length() > 131072) {
//            iflog.Log__c = iflog.Log__c.subString(0, 131065) + ' ...';
//        }
//        if (iflog.ErrorLog__c.length() > 32768) {
//            iflog.ErrorLog__c = iflog.ErrorLog__c.subString(0, 32760) + ' ...';
//        }
//        update iflog;
    }
    
    //private static Asset getAstUpdate(Map<String, Asset> astUpdateMap, Repair__c rpr) {
    //    Asset ast = astUpdateMap.get(rpr.Delivered_Product__c);
    //    if (ast == null) {
    //        ast = new Asset(Id = rpr.Delivered_Product__c);
    //        astUpdateMap.put(rpr.Delivered_Product__c, ast);
    //    }
    //    return ast;
    //}
}