移动系统liao
2025-03-20 63eb28a9ba7aa9c549bc99f9c68d0a4c051453ba
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 代替
        /// </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;
@@ -308,25 +386,88 @@
                }
            data.Attachments = Param.Attachments;
            return await _client.UpdateNav(data).Include(x => x.Attachments, new UpdateNavOptions()
            {
                OneToManyInsertOrUpdate = true,
            }).ExecuteCommandAsync();
            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())
            {
@@ -349,15 +490,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 +600,8 @@
                return false;
        }
        /// <summary>
        /// 生成sn号
        /// </summary>
@@ -390,7 +610,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