From bd5fe71ba3f02bae02503a1f59f26eef48fdba05 Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 12 Jul 2023 10:37:24 +0800 Subject: [PATCH 1/6] 1 --- .../Service/BookingOrder/BookingOrderService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 7667ada2..74ac294e 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -7752,10 +7752,10 @@ namespace Myshipping.Application [NonAction] public async Task SendBookingOrder(long[] ids) { - var itemcode = App.Configuration["ITEMCODE"]; + var itemcode = App.Configuration["ITEMCODE"].ToString() ; var BookingOrderMQUri= App.Configuration["SendBookingOrderMQUri"]; - _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri); - if (!string.IsNullOrEmpty(itemcode) && itemcode == "true") + _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri+ itemcode); + if (!string.IsNullOrEmpty(itemcode) && itemcode == "True") { if (ids.Count() == 0) { From d51c593f932da23ede97b064e678b200790e0cfd Mon Sep 17 00:00:00 2001 From: wet <1034391973@qq.com> Date: Wed, 12 Jul 2023 11:33:57 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=94=BE=E8=88=B1=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 74ac294e..67d1c7f8 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1987,37 +1987,40 @@ 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 - { - 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()) + if (entity!=null) { + var json = entity.ToJsonString(); + try { - 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}】"); + 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()) + { + 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) - { - _logger.LogError(ex.Message); - _logger.LogError(ex.StackTrace); + catch (Exception ex) + { + _logger.LogError(ex.Message); + _logger.LogError(ex.StackTrace); + } } + return null; } From 46305c447f8c44eb212f07aaa93fe58bb2e32e21 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Wed, 12 Jul 2023 11:51:16 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=AE=88=E6=8A=A4=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServiceDeamon/App.config | 5 +++ ServiceDeamon/CheckServiceHelper.cs | 14 ++++--- ServiceDeamon/DeamonService.cs | 41 +++++++++++++++++++++ ServiceDeamon/Program.cs | 57 +++++++++++++++++++++-------- 4 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 ServiceDeamon/DeamonService.cs 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..04a2f429 100644 --- a/ServiceDeamon/CheckServiceHelper.cs +++ b/ServiceDeamon/CheckServiceHelper.cs @@ -10,25 +10,27 @@ namespace ServiceDeamon { public class CheckServiceHelper { - private static ServiceController servCtl; - private static string ServName = ConfigurationManager.AppSettings["ServiceName"]; + 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); + Console.WriteLine($"服务 {ServName} 的当前状态:{servCtl.Status}"); } - Console.WriteLine($"服务 {ServName} 的当前状态:{servCtl.Status}"); - if (servCtl != null && servCtl.Status == ServiceControllerStatus.Stopped) { Console.WriteLine($"服务已停止,自动启动:{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..9a31fe2c --- /dev/null +++ b/ServiceDeamon/DeamonService.cs @@ -0,0 +1,41 @@ +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"]); + + + public bool Start(HostControl hostControl) + { + timer = new Timer(new TimerCallback(CheckSta)); + timer.Change(CheckInteval, Timeout.Infinite); + + return true; + } + + public bool Stop(HostControl hostControl) + { + 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); + } } } From 70f3173c9d03e5d916fa7c4857b9fd1ea1cfcb0e Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Wed, 12 Jul 2023 13:52:11 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ServiceDeamon/CheckServiceHelper.cs | 9 ++++++--- ServiceDeamon/DeamonService.cs | 6 +++++- ServiceDeamon/ServiceDeamon.csproj | 7 +++++++ ServiceDeamon/nlog.config | 30 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 ServiceDeamon/nlog.config diff --git a/ServiceDeamon/CheckServiceHelper.cs b/ServiceDeamon/CheckServiceHelper.cs index 04a2f429..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; @@ -12,6 +13,8 @@ namespace ServiceDeamon { private static string ServName = ConfigurationManager.AppSettings["ServiceName"]; + private static readonly Logger log = LogManager.GetCurrentClassLogger(); + private static ServiceControllerStatus LastStatus; public static void CheckStatus() @@ -20,12 +23,12 @@ namespace ServiceDeamon if (LastStatus != servCtl.Status) { - Console.WriteLine($"服务 {ServName} 的当前状态:{servCtl.Status}"); + log.Info($"服务 {ServName} 的当前状态:{servCtl.Status}"); } if (servCtl != null && servCtl.Status == ServiceControllerStatus.Stopped) { - Console.WriteLine($"服务已停止,自动启动:{ServName}"); + log.Info($"服务已停止,自动启动:{ServName}"); servCtl.Start(); } diff --git a/ServiceDeamon/DeamonService.cs b/ServiceDeamon/DeamonService.cs index 9a31fe2c..2b3015ed 100644 --- a/ServiceDeamon/DeamonService.cs +++ b/ServiceDeamon/DeamonService.cs @@ -1,4 +1,5 @@ -using System; +using NLog; +using System; using System.Collections.Generic; using System.Configuration; using System.Linq; @@ -13,9 +14,11 @@ namespace ServiceDeamon 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); @@ -24,6 +27,7 @@ namespace ServiceDeamon public bool Stop(HostControl hostControl) { + log.Info("服务停止"); timer.Change(-1, 0); return true; 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 @@ + + + + + + + + + + + + + + + + + + + From f6fca37cb4f694109449a77c3dc5423cde6d1f95 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Wed, 12 Jul 2023 14:27:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=B8=8B=E8=B4=A7=E7=BA=B8=E5=86=BB?= =?UTF-8?q?=E6=9F=9C=E5=92=8C=E5=8D=B1=E9=99=A9=E5=93=81=E5=BF=85=E5=A1=AB?= =?UTF-8?q?=E9=A1=B9=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/XiahuozhiHelpler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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); From 813dfe388a4917a7df0a228f6006ab612c3bc606 Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Wed, 12 Jul 2023 15:48:12 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=8F=B0=E8=B4=A6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 92 +++++++++++++++++-- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 67d1c7f8..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,7 +2063,8 @@ namespace Myshipping.Application public async Task SendLetterYard(long bookingId) { var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.BookingId == bookingId); - if (entity!=null) { + if (entity != null) + { var json = entity.ToJsonString(); try { @@ -2020,7 +2097,7 @@ namespace Myshipping.Application } } - + return null; } @@ -7384,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(); @@ -7404,6 +7483,7 @@ namespace Myshipping.Application await _repCtn.InsertAsync(ctn); } + _logger.LogInformation($"{bookId}({order.MBLNO})的箱封号自动引入完成"); } @@ -7755,9 +7835,9 @@ namespace Myshipping.Application [NonAction] public async Task SendBookingOrder(long[] ids) { - var itemcode = App.Configuration["ITEMCODE"].ToString() ; - var BookingOrderMQUri= App.Configuration["SendBookingOrderMQUri"]; - _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri+ itemcode); + 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)