cjy 2 weeks ago
commit 2d3ab90c90

@ -21,4 +21,10 @@
<ProjectReference Include="..\DS.WMS.Core\DS.WMS.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

@ -0,0 +1,142 @@
using iText.Kernel.Pdf.Canvas.Parser.ClipperLib;
using iText.Layout.Properties;
using Microsoft.AspNetCore.Mvc;
using Spire.Xls.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DS.WMS.FeeBillRecvService
{
/// <summary>
/// 客户类型枚举
/// </summary>
public enum CustomerTypeEnum
{
/// <summary>
/// 船公司
/// </summary>
[Description("船公司")]
carrier,
/// <summary>
/// 场站
/// </summary>
[Description("场站")]
yard,
/// <summary>
/// 订舱口
/// </summary>
[Description("订舱口")]
booking,
/// <summary>
/// 车队
/// </summary>
[Description("车队")]
truck,
/// <summary>
/// 委托单位
/// </summary>
[Description("委托单位")]
controller,
/// <summary>
/// 船公司
/// </summary>
[Description("报关行")]
custom,
/// <summary>
/// 代理(国外)
/// </summary>
[Description("代理(国外)")]
agent,
/// <summary>
/// 代理(国内)
/// </summary>
[Description("代理(国内)")]
agentcn,
/// <summary>
/// 快递公司
/// </summary>
[Description("快递公司")]
express,
/// <summary>
/// 航空公司
/// </summary>
[Description("航空公司")]
airlines,
/// <summary>
/// 发货人
/// </summary>
[Description("发货人")]
shipper,
/// <summary>
/// 收货人
/// </summary>
[Description("收货人")]
consignee,
/// <summary>
/// 通知人
/// </summary>
[Description("通知人")]
notifyParty,
/// <summary>
/// 仓库
/// </summary>
[Description("仓库")]
wareHouse,
/// <summary>
/// 通知人
/// </summary>
[Description("保险公司")]
insurer,
/// <summary>
/// 租箱公司
/// </summary>
[Description("租箱公司")]
leasing,
/// <summary>
/// 贸易代理
/// </summary>
[Description("贸易代理")]
tradingagency,
/// <summary>
/// 船代
/// </summary>
[Description("船代")]
shipagency,
/// <summary>
/// 经营单位
/// </summary>
[Description("经营单位")]
enterprise,
/// <summary>
/// 码头
/// </summary>
[Description("码头")]
wharf,
/// <summary>
/// 国内同行
/// </summary>
[Description("国内同行")]
domesticPeers,
/// <summary>
/// 国外同行
/// </summary>
[Description("国外同行")]
foreignCounterparts,
/// <summary>
/// 国内直客
/// </summary>
[Description("国内直客")]
isDirectCustomerCn,
/// <summary>
/// 国内发货人
/// </summary>
[Description("国内发货人")]
shippercn,
}
}

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.FeeBillRecvService
{
/// <summary>
/// 计费标准枚举
/// </summary>
public enum FeeUnitEnum
{
/// <summary>
/// 单票
/// </summary>
[Description("单票")]
P,
/// <summary>
/// 重量
/// </summary>
[Description("重量")]
Z,
/// <summary>
/// 尺码
/// </summary>
[Description("尺码")]
C,
/// <summary>
/// 件数
/// </summary>
[Description("件数")]
J,
/// <summary>
/// 计费吨
/// </summary>
[Description("计费吨")]
JF,
/// <summary>
/// TEU
/// </summary>
[Description("TEU")]
TEU,
/// <summary>
/// 净重
/// </summary>
[Description("净重")]
JZ,
/// <summary>
/// 总价
/// </summary>
[Description("总价")]
ZJ,
/// <summary>
/// 计价重量
/// </summary>
[Description("计价重量")]
JJZL,
/// <summary>
/// 箱型
/// </summary>
[Description("箱型")]
XX,
/// <summary>
/// 天
/// </summary>
[Description("天")]
DAY,
/// <summary>
/// 个
/// </summary>
[Description("个")]
GE,
/// <summary>
/// 小时
/// </summary>
[Description("小时")]
HOUR,
/// <summary>
/// 票
/// </summary>
[Description("票")]
Bill,
/// <summary>
/// 箱
/// </summary>
[Description("箱")]
CNTR,
}
}

