コード例 #1
0
        public IActionResult Get(Guid id)
        {
            try
            {
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    DutyGroupSchedule data = db.DutyGroupSchedule
                                             .Include(t => t.Lister)
                                             .Include(t => t.Organization)
                                             .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckMan)
                                             .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule)/*.ThenInclude(t => t.CheckDutySite).ThenInclude(t => t.Camera)*/
                                             .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.CheckMan)
                                             .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.SiteOrganization)
                                             .Include(t => t.Schedule).ThenInclude(t => t.ScheduleCycle).ThenInclude(t => t.CycleType)
                                             .Include(t => t.Schedule).ThenInclude(t => t.ScheduleCycle).ThenInclude(t => t.DayPeriods).ThenInclude(t => t.TimePeriods)
                                             .Include(t => t.Schedule).ThenInclude(t => t.ScheduleType)
                                             .Include(t => t.Reservegroup).ThenInclude(t => t.Staff)
                                             .Include(t => t.EmergencyTeam).ThenInclude(t => t.Staff)
                                             .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(id));
                    if (data == null)
                    {
                        return(NoContent());
                    }

                    return(new ObjectResult(data));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }
コード例 #2
0
 /// <summary>
 /// 获取查勤点日志
 /// </summary>
 /// <param name="model">计划实体</param>
 /// <param name="time">计划时间</param>
 /// <param name="tp">时间段</param>
 /// <param name="dss">检查点人员安排明细</param>
 /// <returns></returns>
 private static DutyCheckLog GetSiteLog(DutyGroupSchedule model, DateTime time, TimePeriod tp, DutyCheckSiteSchedule dss, Guid dayPeriod)
 {
     return(new DutyCheckLog
     {
         DutyCheckLogId = Guid.NewGuid(),
         TimePeriod = tp,
         DutyCheckSiteScheduleId = dss.DutyCheckSiteScheduleId,
         PlanDate = time,
         DutyCheckStaffId = dss.CheckManId,
         OrganizationId = model.OrganizationId,
         StatusId = new Guid("361ADFE9-E58A-4C88-B191-B742CC212443"),     //未开始
         RecordTypeId = new Guid("a0002016-e009-b019-e001-abcd18000002"), //实地查勤
         DayPeriodId = dayPeriod,
     });
 }
コード例 #3
0
        public IActionResult Add([FromBody] DutyGroupSchedule model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    //判断是否已存在编排
                    if (DutyGroupScheduleHelper.IsExist(model.StartDate, model.EndDate, model.OrganizationId))
                    {
                        return(BadRequest(new ApplicationException {
                            ErrorCode = "DataError", ErrorMessage = "当前时间已进行编排"
                        }));
                    }

                    if (CompletionData(model, db))
                    {
                        return(BadRequest(new ApplicationException {
                            ErrorCode = "DataError", ErrorMessage = "编排哨位节点下的监控点数据不存在"
                        }));
                    }
                    //
                    db.DutyGroupSchedule.Add(model);
                    db.SaveChanges();
                    //生成日数据
                    Task.Factory.StartNew(() =>
                    {
                        DutyGroupScheduleHelper.GetAbsoultedDutyCheckLog(model);
                    });
                    return(Created("", "OK"));
                }
            }
            catch (DbUpdateException dbEx)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                }));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }
