binxie
2023-06-26 b5c5eb130ca0848124f9d136af4be142ad5aac07
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
public without sharing class LexArriveGoodsMainController {
    /*****************検索用******************/
    //经销商产品分类
    public static String agencyProType {get;set;}
    // public static Consumable_order__c coc { get; set; }
    public static String category1 { get; set; }
    private static String cate1ForSort = null;
    private static Date cate2ForSort = Date.today();
    private static Date cate2 = Date.today();
    private static String[] columus = new String[]{ 'Product2__c.Name'};
    // 产品 ID
    private static String ESetId = '';
    private static String accountid = null;
    // 订单 字段标签
    public static List<String> title { get; private set; }
    // 订单 字段名
    public static List<String> column;
    public static List<List<String>> columns { get; private set; }
    // 画面显示数据
    public static List<Consumable_order__c> raesList { get; private set; }
    // 登录者工作地
    private static String userWorkLocation;
    // 20200904 ljh  汇总使用 start
    public static Integer Total_num {get; set;}
    public static Integer OrderNumber_arrived {get; set;}
    public static Integer Delivery_detail_count {get; set;}
    public static Integer OrderNumber_notarrive {get; set;}
    public static Integer More_than_seven_days {get; set;}
 
    @AuraEnabled
    public static Results init(){
        Results results = new Results();
        results.isNoteStay = LexUtility.getIsNoteStay();
        try {
            // coc = new Consumable_order__c();
            String userId = UserInfo.getUserId();
            List<user> Useracc = New List<user>();
            Useracc = [select accountid, Work_Location__c,UserPro_Type__c from user where id =:userId];
            accountid = Useracc[0].accountid;
            userWorkLocation = Useracc[0].Work_Location__c;
            agencyProType = Useracc[0].UserPro_Type__c;
            if(String.isBlank(Useracc[0].UserPro_Type__c)){
                agencyProType = 'ET';
            }
            // 获得订单一览
            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('\\.'));
            }
            // 获得显示数据
            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 Order_ProType__c =\'' + agencyProType +'\' and   (OrderNumber_notarrive__c > 0 or Delivery_detail_count__c >0) and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' and showFalseNotshowTrue__c = false order by Deliver_date__c'; //
            // soql = 'select id,name,ContractNo__c,Total_num__c,OrderNumber_arrived__c,Delivery_detail_count__c,OrderNumber_notarrive__c,More_than_seven_days__c,Shipment_date__c,First_Delivery__c from Consumable_order__c where id in :idList';
            raesList = Database.query(soql);
            //20200904 ljh add start
            Total_num = 0;
            OrderNumber_arrived = 0;
            Delivery_detail_count = 0;
            OrderNumber_notarrive = 0;
            More_than_seven_days = 0;
            System.debug('-----1------'+raesList);
            for(Consumable_order__c conorder :raesList){
                if(conorder.Total_num__c != null){
                    Total_num += (Integer)conorder.Total_num__c;
                }
                if(conorder.OrderNumber_arrived__c != null){
                    OrderNumber_arrived += (Integer)conorder.OrderNumber_arrived__c;
                }
                if(conorder.Delivery_detail_count__c != null){
                    Delivery_detail_count += (Integer)conorder.Delivery_detail_count__c;
                }
                if(conorder.OrderNumber_notarrive__c != null){
                    OrderNumber_notarrive += (Integer)conorder.OrderNumber_notarrive__c;
                }
                if(conorder.More_than_seven_days__c != null){
                    More_than_seven_days += (Integer)conorder.More_than_seven_days__c;
                }
            }
            results.agencyProType = agencyProType;
            results.accountId = accountid;
            results.title = title;
            results.raesList = raesList;
            results.userWorkLocation = userWorkLocation;
            results.totalNum = Total_num;
            results.orderNumberArrived = OrderNumber_arrived;
            results.deliveryDetailCount = Delivery_detail_count;
            results.orderNumberNotarrive = OrderNumber_notarrive;
            results.moreThanSevenDays = More_than_seven_days;
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    @AuraEnabled
    public static Results searchConsumableorderdetails(String category1Str, Date cate2Str, String accountidStr, String userWorkLocationStr, String agencyProTypeStr){
        Results results = new Results();
        category1 = category1Str;
        cate2 = cate2Str;
        accountid = accountidStr;
        userWorkLocation = userWorkLocationStr;
        agencyProType = agencyProTypeStr;
        try {
            // cate2 = coc.Shipment_date__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('\\.'));
            }
            // 获得显示数据
            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  (OrderNumber_notarrive__c > 0 or Delivery_detail_count__c >0) ';
            soql += 'and Order_Owner_WorkLocal__c = \'' + userWorkLocation + '\' ';
            soql += 'and showFalseNotshowTrue__c = false';
            if (!String.isBlank(category1)) {
                soql += ' and Name like \'%' + String.escapeSingleQuotes(category1.replaceAll('%', '\\%')) + '%\' ';
            }
            if(cate2 != null){
                soql += ' and Shipment_date__c = :cate2 ';
            }
            soql += '  and Order_ProType__c =\'' + agencyProType +'\'';
            soql += ' order by Deliver_date__c';
            system.debug('====soql:' + soql);
            raesList = Database.query(soql);
            results.raesList = raesList;
            results.result = 'Success';
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    public class Results {
        @AuraEnabled
        public String result;
        @AuraEnabled
        public String errorMsg;
        @AuraEnabled
        public String agencyProType;
        @AuraEnabled
        public String category1;
        @AuraEnabled
        public Date cate2;
        @AuraEnabled
        public String eSetId;
        @AuraEnabled
        public String accountId;
        @AuraEnabled
        public List<String> title;
        @AuraEnabled
        public List<Consumable_order__c> raesList;
        @AuraEnabled
        public String userWorkLocation;
        @AuraEnabled
        public Integer totalNum;
        @AuraEnabled
        public Integer orderNumberArrived;
        @AuraEnabled
        public Integer deliveryDetailCount;
        @AuraEnabled
        public Integer orderNumberNotarrive;
        @AuraEnabled
        public Integer moreThanSevenDays;
        @AuraEnabled
        public Boolean isNoteStay;
    }
}