@ -3,10 +3,25 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.HangfireJob.Interface;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.FeeBillRecvService.Dtos;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NPOI.OpenXmlFormats.Wordprocessing;
using Org.BouncyCastle.Ocsp;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using SqlSugar;
namespace DS.WMS.FeeBillRecvService
{
@ -15,43 +30,25 @@ namespace DS.WMS.FeeBillRecvService
private readonly ILogger<RecvFeeBillWorker> _logger;
private IConnection mqConn;
private IModel model;
public RecvFeeBillWorker(ILogger<RecvFeeBillWorker> logger)
{
_logger = logger;
}
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
public override async Task StartAsync(CancellationToken stoppingToken)
public RecvFeeBillWorker(IServiceProvider serviceProvider,
ILogger<RecvFeeBillWorker> logger)
{
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);
}
_logger = logger;
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("启动j账单 ExecuteAsync");
_logger.LogInformation("启动账单 ExecuteAsync");
return Task.Run(() =>
{
@ -65,14 +62,18 @@ namespace DS.WMS.FeeBillRecvService
private void BindMQ()
{
string ExchangeName = "billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6";
string QueueName = $"billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6";
//string ExchangeName = "billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6";
//string QueueName = $"billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6";
string ExchangeName = AppSetting.app(new string[] { "FeeSettings", "ExchangeName" });
string QueueName = AppSetting.app(new string[] { "FeeSettings", "QueueName" });
var mqUrl = AppSetting.app(new string[] { "FeeSettings", "MQUrl" });
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 = "amqp://dongsheng8bill:dongsheng8bill@47.104.207.5:12567/billcenter";
//var mqUrl = repoSysCfg.FirstOrDefault(x => x.Code == "DjyBookingAutoMQUrl")?.Value;
if (string.IsNullOrEmpty(mqUrl))
{
@ -86,7 +87,7 @@ namespace DS.WMS.FeeBillRecvService
model = mqConn.CreateModel();
model.ExchangeDeclare(ExchangeName, ExchangeType.Topic);
model.QueueDeclare(QueueName, false, false, true, null);
model.QueueDeclare(QueueName, false, false, false, null);
model.QueueBind(QueueName, ExchangeName, "*", null);
var consumer = new EventingBasicConsumer(model);
@ -95,6 +96,9 @@ namespace DS.WMS.FeeBillRecvService
var body = arg.Body;
var strBody = Encoding.UTF8.GetString(body.ToArray());
_logger.LogInformation($"收到订舱自动化消息队列:{strBody}");
DoWork(strBody);
};
model.BasicConsume(QueueName, true, consumer);
}
@ -110,10 +114,197 @@ namespace DS.WMS.FeeBillRecvService
_logger.LogInformation("BookingAutoService Dispose");
}
private async Task DoWork(CancellationToken cancellationToken)
private void DoWork(string json)
{
/*
1
2
3
*/
string msg = string.Empty;
try
{
var model = GetInfo(json, out msg);
_logger.LogInformation($"报文转换完成 GID={model.GID} BookingBill={model.BookingBill} 共【{model.DetailList.Count}】条");
//var tenantDb = saasService.GetBizJobDbScopeById(new JobDbInitConfig
//{
// UserId = 1819549542463442944,
// UserName = "东胜8测试",
// TenantId = 1819549542425694208,
// OrgId = 1819557001806614528
//});
var tenantDb = saasService.GetBizJobDbScopeById(new JobDbInitConfig
{
//UserId = long.Parse(AppSetting.app(new string[] { "FeeSettings", "UserId" })),
//UserName = AppSetting.app(new string[] { "FeeSettings", "UserName" }),
TenantId = long.Parse(AppSetting.app(new string[] { "FeeSettings", "TenantId" })),
//OrgId = long.Parse(AppSetting.app(new string[] { "FeeSettings", "OrgId" })),
});
_logger.LogInformation($"提取对应租户数据访问完成 GID={model.GID} BookingBill={model.BookingBill}");
string blno = model.BookingBill?.Trim();
_logger.LogInformation($"提取订单信息 GID={model.GID} BookingBill={model.BookingBill}");
var booking = tenantDb.Queryable<SeaExport>().ClearFilter(typeof(IOrgId)).First(a => a.MBLNO == blno && a.Deleted == false && (a.IsRefund == null || a.IsRefund.Value == false)
&& (a.IsChangeETD == null || a.IsChangeETD.Value == false));
_logger.LogInformation($"提取订单完成 GID={model.GID} BookingBill={model.BookingBill} Order={JsonConvert.SerializeObject(booking)}");
if (booking != null)
{
DateTime nowDate = DateTime.Now;
var custTypeDict = DS.Module.Core.EnumUtil.GetEnumDictionaryWithKey(typeof(CustomerTypeEnum));
var feeUnitDict = DS.Module.Core.EnumUtil.GetEnumDictionaryWithKey(typeof(FeeUnitEnum));
var codeCurrency = tenantDb.Queryable<FeeCurrency>().ToList();
var userInfo = db.Queryable<SysUser>().Filter(null, true).First(x => x.Id == booking.OperatorId && x.TenantId == long.Parse("1819549542425694208"));
List<string> errorMsgList = new List<string>();
int start = 1;
foreach (var fee in model.DetailList)
{
string qFee = fee.CustSysName?.Trim();
//if(string.IsNullOrWhiteSpace(qFee))
//{
// errorMsgList.Add("没有费用名称");
// continue;
//}
var feecode = tenantDb.Queryable<FeeCode>().First(x => x.Name == qFee);
if (feecode == null)
{
}
var newfee = new FeeRecord();
newfee.BusinessId = booking.Id;
newfee.FeeId = feecode.Id;
newfee.FeeName = feecode.Name;
newfee.FeeCode = feecode.Code;
newfee.TaxRate = feecode.TaxRate == null ? 0 : (decimal)feecode.TaxRate;
newfee.BusinessType = BusinessType.OceanShippingExport;
string custShortName = string.Empty;
string custType = string.Empty;
if (fee.CustSettleFor.IndexOf("#") >= 0)
{
var currArg = fee.CustSettleFor.Split(new char[] { '#' });
custShortName = currArg[0]?.Trim();
if (currArg.Length == 2)
{
custType = currArg[1].Trim();
}
}
else
{
custShortName = fee.CustSettleFor?.Trim();
}
var customerInfo = tenantDb.Queryable<InfoClient>().ClearFilter(typeof(IOrgId)).First(x => x.ShortName == custShortName);
newfee.CustomerId = customerInfo.Id;
newfee.CustomerName = customerInfo.Description;
var custTypeKey = custTypeDict.FirstOrDefault(x => x.Value == custType);
newfee.CustomerType = custTypeKey.Key;
newfee.CustomerTypeText = custTypeKey.Value;
newfee.FeeType = FeeType.Payable; //租箱月结明细.FeeType;
var feeUnitKey = feeUnitDict.FirstOrDefault(x => x.Value == fee.CustFeeStandard?.Trim());
newfee.Unit = feeUnitKey.Key;
newfee.UnitText = feeUnitKey.Value;
var currCurrCode = codeCurrency.First(a => a.CodeName == fee.CustCurrency);
newfee.Currency = currCurrCode.CodeName;
if (!fee.UnitPrice.HasValue)
{
if (fee.Quantity.HasValue && fee.Amount.HasValue)
{
var price = fee.Amount.Value / fee.Quantity.Value;
newfee.TaxUnitPrice = price;
}
else
{
newfee.TaxUnitPrice = 0;
}
}
else
{
newfee.TaxUnitPrice = fee.UnitPrice.Value;
}
newfee.Quantity = fee.Quantity.HasValue ? fee.Quantity.Value : 0;
newfee.Amount = fee.Amount.HasValue ? fee.Amount.Value : 0;
newfee.CreateTime = nowDate;
newfee.CreateBy = userInfo.Id;
newfee.CreateUserName = userInfo.UserName;
newfee.UpdateTime = nowDate;
newfee.Note = "大简云账单解析";
_logger.LogInformation($"写入账单开始 第【{start}】条 GID={model.GID} BookingBill={model.BookingBill} Order={JsonConvert.SerializeObject(newfee)}");
tenantDb.Insertable<FeeRecord>(newfee).ExecuteCommand();
_logger.LogInformation($"写入账单完成 第【{start}】条 GID={model.GID} BookingBill={model.BookingBill} Order={JsonConvert.SerializeObject(newfee)}");
start++;
}
}
}
catch (Exception ex)
{
_logger.LogInformation($"产生异常,原因:{ex.Message}");
}
}
private FeeBillReadDto GetInfo(string json,out string msg)
{
// 这里放你的业务逻辑代码
await Task.CompletedTask;
FeeBillReadDto model = null;
msg = string.Empty;
try
{
model = JsonConvert.DeserializeObject<FeeBillReadDto>(json);
}
catch(Exception ex)
{
msg = $"转换报文异常,原因:{ex.Message}";
}
return model;
}
}
}

