From 16b063870156db78148440971ab46c649e3e6018 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期三, 19 三月 2025 11:44:22 +0800
Subject: [PATCH] 测试定版,

---
 cylsg/cylsg.Application/CyOS/CyOsDeliverManage.cs |  274 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 250 insertions(+), 24 deletions(-)

diff --git a/cylsg/cylsg.Application/CyOS/CyOsDeliverManage.cs b/cylsg/cylsg.Application/CyOS/CyOsDeliverManage.cs
index b330891..2389bff 100644
--- a/cylsg/cylsg.Application/CyOS/CyOsDeliverManage.cs
+++ b/cylsg/cylsg.Application/CyOS/CyOsDeliverManage.cs
@@ -5,12 +5,14 @@
 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;
 
 namespace cylsg.Application.CyOS
 {
@@ -34,9 +36,29 @@
         }
         [HttpGet]
         [AllowAnonymous]
-        public async Task<string> testc()
+        public async Task<OA_DriverRecord> testc()
         {
-            return await CreatDeliverPlanSn();
+            OA_DriverRecord data = null;
+
+            data = await _client.Queryable<OA_DriverRecord>().Where(x =>
+             x.Id == new Guid("BE15D584-DFE3-438D-863B-705DB1AB14ED")
+           ).Includes(x=>x.Attachments).FirstAsync();
+          
+            data.Attachments?.Add(new OA_attachment
+            {
+                PlanAttachment = "1111",
+                AttachmentType = 4,
+                Operator= "sdasd"
+            });
+            data.CarConditionAttachments = null;
+            await _client.UpdateNav(data).Include(x => x.CarConditionAttachments,new UpdateNavOptions
+            {
+                OneToManyInsertOrUpdate=true,
+                 
+            }).ExecuteCommandAsync();
+
+            return await _client.Queryable<OA_DriverRecord>().Where(x => x.Id == new Guid("BE15D584-DFE3-438D-863B-705DB1AB14ED")).Includes(x => x.Attachments).Includes(x => x.CarConditionAttachments).FirstAsync();
+
         }
 
         /// <summary>
@@ -114,12 +136,14 @@
 
         }
         /// <summary>
-        /// 鍙楃悊        
+        /// 鍙楃悊       寮冪敤锛岀敤  CreatDeliverPlan 浠f浛
         /// </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涓嶈兘涓虹┖");
 
@@ -150,20 +174,41 @@
         /// <param name="Param"> 鍙渶瑕佷紶閫�</param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<int> CreatDeliverPlan(OA_DeliverPlan Param)
+        public async Task<int> CreatDeliverPlan(OA_DeliverPlanPaiche Param)
         {
-            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();
+
 
             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_DeliverPlan DeliverPlan = new OA_DeliverPlan()
+            OA_DeliverPlanPaiche DeliverPlan = new OA_DeliverPlanPaiche()
             {
                 Keyid = Guid.NewGuid(),
                 FirmId = _oAServices.firmId,
@@ -178,7 +223,7 @@
 
 
                 Transferstatus = 1,
-                Sort = 1,
+                Sort = Param.Sort,
                 Creater = Param.Creater ?? Permissions.MemberId,
                 CreateTime = DateTime.Now,
                 DriverId = Param.DriverId,
@@ -192,7 +237,28 @@
                 Lianxiren = Param.Lianxiren,
                 Deliveredstatus = (int)DeliveredType.Undeliver,
                 CompanyName = Param.CompanyName,
-            }; return await _client.Insertable(DeliverPlan).ExecuteCommandAsync();
+
+
+            };
+            try
+            {
+            
+                if (tixing!=null)
+                {
+                    tixing.DeliverPlanPaicheId = DeliverPlan.Keyid;
+                     await _client.Updateable(tixing).ExecuteCommandAsync();
+                }
+
+                return await _client.Insertable(DeliverPlan).ExecuteCommandAsync();
+
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+            
+           
         }
 
 
@@ -210,7 +276,7 @@
                 throw Oops.Oh("娌℃湁鏉冮檺");
             }
 
-            Expression<Func<OA_DeliverPlan, bool>> SearchList = (x) => true;
+            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);//杩囨护鏈夋晥
@@ -225,11 +291,11 @@
             }
             if (Param.TimeStart != null)
             {
-                SearchList = SearchList.And(x => x.DeliverTime > Param.TimeStart);
+                SearchList = SearchList.And(x => x.DeliverTime >= Param.TimeStart.Value.Date);
             }
             if (Param.TimeEnd != null)
             {
-                SearchList = SearchList.And(x => x.DeliverTime < Param.TimeEnd.Value.AddDays(1));
+                SearchList = SearchList.And(x => x.DeliverTime < Param.TimeEnd.Value.Date.AddDays(1));
             }
             if (Param.DeliveredState != null)
             {
@@ -245,8 +311,8 @@
 
             //寮哄埗澧炲姞鍛樺伐杩囨护
             RefAsync<int> totle = 0;
-            var data = await _client.Queryable<OA_DeliverPlan>().Includes(x => x.Driver).Includes(x => x.SentStaff)
-                .Where(SearchList).OrderBy(x => x.Dizhi).OrderBy(x => x.Sort).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
+            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
@@ -265,7 +331,7 @@
         /// </summary>
         /// <param name="Param"></param>
         /// <returns></returns>
-        public async Task<bool> UpDataDeliverPlans(OA_DeliverPlan Param)
+        public async Task<bool> UpDataDeliverPlans(OA_DeliverPlanPaiche Param)
         {
 
             if (Param.Keyid == null)
@@ -274,16 +340,28 @@
             {
                 throw Oops.Oh("娌℃湁鏉冮檺");
             }
-            var data = await _client.Queryable<OA_DeliverPlan>().Where(x => x.ShifouDelivery != 2 && x.Keyid == Param.Keyid).FirstAsync();
+            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;
 
@@ -311,22 +389,91 @@
             return await _client.UpdateNav(data).Include(x => x.Attachments, new UpdateNavOptions()
             {
                 OneToManyInsertOrUpdate = true,
+            }).Include(x => x.DeliverPlans, new UpdateNavOptions()
+            {
+                OneToManyInsertOrUpdate = true,
             }).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())
             {
@@ -349,15 +496,92 @@
         /// </summary>
         /// <param name="KeyId"></param>
         /// <returns></returns>
-        public async Task<OA_DeliverPlan> GetDeliverPlanInfo(Guid KeyId)
+        public async Task<OA_DeliverPlanPaiche> GetDeliverPlanInfo(Guid KeyId)
         {
 
             if (!await CheckRols())
             {
                 throw Oops.Oh("娌℃湁鏉冮檺");
             }
-            return await _client.Queryable<OA_DeliverPlan>().Includes(x => x.SentStaff).Includes(x => x.Attachments).Includes(x => x.Driver).Includes(x => x.Manager)
+            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>
@@ -382,6 +606,8 @@
                 return false;
         }
 
+
+
         /// <summary>
         /// 鐢熸垚sn鍙�
         /// </summary>
@@ -390,7 +616,7 @@
         {
             // 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_DeliverPlan>().Where(x => x.CreateTime.Value.Date == DateTime.Now.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

--
Gitblit v1.9.1