高章伟
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
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
public without sharing class TopPageController {
    //经销商信息
    public account accountInfo { get; set; }
    /*****************画面表示Bean******************/
    public List<ConsumableorderdetailsInfo> consumableorderdetailsRecords =new List<ConsumableorderdetailsInfo>();
    public List<List<ConsumableorderdetailsInfo>> consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
 
    //page
    Public Integer pagesize{get; set;} 
    Public Integer totalcount{get; set;} 
    Public Integer pagecount{get; set;} 
    Public Integer currentpage{get; set;} 
    public Boolean hasPrevious{get; set;}
    public Boolean hasNext{get; set;}
    public List<ConsumableorderdetailsInfo> pageRecords { get; set; }
    public String soql {get;set;}
    
 
    // update start by vivek2020-01-15 汇总使用
    public Integer Total_num {get; set;}
    public Integer OrderNumber_arrived {get; set;}
    public Integer Delivery_detail_count {get; set;}
    public Integer OrderNumber_notarrive {get; set;}
    public Integer More_than_seven_days {get; set;}
    // update end by vivek2020-01-15 
 
    //排序使用
    public String sortKey { get; set; }
    public String preSortKey { get; private set; }
    public Boolean sortOrderAsc { get; private set; }
    public String[] sortOrder { get; private set; }
    /*****************一周未到货订单一览对应start******************/
    // 订单 字段标签
    public List<String> title { get; private set; }
    // 订单 字段名
    public List<String> column;
    public List<List<String>> columns { get; private set; }
    // 画面显示数据
    public List<Consumable_order__c> raesList { get; private set; }
    /*****************一周未到货订单一览对应end******************/
    //排序使用
    private String[] orderby = new String[]{ 'Product2__c.Name__c'};
    //产品上下限
    String[] proLimitAndDate =new String[]{};
    public String product_Limit { get; set; }
    //库存产品最早有效期限
    private Map<String,Date> productkucun = new Map<String,Date>();
    //消费期限小于一年的产品
    public List<ConsumableorderdetailsInfo> overlimitdateorderdetails { get; set; }
 
    public String accountid { get; set; }
    public String accountName { get; set; }
    List<String> orderDetZaikuList = new List<String>();
 
    // 登录者工作地
    private String userWorkLocation;
 
    // 未到货订单信息(超过一周)显示控制
    //public Boolean over_view { get; set; }
    public Boolean over_view {
        get {
            return raesList.size() > 0 ? true : false;
        }
    }
 
    // 使用期限小于一年的产品 显示控制
    public Boolean overlimit {
        get {
            return overlimitdateorderdetails.size() > 0 ? true : false;
        }
    }
    //--------AddStart-----XHL--------------20180929-------------
    //用户产品区分
    public String userPro_Type {get; set;}
    public String userPro_Typestr = null;
    public Boolean EngFlag = false;
    public Boolean ETFlag = false;
    //--------AddEnd-----XHL--------------20180929-------------
 
    //add by rentx start
    public Boolean hasHos{get;set;}
    //add by rentx end
 
    public TopPageController() {
        //over_view = false;
        consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        consumableorderdetailsRecordsview = new List<List<ConsumableorderdetailsInfo>>();
        overlimitdateorderdetails = new List<ConsumableorderdetailsInfo>();
 
        //page
        pagesize = Integer.valueof(system.label.orderdetLimitsize);
        currentpage = 0;
    }
 
    // 画面初始化
    public void init() {
        User useracc = [SELECT accountid, Work_Location__c,UserPro_Type__c
                        FROM user
                        WHERE id =:UserInfo.getUserId()];
        accountid = useracc.accountid;
        userWorkLocation = useracc.Work_Location__c;
        //--------AddStart-----XHL--------------20180929-------------
        userPro_Type = useracc.UserPro_Type__c;
        if(String.isBlank(userPro_Type)){
            userPro_Type = 'ET';
        }
        userPro_Typestr = '%' + userPro_Type + '%';
        if(userPro_Type == 'ENG'){
            EngFlag = true;
        }else{
            ETFlag = true;
        }
        //--------AddEnd-----XHL--------------20180929-------------
        //经销商·基本信息获取
        accountInfo = [SELECT Name,Ban_On_Use_Reason__c,Deposit_Price__c,
                        Medical_Equipment_Num__c,Medical_Equipment_Expiration_Date__c,
                        Ban_On_Use_Date__c,Tax_Practice_No__c,Tax_Practice_Expiration_Date__c,
                        Business_Authorization_No__c,Business_Paper_Expiration_Date__c,
                        Credit_Check_No__c,Dealer_discount__c,
                        Phone,Address_Together__c,Is_Active_Formula__c,
                        Management_Code__c,Sales_Shop_Class__c,Postal_Code__c,
                        Fax,Address__c,Deposit_Receipt_Finished__c,
                        Deposit_Receipt_Completion_Day__c,
                        Product_Limit_Date__c,
                        Product_Limit_DateENG__c
                        FROM account WHERE id =:accountid];
        accountName = accountInfo.Name;
        //--------UpdateStart-----XHL--------------20181008-------------
        if(EngFlag){
           product_Limit = accountInfo.Product_Limit_DateENG__c;    
        }else if(ETFlag){
           product_Limit = accountInfo.Product_Limit_Date__c;
        }
        //--------UpdateEnd-----XHL--------------20181008-------------
        if(product_Limit != null && product_Limit !=''){
            proLimitAndDate = product_Limit.split(',');
        }
 
        List<ConsumableorderdetailsInfo> boxRecords = new List<ConsumableorderdetailsInfo>();
        //库存明细取得
        orderDetZaikuList = new List<String>();
        List<AggregateResult>  orderDetZaiku = [SELECT count(Id),
                                                      Consumable_Product__c
                                                FROM Consumable_order_details2__c
                                                WHERE Dealer_Arrive__c = true
                                                AND Dealer_Shipment__c = false
                                                AND Dealer_Saled__c = false
                                                AND Lose_Flag__c = false
                                                AND Dealer_Returned__c = false
                                                AND Cancellation_Flag__c = false
                                                AND Bar_Code__c !=null
                                                AND Product_Type__c like : userPro_Typestr
                                                AND Dealer_Info_text__c = :accountName
                                                AND Arrive_Owner_Work_Location__c = :userWorkLocation
                                                group by Consumable_Product__c];
        for(AggregateResult zaikuId : orderDetZaiku){
            orderDetZaikuList.add(String.valueOf(zaikuId.get('Consumable_Product__c')));
        }
        Map<String,Product2__c> MidMap = new Map<String,Product2__c>();
        List<Product2__c> product2Selected = [SELECT Id, Name,
                                Name__c,
                                Asset_Model_No__c,
                                Category3__c,
                                Category4__c,
                                Category5__c,
                                SFDA_Status__c,
                                Product2__r.SFDA_Approbation_No__c,
                                Product2__r.SFDA_Expiration_Date__c,
                                Product2__r.Packing_list_manual__c
                            FROM Product2__c
                            WHERE Id in :orderDetZaikuList
                            ];
 
        for (Integer i = 0; i < product2Selected.size(); i++) {
            MidMap.put(product2Selected[i].Id, product2Selected[i]);
        }
        //返品库存统计
        List<Consumable_order_details2__c> CountDel = [SELECT Id,
                            Bar_Code__c,
                            Name,
                            Inventory_date__c,
                            Consumable_Product__c,
                            Recordtypeid,
                            Guarantee_period_for_products__c,
                            Isoverdue__c,
                            Box_Piece__c,
                            hospitalSpecialOffer__c 
                        FROM Consumable_order_details2__c
                        WHERE  Dealer_Arrive__c = true
                        AND Dealer_Shipment__c = false
                        AND Dealer_Saled__c = false
                        AND Dealer_Returned__c = false
                        AND Lose_Flag__c = false
                        AND Cancellation_Flag__c = false
                        AND Bar_Code__c !=null
                        AND Product_Type__c like : userPro_Typestr
                        AND Dealer_Info_text__c = :accountName
                        AND Arrive_Owner_Work_Location__c = :userWorkLocation];
                        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'CountDel +++++' + CountDel.size())); 
        Map<String,ConsumableorderdetailsInfo> newMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newHosMidBoxMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newHosMidPieceMap = new Map<String,ConsumableorderdetailsInfo>();
 
        for(Integer i = 0 ; i< CountDel.size();i++){
            //然后循环CountDel做Box和piece2个map
            /*if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒'){
 
                if(newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c)){
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c, Jstage);
                }else{
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c, Jstage);
                }
            }else if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个'){
                if(newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c)){
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c, Jstage);
                }else{
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c, Jstage);
                }
            }*/
            if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '盒'){
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
                if(newMidBoxMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex)){
                    ConsumableorderdetailsInfo Jstage = newMidBoxMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                        newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                    }else{
                        Jstage.hospitalSpecialOffer = false;
                        newMidBoxMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
 
                    }
                }
 
            }else if(MidMap.containsKey(CountDel[i].Consumable_Product__c) && CountDel[i].Box_Piece__c == '个'){
                String tex = 'A';
                if (CountDel[i].hospitalSpecialOffer__c) {
                    tex = 'B';
                }
 
                if(newMidPieceMap.containsKey(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c+ tex )){
                    ConsumableorderdetailsInfo Jstage = newMidPieceMap.get(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c+ tex).clone();
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c + tex, Jstage);
                }else{
                    ConsumableorderdetailsInfo Jstage = new ConsumableorderdetailsInfo(MidMap.get(CountDel[i].Consumable_Product__c));
                    Jstage.allnumber = Jstage.allnumber+1 ;
                    if(CountDel[i].Isoverdue__c == 1){
                        Jstage.limitCount = Jstage.limitCount + 1;
                    }
                    Jstage.BoxPiece = CountDel[i].Box_Piece__c;
                    if (CountDel[i].hospitalSpecialOffer__c) {
                        Jstage.hospitalSpecialOffer = true;
                        newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c+ tex, Jstage);
                    }else{
                        Jstage.hospitalSpecialOffer = false;
                        newMidPieceMap.put(CountDel[i].Consumable_Product__c+CountDel[i].Box_Piece__c+ tex, Jstage);
 
                    }
                }
            }
 
 
            
            //如果是 医院特价创建的明细2  则   update and add by rentx 2020-11-26 end
 
        }
        consumableorderdetailsRecords = new List<ConsumableorderdetailsInfo>();
        List<ConsumableorderdetailsInfo> newHosMidBoxList = new List<ConsumableorderdetailsInfo>();
        //把Boxmap里的值从新赋给boxRecords
        for(ConsumableorderdetailsInfo bss : newMidBoxMap.values()){
            if(bss.allnumber>0){
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                bss.overlimitCount = bss.allnumber - bss.limitCount;
                boxRecords.add(bss);
            }
        }
        boxRecords.sort();
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if(bss.allnumber>0){
                bss.packing_list = Integer.valueof(bss.Prod.Product2__r.Packing_list_manual__c);
                bss.approbation_No = bss.Prod.Product2__r.SFDA_Approbation_No__c;
                bss.expiration_Date = bss.Prod.Product2__r.SFDA_Expiration_Date__c;
                bss.overlimitCount = bss.allnumber - bss.limitCount;
            }
        }
        //===========================================add by rentx 2020-11-26 start 
        
 
        //========================================add by rentx 2020-11-26  end
 
        //排序应该是 非医院特价的盒,医院特价的盒,非医院特价的个,医院特价的个
        
        //add by rentx 2020-11-27 先判断医院特价的盒 和 个
        //2020-11-27 日 于 rentx 注释 start
        String temp = 'A';
        for(ConsumableorderdetailsInfo bss : boxRecords){
            consumableorderdetailsRecords.add(bss);
            //该产品是医院特价产品
            if (bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
                if (newMidPieceMap.get(bss.Prod.Id+'个B').hospitalSpecialOffer) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个B'));
                    newMidPieceMap.remove(bss.Prod.Id+'个B');
                }
            }
 
            if (!bss.hospitalSpecialOffer && newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
                // if (newMidPieceMap.get(bss.Prod.Id+'个A')) {
                    consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id+'个A'));
                    newMidPieceMap.remove(bss.Prod.Id+'个A');
                // }
            }
        }
 
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个B')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个B'));
            }
        }
        for(ConsumableorderdetailsInfo bss : newMidPieceMap.values()){
            if (newMidPieceMap.containsKey(bss.Prod.Id+'个A')) {
                consumableorderdetailsRecords.add(newMidPieceMap.get(bss.Prod.Id + '个A'));
            }
        }
        // consumableorderdetailsRecords.addAll(newMidPieceMap.values());
        //2020-11-27 日 于 rentx 注释 end
        
        notarriveorder();
        productLimtAndDate();
        datelimitSearch();
        //add by rentx
        Integer ishos = 0;
        for(ConsumableorderdetailsInfo bss : consumableorderdetailsRecords){
            if(productkucun.get(bss.Prod.Id) != null){
                bss.guaranteeperiod = productkucun.get(bss.Prod.Id);
            }
            //add by rentx 2021-3-10 start
            if (bss.hospitalSpecialOffer) {
                ishos = ishos+1;
            }
            
        }
        if (ishos > 0) {
            hasHos = true;
        }else{
            hasHos = false;
        }
        //add by rentx 2021-3-10 end
 
        //consumableorderdetailsRecords.sort();
        //list分割
        //listCut();
        this.sortKey = '0';
        this.preSortKey = '0';
        this.sortOrderAsc = false;
        this.sortOrder = new String[1];
        this.sortOrder = new String[]{' ', '↓'};
 
        //总件数
        totalcount = consumableorderdetailsRecords.size();
        //页数
        pagecount=(totalcount  +  pagesize  - 1) / pagesize; 
        //显示第一页
        moveToFirst();
        makeCurrentPageRecords();
    }
 
    public void datelimitSearch(){
        Set<String> barcodekucun = new Set<String>();
        //--------UpdateStart-----XHL--------------20180929-------------
         List<Consumable_order_details2__c> orderkucun = [SELECT Id,Bar_Code__c, Name,Consumable_Product__c,
                                                        Recordtypeid,Guarantee_period_for_products__c,
                                                        Sterilization_limit__c,Box_Piece__c
                                                        FROM Consumable_order_details2__c
                                                        WHERE Dealer_Arrive__c = true
                                                        AND Dealer_Shipment__c = false
                                                        AND Dealer_Saled__c = false
                                                        AND Dealer_Returned__c = false
                                                        AND Lose_Flag__c = false
                                                        AND Bar_Code__c !=null
                                                        AND Product_Type__c like :userPro_Typestr
                                                        AND Dealer_Info_text__c = :accountName
                                                        AND Arrive_Owner_Work_Location__c = :userWorkLocation
                                                        ORDER BY Consumable_Product__c, Sterilization_limit__c asc ];
        //--------UpdateEnd-----XHL--------------20180929-------------
        for(Integer i = 0 ; i< orderkucun.size();i++){
            if(productkucun.containsKey(orderkucun[i].Consumable_Product__c)){
                continue;
            }else{
                productkucun.put(orderkucun[i].Consumable_Product__c, orderkucun[i].Sterilization_limit__c);
            }
        }
        barcodekucun.clear();
        for(Integer i = 0 ; i< orderkucun.size();i++){
            if(orderkucun[i].Sterilization_limit__c < Date.today().addYears(1)){
                if(barcodekucun.contains(orderkucun[i].Bar_Code__c)){
                    continue;
                }else{
                    barcodekucun.add(orderkucun[i].Bar_Code__c);
                }
            }
        }
        List<AggregateResult>  overlimitdatedetails = [SELECT Asset_Model_No__c prodName ,
                                            Box_Piece__c BoxPiece,count(id) countid
                                        FROM Consumable_order_details2__c
                                        WHERE Bar_Code__c in :barcodekucun
                                        AND Dealer_Arrive__c = true
                                        AND Dealer_Shipment__c = false
                                        AND Dealer_Saled__c = false
                                        AND Dealer_Returned__c = false
                                        AND Lose_Flag__c = false
                                        GROUP BY Asset_Model_No__c,Box_Piece__c
                                        ORDER BY Asset_Model_No__c,Box_Piece__c];
        for(Integer i = 0 ; i< overlimitdatedetails.size();i++){
            overlimitdateorderdetails.add(new ConsumableorderdetailsInfo(overlimitdatedetails[i]));
        }
    }
 
    //超过一周未到货订单
    public void notarriveorder (){
        //over_view = false;
        Date orderdate = Date.today().addDays(-7);
        
        List<Consumable_order_details2__c> orderdetails = [SELECT Id,Name,Consumable_order_minor__c
                                                            FROM Consumable_order_details2__c
                                                            WHERE Deliver_date__c < :orderdate
                                                            and Consumable_order_minor__c !=null
                                                            and Dealer_Info_text__c = :accountName
                                                            AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery
                                                            AND Dealer_Arrive__c = false
                                                            ];
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO , 'userPro_Type——————' + userPro_Type));
        Map<String, String> notarriveorderMap = new Map<String, String>();
        List<String> notarriveorderid = new List<String>();
        for(Integer i = 0; i < orderdetails.size(); i++){
            if(notarriveorderMap.containsKey(orderdetails[i].Consumable_order_minor__c)){
                continue;
            }else{
                notarriveorderMap.put(orderdetails[i].Consumable_order_minor__c, orderdetails[i].Consumable_order_minor__c);
                //notarriveorderid.add('\'' + orderdetails[i].Consumable_order_minor__c +'\'');
                notarriveorderid.add(orderdetails[i].Consumable_order_minor__c);
            }
        }
        // 获得订单一览
        Map<String, Schema.FieldSet> fsMap = Schema.getGlobalDescribe().get('Consumable_order__c').getDescribe().fieldSets.getMap();
        Schema.FieldSet fs = fsMap.get('arrive_view');
        // 获得订单中的所有项目
        List<FieldSetMember> fsmList = fs.getFields();
        // 获得字段标签和字段名
        title = new List<String>();
        column = new List<String>();
        columns = new List<List<String>>();
        for (FieldSetMember fsm : fsmList) {
            title.add(fsm.getLabel());
            column.add(fsm.getFieldPath());
            columns.add(fsm.getFieldPath().split('\\.'));
        }
        system.debug('columns=====================>'+columns);
        // 获得显示数据
        raesList = new List<Consumable_order__c>();
        String soql = 'select Id';
        for (String s : column) {
            soql += ',' + s;
        }
        soql += ' from Consumable_order__c where Order_type__c = \''+'订单'+'\' and  recordtypeid =\'' + System.Label.RT_ConOrder_Delivery + '\' and Dealer_Info__c =\'' + accountid +'\'  and  Delivery_detail_count__c > 0 and showFalseNotshowTrue__c = false  ';
        soql += ' and Order_ProType__c = \'' + userPro_Type  + '\' ' ;
        soql += ' and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
       
        if(notarriveorderid.size() < 1){
            soql +=' AND Id = null ';
        }else{
            String sqlTail = '(\'';
            for(Integer i = 0 ; i< notarriveorderid.size();i++){
                if(i<notarriveorderid.size()-1){
                    sqlTail += notarriveorderid[i]+'\',\'';
                }else{
                    sqlTail += notarriveorderid[i]+'\')';
                }
            }
            //over_view = true;
            soql +=' AND Id in ' + sqlTail;
        }
        system.debug('soql_____11111__' + soql);
        raesList = Database.query(soql);
        // update end by vivek2020-01-15 
        Total_num = 0;
        OrderNumber_arrived = 0;
        Delivery_detail_count = 0;
        OrderNumber_notarrive = 0;
        More_than_seven_days = 0;
        for(Consumable_order__c conorder :raesList){
            Total_num += (Integer)conorder.Total_num__c;
            OrderNumber_arrived += (Integer)conorder.OrderNumber_arrived__c;
            Delivery_detail_count += (Integer)conorder.Delivery_detail_count__c;
            OrderNumber_notarrive += (Integer)conorder.OrderNumber_notarrive__c;
            More_than_seven_days += (Integer)conorder.More_than_seven_days__c;
        }
        // update end by vivek2020-01-15
    }
 
    public void productLimtAndDate (){
        String nowName = null, nowRightAsstModelNo = null;
        Map<String,String> productLimt = new Map<String,String>();
        for(Integer i = 0; i < proLimitAndDate.size(); i++){
            nowName = proLimitAndDate[i];
            if( nowName.indexOf( '|') >= 0) {
                nowRightAsstModelNo = nowName.subString( 0, nowName.indexOf( '|'));
                nowName = nowName.subString( nowName.indexOf( '|')+1);
            }
            productLimt.put(nowRightAsstModelNo, nowName);
        }
        for(ConsumableorderdetailsInfo ass : consumableorderdetailsRecords){
            if(productLimt.containsKey(ass.Prod.Asset_Model_No__c)){
                ass.lowerlimit = decimal.valueOf(productLimt.get(ass.Prod.Asset_Model_No__c).subString(0, productLimt.get(ass.Prod.Asset_Model_No__c).indexOf( '|')));
                ass.upperlimit = decimal.valueOf(productLimt.get(ass.Prod.Asset_Model_No__c).subString(productLimt.get(ass.Prod.Asset_Model_No__c).indexOf( '|')+1));
           }
        }
    }
 
   //排序
   public void SortLimited(){
        Map<String,ConsumableorderdetailsInfo> MidMap = new Map<String,ConsumableorderdetailsInfo>();
        Map<String,ConsumableorderdetailsInfo> newMap = new Map<String,ConsumableorderdetailsInfo>();
        if (this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        } else {
            this.sortOrderAsc = true;
            this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        }
        String sqlTail = '(\'';
        for(Integer i = 0 ; i< orderDetZaikuList.size();i++){
            if(i<orderDetZaikuList.size()-1){
                sqlTail += orderDetZaikuList[i]+'\',\'';
            }else{
                sqlTail += orderDetZaikuList[i]+'\')';
            }
        }
 
        this.preSortKey = this.sortKey;
        // 所有产品取得
        //共通方法的使用,limit 去掉  71行for 循环 写成共通函数
        String soql = 'select Id, Name,Name__c,Asset_Model_No__c,Category3__c,Category4__c,Category5__c,';
        soql += ' SFDA_Status__c,Product2__r.SFDA_Approbation_No__c,Product2__r.SFDA_Expiration_Date__c,';
        soql += ' Product2__r.Packing_list_manual__c from Product2__c ';
        soql += ' WHERE Id in' + sqlTail;
        soql += ' order by ' + this.orderby[Integer.valueOf(this.sortKey)];
        soql += ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last');
        List<Product2__c> queryList = Database.query(soql);
 
        // 選択済みの明细を取得
        for (Integer i = 0; i < queryList.size(); i++) {
            MidMap.put(queryList[i].Id + '盒', null);
            MidMap.put(queryList[i].Id + '个', null);
        }
        //update by rentx 2020-12-29
        for(Integer i = 0 ; i< pageRecords.size();i++){
            if(MidMap.containsKey(pageRecords[i].prod.Id+pageRecords[i].BoxPiece)){
                ConsumableorderdetailsInfo Jstage = pageRecords[i].clone();
                if (Jstage.hospitalSpecialOffer == true) {
                    newMap.put(pageRecords[i].prod.id+pageRecords[i].BoxPiece, Jstage);
                }else{
                    MidMap.put(pageRecords[i].prod.id+pageRecords[i].BoxPiece, Jstage);
                }
            }
        }
        //update by rentx 2020-12-29
        pageRecords = new List<ConsumableorderdetailsInfo>();
 
        //再把map里的值从新赋给CpageRecords
        for(ConsumableorderdetailsInfo bss : MidMap.values()){
 
            if(bss != null){
                pageRecords.add(bss);
                if (newMap.get(bss.Prod.Id+bss.BoxPiece) != null) {
                    pageRecords.add(newMap.get(bss.Prod.Id+bss.BoxPiece));
                    newMap.remove(bss.Prod.Id+bss.BoxPiece);
                }
            }
        }
        for(ConsumableorderdetailsInfo bss : newMap.values()){
            if (bss != null) {
                pageRecords.add(bss);
            }
        }
 
        /*
        for(ConsumableorderdetailsInfo bss : MidMap.values()){
            if(bss != null){
                pageRecords.add(bss);
           }
        }*/
    }
 
    //首页
    public void moveToFirst(){
        if(currentpage == 1) return;
        currentpage = 1;
        canMove();
        //makeCurrentPageRecords();
    }
 
    //尾页
    public void moveToLast(){
        if(currentpage >= pagecount) return;
        currentpage = pagecount;
        canMove();
        //makeCurrentPageRecords();
    }
 
    //上一页
    public void moveToPrevious(){
        if(currentpage == 1) return;
        currentpage = currentpage -1;
        canMove();
        //makeCurrentPageRecords();
    }
 
    //下一页
    public void moveToNext(){
        if(currentpage >= pagecount) return;
 
        currentpage = currentpage + 1;
        canMove();
        //makeCurrentPageRecords();
    }
 
    //判断是否可翻页
    public void canMove(){
        hasPrevious = false;
        hasNext = false;
        if(pagecount > 1 && currentpage > 1) hasPrevious = true;
        if(pagecount > 1 && currentpage < pagecount)  hasNext = true;
    }
 
 
    //刷新当前页
    public PageReference refreshPageSize() {
        makeCurrentPageRecords();
        return null;
    }
 
    //编辑当前页内容
    public void makeCurrentPageRecords(){
        Integer startIdx;
        Integer endIdx;
 
        pageRecords = new List<ConsumableorderdetailsInfo>();
        startIdx = (currentpage-1) * pagesize;
        endIdx = (currentpage-1) * pagesize+ pagesize;
        if (endIdx > consumableorderdetailsRecords.size()){
            endIdx = consumableorderdetailsRecords.size();
        } 
 
        for(Integer i=startIdx; i < endIdx ; i++){
            pageRecords.add(consumableorderdetailsRecords.get(i));
        }
   }
 
    // Data Bean
    class ConsumableorderdetailsInfo implements Comparable {
        //public Boolean check { get; set; }
        //public Boolean oldCheck { get; set; }
        public Consumable_order_details2__c esd { get; set; }
        public Product2__c Prod { get; set; }
        public Decimal allnumber { get; set; }
        public Decimal oldConsumableCount { get; set; }
        public Integer packing_list { get; set; }
        public Date expiration_Date { get; set; }
        public String approbation_No { get; set; }
        public Decimal upperlimit { get; set; }
        public Decimal lowerlimit { get; set; }
        public Date guaranteeperiod { get; set; }
        public Decimal countid { get; set; }
        public String prodName { get; set; }
        public Decimal limitCount { get; set; }
        public Decimal overlimitCount { get; set; }
        public String BoxPiece { get; set; }
 
        public Boolean hospitalSpecialOffer { get; set ;}
 
        public ConsumableorderdetailsInfo(Product2__c e) {
            //check = false;
            //oldCheck = false;
            esd = new Consumable_order_details2__c();
            Prod = e;
            oldConsumableCount = null;
            allnumber = 0;
            limitCount = 0;
            overlimitCount = 0;
 
        }
 
        public ConsumableorderdetailsInfo(AggregateResult e) {
            countid =Integer.valueOf(e.get('countid'));
            prodName = String.valueOf(e.get('prodname'));
            BoxPiece = String.valueOf(e.get('BoxPiece'));
        }
 
        // 排序
        public Integer compareTo(Object compareTo) {
            ConsumableorderdetailsInfo compareToesd =(ConsumableorderdetailsInfo)compareTo;
            Integer returnValue = 0;
            if (allnumber > compareToesd.allnumber) {
                returnValue = -1;
            } else if (allnumber < compareToesd.allnumber) {
                returnValue = 1;
            }
            return returnValue;
        }
    }
 
}