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/CyOSSDriver.cs |  382 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 363 insertions(+), 19 deletions(-)

diff --git a/cylsg/cylsg.Application/CyOS/CyOSSDriver.cs b/cylsg/cylsg.Application/CyOS/CyOSSDriver.cs
index 0c3e108..ddd0db6 100644
--- a/cylsg/cylsg.Application/CyOS/CyOSSDriver.cs
+++ b/cylsg/cylsg.Application/CyOS/CyOSSDriver.cs
@@ -3,6 +3,7 @@
 using ECTESTOA;
 using EzCoreNet.Redis;
 using Furion.LinqBuilder;
+using Microsoft.AspNetCore.Http.HttpResults;
 using Models;
 using System;
 using System.Collections.Generic;
@@ -43,7 +44,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.DriverId == Permissions.KeyId);//鍙湅鑷繁
             SearchList = SearchList.And(x => x.ShifouDelivery != 2);//杩囨护鏈夋晥
@@ -58,11 +59,11 @@
             }
             if (Param.TimeStart != null)
             {
-                SearchList = SearchList.And(x => x.CreateTime > Param.TimeStart);
+                SearchList = SearchList.And(x => x.DeliverTime >= Param.TimeStart.Value.Date);
             }
             if (Param.TimeEnd != null)
             {
-                SearchList = SearchList.And(x => x.CreateTime < Param.TimeEnd.Value.AddDays(1));
+                SearchList = SearchList.And(x => x.DeliverTime < Param.TimeEnd.Value.Date.AddDays(1));
             }
             if (Param.DeliveredState != null)
             {
@@ -78,8 +79,8 @@
 
             //寮哄埗澧炲姞鍛樺伐杩囨护
             RefAsync<int> totle = 0;
-            var data = await _client.Queryable<OA_DeliverPlan>().Includes(x=>x.SentStaff)
-                .Where(SearchList).OrderByDescending(x => x.CreateTime.Value.Date).OrderBy(x => SqlFunc.Asc(x.Sort)).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
+            var data = await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x=>x.Manager)
+                .Where(SearchList).OrderByDescending(x => x.DeliverTime.Value.Date).OrderBy(x => SqlFunc.Asc(x.Sort)).ToPageListAsync(Param.page.PageIndex, Param.page.PageSize, totle);
 
             Param.page.TotalCount = totle;
 
@@ -99,14 +100,14 @@
         /// </summary>
         /// <param name="Param"></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.Attachments.Where(y=>y.AttachmentType==3).ToList()).Includes(x=>x.Manager).Includes(x=>x.SentStaff)
+            return await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x=>x.Attachments).Includes(x=>x.Manager).Includes(x=>x.DeliverPlans)
                 .Where(x => x.DriverId == Permissions.KeyId && x.Keyid == KeyId&&x.ShifouDelivery!=2).FirstAsync();
 
         }
@@ -124,7 +125,7 @@
             {
                 throw Oops.Oh("娌℃湁鏉冮檺");
             }
-             var a= await _client.Queryable<OA_DeliverPlan>().Where(x => x.DriverId == Permissions.KeyId && x.Keyid == KeyId && x.ShifouDelivery != 2).FirstAsync();
+             var a= await _client.Queryable<OA_DeliverPlanPaiche>().Where(x => x.DriverId == Permissions.KeyId && x.Keyid == KeyId && x.ShifouDelivery != 2).FirstAsync();
             if(a==null)
                 throw Oops.Oh("娌℃湁鏉冮檺");
             if(a.Deliveredstatus!= DeliveredType.Undeliver)
@@ -146,7 +147,7 @@
         /// </summary>
         /// <param name="Param"></param>
         /// <returns></returns>
