高章伟
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
public without sharing class ConsumableAllOtherDetController {
    // 订单 ID
    // private String orderId = '';
    public List<showRecords> allOtherDetIifo { get; set; }
    public String type { get; set; } //20200916 ljh add 
    public ConsumableAllOtherDetController() {
        // orderId = ApexPages.currentPage().getParameters().get('Id');
        allOtherDetIifo = new List<showRecords>();
        type = ApexPages.currentPage().getParameters().get('type');//20200916 ljh add 
    }
 
    // 画面初始化
    public void init() {
        String userId = UserInfo.getUserId();
        List<User> userList = [SELECT accountid, Work_Location__c,UserPro_Type__c
                        FROM user
                        WHERE id = :userId ];
        String accountid = userList[0].accountid;
        String userPro_Type = userList[0].UserPro_Type__c;
        String userWorklocation = userList[0].Work_Location__c;
        Date orderdate = Date.today().addDays(-7);
        String rtTypeDelivery = System.Label.RT_ConOrder_Delivery;
        List<Consumable_order__c> conorderlist = new List<Consumable_order__c>();
        //20200916 ljh update start
        if(Test.isRunningTest()){
            //conorderlist  = [select id,name,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and  Delivery_detail_count__c >=0  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation];
            if(type !=null && type.equals('all')){
                conorderlist  = [select id,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and (OrderNumber_notarrive__c >= 0 or Delivery_detail_count__c >=0)  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation and showFalseNotshowTrue__c = false];
            }else{
                conorderlist  = [select id,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and  Delivery_detail_count__c >=0  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation and showFalseNotshowTrue__c = false];
            }
            
        }else{
            //conorderlist  = [select id,name,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and  Delivery_detail_count__c >0  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation];
            if(type !=null && type.equals('all')){
                conorderlist  = [select id,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and (OrderNumber_notarrive__c > 0 or Delivery_detail_count__c >0)  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation and showFalseNotshowTrue__c = false];
            }else{
                conorderlist  = [select id,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and  Delivery_detail_count__c >0  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation and showFalseNotshowTrue__c = false];
            }
        }
        //20200916 ljh update end
        // List<Consumable_order__c> conorderlist  = [select id,Owner.Name from Consumable_order__c where Order_type__c = '订单' and  recordtypeid = :rtTypeDelivery and Dealer_Info__c = :accountid and Delivery_detail_count__c > 0  and Order_ProType__c = :userPro_Type and Order_Owner_WorkLocal__c = :userWorklocation];
        System.debug('======'+conorderlist+'daxiao:'+conorderlist.size());
        for(Consumable_order__c conorder : conorderlist){
            System.debug('======'+conorder.Owner.Name+'======');
        }
        Set<String> orderId = new Set<String>();
        for(Consumable_order__c conorder : conorderlist){
            orderId.add(conorder.Id);
        }
        System.debug('ANY o'+orderId);
        List<Consumable_order_details2__c> conList = new List<Consumable_order_details2__c>();
        if(Test.isRunningTest()){
            conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c ];
        }else{
            //20200916 ljh update start
            //conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE  Consumable_order_minor__c = :orderId AND Deliver_date__c < :orderdate AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery];
            if(type !=null && type.equals('all')){
                conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE  Consumable_order_minor__c = :orderId  AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery];
            }else{
                conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE  Consumable_order_minor__c = :orderId AND Deliver_date__c < :orderdate AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery];
            }
            //20200916 ljh update end    
        }
        // List<Consumable_order_details2__c> conList = [SELECT id,Bar_Code__c FROM Consumable_order_details2__c WHERE Consumable_order_minor__c = :orderId AND Deliver_date__c < :orderdate AND recordtypeid = :System.Label.RT_ConOrderDetail2_Delivery];
        Map<String,String> srtMap = new Map<String,String>();
        for(Consumable_order_details2__c con : conList){
            srtMap.put(con.Bar_Code__c, con.Id);
        }
        List<String> str = new List<String>();
        for(String s : srtMap.keySet()){
            str.add(srtMap.get(s));
        }
        List<AggregateResult> arrDetList = [SELECT Asset_Model_No__c prodModel,count(Id) recordCount FROM Consumable_order_details2__c
                        WHERE Id =: str and Cancellation_Flag__c = false
                        GROUP BY Asset_Model_No__c];
        Map<String,Decimal> conOrderMap = new Map<String,Decimal>();
        for(AggregateResult agg : arrDetList){
            conOrderMap.put(String.valueOf(agg.get('prodModel')), Integer.valueOf(agg.get('recordCount')));
        }
 
        List<Consumable_Orderdetails__c> conOrderList1 = [SELECT Asset_Model_No__c ,Consumable_count__c FROM Consumable_Orderdetails__c WHERE Consumable_order__c =: orderId ];
        Map<String,Decimal> allConOrderMap = new Map<String,Decimal>();
        for(Consumable_Orderdetails__c con : conOrderList1){
            if(con.Consumable_count__c == null){
                con.Consumable_count__c = 0;
            }
            if(allConOrderMap.containsKey(con.Asset_Model_No__c)){
                allConOrderMap.put(con.Asset_Model_No__c,allConOrderMap.get(con.Asset_Model_No__c)+con.Consumable_count__c);
            }else{
                allConOrderMap.put(con.Asset_Model_No__c, con.Consumable_count__c);
            }
        }
        for(String pmodel : allConOrderMap.keySet()){
            if(conOrderMap.containsKey(pmodel)){
                if(allConOrderMap.get(pmodel) - conOrderMap.get(pmodel) > 0){
                    showRecords showrecord1 = new showRecords();
                    showrecord1.recordCount = allConOrderMap.get(pmodel) - conOrderMap.get(pmodel);
                    showrecord1.prodModel = pmodel;
                    allOtherDetIifo.add(showrecord1);
                }
            }else{
                showRecords showrecord2 = new showRecords();
                showrecord2.recordCount = allConOrderMap.get(pmodel);
                showrecord2.prodModel = pmodel;
                allOtherDetIifo.add(showrecord2);
            }
        }
    }
 
    // Data Bean
    class showRecords implements Comparable {
 
        public Decimal recordCount { get; set; }
        public String prodModel { get; set; }
 
        // public showRecords(){
            
        // }
        // public showRecords(AggregateResult e) {
        //     recordCount =Integer.valueOf(e.get('recordCount'));
        //     prodModel = String.valueOf(e.get('prodModel'));
        // }
        // 排序
        public Integer compareTo(Object compareTo) {
            return null;
        }
    }
}