移动系统liao
2025-05-01 a247547df86f0fad8f03aebb91de68d3f2bc7918
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
using cylsg.Model.ECTEModel;
using cylsg.Model.utilityViewModel;
using cylsg.utility.Extend;
using ECTESTOA;
using EzCoreNet.Redis;
using Furion.LinqBuilder;
using Models;
using StackExchange.Profiling;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using TencentCloud.Iecp.V20210914.Models;
using TencentCloud.Monitor.V20180724.Models;
 
namespace cylsg.Application.CyOS
{
    /// <summary>
    /// 川印配送控制器
    /// </summary>
    [Authorize]
    [ApiDescriptionSettings("CYOA")]
    public class CyOsDeliverManage : IDynamicApiController
    {
 
        private readonly ISqlSugarClient _client;
        private readonly IOAServices _oAServices;
        private readonly IEzCoreNetRedisService _eZCoreNetRedisService;
        private ECTESTOAPermissions Permissions;
        public CyOsDeliverManage(ISqlSugarClient client, IOAServices oAServices, IEzCoreNetRedisService netRedisService)
        {
            _client = client.AsTenant().GetConnection("ECTESTOADB");
            _oAServices = oAServices;
            _eZCoreNetRedisService = netRedisService;
        }
        //[HttpGet]
        //[AllowAnonymous]
        //public async Task<bool > TestCreat()
        //{
        //    OaWorkPlan pram = new OaWorkPlan()
        //    {
 
        //        EvaluationContent = "",
        //        PlanDataType = 17,
        //        PlanType = 3,
        //        MemberId = _oAServices.firmId,
        //        SentStaffId = Guid.Empty,
        //        ReciveStaffId = Guid.Empty,
        //        DepartId = 0,
        //        PlanStartTime = DateTime.Now,
        //        RewardContent = "",
        //        LastUpdateTime = DateTime.Now,
        //        Operator = "",
        //        PlanTitle = "",
        //        PlanRunTime = DateTime.Now,
        //        PlanRemark = "",
        //        PlanPeople = "测试测试",
        //        PlanComplany = "",
        //        PlanStatus = PlanStatusType.unApproval,
        //        ApprovalStaffId = Guid.Empty,
        //        ApprovalStatus = PlanStatusType.unApproval,
        //        EvaluationStatus = BaoxiaoStausType.Unknown,
        //        FirmAccountId = 0,
        //        HoubufapiaoStatus = HoubufapiaoStatusType.Unknown,
        //        PlanMoney = 200,
        //        PlanContent = "测试批量",
        //        RewardResult = "10",
 
        //        ApprovalTime = DateTime.Now,
        //        ApprovalContent = "",
        //        EvaluationStaffId = Guid.Empty,
        //        EvaluationTime = DateTime.Now,
        //        RewardMoney = 0,
        //        RewardType = 1,
        //        Keyid = null,
        //        WorkPlanAttachments = new List<OaWorkPlanAttachment>()
        //        {
        //             new OaWorkPlanAttachment
        //             {
        //                  AttachmentType=1,
        //                   CreateTime=DateTime.Now,
        //                    Operator="123213",
        //                     PlanAttachment="hhttp://1.jpg"
        //             },
        //              new OaWorkPlanAttachment
        //             {
        //                  AttachmentType=1,
        //                   CreateTime=DateTime.Now,
        //                    Operator="123213",
        //                     PlanAttachment="hhttp://2.jpg"
        //             }
        //              ,
        //              new OaWorkPlanAttachment
        //             {
        //                  AttachmentType=4,
        //                   CreateTime=DateTime.Now,
        //                    Operator="123213",
        //                     PlanAttachment="hhttp://2.jpg"
        //             }
        //        }
               
 
        //    };
        //    return await _client.InsertNav(pram).Include(x => x.WorkPlanAttachments).ExecuteCommandAsync();
 
 
 
        //}
 