コード例 #4
0
        public IActionResult Delete(Guid id)
        {
            try
            {
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    using (var tran = db.Database.BeginTransaction())
                    {
                        DutyGroupSchedule dutyGroupSchedule = db.DutyGroupSchedule
                                                              .Include(t => t.Lister)
                                                              .Include(t => t.Organization)
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckMan)
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule)/*.ThenInclude(t => t.CheckDutySite).ThenInclude(t => t.Camera)*/
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.CheckMan)
                                                              .Include(t => t.Reservegroup).ThenInclude(t => t.Staff)
                                                              .Include(t => t.EmergencyTeam).ThenInclude(t => t.Staff)
                                                              .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(id));
                        if (dutyGroupSchedule == null)
                        {
                            return(NoContent());
                        }
                        if (DutyGroupScheduleHelper.IsInWork(dutyGroupSchedule.StartDate, dutyGroupSchedule.EndDate, dutyGroupSchedule.OrganizationId) > 0)
                        {
                            dutyGroupSchedule.IsCancel = true;
                            db.DutyGroupSchedule.Update(dutyGroupSchedule);
                            db.SaveChanges();
                        }
                        else
                        {
                            //
                            RemoveLinkage(db, dutyGroupSchedule);
                            //
                            db.DutyGroupSchedule.Remove(dutyGroupSchedule);
                            db.SaveChanges();
                        }
                        tran.Commit();

                        return(new NoContentResult());
                    }
                }
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }
コード例 #5
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static DutyGroupSchedule UpdateData(DutyGroupSchedule model)
        {
            DutyGroupSchedule newModel = new DutyGroupSchedule();

            newModel.DutyGroupScheduleId = Guid.NewGuid();
            newModel.EndDate             = model.EndDate;
            newModel.ListerId            = model.ListerId;
            newModel.OrganizationId      = model.OrganizationId;
            newModel.ScheduleId          = model.ScheduleId;
            newModel.StartDate           = model.StartDate;
            newModel.TabulationTime      = model.TabulationTime;
            //
            //明细
            List <DutyGroupScheduleDetail> list = new List <DutyGroupScheduleDetail>();

            foreach (DutyGroupScheduleDetail dgsd in model.DutyGroupScheduleDetails)
            {
                dgsd.DutyGroupScheduleDetailId = Guid.NewGuid();
                List <DutyCheckSiteSchedule> dcss = new List <DutyCheckSiteSchedule>();
                foreach (DutyCheckSiteSchedule dcs in dgsd.CheckDutySiteSchedule)
                {
                    dcs.DutyCheckSiteScheduleId = Guid.NewGuid();
                    dcss.Add(dcs);
                }
                dgsd.CheckDutySiteSchedule = dcss;
                list.Add(dgsd);
            }
            //备勤组
            List <Reservegroup> reservegroup = new List <Reservegroup>();

            foreach (Reservegroup rg in model.Reservegroup)
            {
                rg.DutyGroupScheduleId = Guid.NewGuid();
                reservegroup.Add(rg);
            }
            newModel.Reservegroup = reservegroup;
            //应急小组
            List <EmergencyTeam> emergencyteam = new List <EmergencyTeam>();

            foreach (EmergencyTeam et in model.EmergencyTeam)
            {
                et.DutyGroupScheduleId = Guid.NewGuid();
                emergencyteam.Add(et);
            }
            newModel.EmergencyTeam            = emergencyteam;
            newModel.DutyGroupScheduleDetails = list;
            return(newModel);
        }
コード例 #6
0
        /// <summary>
        /// 补全数据
        /// </summary>
        /// <param name="dgs"></param>
        /// <returns></returns>
        public static DutyGroupSchedule CompletionData(DutyGroupSchedule dgs)
        {
            DutyGroupSchedule model;

            using (var db = new AllInOneContext.AllInOneContext())
            {
                model = db.DutyGroupSchedule
                        .Include(t => t.Lister)
                        .Include(t => t.Organization)
                        .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckMan)
                        .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.CheckMan)
                        .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.SiteOrganization)
                        .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule)/*.ThenInclude(t => t.CheckDutySite)*/
                        .Include(t => t.Schedule).ThenInclude(t => t.ScheduleCycle).ThenInclude(t => t.DayPeriods).ThenInclude(t => t.TimePeriods)
                        .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(dgs.DutyGroupScheduleId));
            }

            return(model);
        }
コード例 #7
0
        /// <summary>
        /// 自动匹配该组织节点下的摄像机数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="db"></param>
        private static bool CompletionData(DutyGroupSchedule model, AllInOneContext.AllInOneContext db)
        {
            bool isCompleted = false;

            foreach (DutyGroupScheduleDetail dgsd in model.DutyGroupScheduleDetails)
            {
                foreach (DutyCheckSiteSchedule dcss in dgsd.CheckDutySiteSchedule)
                {
                    MonitorySite ms = DutyGroupScheduleHelper.GetMonitorySiteByOrganizationId(dcss.SiteOrganizationId.Value, db);
                    if (ms != null)
                    {
                        dcss.CheckDutySiteId = ms.MonitorySiteId;
                    }
                    else
                    {
                        isCompleted = true;
                    }
                }
            }
            return(isCompleted);
        }
