diff --git a/ConsoleApp1/Services/OrderService.cs b/ConsoleApp1/Services/OrderService.cs index a2fad701a7e55a995886203eacaceda573a9c72b..861756d28c1dfd712b8afdd74901a673929b4e0a 100644 --- a/ConsoleApp1/Services/OrderService.cs +++ b/ConsoleApp1/Services/OrderService.cs @@ -158,19 +158,20 @@ namespace MygigIntegration.Service.Services _log.Info($"Не синхронизирована торговая точка для заказа {order.IDDemand}; id точки: {order.IDDirection};"); return null; } - decimal? salary = OrderHelper.GetSalary(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, + RateInfo rateInfo = OrderHelper.GetSalary(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, order.IDJobPosition ?? Guid.Empty, order.MedBook, order.IDDepartment, order.IDDirection ?? Guid.Empty, order.DateOrder); - if (salary == null) + if (rateInfo == null) { _log.Info($"Невозможно рассчитать ставку по заявке {order.IDDemand}."); return null; } - if (salary == 0) + if (rateInfo.Salary == 0) { _log.Info($"Cтавка по заявке {order.IDDemand} должна быть больше нуля."); return null; } + decimal? rate = OrderHelper.GetRate(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, order.IDJobPosition ?? Guid.Empty, order.MedBook, order.IDDepartment, order.IDDirection ?? Guid.Empty, order.DateOrder); @@ -189,7 +190,7 @@ namespace MygigIntegration.Service.Services description: $"{order.Comment ?? "открытая позиция"}", documents: documents, paymentPerJob: rate ?? 0, - salary, rate ?? 0, salary, null, + rateInfo.Salary, rate ?? 0, rateInfo.Salary, null, order.MygigDirectionID, order.MygigClientID, null/*order.Breaktime*/);; @@ -204,19 +205,48 @@ namespace MygigIntegration.Service.Services _log.Info($"Не синхронизирована торговая точка для заказа {order.IDDemand}; id точки: {order.IDDirection};"); return null; } - decimal? salary = OrderHelper.GetSalary(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, + RateInfo rateInfo = OrderHelper.GetSalary(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, order.IDJobPosition ?? Guid.Empty, order.MedBook, order.IDDepartment, order.IDDirection ?? Guid.Empty, order.DateOrder); - if (salary == null) + if (rateInfo == null) { _log.Info($"Невозможно рассчитать ставку по заявке {order.IDDemand}."); return null; } - if (salary == 0) + if (rateInfo.Salary == 0) { _log.Info($"Cтавка по заявке {order.IDDemand} должна быть больше нуля."); return null; } + + if (rateInfo.IsUpRate.HasValue && rateInfo.IsUpRate == 1) + { + JobsApi instance = new JobsApi(_url); + if (instance.Configuration.DefaultHeader.ContainsKey("Authorization")) + instance.Configuration.DefaultHeader.Remove("Authorization"); + if (!instance.Configuration.DefaultHeader.ContainsKey("Authorization")) + instance.Configuration.DefaultHeader.Add("Authorization", "Bearer " + _token); + + var jobs = instance.JobsGet(order.MygigOrderID); + if (jobs != null) + { + var jobResponse = jobs.FirstOrDefault(q => q.Source.ToUpper() == order.IDDemand.ToString().ToUpper()); + + if (jobResponse != null) + { + OrderHelper.AddCommentToShifts(_connectionstring, order.IDOrder, jobResponse.Worker); + } + else + { + _log.Error($"Не найден работник IDDemand {order.IDDemand}"); + } + } + else + { + _log.Error($"Не найден job {order.MygigOrderID}"); + } + } + decimal? rate = OrderHelper.GetRate(_connectionstring, order.DateBeginMS ?? DateTime.Today, order.DateEndMS ?? DateTime.Today, order.IDJobPosition ?? Guid.Empty, order.MedBook, order.IDDepartment, order.IDDirection ?? Guid.Empty, order.DateOrder); @@ -234,7 +264,7 @@ namespace MygigIntegration.Service.Services order.MygigJobPosName, $"{order.Comment ?? "открытая позиция"}", documents, - salary, salary, rate??0, + rateInfo.Salary, rateInfo.Salary, rate??0, /*Убрал подстановку времени сдвига по часовому поясу*/ //DateTime.Parse(order.DateBeginMS.ToString()+ $"+{order.Timezone}:00"), //DateTime.Parse(order.DateEndMS.ToString() + $"+{order.Timezone}:00"), diff --git a/MygigIntegration.DomainModel/BL/OrderHelper.cs b/MygigIntegration.DomainModel/BL/OrderHelper.cs index 9bd9c7dee3eb7c202c410bcbdd988c10efa1558e..649e217990857c7fc0378ab02545021da5aab754 100644 --- a/MygigIntegration.DomainModel/BL/OrderHelper.cs +++ b/MygigIntegration.DomainModel/BL/OrderHelper.cs @@ -9,8 +9,7 @@ using System.Text; using System.Threading.Tasks; namespace MygigIntegration.DomainModel.BL -{ - +{ public static class OrderHelper { public static bool ExistEmployeeByiddemand(string connectionString, string mygigorder,string worker) @@ -107,9 +106,11 @@ namespace MygigIntegration.DomainModel.BL } } - public static decimal? GetSalary(string connectionString, DateTime shiftbegin, DateTime shiftend, Guid jobposition, + public static RateInfo GetSalary(string connectionString, DateTime shiftbegin, DateTime shiftend, Guid jobposition, bool? RateMK, Guid? IDDepartment, Guid customer, DateTime orderdate) { + var rateInfo = new RateInfo(); + using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlCommand cmd = new SqlCommand()) { @@ -127,7 +128,7 @@ namespace MygigIntegration.DomainModel.BL orderdate.ToString("yyyy-MM-dd"), "0", "0", Guid.Empty, - (RateMK ?? false) ? 1 : 0, IDDepartment,0, 1); + (RateMK ?? false) ? 1 : 0, IDDepartment, 0, 1); try { using (SqlDataReader rd = cmd.ExecuteReader()) @@ -136,8 +137,20 @@ namespace MygigIntegration.DomainModel.BL { //return new Tuple(decimal.Parse(rd[0].ToString()), rd[1].ToString()); ////em.ShiftRate = decimal.Parse(rd[0].ToString()); - if (rd != null && rd[0] != DBNull.Value) - return decimal.Parse(rd[0].ToString()); + if (rd != null) + { + if (rd[0] != DBNull.Value) + rateInfo.Salary = decimal.Parse(rd[0].ToString()); + + if (rd.FieldCount > 1 && rd[1] != DBNull.Value) + rateInfo.Description = rd[1].ToString(); + + if (rd.FieldCount > 2 && rd[2] != DBNull.Value) + rateInfo.IsUpRate = Convert.ToByte(rd[2]); + + return rateInfo; + + } else return null; } @@ -153,6 +166,33 @@ namespace MygigIntegration.DomainModel.BL } } + /// + /// Добавить комментарий к смене. + /// + /// + /// ID заказа + /// ID гигера + public static void AddCommentToShifts(string connectionString, Guid? IDOrder, string worker) + { + try + { + using (var cnn = new SqlConnection(connectionString)) + { + using (var cmd = new SqlCommand()) + { + cmd.CommandText = $"nsp_add_CommentShifts '{IDOrder}', '{worker}'"; + cmd.Connection = cnn; + cnn.Open(); + var number = cmd.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + _log.Error(ex); + } + } + public static decimal? GetRate(string connectionString, DateTime shiftbegin, DateTime shiftend, Guid jobposition, bool? RateMK, Guid? IDDepartment, Guid customer, DateTime orderdate) { @@ -294,4 +334,26 @@ namespace MygigIntegration.DomainModel.BL } } } + + /// + /// Ставка смены. + /// + public class RateInfo + { + /// + /// Зарплата + /// + public decimal? Salary { get; set; } + + /// + /// Описание + /// + public string Description { get; set; } + + /// + /// Повышение ставки + /// + public byte? IsUpRate { get; set; } + + } }