diff --git a/Myshipping.Application/EDI/XiahuozhiHelpler.cs b/Myshipping.Application/EDI/XiahuozhiHelpler.cs index 821c0976..eb494241 100644 --- a/Myshipping.Application/EDI/XiahuozhiHelpler.cs +++ b/Myshipping.Application/EDI/XiahuozhiHelpler.cs @@ -75,6 +75,17 @@ namespace Myshipping.Application.EDI return new KeyValuePair(false, "海关航次不能为空"); } + //2023年7月12日,下货纸为冻柜,需填写温度和通风,危险品需填写等级和编号 + if (order.CARGOID == "R" && (string.IsNullOrEmpty(order.TEMPSET) || string.IsNullOrEmpty(order.REEFERF))) + { + return new KeyValuePair(false, "冻柜的温度和通风必须填写"); + } + + if (order.CARGOID == "D" && (string.IsNullOrEmpty(order.DUNNO) || string.IsNullOrEmpty(order.DCLASS))) + { + return new KeyValuePair(false, "危险品的等级和编号必须填写"); + } + var fileOpt = App.GetOptions(); if (string.IsNullOrEmpty(fileOpt.basePath)) { @@ -412,7 +423,7 @@ namespace Myshipping.Application.EDI repBookingFile.Insert(attFile); //发送邮件 - var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL,new KeyValuePair(ediFileName, msResult.GetBuffer())); + var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL, new KeyValuePair(ediFileName, msResult.GetBuffer())); if (!sendResult.Key) { return new KeyValuePair(false, sendResult.Value); diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 7667ada2..ed47ad7e 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1046,6 +1046,82 @@ namespace Myshipping.Application await SendBookingOrder(new long[] { order.Id }); } + /// + /// 在订舱台账保存单证备注、操作备注等功能 + /// + /// + /// + [HttpPost("/BookingOrder/SaveDataInList"), AllowAnonymous] + public async Task SaveDataInList(JObject obj) + { + if (!obj.ContainsKey("Id")) + { + throw Oops.Bah("参数有误,没有Id"); + } + + var id = obj.GetLongValue("Id"); + + var order = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id); + if (order == null) + { + throw Oops.Bah("订舱数据不存在"); + } + + //判断权限,返回null表示有全部权限 + List userlist = await _right.GetDataScopeList(MenuConst.MenuBookingOrder, true); + if (userlist != null && !userlist.Contains(UserManager.UserId)) + { + throw Oops.Bah("无权修改"); + } + + var orderCompare = await _rep.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == id); + + var propsOrder = typeof(BookingOrder).GetProperties(); + foreach (var property in obj) + { + var propNameLower = property.Key.ToLower(); + var propOrd = propsOrder.FirstOrDefault(p => p.Name.ToLower() == propNameLower); + if (propOrd != null) + { + if (propOrd.PropertyType == typeof(string)) + { + propOrd.SetValue(order, obj.GetStringValue(property.Key)); + } + else if (propOrd.PropertyType == typeof(int) || propOrd.PropertyType == typeof(int?)) + { + propOrd.SetValue(order, obj.GetIntValue(property.Key)); + } + else if (propOrd.PropertyType == typeof(long) || propOrd.PropertyType == typeof(long?)) + { + propOrd.SetValue(order, obj.GetLongValue(property.Key)); + } + else if (propOrd.PropertyType == typeof(DateTime) || propOrd.PropertyType == typeof(DateTime?)) + { + propOrd.SetValue(order, obj.GetDateTimeValue(property.Key)); + } + else if (propOrd.PropertyType == typeof(bool) || propOrd.PropertyType == typeof(bool?)) + { + propOrd.SetValue(order, obj.GetBooleanValue(property.Key)); + } + else if (propOrd.PropertyType == typeof(decimal) || propOrd.PropertyType == typeof(decimal?)) + { + propOrd.SetValue(order, obj.GetDecimalValue(property.Key)); + } + } + } + + JsonUtil.PropToUpper(order, "ORDNO", "BSSTATUS", "YARDID", "YardContract", "YardContractTel", "YardContractEmail", "MARKS", "DESCRIPTION", "CONSIGNEENAME", "SHIPPERNAME", "NOTIFYPARTYNAME", "DZRemark", "CZRemark"); + + order.VERSION = Guid.NewGuid().ToString(); + await _rep.UpdateAsync(order); + + //记录修改日志 + await SaveLog(order, orderCompare); + + //推送东胜 + await SendBookingOrder(new long[] { order.Id }); + } + /// /// 删除订舱 /// @@ -1884,7 +1960,7 @@ namespace Myshipping.Application } - + #endregion #region 放舱(入货通知) @@ -1987,37 +2063,41 @@ namespace Myshipping.Application public async Task SendLetterYard(long bookingId) { var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.BookingId == bookingId); - var json = entity.ToJsonString(); - try + if (entity != null) { - const string MqActionExchangeName = "djy.output.dingcang.ds6"; - const string MqActionQueueName = "djy.output.dingcang.ds6_fangcang"; - ConnectionFactory factory = new ConnectionFactory(); - factory.Uri = new Uri(_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()); + var json = entity.ToJsonString(); + try + { + const string MqActionExchangeName = "djy.output.dingcang.ds6"; + const string MqActionQueueName = "djy.output.dingcang.ds6_fangcang"; + ConnectionFactory factory = new ConnectionFactory(); + factory.Uri = new Uri(_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()); - using (IConnection conn = factory.CreateConnection()) + using (IConnection conn = factory.CreateConnection()) + { + IModel mqModel = conn.CreateModel(); + mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct); + var queueName = $"{MqActionQueueName}.{UserManager.TENANT_ID}"; + mqModel.QueueDeclare(queueName, false, false, false, null); + mqModel.QueueBind(queueName, MqActionExchangeName, queueName, null); + byte[] messageBodyBytes = Encoding.UTF8.GetBytes(json); + IBasicProperties props = mqModel.CreateBasicProperties(); + props.DeliveryMode = 2; + mqModel.BasicPublish(MqActionExchangeName, + queueName, props, + messageBodyBytes); + conn.Close(); + _logger.LogInformation($"放舱数据回推,已发送数据到消息队列【{_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()}】,数据内容:【{json}】"); + } + } + catch (Exception ex) { - IModel mqModel = conn.CreateModel(); - mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct); - var queueName = $"{MqActionQueueName}.{UserManager.TENANT_ID}"; - mqModel.QueueDeclare(queueName, false, false, false, null); - mqModel.QueueBind(queueName, MqActionExchangeName, queueName, null); - byte[] messageBodyBytes = Encoding.UTF8.GetBytes(json); - IBasicProperties props = mqModel.CreateBasicProperties(); - props.DeliveryMode = 2; - mqModel.BasicPublish(MqActionExchangeName, - queueName, props, - messageBodyBytes); - conn.Close(); - _logger.LogInformation($"放舱数据回推,已发送数据到消息队列【{_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()}】,数据内容:【{json}】"); + _logger.LogError(ex.Message); + _logger.LogError(ex.StackTrace); + } } - catch (Exception ex) - { - _logger.LogError(ex.Message); - _logger.LogError(ex.StackTrace); - } return null; } @@ -7381,6 +7461,8 @@ namespace Myshipping.Application var rtn = await GetYardDataAndMappingSystem(order, false); await _repCtn.DeleteAsync(x => x.BILLID == bookId); + _logger.LogInformation($"{bookId}({order.MBLNO})的箱封号自动引入获取场站数据:{rtn.ToJsonString()}"); + foreach (var item in rtn) { var ctn = new BookingCtn(); @@ -7401,6 +7483,7 @@ namespace Myshipping.Application await _repCtn.InsertAsync(ctn); } + _logger.LogInformation($"{bookId}({order.MBLNO})的箱封号自动引入完成"); } @@ -7752,10 +7835,10 @@ namespace Myshipping.Application [NonAction] public async Task SendBookingOrder(long[] ids) { - var itemcode = App.Configuration["ITEMCODE"]; - var BookingOrderMQUri= App.Configuration["SendBookingOrderMQUri"]; - _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri); - if (!string.IsNullOrEmpty(itemcode) && itemcode == "true") + var itemcode = App.Configuration["ITEMCODE"].ToString(); + var BookingOrderMQUri = App.Configuration["SendBookingOrderMQUri"]; + _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri + itemcode); + if (!string.IsNullOrEmpty(itemcode) && itemcode == "True") { if (ids.Count() == 0) { diff --git a/ServiceDeamon/App.config b/ServiceDeamon/App.config index 75622970..40b4dab8 100644 --- a/ServiceDeamon/App.config +++ b/ServiceDeamon/App.config @@ -1,7 +1,12 @@  + + + + + \ No newline at end of file diff --git a/ServiceDeamon/CheckServiceHelper.cs b/ServiceDeamon/CheckServiceHelper.cs index 0ba70891..9db8a57b 100644 --- a/ServiceDeamon/CheckServiceHelper.cs +++ b/ServiceDeamon/CheckServiceHelper.cs @@ -1,4 +1,5 @@ -using System; +using NLog; +using System; using System.Collections.Generic; using System.Configuration; using System.Linq; @@ -10,25 +11,29 @@ namespace ServiceDeamon { public class CheckServiceHelper { - private static ServiceController servCtl; - private static string ServName = ConfigurationManager.AppSettings["ServiceName"]; + private static readonly Logger log = LogManager.GetCurrentClassLogger(); + + private static ServiceControllerStatus LastStatus; + public static void CheckStatus() { - if (servCtl == null || servCtl.ServiceName != ServName) + var servCtl = new ServiceController(ServName); + + if (LastStatus != servCtl.Status) { - servCtl = new ServiceController(ServName); + log.Info($"服务 {ServName} 的当前状态:{servCtl.Status}"); } - Console.WriteLine($"服务 {ServName} 的当前状态:{servCtl.Status}"); - if (servCtl != null && servCtl.Status == ServiceControllerStatus.Stopped) { - Console.WriteLine($"服务已停止,自动启动:{ServName}"); + log.Info($"服务已停止,自动启动:{ServName}"); servCtl.Start(); } + LastStatus = servCtl.Status; + //Console.WriteLine("CheckStatus"); } } diff --git a/ServiceDeamon/DeamonService.cs b/ServiceDeamon/DeamonService.cs new file mode 100644 index 00000000..2b3015ed --- /dev/null +++ b/ServiceDeamon/DeamonService.cs @@ -0,0 +1,45 @@ +using NLog; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Topshelf; + +namespace ServiceDeamon +{ + public class DeamonService : ServiceControl + { + private static Timer timer; + private static int CheckInteval = Convert.ToInt32(ConfigurationManager.AppSettings["CheckInteval"]); + + private readonly Logger log = LogManager.GetCurrentClassLogger(); + + public bool Start(HostControl hostControl) + { + log.Info("服务启动"); + timer = new Timer(new TimerCallback(CheckSta)); + timer.Change(CheckInteval, Timeout.Infinite); + + return true; + } + + public bool Stop(HostControl hostControl) + { + log.Info("服务停止"); + timer.Change(-1, 0); + + return true; + } + + + + private static void CheckSta(object sta) + { + CheckServiceHelper.CheckStatus(); + + timer.Change(CheckInteval, Timeout.Infinite); + } + } +} diff --git a/ServiceDeamon/Program.cs b/ServiceDeamon/Program.cs index b4760fc8..13667c3b 100644 --- a/ServiceDeamon/Program.cs +++ b/ServiceDeamon/Program.cs @@ -1,27 +1,52 @@ using ServiceDeamon; using System.Configuration; using System.ServiceProcess; +using Topshelf; public class Program { - private static Timer timer; - - private static int CheckInteval = Convert.ToInt32(ConfigurationManager.AppSettings["CheckInteval"]); - public static void Main(string[] args) { - timer = new Timer(new TimerCallback(CheckSta)); - timer.Change(CheckInteval, Timeout.Infinite); - - - Console.Read(); - } - - private static void CheckSta(object sta) - { - CheckServiceHelper.CheckStatus(); - - timer.Change(CheckInteval, Timeout.Infinite); + try + { + var serviceName = ConfigurationManager.AppSettings["DeamonServiceName"]; + var serviceDisplayName = ConfigurationManager.AppSettings["DeamonServiceDisplayName"]; + + if (Environment.UserInteractive) + { + Console.Title = serviceDisplayName; + } + + Host host = HostFactory.New(x => + { + // 基本的配置 + x.RunAsLocalSystem(); + x.SetServiceName(serviceName); + x.SetDisplayName(serviceDisplayName); + x.StartAutomaticallyDelayed(); + x.EnableShutdown(); + + // 注册服务 + x.Service(hostSettings => new DeamonService()); + + // 设置服务失败后的操作,分别对应第一次、第二次、后续 + x.EnableServiceRecovery(t => + { + t.RestartService(0); + + t.RestartService(0); + + t.RestartService(0); + t.OnCrashOnly(); + }); + }); + + host.Run(); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } } } diff --git a/ServiceDeamon/ServiceDeamon.csproj b/ServiceDeamon/ServiceDeamon.csproj index ffa42eaf..dbb7128c 100644 --- a/ServiceDeamon/ServiceDeamon.csproj +++ b/ServiceDeamon/ServiceDeamon.csproj @@ -8,9 +8,16 @@ + + + + PreserveNewest + + + diff --git a/ServiceDeamon/nlog.config b/ServiceDeamon/nlog.config new file mode 100644 index 00000000..06724f5d --- /dev/null +++ b/ServiceDeamon/nlog.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + +