From 53adb7ffde5569c3522cb0fb3443ba18fbe4a7b0 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Wed, 27 Dec 2023 15:50:47 +0800 Subject: [PATCH] =?UTF-8?q?AFR=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/Djy.Common/Common.csproj | 1 + web/Djy.Common/Helpers/LogLock.cs | 123 ++++++++++ web/Djy.Common/Utilities/PageModel.cs | 40 +++ web/Djy.Common/Utilities/Response.cs | 42 +++- web/djy.IService/Afr/IAfrService.cs | 22 +- web/djy.IService/djy.IService.csproj | 1 + web/djy.Model/AFR/AFRBaseModel.cs | 50 ++++ web/djy.Model/AFR/AFRCntrno.cs | 46 +--- web/djy.Model/AFR/AFRHouse.cs | 45 +--- web/djy.Model/AFR/AFRMaster.cs | 50 +--- web/djy.Model/AFRDto/AFRMasterDto.cs | 12 +- web/djy.Model/AFRDto/AFRMasterInputDto.cs | 49 ++++ web/djy.Model/AFRDto/AFRMasterPageDataDto.cs | 20 -- web/djy.Model/AFRDto/AFRReceiptDto.cs | 21 ++ web/djy.Model/djy.Model.csproj | 1 + web/djy.Service/Afr/AfrService.cs | 231 +++++++++++++++++- web/djy.Service/DjyService/DbContext.cs | 34 ++- web/djy.Service/djy.Service.csproj | 1 + web/djy_AfrApi/Controllers/AfrController.cs | 65 +++-- web/djy_AfrApi/Controllers/ApiBase.cs | 151 ++++-------- .../Controllers/CommonController.cs | 224 +++++++++++++++++ .../Filter/GlobalExceptionsFilter.cs | 6 +- .../Log/SqlLog/SqlLog_2023-12-27.log | 33 +++ .../ExceptionHandlerMiddleware.cs | 9 +- .../NextAuthorizationMiddleware.cs | 8 +- .../Milldlewares/UnifyResultMiddleware.cs | 9 +- web/djy_AfrApi/Properties/launchSettings.json | 2 +- web/djy_AfrApi/djy_AfrApi.csproj | 1 + 28 files changed, 1000 insertions(+), 297 deletions(-) create mode 100644 web/Djy.Common/Helpers/LogLock.cs create mode 100644 web/Djy.Common/Utilities/PageModel.cs create mode 100644 web/djy.Model/AFR/AFRBaseModel.cs create mode 100644 web/djy.Model/AFRDto/AFRMasterInputDto.cs delete mode 100644 web/djy.Model/AFRDto/AFRMasterPageDataDto.cs create mode 100644 web/djy.Model/AFRDto/AFRReceiptDto.cs create mode 100644 web/djy_AfrApi/Controllers/CommonController.cs create mode 100644 web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log diff --git a/web/Djy.Common/Common.csproj b/web/Djy.Common/Common.csproj index 702fe37..d1fe6fb 100644 --- a/web/Djy.Common/Common.csproj +++ b/web/Djy.Common/Common.csproj @@ -8,6 +8,7 @@ Common Common包 1.2.1 + false diff --git a/web/Djy.Common/Helpers/LogLock.cs b/web/Djy.Common/Helpers/LogLock.cs new file mode 100644 index 0000000..fe71829 --- /dev/null +++ b/web/Djy.Common/Helpers/LogLock.cs @@ -0,0 +1,123 @@ +using System; +using System.IO; +using System.Threading; + +namespace Common.Helpers +{ + public class LogLock + { + //private static readonly ILog log = LogManager.GetLogger(typeof(LogLock)); + private static ReaderWriterLockSlim LogWriteLock = new(); + //private static int WritedCount = 0; + //private static int FailedCount = 0; + private static string _contentRoot = string.Empty; + + public LogLock(string contentPath) + { + _contentRoot = contentPath; + } + + public static void LogRecordAccess(string[] dataParas, bool IsHeader = true, bool isWrt = false) + { + OutSql2LogToFile("RecordAccessLog", dataParas, IsHeader, isWrt); + } + public static void LogInfo(string[] dataParas, bool IsHeader = true, bool isWrt = false) + { + OutSql2LogToFile("InfoLog", dataParas, IsHeader, isWrt); + } + public static void LogSql(string[] dataParas, bool IsHeader = true, bool isWrt = false) + { + OutSql2LogToFile("SqlLog", dataParas, IsHeader, isWrt); + } + + public static void OutSql2LogToFile(string prefix, string[] dataParas, bool IsHeader = true, bool isWrt = false) + { + try + { + //设置读写锁为写入模式独占资源,其他写入请求需要等待本次写入结束之后才能继续写入 + //注意:长时间持有读线程锁或写线程锁会使其他线程发生饥饿 (starve)。 为了得到最好的性能,需要考虑重新构造应用程序以将写访问的持续时间减少到最小。 + // 从性能方面考虑,请求进入写入模式应该紧跟文件操作之前,在此处进入写入模式仅是为了降低代码复杂度 + // 因进入与退出写入模式应在同一个try finally语句块内,所以在请求进入写入模式之前不能触发异常,否则释放次数大于请求次数将会触发异常 + LogWriteLock.EnterWriteLock(); + + string folderPath = Path.Combine(_contentRoot, "Log", prefix); + if (!Directory.Exists(folderPath)) + { + Directory.CreateDirectory(folderPath); + } + //string logFilePath = Path.Combine(path, $@"{filename}.log"); + //string logFilePath = FileHelper.GetAvailableFileWithPrefixOrderSize(folderPath, prefix, 3145728); + string logFilePath = Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.ToString("yyyy-MM-dd")}.log"); + + DateTime now = DateTime.Now; + string logContent; + if (IsHeader) + { + logContent = ( + "--------------------------------\r\n" + + DateTime.Now + "|\r\n" + + String.Join("\r\n", dataParas) + "\r\n" + ); + } + else + { + logContent = String.Join("\r\n", dataParas); + } + if (isWrt) + { + File.WriteAllText(logFilePath, logContent); + } + else + { + File.AppendAllText(logFilePath, logContent); + } + //WritedCount++; + } + catch (Exception e) + { + Console.Write(e.Message); + //FailedCount++; + } + finally + { + //退出写入模式,释放资源占用 + //注意:一次请求对应一次释放 + // 若释放次数大于请求次数将会触发异常[写入锁定未经保持即被释放] + // 若请求处理完成后未释放将会触发异常[此模式不下允许以递归方式获取写入锁定] + LogWriteLock.ExitWriteLock(); + } + } + //public static void OutSql2LogToDB(string prefix, string[] dataParas, bool IsHeader = true) + //{ + + // string logContent = String.Join("", dataParas); + // if (IsHeader) + // { + // logContent = (String.Join("", dataParas)); + // } + // switch (prefix) + // { + // case "AOPLog": + // log.Info(logContent); + // break; + // case "AOPLogEx": + // log.Error(logContent); + // break; + // case "RequestIpInfoLog": + // log.Debug(logContent); + // break; + // case "RecordAccessLogs": + // log.Debug(logContent); + // break; + // case "SqlLog": + // log.Info(logContent); + // break; + // case "RequestResponseLog": + // log.Debug(logContent); + // break; + // default: + // break; + // } + //} + } +} diff --git a/web/Djy.Common/Utilities/PageModel.cs b/web/Djy.Common/Utilities/PageModel.cs new file mode 100644 index 0000000..35b2c95 --- /dev/null +++ b/web/Djy.Common/Utilities/PageModel.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +namespace Common.Utilities +{ + public class PageModel + { + /// + /// 第几页,从1开始 + /// + public int PageNumber { get; set; } = 1; + /// + /// 总页数 + /// + public int PageCount => (int)Math.Ceiling((decimal)Count / PageSize); + /// + /// 查询的记录数量 + /// + public long Count { get; set; } = 0; + /// + /// 每页大小 + /// + public int PageSize { set; get; } = 20; + /// + /// 返回数据 + /// + public List Result { get; set; } + + + public PageModel() { } + + public PageModel(int pageNumber, long count, int pageSize, List result) + { + PageNumber = pageNumber; + Count = count; + PageSize = pageSize; + Result = result; + } + } +} diff --git a/web/Djy.Common/Utilities/Response.cs b/web/Djy.Common/Utilities/Response.cs index 1e80be3..3fb06ec 100644 --- a/web/Djy.Common/Utilities/Response.cs +++ b/web/Djy.Common/Utilities/Response.cs @@ -1,4 +1,7 @@ -namespace Common.Utilities +using System; +using System.Collections.Generic; + +namespace Common.Utilities { /// /// @@ -17,10 +20,10 @@ /// 操作状态码,200为正常 /// public int Code { get; set; } - /// - /// - /// - public int Total { get; set; } + ///// + ///// + ///// + //public int Total { get; set; } /// /// /// @@ -43,4 +46,33 @@ /// public T Result { get; set; } } + + /// + /// WEBAPI通用返回泛型基类 + /// + /// + public class ResponsePage : Response + { + /// + /// 第几页,从1开始 + /// + public int PageNumber { get; set; } + /// + /// 每页多少 + /// + public int PageSize { get; set; } + /// + /// 查询的记录数量 + /// + public long Count { get; set; } + /// + /// 总页数 + /// + public int PageCount => (int)Math.Ceiling((decimal)Count / PageSize); + + /// + /// 回传的结果 + /// + public List Result { get; set; } + } } diff --git a/web/djy.IService/Afr/IAfrService.cs b/web/djy.IService/Afr/IAfrService.cs index 9210540..d296c9c 100644 --- a/web/djy.IService/Afr/IAfrService.cs +++ b/web/djy.IService/Afr/IAfrService.cs @@ -1,12 +1,28 @@ -using System; +using Common.Utilities; +using djy.Model.Afr; +using djy.Model.AFRDto; +using djy.Model.AmsDto; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; namespace djy.IService.Afr { public interface IAfrService { + #region 字典接口 + List GetCountry(string strlink, int page, int limit); + List GetCARRIER(); + List GetCTNALL(); + List GetPackage(); + List GetDangerousGoods(string strlink); + List GetPort(string strlink, int page, int limit); + List GetVessel(string strlink, int page, int limit); + #endregion + + Task> Load(AFRMasterInputDto input); + Task SaveInfo(AFRMasterDto input); + Task Delete(string ids); + Task Send(string ids, string msgType); + Task SaveReceipt(AFRReceiptDto input); } } diff --git a/web/djy.IService/djy.IService.csproj b/web/djy.IService/djy.IService.csproj index 08cdfed..7e73095 100644 --- a/web/djy.IService/djy.IService.csproj +++ b/web/djy.IService/djy.IService.csproj @@ -2,6 +2,7 @@ net5.0 + false diff --git a/web/djy.Model/AFR/AFRBaseModel.cs b/web/djy.Model/AFR/AFRBaseModel.cs new file mode 100644 index 0000000..2b0acf1 --- /dev/null +++ b/web/djy.Model/AFR/AFRBaseModel.cs @@ -0,0 +1,50 @@ +using FreeSql.DataAnnotations; +using System; + +namespace djy.Model.AFR +{ + public class AFRBaseModel + { + /// + /// 主键 + /// + [Column(IsPrimary = true)] + public string GID { get; set; } + + /// + /// 用户ID + /// + public string UserID { get; set; } + + /// + /// 用户名称 + /// + public string UserName { get; set; } + + /// + /// 公司ID + /// + public string CompID { get; set; } + + /// + /// 公司名称 + /// + public string CompName { get; set; } + /// + /// 是否删除 + /// + public bool? IsDel { get; set; } + + /// + /// 最后修改时间 + /// + [Column(CanInsert = false)] + public DateTime? LastUpdate { get; set; } + + /// + /// 创建时间 + /// + [Column(CanUpdate =false)] + public DateTime? CreateTime { get; set; } + } +} diff --git a/web/djy.Model/AFR/AFRCntrno.cs b/web/djy.Model/AFR/AFRCntrno.cs index 408d8e6..3ae4ea9 100644 --- a/web/djy.Model/AFR/AFRCntrno.cs +++ b/web/djy.Model/AFR/AFRCntrno.cs @@ -1,4 +1,5 @@ -using FreeSql.DataAnnotations; +using djy.Model.AFR; +using FreeSql.DataAnnotations; using System; namespace djy.Model.Afr @@ -8,28 +9,14 @@ namespace djy.Model.Afr /// /// [Table(Name = "AFR_Cntrno", DisableSyncStructure = true)] - public partial class AFRCntrno + public partial class AFRCntrno: AFRBaseModel { - /// - /// - /// - public string GID { get; set; } /// /// 货代提单号唯一编号 同货代提单号,原始修改删除重发报文,该值要一致 /// public string BusinessId { get; set; } - /// - /// - /// - public string CompID { get; set; } - - /// - /// - /// - public string CompName { get; set; } - /// /// 货主箱标志 /// @@ -45,11 +32,6 @@ namespace djy.Model.Afr /// public string ContainerType { get; set; } - /// - /// - /// - public DateTime? CreateTime { get; set; } - /// /// 危品联系人(选填) /// @@ -95,16 +77,6 @@ namespace djy.Model.Afr /// public string Ignite { get; set; } - /// - /// - /// - public bool? IsDel { get; set; } - - /// - /// - /// - public DateTime? LastUpdate { get; set; } - /// /// 原产国(选填) /// @@ -145,21 +117,9 @@ namespace djy.Model.Afr /// 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 index c5b1471..c16d197 100644 --- a/web/djy.Model/AFR/AFRHouse.cs +++ b/web/djy.Model/AFR/AFRHouse.cs @@ -1,4 +1,6 @@ -using FreeSql.DataAnnotations; +using djy.Model.AFR; +using FreeSql.DataAnnotations; +using NetTopologySuite.Geometries.Prepared; using System; namespace djy.Model.Afr @@ -8,49 +10,23 @@ namespace djy.Model.Afr /// /// [Table(Name = "AFR_House", DisableSyncStructure = true)] - public partial class AFRHouse + public partial class AFRHouse: AFRBaseModel { - /// - /// - /// - public string GID { get; set; } + public string PID { 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; } /// /// 通知人地址 @@ -161,17 +137,6 @@ namespace djy.Model.Afr /// 货代单运编号(选填) /// 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 index b27e244..6a29854 100644 --- a/web/djy.Model/AFR/AFRMaster.cs +++ b/web/djy.Model/AFR/AFRMaster.cs @@ -1,5 +1,8 @@ -using FreeSql.DataAnnotations; +using djy.Model.AFR; +using djy.Model.Ams; +using FreeSql.DataAnnotations; using System; +using System.Collections.Generic; namespace djy.Model.Afr { @@ -7,38 +10,18 @@ namespace djy.Model.Afr /// /// [Table(Name = "AFR_Master", DisableSyncStructure = true)] - public partial class AFRMaster + public partial class AFRMaster : AFRBaseModel { - - /// - /// - /// - 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; } /// /// 卸货港全称 @@ -60,10 +43,6 @@ namespace djy.Model.Afr /// public string FilingType { get; set; } - /// - /// - /// - public bool? IsDel { get; set; } /// /// 交货地全称(条件)申报运输类型Tranship时,必填 @@ -75,10 +54,6 @@ namespace djy.Model.Afr /// public string LastForeignHarbourCode { get; set; } - /// - /// - /// - public DateTime? LastUpdate { get; set; } /// /// 预计开船日期 @@ -113,22 +88,21 @@ namespace djy.Model.Afr /// /// /// - public string UserID { get; set; } + public string Vessel { get; set; } /// /// /// - public string UserName { get; set; } + public string Voyno { get; set; } - /// - /// - /// - public string Vessel { get; set; } + #region 导航属性 /// - /// + /// 分单列表 /// - public string Voyno { get; set; } + [Navigate(nameof(AMS_Master.GID))] + public List Houses { get; set; } + #endregion } diff --git a/web/djy.Model/AFRDto/AFRMasterDto.cs b/web/djy.Model/AFRDto/AFRMasterDto.cs index ab35a29..0f409e8 100644 --- a/web/djy.Model/AFRDto/AFRMasterDto.cs +++ b/web/djy.Model/AFRDto/AFRMasterDto.cs @@ -1,4 +1,8 @@ -using System; +using djy.Model.Afr; +using djy.Model.AFR; +using djy.Model.Ams; +using FreeSql.Internal.Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,11 @@ using System.Threading.Tasks; namespace djy.Model.AFRDto { - public class AFRMasterDto + public class AFRMasterDto : AFRMaster { + /// + /// 分单列表 + /// + List Houses { get; set; } } } diff --git a/web/djy.Model/AFRDto/AFRMasterInputDto.cs b/web/djy.Model/AFRDto/AFRMasterInputDto.cs new file mode 100644 index 0000000..26bc787 --- /dev/null +++ b/web/djy.Model/AFRDto/AFRMasterInputDto.cs @@ -0,0 +1,49 @@ +using FreeSql.Internal.Model; +using System; + +namespace djy.Model.AFRDto +{ + public class AFRMasterInputDto : BasePagingInfo + { + /// + /// 查询类型(1:草稿箱列表 2:已发送列表) + /// + public int Type { get; set; } + + + /// + /// 船东提单号 + /// + public string MBLNO { get; set; } + /// + /// 货代提单号 修改报文,该值不可以变更 + /// + public string HouseBillNo { get; set; } + /// + /// 按创建时间查询的开始时间 + /// + public DateTime? CreateTimeStart { get; set; } + /// + /// 按创建时间查询的结束时间 + /// + public DateTime? CreateTimeEnd{ get; set; } + /// + /// 操作用户名称 + /// + public string UserName { get; set; } + /// + /// 卸货港名称 + /// + public string DischargeHarbour { get; set; } + + + /// + /// 用户Id + /// + public string UserId { get; set; } + /// + /// 公司企业Id + /// + public string CompanyId { get; set; } + } +} diff --git a/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs b/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs deleted file mode 100644 index 34ad4f9..0000000 --- a/web/djy.Model/AFRDto/AFRMasterPageDataDto.cs +++ /dev/null @@ -1,20 +0,0 @@ -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/AFRDto/AFRReceiptDto.cs b/web/djy.Model/AFRDto/AFRReceiptDto.cs new file mode 100644 index 0000000..9d661fc --- /dev/null +++ b/web/djy.Model/AFRDto/AFRReceiptDto.cs @@ -0,0 +1,21 @@ +namespace djy.Model.AFRDto +{ + public class AFRReceiptDto + { + public string businessId { get; set; } + public string content { get; set; } + public string houseBillNo { get; set; } + /// + /// 值有:Accept、Warning、Reject、Matched、Hold、Cancel + /// + public string status { get; set; } + } +} + +//样例: +//{ +// businessId:"63401", +// content:" 海关已接收 Master B/L Registration Status 13RHPASU8027790980", +// houseBillNo:"KMTCNBO6178011", +// status:"Accept" +//} diff --git a/web/djy.Model/djy.Model.csproj b/web/djy.Model/djy.Model.csproj index b860c7a..fd3a0e2 100644 --- a/web/djy.Model/djy.Model.csproj +++ b/web/djy.Model/djy.Model.csproj @@ -2,6 +2,7 @@ net5.0 + false diff --git a/web/djy.Service/Afr/AfrService.cs b/web/djy.Service/Afr/AfrService.cs index e11ef0d..a96d6a2 100644 --- a/web/djy.Service/Afr/AfrService.cs +++ b/web/djy.Service/Afr/AfrService.cs @@ -1,5 +1,13 @@ -using djy.IService.Afr; +using Common.DJYModel; +using Common.Extensions; +using Common.Utilities; +using djy.IService.Afr; +using djy.Model.Afr; +using djy.Model.AFRDto; +using djy.Model.Ams; +using djy.Model.AmsDto; using djy.Service.DjyService; +using FreeSql.Internal.Model; using System; using System.Collections.Generic; using System.Linq; @@ -10,6 +18,225 @@ namespace djy.Service.AFR { public class AfrService : DbContext, IAfrService { - + #region 下拉接口 + public List GetCountry(string strlink, int page, int limit) + { + try + { + if (page == 0 && limit == 0) + { + var List = DbBus.Get(DbList.Common).Select().ToList().Select(x => new CommonCNEN + { + Code = x.Code, + ENName = x.EnName, + CNName = x.CnName, + }).Distinct().ToList(); + return List; + } + else + { + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim()) || x.CnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCNEN + { + Code = x.Code, + ENName = x.EnName, + CNName = x.CnName, + }).Distinct().ToList(); + return List; + } + } + catch (Exception e) + { + throw; + } + } + + public List GetCARRIER() + { + try + { + var List = DbBus.Get(DbList.Common).Select().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonMappiCode + { + Code = cc.Code, + Value = cc.EnName, + MapCode = map.MapCode + }).Distinct().ToList(); + return List; + } + catch (Exception e) + { + throw; + } + } + + public List GetCTNALL() + { + try + { + var List = DbBus.Get(DbList.Common).Select().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonCodeValue + { + Code = cc.Code, + Value = cc.Name, + }).Distinct().ToList(); + return List; + } + catch (Exception e) + { + throw; + } + } + + public List GetPackage() + { + try + { + var List = DbBus.Get(DbList.Common).Select().InnerJoin((cc, map) => cc.Code == map.Code && map.Module == "Afr").ToList((cc, map) => new CommonCodeValue + { + Code = cc.Code, + Value = cc.Name, + }).Distinct().ToList(); + return List; + } + catch (Exception e) + { + throw; + } + } + + public List GetDangerousGoods(string strlink) + { + try + { + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.Grade.Contains(strlink.Trim())).ToList().Select(x => new CodeDangerGradeDto + { + Code = x.Code, + Grade = x.Grade, + }).Distinct().ToList(); + return List; + } + catch (Exception e) + { + throw; + } + } + + public List GetPort(string strlink, int page, int limit) + { + try + { + if (page == 0 && limit == 0) + { + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue + { + Code = x.Code, + Value = x.EnName, + }).Distinct().ToList(); + return List; + } + else + { + + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Code.Contains(strlink.Trim()) || x.EnName.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue + { + Code = x.Code, + Value = x.EnName, + }).Distinct().ToList(); + return List; + } + } + catch (Exception e) + { + throw; + } + } + + public List GetVessel(string strlink, int page, int limit) + { + try + { + if (page == 0 && limit == 0) + { + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).ToList().Select(x => new CommonCodeValue + { + Code = x.Name, + Value = x.Name, + }).Distinct().ToList(); + return List; + } + else + { + var List = DbBus.Get(DbList.Common).Select().WhereIf(strlink != "", x => x.Name.Contains(strlink.Trim())).Page(page, limit).ToList().Select(x => new CommonCodeValue + { + Code = x.Name, + Value = x.Name, + }).Distinct().ToList(); + return List; + } + } + catch (Exception e) + { + throw; + } + } + #endregion + + + public async Task> Load(AFRMasterInputDto input) + { + // 查询草稿箱列表 + if (input.Type == 1) + { + var select = DbBus.Get(DbList.AMSCenter) + .Select() + .LeftJoin((m, h) => m.GID == h.PID) + .Where((m) => m.IsDel == false) + .WhereIf(!string.IsNullOrEmpty(input.CompanyId), m => m.CompID == input.CompanyId) + .WhereIf(!string.IsNullOrEmpty(input.UserId), m => m.UserID == input.UserId) + .WhereIf(!string.IsNullOrEmpty(input.MBLNO), m => m.MBLNO.Contains(input.MBLNO)) + .WhereIf(!string.IsNullOrEmpty(input.UserName), m => m.UserName.Contains(input.UserName)) + .WhereIf(!string.IsNullOrEmpty(input.DischargeHarbour), m => m.DischargeHarbour.Contains(input.DischargeHarbour)) + .WhereIf(input.CreateTimeStart != null, m => m.CreateTime >= input.CreateTimeStart) + .WhereIf(input.CreateTimeEnd != null, m => m.CreateTime <= input.CreateTimeEnd); + + if (!string.IsNullOrEmpty(input.HouseBillNo)) + { + select.Where((m, h) => h.HouseBillNo == input.HouseBillNo); + } + List result = await select.Page(input) + .IncludeMany(m => m.Houses) + .OrderByDescending(m => m.CreateTime) + .ToListAsync(); + + return new PageModel(input.PageNumber, + input.Count, + input.PageSize, + result); + } + // 查询已发送列表 + else + { + return default; + } + + //HouseBillNo + } + public Task SaveInfo(AFRMasterDto input) + { + throw new NotImplementedException(); + } + + public Task Delete(string ids) + { + throw new NotImplementedException(); + } + + public Task Send(string ids, string msgType) + { + throw new NotImplementedException(); + } + + public Task SaveReceipt(AFRReceiptDto input) + { + throw new NotImplementedException(); + } } } diff --git a/web/djy.Service/DjyService/DbContext.cs b/web/djy.Service/DjyService/DbContext.cs index 4624f9c..07ac895 100644 --- a/web/djy.Service/DjyService/DbContext.cs +++ b/web/djy.Service/DjyService/DbContext.cs @@ -10,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Common; using System.Data; +using Common.Helpers; namespace djy.Service.DjyService { @@ -83,17 +84,32 @@ namespace djy.Service.DjyService } else { - DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString) - .UseAutoSyncStructure(false) - .UseNoneCommandParameter(true) - .UseMonitorCommand(cmd => + DbBus.Register(item.SysKey, () => { - Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText); - }) - .Build()); - + IFreeSql freeSql = new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString) + .UseAutoSyncStructure(false) + .UseNoneCommandParameter(true) + .UseMonitorCommand(cmd => + { + Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText); + }) + .Build(); + + if (item.SysKey == DbList.AMSCenter) + { + freeSql.Aop.CurdAfter += (s, e) => + { + string msg = $"ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}; FullName:{e.EntityType.FullName} ElapsedMilliseconds:{e.ElapsedMilliseconds}ms{Environment.NewLine}{Environment.NewLine}{e.Sql}"; + Parallel.For(0, 1, e2 => + { + LogLock.LogSql(new string[] { msg }); + }); + }; + } + + return freeSql; + }); } - } return true; diff --git a/web/djy.Service/djy.Service.csproj b/web/djy.Service/djy.Service.csproj index 88b6423..86eda3c 100644 --- a/web/djy.Service/djy.Service.csproj +++ b/web/djy.Service/djy.Service.csproj @@ -2,6 +2,7 @@ net5.0 + false diff --git a/web/djy_AfrApi/Controllers/AfrController.cs b/web/djy_AfrApi/Controllers/AfrController.cs index c927dc2..efa2cf4 100644 --- a/web/djy_AfrApi/Controllers/AfrController.cs +++ b/web/djy_AfrApi/Controllers/AfrController.cs @@ -1,23 +1,30 @@ -using Common.Utilities; +using Common.DJYModel; +using Common.Utilities; using djy.IService.Afr; using djy.Model; using djy.Model.Afr; using djy.Model.AFRDto; +using djy.Model.IsfDto; using djy_AfrApi.HttpContextUser; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using Org.BouncyCastle.Crypto; +using System; using System.Collections.Generic; using System.Threading.Tasks; namespace djy_AfrApi.Controllers { + [Route("api/[controller]")] + [ApiController] + [Authorize] public class AfrController : ApiBase { private readonly ILogger logger; private readonly IUser user; - private readonly IAfrService afrService; + private readonly IAfrService _afrService; //private readonly ILogger bigLogger; @@ -27,7 +34,7 @@ namespace djy_AfrApi.Controllers { this.logger = logger; this.user = user; - this.afrService = afrService; + this._afrService = afrService; // 获取ILogger对象 //ILoggerFactory loggerFactory, @@ -35,33 +42,59 @@ namespace djy_AfrApi.Controllers } #region 查询接口 - [HttpGet("[action]")] - public async Task>> PageData(AFRMasterPageDataDto input) + [HttpGet("PageData")] + public async Task> PageData(AFRMasterInputDto input) { - var data = afrService.Load(); + UserAuthorityDto aut = GetUserAuthorityToFormDto("modIsfList"); - return default; - } + input.CompanyId = aut.CompayId?.ToString(); + input.UserId = aut.UserId?.ToString(); - [HttpGet("[action]")] - [AllowAnonymous] - public async Task Reveive() - { - var r = MessageModel.Success("555", new { ff = "44", fff = "33" }); - return r; + var pageData = await _afrService.Load(input); + return SuccessPage(pageData); } #endregion #region 新增/编辑 - + [HttpPost("AddOrUpdate")] + public async Task AddOrUpdateAsync([FromBody] AFRMasterDto input) + { + await _afrService.SaveInfo(input); + return SuccessResp(); + } #endregion #region 删除 - + [HttpPost("Del")] + public async Task Delete(string ids) + { + await _afrService.Delete(ids); + return SuccessResp(); + } #endregion #region 第三方接口 + [HttpGet("Send")] + public async Task Send(string ids, string msgType) + { + await _afrService.Send(ids, msgType); + return SuccessResp(); + } + [AllowAnonymous] + [HttpPost("Receipt")] + public async Task SaveReceiptAsync(AFRReceiptDto input) + { + await _afrService.SaveReceipt(input); + return SuccessResp("接收成功"); + } #endregion + + [AllowAnonymous] + [HttpGet("[action]")] + public Response GetTime() + { + return SuccessResp(DateTime.Now.ToString()); + } } } diff --git a/web/djy_AfrApi/Controllers/ApiBase.cs b/web/djy_AfrApi/Controllers/ApiBase.cs index 629f2e0..da79f7f 100644 --- a/web/djy_AfrApi/Controllers/ApiBase.cs +++ b/web/djy_AfrApi/Controllers/ApiBase.cs @@ -2,8 +2,8 @@ using Common.DJYModel; using Common.Extensions; using Common.Tools; +using Common.Utilities; using djy.IService.Djy; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; @@ -15,14 +15,35 @@ namespace djy_AfrApi.Controllers /// /// api接口基类 /// - [Route("api/[controller]")] - [ApiController] - [Authorize] public class ApiBase : Controller { - #region http数据获取 + #region 构建响应对象 + [NonAction] + protected ResponsePage SuccessPage(PageModel pageModel) + { + return new ResponsePage() + { + Code = 200, + Message = "查询成功", + Result = pageModel.Result, + Count = pageModel.Count, + PageNumber = pageModel.PageNumber, + PageSize = pageModel.PageSize + }; + } + [NonAction] + protected Response SuccessResp(string message = "操作成功") + { + return new Response() + { + Code = 200, + Message = message + }; + } + #endregion + #region http数据获取 /// /// 创建日志 /// @@ -42,14 +63,16 @@ namespace djy_AfrApi.Controllers /// /// keyname标识 /// - protected DJyUserAuthorityDto GetDJyUserAuthority(string KeyName) { + protected DJyUserAuthorityDto GetDJyUserAuthority(string KeyName) + { var _djyserver = IOC.AddServer(); - var rs= _djyserver.GetUserAuthority(GetLoginId,KeyName); + var rs = _djyserver.GetUserAuthority(GetLoginId, KeyName); if (rs.Status) { return rs.Data; } - else { + else + { return null; } } @@ -57,7 +80,7 @@ namespace djy_AfrApi.Controllers /// 获取登录详情信息 /// /// - protected User GetUserInfo(Guid? UserGid = null) + protected User GetUserInfo(Guid? UserGid = null) { var _suser = IOC.AddServer(); if (UserGid == null) @@ -79,7 +102,8 @@ namespace djy_AfrApi.Controllers /// 模块keyname标识 /// 0 查询查看权限 1 操作更新权限 默认 0 /// - protected UserAuthorityDto GetUserAuthorityToFormDto(string KeyName,int type=0 ) { + protected UserAuthorityDto GetUserAuthorityToFormDto(string KeyName, int type = 0) + { //本人的绑定UserId 全部 userid 和 compayid不做绑定 注册公司的 绑定 companyid 没有权限则指定userid和companyid 为不存的guid值 var RetrunData = new UserAuthorityDto(); var _djyserver = IOC.AddServer(); @@ -87,9 +111,9 @@ namespace djy_AfrApi.Controllers User = null; var uuid = GetLoginId.ToString(); var userrs = _djyserver.GetUserInfo(GetLoginId.ToString()); - + var notguid = Guid.Parse("00000000-0000-0000-0000-000000000001"); - + RetrunData.CompayId = null; if (userrs.Status) @@ -107,11 +131,13 @@ namespace djy_AfrApi.Controllers if (aut != null) {//根据权限处理 _userid 和 _companyid 值 RetrunData.IsPower = true; - var _useraut= aut.Visiblerange; - if (type == 1) { + var _useraut = aut.Visiblerange; + if (type == 1) + { _useraut = aut.Operaterange; } - switch (_useraut) { + switch (_useraut) + { case 0://全部 RetrunData.UserId = null; @@ -134,12 +160,12 @@ namespace djy_AfrApi.Controllers case 7://注册公司 RetrunData.UserId = null; - RetrunData.CompayId = Guid.Parse( User.CompId); + RetrunData.CompayId = Guid.Parse(User.CompId); break; default: RetrunData.UserId = notguid; RetrunData.CompayId = notguid; - break; + break; } } @@ -152,9 +178,9 @@ namespace djy_AfrApi.Controllers //if (sysOptionConfig.Webconfig.IsDev) //{ - // RetrunData.UserId = null; - // RetrunData.CompayId =null; - // RetrunData.IsPower = true; + // RetrunData.UserId = null; + // RetrunData.CompayId =null; + // RetrunData.IsPower = true; //} return RetrunData; @@ -165,7 +191,7 @@ namespace djy_AfrApi.Controllers /// /// 获取登录Id /// - protected Guid? GetLoginId { get { return Guid.Parse(GetClaimsValue("loginid")); } } + protected Guid? GetLoginId { get { return Guid.Parse(GetClaimsValue("loginid")); } } /// /// 获取登录类型 @@ -204,8 +230,9 @@ namespace djy_AfrApi.Controllers return IsDecrtypt ? _DecryptDES(id.Value) : id.Value; } - catch { - return null; + catch + { + return null; } } @@ -220,82 +247,4 @@ namespace djy_AfrApi.Controllers } #endregion } - - - /// - ///api接口基类 - /// - /// 接口类型比如 Iservice - public class ApiBase : ApiBase - { - /// - /// - /// - protected IS _server = IOC.AddServer(); - - /// - /// 执行指定的方法 - /// - /// 方法名称 - /// 参数对象队列 - /// - protected object _InvokeServer(string methodName, object[] parameters) - { - return _server.GetType().GetMethod(methodName).Invoke(_server, parameters); - - } - } - - /// - /// api接口基类 - /// - /// 接口类型比如 Iservice - /// Dto Model - /// Tables数据表model - public class ApiBase : ApiBase - { - /// - /// 根据Id获取实体 - /// - /// - /// - protected virtual object _GetId(long Id) - { - return _InvokeServer("GetId", new object[] { Id }); - } - /// - ///基础的创建接口 提交创建对象 - /// - /// - /// - protected virtual object _Add(T Dto) - { - return _InvokeServer("Add", new object[] { Dto }); - } - - /// - /// 最基础的更新接口 传递要更新的数据对象 必须有Id - /// - /// - /// - protected virtual object _Up(T Dto) - { - return _InvokeServer("Up", new object[] { Dto, null, null }); - } - - /// - /// 最基础的删除接口 [1,2,3] - /// - /// - /// - protected virtual object _Del(long[] Idlist) - { - return _InvokeServer("Del", new object[] { Idlist }); - } - - - } - - - } diff --git a/web/djy_AfrApi/Controllers/CommonController.cs b/web/djy_AfrApi/Controllers/CommonController.cs new file mode 100644 index 0000000..6a27313 --- /dev/null +++ b/web/djy_AfrApi/Controllers/CommonController.cs @@ -0,0 +1,224 @@ +using Common; +using Common.Utilities; +using djy.IService.Afr; +using djy.Model.AmsDto; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; + +namespace djy_AfrApi.Controllers.Common +{ + public class CommonController + { + + IAfrService ser = IOC.AddServer(); + #region 下拉接口 + /// + /// 下拉获取国家 + /// + /// + [HttpGet("GetCountry")] + public Response> GetCountry(string strlink = "", int page = 0, int limit = 0) + { + var result = new Response>(); + try + { + result.Result = ser.GetCountry(strlink, page, limit); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + + return result; + } + + /// + /// 下拉获取船公司 + /// + /// + [HttpGet("GetCARRIER")] + public Response> GetCARRIER() + { + var result = new Response>(); + try + { + result.Result = ser.GetCARRIER(); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + return result; + } + + /// + /// 下拉获取箱型 + /// + /// + [HttpGet("GetCTNALL")] + public Response> GetCTNALL() + { + var result = new Response>(); + try + { + result.Result = ser.GetCTNALL(); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + + return result; + } + + + /// + /// 下拉获取包装单位 + /// + /// + [HttpGet("GetPackage")] + public Response> GetPackage() + { + var result = new Response>(); + try + { + result.Result = ser.GetPackage(); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + return result; + } + + /// + /// 下拉获取危品等级及 CODE + /// + /// + [HttpGet("GetDangerousGoods")] + public Response> GetDangerousGoods(string strlink = "",int page = 0, int limit = 0) + { + var result = new Response>(); + try + { + result.Result = ser.GetDangerousGoods(strlink); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + return result; + } + + + ///// + ///// 下拉获取起运港口 + ///// + ///// + //[HttpGet("GetCodePortLoad")] + //public Response> GetCodePortLoad() + //{ + // var result = new Response>(); + // try + // { + // result.Result = ser.GetCodePortLoad(); + // } + // catch (Exception ex) + // { + // result.Code = 500; + // result.Message = ex.InnerException?.Message ?? ex.Message; + // } + // return result; + //} + + + /// + /// 下拉获取港口 + /// + /// + [HttpGet("GetPort")] + public Response> GetPort(string strlink = "", int page = 0, int limit = 0) + { + var result = new Response>(); + try + { + result.Result = ser.GetPort(strlink, page, limit); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + return result; + } + + + /// + /// 下拉获取船名 + /// + /// + [HttpGet("GetVessel")] + public Response> GetVessel(string strlink = "", int page = 0,int limit =0) + { + var result = new Response>(); + try + { + result.Result = ser.GetVessel(strlink, page,limit); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + return result; + } + + + + ///// + ///// 下拉获取省份 + ///// + ///// + //[HttpGet("GetCodeProvince")] + //public Response> GetCodeProvince(string code) + //{ + // var result = new Response>(); + // try + // { + // result.Result = ser.GetCodeProvince(code); + // } + // catch (Exception ex) + // { + // result.Code = 500; + // result.Message = ex.InnerException?.Message ?? ex.Message; + // } + // return result; + //} + ///// + ///// 下拉获取城市 邮编 + ///// + ///// + //[HttpGet("GetCodeCity")] + //public Response> GetCodeCity(string provinceCode) + //{ + // var result = new Response>(); + // try + // { + // result.Result = ser.GetCodeCity(provinceCode); + // } + // catch (Exception ex) + // { + // result.Code = 500; + // result.Message = ex.InnerException?.Message ?? ex.Message; + // } + // return result; + //} + #endregion + } +} diff --git a/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs b/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs index 0bacec7..503ff65 100644 --- a/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs +++ b/web/djy_AfrApi/Filter/GlobalExceptionsFilter.cs @@ -1,10 +1,6 @@ -using Common.Helpers; -using Common.Utilities; -using djy.Service.DjyService; -using Microsoft.AspNetCore.Hosting; +using Common.Utilities; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Newtonsoft.Json; diff --git a/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log b/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log new file mode 100644 index 0000000..cdac28b --- /dev/null +++ b/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log @@ -0,0 +1,33 @@ +-------------------------------- +2023/12/27 15:41:20| +ManagedThreadId:19; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:30ms + +SELECT count(1) as1 +FROM [AFR_Master] a +LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID] +WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum') +-------------------------------- +2023/12/27 15:42:50| +ManagedThreadId:7; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:44ms + +SELECT count(1) as1 +FROM [AFR_Master] a +LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID] +WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum') +-------------------------------- +2023/12/27 15:45:04| +ManagedThreadId:12; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:46ms + +SELECT count(1) as1 +FROM [AFR_Master] a +LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID] +WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum') +-------------------------------- +2023/12/27 15:45:04| +ManagedThreadId:5; FullName:djy.Model.Afr.AFRMaster ElapsedMilliseconds:330ms + +SELECT TOP 10 a.[GID], a.[UserID], a.[UserName], a.[CompID], a.[CompName], a.[IsDel], a.[LastUpdate], a.[CreateTime], a.[Clause], a.[ConsignmentType], a.[DischargeHarbour], a.[DischargeHarbourCode], a.[EstimatedArrivalTime], a.[FilingType], a.[LastForeignHarbour], a.[LastForeignHarbourCode], a.[LoadDate], a.[LoadHarbour], a.[LoadHarbourCode], a.[MBLNO], a.[ShipCompany], a.[ShippingNo], a.[Vessel], a.[Voyno] +FROM [AFR_Master] a +LEFT JOIN [AFR_House] h ON a.[GID] = h.[PID] +WHERE (a.[IsDel] = 0) AND ((a.[UserName]) LIKE N'%朱洋%') AND (a.[CreateTime] >= '1991-04-18 21:23:40.000') AND (a.[CreateTime] <= '1988-04-22 20:14:18.000') AND (h.[HouseBillNo] = N'sunt laborum') +ORDER BY a.[CreateTime] DESC diff --git a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs index bb7a5ea..8bed011 100644 --- a/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/ExceptionHandlerMiddleware.cs @@ -1,4 +1,5 @@ -using djy.Model; +using Common.Utilities; +using djy.Model; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -23,7 +24,7 @@ namespace djy_AfrApi.Middlewares { try { - _ = int.Parse(""); + //_ = int.Parse(""); await _next(context); } catch (Exception ex) @@ -35,7 +36,7 @@ namespace djy_AfrApi.Middlewares private async Task HandleExceptionAsync(HttpContext context, Exception e) { if (e == null) return; - + logger.LogError(WriteLog("ExceptionHandlerMiddleware中捕获的全局异常", e)); await WriteExceptionAsync(context, e).ConfigureAwait(false); @@ -57,7 +58,7 @@ namespace djy_AfrApi.Middlewares context.Response.ContentType = "application/json"; await context.Response - .WriteAsync(JsonConvert.SerializeObject(new MessageModel() { code = 500, message = message })) + .WriteAsync(JsonConvert.SerializeObject(new Response() { Code = 500, Message = message })) .ConfigureAwait(false); } diff --git a/web/djy_AfrApi/Milldlewares/NextAuthorizationMiddleware.cs b/web/djy_AfrApi/Milldlewares/NextAuthorizationMiddleware.cs index b59a9f1..17e12ac 100644 --- a/web/djy_AfrApi/Milldlewares/NextAuthorizationMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/NextAuthorizationMiddleware.cs @@ -26,7 +26,7 @@ namespace djy_AfrApi.Milldlewares public async Task InvokeAsync(HttpContext context) { var endpoint = context.GetEndpoint(); - if (endpoint?.Metadata.GetMetadata() == null) + if (endpoint?.Metadata.GetMetadata() == null && context.Request.Path.Value.ToLower().Contains("/api/afr")) { // 因为ISF/AMS这步验证始终都无效,所以这里先不做验证 //if (context.Request.Path.Value.Contains("/Load")) @@ -39,10 +39,10 @@ namespace djy_AfrApi.Milldlewares var user = _userService.GetUserInfo(userId); if (user.Data == null) { - MessageModel result = new MessageModel() + Response result = new Response() { - code = 401, - message = "登录过期(未查询到此用户),请重新登录!" + Code = 401, + Message = "登录过期(未查询到此用户),请重新登录!" }; context.Response.ContentType = "application/json"; diff --git a/web/djy_AfrApi/Milldlewares/UnifyResultMiddleware.cs b/web/djy_AfrApi/Milldlewares/UnifyResultMiddleware.cs index a3eab7f..a033e84 100644 --- a/web/djy_AfrApi/Milldlewares/UnifyResultMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/UnifyResultMiddleware.cs @@ -1,4 +1,5 @@ -using djy.Model; +using Common.Utilities; +using djy.Model; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using System.Threading.Tasks; @@ -25,10 +26,10 @@ namespace djy_AfrApi.Milldlewares await context.Response .WriteAsync(JsonConvert.SerializeObject( - new MessageModel() + new Response() { - code = context.Response.StatusCode, - message = "授权验证失败或已过期,请重新登录!" + Code = context.Response.StatusCode, + Message = "授权验证失败或已过期,请重新登录!" })) .ConfigureAwait(false); } diff --git a/web/djy_AfrApi/Properties/launchSettings.json b/web/djy_AfrApi/Properties/launchSettings.json index fa0d31b..341c2b9 100644 --- a/web/djy_AfrApi/Properties/launchSettings.json +++ b/web/djy_AfrApi/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "djy_AfrApi": { "commandName": "Project", - "launchBrowser": false, + "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/web/djy_AfrApi/djy_AfrApi.csproj b/web/djy_AfrApi/djy_AfrApi.csproj index 2fa0869..7278c4b 100644 --- a/web/djy_AfrApi/djy_AfrApi.csproj +++ b/web/djy_AfrApi/djy_AfrApi.csproj @@ -2,6 +2,7 @@ net5.0 + false