diff --git a/ds-wms-service/DS.WMS.FeeBillRecvService/DS.WMS.FeeBillRecvService.csproj b/ds-wms-service/DS.WMS.FeeBillRecvService/DS.WMS.FeeBillRecvService.csproj index befc2135..0c83bc4b 100644 --- a/ds-wms-service/DS.WMS.FeeBillRecvService/DS.WMS.FeeBillRecvService.csproj +++ b/ds-wms-service/DS.WMS.FeeBillRecvService/DS.WMS.FeeBillRecvService.csproj @@ -10,6 +10,7 @@ + diff --git a/ds-wms-service/DS.WMS.FeeBillRecvService/Dtos/FeeBillReadDto.cs b/ds-wms-service/DS.WMS.FeeBillRecvService/Dtos/FeeBillReadDto.cs new file mode 100644 index 00000000..00836e8e --- /dev/null +++ b/ds-wms-service/DS.WMS.FeeBillRecvService/Dtos/FeeBillReadDto.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.FeeBillRecvService.Dtos +{ + public class FeeBillReadDto + { + /// + /// 主键 + /// + public string GID { get; set; } + + /// + /// 提单号 + /// + public string BookingBill { get; set; } + + /// + /// 发票号 + /// + public string InvoiceNumber { get; set; } + + /// + /// 费用明细 + /// + public List DetailList { get; set; } + } + + public class FeeBillReadDetailDto + { + /// + /// 主键 + /// + public string GID { get; set; } + + /// + /// 费用名称 + /// + public string CostName { get; set; } + + /// + /// 单价 + /// + public Nullable UnitPrice { get; set; } + + /// + /// 数量 + /// + public Nullable Quantity { get; set; } + + /// + /// 总金额 + /// + public Nullable Amount { get; set; } + + /// + /// 计费标准 BILL-按票 + /// + public string FeeStandard { get; set; } + + /// + /// 标题 + /// + public string Tips { get; set; } + + /// + /// 客户费用代码 + /// + public string CustSysCode { get; set; } + + /// + /// 客户费用名称 + /// + public string CustSysName { get; set; } + + /// + /// 币别 + /// + public string CustCurrency { get; set; } + + /// + /// 结算对象 + /// + public string CustSettleFor { get; set; } + + /// + /// 客户计费类型 + /// + public string CustFeeStandard { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.FeeBillRecvService/Program.cs b/ds-wms-service/DS.WMS.FeeBillRecvService/Program.cs index aad6e58a..e0e4545d 100644 --- a/ds-wms-service/DS.WMS.FeeBillRecvService/Program.cs +++ b/ds-wms-service/DS.WMS.FeeBillRecvService/Program.cs @@ -41,7 +41,9 @@ builder.Services.AddSaasDbInstall();//分库服务 //应用作为 Windows 服务 //builder.Services.AddWindowsService(); -//builder.Services.AddHostedService(); +builder.Services.AddHostedService(); + + //允许 BackgroundService 中存在未经处理的异常,不停止主机 builder.Services.Configure(hostOptions => diff --git a/ds-wms-service/DS.WMS.FeeBillRecvService/RecvFeeBillWorker.cs b/ds-wms-service/DS.WMS.FeeBillRecvService/RecvFeeBillWorker.cs new file mode 100644 index 00000000..c6322518 --- /dev/null +++ b/ds-wms-service/DS.WMS.FeeBillRecvService/RecvFeeBillWorker.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; + +namespace DS.WMS.FeeBillRecvService +{ + public class RecvFeeBillWorker : BackgroundService + { + private readonly ILogger _logger; + private IConnection mqConn; + private IModel model; + + public RecvFeeBillWorker(ILogger logger) + { + _logger = logger; + } + + + public override async Task StartAsync(CancellationToken stoppingToken) + { + try + { + //while (!stoppingToken.IsCancellationRequested) + //{ + // _OpServer = new BackgroundJobServer(new BackgroundJobServerOptions + // { + // SchedulePollingInterval = TimeSpan.FromMinutes(1), + // ServerName = "OpWorkService", + // Queues = new[] { "op" } + // }); + // await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken); + //} + } + catch (OperationCanceledException ex) + { + Console.WriteLine(ex.ToString()); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + //Environment.Exit(1); + } + + } + + protected override Task ExecuteAsync(CancellationToken stoppingToken) + { + _logger.LogInformation("启动j账单 ExecuteAsync"); + + return Task.Run(() => + { + _logger.LogInformation("BookingAutoService ExecuteAsync RunTask"); + + //绑定队列 + BindMQ(); + }); + + } + + private void BindMQ() + { + string ExchangeName = "billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6"; + string QueueName = $"billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6"; + + ConnectionFactory factory = new ConnectionFactory(); + + //var repoSysCfg = _serviceScope.ServiceProvider.GetService>(); + + var mqUrl = "amqp://djy_mail:djymailqwe@47.104.207.5:12567/djy_email_parser"; + //var mqUrl = repoSysCfg.FirstOrDefault(x => x.Code == "DjyBookingAutoMQUrl")?.Value; + if (string.IsNullOrEmpty(mqUrl)) + { + _logger.LogError($"接收订舱自动化消息推送所需MQUrl未配置"); + } + else + { + _logger.LogInformation($"准备连接订舱自动化消息队列:{mqUrl}"); + factory.Uri = new Uri(mqUrl); + mqConn = factory.CreateConnection("东胜8接收账单邮件解析"); + + model = mqConn.CreateModel(); + model.ExchangeDeclare(ExchangeName, ExchangeType.Topic); + model.QueueDeclare(QueueName, false, false, true, null); + model.QueueBind(QueueName, ExchangeName, "*", null); + + var consumer = new EventingBasicConsumer(model); + consumer.Received += (obj, arg) => + { + var body = arg.Body; + var strBody = Encoding.UTF8.GetString(body.ToArray()); + _logger.LogInformation($"收到订舱自动化消息队列:{strBody}"); + }; + model.BasicConsume(QueueName, true, consumer); + } + } + + public override void Dispose() + { + base.Dispose(); + //_serviceScope.Dispose(); + if (mqConn != null && mqConn.IsOpen) + mqConn.Close(); + + _logger.LogInformation("BookingAutoService Dispose"); + } + + private async Task DoWork(CancellationToken cancellationToken) + { + // 这里放你的业务逻辑代码 + await Task.CompletedTask; + } + } +} diff --git a/ds-wms-service/DS.WMS.FeeBillRecvService/appsettings.json b/ds-wms-service/DS.WMS.FeeBillRecvService/appsettings.json new file mode 100644 index 00000000..993532c9 --- /dev/null +++ b/ds-wms-service/DS.WMS.FeeBillRecvService/appsettings.json @@ -0,0 +1,22 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "DBInfo": { + "DefaultDbConnId": "1288018625843826688", + "DefaultDbType": 0, + "DefaultDbString": "server=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;port=3306;uid=rulesengine_admin;pwd=Rule1qaz2wsx!QAZ;database=shippingweb8_dev", + "DBS": [ + { + "ConnId": "1288018625843826680", + "DBType": 0, + "Enabled": false, + "HitRate": 40, + "Connection": "server=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;port=3306;uid=rulesengine_admin;pwd=Rule1qaz2wsx!QAZ;database=shippingweb8_log" + } + ] + } +}