        ///// <summary>
        ///// 
        ///// </summary>
        ///// <returns></returns>
        //[HttpGet]
        //[AllowAnonymous]
        //public async Task<OA_DriverRecord> TestUpdata()
        //{
 
 
 
        //}
 
        /// <summary>
        /// 获取预约配送信息
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppointmentDeliverRet> GetListAppointmentDeliverList(ApoointmentDeliverSearchParam Param)
        {
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
 
            Expression<Func<OA_DeliverTixing, bool>> SearchList = (x) => true;
            SearchList = SearchList.And(x => x.FirmId == _oAServices.firmId);
            if (!string.IsNullOrEmpty(Param.Content))
            {
                SearchList = SearchList.And(x => x.Remark.Contains(Param.Content));
            }
            if (Param.MemberId != null)
            {
                SearchList = SearchList.And(x => x.FirmId == Param.MemberId);
            }
            if (Param.TimeStart != null)
            {
                SearchList = SearchList.And(x => x.CreateTime > Param.TimeStart);
            }
            if (Param.TimeEnd != null)
            {
                SearchList = SearchList.And(x => x.CreateTime < Param.TimeEnd);
            }
 
 
            //报销状态
            if (Param.DeliverState != null)
            {
                SearchList = SearchList.And(x => x.Chulistatus == Param.DeliverState);
            }
            //强制增加员工过滤
            RefAsync<int> totle = 0;
            var data = await _client.Queryable<OA_DeliverTixing>().Includes(x => x.SentStaff)
                .Where(SearchList).OrderByDescending(x => x.ChuliTime).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
 
            Param.page.TotalCount = totle;
 
            return new AppointmentDeliverRet
 
            {
                Data = data,
                page = Param.page,
 
            };
        }
 
        /// <summary>
        /// 送货预约单详情
        /// </summary>
        /// <param name="KeiId"></param>
        /// <returns></returns>
        public async Task<OA_DeliverTixing> GetAppointmentDeliverInfo(int KeiId)
        {
 
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            var data = await _client.Queryable<OA_DeliverTixing>().Includes(x => x.SentStaff).Where(x => x.Keyid == KeiId && x.FirmId == _oAServices.firmId).FirstAsync();
 
            return data;
 
 
        }
        /// <summary>
        /// 受理       弃用,用  CreatDeliverPlan 代替
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        [Obsolete]
        public async Task<int> AcceptAppointmentDeliver(int KeiId)
        {
            throw Oops.Oh("已经启用");
            if (!(KeiId > 0))
                throw Oops.Oh("Keyid不能为空");
 
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            var data = await _client.Queryable<OA_DeliverTixing>().Where(x => x.Keyid == KeiId && x.FirmId == _oAServices.firmId).FirstAsync();
            if (data == null)
                throw Oops.Oh("没找到数据");
            if (data.Chulistatus != AppointmentDeliverState.unAccept)
                throw Oops.Oh("订单已处理");
 
            data.Chulistatus = AppointmentDeliverState.Accept;
            data.LastUpdateTime = DateTime.Now;
            data.Updater = Permissions.MemberId;
            return await _client.Updateable(data).ExecuteCommandAsync();
 
 
 
 
        }
 
