修改邮件账单解析服务

dev
jianghaiqing 3 weeks ago
parent 99d91800a7
commit ed56ad6aea

@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
</ItemGroup>
<ItemGroup>

@ -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
{
/// <summary>
/// 主键
/// </summary>
public string GID { get; set; }
/// <summary>
/// 提单号
/// </summary>
public string BookingBill { get; set; }
/// <summary>
/// 发票号
/// </summary>
public string InvoiceNumber { get; set; }
/// <summary>
/// 费用明细
/// </summary>
public List<FeeBillReadDetailDto> DetailList { get; set; }
}
public class FeeBillReadDetailDto
{
/// <summary>
/// 主键
/// </summary>
public string GID { get; set; }
/// <summary>
/// 费用名称
/// </summary>
public string CostName { get; set; }
/// <summary>
/// 单价
/// </summary>
public Nullable<decimal> UnitPrice { get; set; }
/// <summary>
/// 数量
/// </summary>
public Nullable<decimal> Quantity { get; set; }
/// <summary>
/// 总金额
/// </summary>
public Nullable<decimal> Amount { get; set; }
/// <summary>
/// 计费标准 BILL-按票
/// </summary>
public string FeeStandard { get; set; }
/// <summary>
/// 标题
/// </summary>
public string Tips { get; set; }
/// <summary>
/// 客户费用代码
/// </summary>
public string CustSysCode { get; set; }
/// <summary>
/// 客户费用名称
/// </summary>
public string CustSysName { get; set; }
/// <summary>
/// 币别
/// </summary>
public string CustCurrency { get; set; }
/// <summary>
/// 结算对象
/// </summary>
public string CustSettleFor { get; set; }
/// <summary>
/// 客户计费类型
/// </summary>
public string CustFeeStandard { get; set; }
}
}

@ -41,7 +41,9 @@ builder.Services.AddSaasDbInstall();//分库服务
//应用作为 Windows 服务
//builder.Services.AddWindowsService();
//builder.Services.AddHostedService<WindowsBackgroundService>();
builder.Services.AddHostedService<RecvFeeBillWorker>();
//允许 BackgroundService 中存在未经处理的异常,不停止主机
builder.Services.Configure<HostOptions>(hostOptions =>

@ -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<RecvFeeBillWorker> _logger;
private IConnection mqConn;
private IModel model;
public RecvFeeBillWorker(ILogger<RecvFeeBillWorker> 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<SqlSugarRepository<SysConfig>>();
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;
}
}
}

@ -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"
}
]
}
}
Loading…
Cancel
Save