jianghaiqing 1 year ago
commit 653853ae5c

@ -75,6 +75,17 @@ namespace Myshipping.Application.EDI
return new KeyValuePair<bool, string>(false, "海关航次不能为空"); return new KeyValuePair<bool, string>(false, "海关航次不能为空");
} }
//2023年7月12日下货纸为冻柜需填写温度和通风危险品需填写等级和编号
if (order.CARGOID == "R" && (string.IsNullOrEmpty(order.TEMPSET) || string.IsNullOrEmpty(order.REEFERF)))
{
return new KeyValuePair<bool, string>(false, "冻柜的温度和通风必须填写");
}
if (order.CARGOID == "D" && (string.IsNullOrEmpty(order.DUNNO) || string.IsNullOrEmpty(order.DCLASS)))
{
return new KeyValuePair<bool, string>(false, "危险品的等级和编号必须填写");
}
var fileOpt = App.GetOptions<BookingAttachOptions>(); var fileOpt = App.GetOptions<BookingAttachOptions>();
if (string.IsNullOrEmpty(fileOpt.basePath)) if (string.IsNullOrEmpty(fileOpt.basePath))
{ {
@ -412,7 +423,7 @@ namespace Myshipping.Application.EDI
repBookingFile.Insert(attFile); repBookingFile.Insert(attFile);
//发送邮件 //发送邮件
var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL,new KeyValuePair<string, byte[]>(ediFileName, msResult.GetBuffer())); var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL, new KeyValuePair<string, byte[]>(ediFileName, msResult.GetBuffer()));
if (!sendResult.Key) if (!sendResult.Key)
{ {
return new KeyValuePair<bool, string>(false, sendResult.Value); return new KeyValuePair<bool, string>(false, sendResult.Value);

@ -1046,6 +1046,82 @@ namespace Myshipping.Application
await SendBookingOrder(new long[] { order.Id }); await SendBookingOrder(new long[] { order.Id });
} }
/// <summary>
/// 在订舱台账保存单证备注、操作备注等功能
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[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<long> 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 });
}
/// <summary> /// <summary>
/// 删除订舱 /// 删除订舱
/// </summary> /// </summary>
@ -1884,7 +1960,7 @@ namespace Myshipping.Application
} }
#endregion #endregion
#region 放舱(入货通知) #region 放舱(入货通知)
@ -1987,37 +2063,41 @@ namespace Myshipping.Application
public async Task<dynamic> SendLetterYard(long bookingId) public async Task<dynamic> SendLetterYard(long bookingId)
{ {
var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.BookingId == bookingId); var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.BookingId == bookingId);
var json = entity.ToJsonString(); if (entity != null)
try
{ {
const string MqActionExchangeName = "djy.output.dingcang.ds6"; var json = entity.ToJsonString();
const string MqActionQueueName = "djy.output.dingcang.ds6_fangcang"; try
ConnectionFactory factory = new ConnectionFactory(); {
factory.Uri = new Uri(_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()); 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(); _logger.LogError(ex.Message);
mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct); _logger.LogError(ex.StackTrace);
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);
}
return null; return null;
} }
@ -7381,6 +7461,8 @@ namespace Myshipping.Application
var rtn = await GetYardDataAndMappingSystem(order, false); var rtn = await GetYardDataAndMappingSystem(order, false);
await _repCtn.DeleteAsync(x => x.BILLID == bookId); await _repCtn.DeleteAsync(x => x.BILLID == bookId);
_logger.LogInformation($"{bookId}({order.MBLNO})的箱封号自动引入获取场站数据:{rtn.ToJsonString()}");
foreach (var item in rtn) foreach (var item in rtn)
{ {
var ctn = new BookingCtn(); var ctn = new BookingCtn();
@ -7401,6 +7483,7 @@ namespace Myshipping.Application
await _repCtn.InsertAsync(ctn); await _repCtn.InsertAsync(ctn);
} }
_logger.LogInformation($"{bookId}({order.MBLNO})的箱封号自动引入完成");
} }
@ -7752,10 +7835,10 @@ namespace Myshipping.Application
[NonAction] [NonAction]
public async Task<dynamic> SendBookingOrder(long[] ids) public async Task<dynamic> SendBookingOrder(long[] ids)
{ {
var itemcode = App.Configuration["ITEMCODE"]; var itemcode = App.Configuration["ITEMCODE"].ToString();
var BookingOrderMQUri= App.Configuration["SendBookingOrderMQUri"]; var BookingOrderMQUri = App.Configuration["SendBookingOrderMQUri"];
_logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri); _logger.LogInformation("订舱数据回推地址:" + BookingOrderMQUri + itemcode);
if (!string.IsNullOrEmpty(itemcode) && itemcode == "true") if (!string.IsNullOrEmpty(itemcode) && itemcode == "True")
{ {
if (ids.Count() == 0) if (ids.Count() == 0)
{ {

@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="DeamonServiceName" value="ServiceDeamon"/>
<add key="DeamonServiceDisplayName" value="进程守护服务"/>
<add key="ServiceName" value="nginx"/> <add key="ServiceName" value="nginx"/>
<add key="CheckInteval" value="5000"/> <add key="CheckInteval" value="5000"/>
</appSettings> </appSettings>
</configuration> </configuration>

@ -1,4 +1,5 @@
using System; using NLog;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
using System.Linq; using System.Linq;
@ -10,25 +11,29 @@ namespace ServiceDeamon
{ {
public class CheckServiceHelper public class CheckServiceHelper
{ {
private static ServiceController servCtl;
private static string ServName = ConfigurationManager.AppSettings["ServiceName"]; private static string ServName = ConfigurationManager.AppSettings["ServiceName"];
private static readonly Logger log = LogManager.GetCurrentClassLogger();
private static ServiceControllerStatus LastStatus;
public static void CheckStatus() 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) if (servCtl != null && servCtl.Status == ServiceControllerStatus.Stopped)
{ {
Console.WriteLine($"服务已停止,自动启动:{ServName}"); log.Info($"服务已停止,自动启动:{ServName}");
servCtl.Start(); servCtl.Start();
} }
LastStatus = servCtl.Status;
//Console.WriteLine("CheckStatus"); //Console.WriteLine("CheckStatus");
} }
} }

@ -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);
}
}
}