        /// <summary>
        /// 创建配送单
        /// </summary>
        /// <param name="Param"> 只需要传递</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreatDeliverPlan(OA_DeliverPlanPaiche Param)
        {
 
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            OA_DeliverTixing? tixing=null;
            if(Param.DeliverTixingId>0)
            {
                //是提醒订单,需要执行提醒单 状态干煸
                tixing = await _client.Queryable<OA_DeliverTixing>().Where(x => x.Keyid == Param.DeliverTixingId).FirstAsync();
                if(tixing == null)
                {
                    throw Oops.Oh("提醒单不存在了");
                }
                if(tixing.Chulistatus != AppointmentDeliverState.unAccept)
                    throw Oops.Oh("提醒单已经处理了");
                tixing.Chulistatus= AppointmentDeliverState.Accept;
                tixing.ChuliTime = DateTime.Now;
                tixing.ChuliRen=Permissions.MemberId;
                tixing.LastUpdateTime = DateTime.Now;
                tixing.Updater = Permissions.MemberId;
 
            }
            OA_CarManage car = null;
            if (Param.DriverId != null)
                car = await _client.Queryable<OA_CarManage>().Where(x => x.StaffID == Param.DriverId && x.MemberID == _oAServices.firmId).FirstAsync();
 
         
            OA_CorporateClients cor = null;
            if (Param.BuyerId != null)
                cor = await _client.Queryable<OA_CorporateClients>().Where(x => x.Keyid == Param.BuyerId).FirstAsync();
            OA_DeliverPlanPaiche DeliverPlan = new OA_DeliverPlanPaiche()
            {
                Keyid = Guid.NewGuid(),
                FirmId = _oAServices.firmId,
                BuyerId = Param.BuyerId ?? Guid.Empty,
                DeliverTime = Param.DeliverTime,
                CarId = car == null ? 0 : car.Keyid,
                Wentifankui = "",
                Xingzhengzhuize = "",
                Yichangchuli = "",
                Zhuyishixiang = "",
                Gongzuokaoping = "",
 
 
                Transferstatus = 1,
                Sort = Param.Sort,
                Creater = Param.Creater ?? Permissions.MemberId,
                CreateTime = DateTime.Now,
                DriverId = Param.DriverId,
                SellerOrderId = await CreatDeliverPlanSn(),
                Dianhua = Param.Dianhua,
                Dizhi = Param.Dizhi,
                Remark = Param.Remark,
                BusinessManagerId = cor == null ? 0 : cor.BusinessManagerId,
                Biddingcompany = cor == null ? 0 : (cor.Biddingcompany ?? 0),
                ShifouDelivery = 1,
                Lianxiren = Param.Lianxiren,
                Deliveredstatus = (int)DeliveredType.Undeliver,
                CompanyName = Param.CompanyName,
 
 
            };
            try
            {
            
                if (tixing!=null)
                {
                    tixing.DeliverPlanPaicheId = DeliverPlan.Keyid;
                     await _client.Updateable(tixing).ExecuteCommandAsync();
                }
 
                return await _client.Insertable(DeliverPlan).ExecuteCommandAsync();
 
            }
            catch (Exception)
            {
 
                throw;
            }
            
           
        }
 
 
 
        /// <summary>
        /// 获取送货单
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<DeliverOderPageRet> GetDeliverPlans(DeliverPlanSearchParam Param)
        {
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
 
            Expression<Func<OA_DeliverPlanPaiche, bool>> SearchList = (x) => true;
            SearchList = SearchList.And(x => x.FirmId == _oAServices.firmId);
            //SearchList = SearchList.And(x => x.Creater == Permissions.MemberId);//只看自己
            SearchList = SearchList.And(x => x.ShifouDelivery != 2);//过滤有效
            if (Param.DeliverKeyID != null)
            {
                SearchList = SearchList.And(x => x.DriverId == Param.DeliverKeyID);
            }
            //客户名称
            if (!string.IsNullOrEmpty(Param.CorporateClient))
            {
                SearchList = SearchList.And(x => x.CompanyName.Contains(Param.CorporateClient));
            }
            if (Param.TimeStart != null)
            {
                SearchList = SearchList.And(x => x.DeliverTime >= Param.TimeStart.Value.Date);
            }
            if (Param.TimeEnd != null)
            {
                SearchList = SearchList.And(x => x.DeliverTime < Param.TimeEnd.Value.Date.AddDays(1));
            }
            if (Param.DeliveredState != null)
            {
                if (Param.DeliveredState != DeliveredType.Delivered)
                {
                    SearchList = SearchList.And(x => x.Deliveredstatus != DeliveredType.Delivered);
                }
                else
                {
                    SearchList = SearchList.And(x => x.Deliveredstatus == DeliveredType.Delivered);
                }
            }
 
            //强制增加员工过滤
            RefAsync<int> totle = 0;
            var data = await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x => x.Driver).Includes(x => x.SentStaff).Includes(x=>x.DeliverPlans)
                .Where(SearchList).OrderBy(x => x.DeliverTime).OrderBy(x => x.Sort).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
 
