高章伟
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
// RowDataを残すため、@future execute にします
global class NFM104WebService {
    global class RepairQuotation {
        webservice NFMUtil.Monitoring Monitoring;
        webservice NFM104WebService.QuotationHeaderInformation[] QuotationHeaderInformation;
    }
    global class QuotationHeaderInformation {
        webservice String SFDCRepairNo;
        webservice String SAPRepairNo;
        webservice String SAPQuotationNo;
        webservice String FirstQuotationDate;
        webservice String LatestQuotationDate;
        webservice String ListPrice;
        webservice String TotalPrice;
        webservice String RepairRank;
        webservice String CafeteriaFlag;
        webservice NFM104WebService.DiscountInformation[] DiscountInformation;
        webservice NFM104WebService.InspectionResultInformation[] InspectionResultInformation;
        webservice NFM104WebService.FailureInformation[] FailureInformation;
        webservice NFM104WebService.ActivityInformation[] ActivityInformation;
    }
    global class DiscountInformation {
        webservice String DiscountType;
        webservice String DiscountAmount;
    }
    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;
    }
    global class ActivityInformation {
        webservice String ActivityDescription;
    }
 
    // 非同期を見せかけ、常にreturn void
    webservice static void NFM104(NFM104WebService.RepairQuotation RepairQuotation) {
        if (RepairQuotation == null) {
            return;
        }
        NFMUtil.Monitoring Monitoring = RepairQuotation.Monitoring;
        if (Monitoring == null) {
            return;
        }
        BatchIF_Log__c rowData = NFMUtil.saveRowData(Monitoring, 'NFM104', RepairQuotation.QuotationHeaderInformation);
        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-BAF2VC 20190327 NFM104Webservice停用,以后使用NFM104Rest
 
        //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 = 'NFM104';
        //iflog.MessageGroupNumber__c = rowData.MessageGroupNumber__c;
        //iflog.Log__c = logstr;
        //iflog.ErrorLog__c = '';
        //insert iflog;
        //String rowDataStr = NFMUtil.getRowDataStr(rowData);
        //List<QuotationHeaderInformation> quotationInformationList = (List<QuotationHeaderInformation>) JSON.deserialize(rowDataStr, List<QuotationHeaderInformation>.class);
        //if (quotationInformationList == null || quotationInformationList.size() == 0) {
        //    return;
        //}
 
        //Savepoint sp = Database.setSavepoint();
        //try {
        //    //repairNo list
        //    List<String> receiptNoList = new List<String>();
        //    //报价No SAPQuotationNo list
        //    List<String> quotationNoList = new List<String>();
        //    // 2018/8/20 HWAG-B3P55Z start 存储CafeteriaFlagList
        //    list<string> CafeteriaFlagList = new list<string>();
        //    // 2018/8/20 HWAG-B3P55Z start 存储CafeteriaFlagList
        //    for (NFM104WebService.QuotationHeaderInformation quoteInfo : quotationInformationList) {
        //        // 必須項目がない場合、処理と飛ばす
        //        if (quoteInfo.SAPQuotationNo == null || quoteInfo.SAPQuotationNo == '') {
        //            iflog.ErrorLog__c += 'SAPQuotationNo is required\n';
        //            continue;
        //        }
        //        if (quoteInfo.SFDCRepairNo == null || quoteInfo.SFDCRepairNo == '') {
        //            iflog.ErrorLog__c += '[' + quoteInfo.SAPQuotationNo + ']SFDCRepairNo is required\n';
        //            continue;
        //        }
 
        //        if (quoteInfo.SFDCRepairNo != null && quoteInfo.SFDCRepairNo != '') {
        //            receiptNoList.add(quoteInfo.SFDCRepairNo);
        //        }
        //    // 2018/8/20 HWAG-B3P55Z start 存储CafeteriaFlagList
        //        if(String.isNotEmpty(quoteInfo.CafeteriaFlag)){
        //            CafeteriaFlagList.add(quoteInfo.CafeteriaFlag);
        //        }
        //    // 2018/8/20 HWAG-B3P55Z start 存储CafeteriaFlagList
        //        quotationNoList.add(quoteInfo.SAPQuotationNo);
        //    }
 
        //    //修理を検索
        //    List<Repair__c> sfdcRpairList = [select Id, Name, SAPRepairNo__c, Repair_Quotation_Id__c
        //                                        , Repair_Quotation_Id__r.MessageGroupNumber__c
        //                                   from Repair__c
        //                                  where Name in :receiptNoList];
        //    Map<String, Repair__c> sfdcRepairsMap = new Map<String, Repair__c>();
        //    for (Repair__c recpt : sfdcRpairList) {
        //        sfdcRepairsMap.put(recpt.Name, recpt);
        //    }
 
        //    List<Repair_Quotation__c> quotationList = [select Id, Name, Repair_Rank__c, Repair__c
        //                                                      , InspectionComment__c, InspectionResultFlag__c
        //                                                      , InspectionFailureCause__c
        //                                                      , LatestQuotationDate__c
        //                                                      , FirstQuotationDate__c, ListPrice__c, TotalPrice__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> repairUpdateMap = new Map<String, Repair__c>();
        //    Map<String, Repair_Quotation__c> rqUpdateMap = new Map<String, Repair_Quotation__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>>();
 
        //    // 2018/8/20 HWAG-B3P55Z start 构造经销商map
        //    list<Account> accs = [select id,Name, Management_Code__c from Account where Management_Code__c in: CafeteriaFlagList];
        //    map<string, Account> DealersAccMap = new map<string, Account>();
        //    for(Account acc : accs){
        //        DealersAccMap.put(acc.Management_Code__c,acc);
        //    }
        //    // 2018/8/20 HWAG-B3P55Z end 构造经销商map
        //    for (NFM104WebService.QuotationHeaderInformation quoteInfo : quotationInformationList) {
        //        Repair_Quotation__c rq = null;
        //        if (quoteInfo.SAPQuotationNo != null && quoteInfo.SAPQuotationNo != '') {
        //            rq = quotationMap.get(quoteInfo.SAPQuotationNo);
        //        }
        //        if (rq == null) {
        //            rq = new Repair_Quotation__c();
        //        }
        //        //修理を取る
        //        Repair__c rpr = sfdcRepairsMap.get(quoteInfo.SFDCRepairNo.toUpperCase());
        //        if (rpr == null) {
        //            iflog.ErrorLog__c += 'SFDCRepairNo[' + quoteInfo.SFDCRepairNo + ']NotExist\n';
        //            continue;
        //        } else {
        //            // 同期中的询价为空或者MessageGroupNumber小于正在执行的的MessageGroupNumber
        //            if (rpr.Repair_Quotation_Id__c == null
        //                    || String.isBlank(rpr.Repair_Quotation_Id__r.MessageGroupNumber__c)
        //                    || Integer.valueOf(rpr.Repair_Quotation_Id__r.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //                //rprUpdateList.add(rpr);
        //                repairUpdateMap.put(quoteInfo.SAPQuotationNo, rpr);
        //                rpr.SAPRepairNo__c = quoteInfo.SAPRepairNo;
        //                rpr.Repair_Rank__c = quoteInfo.RepairRank;
        //                /*if (String.isBlank(quoteInfo.CafeteriaFlag) == false && ( quoteInfo.CafeteriaFlag.length() == 15 || quoteInfo.CafeteriaFlag.length() == 18)) {
        //                    rpr.Dealer__c = quoteInfo.CafeteriaFlag;
        //                }*/
        //            }
        //        }
        //        if (rq.Repair__c == null) {
        //            rq.Repair__c = rpr.Id;
        //        } else {
        //            if (rq.Repair__c != rpr.Id) {
        //                iflog.ErrorLog__c += 'isnot SFDCRepairNo[' + quoteInfo.SFDCRepairNo + ']\'s child\n';
        //            }
        //        }
 
        //        rq.Name = quoteInfo.SAPQuotationNo;
        //        if (rqUpdateMap.get(rq.Name) == null) {
        //            rqUpdateMap.put(rq.Name, rq);
        //            logstr += quoteInfo.SAPQuotationNo + ' ';
        //        } else {
        //            rq = rqUpdateMap.get(rq.Name);
        //        }
 
        //        if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //            rq.FirstQuotationDate__c   = NFMUtil.parseStr2Date(quoteInfo.FirstQuotationDate);              // TODO 修理単位?报价単位?
        //            rq.LatestQuotationDate__c  = NFMUtil.parseStr2Date(quoteInfo.LatestQuotationDate);             // TODO 修理単位?报价単位?
        //            rq.Repair_Rank__c          = quoteInfo.RepairRank;
        //            rq.ListPrice__c            = String.isBlank(quoteInfo.ListPrice) ? null : Decimal.valueOf(quoteInfo.ListPrice);
        //            rq.TotalPrice__c           = String.isBlank(quoteInfo.TotalPrice) ? null : Decimal.valueOf(quoteInfo.TotalPrice);
        //            // 2018/8/17 HWAG-B3P55Z start 注释
        //            //rq.CafeteriaFlag__c        = quoteInfo.CafeteriaFlag == 'X' ? true : false;
        //            // 2018/8/17 HWAG-B3P55Z start 注释
        //            // 2018/8/17 HWAG-B3P55Z start 赋值给经销商管理编码
        //            if(String.isNotEmpty(quoteInfo.CafeteriaFlag)){
        //                if(DealersAccMap.containsKey(quoteInfo.CafeteriaFlag)){
        //                    Account acc = DealersAccMap.get(quoteInfo.CafeteriaFlag);
        //                    rq.Dealer_Name__c               = acc.Name;
        //                    rq.Dealer_Management_Code__c    = quoteInfo.CafeteriaFlag;
        //                }
        //            }
        //            // 2018/8/17 HWAG-B3P55Z end  赋值给经销商管理编码
        //        }
 
        //        if (quoteInfo.DiscountInformation != null && quoteInfo.DiscountInformation.size() != 0) {
        //            if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //                // 新しいI/F しか処理しない
        //                for (NFM104WebService.DiscountInformation di : quoteInfo.DiscountInformation) {
        //                    if (di.DiscountType == '营业对应') {
        //                        rq.sales_discount__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '维修协议') {
        //                        rq.Contract_target__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '新品保修期内无偿') {
        //                        rq.New_QIS_free__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '新品保修期内非品质问题') {
        //                        rq.New_QIS_not_QIS_issue__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '维修保修期内无偿') {
        //                        rq.Contract_free__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '维修保修期非品质问题') {
        //                        rq.Contract_not_QIS_issue__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '备品修理') {
        //                        rq.Loaner_repair__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '维护保养项目') {
        //                        rq.maintenance_pj__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == 'CCD线短') {
        //                        rq.CCD_cut__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '特别对应') {
        //                        rq.Special_offer__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '多年保修') {
        //                        rq.long_term_insurance__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '套餐折扣') {
        //                        rq.Set_discount__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else if (di.DiscountType == '维修合同') {
        //                        rq.Servince_contract_discount_amount__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    // add by hanchao 2016.7.21
        //                    else if (di.DiscountType == '运输索赔') {
        //                        rq.Delivery_compensation__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    //
        //                    else if (di.DiscountType == '其他') {
        //                        rq.Other_discount__c = String.isBlank(di.DiscountAmount) ? null : Decimal.valueOf(di.DiscountAmount);
        //                    }
        //                    else {
        //                        iflog.ErrorLog__c += 'SFDCRepairNo[' + quoteInfo.SFDCRepairNo + '] Undefined DiscountType[' + di.DiscountType + ']\n';
        //                    }
        //                }
        //            }
        //            if (String.isBlank(rq.MessageGroupNumber__c) || rq.MessageGroupNumber__c > rowData.MessageGroupNumber__c) {
        //                // 一回目 or 古いI/Fが来た場合
        //                rq.Repair_Discount_Date__c = NFMUtil.parseStr2DateTimeDate(rowData.TransmissionDateTime__c + '00');
        //            }
        //        }
        //        if (quoteInfo.InspectionResultInformation != null && quoteInfo.InspectionResultInformation.size() != 0) {
        //            if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //                if (quoteInfo.InspectionResultInformation.size() > 1) {
        //                    iflog.ErrorLog__c += '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;
        //            }
        //        }
        //        // Repair_quotation_reason__c delete insert する、見積りはまだinsertされていない可能性もあるので、upsert rqList; のあとやります。
        //        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);            // 複数見積りの場合後優先にする
        //        System.debug('quoteInfo.ActivityInformation=' + quoteInfo.ActivityInformation);
        //        if (quoteInfo.ActivityInformation != null && quoteInfo.ActivityInformation.size() != 0) {
        //        System.debug('rq.MessageGroupNumber__c=' + rq.MessageGroupNumber__c);
        //            if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //                System.debug('before ActivityInformation quotationReasons=' + quotationReasons);
        //                for (NFM104WebService.ActivityInformation ai : quoteInfo.ActivityInformation) {
        //                    if (String.isBlank(ai.ActivityDescription) == false) {
        //                        Repair_Quotation_reason__c qrsn = new Repair_Quotation_reason__c();
        //                        quotationReasons.add(qrsn);
        //                        qrsn.ActivityDescription__c = ai.ActivityDescription;
        //                        Repair_reason__c rrsn = new Repair_reason__c(Repair__c = rpr.Id);
        //                        repairReasons.add(rrsn);
        //                        rrsn.ActivityDescription__c = ai.ActivityDescription;
        //                    }
        //                }
        //            }
        //        }
        //        if (String.isBlank(rq.MessageGroupNumber__c) || Integer.valueOf(rq.MessageGroupNumber__c) <= Integer.valueOf(rowData.MessageGroupNumber__c)) {
        //            if (quoteInfo.FailureInformation != null && quoteInfo.FailureInformation.size() != 0) {
        //                for (NFM104WebService.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;
        //        }
        //    }
 
        //    List<Repair_Quotation__c> rqList = rqUpdateMap.values();
        //    if (rqList.size() > 0) {
        //        // TODO update false;
        //        upsert rqList;
        //        deleteInsertReasons(rqUpdateMap, quotationReasonsMap, null);        // repairReasonsMap
        //    }
            
        //    if (repairUpdateMap.size() > 0) {
        //        //同期中的报价をwrite back, Idについて見積りがupsert後しかとれないです。
        //        for (String sapQuotationNo : repairUpdateMap.keySet()) {
        //            Repair__c rpr = repairUpdateMap.get(sapQuotationNo);
        //            rpr.Repair_Quotation_Id__c = rqUpdateMap.get(sapQuotationNo).Id;
        //            rpr.Repair_Estimated_Date__c = rqUpdateMap.get(sapQuotationNo).FirstQuotationDate__c;
        //            rpr.Repair_Discount_Date__c = rqUpdateMap.get(sapQuotationNo).Repair_Discount_Date__c;
        //        }
        //        update repairUpdateMap.values();
        //    }
 
        //    logstr += '\nend';
        //    rowData.retry_cnt__c=0;
        //} catch (Exception ex) {
        //    // エラーが発生した場合
        //    Database.rollback(sp);
        //    System.debug(Logginglevel.ERROR, 'NFM104_' + rowData.MessageGroupNumber__c + ':' + ex.getMessage());
        //    System.debug(Logginglevel.ERROR, 'NFM104_' + 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;
    }
    
    // NFM104とNFM105より呼び出す
    public static void deleteInsertReasons(Map<String, Repair_Quotation__c> rqNameMap,
            Map<String, List<Repair_Quotation_reason__c>> quotationReasonsMap, Map<Id, List<Repair_reason__c>> repairReasonsMap) {
        //System.debug('deleteInsertReasons start');
        //Boolean fromNFM105 = false;
        //if (repairReasonsMap != null) {
        //    fromNFM105 = true;
        //}
        //List<Repair_quotation_reason__c> quoReasonList = null;
        //if (fromNFM105) {
        //    // NFM105の場合、理由だけ変更する
        //    quoReasonList = [Select Id from Repair_quotation_reason__c where Repair_quotation__r.Name IN: quotationReasonsMap.keySet() and ActivityDescription__c = null];
        //} else {
        //    quoReasonList = [Select Id from Repair_quotation_reason__c where Repair_quotation__r.Name IN: quotationReasonsMap.keySet()];
        //}
        //if (quoReasonList.size() > 0) delete quoReasonList;
        //if (repairReasonsMap != null) {
        //    List<Id> rprIds = new List<Id>();
        //    for (String rqName : quotationReasonsMap.keySet()) {
        //        rprIds.add(rqNameMap.get(rqName).Repair__c);
        //    }
        //    List<Repair_reason__c> rprReasonList = null;
        //    if (fromNFM105) {
        //        // NFM105の場合、理由だけ変更する
        //        rprReasonList = [Select Id from Repair_reason__c where Repair__c IN: rprIds and ActivityDescription__c = null];
        //    } else {
        //        rprReasonList = [Select Id from Repair_reason__c where Repair__c IN: rprIds];
        //    }
        //    if (rprReasonList.size() > 0) delete rprReasonList;
        //}
        //List<Repair_Quotation_reason__c> qrsnList = new List<Repair_Quotation_reason__c>();
        //List<Repair_reason__c> rrsnList = new List<Repair_reason__c>();
        //for (String rqName : quotationReasonsMap.keySet()) {
        //    List<Repair_Quotation_reason__c> quotationReasons = quotationReasonsMap.get(rqName);
        //    qrsnList.addAll(quotationReasons);
        //    for (Repair_Quotation_reason__c qrsn : quotationReasons) {
        //        qrsn.Repair_quotation__c = rqNameMap.get(rqName).Id;
        //    }
        //    if (repairReasonsMap != null) {
        //        List<Repair_reason__c> repairReasons = repairReasonsMap.get(rqNameMap.get(rqName).Repair__c);
        //        rrsnList.addAll(repairReasons);
        //        for (Repair_reason__c rrsn : repairReasons) {
        //            rrsn.Repair_quotation__c = rqNameMap.get(rqName).Id;
        //        }
        //    }
        //}
        //System.debug('deleteInsertReasons qrsnList=' + qrsnList);
        //if (rrsnList.size() > 0) insert rrsnList;
        //if (qrsnList.size() > 0) insert qrsnList;
    }
}