@ -1,27 +1,52 @@
using ServiceDeamon; using ServiceDeamon;
using System.Configuration; using System.Configuration;
using System.ServiceProcess; using System.ServiceProcess;
using Topshelf;
public class Program public class Program
{ {
private static Timer timer;
private static int CheckInteval = Convert.ToInt32(ConfigurationManager.AppSettings["CheckInteval"]);
public static void Main(string[] args) public static void Main(string[] args)
{ {
timer = new Timer(new TimerCallback(CheckSta)); try
timer.Change(CheckInteval, Timeout.Infinite); {
var serviceName = ConfigurationManager.AppSettings["DeamonServiceName"];
var serviceDisplayName = ConfigurationManager.AppSettings["DeamonServiceDisplayName"];
Console.Read();
} if (Environment.UserInteractive)
{
private static void CheckSta(object sta) Console.Title = serviceDisplayName;
{ }
CheckServiceHelper.CheckStatus();
Host host = HostFactory.New(x =>
timer.Change(CheckInteval, Timeout.Infinite); {
// 基本的配置
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);
}
} }
} }

@ -8,9 +8,16 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NLog" Version="5.2.2" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" /> <PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="7.0.1" /> <PackageReference Include="System.ServiceProcess.ServiceController" Version="7.0.1" />
<PackageReference Include="Topshelf" Version="4.3.0" /> <PackageReference Include="Topshelf" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogLevel="Warning"
internalLogFile="Logs/nlog-internal.log">
<!-- enable asp.net core layout renderers -->
<extensions>
</extensions>
<!-- the targets to write to -->
<targets>
<target name="fileDebug"
xsi:type="File"
fileName="${basedir}/logs/${shortdate}-debug.log"
layout="${longdate} [${uppercase:${level}}] [${callsite}] [${threadid}] | ${message}${newline}" archiveAbovesize="10240000" enableArchiveFileCompression="true" />
<target name="errorDebug"
xsi:type="File"
fileName="${basedir}/logs/${shortdate}-error.log"
layout="${longdate} [${uppercase:${level}}] [${callsite}] [${threadid}] | ${message}${newline}" archiveAbovesize="10240000" enableArchiveFileCompression="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" maxlevel="Info" writeTo="fileDebug" />
<logger name="*" minlevel="Warning" writeTo="errorDebug" />
</rules>
</nlog>
Loading…
Cancel
Save