            Param.page.TotalCount = totle;
            return new DeliverOderPageRet
 
            {
                Data = data,
                page = Param.page,
 
            };
 
 
        }
 
        /// <summary>
        /// 修改订单
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        public async Task<bool> UpDataDeliverPlans(OA_DeliverPlanPaiche Param)
        {
 
            if (Param.Keyid == null)
                throw Oops.Oh("ID错误");
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            var data = await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x=>x.DeliverPlans).Where(x => x.ShifouDelivery != 2 && x.Keyid == Param.Keyid).FirstAsync();
            data.LastUpdateTime = DateTime.Now;
            data.Updater = Permissions.MemberId;
 
            if (data.DriverId != Param.DriverId)
            {
                data.DriverId = Param.DriverId;
                var car = await _client.Queryable<OA_CarManage>().Where(x => x.StaffID == Param.DriverId && x.MemberID == _oAServices.firmId).FirstAsync();
                data.CarId = car == null ? 0 : car.Keyid;
 
                //foreach (var item in data.DeliverPlans)
                //{
                //    item.DriverId = Param.DriverId;
                //    item.CarId = car == null ? 0 : car.Keyid;
                //    item.Updater = Permissions.MemberId;
                //    item.LastUpdateTime = DateTime.Now;
                //    item.DeliverTime = Param.DeliverTime;
 
                //}
            }
 
   
            data.DeliverTime = Param.DeliverTime;
            data.Remark = Param.Remark;
 
            data.CompanyName = Param.CompanyName;
            data.Dizhi = Param.Dizhi;
            data.Lianxiren = Param.Lianxiren;
            data.Dianhua = Param.Dianhua;
            data.Sort = Param.Sort;
            if (Param.Attachments != null)
                foreach (var item in Param.Attachments)
                {
                    if (item.Keyid > 0)
                    {
 
                    }
                    else
                    {
                        item.OA_Id = data.Keyid;
                        item.CreateTime = DateTime.Now;
                        item.Operator = Permissions.Name;
                    }
                }
            data.Attachments = Param.Attachments;
 
