高章伟
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
public class QueuePageByAssetIdController extends CreateRelationListPagingCtrlBase{
    private Id asId;
 
    private String wher;        // and 4つ条件
 
    private Map<Id, String> queueConmentMap;
 
    //public Asset aset {get;private set;}
    public Rental_Apply_Equipment_Set_Detail__c raesd {get;private set;}
 
    public String modelNo {get;private set;}
    public Boolean isNotShow {get;private set;}
    public Integer inptNum {get; set;}
    public Integer inptNumStr {get; set;}
    public Boolean inputUpDownFlag {get; set;}
 
    public override Boolean getIsNeedRunSearch() {
        return false;
    }
 
    /* 選択されたデータ取得用Soql Fromから*/
    public override String getSelectedDataSql() {
        // オブジェクトAPI名
        selectedDataSql = ' From Rental_Apply_Equipment_Set_Detail__c';
        selectedDataSql += ' where Queue_Number__c > 0 AND Fixture_Model_No_text__c = \'' + modelNo + '\'';
        selectedDataSql += ' AND Cancel_Select__c = false ' + wher;
        selectedDataSql += ' order by Queue_Number__c ASC nulls last';
        // 20220107 ljh update start
        /*Profile profileObj = [SELECT Id, Name FROM Profile WHERE Id =: UserInfo.getProfileId() LIMIT 1];
        // 只有系统管理员,页面上 排队No,排队时间,负责人 字段是显示可编辑状态
        if (profileObj == null || (profileObj != null && !profileObj.Name.contains('系统管理员'))) {
            myComponentController.columnRightRW.put('Queue_Number__c', 'r');
            myComponentController.columnRightRW.put('Queue_Day__c', 'r');
            myComponentController.columnRightRW.put('Queue_User__c', 'r');
        }*/
        // 20220107 ljh update end
        myComponentController.columnRightRW.put('Allow_Adjust_Queue_Flag__c', 'r');
        myComponentController.columnRightRW.put('jumpReason__c', 'r');
        return selectedDataSql;
    }
 
    public override String getOriginObjName() {
        // オブジェクトAPI名
        originObjName = 'Rental_Apply_Equipment_Set_Detail__c';
        return originObjName;
    }
 
    public override String getOriginObjColumns() {
        // 項目セット
        // 20211104 ljh 排队 start
        // originObjColumns =  'Id, Asset__c';
        originObjColumns =  'Id';
        // 20211104 ljh 排队 end
        return originObjColumns;
    }
 
    public override Integer getSearchNumMax() {
        //各ページに制御あれば、最大件数を指定する
        searchNumMax = Integer.valueOf(Label.Product_Select_Limit);
        return searchNumMax;
    }
 
    public override String getObjName() {
        // オブジェクトAPI名
        objName = 'Rental_Apply_Equipment_Set_Detail__c';
        return objName;
    }
 
    // ページコントローラに検索処理は、WhereSoql作成のみ、パラメータとして、コンポーネントに渡される
    public override String getSqlWhereStr() {
        sqlWhereStr = '';
 
        return sqlWhereStr;
    }
 
    public override String getColumnRightFieldSetName() {
        // 右の項目セット
        columnRightFieldSetName = 'QueueByAssetId';
        return columnRightFieldSetName;
    }
 
    public override String getColumnLeftFieldSetName() {
        // 左の項目セット
        columnLeftFieldSetName = '';
        return columnLeftFieldSetName;
    }
 
    public override List<String> getColumnFieldList() {
        // strColumus 里加 field
        return new String[]{'Is_Body_F__c', 'Rental_Apply__c'};
    }
    // 画面里直接可以输入的項目 List
    public override List<String> getWritableColumnFieldList() {
        return new List<String>{'Queue_Conment__c'};
    }
 
    public override String getRecordTypeId() {
        //ページレイアウトを収得するのレコードタイプ
        recordTypeId = '';
        return recordTypeId;
    }
 
    // getObjName 连 getOriginObjName 的 FK
    public override String getFKColumnField() {
        return null;
    }
 
