| | |
| | | using ECTESTOA; |
| | | using EzCoreNet.Redis; |
| | | using Furion.LinqBuilder; |
| | | using Microsoft.AspNetCore.Http.HttpResults; |
| | | using Models; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | 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);//过滤有效 |
| | |
| | | } |
| | | 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) |
| | | { |
| | |
| | | |
| | | //强制增加员工过滤 |
| | | 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; |
| | | |
| | |
| | | /// </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(); |
| | | |
| | | } |
| | |
| | | { |
| | | 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) |
| | |
| | | /// </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错误"); |
| | |
| | | { |
| | | 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) |
| | | { |
| | |
| | | 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> |
| | | /// 获取草稿记录 没有代表没有 |
| | | /// </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> |
| | |
| | | { |
| | | 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("有附件地址为空"); |
| | |
| | | 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)) |
| | |
| | | |
| | | |
| | | } |
| | | 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) |
| | | //分开导航会产生冲突应该sqlsun的bug |
| | | // .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> |
| | |
| | | } |
| | | |
| | | } |
| | | /// <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; |
| | | } |
| | | } |