            return await _client.UpdateNav(data).Include(x => x.Attachments).ExecuteCommandAsync();
 
 
 
        }
 
        /// <summary>
        /// 撤销订单
        /// </summary>
        /// <param name="KeyId"></param>
        /// <returns></returns>
        public async Task<int > UndoDeliverPlans(Guid KeyId)
        {
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            var data= await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x=>x.DeliverPlans).Includes(x=>x.DelvceTiXing).Where(x=>x.Keyid == KeyId).FirstAsync();
 
            if (data != null)
            {
                if (data.Deliveredstatus != DeliveredType.Delivered)
                {
                    await _client.AsTenant().BeginTranAsync();
                    try
                    {
                        if (data.DelvceTiXing != null)
                        {
                            data.DelvceTiXing.Chulistatus = AppointmentDeliverState.unAccept;
                            data.DelvceTiXing.LastUpdateTime = DateTime.Now;
                            data.DelvceTiXing.Updater = Permissions.MemberId;
                            data.DelvceTiXing.ChuliTime = DateTime.Now;
                            data.DelvceTiXing.ChuliRen = Permissions.MemberId;
                            await _client.Updateable(data.DelvceTiXing).ExecuteCommandAsync();
                        }
                        if (data.DeliverPlans != null)
                        {
                            foreach (var item in data.DeliverPlans)
                            {
                                item.DriverId = 0;
                                item.DeliverPlanPaicheid = Guid.Empty;
                                item.Deliveredstatus = DeliveredType.Undeliver;                                
                                item.Updater = Permissions.MemberId;
                                item.LastUpdateTime = DateTime.Now;
                            }
                            await _client.Updateable(data.DeliverPlans).ExecuteCommandAsync();
                        }
 
 
                         var a = await _client.Deleteable(data).ExecuteCommandAsync();
 
                        await _client.AsTenant().CommitTranAsync();
                        return a;
                    }
 
 
                    catch (Exception)
                    {
                        await _client.AsTenant().RollbackTranAsync();
                        throw;
                    }
                }
                else
 
                {
                    throw Oops.Oh("配送已完成,无法撤销");
                }
 
            }
            else
                throw Oops.Oh("没有找到订单");
        }
        /// <summary>
        /// 修改订单 弃用
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        [Obsolete]
        public async Task<bool> SortDeliverPlans(SortPlanIn Param)
        {
            throw Oops.Oh("已经弃用");
          
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
 
            var Active = await _client.Queryable<OA_DeliverPlan>().Where(x => x.Keyid == Param.ActiveKeyId).FirstAsync();
            if (Active == null)
                throw Oops.Oh("当前无法排序");
 
            var ActiveList = await _client.Queryable<OA_DeliverPlan>().Where(x => x.CreateTime < Active.CreateTime.Value.AddDays(1).Date && x.CreateTime > Active.CreateTime.Value.Date).ToListAsync();
 
            return true;
 
 
        }
 
        /// <summary>
        /// 获取送货单详情
        /// </summary>
        /// <param name="KeyId"></param>
        /// <returns></returns>
        public async Task<OA_DeliverPlanPaiche> GetDeliverPlanInfo(Guid KeyId)
        {
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
            return await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x => x.Attachments).Includes(x => x.Driver).Includes(x => x.Manager).Includes(x=>x.DeliverPlans)
                .Where(x => x.Keyid == KeyId && x.ShifouDelivery != 2).FirstAsync();
 
        }
 
 
        /// <summary>
        /// 打卡记录详情
        /// </summary>
        public async Task<OA_DriverRecord> GetDriverRecordInfo(Guid Id)
        {
 
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
 
            var data = await _client.Queryable<OA_DriverRecord>()
                .Includes(x=>x.Car)
                   .Includes(x => x.Attachments)
                   .Includes(x => x.CarConditionAttachments)
                   .Where(x =>  x.Id == Id).FirstAsync();
            if (data == null)
                throw Oops.Oh("没有权限");
            return data;
 
        }
        /// <summary>
        /// 获取车辆打卡记录
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<DeliverRecordPageRet> GetDriverRecords(DeliverRecordSearchParam Param)
        {
            if (!await CheckRols())
            {
                throw Oops.Oh("没有权限");
            }
 
            Expression<Func<OA_DriverRecord, bool>> SearchList = (x) => true;
            SearchList = SearchList.And(x => x.ClockType != DriverClockType.RoughDraft);//不看草稿  
            if (Param.CarID != null)
            {
                SearchList = SearchList.And(x => x.CarID == Param.CarID);
            }
 
            if (Param.TimeStart != null)
            {
                SearchList = SearchList.And(x => x.CreatTime >= Param.TimeStart.Value.Date);
            }
            if (Param.TimeEnd != null)
            {
                SearchList = SearchList.And(x => x.CreatTime < Param.TimeEnd.Value.Date.AddDays(1));
            }
            if (Param.ClockType != null)
            {
 
                SearchList = SearchList.And(x => x.ClockType == Param.ClockType);
 
            }
 
            //强制增加员工过滤
            RefAsync<int> totle = 0;
            var data = await _client.Queryable<OA_DriverRecord>().Includes(x=>x.Car)
                .Where(SearchList).OrderByDescending(x => x.CreatTime.Date).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
 
            Param.page.TotalCount = totle;
           // var count = await _client.Queryable<OA_DriverRecord>().Where(x => x.CreatTime.Date == DateTime.Now.Date).CountAsync();
 
            return new DeliverRecordPageRet
 
            {
                Data = data,
                page = Param.page
                
 
            };
 
 
        }
        /// <summary>
        /// 判断是否具有权限
        /// </summary>
        /// <returns></returns>
        private async Task<bool> CheckRols()
        {
            var pr = await _oAServices.GetOAPermissions();
            Permissions = pr;
            if (pr != null && pr.MemberId != null)
            {
                if (pr.BF_IsDeliverManage == true)
 
 
                    return true;
                else
                    return false;
 
            }
            else
                return false;
        }
 
 
 
        /// <summary>
        /// 生成sn号
        /// </summary>
        /// <returns></returns>
        private async Task<string> CreatDeliverPlanSn()
        {
            // var sn = await _client.Queryable<OA_DeliverPlan>().Where(x => x.CreateTime >= DateTime.Now.Date && x.CreateTime < DateTime.Now.AddDays(1).Date).OrderByDescending(x => x.SellerOrderId).Select(x => x.SellerOrderId).FirstAsync();
 
            var sn = await _client.Queryable<OA_DeliverPlanPaiche>().Where(x => x.CreateTime.Value.Date == DateTime.Now.Date).OrderByDescending(x => x.SellerOrderId).Select(x => x.SellerOrderId).FirstAsync();
            if (sn != null)
            {
                try
                {
                    var datasn = sn.Length > 3
    ? sn.Substring(sn.Length - 3)
    : sn; ;
                    int data = datasn.toInt();
                    data += 1;
                    var str = DateTime.Now.ToString("yyyyMMdd");
                    return DateTime.Now.ToString("yyyyMMdd") + data.ToString("D3");
                }
                catch (Exception)
                {
 
                    return DateTime.Now.ToString("yyyyMMdd") + 1.ToString("D3");
                }
 
            }
 
            return DateTime.Now.ToString("yyyymmdd") + 1.ToString("D3");
        }
 
    }
    public class ApoointmentDeliverSearchParam
    {
        /// <summary>
        /// 起始时间
        /// </summary>
        public DateTime? TimeStart { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? TimeEnd { get; set; }
 
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
 
        /// <summary>
        /// 员工ID
        /// </summary>
        public Guid? MemberId { get; set; }
 
        /// <summary>
        /// 受理状态
        /// </summary>
        public AppointmentDeliverState? DeliverState { get; set; }
 
        /// <summary>
        /// 页面参数
        /// </summary>
        public PageModel page { get; set; }
    }
 
 
    public class DeliverPlanSearchParam
    {
 
        /// <summary>
        /// 起始时间
        /// </summary>
        public DateTime? TimeStart { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? TimeEnd { get; set; }
 
        /// <summary>
        /// 司机KeyID
        /// </summary>
        public int? DeliverKeyID { get; set; }
 
 
        /// <summary>
        /// 客户名称
        /// </summary>
        public string CorporateClient { get; set; }
 
        /// <summary>
        /// 配送状态
        /// </summary>
        public DeliveredType? DeliveredState { get; set; }
        /// <summary>
        /// 页面参数
        /// </summary>
        public PageModel page { get; set; }
    }
 
    /// <summary>
    /// 拖动时最后变量
    /// </summary>
    public class SortPlanIn()
    {
        /// <summary>
        /// 拖动的KeyID
        /// </summary>
        public Guid ActiveKeyId { get; set; }
 
 
        /// <summary>
        /// 下一层的项的KeyID
        /// </summary>
        public Guid LowerKeyId { get; set; }
 
 
        /// <summary>
        /// 上一层的邻居的KeyId
        /// </summary>
        public Guid SuperiorKeyId { get; set; }
        /// <summary>
        /// 拖动方向
        /// </summary>
        public DirectionalType Directional { get; set; }
 
    }
 
    public enum DirectionalType
    {
        /// <summary>
        /// 向上拖动
        /// </summary>
        Up,
        /// <summary>
        /// 向下拖动
        /// </summary>
        Down,
    }
}