    //public override
    public override void setViewList(List<sObject> queryList) {
        queueConmentMap = new Map<Id, String>();
        viewList = new List<WrapperInfo>();
        for (Integer i = 0; i < selectedData.size(); i++) {
            Rental_Apply_Equipment_Set_Detail__c raesd = (Rental_Apply_Equipment_Set_Detail__c) selectedData[i];
            if (raesd.Is_Body_F__c == false) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'借出备品配套一览明细:' + raesd.Id + ' 不是主体不能排队'));
            }
            WrapperInfo w = new WrapperInfo(raesd, myComponentController);
            w.orderNo = raesd.Queue_Number__c.intValue();
            w.lineNo = i;
            if (w.orderNo != i + 1) {
                w.orderNo = w.lineno + 1;
                w.changeFlg = '1';
            }
            viewList.add(w);
            queueConmentMap.put(raesd.Id, raesd.Queue_Conment__c);
        }
    }
 
    public void saveQueue(){
        Savepoint sp = Database.setSavepoint();
        Boolean isCheckedFlag = false;
        try {
            for (WrapperInfo w : viewList) {
                Rental_Apply_Equipment_Set_Detail__c rae = (Rental_Apply_Equipment_Set_Detail__c) w.sobj;
                if (w.check) {
                    isCheckedFlag = true;
                    if (rae.Is_Body_F__c == false) {
                        inptNumStr = null;
                        throw new ControllerUtil.myException('借出备品配套一览明细:' + rae.Id + ' 不是主体不能排队');
                    }
 
                    // 没有调整队列,只更改排队备注的情况
                    if (!inputUpDownFlag && (inptNum == 0 || inptNum == null)) {
                        List<Rental_Apply_Equipment_Set_Detail__c> raesdObjList = new List<Rental_Apply_Equipment_Set_Detail__c>();
                        Rental_Apply_Equipment_Set_Detail__c raesdObj = new Rental_Apply_Equipment_Set_Detail__c();
                        raesdObj.Id = rae.Id;
                        raesdObj.Queue_Conment__c = rae.Queue_Conment__c;
                        raesdObj.Queue_User__c = UserInfo.getUserId();
                        raesdObjList.add(raesdObj);
                        FixtureUtil.withoutUpdate(raesdObjList);
                    } else {
                        // 调整队列的情况
                        if (!rae.Allow_Adjust_Queue_Flag__c) {
                            inptNumStr = null;
                            throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。');
                        }
 
                        if (inputUpDownFlag && inptNum == 0) {
                            throw new ControllerUtil.myException('错误的【指定排队NO.】:0');
                        } else {
                            Rental_Apply_Equipment_Set_Detail__c raesd = [
                                    SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c
                                    FROM Rental_Apply_Equipment_Set_Detail__c
                                    WHERE Id =: rae.Id
                                      AND Is_Body__c = true
                                      AND Cancel_Select__c = false];
 
                            if (raesd == null) {
                                inptNumStr = null;
                                throw new ControllerUtil.myException('调整的一览明细不存在。');
                            }
 
                            if (inputUpDownFlag && raesd.Queue_Number__c <= inptNum) {
                                throw new ControllerUtil.myException('请使用【指定排队NO.】来向上调整排队No。');
                            }
                            saveQueue(rae, inptNum, inputUpDownFlag, false);
                        }
                    }
                }
            }
 
            inptNumStr = null;
            inputUpDownFlag = false;
            inptNum = null;
 
            myComponentController.getSelectedDataInfo();
            getSqlWhereStr();
            myComponentController.searchAndPaging();
 
            if (isCheckedFlag) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'保存成功'));
            } else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请勾选需要操作的数据'));
            }
        } catch (Exception e) {
            Database.rollback(sp);
            inputUpDownFlag = false;
            inptNum = null;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getmessage()));
        }
    }
 
    public QueuePageByAssetIdController(){
        // 20211104 ljh 排队 start
        // this.asId = ApexPages.currentPage().getParameters().get('asId');
        // this.parentId = asId;
        this.parentId = ApexPages.currentPage().getParameters().get('parentId');
        if (ApexPages.currentPage().getParameters().get('isNotShow') == 'true') {
            this.isNotShow = true;
        } else {
            this.isNotShow = false;
        }
 
        // 20211104 ljh 排队 end
    }
 
    public void init() {
        isNeedSearchFirst = false;
        getSqlWhereStr();
 
        this.wher = '';
        List<Rental_Apply_Equipment_Set_Detail__c> raesdObjs = [
                    SELECT Id, Rental_Apply_Equipment_Set__c, Asset__c,Salesdepartment_before__c,
                           Product_category_text__c,Equipment_Type_text__c,
                           Internal_asset_location_before__c,Fixture_Model_No__c,Fixture_Model_No_F__c
                     FROM Rental_Apply_Equipment_Set_Detail__c
                    WHERE Rental_Apply_Equipment_Set__c = :parentId
                      and Is_Body__c = true
                      and Cancel_Select__c = false];
        if (raesdObjs.isEmpty()) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'备品一览明细不存在。'));
            return;
        }
        raesd = raesdObjs[0];
        this.modelNo = raesd.Fixture_Model_No__c;
        if (String.isNotBlank(raesd.Salesdepartment_before__c)) {
            wher += ' AND Salesdepartment_before__c = \'' + raesd.Salesdepartment_before__c + '\'';
        }
        if (String.isNotBlank(raesd.Product_category_text__c)) {
            wher += ' AND Product_category_text__c = \'' + raesd.Product_category_text__c + '\'';
        }
        if (String.isNotBlank(raesd.Equipment_Type_text__c)) {
            wher += ' AND Equipment_Type_text__c = \'' + raesd.Equipment_Type_text__c + '\'';
        }
        if (String.isNotBlank(raesd.Internal_asset_location_before__c)) {
            wher += ' AND Internal_asset_location_before__c = \'' + raesd.Internal_asset_location_before__c + '\'';
        }
    }
 
    /**
     * 申请单置顶
     * */
    public void upRentalApply() {
        Savepoint sp = Database.setSavepoint();
        Boolean isCheckedFlag = false;
        try {
            for (WrapperInfo w : viewList) {
                Rental_Apply_Equipment_Set_Detail__c rae = (Rental_Apply_Equipment_Set_Detail__c) w.sobj;
                if (w.check) {
                    isCheckedFlag = true;
                    if (!rae.Allow_Adjust_Queue_Flag__c) {
                        inptNumStr = null;
                        throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。');
                    }
 
                    // 只置顶申请单中已排队,且非暂定分配的一览明细
                    List<Rental_Apply_Equipment_Set_Detail__c> raesdObjs = [
                        SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Name
                        FROM Rental_Apply_Equipment_Set_Detail__c
                        WHERE Rental_Apply__c =: rae.Rental_Apply__c
                          AND Is_Body__c = true
                          AND Cancel_Select__c = false
                          AND Queue_Number__c > 0];
                    // 校验申请单中已排队的其余一览明细的状态
                    for(Rental_Apply_Equipment_Set_Detail__c raesd : raesdObjs){           
                        if (!raesd.Allow_Adjust_Queue_Flag__c) {
                            inptNumStr = null;
                            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'一览明细:' + raesd.Name + ' 型号:' + raesd.Fixture_Model_No__c + ' 备品总窗口未申请插队,无法调整顺序,请确认。'));
                            return;
                        }
 
                        //申请单置顶
                        saveQueue(raesd, 1, true, false);
                    }
                }
            }
 
            inptNumStr = null;
            inputUpDownFlag = false;
            inptNum = null;
 
            myComponentController.getSelectedDataInfo();
            getSqlWhereStr();
            myComponentController.searchAndPaging();
 
            if (isCheckedFlag) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'申请单置顶成功'));
            } else {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'请勾选需要操作的数据'));
            }
        } catch (Exception e) {
            Database.rollback(sp);
            inputUpDownFlag = false;
            inptNum = null;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getmessage()));
        }
    }
 
    /**
     * 调整排队的队列顺序
     * @param raesdObj 需要调整的对象
     * @param num 调整到的排队No
     * @param upDownFlag 向上或者向下调整标识 true:向上; false:向下
     * @param isSkip 是否跳过调整顺序校验 true:跳过校验; false:校验
     */
    public void saveQueue(Rental_Apply_Equipment_Set_Detail__c raesdObj, Integer num, Boolean upDownFlag, Boolean isSkip) {
        List<Rental_Apply_Equipment_Set_Detail__c> raes = new List<Rental_Apply_Equipment_Set_Detail__c>();
        Rental_Apply_Equipment_Set_Detail__c raesd = [
                SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c
                FROM Rental_Apply_Equipment_Set_Detail__c
                WHERE Id =: raesdObj.Id
                  AND Is_Body__c = true
                  AND Cancel_Select__c = false
                FOR UPDATE];
        if (raesd == null) {
            inptNumStr = null;
            throw new ControllerUtil.myException('调整的一览明细不存在。');
        }
 
        if (!raesd.Allow_Adjust_Queue_Flag__c && !isSkip) {
            inptNumStr = null;
            throw new ControllerUtil.myException('一览明细:' + raesd.Name + ' 型号:' + raesd.Fixture_Model_No__c + ' 备品总窗口未申请插队,无法调整顺序,请确认。');
        }
        if (upDownFlag && raesd.Queue_Number__c == num) {
            return;
        }
        
        List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [
                SELECT Id, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c
                FROM Rental_Apply_Equipment_Set_Detail__c
                WHERE Queue_Number__c > 0
                  AND Cancel_Select__c = false
                  AND ExternalKey__c =: raesd.ExternalKey__c
                ORDER BY Queue_Number__c ASC nulls last];
 
        // 先调整队列顺序,后再调整序列顺序
        // upDownFlag true:向上调整、置顶  false:置底
        // 需要按照页面段的检索条件,取出队列一览,来做调整队列时的比较
        Integer orderNo = 1;
        for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) {
            // 向上调整、置顶
            if (upDownFlag) {
                if (orderNo >= num && orderNo < raesd.Queue_Number__c) {
                    rae.Queue_Number__c = orderNo + 1;
                    rae.Queue_User__c = UserInfo.getUserId();
                    raes.add(rae);
                }
            } else {
                // 置底
                if (orderNo > raesd.Queue_Number__c) {
                    rae.Queue_Number__c = orderNo - 1;
                    rae.Queue_User__c = UserInfo.getUserId();
                    raes.add(rae);
                }
            }
            orderNo++;
        }
 
        if (upDownFlag) {
            // 置顶或者向上,需要传调整Num
            raesdObj.Queue_Number__c = num;
        } else {
            // 置底直接用队列的size
            raesdObj.Queue_Number__c = raesdList.size();
        }
        
        // 插队Flag
        raesdObj.Asset__c = null;
        raesdObj.IsAdjust__c = true;
        raesdObj.Queue_User__c = UserInfo.getUserId();
        raes.add(raesdObj);
        // 更新队列信息
        FixtureUtil.withoutUpdate(raes);
 
        // 更新序列信息,先确认是单一序列还是混合序列,混合序列顺序不做调整
        List<Rental_Apply_Sequence__c> rasList = [
                SELECT Id, Series_No__c, ExternalKey__c, Apply_Set_Detail_ExternalKey__c
                FROM Rental_Apply_Sequence__c 
                WHERE Apply_Set_Detail__c =: raesd.Id
                  AND Invalid_Flag__c = false];
 
        Map<String, Integer> externalKeyMap = new Map<String, Integer>();
        for (Rental_Apply_Sequence__c ras : rasList) {
            externalKeyMap.put(ras.ExternalKey__c, 1);
        }
 
        // 先检索出混合序列,从更新序列中排除
        List<Rental_Apply_Sequence__c> rasList1 = [
                SELECT ExternalKey__c
                FROM Rental_Apply_Sequence__c 
                WHERE Invalid_Flag__c = false
                  AND ExternalKey__c IN: externalKeyMap.keySet()
                  AND Apply_Set_Detail_ExternalKey__c !=: raesd.ExternalKey__c
                ORDER BY ExternalKey__c];
 
        for (Rental_Apply_Sequence__c ras : rasList1) {
            if (externalKeyMap.containsKey(ras.ExternalKey__c)) {
                externalKeyMap.remove(ras.ExternalKey__c);
            }
        }
 
        // 检索出单一序列,更新单一序列
        List<Rental_Apply_Sequence__c> rasList2 = [
                SELECT Id, Series_No__c, Apply_Set_Detail__r.Queue_Number__c
                FROM Rental_Apply_Sequence__c 
                WHERE Invalid_Flag__c = false
                  AND ExternalKey__c IN: externalKeyMap.keySet()
                  AND Series_Unequal_Queue_Flag__c = true
                ORDER BY ExternalKey__c];
 
        for (Rental_Apply_Sequence__c ras : rasList2) {
            ras.Series_No__c = ras.Apply_Set_Detail__r.Queue_Number__c;
        }
        // 更新单一序列信息
        FixtureUtil.withoutUpdate(rasList2);
    }
 
    /**
     * 调整队列 + 申请单置顶,并没有比以前改进多少,还难维护,所以注释掉
     * */
    /*public void saveQueue(List<Rental_Apply_Equipment_Set_Detail__c> raesdObjs, Integer num, Boolean upDownFlag) {
        Map<Id, Rental_Apply_Equipment_Set_Detail__c> raesdMap = new Map<Id, Rental_Apply_Equipment_Set_Detail__c>([
                SELECT Id, Allow_Adjust_Queue_Flag__c, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Rental_Apply__c
                FROM Rental_Apply_Equipment_Set_Detail__c
                WHERE Id IN: raesdObjs
                  AND Is_Body__c = true
                  AND Cancel_Select__c = false
                ORDER BY ExternalKey__c, Queue_Number__c ASC nulls last]);
 
        String rentalApplyId = null;
        // 同一申请单中相同型号的设备排同样队列的情况下,需要按照ExternalKey来Map
        Map<String, List<Rental_Apply_Equipment_Set_Detail__c>> externalMap = new Map<String, List<Rental_Apply_Equipment_Set_Detail__c>>();
        for (Rental_Apply_Equipment_Set_Detail__c raesdObj : raesdObjs) {
            if (!raesdMap.containsKey(raesdObj.Id)) {
                throw new ControllerUtil.myException('调整的一览明细不存在。');
            } else {
                Rental_Apply_Equipment_Set_Detail__c raesdTemp = raesdMap.get(raesdObj.Id);
                rentalApplyId = raesdTemp.Rental_Apply__c;
                if (!raesdTemp.Allow_Adjust_Queue_Flag__c) {
                    throw new ControllerUtil.myException('备品总窗口未申请插队,无法调整顺序,请确认。');
                }
                if (upDownFlag && raesdTemp.Queue_Number__c <= num) {
                    throw new ControllerUtil.myException('请使用【指定排队NO.】来向上调整排队No。');
                }
 
                if (!externalMap.containskey(raesdTemp.ExternalKey__c)) {
                    List<Rental_Apply_Equipment_Set_Detail__c> tempList = new List<Rental_Apply_Equipment_Set_Detail__c>();
                    tempList.add(raesdTemp);
                    externalMap.put(raesdTemp.ExternalKey__c, tempList);
                } else {
                    List<Rental_Apply_Equipment_Set_Detail__c> tempList = externalMap.get(raesdTemp.ExternalKey__c);
                    tempList.add(raesdTemp);
                    externalMap.put(raesdTemp.ExternalKey__c, tempList);
                }
            }
        }
 
        List<Rental_Apply_Equipment_Set_Detail__c> raesUpdList = new List<Rental_Apply_Equipment_Set_Detail__c>();
        if (!externalMap.keySet().isEmpty()) {
            List<Rental_Apply_Equipment_Set_Detail__c> raesdList = [
                    SELECT Id, Fixture_Model_No__c, ExternalKey__c, Queue_Number__c, Rental_Apply__c
                    FROM Rental_Apply_Equipment_Set_Detail__c
                    WHERE Queue_Number__c > 0
                      AND Cancel_Select__c = false
                      AND ExternalKey__c IN: externalMap.keySet()
                    ORDER BY ExternalKey__c, Queue_Number__c ASC nulls last];
 
            // 先调整队列顺序,后再调整序列顺序
            // upDownFlag true:向上调整、置顶  false:置底
            // 需要按照页面段的检索条件,取出队列一览,来做调整队列时的比较
            if (raesdObjs.size() == 1) {
                Rental_Apply_Equipment_Set_Detail__c raesd = raesdMap.get(raesdObjs[0].Id);
                // 区分申请单置顶 和 别的操作
                Integer orderNo = 1;
                for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) {
                    // 向上调整、置顶
                    if (upDownFlag) {
                        if (orderNo >= num && orderNo < raesd.Queue_Number__c) {
                            rae.Queue_Number__c = orderNo + 1;
                            rae.Queue_User__c = UserInfo.getUserId();
                            raesUpdList.add(rae);
                        }
                    } else {
                        // 置底
                        if (orderNo > raesd.Queue_Number__c) {
                            rae.Queue_Number__c = orderNo - 1;
                            rae.Queue_User__c = UserInfo.getUserId();
                            raesUpdList.add(rae);
                        }
                    }
                    orderNo++;
                }
 
                if (upDownFlag) {
                    // 置顶或者向上,需要传调整Num
                    raesdObjs[0].Queue_Number__c = num;
                } else {
                    // 置底直接用队列的size
                    raesdObjs[0].Queue_Number__c = raesdList.size();
                }
                
                // 插队Flag
                raesdObjs[0].IsAdjust__c = true;
                raesdObjs[0].Queue_User__c = UserInfo.getUserId();
                raesUpdList.add(raesdObjs[0]);
 
            } else {
                // 申请单置顶
                Integer orderNo = 1;
                Integer endNo = 0;
                String externalKeyTemp = null;
                for (Rental_Apply_Equipment_Set_Detail__c rae : raesdList) {
                    if (rae.ExternalKey__c != externalKeyTemp) {
                        externalKeyTemp = rae.ExternalKey__c;
                        orderNo = externalMap.get(externalKeyTemp).size();
                        endNo = (Integer)externalMap.get(externalKeyTemp)[orderNo-1].Queue_Number__c;
                    }
 
                    if (rae.Rental_Apply__c != rentalApplyId) {
                        // 向上调整、置顶
                        if (upDownFlag) {
                            if (rae.Queue_Number__c >= num && rae.Queue_Number__c < endNo) {
                                rae.Queue_Number__c = orderNo + 1;
                                rae.Queue_User__c = UserInfo.getUserId();
                                raesUpdList.add(rae);
                            }
                        }
                    }
 
                    orderNo++;
                }
 
                if (upDownFlag) {
                    for (String external : externalMap.keySet()) {
                        List<Rental_Apply_Equipment_Set_Detail__c> tempList = new List<Rental_Apply_Equipment_Set_Detail__c>();
                        tempList = externalMap.get(external);
                        orderNo = 1;
                        for (Rental_Apply_Equipment_Set_Detail__c raesTemp : tempList) {
                            // 置顶
                            raesTemp.Queue_Number__c = orderNo;
                            // 插队Flag
                            raesTemp.IsAdjust__c = true;
                            raesTemp.Queue_User__c = UserInfo.getUserId();
                            raesUpdList.add(raesTemp);
                            orderNo++;
                        }
                    }
                }
            }
        }
 
        if (!raesUpdList.isEmpty()) {
            if(raesUpdList.size() > 9000){
                throw new ControllerUtil.myException('当前数据量过大,请到进行单条数据操作');
            }
            // 更新队列信息
            FixtureUtil.withoutUpdate(raesUpdList);
        }
        
        // 更新序列信息,先确认是单一序列还是混合序列,混合序列顺序不做调整
        List<Rental_Apply_Sequence__c> rasList = [
                SELECT Id, Series_No__c, ExternalKey__c, Apply_Set_Detail_ExternalKey__c
                FROM Rental_Apply_Sequence__c 
                WHERE Apply_Set_Detail__c IN: raesdObjs
                  AND Invalid_Flag__c = false];
 
        Map<String, Integer> externalKeyMap = new Map<String, Integer>();
        for (Rental_Apply_Sequence__c ras : rasList) {
            externalKeyMap.put(ras.ExternalKey__c, 1);
        }
 
        // 先检索出混合序列,从更新序列中排除
        List<Rental_Apply_Sequence__c> rasList1 = [
                SELECT ExternalKey__c
                FROM Rental_Apply_Sequence__c 
                WHERE Invalid_Flag__c = false
                  AND ExternalKey__c IN: externalKeyMap.keySet()
                  AND Apply_Set_Detail_ExternalKey__c !=: raesd.ExternalKey__c
                ORDER BY ExternalKey__c];
 
        for (Rental_Apply_Sequence__c ras : rasList1) {
            if (externalKeyMap.containsKey(ras.ExternalKey__c)) {
                externalKeyMap.remove(ras.ExternalKey__c);
            }
        }
 
        // 检索出单一序列,更新单一序列
        List<Rental_Apply_Sequence__c> rasList2 = [
                SELECT Id, Series_No__c, Apply_Set_Detail__r.Queue_Number__c
                FROM Rental_Apply_Sequence__c 
                WHERE Invalid_Flag__c = false
                  AND ExternalKey__c IN: externalKeyMap.keySet()
                  AND Series_Unequal_Queue_Flag__c = true
                ORDER BY ExternalKey__c];
 
        for (Rental_Apply_Sequence__c ras : rasList2) {
            ras.Series_No__c = ras.Apply_Set_Detail__r.Queue_Number__c;
        }
 
        if (!rasList2.isEmpty()) {
            if(raesUpdList.size() + rasList2.size() > 9000){
                throw new ControllerUtil.myException('当前数据量过大,请到进行单条数据操作');
            }
            // 更新单一序列信息
            FixtureUtil.withoutUpdate(rasList2);
        }
    }*/
}