using HL_FristAidPlatform_Help; using HL_FristAidPlatform_IDataBase; using HL_FristAidPlatform_Models; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; namespace HL_FristAidPlatform_DataBase { /// /// 车辆暂调用恢复调用流水记录 /// public class T_Service_FirstAid_VehicleCallRunningDB : BaseDB, IT_Service_FirstAid_VehicleCallRunning { public SqlSugarClient db = GetClient(); /// /// 车辆暂停流水记录 /// /// 医院guid /// 站guid /// /// /// 车辆guid /// pageIndex /// pageSize /// public TableModel GetList(string guid, string hospitalGuid, string time1, string time2, string vehicleGuid, int pageIndex, int pageSize) { int total = 0; List list = new List(); var hospital = db.Queryable().Where(it => it.GUID == guid).First(); if (string.IsNullOrEmpty(hospital.ParentGUID))//总站或调度中心 { list = db.Queryable( (a, b, c, d, e, h, i) => new JoinQueryInfos( JoinType.Inner, a.TaskGUID == b.GUID, JoinType.Inner, b.AlarmGuid == c.GUID, JoinType.Inner, c.HospitalGuid == d.GUID, JoinType.Inner, b.VehicleGUID == e.GUID, JoinType.Inner, a.UserId == h.ID, JoinType.Left, a.RUserId == i.ID)) .Where((a, b, c, d, e) => c.CallHospitalGuid == guid) .WhereIF(!SqlFunc.IsNullOrEmpty(hospitalGuid), (a, b, c, d, e) => c.HospitalGuid == hospitalGuid) .WhereIF(!SqlFunc.IsNullOrEmpty(time1), (a, b, c, d, e) => a.PauseTime >= Convert.ToDateTime(time1)) .WhereIF(!SqlFunc.IsNullOrEmpty(time2), (a, b, c, d, e) => a.PauseTime <= Convert.ToDateTime(time2).AddDays(1)) .WhereIF(!SqlFunc.IsNullOrEmpty(vehicleGuid), (a, b, c, d, e) => b.VehicleGUID == vehicleGuid) .OrderBy((a, b, c, d, e, h) => a.Reason, OrderByType.Asc) .Select((a, b, c, d, e, h, i) => new VehicleCallRunningModel() { HospitalName = d.Name, PlateNumber = e.PlateNumber, PauseTime = a.PauseTime.ToString("yyyy-MM-dd HH:mm:ss"), Reson = a.Reason, UserName = h.FullName, RecoveryTime = Convert.ToDateTime(a.RecoveryTime).ToString("yyyy-MM-dd HH:mm:ss"), RUserName = i.FullName }).ToPageList(pageIndex, pageSize, ref total); } else //分站 { list = db.Queryable( (a, b, c, d, e, h, i) => new JoinQueryInfos( JoinType.Inner, a.TaskGUID == b.GUID, JoinType.Inner, b.AlarmGuid == c.GUID, JoinType.Inner, c.HospitalGuid == d.GUID, JoinType.Inner, b.VehicleGUID == e.GUID, JoinType.Inner, a.UserId == h.ID, JoinType.Left, a.RUserId == i.ID)) .Where((a, b, c, d, e) => c.HospitalGuid == guid) .WhereIF(!SqlFunc.IsNullOrEmpty(hospitalGuid), (a, b, c, d, e) => c.HospitalGuid == hospitalGuid) .WhereIF(!SqlFunc.IsNullOrEmpty(time1), (a, b, c, d, e) => a.PauseTime >= Convert.ToDateTime(time1)) .WhereIF(!SqlFunc.IsNullOrEmpty(time2), (a, b, c, d, e) => a.PauseTime <= Convert.ToDateTime(time2).AddDays(1)) .WhereIF(!SqlFunc.IsNullOrEmpty(vehicleGuid), (a, b, c, d, e) => b.VehicleGUID == vehicleGuid) .OrderBy((a, b, c, d, e, h) => a.Reason, OrderByType.Asc) .Select((a, b, c, d, e, h, i) => new VehicleCallRunningModel() { HospitalName = d.Name, PlateNumber = e.PlateNumber, PauseTime = a.PauseTime.ToString("yyyy-MM-dd HH:mm:ss"), Reson = a.Reason, UserName = h.FullName, RecoveryTime = Convert.ToDateTime(a.RecoveryTime).ToString("yyyy-MM-dd HH:mm:ss"), RUserName = i.FullName }).ToPageList(pageIndex, pageSize, ref total); } total = list.Count(); TableModel t = new TableModel(); t.Code = 0; t.PageCount = list.Count(); t.TotalNumber = total; t.Data = list; t.Msg = "成功"; return t; } public T_Service_FirstAid_VehicleCallRunning GetByTaskGUID(string guid) { return db.Queryable().Where(it => it.TaskGUID == guid && it.DeleteFlag == 0).First(); } /// /// 保存暂停流水记录 /// /// public bool SaveVehicleCallRunning(T_Service_FirstAid_VehicleCallRunning model) { if (!SqlFunc.IsNullOrEmpty(model.GUID)) { model.RecoveryTime = DateTime.Now; return db.Updateable(model).UpdateColumns(it => new { it.RecoveryTime, it.RUserId }).ExecuteCommand() == 1 ? true : false; } else { model.GUID = Guid.NewGuid().ToString(); return db.Insertable(model).IgnoreColumns(ignoreNullColumn: true).ExecuteCommand() == 1 ? true : false; } } } }