liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
public without sharing class taskManageController {
 
    // 初始方法,获取当前所有任务,包括当前用户和当前用户下属的任务
    @AuraEnabled
    public static Task getCurrentTask(string myTaskName, string myTaskType, string myTaskStatus, string myAccountID, Date myStartDate, Date myEndDate, String myTaskDifferent, //2021-09-28  mzy 任务管理改善 start
                                      string subTaskName, string subTaskType, string subSFDCPosition, string subTaskStatus, string subAccountID, Date subStartDate, Date subEndDate,String subTaskDifferent) {
        ID myUserID = UserInfo.getUserId();
        // 检索出来当前用户的任务
        list<TaskWrapper> myTasks = TasksBuild( new list<ID> {myUserID},
                                                myTaskName,  myTaskType, '' ,
                                                myTaskStatus, myAccountID,
                                                myStartDate,
                                                myEndDate ,myTaskDifferent); //2021-09-28  mzy  任务管理改善 start 
        // 下属的ID set
        list<id> subUserIDlist = new list<id>();
        // 检索当前用户是经理、部长、总监等等的下属
        for (user tempUser :
                [select id
                 from user
                 where managerid = : myUserID
                                   or JingliApprovalManager__c = : myUserID
                                           or SalesManager__c = : myUserID
                                                   or JingliEquipmentManager__c = : myUserID
                                                           or BuchangApprovalManagerSales__c = : myUserID
                                                                   or BuchangApprovalManager__c = : myUserID
                                                                           or Buzhang_Equipment_Manager__c = : myUserID
                                                                                   or ZongjianApprovalManager__c = : myUserID
                                                                                           or TongkuoZongjian__c = : myUserID
                ]) {
            subUserIDlist.add(tempUser.id);
        }
        // 检索出来下属用户的任务
        list<TaskWrapper> subTasks = TasksBuild( subUserIDlist,
                                     subTaskName,  subTaskType, subSFDCPosition, subTaskStatus, subAccountID,  subStartDate,  subEndDate ,subTaskDifferent); //2021-09-28  mzy  任务管理改善  start
        Task allTask = new Task(myTasks, subTasks );
        return allTask;
    }
    // 确认或者延期
    @AuraEnabled
    public static string confirmOrDelay(boolean isDelay, string delayReason, string delayReasonOther, string taskID,Boolean IsGeneratePlan,Date ActivityDate,Date feedbackPlanDate,Date estimatedFinishDate) {
        //2021-07-30  mzy SWAG-C5DAX8 update  start
        UserResult u = UserInfo_Owner();
        //2021-07-30  mzy  SWAG-C5DAX8 update  end
        try {
            Task__c tempTask = new Task__c();
            tempTask.id = taskID;
            tempTask.isDelay__c = isDelay;
            tempTask.delayReason__c = delayReason;
            tempTask.delayReasonOther__c = delayReasonOther;
            //2021-07-30  mzy  SWAG-C5DAX8 update  start
            if(u.Job_Category!=null&&u.Job_Category.equals('销售服务')){
              tempTask.delayReasonSelectFSE__c = delayReason;
            }else {
              tempTask.delayReasonSelect__c = delayReason;
            }
            //2021-07-30  mzy  SWAG-C5DAX8 update  end
            //2021-10-20  mzy  任务管理改善  start
            if(IsGeneratePlan == false){
                //不生成计划
                tempTask.taskStatus__c = '02 接受';
                tempTask.GeneratePlan__c = IsGeneratePlan;
                tempTask.ConfirmDate__c = Date.today();
                tempTask.Activity_Date__c = ActivityDate;
                tempTask.feedbackPlanDate__c = feedbackPlanDate;
            }
            //2021-10-20  mzy  任务管理改善   end
 
            // 【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc Start
            Task__c tempObj = [SELECT Id, taskType__c FROM Task__c WHERE Id =: taskID];
            if (tempObj.taskType__c == '盘点检查计划' || tempObj.taskType__c == '温湿度检查计划') {
                if (isDelay) {
                    tempTask.taskStatus__c = '05 延期';
                    tempTask.delayDate__c = Date.today();
                    tempTask.delayToDate__c = estimatedFinishDate;
                } else {
                    tempTask.taskStatus__c = '02 接受';
                    tempTask.ConfirmDate__c = Date.today();
                    tempTask.Estimated_Finish_Date__c = estimatedFinishDate;
                }
            }
            // 【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc End
 
            update tempTask;
            //成功返回更新成功
            return 'Success';
        } catch (exception e) {
            //否则返回错误信息
            return e.getMessage();
        }
    }
 
    //合并任务
    @AuraEnabled
    public static string mergeTask(List<String> taskIdList) {
 
        try {
            
            List<Task__c> taskList = [select id,mergeTaskMain__c,CreateDate__c,Name,account__c,assignee__c,Assignment_Date__c,taskType__c,RelatedInformation_Text__c from task__c where id in :taskIdList];
            Task__c mainTask = new task__c();
            List<Task__c> opdList = [select id,mergeTaskMain__c,CreateDate__c,Name,account__c,assignee__c,Assignment_Date__c,taskType__c,RelatedInformation_Text__c from task__c where id in :taskIdList and taskType__c = 'OPD' order by createdDate desc];
 
            Boolean manyOpd = false;
            if(opdList == null || opdList.size() == 0){
                mainTask = [select id,mergeTaskMain__c,CreateDate__c,Name,account__c,assignee__c,Assignment_Date__c,taskType__c,RelatedInformation_Text__c from task__c where id in :taskIdList order by createdDate desc limit 1];
            }else if(opdList.size() == 1){
                mainTask = opdList.get(0);
            }else{
                manyOpd = true;
                mainTask = opdList.get(0);
            }
            
            List<Task__c> subTaskList = [select id,mergeTaskMain__c,CreateDate__c,Name,account__c,assignee__c,Assignment_Date__c,taskType__c,RelatedInformation_Text__c from task__c where mergeTaskMain__c in :taskIdList ];
            List<Task__c> updateList = new List<Task__c>();
            List<Task__c> deleteList = new List<Task__c>();
            Boolean isSame = false;
            for(Task__c tsk : taskList){
                if(tsk.id != mainTask.id ){
                    // if(tsk.CreateDate__c != null && tsk.CreateDate__c != mainTask.CreateDate__c && tsk.taskType__c == mainTask.taskType__c &&tsk.Name == mainTask.Name && tsk.RelatedInformation_Text__c == mainTask.RelatedInformation_Text__c  ){
                    //     deleteList.add(tsk);
                    //     isSame = true;
                    // }else if( tsk.assignee__c == mainTask.assignee__c && tsk.account__c == mainTask.account__c && tsk.taskType__c != mainTask.taskType__c){
                    //     if(isSame){
                    //         return '相同类型的任务合并时,请勿勾选不同类型的任务!';
                    //     }
                    //     if(manyOpd){
                    //         return '不同类型的任务合并时,最多可包含一个OPD任务!';
                    //     }
                    //     tsk.mergeTaskMain__c = mainTask.Id;
                    //     updateList.add(tsk);
                    // }else{
                    //     //return tsk.Name + ' 与 ' + mainTask.Name + ' 不符合合并条件!请选择派发时间不同,任务名称、类型、相关信息相同的任务进行合并,或者选择派发时间和客户相同,其余信息不同的任务进行合并!';
                    //     return '相同客户才可进行任务合并';
                    // }
                    //只上线相同类型任务合并    
                    if(tsk.CreateDate__c != null && tsk.CreateDate__c != mainTask.CreateDate__c && tsk.taskType__c == mainTask.taskType__c &&tsk.Name == mainTask.Name && tsk.RelatedInformation_Text__c == mainTask.RelatedInformation_Text__c  ){
                        deleteList.add(tsk);
                    }else{
                        return '相同类型的任务才可进行任务合并(任务名称、类型、相关信息相同)';
                    }
                    
                }
                
            }
 
            if(subTaskList != null && subTaskList.size() > 0){
                for(Task__c subTask : subTaskList){
                    subTask.mergeTaskMain__c = mainTask.Id;
                }
                update subTaskList;
            }
            if(updateList != null && updateList.size() > 0){
                update updateList;
            }
            if(deleteList != null && deleteList.size() > 0){
                delete deleteList;
            }
            return 'Success';
        } catch (exception e) {
            //否则返回错误信息
            return e.getMessage();
        }
    }
 
    //2021-10-28 yjk 根据任务id获取询价id
    @AuraEnabled
    public static string checkEnquiryController(String taskId) {
        try {
            List<task__c> tskList = [select id,   OpportunityId__c from task__c where id = :taskId];
            if(tskList.size() != 1){
                return 'error';
            }
            if(tskList.get(0).OpportunityId__c == null ){
                return 'no';
            }
            
            return tskList.get(0).OpportunityId__c;
        } catch (exception e) {
            //否则返回错误信息
            return 'error';
        }
    }
 
    //重新分配任务
    @AuraEnabled
    public static UserResult resetAssignee(string assigneeID, string taskID) {
        UserResult result = new UserResult();
        Savepoint sp = Database.setSavepoint();
        try {
            Task__c tempTask = new Task__c();
            tempTask.id = taskID;
            tempTask.assignee__c = assigneeID;
            tempTask.ownerid = assigneeID;
            tempTask.Assignment_Date__c = Date.today();
            update tempTask;
            //2021-11-12 yjk 任务分配时,子任务也一起分配给用户 start
            List<Task__c> childTasks = [select id,assignee__c,ownerid,Assignment_Date__c from task__c where mergeTaskMain__c = :taskID];
            if(null != childTasks && childTasks.size() > 0 ){
                for(Task__c tsk : childTasks){
                    tsk.assignee__c = assigneeID;
                    tsk.ownerid = assigneeID;
                    tsk.Assignment_Date__c = Date.today();
                }
            }
            update childTasks;
            //2021-11-12 yjk 任务分配时,子任务也一起分配给用户 end
 
            User tempUser =
                [select id, alias from user where id = : assigneeID ];
            result.assigneeID = assigneeID;
            result.assigneeName = tempUser.alias;
 
        } catch (exception e) {
            Database.rollback(sp);
            result.result = e.getMessage();
        }
        return result;
    }
    //20210105 CHAN-BWX3YU you start
     //重新分配任务
    @AuraEnabled
    public static UserResult resetAssignee_Owner(string assigneeID, string taskID) {
        UserResult result = new UserResult();
        Savepoint sp = Database.setSavepoint();
        try {
           // Task__Share tasksha = new Task__Share(UserOrGroupId=assigneeID, AccessLevel='Edit', ParentId = taskID,RowCause = 'Manual');
            //insert tasksha;
            system.debug('==taskID==='+taskID+'==assigneeID=='+assigneeID);
            
            Task__c tempTask = new Task__c();
            tempTask.id = taskID;
            tempTask.assignee__c = assigneeID;
            tempTask.ownerid = assigneeID;
            tempTask.Assignment_Date__c = Date.today();
            update tempTask;
            //2021-11-12 yjk 任务分配时,子任务也一起分配给用户 start
            List<Task__c> childTasks = [select id,assignee__c,ownerid,Assignment_Date__c from task__c where mergeTaskMain__c = :taskID];
            if(null != childTasks && childTasks.size() > 0 ){
                for(Task__c tsk : childTasks){
                    tsk.assignee__c = assigneeID;
                    tsk.ownerid = assigneeID;
                    tsk.Assignment_Date__c = Date.today();
                }
            }
            update childTasks;
            //2021-11-12 yjk 任务分配时,子任务也一起分配给用户 end
            User tempUser =
                [select id, alias from user where id = : assigneeID ];
            result.assigneeID = assigneeID;
            result.assigneeName = tempUser.alias;
 
        } catch (exception e) {
            Database.rollback(sp);
            result.result = e.getMessage();
        }
        return result;
    }
    //获取当前登录人的 省份 和 职种
    @AuraEnabled
    public static UserResult UserInfo_Owner() {
        UserResult result = new UserResult();
        ID myUserID = UserInfo.getUserId();
        
        try { 
            User tempUser =
                [select id,Province__c,Job_Category__c from user where id = : myUserID ];
            result.Job_Category = tempUser.Job_Category__c;
            result.ProvinceName = tempUser.Province__c;
        } catch (exception e) {
            
            result.result = e.getMessage();
        }
        return result;
    }
    //20210105 CHAN-BWX3YU you end
    // 获取当前用户的任务
    @AuraEnabled
    public static Task getMyTask(string myTaskName, string myTaskType,
                                 string myTaskStatus, string myAccountID,
                                 Date myStartDate, Date myEndDate,
                                 //2021-09-28 mzy 任务管理改善 start
                                 String myTaskDifferent
                                 //2021-09-28 mzy 任务管理改善 end
                                 ) {           
        ID myUserID = UserInfo.getUserId();
 
        //2021-09-28 mzy 任务管理改善  update  start
        list<TaskWrapper> myTasks = TasksBuild( new list<ID> {myUserID},
                                                myTaskName,  myTaskType,  '' , myTaskStatus, myAccountID,  myStartDate,  myEndDate, myTaskDifferent );
        //2021-09-28 mzy 任务管理改善  update  end
        Task allTask = new Task(myTasks, null );
        return allTask;
    }
    //获取当前用户下属的任务
    @AuraEnabled
    public static Task getSubTask(string subTaskName, string subTaskType,
                                  string subSFDCPosition , string subTaskStatus,
                                  string subAccountID,
                                  Date subStartDate, Date subEndDate ,
                                  //2021-09-28 mzy 任务管理改善 start
                                 String subTaskDifferent
                                 //2021-09-28 mzy 任务管理改善 end 
                                 ) {
        ID myUserID = UserInfo.getUserId();
        list<id> subUserIDlist = new list<id>();
        for (user tempUser :
                [select id
                 from user
                 where managerid = : myUserID
                                   or JingliApprovalManager__c = : myUserID
                                           or SalesManager__c = : myUserID
                                                   or JingliEquipmentManager__c = : myUserID
                                                           or BuchangApprovalManagerSales__c = : myUserID
                                                                   or BuchangApprovalManager__c = : myUserID
                                                                           or Buzhang_Equipment_Manager__c = : myUserID
                                                                                   or ZongjianApprovalManager__c = : myUserID
                                                                                           or TongkuoZongjian__c = : myUserID
                ]) {
            subUserIDlist.add(tempUser.id);
        }
        //system.debug('subUserIDlist:'+subUserIDlist);
        //2021-09-28 mzy 任务管理改善  update  start
        list<TaskWrapper> subTasks = TasksBuild( subUserIDlist,
                                     subTaskName,  subTaskType, subSFDCPosition, subTaskStatus, subAccountID,  subStartDate,  subEndDate , subTaskDifferent );
        //2021-09-28 mzy 任务管理改善  update  end
        Task allTask = new Task(null, subTasks );
        return allTask;
    }
    // 取消任务
    @AuraEnabled
    public static string cancel(string taskID, string cancelReason, string cancelReasonOther) {
        //2021-07-30  mzy SWAG-C5DAX8 update  start
        UserResult u = UserInfo_Owner();
        //2021-07-30  mzy  SWAG-C5DAX8 update  end
         System.debug('取消理由值:'+cancelReason);
        try {
            
            Task__c tempTask = new Task__c();
            tempTask.id = taskID;
            tempTask.cancelReason__c = cancelReason;
            //2021-11-17  mzy  任务管理改善
            if('客户时间变更或冲突'.equals(cancelReason)){
                cancelReason = '客户事件变更或冲突';
            }
            //2021-11-17  mzy  任务管理改善
            tempTask.cancelReasonOther__c = cancelReasonOther;
            tempTask.taskStatus__c = '04 取消';
            tempTask.cancelDate__c = date.today();
            //2021-07-30  mzy  SWAG-C5DAX8 update  start
            if(u.Job_Category!=null&&u.Job_Category.equals('销售服务')){
              tempTask.cancelReasonSelectFSE__c = cancelReason;
            }else {
              tempTask.cancelReasonSelect__c = cancelReason;
            }
            //2021-07-30  mzy  SWAG-C5DAX8 update  end
 
            update tempTask;
            return 'Success';
        } catch (exception e) {
            return e.getMessage();
        }
    }
 
    // 构建任务集合
    public static list<TaskWrapper> TasksBuild( list<ID> userIDList, string TaskName,
            string taskType,  string SFDCPosition ,
            string TaskStatus, string AccountID,
            Date startDate, Date endDate,String TaskDifferent) {// 2021-09-28  mzy  任务管理改善  start
        list<TaskWrapper> myTasks = new list<TaskWrapper>();
        //2021-11-11  mzy  任务管理改善  start
        UserResult u = UserInfo_Owner();
        //2021-11-11  mzy  任务管理改善  end
        // 拼出来任务检索条件
        String query = 'select id, name, account__c, account__r.name,' +
                       'CreateDate__c,assignee__c , assignee__r.alias, ' +
                       //2021-03-29 WLIG-BZK59N mzy  start
                       'RelatedInformation_ID__c,RelatedInformation_Text__c,'+
                       //2021-03-29 WLIG-BZK59N mzy  end
                       //2021-09-28  mzy  任务管理改善  start
                       'TaskDifferent__c,'+
                       'completeCondition__c ,distributeReason__c,' + //2021-11-17 yjk 增加完成条件,派发原因
                       //2021-09-28  mzy  任务管理改善  end
                       //2021-11-11  mzy  任务管理改善  start
                       'cancelReasonSelect__c,cancelReasonSelectFSE__c,'+
                       'delayReasonSelect__c,delayReasonSelectFSE__c,RecordTypeId,'+
                       //2021-11-11  mzy  任务管理改善   end
                       //2021-11-25  mzy  任务管理改善  start
                       'HopeCompletionDate__c,'+
                       //2021-11-25  mzy  任务管理改善  end
                       // 【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc Start
                       'Estimated_Finish_Date__c,LatestFinishDate__c,'+
                       // 【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc End
                       'taskStatus__c,taskType__c,Assignment_Date__c  from task__c where assignee__c =: userIDList and mergeTaskMain__c = null ' +
                       //2021-1-4 yjk 增加任务区分,只查询被动和上级分配
                       //' and TaskDifferent__c != \'主动任务\' ';
                       '';
                       //任务名称
        if (string.isNotBlank(TaskName)) {
            query += ' and Name like \'%' + String.escapeSingleQuotes(TaskName.trim())  + '%\'';
        }
        //任务类型
        if (string.isNotBlank(taskType)) {
            query += ' and taskType__c = \'' + String.escapeSingleQuotes(taskType)  + '\'';
        }
        // SFDC职种
        if (string.isNotBlank(SFDCPosition)) {
            query += ' and assignee__r.SFDCPosition_C__c = \'' + String.escapeSingleQuotes(SFDCPosition)  + '\'';
        }
        // 所属客户
        if (string.isNotBlank(AccountID)) {
            query += ' and account__c = \'' + String.escapeSingleQuotes(AccountID)  + '\'';
        }
        //任务状态
        if (string.isNotBlank(TaskStatus)) {
            query += ' and taskStatus__c = \'' + String.escapeSingleQuotes(TaskStatus)  + '\'';
        }
        //创建日期的起始日期
        if (startDate != null) {
            query += ' and CreateDate__c >= ' + startDate.format().replace('/', '-')   ;
        }
        //创建日期的结束日期
        if (endDate != null) {
            query += ' and CreateDate__c <= ' + endDate.format().replace('/', '-')  ;
        }
        //2021-09-28  mzy  任务管理改善  start
        //任务区分
        if(string.isNotBlank(TaskDifferent)){
            query += ' and TaskDifferent__c =\''+ String.escapeSingleQuotes(TaskDifferent) +'\'';
        }else {
            query += ' and TaskDifferent__c != \'主动任务\' ';
        }
        //2021-09-28  mzy  任务管理改善   end
 
        //2021-04-19  mzy WLIG-C25DW4   任务一览表显示逻辑  任务管理表请按客户、任务类型和相关信息排序。 start
            query += ' order by TaskDifferent__c desc,account__c ,taskType__c,RelatedInformation_ID__c';
        //2021-04-19  mzy WLIG-C25DW4   任务一览表显示逻辑  任务管理表请按客户、任务类型和相关信息排序。 end  
 
        system.debug('query>>>>>' + query);
        // 检索成功后构建任务wrapper
        for ( Task__c tempTask : Database.query(query) ) {
            TaskWrapper tempTaskWrapper = new TaskWrapper();
            tempTaskWrapper.Id                       = tempTask.id;
            tempTaskWrapper.taskId                   = '/' + tempTask.id;
            //2021-11-25  mzy   任务管理改善  start
            //任务名称只显示 名称不显示客户名
            if(String.isNotBlank(tempTask.Name)){
                String tempTaskName = tempTask.Name;
                if(tempTaskName.contains(':')){
                    tempTaskWrapper.taskName  = tempTaskName.split(':')[0];
                //}else if(tempTaskName.contains('(')){
                //    tempTaskWrapper.taskName  = tempTaskName.split('(')[0];
                }else {
                    tempTaskWrapper.taskName  = tempTaskName;
                }
            }
            //tempTaskWrapper.taskName                 = tempTask.Name;
            //2021-11-25  mzy   任务管理改善  end
            tempTaskWrapper.taskAccountID            = null == tempTask.account__c ? '' : '/' + tempTask.account__c;
            tempTaskWrapper.taskAccountName          = tempTask.account__r.name;
            tempTaskWrapper.taskType                 = tempTask.taskType__c;
            tempTaskWrapper.taskStatus               = tempTask.taskStatus__c;
            tempTaskWrapper.taskCreateddate          = tempTask.CreateDate__c;
            tempTaskWrapper.taskAssigneeName         = tempTask.assignee__r.alias;
            tempTaskWrapper.taskAssigneeUrl          = '/' + tempTask.assignee__c;
            tempTaskWrapper.taskAssigneeID           =  tempTask.assignee__c;
            //2021-09-28  mzy  任务管理改善  start
            tempTaskWrapper.taskDifferent           =  tempTask.TaskDifferent__c;
            //2021-09-28  mzy  任务管理改善  end
 
            tempTaskWrapper.completeCondition       =  tempTask.completeCondition__c;//2021-11-17 yjk 完成条件
            tempTaskWrapper.distributeReason        =  tempTask.distributeReason__c;
            //2021-11-11  mzy  任务管理改善  start
            //根据任务类型显示不同的理由
            tempTaskWrapper.tempTask                =  tempTask;
            tempTaskWrapper.isFSE                   =  ('销售服务'.equals(u.Job_Category) ? true :false);
            //2021-11-11  mzy  任务管理改善  end
            //2021-11-25  mzy  任务管理改善  start
            tempTaskWrapper.HopeCompletionDate      =  tempTask.HopeCompletionDate__c;
            //2021-11-25  mzy  任务管理改善  end
            //2021-03-29 WLIG-BZK59N mzy  start
            if(tempTask.RelatedInformation_Text__c != null && tempTask.RelatedInformation_ID__c != null){ 
                //多年保 和 询价
            tempTaskWrapper.taskRelatedInformation = tempTask.RelatedInformation_Text__c;
            tempTaskWrapper.taskRelatedInformationID = '/'+tempTask.RelatedInformation_ID__c;
            }else if(tempTask.RelatedInformation_Text__c != null&&String.isBlank(String.valueOf(tempTask.RelatedInformation_ID__c))==true){
                //OPD任务 || 是其他
            tempTaskWrapper.taskRelatedInformation = tempTask.RelatedInformation_Text__c;
            tempTaskWrapper.taskRelatedInformationID = '/apex/taskManage?id='+String.ValueOf(UserInfo.getUserId()).substring(0,15)+'#';
            }
            //tempTaskWrapper.taskRelatedInformation = tempTask.RelatedInformation_Text__c;
            //tempTaskWrapper.taskRelatedInformationID = tempTask.RelatedInformation_ID__c==null?'/':'/'+tempTask.RelatedInformation_ID__c;
            //2021-03-29 WLIG-BZK59N mzy  end
            tempTaskWrapper.cancelButtonisDisabled   = false;
            tempTaskWrapper.confirmButtonisDisabled  = false;
            tempTaskWrapper.delayButtonisDisabled    = false;
            tempTaskWrapper.assignButtonisDisabled   = false;
            //20210111 CHAN-BWX3YU you start
            tempTaskWrapper.assignButtonisDisabled_Owner   = false; 
 
            //【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc Start
            tempTaskWrapper.createdAfter3Month   = tempTask.CreateDate__c.addMonths(3);
            tempTaskWrapper.latestFinishDate   = tempTask.LatestFinishDate__c;
            //【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc End
 
            Date d2 = date.today().addDays(-2); 
            Date createdate1= date.newinstance(tempTask.CreateDate__c.year(), tempTask.CreateDate__c.month(), tempTask.CreateDate__c.day());
            system.debug('分配时间'+tempTask.Assignment_Date__c+'==d2=='+d2);
            //20210111  CHAN-BWX3YU you end
            
            if (tempTask.taskStatus__c != null && !tempTask.taskStatus__c.equals('01 分配')) {
                tempTaskWrapper.cancelButtonisDisabled   = true;
                tempTaskWrapper.confirmButtonisDisabled  = true;
                tempTaskWrapper.delayButtonisDisabled    = true;
                tempTaskWrapper.assignButtonisDisabled   = true;
                //20210105 CHAN-BWX3YU you start
                tempTaskWrapper.assignButtonisDisabled_Owner   = true;
                //20210105 CHAN-BWX3YU you end
            }
            //20210618 SWAG-C434H9 zh start
            // if((tempTask.Assignment_Date__c!= null && tempTask.Assignment_Date__c >=d2) || (tempTask.Assignment_Date__c== null && createdate1>=d2 )){
            if(tempTask.Assignment_Date__c!= null && tempTask.Assignment_Date__c >=d2){
            //20210618 SWAG-C434H9 zh end
               //20210113 CHAN-BWX3YU you start
                tempTaskWrapper.assignButtonisDisabled_Owner   = true;
                tempTaskWrapper.assignButtonisDisabled   = true;
                //20210113 CHAN-BWX3YU you end
            }
            //2021-10-08  mzy  任务管理改善  start
            //上级分配的任务只允许 接受 ,不允许 延期/取消
            if(tempTask.TaskDifferent__c != null && tempTask.TaskDifferent__c.equals('上级分配任务')){
                tempTaskWrapper.cancelButtonisDisabled   = true;
                tempTaskWrapper.delayButtonisDisabled    = true;
                tempTaskWrapper.assignButtonisDisabled_Owner   = true;
            }
            //2021-10-08  mzy  任务管理改善  end
            myTasks.add(tempTaskWrapper);
        }
        return myTasks;
    }
    // 获取各种选项列表的选项值
    @AuraEnabled
    public static map<string, list<pickerWrapper>> getpickerField() {
        map<string, list<pickerWrapper>> pickerFields = new map<string, list<pickerWrapper>>();
 
        // 任务类型选项值获取
        list<pickerWrapper> taskTypeOptions = new list<pickerWrapper>();
        Map<String, Schema.RecordTypeInfo> taskTypeNameMap =
            Schema.SObjectType.Task__c.getRecordTypeInfosByName();
        set<string> taskTypeNameSet = taskTypeNameMap.keySet();
        for (string tempStr : taskTypeNameSet) {
            if (!tempStr.equals('主类型')) {
                pickerWrapper temppickerWrapper =
                    new pickerWrapper(tempStr, tempStr);
                taskTypeOptions.add(temppickerWrapper);
            }
        }
        pickerWrapper pickerWrapper =
            new pickerWrapper('所有', '');
        taskTypeOptions.add(pickerWrapper);
        pickerFields.put('taskTypeOptions', taskTypeOptions);
        // 任务状态选项值获取
        list<pickerWrapper> taskStatusOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult taskStatusfieldResult = Task__c.taskStatus__c.getDescribe();
        List<Schema.PicklistEntry> taskStatusple = taskStatusfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : taskStatusple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            taskStatusOptions.add(temppickerWrapper);
        }
        pickerFields.put('taskStatusOptions', taskStatusOptions);
        // 2021-09-28  mzy  任务管理改善  start
        // 任务区分选项值获取
        list<pickerWrapper> taskDifferentOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult taskDifferentfieldResult = Task__c.taskDifferent__c.getDescribe();
        List<Schema.PicklistEntry> taskDifferentple = taskDifferentfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : taskDifferentple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            taskDifferentOptions.add(temppickerWrapper);
        }
        pickerWrapper taskDifferentWrapper =
            new pickerWrapper('所有', '');
        taskDifferentOptions.add(taskDifferentWrapper);
        pickerFields.put('taskDifferentOptions', taskDifferentOptions);
        // 2021-09-28  mzy  任务管理改善   end
        // SFDC 职种选项值获取
        list<pickerWrapper> SFDCPositionOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult SFDCPositionfieldResult = user.SFDCPosition_C__c.getDescribe();
        List<Schema.PicklistEntry> SFDCPositionple = SFDCPositionfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : SFDCPositionple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            SFDCPositionOptions.add(temppickerWrapper);
        }
        pickerFields.put('SFDCPositionOptions', SFDCPositionOptions);
        // 当前用户职种获取
        User curentUser =
            [select id , Job_Category__c
             from User
             where id = : UserInfo.getUserId()];
        // 取消理由选项值获取
        list<pickerWrapper> cancelReasonOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult cancelReasonfieldResult;
        if (curentUser.Job_Category__c != null &&  curentUser.Job_Category__c.equals('销售服务')) {
            cancelReasonfieldResult = Task__c.cancelReasonSelectFSE__c.getDescribe();
 
        } else {
            cancelReasonfieldResult = Task__c.cancelReasonSelect__c.getDescribe();
        }
        List<Schema.PicklistEntry> cancelReasonple = cancelReasonfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : cancelReasonple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            cancelReasonOptions.add(temppickerWrapper);
        }
        pickerFields.put('cancelReasonOptions', cancelReasonOptions);
 
        // 延期理由选项值获取
        list<pickerWrapper> delayReasonOptions = new list<pickerWrapper>();
        Schema.DescribeFieldResult delayReasonfieldResult;
        if (curentUser.Job_Category__c != null &&  curentUser.Job_Category__c.equals('销售服务')) {
            delayReasonfieldResult = Task__c.delayReasonSelectFSE__c.getDescribe();
 
        } else {
            delayReasonfieldResult = Task__c.delayReasonSelect__c.getDescribe();
        }
        List<Schema.PicklistEntry> delayReasonple = delayReasonfieldResult.getPicklistValues();
        for ( Schema.PicklistEntry pickListVal : delayReasonple) {
            pickerWrapper temppickerWrapper =
                new pickerWrapper(pickListVal.getLabel(), pickListVal.getValue());
            delayReasonOptions.add(temppickerWrapper);
        }
        pickerFields.put('delayReasonOptions', delayReasonOptions);
 
        return pickerFields;
    }
 
    public class Task {
        @AuraEnabled
        public list<TaskWrapper> myTasks;
        @AuraEnabled
        public list<TaskWrapper> subTasks;
 
        public Task(list<TaskWrapper> myTasks, list<TaskWrapper> subTasks) {
            this.myTasks = myTasks;
            this.subTasks = subTasks;
        }
    }
    public class TaskWrapper {
        @AuraEnabled
        public String id;
        @AuraEnabled
        public String taskId;
        @AuraEnabled
        public String taskName;
        @AuraEnabled
        public String taskAccountID;
        @AuraEnabled
        public String taskAccountName;
        @AuraEnabled
        public String taskAssigneeID;
        @AuraEnabled
        public String taskAssigneeUrl;
        @AuraEnabled
        public String taskAssigneeName;
        @AuraEnabled
        public String taskType;
        @AuraEnabled
        public String taskStatus;
        @AuraEnabled
        public Date taskCreateddate;
        @AuraEnabled
        public Boolean cancelButtonisDisabled;
        @AuraEnabled
        public Boolean confirmButtonisDisabled;
        @AuraEnabled
        public Boolean delayButtonisDisabled;
        @AuraEnabled
        public Boolean assignButtonisDisabled;
        //20210104 CHAN-BWX3YU you
        @AuraEnabled
        public Boolean assignButtonisDisabled_Owner;
        //2021-03-29  WLIG-BZK59N mzy
        @AuraEnabled
        public String taskRelatedInformation;
        @AuraEnabled
        public String taskRelatedInformationID;
        //2021-09-28 任务管理改善 mzy
        @AuraEnabled
        public String taskDifferent;
        //2021-11-11 任务管理改善  mzy
        @AuraEnabled
        public Task__c tempTask;
        @AuraEnabled
        public Boolean isFSE;
        @AuraEnabled
        public String completeCondition;
        @AuraEnabled
        public String distributeReason;
        //2021-11-25  任务管理改善 mzy
        @AuraEnabled
        public Date  HopeCompletionDate;
        //2021-11-25  任务管理改善 mzy
        //【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc Start
        @AuraEnabled
        public Date  createdAfter3Month;
        @AuraEnabled
        public Date  latestFinishDate;
        //【FY24大及巨大课题】北京新法规项目对应 DB202307428742 20230804 by lc End
    }
    public class pickerWrapper {
        @AuraEnabled
        public string label;
        @AuraEnabled
        public string value;
        public pickerWrapper(string label, string value) {
            this.label = label;
            this.value = value;
        }
 
    }
    public class UserResult {
        @AuraEnabled
        public string assigneeName;
        @AuraEnabled
        public string assigneeID;
        @AuraEnabled
        public string result;
        public UserResult( ) {
            result = 'Success';
        }
        //20210105 CHAN-BWX3YU you start
        @AuraEnabled
        public string Job_Category;
        @AuraEnabled
        public string  ProvinceName;
        //20210105 CHAN-BWX3YU you end
    }
}