@ -18,5 +18,15 @@
"Connection": "server=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;port=3306;uid=rulesengine_admin;pwd=Rule1qaz2wsx!QAZ;database=shippingweb8_log"
}
]
},
"FeeSettings": {
"ShowName": "昭阳接收邮件账单",
"UserId": "1819549542463442944",
"UserName": "东胜8测试",
"TenantId": "1819549542425694208",
"OrgId": "1819557001806614528",
"ExchangeName": "billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6",
"QueueName": "billcenter.output.ds7new.444c19c1-0bf5-4709-a08b-c9859ca775e6",
"MQUrl": "amqp://dongsheng8bill:dongsheng8bill@47.104.207.5:12567/billcenter"
}
}

@ -0,0 +1,36 @@
<?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"
internalLogLevel="info"
internalLogFile="Logs\internal-nlog.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<targets>
<!-- 写入文件配置 -->
<!-- 将日志写入文件 -->
<target xsi:type="File" name="allfile" fileName="Logs\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring} ${newline}" />
<!-- 另一个文件日志只有自己的日志。使用一些ASP.NET核心渲染器 -->
<target xsi:type="File" name="ownFile-web" fileName="Logs\nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action} ${newline}" />
<!-- 将日志写入控制台 -->
<target name="console" xsi:type="ColoredConsole" layout="${longdate} ${message} ${exception:format=tostring}" />
</targets>
<rules>
<!--所有日志包括来自Microsoft的-->
<!--minlevel 改为Trace 跟踪全部 Error 只捕获异常-->
<!-- <logger name="*" minlevel="Trace" writeTo="allfile" /> -->
<logger name="*" minlevel="Trace" writeTo="console" />
<!--跳过非关键的Microsoft日志因此只记录自己的日志-->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<!-- BlackHole without writeTo -->
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
Loading…
Cancel
Save