-        public async Task<bool> FinishDeliverPlan(OA_DeliverPlan Param)
+        public async Task<bool> FinishDeliverPlan(OA_DeliverPlanPaiche Param)
         {
             if(Param.Keyid==null)
                 throw Oops.Oh("ID閿欒");
@@ -157,12 +158,19 @@
             {
                 throw Oops.Oh("娌℃湁鏉冮檺");
             }
-            var a = await _client.Queryable<OA_DeliverPlan>().Where(x => x.DriverId == Permissions.KeyId && x.Keyid == Param.Keyid && x.ShifouDelivery != 2).FirstAsync();
+            var a = await _client.Queryable<OA_DeliverPlanPaiche>().Includes(x=>x.DeliverPlans).Where(x => x.DriverId == Permissions.KeyId && x.Keyid == Param.Keyid && x.ShifouDelivery != 2).FirstAsync();
             if (a == null)
                 throw Oops.Oh("娌℃湁鏉冮檺");
             if (a.Deliveredstatus != DeliveredType.Deliver)
             {
                 throw Oops.Oh("璁㈠崟鐘舵�佺粨鏉�");
+            }
+            foreach (var item in a.DeliverPlans)
+            {
+                //鍚屾 閫佽揣鍗曠姸鎬�
+                item.Updater = Permissions.MemberId;
+                item.LastUpdateTime = DateTime.Now;
+                item.Deliveredstatus= Param.Deliveredstatus;
             }
             foreach (var item in Param.Attachments)
             {
@@ -200,14 +208,124 @@
             a.Wentifankui = Param.Wentifankui;
             a.Deliveredstatus= Param.Deliveredstatus;
             a.Attachments = Param.Attachments;
+
             return await _client.UpdateNav(a).Include(x=>x.Attachments,new SqlSugar.UpdateNavOptions()
                 { 
                    OneToManyInsertOrUpdate = true,//閰嶇疆鍚敤 鎻掑叆銆佹洿鏂版垨鍒犻櫎妯″紡
-                }).ExecuteCommandAsync();
+                }).Include(x=>x.DeliverPlans,new UpdateNavOptions()
+                {
+                    OneToManyInsertOrUpdate=true,
+                }
+                ).ExecuteCommandAsync();
+
+            //await _client.AsTenant().BeginTranAsync();
+            //try
+            //{
+            //    await _client.UpdateNav(a).Include(x => x.Attachments, new SqlSugar.UpdateNavOptions()
+            //    {
+            //        OneToManyInsertOrUpdate = true,//閰嶇疆鍚敤 鎻掑叆銆佹洿鏂版垨鍒犻櫎妯″紡
+            //    }).ExecuteCommandAsync();
+            //    if (a.DeliverPlans?.Count > 0)
+            //        await _client.Updateable(a.DeliverPlans).ExecuteCommandAsync();
+            //    await _client.AsTenant().CommitTranAsync();
+
+            //}
+            //catch (Exception)
+            //{
+            //    await _client.AsTenant().RollbackTranAsync();
+            //    throw;
+            //}
+
+            //return true;
+        }
+        /// <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.CreaterID == Permissions.MemberId);//鍙湅鑷繁
+            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).Mapper((x)=>
+                {
+                    if (x.CreatTime.AddMinutes(30) < DateTime.Now)
+                        x.CanEdit = true;
+                    else
+                        x.CanEdit = false;
+
+                })
+                .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 && x.ClockType != DriverClockType.RoughDraft&& x.CreaterID==Permissions.MemberId).CountAsync();
+            return new DeliverRecordPageRet
+
+            {
+                Data = data,
+                page = Param.page,
+                 NextClockType= count switch
+                 {
+                      1=> DriverClockType.Clockout,
+                      2=> DriverClockType.Unknown,
+                      0=> DriverClockType.ClockIn,
+                      _=> DriverClockType.Unknown
+                 }
+
+            };
 
 
         }
 