コード例 #8
0
        /// <summary>
        /// 根据安排表生成实地查勤
        /// </summary>
        /// <param name="dgs"></param>
        public static bool GetAbsoultedDutyCheckLog(DutyGroupSchedule dgs)
        {
            if (dgs == null)
            {
                return(false);
            }
            bool isOK = false;
            //补全数据
            DutyGroupSchedule model = CompletionData(dgs);

            //组装网络查勤员数据
            Queue <Staff> checkMans = new Queue <Staff>(); //网络查勤员队列

            foreach (DutyGroupScheduleDetail detail in model.DutyGroupScheduleDetails)
            {
                checkMans.Enqueue(detail.CheckMan);
            }

            //取所有哨位信息
            Dictionary <Guid, Queue <DutyCheckSiteSchedule> > groupStaff = new Dictionary <Guid, Queue <DutyCheckSiteSchedule> >();
            Dictionary <Guid, Queue <DutyCheckSiteSchedule> > allStaffs  = new Dictionary <Guid, Queue <DutyCheckSiteSchedule> >();

            //
            foreach (DutyCheckSiteSchedule dss in model.DutyGroupScheduleDetails[0].CheckDutySiteSchedule)
            {
                //groupStaff.Add(dss.CheckDutySite.MonitorySiteId, new Queue<DutyCheckSiteSchedule>());
                //allStaffs.Add(dss.CheckDutySite.MonitorySiteId, new Queue<DutyCheckSiteSchedule>());
                if (dss.CheckDutySiteId != null)
                {
                    groupStaff.Add(dss.CheckDutySiteId.Value, new Queue <DutyCheckSiteSchedule>());
                    allStaffs.Add(dss.CheckDutySiteId.Value, new Queue <DutyCheckSiteSchedule>());
                }
            }

            //取哨位对应的组员信息
            foreach (DutyGroupScheduleDetail detail in model.DutyGroupScheduleDetails)
            {
                foreach (DutyCheckSiteSchedule dss in detail.CheckDutySiteSchedule)
                {
                    if (dss.CheckDutySiteId != null)
                    {
                        if (groupStaff.ContainsKey(dss.CheckDutySiteId.Value))
                        {
                            groupStaff[dss.CheckDutySiteId.Value].Enqueue(dss);
                        }

                        if (allStaffs.ContainsKey(dss.CheckDutySiteId.Value))
                        {
                            allStaffs[dss.CheckDutySiteId.Value].Enqueue(dss);
                        }
                    }
                }
            }
            //过滤过期的时间
            if (model.EndDate <= DateTime.Now)
            {
                return(false);
            }
            //计算有效天数
            int days = (int)(model.EndDate.Date - model.StartDate.Date).TotalDays + 1;

            if (days <= 0)
            {
                Console.WriteLine("生成分组查勤表无效,时间已过期!");
                return(false);
            }
            DateTime validtime = DateTime.Now;

            if (model.StartDate <= DateTime.Now && model.EndDate >= DateTime.Now)
            {
                for (int i = 0; i < days; i++)
                {
                    if (model.StartDate.AddDays(i) >= DateTime.Now.Date)
                    {
                        validtime = model.StartDate.AddDays(i);
                        break;
                    }
                }
                validtime = new DateTime(validtime.Year, validtime.Month, validtime.Day, 0, 0, 0);
            }
            else if (model.StartDate > DateTime.Now)
            {
                validtime = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0);
            }

            days = (int)(model.EndDate.Date - validtime.Date).TotalDays + 1;

            if (days == 0)
            {
                return(false);
            }
            //实际人员轮值总数
            int allCount = days * model.Schedule.ScheduleCycle.DayPeriods[0].TimePeriods.Count() - 1;

            //计算出实际人员的循环情况

            for (int i = 0; i < allCount; i++)
            {
                foreach (var data in groupStaff)
                {
                    DutyCheckSiteSchedule staff = groupStaff[data.Key].Dequeue();
                    //循环进队
                    allStaffs[data.Key].Enqueue(staff);
                    //重新进队
                    groupStaff[data.Key].Enqueue(staff);
                }
            }

            //根据时段循环分配组员
            List <DutyCheckLog> logs = new List <DutyCheckLog>();

            for (int i = 0; i < days; i++)
            {
                try
                {
                    DateTime time = validtime.AddDays(i);
                    foreach (TimePeriod tp in model.Schedule.ScheduleCycle.DayPeriods[0].TimePeriods)
                    {
                        //判断当天的数据,已经失效的时段不再生成记录
                        if (time == DateTime.Now.Date)
                        {
                            DateTime startTime = new DateTime(time.Year, time.Month, time.Day, tp.StartTime.Hour, tp.StartTime.Minute, tp.StartTime.Second);
                            DateTime endTime   = new DateTime(time.Year, time.Month, time.Day, tp.EndTime.Hour, tp.EndTime.Minute, tp.EndTime.Second);

                            if (startTime > DateTime.Now || endTime < DateTime.Now)
                            {
                                continue;
                            }
                        }
                        //组装网络查勤员数据
                        Staff        staff = checkMans.Dequeue();
                        DutyCheckLog log   = GetCheckManLog(model.OrganizationId, time, tp, staff.StaffId);

                        logs.Add(log);
                        checkMans.Enqueue(staff);

                        foreach (var data in allStaffs)
                        {
                            DutyCheckSiteSchedule dss     = allStaffs[data.Key].Dequeue();
                            DutyCheckLog          sitelog = GetSiteLog(model, time, tp, dss, model.Schedule.ScheduleCycle.DayPeriods[0].DayPeriodId);

                            logs.Add(sitelog);
                        }
                    }
                }
                catch (Exception ex)
                {
                    isOK = false;
                    return(isOK);
                }
            }

            //实际保存记录
            using (var db = new AllInOneContext.AllInOneContext())
            {
                //建立事务
                using (var tran = db.Database.BeginTransaction())
                {
                    try
                    {
                        //先移除已排班但尚未执行的记录
                        var del = db.DutyCheckLog
                                  .Where(p => p.PlanDate >= model.StartDate &&
                                         p.PlanDate <= model.EndDate &&
                                         p.StatusId == new Guid("361ADFE9-E58A-4C88-B191-B742CC212443"));

                        if (del != null && del.Count() != 0)
                        {
                            db.DutyCheckLog.RemoveRange(del.ToList());
                            db.SaveChanges();
                        }

                        //新增
                        foreach (DutyCheckLog log in logs)
                        {
                            string txt = JsonConvert.SerializeObject(log);
                            db.DutyCheckLog.Add(log);
                        }

                        db.SaveChanges();

                        tran.Commit();
                        isOK = true;
                    }
                    catch (Exception ex)
                    {
                        isOK = false;
                    }
                }
            }
            return(isOK);
        }
