/// <summary> /// 初始化 /// </summary> /// <returns></returns> public void Start(List <DepartmentEntity> entity) { try { //获取周期数据 var cycle = getCycle().FirstOrDefault(x => x.iswork); DateTime startTime; var nowTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")); int num = 0; int totalday = 0; int month = 0; int day = 0; if (string.IsNullOrEmpty(cycle.starttime)) { startTime = nowTime; num = Util.Time.GetWeekNumberOfDay(nowTime); //星期几 totalday = Util.Time.GetDaysOfMonth(nowTime.Year, nowTime.Month); //本月有多少天 month = nowTime.Month; //第几月 day = nowTime.Day; //第几天 } else { startTime = Convert.ToDateTime(cycle.starttime); num = Util.Time.GetWeekNumberOfDay(startTime); //星期几 totalday = Util.Time.GetDaysOfMonth(startTime.Year, startTime.Month); //本月有多少天 month = startTime.Month; //第几月 day = startTime.Day; //第几天 } //等于0或1 if (Util.Time.DiffDays(nowTime, startTime) > 1) { return; } var messagebll = new MessageBLL(); foreach (var item in entity) { var workFinish = getSevenSFinish(item.DepartmentId); foreach (var finist in workFinish) { messagebll.FinishTodo("7S定点照片到期提醒", finist.Id); } } //周期间隔时间 var EndTime = startTime; switch (cycle.cycle) { case "每周": EndTime = EndTime.AddDays(7 - num); startTime = startTime.AddDays(-num + 1); break; case "每半月": if (day > 15) { startTime = new DateTime(nowTime.Year, month, 16); EndTime = new DateTime(nowTime.Year, month, totalday); } else { startTime = new DateTime(nowTime.Year, month, 1); EndTime = new DateTime(nowTime.Year, month, 15); } break; case "每月": startTime = new DateTime(nowTime.Year, month, 1); EndTime = new DateTime(nowTime.Year, month, totalday); break; case "每季度": if (month < 4) { startTime = new DateTime(nowTime.Year, 1, 1); EndTime = new DateTime(nowTime.Year, 3, 31); } else if (month < 7) { startTime = new DateTime(nowTime.Year, 4, 1); EndTime = new DateTime(nowTime.Year, 6, 30); } else if (month < 9) { startTime = new DateTime(nowTime.Year, 7, 1); EndTime = new DateTime(nowTime.Year, 9, 30); } else { startTime = new DateTime(nowTime.Year, 10, 1); EndTime = new DateTime(nowTime.Year, 12, 31); } break; default: break; } var Picture = new List <SevenSPictureEntity>(); foreach (var item in entity) { var one = new SevenSPictureEntity(); one.Id = Guid.NewGuid().ToString(); one.deptname = item.FullName; one.deptid = item.DepartmentId; one.state = "未提交"; one.CreateDate = DateTime.Now; one.ModifyDate = DateTime.Now; one.planeStartDate = startTime; one.planeEndDate = EndTime; Picture.Add(one); } InsertList(Picture); var plantime = new SevenSPlanTimeEntity(); plantime.Id = Guid.NewGuid().ToString(); plantime.PlanTime = startTime.ToString("yyyy-MM-dd") + "~" + EndTime.ToString("yyyy-MM-dd"); SavePlanTime(plantime); //修改下周期 setCycleTime(EndTime.AddDays(1).ToString("yyyy-MM-dd")); } catch (Exception ex) { throw; } }