private void RunJob() { ReportJobLogEntity jobLog = null; try { jobLog = _jobLogService.CreateJobLog(_jobName); ImportDataByTime(jobLog.DateFrom, jobLog.DateTo); jobLog.JobStatus = JobStatus.Success.ToString(); } catch (Exception e) { if (jobLog != null) { jobLog.ErrorMessage = e.InnerException == null ? e.Message : e.InnerException.Message; } Log.Error <string>(string.Format("article report job error:{0}" + Environment.NewLine + "{1}", e.Message, e.StackTrace)); } finally { if (jobLog != null) { jobLog.UpdatedDate = DateTime.Now; _jobLogService.Repository.Update(jobLog); } } }
public List <OnboardChiefView.EmployeesView> GetEmployeesView(string lillyId, string onboardDate) { var resultItem = new List <OnboardChiefView.ResultItem>(); var OnboardList = new List <OnboardChiefView.ResultItem>(); var SubmittedList = new List <OnboardChiefView.ResultItem>(); var ApprovedList = new List <OnboardChiefView.ResultItem>(); var UnqualifiedList = new List <OnboardChiefView.ResultItem>(); var list = new List <OnboardChiefView.EmployeesView>(); var employeeList = new List <OnboardChiefView.EmployeesView>(); var resultList = new List <OnboardChiefView.ResultDataList>(); ReportJobLogEntity jobLog = null; try { #region chief 接口调用 if (string.IsNullOrEmpty(lillyId)) { var allData = _localSadService.GetEmployeeByLillyId(lillyId); if (allData != null && allData.Count > 0) { foreach (var item in GetManagerLillyIDs(allData)) { var chiefData = _onboardChiefService.GetEmployeeStatusInfo(item.SupervisorLillyID); foreach (var chief in chiefData) { resultList.Add(chief); } } } } else { resultList = _onboardChiefService.GetEmployeeStatusInfo(lillyId); } #region test data //var responseString = "[{\"Result\":[{\"LillyId\":\"C083203\",\"RQSTR_ST\":1}]},{\"Result\":[{\"LillyId\":\"C082561\",\"RQSTR_ST\":1}]},{\"Result\":[{\"LillyId\":\"C217754\",\"RQSTR_ST\":-10}]},{\"Result\":[{\"LillyId\":\"C184034\",\"RQSTR_ST\":1}]},{\"Result\":[{\"LillyId\":\"C258197\",\"RQSTR_ST\":0}]}]"; //resultList = JsonConvert.DeserializeObject<List<OnboardChiefView.ResultDataList>>(responseString); #endregion Logger.Debug <string>(string.Format("chief data count:{0}", resultList.Count)); if (resultList.Any()) { var items = resultList.SelectMany(x => x.Result).ToList(); resultItem = items; OnboardList = GetDataByStatus(resultItem, 6); SubmittedList = GetDataByStatus(resultItem, 0); ApprovedList = GetDataByStatus(resultItem, 1); UnqualifiedList = GetDataByStatus(resultItem, -10); } Logger.Debug <string>(string.Format("chief end spend time.")); #endregion #region LocalSad 接口调用 var date = System.DateTime.Now; #region test data //var employee_json = "[{\"LillyID\": \"C083203\",\"ChineseName\": \"张秀兰\",\"Title\": \"TITLE\",\"Contractorgroup\": \"CNTRCTR_GRP\",\"SupervisorLillyID\": \"C248895\",\"HireDate\": \"" + date.AddDays(4) + "\",\"Phone\":\"\"},{\"LillyID\": \"C082561\",\"ChineseName\": \"钟建强\",\"Title\": \"TITLE\",\"Contractorgroup\": \"CNTRCTR_GRP\",\"SupervisorLillyID\": \"C248895\",\"HireDate\":\"" + date + "\",\"Phone\":\"13912346541\"},{\"LillyID\": \"C258197\",\"ChineseName\": \"张三\",\"Title\": \"TITLE\",\"Contractorgroup\": \"CNTRCTR_GRP\",\"SupervisorLillyID\": \"C248895\",\"HireDate\": \"" + date.AddDays(3) + "\",\"Phone\":\"13912346542\"},{\"LillyID\": \"C217754\",\"ChineseName\": \"李四\",\"Title\": \"TITLE\",\"Contractorgroup\": \"CNTRCTR_GRP\",\"SupervisorLillyID\": \"C248895\",\"HireDate\": \"" + date.AddDays(2) + "\",\"Phone\":\"13912346543\"},{\"LillyID\": \"C184034\",\"ChineseName\": \"张兰\",\"Title\": \"TITLE\",\"Contractorgroup\": \"CNTRCTR_GRP\",\"SupervisorLillyID\": \"C248895\",\"HireDate\": \"" + date.AddDays(1) + "\",\"Phone\":\"13912346540\"}]"; //var jsonData = JsonConvert.DeserializeObject<List<OnboardChiefView.EmployeesView>>(employee_json); #endregion var jsonData = _localSadService.GetEmployeeByLillyId(lillyId); Logger.Debug <string>(string.Format("localsad end spend time.")); if (jsonData != null) { if (OnboardList.Count > 0) { foreach (var item in OnboardList) { list = GetOnboardData(list.Count > 0 ? list : jsonData, item.LillyId); } Logger.Debug <string>(string.Format("OnboardList end spend time.")); } if (ApprovedList.Count > 0) { foreach (var item in ApprovedList) { employeeList = GetEmployeeList(list.Count > 0 ? list : jsonData, item.LillyId, 1); } Logger.Debug <string>(string.Format("ApprovedList end spend time.")); } if (SubmittedList.Count > 0) { employeeList = list.Count > 0 ? list : jsonData; } if (UnqualifiedList.Count > 0) { foreach (var item in UnqualifiedList) { employeeList = GetEmployeeList(list.Count > 0 ? list : jsonData, item.LillyId, -10); } } if (employeeList.Count > 0 && !string.IsNullOrEmpty(onboardDate)) { if (onboardDate == date.ToString("yyyy-MM-dd")) { employeeList = employeeList.Where(e => e.HireDate.ToString("yyyy-MM-dd") == onboardDate).ToList(); } else { DateTime startTime = Convert.ToDateTime(onboardDate).AddDays(-2); DateTime middleTime = Convert.ToDateTime(onboardDate).AddDays(-1); DateTime endTime = Convert.ToDateTime(onboardDate); #region 过滤掉周六和周日 string middle = string.Empty; string end = string.Empty; string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; string start = Day[Convert.ToInt32(startTime.DayOfWeek.ToString("d"))].ToString(); middle = Day[Convert.ToInt32(middleTime.DayOfWeek.ToString("d"))].ToString(); end = Day[Convert.ToInt32(endTime.DayOfWeek.ToString("d"))].ToString(); if (start == "星期六") { startTime = startTime.AddDays(2); middleTime = startTime.AddDays(1); endTime = startTime.AddDays(2); middle = Day[Convert.ToInt32(middleTime.DayOfWeek.ToString("d"))].ToString(); end = Day[Convert.ToInt32(endTime.DayOfWeek.ToString("d"))].ToString(); } else if (start == "星期日") { startTime = startTime.AddDays(1); middleTime = startTime.AddDays(1); endTime = startTime.AddDays(2); middle = Day[Convert.ToInt32(middleTime.DayOfWeek.ToString("d"))].ToString(); end = Day[Convert.ToInt32(endTime.DayOfWeek.ToString("d"))].ToString(); } if (middle == "星期六") { middleTime = middleTime.AddDays(2); endTime = middleTime.AddDays(1); end = Day[Convert.ToInt32(endTime.DayOfWeek.ToString("d"))].ToString(); } else if (middle == "星期日") { middleTime = middleTime.AddDays(1); endTime = middleTime.AddDays(1); end = Day[Convert.ToInt32(endTime.DayOfWeek.ToString("d"))].ToString(); } if (end == "星期六") { endTime = endTime.AddDays(2); } else if (end == "星期日") { endTime = endTime.AddDays(1); } #endregion //employeeList = employeeList.Where(e => DateTime.Parse(e.HireDate.ToString("yyyy-MM-dd")) >= startTime && //DateTime.Parse(e.HireDate.ToString("yyyy-MM-dd")) <= endTime).ToList(); employeeList = employeeList.Where(e => DateTime.Parse(e.HireDate.ToString("yyyy-MM-dd")) == endTime).ToList(); } jobLog = _jobLogService.CreateJobLog(jobName); jobLog.JobStatus = JobStatus.Success.ToString(); } } #endregion } catch (Exception e) { _success = false; if (jobLog != null) { jobLog.ErrorMessage = e.InnerException != null ? e.InnerException.Message : e.Message; jobLog.JobStatus = JobStatus.Error.ToString(); } Logger.Error <string>(string.Format("request data failed:{0}" + Environment.NewLine + "{1}", e.Message, e.StackTrace)); } finally { if (jobLog != null) { jobLog.UpdatedDate = DateTime.Now; _jobLogService.Repository.Update(jobLog); } } return(employeeList.OrderBy(o => o.HireDate).ToList()); }