コード例 #9
0
        private static void RemoveLinkage(AllInOneContext.AllInOneContext db, DutyGroupSchedule dutyGroupSchedule)
        {
            //删除未进行的查勤记录
            var dellog = db.DutyCheckLog
                         .Where(p => p.PlanDate >= dutyGroupSchedule.StartDate &&
                                p.PlanDate <= dutyGroupSchedule.EndDate &&
                                p.StatusId == new Guid("361ADFE9-E58A-4C88-B191-B742CC212443"));

            if (dellog != null && dellog.Count() != 0)
            {
                db.DutyCheckLog.RemoveRange(dellog.ToList());
                db.SaveChanges();
            }

            List <DutyGroupScheduleDetail> mainList = new List <DutyGroupScheduleDetail>();

            if (dutyGroupSchedule.DutyGroupScheduleDetails != null)
            {
                List <DutyCheckSiteSchedule> dutyCheckSiteSchedulelList = new List <DutyCheckSiteSchedule>();
                foreach (DutyGroupScheduleDetail detail in dutyGroupSchedule.DutyGroupScheduleDetails)
                {
                    // 解除DutyCheckSiteSchedule Many To Many
                    if (detail.CheckDutySiteSchedule != null)
                    {
                        foreach (DutyCheckSiteSchedule rp in detail.CheckDutySiteSchedule)
                        {
                            DutyCheckSiteSchedule del = db.Set <DutyCheckSiteSchedule>()
                                                        .FirstOrDefault(p => p.DutyCheckSiteScheduleId.Equals(rp.DutyCheckSiteScheduleId));
                            if (del != null)
                            {
                                dutyCheckSiteSchedulelList.Add(del);
                            }
                        }
                    }
                }
                db.Set <DutyCheckSiteSchedule>().RemoveRange(dutyCheckSiteSchedulelList);
                db.SaveChanges();

                // DutyGroupScheduleDetail Many To Many
                List <DutyGroupScheduleDetail> detailList = new List <DutyGroupScheduleDetail>();
                foreach (DutyGroupScheduleDetail detail in dutyGroupSchedule.DutyGroupScheduleDetails)
                {
                    DutyGroupScheduleDetail del = db.Set <DutyGroupScheduleDetail>()
                                                  .FirstOrDefault(p => p.DutyGroupScheduleDetailId.Equals(detail.DutyGroupScheduleDetailId));
                    if (del != null)
                    {
                        detailList.Add(del);
                    }
                }
                db.Set <DutyGroupScheduleDetail>().RemoveRange(detailList);
                db.SaveChanges();
            }



            // 解除EmergencyTeam Many To Many
            if (dutyGroupSchedule.EmergencyTeam != null)
            {
                List <EmergencyTeam> delList = new List <EmergencyTeam>();
                foreach (EmergencyTeam rp in dutyGroupSchedule.EmergencyTeam)
                {
                    EmergencyTeam del = db.Set <EmergencyTeam>()
                                        .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(rp.DutyGroupScheduleId) && p.StaffId.Equals(rp.StaffId));
                    if (del != null)
                    {
                        delList.Add(del);
                    }
                }
                db.Set <EmergencyTeam>().RemoveRange(delList);
                db.SaveChanges();
            }

            // 解除Reservegroup Many To Many
            if (dutyGroupSchedule.Reservegroup != null)
            {
                List <Reservegroup> delList = new List <Reservegroup>();
                foreach (Reservegroup rp in dutyGroupSchedule.Reservegroup)
                {
                    Reservegroup del = db.Set <Reservegroup>()
                                       .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(rp.DutyGroupScheduleId) && p.StaffId.Equals(rp.StaffId));
                    if (del != null)
                    {
                        delList.Add(del);
                    }
                }
                db.Set <Reservegroup>().RemoveRange(delList);
                db.SaveChanges();
            }
        }
コード例 #10
0
        public IActionResult Update([FromBody] DutyGroupSchedule model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }
                using (var db = new AllInOneContext.AllInOneContext())
                {
                    using (var tran = db.Database.BeginTransaction())
                    {
                        DutyGroupSchedule dutyGroupSchedule = db.DutyGroupSchedule
                                                              .Include(t => t.Lister)
                                                              .Include(t => t.Organization)
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckMan)
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule)/*.ThenInclude(t => t.CheckDutySite).ThenInclude(t => t.Camera)*/
                                                              .Include(t => t.DutyGroupScheduleDetails).ThenInclude(t => t.CheckDutySiteSchedule).ThenInclude(t => t.CheckMan)
                                                              .Include(t => t.Reservegroup).ThenInclude(t => t.Staff)
                                                              .Include(t => t.EmergencyTeam).ThenInclude(t => t.Staff)
                                                              .FirstOrDefault(p => p.DutyGroupScheduleId.Equals(model.DutyGroupScheduleId));
                        if (dutyGroupSchedule == null)
                        {
                            return(BadRequest());
                        }

                        //
                        if (dutyGroupSchedule.StartDate <= model.StartDate && dutyGroupSchedule.EndDate >= model.EndDate)
                        {
                            //判断是否为进行中
                            Delete(dutyGroupSchedule.DutyGroupScheduleId);
                        }
                        //删除未进行的查勤记录
                        var del = db.DutyCheckLog
                                  .Where(p => p.PlanDate >= DateTime.Now &&
                                         p.PlanDate <= dutyGroupSchedule.EndDate &&
                                         p.StatusId != new Guid("361ADFE9-E58A-4C88-B191-B742CC212443"));

                        if (del != null && del.Count() != 0)
                        {
                            db.DutyCheckLog.RemoveRange(del.ToList());
                            db.SaveChanges();
                        }
                        //执行新增流程,重新对实体内属性GUID赋值
                        DutyGroupSchedule newModel = UpdateData(model);
                        //
                        if (CompletionData(newModel, db))
                        {
                            return(BadRequest(new ApplicationException {
                                ErrorCode = "DataError", ErrorMessage = "数据不齐"
                            }));
                        }
                        //
                        db.DutyGroupSchedule.Add(newModel);
                        db.SaveChanges();
                        //生成日数据
                        Task.Factory.StartNew(() =>
                        {
                            DutyGroupScheduleHelper.GetAbsoultedDutyCheckLog(newModel);
                        });
                        tran.Commit();
                        return(new NoContentResult());
                    }
                }
            }
            catch (DbUpdateException dbEx)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message
                }));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new ApplicationException {
                    ErrorCode = "Unknown", ErrorMessage = ex.Message
                }));
            }
        }