+        /// <summary>
+        /// 鑾峰彇鑽夌璁板綍   娌℃湁浠h〃娌℃湁
+        /// </summary>     
+        /// <returns></returns>
+        
+        public async Task<OA_DriverRecord> GetClockRoughDraft()
+        {
+            if (!await CheckRols())
+            {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+          return await _client.Queryable<OA_DriverRecord>()
+                .Where(x => x.CreaterID == Permissions.MemberId 
+                && x.ClockType == DriverClockType.RoughDraft 
+                && x.CreatTime.Date == DateTime.Now.Date).Includes(x=>x.Attachments).Includes(x=>x.CarConditionAttachments).FirstAsync();
+
+
+        }
         /// <summary>
         /// 涓婄彮鎵撳崱 涓婁笅鐝墦鍗¢兘璋冪敤涓�涓瓧娈�
         /// </summary>     
@@ -217,10 +335,44 @@
         {
             if (Param.ClockType == DriverClockType.Unknown)
                 throw Oops.Oh("绫诲瀷涓嶅彲涓烘湭鐭�");
-            Param.Id =  Guid.NewGuid();
-            if (Param.Attachments!=null)
-            foreach (var item in Param.Attachments)
+            if (!await CheckRols())
             {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+          
+          if (Param.ClockType!= DriverClockType.RoughDraft)
+            {
+             var clockid=  await   _client.Queryable<OA_DriverRecord>().Where(x => x.CreaterID == Permissions.MemberId
+                && x.CreatTime.Date == DateTime.Now.Date
+                && x.ClockType == Param.ClockType
+                ).Select(x => x.Id).FirstAsync();
+                if(clockid!=null)
+                {
+                    throw Oops.Oh("浠婂ぉ宸茬粡鎵撹繃璇ョ被鍨嬬殑鍗′簡");
+                }
+            }
+            var carId = await _client.Queryable<OA_CarManage>().Where(x => x.StaffID == Permissions.KeyId && x.MemberID == _oAServices.firmId).Select(x => x.Keyid).FirstAsync();
+            if(carId==null||carId==0)
+            {
+                throw Oops.Oh("璇ュ徃鏈烘湭鍒嗛厤杞﹁締锛屼笉闇�瑕佹墦鍗�");
+            }
+            OA_DriverRecord data = null;
+          
+             data=   await  _client.Queryable<OA_DriverRecord>().Where(x =>
+             //x.Id == Param.Id&&  鏈�澶氭瘡澶╁彧鑳芥湁涓�涓崏绋�
+              x.CreatTime.Date == DateTime.Now.Date
+             && x.CreaterID == Permissions.MemberId 
+             && x.ClockType == DriverClockType.RoughDraft).FirstAsync();
+
+
+            
+             
+            
+
+            Param.CarID = carId;
+            if (Param.Attachments != null)
+                foreach (var item in Param.Attachments)
+                {
                     if (string.IsNullOrWhiteSpace(item.PlanAttachment))
                     {
                         throw Oops.Oh("鏈夐檮浠跺湴鍧�涓虹┖");
@@ -233,13 +385,14 @@
                         throw Oops.Oh("璇疯緭鍏ユ纭殑闄勪欢鍦板潃");
 
                     }
-                    item.AttachmentType =4;
+                    item.AttachmentType = 4;
                     item.CreateTime = DateTime.Now;
                     item.Operator = Permissions.Name;
-                    
-                    
+
+
+
                 }
-             if(Param.CarConditionAttachments!=null)
+            if (Param.CarConditionAttachments != null)
                 foreach (var item in Param.CarConditionAttachments)
                 {
                     if (string.IsNullOrWhiteSpace(item.PlanAttachment))
@@ -260,11 +413,147 @@
 
 
                 }
+            Param.EmptyCause = Param.EmptyCause ?? "";
+            Param.CarCondition = Param.CarCondition ?? "";
+            Param.Remark = Param.Remark ?? "";
             Param.CreatTime = DateTime.Now;
             Param.CreaterID = Permissions.MemberId;
             Param.Creater = Permissions.Name;
-           return await  _client.InsertNav(Param).Include(x => x.Attachments).Include(x => x.Attachments).ExecuteCommandAsync();
+
+            if (data == null)
+            {
+                //娌℃湁鍗曞瓙
+
+                Param.Id = Guid.NewGuid();
+                if (!(carId > 0))
+                {
+
+                    throw Oops.Oh("娌℃壘鍒板尮閰嶈溅杈�");
+                }
+               
+                return await _client.InsertNav(Param).Include(x => x.Attachments).Include(x => x.CarConditionAttachments).ExecuteCommandAsync();
+            }
+
            
+
+            else
+            {
+                data.CarID = Param.CarID;
+                data.CreatTime= Param.CreatTime;
+
+                data.Attachments = Param.Attachments;//瀵艰埅鏇磋鍒嗙被鏉′欢涓嶈捣浣滅敤锛岃繖閲屾洿鏂板皢 杩欎袱涓悎骞舵搷浣�
+              
+                data.CarCondition=Param.CarCondition;
+                data.CarConditionAttachments = Param.CarConditionAttachments;
+                if (data.CarConditionAttachments == null)
+                    data.CarConditionAttachments = new List<OA_attachment>();
+                if (data.Attachments != null)
+                    data.CarConditionAttachments.AddRange(data.Attachments);
+                data.ClockType = Param.ClockType;
+                data.EmptyCause = Param.EmptyCause;
+                return await _client.UpdateNav(data)
+                   //鍒嗗紑瀵艰埅浼氫骇鐢熷啿绐佸簲璇qlsun鐨刡ug
+                //    .Include(x => x.Attachments,new UpdateNavOptions
+                //{
+                //     OneToManyInsertOrUpdate = true,
+                //})
+                    .Include(x => x.CarConditionAttachments,new UpdateNavOptions
+                {
+                    OneToManyInsertOrUpdate = true,
+                }).ExecuteCommandAsync();
+            }
+           
+
+        }
+
+
+        /// <summary>
+        /// 淇敼鎵撳崱璁板綍 鏀寔鍗婂皬鏃跺唴淇敼璁板綍
+        /// </summary>
+        public async Task<bool > UpdataDriverRecord(OA_DriverRecord Param)
+        {
+            if (!await CheckRols())
+            {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+
+            var data = await _client.Queryable<OA_DriverRecord>()
+                   .Includes(x => x.Attachments)
+                   .Includes(x => x.CarConditionAttachments)
+                   .Where(x => x.CreaterID == Permissions.MemberId && x.Id == Param.Id).FirstAsync();
+            if (data != null)
+                throw Oops.Oh("娌℃湁鏉冮檺");
+
+            if(data.CreatTime.AddMinutes(30)<DateTime.Now)
+            {
+                throw Oops.Oh("鍙兘鍦ㄥ崐灏忔椂涔嬪唴淇敼");
+            }
+
+            if(Param.Attachments!=null)
+            {
+                foreach (var attachment in Param.Attachments)
+                {
+                    if (attachment.Keyid > 0)
+                        continue;
+                    else
+                    {
+                        attachment.AttachmentType = 4;
+                        attachment.CreateTime = DateTime.Now;
+                        attachment.Operator = Permissions.Name;
+                        
+                    }
+                }
+            }
+
+
+            if (Param.CarConditionAttachments != null)
+            {
+                foreach (var attachment in Param.CarConditionAttachments)
+                {
+                    if (attachment.Keyid > 0)
+                        continue;
+                    else
+                    {
+                        attachment.AttachmentType = 5;
+                        attachment.CreateTime = DateTime.Now;
+                        attachment.Operator = Permissions.Name;
+
+                    }
+                }
+            }
+
+            data.Attachments = Param.Attachments;
+            data.CarConditionAttachments = Param.CarConditionAttachments;
+            data.CarCondition = Param.CarCondition;
+        return  await   _client.UpdateNav(data).Include(x => x.Attachments, new UpdateNavOptions
+            {
+                OneToManyInsertOrUpdate = true,
+            }).Include(x => x.CarConditionAttachments, new UpdateNavOptions
+            {
+                OneToManyInsertOrUpdate = true,
+            }).ExecuteCommandAsync();
+            
+        }
+
+        /// <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.CreaterID == Permissions.MemberId&&x.Id== Id).FirstAsync();
+            if (data == null)
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            return data;
 
         }
         /// <summary>
@@ -290,4 +579,59 @@
         }
 
     }
