コード例 #1
0
ファイル: Server.cs プロジェクト: EvansYe/bookingTest
        /// <summary>
        /// 添加下周排班
        /// </summary>
        /// <param name="listModalityMaxDate">检查类型</param>
        private void AddNextWeeekQueueArrange(SqlSugarClient db, string hospitalId, string modalityId)
        {
            try
            {
                //队列排班显示日期条数
                var _queueArrangeDisplayCount = Convert.ToInt32(ConfigurationManager.AppSettings["QueueArrangeDisplayCount"].Trim());

                //当前医院当前检查类型下已存在的排班日期
                var existArrangeList = db.Queryable <t_mt_queuearrangemain>()
                                       .Where(n => n.IsDelete == 0)
                                       .Where(n => n.HospitalID == hospitalId)
                                       .Where(n => n.ModalityID == modalityId).ToList();
                if (existArrangeList.Any() == false)
                {
                    Console.WriteLine($"当前检查类型下不存在排班日期,无法添加下周排班!");
                }
                if (existArrangeList.Count < _queueArrangeDisplayCount)
                {
                    var info = new t_mt_queuearrangemain();
                    info.ID         = CommonHandleMethod.GetID();
                    info.IsDelete   = 0;
                    info.CreateDT   = DateTime.Now.ToDate4();
                    info.HospitalID = hospitalId;
                    info.Modality   = CommonHandleMethod.GetModalityNameByGUID(modalityId);
                    info.ModalityID = modalityId;
                    //获取当前日期列表的 最大序号
                    var maxSequenceNo   = existArrangeList.Max(n => n.SequenceNumber);
                    var maxSequenceInfo = existArrangeList.Where(n => n.SequenceNumber == maxSequenceNo).FirstOrDefault();
                    info.SequenceNumber        = maxSequenceNo + 1;
                    info.QueueArrangeStartDate = CommonHandleMethod.GetWeekFirstDayMon(maxSequenceInfo.QueueArrangeEndDate.ToDateTime().AddDays(1)).ToDate1();
                    info.QueueArrangeEndDate   = CommonHandleMethod.GetWeekLastDaySun(maxSequenceInfo.QueueArrangeEndDate.ToDateTime().AddDays(1)).ToDate1();
                    //调用内部方法,新增detail表、relation表记录
                    AddDateFormat(hospitalId, modalityId, db, info);
                }
                else
                {
                    Console.WriteLine($"当前配置仅支持最多{_queueArrangeDisplayCount}周排班!");
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: EvansYe/bookingTest
        /// <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);
            }
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: EvansYe/bookingTest
        /// <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);
            }
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: EvansYe/bookingTest
        /// <summary>
        /// 生成队列排班
        /// </summary>
        public void GenerateQueueArrange(SqlSugarClient db, string hospitalId)
        {
            try
            {
                var validDTO = GetSystemConfig(db, hospitalId);
                //当前该医院已有的排班日期段
                var rsMain = db.Queryable <t_mt_queuearrangemain>().Where(n => n.IsDelete == 0)
                             .Where(n => n.HospitalID == hospitalId).ToList();
                //获取当前医院所有检查类型
                var rsModality = db.Queryable <t_mt_clinic>().Where(n => n.IsDelete == 0)
                                 .Where(n => n.HospitalID == hospitalId).ToList();
                //已经参与排班的检查类型
                var rsModalityMain = rsMain.Select(n => n.ModalityID).ToList();
                //当前存在未生成队列排班的检查类型
                var rsRemain         = rsModality.Select(n => n.ID).ToList().Except(rsModalityMain).ToList();
                var modalityDateList = new List <ModalityArrangeDate>();
                //检查类型-队列排班日期列表
                rsModality.ForEach(item =>
                {
                    var modalityDate        = new ModalityArrangeDate();
                    modalityDate.ModalityId = item.ID;
                    modalityDate.Modality   = CommonHandleMethod.GetModalityNameByGUID(item.ID);
                    rsMain.ForEach(ele =>
                    {
                        if (item.ID == ele.ModalityID)
                        {
                            modalityDate.ArrangeDateList.Add(ele);
                        }
                    });
                    if (modalityDate.ArrangeDateList.Count > 0)
                    {
                        modalityDateList.Add(modalityDate);
                    }
                });
                YLog.LogInfo($"获取检查类型/队列排班日期列表............");
                //清洗后的数据列表
                var tempList = ClearData(db, modalityDateList);
                YLog.LogInfo($"数据清洗完成............");
                var listModalityArrangeDate = new List <ModalityArrangeDate>();
                //检查类型-队列排班日期列表
                tempList.ForEach(item =>
                {
                    var modalityArrangeDate        = new ModalityArrangeDate();
                    modalityArrangeDate.ModalityId = item.ModalityId;
                    modalityArrangeDate.Modality   = item.Modality;
                    if (item.ArrangeDateList.Count >= validDTO.WeekNums)
                    {
                        YLog.LogInfo($"当前检查类型:{item.Modality}的队列排班已满足号源生成周数............");
                        return;
                    }
                    var listArrangeMain = new List <t_mt_queuearrangemain>();
                    //生成其余几周的队列排班
                    for (var i = 0; i < (validDTO.WeekNums - item.ArrangeDateList.Count); i++)
                    {
                        var info        = new t_mt_queuearrangemain();
                        info.ID         = CommonHandleMethod.GetID();
                        info.IsDelete   = 0;
                        info.CreateDT   = DateTime.Now.ToDate4();
                        info.HospitalID = hospitalId;
                        info.Modality   = CommonHandleMethod.GetModalityNameByGUID(item.ModalityId);
                        info.ModalityID = item.ModalityId;
                        //获取当前日期列表的 最大序号
                        var maxSequenceNo          = item.ArrangeDateList.Max(n => n.SequenceNumber);
                        var maxSequenceInfo        = item.ArrangeDateList.Where(n => n.SequenceNumber == maxSequenceNo).FirstOrDefault();
                        info.SequenceNumber        = maxSequenceNo + (i + 1);
                        info.QueueArrangeStartDate = CommonHandleMethod.GetWeekFirstDayMon(maxSequenceInfo.QueueArrangeEndDate.ToDateTime().AddDays(7 * i + 1)).ToDate1();
                        info.QueueArrangeEndDate   = CommonHandleMethod.GetWeekLastDaySun(maxSequenceInfo.QueueArrangeEndDate.ToDateTime().AddDays(7 * i + 1)).ToDate1();
                        listArrangeMain.Add(info);
                    }

                    modalityArrangeDate.ArrangeDateList = listArrangeMain;
                    listModalityArrangeDate.Add(modalityArrangeDate);
                });

                //添加队列排班主业务
                CreateQueueArrange(db, hospitalId, listModalityArrangeDate, rsRemain);

                //提交事务
                db.CommitTran();
                YLog.LogInfo($"队列排班生成完成............");
            }
            catch (Exception ex)
            {
                db.RollbackTran();
                YLog.LogSystemError(ex.Message);
            }
        }