From 96e7b5716978a24e1f11e1db961566f34db093ea Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Tue, 26 Dec 2023 17:58:21 +0800 Subject: [PATCH] AFR --- .gitignore | 8 + web/.editorconfig | 4 + web/djy.IService/Afr/IAfrService.cs | 12 ++ web/djy.Model/AFR/AFRCntrno.cs | 165 ++++++++++++++++ web/djy.Model/AFR/AFRHouse.cs | 177 ++++++++++++++++++ web/djy.Model/AFR/AFRMaster.cs | 135 +++++++++++++ web/djy.Model/AFR/AFRMasterHistory.cs | 51 +++++ .../AFR/生成实体类/__razor.cshtml.txt | 66 +++++++ .../AFR/生成实体类/__重新生成.bat | 2 + web/djy.Model/AFRDto/AFRMasterDto.cs | 12 ++ web/djy.Model/AFRDto/AFRMasterPageDataDto.cs | 20 ++ web/djy.Model/djy.Model.csproj | 4 + web/djy.Service/Afr/AfrService.cs | 15 ++ web/djy.Service/DjyService/DbContext.cs | 26 +-- web/djy.WebApi/djy_AmsApi.csproj.user | 2 +- web/djy_AfrApi/Controllers/AfrController.cs | 24 ++- web/djy_AfrApi/HttpContextUser/AspNetUser.cs | 11 +- .../ExceptionHandlerMiddleware.cs | 22 ++- .../Milldlewares/RequRespLogMiddleware.cs | 20 +- web/djy_AfrApi/NLog.config | 2 +- web/djy_AfrApi/appsettings.Development.json | 12 +- web/djy_AfrApi/appsettings.Staging.json | 12 +- web/djy_IsfApi/appsettings.Development.json | 12 +- web/djy_ams.sln | 7 +- 24 files changed, 760 insertions(+), 61 deletions(-) create mode 100644 .gitignore create mode 100644 web/.editorconfig create mode 100644 web/djy.IService/Afr/IAfrService.cs create mode 100644 web/djy.Model/AFR/AFRCntrno.cs create mode 100644 web/djy.Model/AFR/AFRHouse.cs create mode 100644 web/djy.Model/AFR/AFRMaster.cs create mode 100644 web/djy.Model/AFR/AFRMasterHistory.cs create mode 100644 web/djy.Model/AFR/生成实体类/__razor.cshtml.txt create mode 100644 web/djy.Model/AFR/生成实体类/__重新生成.bat create mode 100644 web/djy.Model/AFRDto/AFRMasterDto.cs create mode 100644 web/djy.Model/AFRDto/AFRMasterPageDataDto.cs create mode 100644 web/djy.Service/Afr/AfrService.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fb8597 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +################################################################################ +# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 +################################################################################ + +/web/djy.Model/AFR/生成实体类/AFRCntrno.cs +/web/djy.Model/AFR/生成实体类/AFRHouse.cs +/web/djy.Model/AFR/生成实体类/AFRMaster.cs +/web/djy.Model/AFR/生成实体类/AFRMasterHistory.cs diff --git a/web/.editorconfig b/web/.editorconfig new file mode 100644 index 0000000..36d44d5 --- /dev/null +++ b/web/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# CS1591: 缺少对公共可见类型或成员的 XML 注释 +dotnet_diagnostic.CS1591.severity = suggestion diff --git a/web/djy.IService/Afr/IAfrService.cs b/web/djy.IService/Afr/IAfrService.cs new file mode 100644 index 0000000..9210540 --- /dev/null +++ b/web/djy.IService/Afr/IAfrService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace djy.IService.Afr +{ + public interface IAfrService + { + } +} diff --git a/web/djy.Model/AFR/AFRCntrno.cs b/web/djy.Model/AFR/AFRCntrno.cs new file mode 100644 index 0000000..408d8e6 --- /dev/null +++ b/web/djy.Model/AFR/AFRCntrno.cs @@ -0,0 +1,165 @@ +using FreeSql.DataAnnotations; +using System; + +namespace djy.Model.Afr +{ + + /// + /// + /// + [Table(Name = "AFR_Cntrno", DisableSyncStructure = true)] + public partial class AFRCntrno + { + /// + /// + /// + public string GID { get; set; } + + /// + /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + /// + public string BusinessId { get; set; } + + /// + /// + /// + public string CompID { get; set; } + + /// + /// + /// + public string CompName { get; set; } + + /// + /// 货主箱标志 + /// + public string ContainerMark { get; set; } + + /// + /// 箱号 + /// + public string ContainerNo { get; set; } + + /// + /// 箱型 + /// + public string ContainerType { get; set; } + + /// + /// + /// + public DateTime? CreateTime { get; set; } + + /// + /// 危品联系人(选填) + /// + public string DangerContact { get; set; } + + /// + /// 危品联系人电话(选填) + /// + public string DangerContactTel { get; set; } + + /// + /// 危品等级(条件必填) + /// + public string DangerGrade { get; set; } + + /// + /// 危品备注(选填) + /// + public string DangerMemo { get; set; } + + /// + /// 件数 + /// + public int? Digit { get; set; } + + /// + /// 品名 + /// + public string EnProductName { get; set; } + + /// + /// 毛重 + /// + public double? GrossWeight { get; set; } + + /// + /// HSCode + /// + public string Hscode { get; set; } + + /// + /// 燃点,摄氏度(选填) + /// + public string Ignite { get; set; } + + /// + /// + /// + public bool? IsDel { get; set; } + + /// + /// + /// + public DateTime? LastUpdate { get; set; } + + /// + /// 原产国(选填) + /// + public string OriginCountry { get; set; } + + /// + /// 原产国国家代码(选填) + /// + public string OriginCountryCode { get; set; } + + /// + /// 包装 + /// + public string Packing { get; set; } + + /// + /// 包装代码 + /// + public string PackingCode { get; set; } + + /// + /// + /// + public string PID { get; set; } + + /// + /// 封号 + /// + public string SealNo { get; set; } + + /// + /// 唛头 + /// + public string ShippingMark { get; set; } + + /// + /// UN CODE(条件必填) + /// + public string UnCode { get; set; } + + /// + /// + /// + public string UserID { get; set; } + + /// + /// + /// + public string UserName { get; set; } + + /// + /// 体积 + /// + public double? Volume { get; set; } + + } + +} diff --git a/web/djy.Model/AFR/AFRHouse.cs b/web/djy.Model/AFR/AFRHouse.cs new file mode 100644 index 0000000..c5b1471 --- /dev/null +++ b/web/djy.Model/AFR/AFRHouse.cs @@ -0,0 +1,177 @@ +using FreeSql.DataAnnotations; +using System; + +namespace djy.Model.Afr +{ + + /// + /// + /// + [Table(Name = "AFR_House", DisableSyncStructure = true)] + public partial class AFRHouse + { + + /// + /// + /// + public string GID { get; set; } + + /// + /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 + /// + public string BusinessId { get; set; } + + /// + /// + /// + public string CompID { get; set; } + + /// + /// + /// + public string CompName { get; set; } + + /// + /// + /// + public DateTime? CreateTime { get; set; } + + /// + /// 货代提单号 修改报文,该值不可以变更 + /// + /// + public string HouseBillNo { get; set; } + + /// + /// + /// + public bool? IsDel { get; set; } + + /// + /// + /// + public DateTime? LastUpdate { get; set; } + + /// + /// 通知人地址 + /// + public string NotifyAddress { get; set; } + + /// + /// 通知人城市 + /// + public string NotifyCity { get; set; } + + /// + /// 通知人联系人 + /// + public string NotifyContact { get; set; } + + /// + /// 通知人国家 + /// + public string NotifyCountry { get; set; } + + /// + /// 通知人国家代码 + /// + public string NotifyCountryCode { get; set; } + + /// + /// 通知人名称 + /// + public string NotifyName { get; set; } + + /// + /// 通知人联系人电话 + /// + public string NotifyTel { get; set; } + + /// + /// 收货人地址 + /// + public string ReceiveAddress { get; set; } + + /// + /// 收货人城市 + /// + public string ReceiveCity { get; set; } + + /// + /// 收货人联系人 + /// + public string ReceiveContact { get; set; } + + /// + /// 收货人国家 + /// + public string ReceiveCountry { get; set; } + + /// + /// 收货人国家代码 + /// + public string ReceiveCountryCode { get; set; } + + /// + /// 收货人名称 + /// + public string ReceiveName { get; set; } + + /// + /// 收货人联系人电话 + /// + public string ReceiveTel { get; set; } + + /// + /// 发货人地址 + /// + public string SendAddress { get; set; } + + /// + /// 发货人城市 + /// + public string SendCity { get; set; } + + /// + /// 发货人联系人 + /// + public string SendContact { get; set; } + + /// + /// 发货人国家 + /// + public string SendCountry { get; set; } + + /// + /// 发货人国家代码 + /// + public string SendCountryCode { get; set; } + + /// + /// 发货人名称 + /// + public string SendName { get; set; } + + /// + /// 发货人联系人电话 + /// + public string SendTel { get; set; } + + /// + /// 货代单运编号(选填) + /// + public string ShippingNo { get; set; } + + /// + /// + /// + public string UserID { get; set; } + + /// + /// + /// + public string UserName { get; set; } + + } + +} diff --git a/web/djy.Model/AFR/AFRMaster.cs b/web/djy.Model/AFR/AFRMaster.cs new file mode 100644 index 0000000..b27e244 --- /dev/null +++ b/web/djy.Model/AFR/AFRMaster.cs @@ -0,0 +1,135 @@ +using FreeSql.DataAnnotations; +using System; + +namespace djy.Model.Afr +{ + /// + /// + /// + [Table(Name = "AFR_Master", DisableSyncStructure = true)] + public partial class AFRMaster + { + + /// + /// + /// + public string GID { get; set; } + + /// + /// 运输条款代码 + /// + public string Clause { get; set; } + + /// + /// + /// + public string CompID { get; set; } + + /// + /// + /// + public string CompName { get; set; } + + /// + /// 整箱/拼箱 + /// + public string ConsignmentType { get; set; } + + /// + /// + /// + public DateTime? CreateTime { get; set; } + + /// + /// 卸货港全称 + /// + public string DischargeHarbour { get; set; } + + /// + /// 卸货港五字码 + /// + public string DischargeHarbourCode { get; set; } + + /// + /// 预计到达日期 + /// + public DateTime? EstimatedArrivalTime { get; set; } + + /// + /// 申报运输类型 + /// + public string FilingType { get; set; } + + /// + /// + /// + public bool? IsDel { get; set; } + + /// + /// 交货地全称(条件)申报运输类型Tranship时,必填 + /// + public string LastForeignHarbour { get; set; } + + /// + /// 交货地五字码(条件)申报运输类型Tranship时,必填 + /// + public string LastForeignHarbourCode { get; set; } + + /// + /// + /// + public DateTime? LastUpdate { get; set; } + + /// + /// 预计开船日期 + /// + public DateTime? LoadDate { get; set; } + + /// + /// 装货港全称 + /// + public string LoadHarbour { get; set; } + + /// + /// 装货港五字码 + /// + public string LoadHarbourCode { get; set; } + + /// + /// 船东提单号 + /// + public string MBLNO { get; set; } + + /// + /// + /// + public string ShipCompany { get; set; } + + /// + /// 船东单运编号(选填) + /// + public string ShippingNo { get; set; } + + /// + /// + /// + public string UserID { get; set; } + + /// + /// + /// + public string UserName { get; set; } + + /// + /// + /// + public string Vessel { get; set; } + + /// + /// + /// + public string Voyno { get; set; } + + } + +} diff --git a/web/djy.Model/AFR/AFRMasterHistory.cs b/web/djy.Model/AFR/AFRMasterHistory.cs new file mode 100644 index 0000000..8253db6 --- /dev/null +++ b/web/djy.Model/AFR/AFRMasterHistory.cs @@ -0,0 +1,51 @@ +using FreeSql.DataAnnotations; +using System; + +namespace djy.Model.Afr +{ + + /// + /// + /// + [Table(Name = "AFR_MasterHistory", DisableSyncStructure = true)] + public partial class AFRMasterHistory + { + + /// + /// + /// + public string GID { get; set; } + + /// + /// + /// + public string AMID { get; set; } + + /// + /// + /// + public string Operator { get; set; } + + /// + /// + /// + public string Remark { get; set; } + + /// + /// + /// + public DateTime? SendTime { get; set; } + + /// + /// + /// + public string State { get; set; } + + /// + /// + /// + public string Type { get; set; } + + } + +} diff --git a/web/djy.Model/AFR/生成实体类/__razor.cshtml.txt b/web/djy.Model/AFR/生成实体类/__razor.cshtml.txt new file mode 100644 index 0000000..a869d08 --- /dev/null +++ b/web/djy.Model/AFR/生成实体类/__razor.cshtml.txt @@ -0,0 +1,66 @@ +using FreeSql.DatabaseModel;@{ +var gen = Model as RazorModel; + +Func GetAttributeString = attr => { + if (string.IsNullOrEmpty(attr)) return ""; + return string.Concat(", ", attr.Trim('[', ']')).Trim(','); +}; +Func GetDefaultValue = defval => { + if (string.IsNullOrEmpty(defval)) return ""; + return " = " + defval + ";"; +}; +}@{ +switch (gen.fsql.Ado.DataType) { + case FreeSql.DataType.PostgreSQL: +@:using System; +@:using System.Collections; +@:using System.Collections.Generic; +@:using System.Linq; +@:using System.Reflection; +@:using System.Threading.Tasks; +@:using Newtonsoft.Json; +@:using FreeSql.DataAnnotations; +@:using System.Net; +@:using Newtonsoft.Json.Linq; +@:using System.Net.NetworkInformation; +@:using NpgsqlTypes; +@:using Npgsql.LegacyPostgis; + break; + case FreeSql.DataType.SqlServer: + case FreeSql.DataType.MySql: + default: +@:using System; +@:using System.Collections; +@:using System.Collections.Generic; +@:using System.Linq; +@:using System.Reflection; +@:using System.Threading.Tasks; +@:using Newtonsoft.Json; +@:using FreeSql.DataAnnotations; + break; +} +} + +namespace @gen.NameSpace { + +@if (false == false) { + @:/// + @:/// @gen.table.Comment.Replace("\r\n", "\n").Replace("\n", "\r\n /// ") + @:/// +} + [@GetAttributeString(gen.GetTableAttribute())] + public partial class @gen.GetCsName(gen.FullTableName) { + + @foreach (var col in gen.columns) { + + if (false == false) { + @:/// + @:/// @col.Comment.Replace("\r\n", "\n").Replace("\n", "\r\n /// ") + @:/// + } + @:public @gen.GetCsType(col) @gen.GetCsName(col.Name) { get; set; }@GetDefaultValue(gen.GetColumnDefaultValue(col, false)) +@: + } + } +@gen.GetMySqlEnumSetDefine() +} \ No newline at end of file diff --git a/web/djy.Model/AFR/生成实体类/__重新生成.bat b/web/djy.Model/AFR/生成实体类/__重新生成.bat new file mode 100644 index 0000000..642dc4e --- /dev/null +++ b/web/djy.Model/AFR/生成实体类/__重新生成.bat @@ -0,0 +1,2 @@ + +FreeSql.Generator -Razor "__razor.cshtml.txt" -NameOptions 0,0,0,1 -NameSpace djy.Model.Afr -DB "SqlServer,Data Source=60.209.125.238,32009;Initial Catalog=DevAMS;User Id=sa;Password=Djy@Sql2022.test;" -Filter "View+StoreProcedure" -Match "AFR" -FileName "{name}.cs" diff --git a/web/djy.Model/AFRDto/AFRMasterDto.cs b/web/djy.Model/AFRDto/AFRMasterDto.cs new file mode 100644 index 0000000..ab35a29 --- /dev/null +++ b/web/djy.Model/AFRDto/AFRMasterDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace djy.Model.AFRDto +{ + public class AFRMasterDto + { + } +} diff --git a/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs b/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs new file mode 100644 index 0000000..34ad4f9 --- /dev/null +++ b/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs @@ -0,0 +1,20 @@ +namespace djy.Model.AFRDto +{ + public class AFRMasterPageDataDto + { + /// + /// 查询类型(1:草稿箱列表 2:已发送列表) + /// + public int Type { get; set; } + + /// + /// 当前页 + /// + public int Page { get; set; } + + /// + /// 每页数量 + /// + public int Limit { get; set; } + } +} diff --git a/web/djy.Model/djy.Model.csproj b/web/djy.Model/djy.Model.csproj index 8e3cf9a..b860c7a 100644 --- a/web/djy.Model/djy.Model.csproj +++ b/web/djy.Model/djy.Model.csproj @@ -24,6 +24,10 @@ + + + + diff --git a/web/djy.Service/Afr/AfrService.cs b/web/djy.Service/Afr/AfrService.cs new file mode 100644 index 0000000..e11ef0d --- /dev/null +++ b/web/djy.Service/Afr/AfrService.cs @@ -0,0 +1,15 @@ +using djy.IService.Afr; +using djy.Service.DjyService; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace djy.Service.AFR +{ + public class AfrService : DbContext, IAfrService + { + + } +} diff --git a/web/djy.Service/DjyService/DbContext.cs b/web/djy.Service/DjyService/DbContext.cs index d2d8bc4..4624f9c 100644 --- a/web/djy.Service/DjyService/DbContext.cs +++ b/web/djy.Service/DjyService/DbContext.cs @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Common; using System.Data; - + namespace djy.Service.DjyService { /// @@ -25,15 +25,15 @@ namespace djy.Service.DjyService /// ///大简云平台老库 /// - public const string djyolddb = "djydb"; + public const string djyolddb = "djydb"; /// /// AMS /// - public const string AMSCenter = "AMS"; + public const string AMSCenter = "AMS"; /// /// 日志库 /// - public const string Logsdb = "logsdb"; + public const string Logsdb = "logsdb"; /// /// Common库 @@ -49,13 +49,13 @@ namespace djy.Service.DjyService /// /// 数据库操作类 /// - public class DbContext + public class DbContext { /// /// 数据库连接池 /// - public static IdleBus DbBus=new IdleBus(TimeSpan.FromSeconds(20)); - + public static IdleBus DbBus = new IdleBus(TimeSpan.FromSeconds(20)); + /// /// RedisDB /// @@ -65,11 +65,11 @@ namespace djy.Service.DjyService /// 数据库连接池初始化 /// /// - public static bool DbBusInit() { + public static bool DbBusInit() + { foreach (var item in sysOptionConfig.Webconfig.DataConnList) { - if (item.SysKey == DbList.Logsdb)//日志库允许自动更新表结构 { DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString) @@ -100,11 +100,11 @@ namespace djy.Service.DjyService } - - - - + + + + } diff --git a/web/djy.WebApi/djy_AmsApi.csproj.user b/web/djy.WebApi/djy_AmsApi.csproj.user index f46bcf1..9e60180 100644 --- a/web/djy.WebApi/djy_AmsApi.csproj.user +++ b/web/djy.WebApi/djy_AmsApi.csproj.user @@ -4,7 +4,7 @@ MvcControllerEmptyScaffolder root/Common/MVC/Controller C:\Project\DJYAMS\djyweb_ams\web\djy.WebApi\Properties\PublishProfiles\FolderProfile.pubxml - IIS Express + djy_AmsApi ProjectDebugger diff --git a/web/djy_AfrApi/Controllers/AfrController.cs b/web/djy_AfrApi/Controllers/AfrController.cs index c8f6bb6..c927dc2 100644 --- a/web/djy_AfrApi/Controllers/AfrController.cs +++ b/web/djy_AfrApi/Controllers/AfrController.cs @@ -1,10 +1,14 @@ using Common.Utilities; +using djy.IService.Afr; using djy.Model; +using djy.Model.Afr; +using djy.Model.AFRDto; using djy_AfrApi.HttpContextUser; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using System.Collections.Generic; using System.Threading.Tasks; namespace djy_AfrApi.Controllers @@ -13,22 +17,30 @@ namespace djy_AfrApi.Controllers { private readonly ILogger logger; private readonly IUser user; - private readonly ILogger bigLogger; + private readonly IAfrService afrService; - public AfrController(ILogger logger, ILoggerFactory loggerFactory, IUser user) + //private readonly ILogger bigLogger; + + public AfrController(ILogger logger, + IUser user, + IAfrService afrService) { this.logger = logger; this.user = user; + this.afrService = afrService; // 获取ILogger对象 - bigLogger = loggerFactory.CreateLogger("BigDataLogger"); // 通过指定名称获取ILogger对象 + //ILoggerFactory loggerFactory, + //bigLogger = loggerFactory.CreateLogger("BigDataLogger"); // 通过指定名称获取ILogger对象 } #region 查询接口 - [HttpGet("Load")] - public async Task Load() + [HttpGet("[action]")] + public async Task>> PageData(AFRMasterPageDataDto input) { - return MessageModel.Success("12312", new { ff = "11", fff = "22" }); + var data = afrService.Load(); + + return default; } [HttpGet("[action]")] diff --git a/web/djy_AfrApi/HttpContextUser/AspNetUser.cs b/web/djy_AfrApi/HttpContextUser/AspNetUser.cs index fd022aa..2bddd82 100644 --- a/web/djy_AfrApi/HttpContextUser/AspNetUser.cs +++ b/web/djy_AfrApi/HttpContextUser/AspNetUser.cs @@ -23,13 +23,16 @@ namespace djy_AfrApi.HttpContextUser var user = accessor.HttpContext.Items["CurrentUser"] as User; if (user != null) { - accessor.HttpContext.Items["CurrentUser"] = user; - return user; + return user; } var userId = accessor.HttpContext.User?.Claims?.FirstOrDefault(c => c.Type == "loginid")?.Value; - var user2 = userService.GetUserInfo(userId); - if (user2.Data != null) return user2.Data; + var userTemp = userService.GetUserInfo(userId); + if (userTemp.Data != null) + { + accessor.HttpContext.Items["CurrentUser"] = userTemp.Data; + return userTemp.Data; + } throw new Exception("获取当前登录用户时发生异常"); } diff --git a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs index 81bbca7..bb7a5ea 100644 --- a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs @@ -1,5 +1,6 @@ using djy.Model; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Net; @@ -10,17 +11,19 @@ namespace djy_AfrApi.Middlewares public class ExceptionHandlerMiddleware { private readonly RequestDelegate _next; + private readonly ILogger logger; - public ExceptionHandlerMiddleware(RequestDelegate next) + public ExceptionHandlerMiddleware(RequestDelegate next, ILogger logger) { _next = next; + this.logger = logger; } public async Task Invoke(HttpContext context) { try { - //_ = int.Parse(""); + _ = int.Parse(""); await _next(context); } catch (Exception ex) @@ -32,7 +35,8 @@ namespace djy_AfrApi.Middlewares private async Task HandleExceptionAsync(HttpContext context, Exception e) { if (e == null) return; - // TODO :记录日志 + + logger.LogError(WriteLog("ExceptionHandlerMiddleware中捕获的全局异常", e)); await WriteExceptionAsync(context, e).ConfigureAwait(false); } @@ -56,5 +60,17 @@ namespace djy_AfrApi.Middlewares .WriteAsync(JsonConvert.SerializeObject(new MessageModel() { code = 500, message = message })) .ConfigureAwait(false); } + + /// + /// 自定义返回格式 + /// + /// + /// + /// + public string WriteLog(string throwMsg, Exception ex) + { + return string.Format("\r\n【自定义错误】:{0} \r\n【异常类型】:{1} \r\n【异常信息】:{2} \r\n【堆栈调用】:{3}\r\n自定义异常结束", new object[] { throwMsg, + ex.GetType().Name, ex.Message, ex.StackTrace }); + } } } \ No newline at end of file diff --git a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs index 7249f37..ab1f868 100644 --- a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs @@ -31,19 +31,11 @@ namespace djy_AfrApi.Milldlewares //// 存储请求数据 var request = context.Request; var sr = new StreamReader(request.Body); - RequestLogInfo requestResponse = new RequestLogInfo() - { - Path = request.Path, - QueryString = request.QueryString.ToString(), - BodyData = await sr.ReadToEndAsync() - }; - var content = JsonConvert.SerializeObject(requestResponse); - - if (!string.IsNullOrEmpty(content)) - { - _logger.LogInformation($"请求 - {context.TraceIdentifier}{Environment.NewLine}{content}"); - request.Body.Position = 0; - } + + var bodyData = await sr.ReadToEndAsync(); + + _logger.LogInformation($"请求 - {context.TraceIdentifier}{Environment.NewLine}[Path]:{request.Path} [QueryString]:{request.QueryString}{Environment.NewLine}[Body]:{bodyData}"); + request.Body.Position = 0; // 存储响应数据 using (MemoryStream memoryStream = new MemoryStream()) @@ -62,7 +54,7 @@ namespace djy_AfrApi.Milldlewares string responseBody = new StreamReader(memoryStream).ReadToEnd(); // 记录响应内容 - _logger.LogInformation($"响应 - {context.TraceIdentifier} - {_stopwatch.ElapsedMilliseconds}ms{Environment.NewLine}StatusCode:{context.Response.StatusCode}{Environment.NewLine}{responseBody}"); + _logger.LogInformation($"响应 - {context.TraceIdentifier} - {_stopwatch.ElapsedMilliseconds}ms{Environment.NewLine}[StatusCode]:{context.Response.StatusCode} [Body]:{responseBody}"); // 将响应内容写回原始响应流 memoryStream.Seek(0, SeekOrigin.Begin); diff --git a/web/djy_AfrApi/NLog.config b/web/djy_AfrApi/NLog.config index 08ce953..0a84496 100644 --- a/web/djy_AfrApi/NLog.config +++ b/web/djy_AfrApi/NLog.config @@ -52,7 +52,7 @@ - + diff --git a/web/djy_AfrApi/appsettings.Development.json b/web/djy_AfrApi/appsettings.Development.json index 1d17f19..69b9a9c 100644 --- a/web/djy_AfrApi/appsettings.Development.json +++ b/web/djy_AfrApi/appsettings.Development.json @@ -28,8 +28,8 @@ "Rbmq_Host": "", "Rbmq_UserName": "admin", "Rbmq_Password": "admin", - "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true", - "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;", + "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true", + "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;", "DataConnList": [ { "SysKey": "AMS", @@ -37,7 +37,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "Common", @@ -45,7 +45,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "djydb", @@ -53,7 +53,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" }, { "SysKey": "logsdb", @@ -61,7 +61,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" } ] } diff --git a/web/djy_AfrApi/appsettings.Staging.json b/web/djy_AfrApi/appsettings.Staging.json index b2f34f6..a6a722b 100644 --- a/web/djy_AfrApi/appsettings.Staging.json +++ b/web/djy_AfrApi/appsettings.Staging.json @@ -28,8 +28,8 @@ "Rbmq_Host": "", "Rbmq_UserName": "admin", "Rbmq_Password": "admin", - "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true", - "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;", + "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true", + "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;", "DataConnList": [ { "SysKey": "AMS", @@ -37,7 +37,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "Common", @@ -45,7 +45,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "djydb", @@ -53,7 +53,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" }, { "SysKey": "logsdb", @@ -61,7 +61,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" } ] } diff --git a/web/djy_IsfApi/appsettings.Development.json b/web/djy_IsfApi/appsettings.Development.json index 1c97a0c..0629ddd 100644 --- a/web/djy_IsfApi/appsettings.Development.json +++ b/web/djy_IsfApi/appsettings.Development.json @@ -27,8 +27,8 @@ "Rbmq_Host": "", "Rbmq_UserName": "admin", "Rbmq_Password": "admin", - "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true", - "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;", + "Rbmq_Sqlhost": "Data Source =60.209.125.238; Initial Catalog=djy_logs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true", + "DapperDbString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;", "requesterDea": "nbforwarder", "DataConnList": [ @@ -38,7 +38,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevAMS; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "Common", @@ -46,7 +46,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true;" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=DevCommonDB; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true;" }, { "SysKey": "djydb", @@ -54,7 +54,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDsPingTai; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" }, { @@ -63,7 +63,7 @@ "Index": 100, "DataType": 1, "Status": 0, - "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=sa@djy.net;pooling=true" + "ConnString": "Data Source =60.209.125.238,32009; Initial Catalog=TestDjyLogs; Persist Security Info=True; User ID =sa; Password=Djy@Sql2022.test;pooling=true" } diff --git a/web/djy_ams.sln b/web/djy_ams.sln index f264b5f..7111de0 100644 --- a/web/djy_ams.sln +++ b/web/djy_ams.sln @@ -27,7 +27,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "djy_IsfApi", "djy_IsfApi\dj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "djy_Report", "djy_Report\djy_Report.csproj", "{A201194B-42CA-41BF-8123-7DB5D332C940}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "djy_AfrApi", "djy_AfrApi\djy_AfrApi.csproj", "{E798A4EC-13E8-4681-8DB7-CB9F3C32A3EE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "djy_AfrApi", "djy_AfrApi\djy_AfrApi.csproj", "{E798A4EC-13E8-4681-8DB7-CB9F3C32A3EE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A168654F-F0E2-408D-8BA1-D71AD5C00850}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution