/// <summary> /// 添加 队列排班detail表、relation表 /// </summary> /// <param name="hospitalId">医院组织机构代码</param> /// <param name="modalityId">检查类型Id</param> /// <param name="db">数据库连接对象</param> /// <param name="info">队列排班主表</param> private void AddDateFormat(string hospitalId, string modalityId, SqlSugarClient db, t_mt_queuearrangemain info = null) { var mainInfo = new t_mt_queuearrangemain(); var listDetailInfo = new List <t_mt_queuearrangedetail>(); var listRelationInfo = new List <t_mt_queuerearrangerelation>(); try { var firstDay = CommonHandleMethod.GetWeekFirstDayMon(DateTime.Now); var lastDay = CommonHandleMethod.GetWeekLastDaySun(DateTime.Now); //获取该检查类型下的所有队列 var queueList = db.Queryable <t_mt_devicegroup>().Where(n => n.IsDelete == "0").Where(n => n.State == 1).Where(n => n.ClinicID == modalityId).ToList().Select(n => new { QueueId = n.ID, QueueName = n.GroupName }).ToList(); #region "main表" if (info == null) { mainInfo.ID = CommonHandleMethod.GetID(); mainInfo.HospitalID = hospitalId; mainInfo.ModalityID = modalityId; mainInfo.Modality = CommonHandleMethod.GetModalityNameByGUID(modalityId); mainInfo.IsDelete = 0; mainInfo.CreateDT = DateTime.Now.ToDate4(); mainInfo.QueueArrangeStartDate = firstDay.ToDate1(); mainInfo.QueueArrangeEndDate = lastDay.ToDate1(); mainInfo.SequenceNumber = 1; } else { mainInfo = info; firstDay = mainInfo.QueueArrangeStartDate.ToDateTime(); } #endregion #region "detail表" for (var i = 0; i < 7; i++) { for (var j = 1; j <= 4; j++) { var detailInfo = new t_mt_queuearrangedetail(); detailInfo.ID = CommonHandleMethod.GetID(); detailInfo.QueueArrangeMainID = mainInfo.ID; detailInfo.QueueArrangeDate = firstDay.AddDays(i).ToDate1(); detailInfo.QueueArrangeWeekDay = CommonHandleMethod.CaculateWeekDay(firstDay.AddDays(i)); detailInfo.QueueArrangePeriod = j; detailInfo.CreateDT = DateTime.Now.ToDate4(); detailInfo.IsDelete = 0; listDetailInfo.Add(detailInfo); #region "relation表" queueList.ForEach(item => { var relationInfo = new t_mt_queuerearrangerelation(); relationInfo.ID = CommonHandleMethod.GetID(); relationInfo.QueueArrangeDetailID = detailInfo.ID; relationInfo.QueueID = item.QueueId; relationInfo.QueueName = item.QueueName; relationInfo.State = 0; relationInfo.CreateDT = DateTime.Now.ToDate4(); relationInfo.IsDelete = 0; listRelationInfo.Add(relationInfo); }); #endregion } } #endregion //开始事务 db.BeginTran(); db.Insertable <t_mt_queuearrangemain>(mainInfo).ExecuteCommand(); db.Insertable <t_mt_queuearrangedetail>(listDetailInfo).ExecuteCommand(); db.Insertable <t_mt_queuerearrangerelation>(listRelationInfo).ExecuteCommand(); //提交事务 db.CommitTran(); } catch (Exception ex) { db.RollbackTran(); throw (ex); } }
/// <summary> /// 创建队列排班 /// </summary> /// <param name="modalityId">检查类型Id</param> /// <param name="db">dbClient</param> /// <param name="listMainInfo">排班日期主表列表</param> private void CreateQueueArrange(SqlSugarClient db, string hospitalId, List <ModalityArrangeDate> listModalityDate, List <string> remainModalityList) { YLog.LogInfo($"开始生成队列排班............"); try { if (listModalityDate.Count > 0) { listModalityDate.ForEach(item => { //获取该检查类型下的所有队列 var queueList = db.Queryable <t_mt_devicegroup>().Where(n => n.IsDelete == "0") .Where(n => n.State == 1).Where(n => n.ClinicID == item.ModalityId) .ToList().Select(n => new { QueueId = n.ID, QueueName = n.GroupName }).ToList(); item.ArrangeDateList.ForEach(ele => { var listDetailInfo = new List <t_mt_queuearrangedetail>(); var listRelationInfo = new List <t_mt_queuerearrangerelation>(); #region "detail表" for (var i = 0; i < 7; i++) { for (var j = 1; j <= 4; j++) { var detailInfo = new t_mt_queuearrangedetail(); detailInfo.ID = CommonHandleMethod.GetID(); detailInfo.QueueArrangeMainID = ele.ID; detailInfo.QueueArrangeDate = ele.QueueArrangeStartDate.ToDateTime().AddDays(i).ToDate1(); detailInfo.QueueArrangeWeekDay = CommonHandleMethod.CaculateWeekDay(ele.QueueArrangeStartDate.ToDateTime().AddDays(i)); detailInfo.QueueArrangePeriod = j; detailInfo.CreateDT = DateTime.Now.ToDate4(); detailInfo.IsDelete = 0; listDetailInfo.Add(detailInfo); #region "relation表" queueList.ForEach(element => { var relationInfo = new t_mt_queuerearrangerelation(); relationInfo.ID = CommonHandleMethod.GetID(); relationInfo.QueueArrangeDetailID = detailInfo.ID; relationInfo.QueueID = element.QueueId; relationInfo.QueueName = element.QueueName; relationInfo.State = 0; relationInfo.CreateDT = DateTime.Now.ToDate4(); relationInfo.IsDelete = 0; listRelationInfo.Add(relationInfo); }); #endregion } } #endregion db.Insertable <t_mt_queuearrangemain>(ele).ExecuteCommand(); db.Insertable <t_mt_queuearrangedetail>(listDetailInfo).ExecuteCommand(); db.Insertable <t_mt_queuerearrangerelation>(listRelationInfo).ExecuteCommand(); }); }); } //存在未曾添加过队列排班的检查类型 if (remainModalityList.Any()) { var listMainInfo = new List <t_mt_queuearrangemain>(); var listDetailInfo = new List <t_mt_queuearrangedetail>(); var listRelationInfo = new List <t_mt_queuerearrangerelation>(); Dictionary <string, int> modalityCountMap = new Dictionary <string, int>(); int count = 1; remainModalityList.ForEach(item => { if (modalityCountMap.TryGetValue(item, out count)) { modalityCountMap[item] = count++; } else { modalityCountMap.Add(item, 1); count = 1; } YLog.LogInfo($"新增检查类型:{CommonHandleMethod.GetModalityNameByGUID(item)}的队列排班............"); var mainInfo = new t_mt_queuearrangemain(); var firstDay = CommonHandleMethod.GetWeekFirstDayMon(DateTime.Now); var lastDay = CommonHandleMethod.GetWeekLastDaySun(DateTime.Now); //获取该检查类型下的所有队列 var queueList = db.Queryable <t_mt_devicegroup>().Where(n => n.IsDelete == "0").Where(n => n.State == 1).Where(n => n.ClinicID == item).ToList().Select(n => new { QueueId = n.ID, QueueName = n.GroupName }).ToList(); mainInfo.ID = CommonHandleMethod.GetID(); mainInfo.HospitalID = hospitalId; mainInfo.ModalityID = item; mainInfo.Modality = CommonHandleMethod.GetModalityNameByGUID(item); mainInfo.IsDelete = 0; mainInfo.CreateDT = DateTime.Now.ToDate4(); mainInfo.QueueArrangeStartDate = firstDay.ToDate1(); mainInfo.QueueArrangeEndDate = lastDay.ToDate1(); mainInfo.SequenceNumber = count; YLog.LogInfo($"当前生成序号:{count}"); for (var i = 0; i < 7; i++) { for (var j = 1; j <= 4; j++) { var detailInfo = new t_mt_queuearrangedetail(); detailInfo.ID = CommonHandleMethod.GetID(); detailInfo.QueueArrangeMainID = mainInfo.ID; detailInfo.QueueArrangeDate = firstDay.AddDays(i).ToDate1(); detailInfo.QueueArrangeWeekDay = CommonHandleMethod.CaculateWeekDay(firstDay.AddDays(i)); detailInfo.QueueArrangePeriod = j; detailInfo.CreateDT = DateTime.Now.ToDate4(); detailInfo.IsDelete = 0; listDetailInfo.Add(detailInfo); #region "relation表" queueList.ForEach(ele => { var relationInfo = new t_mt_queuerearrangerelation(); relationInfo.ID = CommonHandleMethod.GetID(); relationInfo.QueueArrangeDetailID = detailInfo.ID; relationInfo.QueueID = ele.QueueId; relationInfo.QueueName = ele.QueueName; relationInfo.State = 0; relationInfo.CreateDT = DateTime.Now.ToDate4(); relationInfo.IsDelete = 0; listRelationInfo.Add(relationInfo); }); #endregion } } listMainInfo.Add(mainInfo); }); db.Insertable <t_mt_queuearrangemain>(listMainInfo).ExecuteCommand(); db.Insertable <t_mt_queuearrangedetail>(listDetailInfo).ExecuteCommand(); db.Insertable <t_mt_queuerearrangerelation>(listRelationInfo).ExecuteCommand(); } } catch (Exception ex) { db.RollbackTran(); throw (ex); } }