+    /// <summary>
+    /// 鍙告満鎵撳崱璁板綍鎼滅储閫夐」
+    /// </summary>
+    public class DeliverRecordSearchParam
+    {
+        /// <summary>
+        /// 璧峰鏃堕棿
+        /// </summary>
+        public DateTime? TimeStart { get; set; }
+        /// <summary>
+        /// 缁撴潫鏃堕棿
+        /// </summary>
+        public DateTime? TimeEnd { get; set; }
+
+        /// <summary>
+        /// 鍙告満KeyID
+        /// </summary>
+        public int? DeliverMemudID { get; set; }
+
+
+        /// <summary>
+        /// 杞﹁締ID
+        /// </summary>
+        public int?  CarID { get; set; }
+
+        /// <summary>
+        /// 鎵撳崱 绫诲瀷
+        /// </summary>
+        public DriverClockType? ClockType { get; set; }
+        /// <summary>
+        /// 椤甸潰鍙傛暟
+        /// </summary>
+        public PageModel page { get; set; }
+    }
+
+    /// <summary>
+    /// 鎵撳崱璁板綍杈撳嚭
+    /// </summary>
+    public class DeliverRecordPageRet
+    {
+        /// <summary>
+        /// 鏁版嵁鍒楄〃
+        /// </summary>
+        public List<OA_DriverRecord> Data { get; set; }
+
+        /// <summary>
+        /// 椤甸潰鍙傛暟
+        /// </summary>
+        public PageModel page { get; set; }
+
+        /// <summary>
+        /// 涓嬩竴娆℃墦鍗$姸鎬� 涓虹┖鏃朵笉鏄剧ず鎸夐挳 
+        /// </summary>
+        public DriverClockType? NextClockType { get; set; } = null;
+    }
 }

--
Gitblit v1.9.1