高章伟
2022-02-18 650847118307a1c9ae0ada15b7c69bbf5792c54c
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
global class RadiationUtil {
 
    public static Boolean EscapeOrderTriggerHandler = true;
    /**
     * [updateRadiationTypeQuantity description]更新代理商证照明细,更新奥林巴斯代理商的证照明细
     * @param Id           [description]合同Id
     * @param orderFounder [description]合同创建人
     * @param dealerId     [description]代理商Id
     * @param toloseFlag   [description]根据条件增加还是减去代理商购买明细的数量
     */
    public static void updateRadiationTypeQuantity (String Id, String orderFounder, String dealerId, Boolean toloseFlag, String operationType, String operator) {
 
        String olympusAccountId = System.label.Olympus_Id;
 
        String orderId = Id;
        //获取合同的辐射类型和数量
        Map<String, Integer> radiationTypeQuantityMap =  GetModelQuantityMap(Id);
        if ( radiationTypeQuantityMap.size() > 0 ) {
 
            //查代理商的代理商购买明细
            Map<String, PurchaseDetails__c> dealerModelQuantityMap = GetPurchaseDetailsMap(dealerId);
            //查奥林巴斯的代理商购买明细
            Map<String, PurchaseDetails__c> olympusModelQuantityMap = GetPurchaseDetailsMap(olympusAccountId);
            // 查找 合同提交对应的代理商购买明细
            Map<String, PurchaseDetails__c> dealerResult = new Map<String, PurchaseDetails__c>();
            Map<String, PurchaseDetails__c> olympusResult = new Map<String, PurchaseDetails__c>();
            // 合同驳回、合同调回、合同状态由批准变草案--->已售产品数量    
            if (toloseFlag) {
                // 1.查找合同 的 购买明细变更详情 操作类型是 合同提交和合同草案中变批准        
                List<ChangedReport__c> selectChangedReportList = [
                SELECT Id,Name,ChangedPurchase__c,ChangedReportOrder__c,OperationType__c,
                       ChangedPurchase__r.PurchaseAccount__c 
                FROM ChangedReport__c 
                WHERE ChangedReportOrder__c = :orderId AND OperationType__c IN ('合同提交','合同草案中变批准')  Order by Id ];
 
                if (selectChangedReportList.size() > 0) {
                    // 2.取出合同对应的代理商最新的 购买明细变更详情
                    Map<String,String> tempMap = new Map<String,String>();
                    for (ChangedReport__c changedReport:selectChangedReportList) {
                        String accountIdSub = changedReport.ChangedPurchase__r.PurchaseAccount__c;
                        accountIdSub = accountIdSub.substring(0,15);
                        tempMap.put(accountIdSub,changedReport.ChangedPurchase__c);
                    }
                    if (tempMap.size() > 0) {
                        // 3.取出对应的 代理商辐射产品购买明细
                        List<PurchaseDetails__c> purchaseDetailsList = [
                        SELECT Id, Name, RemainingNumber__c, SoldNumber__c,
                                                 PurProductModel__c, PurchaseAccount__c
                        FROM PurchaseDetails__c
 
                        WHERE Id IN :tempMap.values()];
                        
                        if (purchaseDetailsList.size() > 0) {
                            for (PurchaseDetails__c purchaseDetail : purchaseDetailsList) {
                                String accountIdSub = purchaseDetail.PurchaseAccount__c;
                                accountIdSub = accountIdSub.substring(0,15);
 
                                if (dealerId.equals(accountIdSub)) {
                                    dealerResult.put(purchaseDetail.PurProductModel__c, purchaseDetail);
                                } else if(olympusAccountId.equals(accountIdSub)){
                                    olympusResult.put(purchaseDetail.PurProductModel__c, purchaseDetail);
                                }
                                
                            }
                        }
                    }
                }
            }
 
            
            Map<String, ChangedReport__c> reportMap = new Map<String, ChangedReport__c>();
            Map<String, ChangedReport__c> insertReportMap = new Map<String, ChangedReport__c>();
            for ( String radiationType : radiationTypeQuantityMap.keySet()) {
 
                //代理商的代理商购买明细赋值
                Integer quantity = radiationTypeQuantityMap.get(radiationType);
                if (dealerModelQuantityMap.size() > 0) {
                    if ( dealerModelQuantityMap.containsKey(radiationType)) {
 
                        if (toloseFlag) {//减去已售产品数量
                            reportMap.putAll(upsertChangedReport(dealerId, radiationType, operationType, orderId, -quantity, operator));
                            dealerResult.get(radiationType).SoldNumber__c -= quantity;
                        } else {//增加已售产品数量
                            reportMap.putAll(upsertChangedReport(dealerId, radiationType, operationType, orderId, quantity, operator));
                            dealerModelQuantityMap.get(radiationType).SoldNumber__c += quantity;
                        }
 
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(dealerId, radiationType, operationType, orderId, quantity, operator));
                        dealerModelQuantityMap = insertPurchaseDetail(dealerModelQuantityMap, dealerId, radiationType, radiationTypeQuantityMap);
                    }
                } else {
                    if (toloseFlag) {//减去已售产品数量
                        reportMap.putAll(upsertChangedReport(dealerId, radiationType, operationType, orderId, -quantity, operator));
                        dealerResult.get(radiationType).SoldNumber__c -= quantity;
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(dealerId, radiationType, operationType, orderId, quantity, operator));
                        dealerModelQuantityMap = insertPurchaseDetail(dealerModelQuantityMap, dealerId, radiationType, radiationTypeQuantityMap);
                    }
                   
 
                }
 
                //奥林巴斯的代理商购买明细赋值
                if (olympusModelQuantityMap.size() > 0 ) {
                    if (olympusModelQuantityMap.containsKey(radiationType)) {
                        if (toloseFlag) {//减去已售产品数量
                            reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, -quantity, operator));
                            olympusResult.get(radiationType).SoldNumber__c -= quantity;
                        } else {//增加已售产品数量
                            reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
                            olympusModelQuantityMap.get(radiationType).SoldNumber__c += quantity;
                        }
 
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
                        olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
                    }
                } else {//减去已售产品数量
                    if (toloseFlag) {
                        reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, -quantity, operator));
                        olympusResult.get(radiationType).SoldNumber__c -= quantity;
                    } else {//增加已售产品数量
                        reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
                        olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
                    }
                    
                }
            }
            
            if (toloseFlag) {
                if ( dealerResult.size() > 0 && dealerResult != null) {
                    upsert dealerResult.values();
 
                    insertReportMap.putAll(insertChangedReport(dealerResult,reportMap));
                } 
 
                if ( olympusResult.size() > 0 && olympusResult != null) {
                    upsert olympusResult.values();
                    insertReportMap.putAll(insertChangedReport(olympusResult, reportMap));
                }
 
            } else {
                if ( dealerModelQuantityMap.size() > 0 && dealerModelQuantityMap != null) {
                    upsert dealerModelQuantityMap.values();
                    insertReportMap.putAll(insertChangedReport(dealerModelQuantityMap,reportMap));
                } 
 
                if ( olympusModelQuantityMap.size() > 0 && olympusModelQuantityMap != null) {
                    upsert olympusModelQuantityMap.values();
                    insertReportMap.putAll(insertChangedReport(olympusModelQuantityMap, reportMap));
                }
            }
                
            if ( insertReportMap.size() > 0 && insertReportMap != null) {
                insert insertReportMap.values();
            }
            
            Map<String, Integer> radiationMap =  new Map<String, Integer>();
            String accountDealerErrorMessage = updateCertificationDetails(dealerId, orderFounder, radiationMap, true);
            String olympusDealerErrorMessage = updateCertificationDetails(olympusAccountId, orderFounder, radiationMap, true);
        }
 
    }
    /**
     * 代理商购买明细操作详情赋值
     * @Author   稀里糊涂
     * @DateTime 2020-02-22
     * @param    detailsMap [description]代理商购买明细
     * @param    reportMap  [description]代理商购买明细操作详情
     * @return              [description]
     */
    public static Map<String, ChangedReport__c> insertChangedReport( Map<String, PurchaseDetails__c> detailsMap, Map<String, ChangedReport__c> reportMap) {
        for (PurchaseDetails__c detail : detailsMap.values()) {
            String accountId = detail.PurchaseAccount__c;
            //String accountIdafter = accountId.subString(0,15);
            String key = accountId.subString(0, 15) + detail.PurProductModel__c;
            if (reportMap.containsKey(key)) {
                reportMap.get(key).ChangedPurchase__c = detail.Id;
            }
        }
 
        return reportMap;
    }
    /**
     * [updateCertificationDetails description]更新代理商的证照明细
     * @param  accountId    [description]代理商Id
     * @param  orderFounder [description]合同创建人
     * @param  dataMap      [description]待验证的数据
     * @param  updateFlag   [description]是否更新数据
     * @return              [description]
     */
    public static String updateCertificationDetails( String accountId, String orderFounder, Map<String, Decimal> dataMap, Boolean updateFlag) {
 
        Map<String, CertificationDetails__c> certificationDetailMap = GetAccountCertificationDetail(accountId);
        Map<String, CertificationDetails__c> temporaryCertificationDetailMap = GetAccountCertificationDetail(accountId);
        Map<String, PurchaseDetails__c> purchaseDetailMap = GetPurchaseDetailsMap(accountId);
 
        Map<String, CertificationDetails__c> updatecertificationDetailMap = new Map<String, CertificationDetails__c>();
        String record = '';
        String errorMessage = '';
        if (certificationDetailMap.size() > 0 && certificationDetailMap != null ) {
 
            if (dataMap.size() > 0 && dataMap != null) {
 
                for (String temp : dataMap.keySet()) {
                    if (certificationDetailMap.containsKey(temp)) {
 
                    } else {
                        if (certificationDetailMap.containsKey('Delta和Vanta')) {
                            List<String> childModels = new List<String> {'Delta', 'Vanta'};
                            if (childModels.contains(temp)) {
 
                            } else {
                                errorMessage = '你不能' + temp + '系列产品' + certificationDetailMap.keySet();
                                return errorMessage;
                            }
                        } else {
                            errorMessage = '你不能' + temp + '系列产品' + certificationDetailMap.keySet();
                            return errorMessage;
 
                        }
 
                    }
                }
            }
 
            // 遍历查询出来的证照明细
            for (String model : certificationDetailMap.keySet()) {
 
                Decimal purchaseQuantity = 0;
                //获取辐射证照明细上,该型号对应的数量
                Decimal certificationQuantity = certificationDetailMap.get(model).ProductModelNumber__c;
                //获取证照的客户名称
                String accountName = certificationDetailMap.get(model).CertificationDetailAccountName__c;
                //获取证照的客户是否数量管控
                Boolean ifQuantityCtrl = certificationDetailMap.get(model).LicenseInformation__r.IfQuantityCtrl__c;
                //获取证照的客户的记录类型
                String  accountRecordType = certificationDetailMap.get(model).AccountRecordType__c;
                //证照的客户记录类型为代理商并且非数量管控直接跳过
                if (!ifQuantityCtrl && 'Dealer'.equals(accountRecordType)) {
                    system.debug(' 我被跳过了,请注意');
                    continue;    
                } else {
                    if (certificationQuantity == null || certificationQuantity == 0) {
                        errorMessage += record = '客户名 [ ' + accountName + ' ] 产品辐射类型 [ ' + model + ' ] 所对应可售数量异常!!!';
                        return errorMessage;
                    }
                }
                Decimal percentage = 0;
                Decimal originalQuantity = 0;
                Decimal newQuantity = 0;
                Boolean errorFlag = false;
                if (model.equals('Delta和Vanta')) {
                    List<String> childModels = new List<String> {'Delta', 'Vanta'};
                    for (String childModel : childModels) {
                        if (purchaseDetailMap.containsKey(childModel)) {
                            originalQuantity += purchaseDetailMap.get(childModel).SoldNumber__c;
                        }
                        if (dataMap != null && dataMap.size() > 0 && dataMap.containsKey(childModel)) {
 
                            newQuantity += dataMap.get(childModel);
                        }
                    }
 
                } else {
                    if (purchaseDetailMap.containsKey(model)) {
                        originalQuantity = purchaseDetailMap.get(model).SoldNumber__c;
 
                    }
                    if (dataMap != null && dataMap.size() > 0 && dataMap.containsKey(model)) {
                        newQuantity += dataMap.get(model);
                    }
                }
 
                purchaseQuantity = originalQuantity + newQuantity;
 
                percentage = purchaseQuantity / certificationQuantity;
 
                if (updateFlag) {
 
                    record = '客户名 [ ' + accountName + ' ] 产品辐射类型 [ ' + model + ' ] 已售出数量为 [ ' + originalQuantity + ' ] 件,允许售出的数量为 [ ' + certificationQuantity + ' ]件。' ;
                    // if (percentage <= 1) {
 
                    temporaryCertificationDetailMap = radiationSendEmailSign(certificationDetailMap, orderFounder, model, record, percentage, updateFlag);
                        // system.debug('temporaryCertificationDetailMap----->'+'(---'+accountName+'---)'+temporaryCertificationDetailMap);
                    updatecertificationDetailMap.putAll(temporaryCertificationDetailMap);
                    // } else {
                    //     errorMessage += record + '已超出可售数量限制,无法保存。\n';
                    // }
 
                } else {
                    if (newQuantity > 0) {
                        record = '客户名 [ ' + accountName + ' ] 产品辐射类型 [ ' + model + ' ] 已售出数量为 [ ' + originalQuantity + ' ] 件,新增 [ ' + newQuantity + ' ]件,允许售出的数量为 [ ' + certificationQuantity + ' ]件。';
                        if (percentage > 1) {
 
                            errorMessage += record + '已超出可售数量限制。\n';
                        }
                    }
 
                }
 
            }
 
            if (updateFlag) {
 
                if ( updatecertificationDetailMap.size() > 0) {
                    update updatecertificationDetailMap.values();
                }
            }
        }
 
        return errorMessage;
 
 
    }
 
    /**
     * [radiationSendEmailSign description]检验是否超过可售上限的80%,90%
     * @param  certificationDetailMap [description]代理商的证照明细
     * @param  orderFounder           [description]合同创建人Id
     * @param  model                  [description]辐射产品型号
     * @param  record                 [description]百分比记录
     * @param  percentage             [description]百分比
     * @param  updateFlag             [description]是否更新数据
     * @return                        [description]
     */
    public static Map<String, CertificationDetails__c> radiationSendEmailSign(Map<String, CertificationDetails__c> certificationDetailMap, String orderFounder, String model, String record, Decimal percentage, Boolean updateFlag) {
 
        Map<String, CertificationDetails__c> result = new  Map<String, CertificationDetails__c>();
        String olympusAccountId = System.label.Olympus_Id;
 
        CertificationDetails__c  detail = certificationDetailMap.get(model);
        system.debug('detail----->'+detail);
        // 当代理商为"奥林巴斯代理商"时,要给"马喜芝、王冉之"发送邮件
        if (olympusAccountId == detail.CertificationDetailAccount__c) {
            detail.OSHSafeguardOne__c = System.label.OSHSafeguardOne;
            detail.OSHSafeguardTwo__c = System.label.OSHSafeguardTwo;
        } 
        if (percentage >= 1) {
            detail.Ceiling100__c = true;
            detail.Ceiling80__c = true;
            detail.Ceiling90__c = true;
            detail.Record100__c = record + '已达到可售上限,请注意!';
            result.put(model, detail);
        }  else if (percentage >= 0.9) {
            detail.Ceiling80__c = true;
            detail.Ceiling90__c = true;
            detail.Record90__c = record + '已超过可售上限的90%,请注意!';
            result.put(model, detail);
        } else {
 
            if (percentage >= 0.8 && !detail.Ceiling90__c) {
                detail.Ceiling80__c = true;
 
                detail.Record80__c = record + '已超过可售上限的80%,请注意!';
                result.put(model, detail);
            }
        }
        return result;
 
    }
    /**
     * [GetAccountCertificationDetail description]查找代理商的的证照明细
     * @param  accountId [description]代理商Id
     * @return           [description]
     */
    public static Map<String, CertificationDetails__c> GetAccountCertificationDetail (String accountId) {
        Map<String, CertificationDetails__c> result = new Map<String, CertificationDetails__c>();
        List<CertificationDetails__c> certificationDetailsList = [ select Id, Name, ProdustionType__c, 
                                    ProductModelNumber__c, Ceiling80__c, Record80__c, Ceiling90__c, Record90__c , 
                                    CertificationDetailAccount__c, CertificationDetailAccountName__c,
                                    LicenseInformation__r.IfQuantityCtrl__c,AccountRecordType__c,Record100__c,
                                    Ceiling100__c
                                    from CertificationDetails__c 
                                    where CertificationDetailAccount__c = :accountId  
                                        and ActivitieTypes__c = '销售' and IsActive__c = true];
 
        for  (CertificationDetails__c detail : certificationDetailsList) {
            result.put(detail.ProdustionType__c, detail);
        }
 
 
        return result;
 
 
    }
    /**
     * [insertPurchaseDetail description]为代理商的代理商购买明细赋值
     * @param  modelQuantityMap         [description]代理商销售明细
     * @param  id                       [description]代理商Id
     * @param  productModel             [description]产品辐射类型
     * @param  radiationTypeQuantityMap [description]新增的类型及对应的数量
     * @return                          [description]
     */
    public static Map<String, PurchaseDetails__c> insertPurchaseDetail(Map<String, PurchaseDetails__c> modelQuantityMap,
            String id, String productModel, Map<String, Integer> radiationTypeQuantityMap) {
        
        Map<String, CertificationDetails__c>  certificationDetailMap = GetAccountCertificationDetail(id);
        String effectiveYear = String.valueOf(Date.today().year());
       
        PurchaseDetails__c purchaseDetail = new PurchaseDetails__c();
        purchaseDetail.SoldNumber__c = radiationTypeQuantityMap.get(productModel);
        purchaseDetail.PurProductModel__c = productModel;
        purchaseDetail.PurchaseAccount__c = id;
        purchaseDetail.TakeEffectInYear__c = effectiveYear;
 
        for (String model:certificationDetailMap.keySet()) {
            if ('Delta和Vanta'.equals(model)) {
 
                List<String> childModels = new List<String> {'Delta', 'Vanta'};
                for (String childModel : childModels) {
                    if (childModel.equals(productModel)) {
                        purchaseDetail.PurchaseDetail__c = certificationDetailMap.get(model).Id;    
                    }
                }
 
            } else {
                purchaseDetail.PurchaseDetail__c = certificationDetailMap.get(productModel).Id;
            }
        }
        // purchaseDetail.PurchaseDetail__c = certificationDetailMap.get(productModel).Id;            
        modelQuantityMap.put(productModel, purchaseDetail);
        return modelQuantityMap;
    }
 
    /**
     * 代理商购买明细操作详情
     * @Author   XHL
     * @DateTime 2020-02-22
     * @param    accountId     [description]代理商Id
     * @param    radiationType [description]辐射产品系列
     * @param    operationType [description]操作类型
     * @param    orderId       [description]合同Id
     * @param    quantity      [description]变更数量
     * @param    operator      [description]操作人
     * @return                 [description]
     */
    public static Map<String, ChangedReport__c>  upsertChangedReport(String accountId, String radiationType, String operationType, String orderId, Integer quantity, String operator) {
        
        Map<String, ChangedReport__c> result = new Map<String, ChangedReport__c>();
        String key = accountId + radiationType;
        ChangedReport__c  changedReport = new ChangedReport__c();
        changedReport.ChangedReportOrder__c = orderId;
        changedReport.RadiationType__c = radiationType;
        changedReport.OperationType__c = operationType;
        changedReport.Operator__c = operator;
        changedReport.ChangeQuantity__c = quantity;
 
        result.put(key, changedReport);
 
        return result;
 
    }
    /**
     * [GetPurchaseDetailsMap description]获取客户的代理商购买明细的数据
     * @param  accountId [description]代理商Id
     * @return           [description]
     */
    public static Map<String, PurchaseDetails__c> GetPurchaseDetailsMap( String accountId) {
        String effectiveYear = String.valueOf(Date.today().year());
        Map<String, PurchaseDetails__c> result = new Map<String, PurchaseDetails__c>();
        List<PurchaseDetails__c> purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
                                 PurProductModel__c, PurchaseAccount__c
                                 from PurchaseDetails__c
                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId];
        if (purchaseDetailsList.size() > 0) {
            for (PurchaseDetails__c purchaseDetail : purchaseDetailsList) {
                result.put(purchaseDetail.PurProductModel__c, purchaseDetail);
            }
        }
 
        return  result;
    }
 
    /**
     * [GetModelQuantityMap description]汇总辐射产品的型号和数量
     * @param  Id [description]合同Id
     * @return    [description]
     */
    public static  Map<String, Integer> GetModelQuantityMap(String Id) {
        Map<String, Integer> result = new Map<String, Integer>();
        List<OrderItem> orderItemList = [select Id, PriceBookEntry.Product2.If_Radiation_Product__c,
                                         PriceBookEntry.Product2.RadiationType__c, PriceBookEntry.Product2.If_Exempt_Product__c, Quantity, Order.Opportunity.Dealer__c
                                         from OrderItem
                                         where OrderId = :Id
                                                 order by QuoteLineItemId, Id];
        if ( orderItemList.size() > 0) {
 
            for ( OrderItem orderItem : orderItemList) {
                Boolean radiationFlag = orderItem.PriceBookEntry.Product2.If_Radiation_Product__c;
                Boolean exemptFlag = orderItem.PriceBookEntry.Product2.If_Exempt_Product__c;
                if ( radiationFlag && !exemptFlag) {
                    String radiationType = orderItem.PriceBookEntry.Product2.RadiationType__c;
                    Integer quantity  = Integer.valueOf(orderItem.Quantity);
                    if ( result.containsKey(radiationType)) {
                        Integer num = result.get(radiationType) + quantity;
                        result.put(radiationType, num);
                    } else {
                        result.put(radiationType, quantity);
                    }
                }
 
            }
        }
 
        return result;
    }
 
    public static  Map<String, Integer> GetOpportunityLineMap(String Id) {
        Map<String, Integer> result = new Map<String, Integer>();
        List<OpportunityLineItem> oppItemList = [select Id, PriceBookEntry.Product2.If_Radiation_Product__c,
                                  PriceBookEntry.Product2.RadiationType__c, PriceBookEntry.Product2.If_Exempt_Product__c, Quantity, Opportunity.Dealer__c
                                  from OpportunityLineItem
                                  where OpportunityId = :Id
                                          order by Id];
        if ( oppItemList.size() > 0) {
 
            for ( OpportunityLineItem oppItem : oppItemList) {
                Boolean radiationFlag = oppItem.PriceBookEntry.Product2.If_Radiation_Product__c;
                Boolean exemptFlag = oppItem.PriceBookEntry.Product2.If_Exempt_Product__c;
                if ( radiationFlag && !exemptFlag) {
                    String radiationType = oppItem.PriceBookEntry.Product2.RadiationType__c;
                    Integer quantity  = Integer.valueOf(oppItem.Quantity);
                    if ( result.containsKey(radiationType)) {
                        Integer num = result.get(radiationType) + quantity;
                        result.put(radiationType, num);
                    } else {
                        result.put(radiationType, quantity);
                    }
                }
 
            }
        }
 
        return result;
    }
 
    /**
     * 检查代理商能否可以卖某些辐射产品
     * @param  accountId [description]
     * @param  dataMap   [description]
     * @return           [description]
     */
    public static String GetCertificationDetail (String accountId, Map<String, Decimal> dataMap) {
        Map<String, CertificationDetails__c> certificationDetailMap = GetAccountCertificationDetail(accountId);
        System.debug(certificationDetailMap);
        String record = '';
        String errorMessage = '';
        if (certificationDetailMap.size() > 0 && certificationDetailMap != null ) {
 
            for (String temp : dataMap.keySet()) {
                if (certificationDetailMap.containsKey(temp)) {
 
                } else {
                    if (certificationDetailMap.containsKey('Delta和Vanta')) {
                        List<String> childModels = new List<String> {'Delta', 'Vanta'};
                        if (childModels.contains(temp)) {
 
                        } else {
                            errorMessage = '你不能' + temp + '系列产品' + certificationDetailMap.keySet();
                            return errorMessage;
                        }
                    } else {
                        errorMessage = '你不能' + temp + '系列产品' + certificationDetailMap.keySet();
                        return errorMessage;
 
                    }
 
                }
            }
        }
        return errorMessage;
 
    }
    
}