From 9e1408d6890496dd35cf5d6d303cda827fe7d6ae Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Fri, 29 Dec 2023 13:43:36 +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/DJYModel/CustFee.cs | 4 + web/Djy.Common/Helpers/LogLock.cs | 60 +--- web/Djy.Common/Tools/Redis.cs | 19 + web/djy.IService/Afr/IAfrService.cs | 3 +- web/djy.Model/AFR/AFRBaseModel.cs | 26 +- web/djy.Model/AFR/AFRCntrno.cs | 8 +- web/djy.Model/AFR/AFRHouse.cs | 30 +- web/djy.Model/AFR/AFRMaster.cs | 36 +- web/djy.Model/AFR/AFRMasterHistory.cs | 14 +- web/djy.Model/AFRDto/AFRMasterInputDto.cs | 8 + .../HttpContextUser/IUser.cs | 2 +- web/djy.Model/ResponseModel.cs | 148 -------- web/djy.Model/djy.Model.csproj | 3 +- web/djy.Service/Afr/AfrService.cs | 331 ++++++++++++++++-- .../DjyService}/AspNetUser.cs | 5 +- web/djy.Service/DjyService/DbContext.cs | 25 +- web/djy_AfrApi/Attributes/CacheAttribute.cs | 9 + web/djy_AfrApi/Controllers/AfrController.cs | 54 ++- web/djy_AfrApi/Controllers/ApiBase.cs | 15 + .../Controllers/CommonController.cs | 22 +- .../Log/SqlLog/SqlLog_2023-12-27.log | 33 -- .../Milldlewares/CommonCacheMiddleware.cs | 85 +++++ .../Milldlewares/MiddlewareHelpers.cs | 12 +- .../Milldlewares/RequRespLogMiddleware.cs | 7 +- web/djy_AfrApi/Properties/launchSettings.json | 1 - web/djy_AfrApi/Startup.cs | 21 +- web/djy_AfrApi/djy_AfrApi.csproj | 1 + 27 files changed, 631 insertions(+), 351 deletions(-) rename web/{djy_AfrApi => djy.Model}/HttpContextUser/IUser.cs (85%) delete mode 100644 web/djy.Model/ResponseModel.cs rename web/{djy_AfrApi/HttpContextUser => djy.Service/DjyService}/AspNetUser.cs (91%) create mode 100644 web/djy_AfrApi/Attributes/CacheAttribute.cs delete mode 100644 web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log create mode 100644 web/djy_AfrApi/Milldlewares/CommonCacheMiddleware.cs diff --git a/web/Djy.Common/DJYModel/CustFee.cs b/web/Djy.Common/DJYModel/CustFee.cs index a23bd61..e3eaf54 100644 --- a/web/Djy.Common/DJYModel/CustFee.cs +++ b/web/Djy.Common/DJYModel/CustFee.cs @@ -129,6 +129,10 @@ namespace Common.DJYModel [JsonProperty] public DateTime? SENDTIME { get; set; } + + /// + /// 0:新增发送或原始重发 1:修改发送 5:删除发送 + /// [JsonProperty] public int? SENDTYPE { get; set; } /// diff --git a/web/Djy.Common/Helpers/LogLock.cs b/web/Djy.Common/Helpers/LogLock.cs index fe71829..615cdda 100644 --- a/web/Djy.Common/Helpers/LogLock.cs +++ b/web/Djy.Common/Helpers/LogLock.cs @@ -6,28 +6,10 @@ 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); + OutSql2LogToFile("sqlLog", dataParas, IsHeader, isWrt); } public static void OutSql2LogToFile(string prefix, string[] dataParas, bool IsHeader = true, bool isWrt = false) @@ -39,15 +21,13 @@ namespace Common.Helpers // 浠庢ц兘鏂归潰鑰冭檻锛岃姹傝繘鍏ュ啓鍏ユā寮忓簲璇ョ揣璺熸枃浠舵搷浣滀箣鍓嶏紝鍦ㄦ澶勮繘鍏ュ啓鍏ユā寮忎粎鏄负浜嗛檷浣庝唬鐮佸鏉傚害 // 鍥犺繘鍏ヤ笌閫鍑哄啓鍏ユā寮忓簲鍦ㄥ悓涓涓猼ry finally璇彞鍧楀唴锛屾墍浠ュ湪璇锋眰杩涘叆鍐欏叆妯″紡涔嬪墠涓嶈兘瑙﹀彂寮傚父锛屽惁鍒欓噴鏀炬鏁板ぇ浜庤姹傛鏁板皢浼氳Е鍙戝紓甯 LogWriteLock.EnterWriteLock(); - - string folderPath = Path.Combine(_contentRoot, "Log", prefix); + + string folderPath = Path.Combine(AppContext.BaseDirectory, "Logs", DateTime.Now.ToString("yyyy-MM-dd")); 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"); + string logFilePath = Path.Combine(folderPath, $@"{prefix}.txt"); DateTime now = DateTime.Now; string logContent; @@ -87,37 +67,5 @@ namespace Common.Helpers 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/Tools/Redis.cs b/web/Djy.Common/Tools/Redis.cs index e02a73f..d09d6a6 100644 --- a/web/Djy.Common/Tools/Redis.cs +++ b/web/Djy.Common/Tools/Redis.cs @@ -151,5 +151,24 @@ namespace Common.Tools return Json.JsonToObject(val); } } + + /// + /// 璇诲彇redis涓殑瀵硅薄鏁版嵁 涓嶅瓨鍦ㄨ繑鍥瀗ull + /// + /// + /// + /// + public static string RedisGetString(string Key) + { + var val = DbRedis.Get(Key); + if (val.IsNull()) + { + return default; + } + else + { + return val; + } + } } } diff --git a/web/djy.IService/Afr/IAfrService.cs b/web/djy.IService/Afr/IAfrService.cs index d296c9c..5496409 100644 --- a/web/djy.IService/Afr/IAfrService.cs +++ b/web/djy.IService/Afr/IAfrService.cs @@ -20,7 +20,8 @@ namespace djy.IService.Afr #endregion Task> Load(AFRMasterInputDto input); - Task SaveInfo(AFRMasterDto input); + Task Get(string gid); + Task SaveInfo(AFRMaster input); Task Delete(string ids); Task Send(string ids, string msgType); Task SaveReceipt(AFRReceiptDto input); diff --git a/web/djy.Model/AFR/AFRBaseModel.cs b/web/djy.Model/AFR/AFRBaseModel.cs index 2b0acf1..ea8e537 100644 --- a/web/djy.Model/AFR/AFRBaseModel.cs +++ b/web/djy.Model/AFR/AFRBaseModel.cs @@ -11,30 +11,6 @@ namespace djy.Model.AFR [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; } - /// /// 鏈鍚庝慨鏀规椂闂 /// @@ -44,7 +20,7 @@ namespace djy.Model.AFR /// /// 鍒涘缓鏃堕棿 /// - [Column(CanUpdate =false)] + [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 3ae4ea9..6088558 100644 --- a/web/djy.Model/AFR/AFRCntrno.cs +++ b/web/djy.Model/AFR/AFRCntrno.cs @@ -11,6 +11,10 @@ namespace djy.Model.Afr [Table(Name = "AFR_Cntrno", DisableSyncStructure = true)] public partial class AFRCntrno: AFRBaseModel { + /// + /// 鍒嗗崟璁板綍涓婚敭 + /// + public string PID { get; set; } /// /// 璐т唬鎻愬崟鍙峰敮涓缂栧彿 鍚岃揣浠f彁鍗曞彿锛屽師濮嬩慨鏀瑰垹闄ら噸鍙戞姤鏂囷紝璇ュ艰涓鑷 @@ -97,10 +101,6 @@ namespace djy.Model.Afr /// public string PackingCode { get; set; } - /// - /// - /// - public string PID { get; set; } /// /// 灏佸彿 diff --git a/web/djy.Model/AFR/AFRHouse.cs b/web/djy.Model/AFR/AFRHouse.cs index c16d197..404dad3 100644 --- a/web/djy.Model/AFR/AFRHouse.cs +++ b/web/djy.Model/AFR/AFRHouse.cs @@ -2,6 +2,7 @@ using FreeSql.DataAnnotations; using NetTopologySuite.Geometries.Prepared; using System; +using System.Collections.Generic; namespace djy.Model.Afr { @@ -10,23 +11,38 @@ namespace djy.Model.Afr /// /// [Table(Name = "AFR_House", DisableSyncStructure = true)] - public partial class AFRHouse: AFRBaseModel + public partial class AFRHouse : AFRBaseModel { - + /// + /// 涓诲崟涓婚敭 + /// public string PID { get; set; } + /// + /// 鏄惁鍒犻櫎 + /// + public bool IsDel { get; set; } + /// /// 璐т唬鎻愬崟鍙峰敮涓缂栧彿 鍚岃揣浠f彁鍗曞彿锛屽師濮嬩慨鏀瑰垹闄ら噸鍙戞姤鏂囷紝璇ュ艰涓鑷 /// public string BusinessId { get; set; } - /// /// 璐т唬鎻愬崟鍙 淇敼鎶ユ枃锛岃鍊间笉鍙互鍙樻洿 /// public string HouseBillNo { get; set; } + /// + /// 鐘舵侊細娴峰叧鎺ユ敹 + /// + public byte? StateIsAccept { get; set; } + + /// + /// 鐘舵侊細宸插尮閰 + /// + public byte? StateIsMatched { get; set; } /// /// 閫氱煡浜哄湴鍧 @@ -137,6 +153,14 @@ namespace djy.Model.Afr /// 璐т唬鍗曡繍缂栧彿锛堥夊~锛 /// public string ShippingNo { get; set; } + + #region 瀵艰埅灞炴 + /// + /// 绠卞瓙鍒楄〃 + /// + [Navigate(nameof(AFRCntrno.PID))] + public List CntrList { get; set; } = new List(); + #endregion } } diff --git a/web/djy.Model/AFR/AFRMaster.cs b/web/djy.Model/AFR/AFRMaster.cs index 6a29854..5c5f9b1 100644 --- a/web/djy.Model/AFR/AFRMaster.cs +++ b/web/djy.Model/AFR/AFRMaster.cs @@ -12,6 +12,30 @@ namespace djy.Model.Afr [Table(Name = "AFR_Master", DisableSyncStructure = true)] public partial class AFRMaster : AFRBaseModel { + /// + /// 鐢ㄦ埛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; } + /// /// 杩愯緭鏉℃浠g爜 /// @@ -76,7 +100,7 @@ namespace djy.Model.Afr public string MBLNO { get; set; } /// - /// + /// 鑸瑰叕鍙 /// public string ShipCompany { get; set; } @@ -100,8 +124,14 @@ namespace djy.Model.Afr /// /// 鍒嗗崟鍒楄〃 /// - [Navigate(nameof(AMS_Master.GID))] - public List Houses { get; set; } + [Navigate(nameof(AFRHouse.PID))] + public List HouseList { get; set; } = new List(); + + /// + /// 鎿嶄綔鍘嗗彶 + /// + [Navigate(nameof(AFRMasterHistory.PID))] + public AFRMasterHistory History { get; set; } #endregion } diff --git a/web/djy.Model/AFR/AFRMasterHistory.cs b/web/djy.Model/AFR/AFRMasterHistory.cs index 8253db6..0da25c4 100644 --- a/web/djy.Model/AFR/AFRMasterHistory.cs +++ b/web/djy.Model/AFR/AFRMasterHistory.cs @@ -3,14 +3,12 @@ using System; namespace djy.Model.Afr { - /// /// /// [Table(Name = "AFR_MasterHistory", DisableSyncStructure = true)] public partial class AFRMasterHistory { - /// /// /// @@ -19,12 +17,12 @@ namespace djy.Model.Afr /// /// /// - public string AMID { get; set; } + public string Operator { get; set; } /// /// /// - public string Operator { get; set; } + public string PID { get; set; } /// /// @@ -34,7 +32,7 @@ namespace djy.Model.Afr /// /// /// - public DateTime? SendTime { get; set; } + public DateTime? CreateTime { get; set; } /// /// @@ -42,10 +40,8 @@ namespace djy.Model.Afr public string State { get; set; } /// - /// + /// 鏃ュ織绫诲瀷銆0锛氫汉涓烘搷浣滃巻鍙 1锛氭帴鏀跺洖鎵у巻鍙 /// - public string Type { get; set; } - + public byte? Type { get; set; } } - } diff --git a/web/djy.Model/AFRDto/AFRMasterInputDto.cs b/web/djy.Model/AFRDto/AFRMasterInputDto.cs index 26bc787..5141f38 100644 --- a/web/djy.Model/AFRDto/AFRMasterInputDto.cs +++ b/web/djy.Model/AFRDto/AFRMasterInputDto.cs @@ -10,6 +10,10 @@ namespace djy.Model.AFRDto /// public int Type { get; set; } + ///// + ///// 鎿嶄綔鍘嗗彶鏌ヨ绫诲瀷锛宎ll:鍏ㄩ儴 latest-people:鏈鏂扮殑涓鏉′汉涓烘搷浣滆褰 + ///// + //public string HistoryQueryType { get; set; } /// /// 鑸逛笢鎻愬崟鍙 @@ -28,6 +32,10 @@ namespace djy.Model.AFRDto /// public DateTime? CreateTimeEnd{ get; set; } /// + /// 鑸瑰叕鍙 + /// + public string ShipCompany { get; set; } + /// /// 鎿嶄綔鐢ㄦ埛鍚嶇О /// public string UserName { get; set; } diff --git a/web/djy_AfrApi/HttpContextUser/IUser.cs b/web/djy.Model/HttpContextUser/IUser.cs similarity index 85% rename from web/djy_AfrApi/HttpContextUser/IUser.cs rename to web/djy.Model/HttpContextUser/IUser.cs index ef9bc2c..0b7d0da 100644 --- a/web/djy_AfrApi/HttpContextUser/IUser.cs +++ b/web/djy.Model/HttpContextUser/IUser.cs @@ -1,6 +1,6 @@ 锘縰sing Common.DJYModel; -namespace djy_AfrApi.HttpContextUser +namespace djy.Model { public interface IUser { diff --git a/web/djy.Model/ResponseModel.cs b/web/djy.Model/ResponseModel.cs deleted file mode 100644 index 656b3e2..0000000 --- a/web/djy.Model/ResponseModel.cs +++ /dev/null @@ -1,148 +0,0 @@ -锘縰sing NPOI.SS.Formula.Functions; - -namespace djy.Model -{ - /// - /// 閫氱敤杩斿洖淇℃伅绫 - /// - public class MessageModel - { - /// - /// 鐘舵佺爜 - /// - public int code { get; set; } = 200; - /// - /// 鎿嶄綔鏄惁鎴愬姛 - /// - public bool success { get; set; } = false; - /// - /// 杩斿洖淇℃伅 - /// - public string message { get; set; } = ""; - /// - /// 寮鍙戣呬俊鎭 - /// - public string msgDev { get; set; } - /// - /// 杩斿洖鏁版嵁闆嗗悎 - /// - public T data { get; set; } - - /// - /// 杩斿洖鎴愬姛 - /// - /// 娑堟伅 - /// - public static MessageModel Success(string msg) - { - return Message(true, msg, default); - } - /// - /// 杩斿洖鎴愬姛 - /// - /// 娑堟伅 - /// 鏁版嵁 - /// - public static MessageModel Success(string msg, T data) - { - return Message(true, msg, data); - } - /// - /// 杩斿洖澶辫触 - /// - /// 娑堟伅 - /// - public static MessageModel Fail(string msg) - { - return Message(false, msg, default); - } - /// - /// 杩斿洖澶辫触 - /// - /// 娑堟伅 - /// 鏁版嵁 - /// - public static MessageModel Fail(string msg, T data) - { - return Message(false, msg, data); - } - /// - /// 杩斿洖娑堟伅 - /// - /// 澶辫触/鎴愬姛 - /// 娑堟伅 - /// 鏁版嵁 - /// - private static MessageModel Message(bool success, string msg, T data) - { - return new MessageModel() { message = msg, data = data, success = success }; - } - } - /// - /// - /// - public class MessageModel - { - /// - /// 鐘舵佺爜 - /// - public int code { get; set; } = 200; - /// - /// 鎿嶄綔鏄惁鎴愬姛 - /// - public bool success { get; set; } = false; - /// - /// 杩斿洖淇℃伅 - /// - public string message { get; set; } = ""; - /// - /// 杩斿洖鏁版嵁闆嗗悎 - /// - public object data { get; set; } - - - /// - /// 杩斿洖鎴愬姛 - /// - /// 娑堟伅 - /// - public static MessageModel Success(string msg) - { - return Message(true, msg, default); - } - - /// - /// 杩斿洖鎴愬姛 - /// - /// 娑堟伅 - /// 鏁版嵁 - /// - public static MessageModel Success(string msg, object data) - { - return Message(true, msg, data); - } - - /// - /// 杩斿洖澶辫触 - /// - /// 娑堟伅 - /// - public static MessageModel Fail(string msg) - { - return Message(false, msg, default); - } - - /// - /// 杩斿洖娑堟伅 - /// - /// 澶辫触/鎴愬姛 - /// 娑堟伅 - /// 鏁版嵁 - /// - private static MessageModel Message(bool success, string msg, object data) - { - return new MessageModel() { message = msg, data = data, success = success }; - } - } - -} diff --git a/web/djy.Model/djy.Model.csproj b/web/djy.Model/djy.Model.csproj index fd3a0e2..64456fb 100644 --- a/web/djy.Model/djy.Model.csproj +++ b/web/djy.Model/djy.Model.csproj @@ -3,10 +3,11 @@ net5.0 false + True - bin\Debug\net5.0\djy.Model.xml + diff --git a/web/djy.Service/Afr/AfrService.cs b/web/djy.Service/Afr/AfrService.cs index a96d6a2..cfdae72 100644 --- a/web/djy.Service/Afr/AfrService.cs +++ b/web/djy.Service/Afr/AfrService.cs @@ -1,23 +1,30 @@ 锘縰sing Common.DJYModel; -using Common.Extensions; using Common.Utilities; using djy.IService.Afr; +using djy.Model; 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 FreeSql; using System; using System.Collections.Generic; +using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace djy.Service.AFR { - public class AfrService : DbContext, IAfrService + public class AfrService : DjyService.DbContext, IAfrService { + private IUser User { get; } + + public AfrService(IUser user) + { + User = user; + } #region 涓嬫媺鎺ュ彛 public List GetCountry(string strlink, int page, int limit) { @@ -182,46 +189,299 @@ namespace djy.Service.AFR public async Task> Load(AFRMasterInputDto input) { - // 鏌ヨ鑽夌ǹ绠卞垪琛 + ISelect select = null; + // 鏌ヨ鑽夌ǹ绠卞垪琛紝鑽夌ǹ绠卞垪琛ㄩ噰鐢ㄤ竴涓诲崟鍐呭惈鏈夊涓垎鍗曠殑鏄剧ず妯″紡 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); - } - // 鏌ヨ宸插彂閫佸垪琛 + select = DbAMS.Select(); + } + // 鏌ヨ宸插彂閫佸垪琛紝宸插彂閫佸垪琛ㄩ噰鐢ㄦ寜鍒嗗崟鐨勬樉绀烘柟寮 + else if (input.Type == 2) + { + select = DbAMS.Select() + .InnerJoin((m, h) => m.GID == h.PID); + } + + select.Where((m) => m.IsDel == false) + //涓嬮潰涓や釜鏄疌ontroller涓紶鏉ョ殑鏉′欢 + .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(!string.IsNullOrEmpty(input.ShipCompany), m => m.ShipCompany.Contains(input.ShipCompany)) + .WhereIf(input.CreateTimeStart != null, m => m.CreateTime >= input.CreateTimeStart) + .WhereIf(input.CreateTimeEnd != null, m => m.CreateTime <= input.CreateTimeEnd); + + // 鍒嗗崟涓婄殑鏌ヨ鏉′欢鍦ㄨ繖閲岋紝瀹炵幇鏂瑰紡锛氭煡鍑哄垎鍗曚腑鐨凱ID锛屼綔涓轰富鍗曠殑绛涢夋潯浠 + if (!string.IsNullOrEmpty(input.HouseBillNo)) + { + var pids = await DbAMS.Select() + .Where(h => h.HouseBillNo.Contains(input.HouseBillNo)) + .ToListAsync(h => h.PID); + select.Where(m => pids.Contains(m.GID)); + } + + List result = await select.IncludeMany(m => m.HouseList, then => then.Where(h => h.IsDel == false)) + .Page(input) + .OrderByDescending(m => m.CreateTime) + .ToListAsync(); + + // 鏌ヨ鎿嶄綔鍘嗗彶锛堝彧鏌ヨ鏈鏂扮殑涓鏉′汉涓烘搷浣滃巻鍙诧級 + if (result.Count > 0) + { + // FreeSql鐗堟湰杈冧綆锛屾棤娉曚娇鐢ㄥ祵濂楁煡璇紝鎵浠ラ噰鐢ㄦ嫾sql鐨勬柟寮 + var pids = result.Select(m => m.GID); + var pidStr = string.Join("','", pids); + var histories = await DbAMS.Select() + .WithSql(@$"SELECT * FROM ( + SELECT *,row_number() over ( PARTITION BY Pid ORDER BY {nameof(AFRMasterHistory.CreateTime)} DESC ) AS row_num FROM AFR_MasterHistory WHERE {nameof(AFRMasterHistory.Type)} = 0 AND pid IN ('{pidStr}')) t WHERE row_num =1") + .ToListAsync(); + histories.ForEach(item => + { + var master = result.FirstOrDefault(m => m.GID == item.PID); + if (master == null) return; + master.History = item; + }); + } + + return new PageModel(input.PageNumber, + input.Count, + input.PageSize, + result); + } + public async Task Get(string gid) + { + AFRMaster model = await DbAMS.Select() + .Where((m) => m.IsDel == false && m.GID == gid) + .IncludeMany(m => m.HouseList, then => then.Where(h => h.IsDel == false) + .IncludeMany(house => house.CntrList)) + .FirstAsync(); + return model; + } + + public async Task SaveInfo(AFRMaster input) + { + int type; + AFRMaster oldMaster = null; + var nowTime = DateTime.Now; + + if (string.IsNullOrEmpty(input.GID)) + { + type = 0; + } else { - return default; + oldMaster = await Get(input.GID); + type = oldMaster == null ? 0 : 1; + } + // 鏂板 + if (type == 0) + { + // 灏唍ull鎹负绌哄璞★紝閬垮厤鍚庣画澶勭悊null鍊奸夯鐑 + input.HouseList ??= new List(); + + input.GID = Guid.NewGuid().ToString(); + input.UserID = User.GID; + input.UserName = User.ShowName; + input.CompID = User.CompId; + input.CompName = User.CompName; + input.CreateTime = nowTime; + input.HouseList.ForEach(house => + { + house.GID = Guid.NewGuid().ToString(); + house.PID = input.GID; + house.CreateTime = nowTime; + + // 灏唍ull鎹负绌哄璞★紝閬垮厤鍚庣画澶勭悊null鍊奸夯鐑 + house.CntrList ??= new List(); + house.CntrList.ForEach(cntr => + { + cntr.GID = Guid.NewGuid().ToString(); + cntr.PID = house.GID; + cntr.CreateTime = nowTime; + }); + }); + + await using DbTransaction tran = await GetDbAmsTransaction(); + + await DbAMS.Insert(input).ExecuteAffrowsAsync(); + await DbAMS.Insert(input.HouseList).WithTransaction(tran).ExecuteAffrowsAsync(); + await DbAMS.Insert(input.HouseList.SelectMany(h => h.CntrList)).WithTransaction(tran).ExecuteAffrowsAsync(); + + AFRMasterHistory history = BuildAFRMasterHistory(input.GID, "鏂板", 0, "鍒涘缓浜嗗崟鎹"); + await DbAMS.Insert(history).WithTransaction(tran).ExecuteAffrowsAsync(); + + tran.Commit(); } + // 淇敼 + else + { + // 涓嬮潰杩欐鐨3涓綔鐢細 + // 1. 灏唍ull鎹负绌哄璞★紝閬垮厤鍚庣画澶勭悊null鍊奸夯鐑 + // 2. 濡傛灉涓婚敭涓簄ull锛岃鏄庢槸鏂板姞鐨勬暟鎹紝杩欐椂鍊欓渶瑕佹墜鍔ㄧ粰GID銆丳ID銆丆reateTime璧嬪 + // 3. 濡傛灉涓婚敭涓嶄负null锛岃鏄庢槸淇敼鐨勬暟鎹紝杩欐椂鍊欓渶瑕佹墜鍔ㄧ粰LastUpdate璧嬪 + input.LastUpdate = nowTime; + if (input.HouseList == null) + { + input.HouseList = new List(); + } + else + { + input.HouseList.ForEach(h => + { + if (string.IsNullOrEmpty(h.GID)) + { + h.GID = Guid.NewGuid().ToString(); + h.PID = input.GID; + h.CreateTime = nowTime; + } + else + { + h.LastUpdate = nowTime; + } - //HouseBillNo + if (h.CntrList == null) + { + h.CntrList = new List(); + } + else + { + h.CntrList.ForEach(c => + { + if (string.IsNullOrEmpty(c.GID)) + { + c.GID = Guid.NewGuid().ToString(); + c.PID = h.GID; + c.CreateTime = nowTime; + } + else + { + c.LastUpdate = nowTime; + } + }); + } + }); + } + + #region 瀵瑰垎鍗曟暟鎹粺璁″嚭瑕佹墽琛岀殑鎿嶄綔锛屽垽鏂摢浜涙暟鎹槸 鏂板/淇敼/鍒犻櫎 + var inputHouseGids = input.HouseList?.Select(h => h.GID); + var oldHouseGids = oldMaster.HouseList?.Select(h => h.GID); + + var waitInsertHouseGids = inputHouseGids.Except(oldHouseGids); // 瑕佹柊澧炵殑鍒嗗崟涓婚敭 + var waitDeleteHouseGids = oldHouseGids.Except(inputHouseGids); // 瑕佸垹闄ょ殑鍒嗗崟涓婚敭 + var waitUpdateHouseGids = oldHouseGids.Intersect(inputHouseGids); // 瑕佷慨鏀圭殑鍒嗗崟涓婚敭 + + List waitInsertHouseList = null, waitUpdateHouseList = null; + if (waitInsertHouseGids.Any()) + { + waitInsertHouseList = input.HouseList.Where(h => waitInsertHouseGids.Contains(h.GID)).ToList(); + } + if (waitUpdateHouseGids.Any()) + { + waitUpdateHouseList = input.HouseList.Where(h => waitUpdateHouseGids.Contains(h.GID)).ToList(); + } + #endregion + + #region 瀵圭瀛愭暟鎹粺璁″嚭瑕佹墽琛岀殑鎿嶄綔锛屽垽鏂摢浜涙暟鎹槸 鏂板/淇敼/鍒犻櫎 + var inputCtnList = input.HouseList.SelectMany(h => h.CntrList); + var oldCtnList = oldMaster.HouseList.SelectMany(h => h.CntrList); + + var inputCtnGids = inputCtnList.Select(ctn => ctn.GID); + var oldCtnGids = oldCtnList.Select(ctn => ctn.GID); + + + var waitInsertCtnGids = inputCtnGids.Except(oldCtnGids); // 瑕佹柊澧炵殑绠卞瓙涓婚敭 + var waitDeleteCtnGids = oldCtnGids.Except(inputCtnGids); // 瑕佸垹闄ょ殑绠卞瓙涓婚敭 + var waitUpdateCtnGids = oldCtnGids.Intersect(inputCtnGids); // 瑕佷慨鏀圭殑绠卞瓙涓婚敭 + + List waitInsertCtnList = null, waitUpdateCtnList = null; + if (waitInsertCtnGids.Any()) + { + waitInsertCtnList = inputCtnList.Where(c => waitInsertCtnGids.Contains(c.GID)).ToList(); + } + if (waitUpdateCtnGids.Any()) + { + waitUpdateCtnList = inputCtnList.Where(c => waitUpdateCtnGids.Contains(c.GID)).ToList(); + } + #endregion + + + #region 寮濮嬫墽琛 + await using DbTransaction tran = await GetDbAmsTransaction(); + + // 涓诲崟鎵ц + await DbAMS.Update() + .SetSource(input) + .IgnoreColumns(m => new { m.CompID, m.CompName, m.UserID, m.UserName }) + .WithTransaction(tran) + .ExecuteAffrowsAsync(); + + // 鍒嗗崟鎵ц + if (waitInsertHouseGids.Any()) + { + await DbAMS.Insert(waitInsertHouseList).WithTransaction(tran).ExecuteAffrowsAsync(); + } + if (waitDeleteHouseGids.Any()) + { + await DbAMS.Update() + .Set(h => h.IsDel == true) + .Set(h => h.LastUpdate == nowTime) + .WithTransaction(tran) + .Where(h => waitDeleteHouseGids.Contains(h.GID)) + .ExecuteAffrowsAsync(); + } + if (waitUpdateHouseGids.Any()) + { + await DbAMS.Update() + .SetSource(waitUpdateHouseList) + .IgnoreColumns(h => new { h.StateIsMatched, h.StateIsAccept }) + .WithTransaction(tran) + .ExecuteAffrowsAsync(); + } + + // 绠卞瓙鎵ц + if (waitInsertCtnGids.Any()) + { + await DbAMS.Insert(waitInsertCtnList).WithTransaction(tran).ExecuteAffrowsAsync(); + } + if (waitDeleteCtnGids.Any()) + { + await DbAMS.Delete() + .WithTransaction(tran) + .Where(h => waitDeleteCtnGids.Contains(h.GID)) + .ExecuteAffrowsAsync(); + } + if (waitUpdateCtnGids.Any()) + { + await DbAMS.Update() + .SetSource(waitUpdateCtnList) + .WithTransaction(tran) + .ExecuteAffrowsAsync(); + } + #endregion + + AFRMasterHistory history = BuildAFRMasterHistory(input.GID, "淇敼", 0, "淇敼浜嗗崟鎹"); + await DbAMS.Insert(history).WithTransaction(tran).ExecuteAffrowsAsync(); + + tran.Commit(); + } } - public Task SaveInfo(AFRMasterDto input) + + private AFRMasterHistory BuildAFRMasterHistory(string pid, string state, int type, string remark) { - throw new NotImplementedException(); + var history = new AFRMasterHistory() + { + GID = Guid.NewGuid().ToString(), + CreateTime = DateTime.Now, + Operator = User.ShowName, + PID = pid, + State = state, + Type = Convert.ToByte(type) + }; + history.Remark = $"{history.Operator}浜巤history.CreateTime}{remark}"; + return history; } public Task Delete(string ids) @@ -238,5 +498,6 @@ namespace djy.Service.AFR { throw new NotImplementedException(); } + } } diff --git a/web/djy_AfrApi/HttpContextUser/AspNetUser.cs b/web/djy.Service/DjyService/AspNetUser.cs similarity index 91% rename from web/djy_AfrApi/HttpContextUser/AspNetUser.cs rename to web/djy.Service/DjyService/AspNetUser.cs index 2bddd82..3977a6f 100644 --- a/web/djy_AfrApi/HttpContextUser/AspNetUser.cs +++ b/web/djy.Service/DjyService/AspNetUser.cs @@ -1,10 +1,11 @@ 锘縰sing Common.DJYModel; using djy.IService.Djy; +using djy.Model; using Microsoft.AspNetCore.Http; using System; using System.Linq; -namespace djy_AfrApi.HttpContextUser +namespace djy.Service.DjyService { public class AspNetUser : IUser { @@ -34,7 +35,7 @@ namespace djy_AfrApi.HttpContextUser return userTemp.Data; } - throw new Exception("鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛鏃跺彂鐢熷紓甯"); + throw new Exception("鐧诲綍澶辨晥"); } } public string CompId => CurrentUser.CompId; diff --git a/web/djy.Service/DjyService/DbContext.cs b/web/djy.Service/DjyService/DbContext.cs index 07ac895..5032bd0 100644 --- a/web/djy.Service/DjyService/DbContext.cs +++ b/web/djy.Service/DjyService/DbContext.cs @@ -1,16 +1,13 @@ -锘縰sing FreeRedis; -using FreeRedis.Internal; +锘縰sing Common; +using Common.Helpers; +using FreeRedis; using FreeSql; +using FreeSql.Internal.ObjectPool; using System; -using System.Collections.Generic; +using System.Data.Common; using System.Diagnostics; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; -using Common; -using System.Data; -using Common.Helpers; namespace djy.Service.DjyService { @@ -57,6 +54,16 @@ namespace djy.Service.DjyService /// public static IdleBus DbBus = new IdleBus(TimeSpan.FromSeconds(20)); + public static IFreeSql DbAMS => DbBus.Get(DbList.AMSCenter); + + + public async Task GetDbAmsTransaction() + { + Object conn = await DbAMS.Ado.MasterPool.GetAsync(); + DbTransaction transaction = await conn.Value.BeginTransactionAsync(); + return transaction; + } + /// /// RedisDB /// @@ -106,7 +113,7 @@ namespace djy.Service.DjyService }); }; } - + return freeSql; }); } diff --git a/web/djy_AfrApi/Attributes/CacheAttribute.cs b/web/djy_AfrApi/Attributes/CacheAttribute.cs new file mode 100644 index 0000000..18f6353 --- /dev/null +++ b/web/djy_AfrApi/Attributes/CacheAttribute.cs @@ -0,0 +1,9 @@ +锘縰sing System; + +namespace djy_AfrApi.Attributes +{ + [AttributeUsage(AttributeTargets.Method)] + public class RedisCachingAttribute : Attribute + { + } +} diff --git a/web/djy_AfrApi/Controllers/AfrController.cs b/web/djy_AfrApi/Controllers/AfrController.cs index efa2cf4..07a102d 100644 --- a/web/djy_AfrApi/Controllers/AfrController.cs +++ b/web/djy_AfrApi/Controllers/AfrController.cs @@ -1,39 +1,33 @@ 锘縰sing 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 { + /// + /// AFR瀵规帴鎺ュ彛 + /// [Route("api/[controller]")] [ApiController] [Authorize] public class AfrController : ApiBase { private readonly ILogger logger; - private readonly IUser user; private readonly IAfrService _afrService; //private readonly ILogger bigLogger; public AfrController(ILogger logger, - IUser user, IAfrService afrService) { this.logger = logger; - this.user = user; this._afrService = afrService; // 鑾峰彇ILogger瀵硅薄 @@ -42,6 +36,11 @@ namespace djy_AfrApi.Controllers } #region 鏌ヨ鎺ュ彛 + /// + /// 鍒嗛〉鏌ヨ鑽夌ǹ绠辨垨宸插彂閫佸垪琛ㄧ殑鏁版嵁 + /// + /// + /// [HttpGet("PageData")] public async Task> PageData(AFRMasterInputDto input) { @@ -53,9 +52,25 @@ namespace djy_AfrApi.Controllers var pageData = await _afrService.Load(input); return SuccessPage(pageData); } + /// + /// 鑾峰彇璇︽儏 + /// + /// + /// + [HttpGet("Get")] + public async Task> Get(string gid) + { + var model = await _afrService.Get(gid); + return SuccessResp(model); + } #endregion #region 鏂板/缂栬緫 + /// + /// 鏂板鎴栦慨鏀 + /// + /// + /// [HttpPost("AddOrUpdate")] public async Task AddOrUpdateAsync([FromBody] AFRMasterDto input) { @@ -65,6 +80,11 @@ namespace djy_AfrApi.Controllers #endregion #region 鍒犻櫎 + /// + /// 鍒犻櫎 + /// + /// + /// [HttpPost("Del")] public async Task Delete(string ids) { @@ -74,6 +94,12 @@ namespace djy_AfrApi.Controllers #endregion #region 绗笁鏂规帴鍙 + /// + /// 鍙戦佹帴鍙 + /// + /// + /// + /// [HttpGet("Send")] public async Task Send(string ids, string msgType) { @@ -81,6 +107,11 @@ namespace djy_AfrApi.Controllers return SuccessResp(); } + /// + /// 鎺ユ敹鍥炴墽 + /// + /// + /// [AllowAnonymous] [HttpPost("Receipt")] public async Task SaveReceiptAsync(AFRReceiptDto input) @@ -89,7 +120,10 @@ namespace djy_AfrApi.Controllers return SuccessResp("鎺ユ敹鎴愬姛"); } #endregion - + /// + /// 鑾峰彇鏈嶅姟鍣ㄥ綋鍓嶆椂闂 + /// + /// [AllowAnonymous] [HttpGet("[action]")] public Response GetTime() diff --git a/web/djy_AfrApi/Controllers/ApiBase.cs b/web/djy_AfrApi/Controllers/ApiBase.cs index da79f7f..ee7764f 100644 --- a/web/djy_AfrApi/Controllers/ApiBase.cs +++ b/web/djy_AfrApi/Controllers/ApiBase.cs @@ -21,6 +21,11 @@ namespace djy_AfrApi.Controllers [NonAction] protected ResponsePage SuccessPage(PageModel pageModel) { + if (pageModel is null) + { + throw new ArgumentNullException(nameof(pageModel)); + } + return new ResponsePage() { Code = 200, @@ -40,6 +45,16 @@ namespace djy_AfrApi.Controllers Message = message }; } + [NonAction] + protected Response SuccessResp(T result) + { + return new Response() + { + Code = 200, + Message = "鎿嶄綔鎴愬姛", + Result = result + }; + } #endregion diff --git a/web/djy_AfrApi/Controllers/CommonController.cs b/web/djy_AfrApi/Controllers/CommonController.cs index 6a27313..c9a0a77 100644 --- a/web/djy_AfrApi/Controllers/CommonController.cs +++ b/web/djy_AfrApi/Controllers/CommonController.cs @@ -1,23 +1,33 @@ -锘縰sing Common; -using Common.Utilities; +锘縰sing Common.Utilities; using djy.IService.Afr; using djy.Model.AmsDto; +using djy_AfrApi.Attributes; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; namespace djy_AfrApi.Controllers.Common { + [Route("api/[controller]")] + [ApiController] + [Authorize] public class CommonController { - IAfrService ser = IOC.AddServer(); + private readonly IAfrService ser; + + public CommonController(IAfrService service) + { + this.ser = service; + } #region 涓嬫媺鎺ュ彛 /// /// 涓嬫媺鑾峰彇鍥藉 /// /// [HttpGet("GetCountry")] + [RedisCaching] public Response> GetCountry(string strlink = "", int page = 0, int limit = 0) { var result = new Response>(); @@ -39,6 +49,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetCARRIER")] + [RedisCaching] public Response> GetCARRIER() { var result = new Response>(); @@ -59,6 +70,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetCTNALL")] + [RedisCaching] public Response> GetCTNALL() { var result = new Response>(); @@ -81,6 +93,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetPackage")] + [RedisCaching] public Response> GetPackage() { var result = new Response>(); @@ -101,6 +114,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetDangerousGoods")] + [RedisCaching] public Response> GetDangerousGoods(string strlink = "",int page = 0, int limit = 0) { var result = new Response>(); @@ -143,6 +157,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetPort")] + [RedisCaching] public Response> GetPort(string strlink = "", int page = 0, int limit = 0) { var result = new Response>(); @@ -164,6 +179,7 @@ namespace djy_AfrApi.Controllers.Common /// /// [HttpGet("GetVessel")] + [RedisCaching] public Response> GetVessel(string strlink = "", int page = 0,int limit =0) { var result = new Response>(); diff --git a/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log b/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log deleted file mode 100644 index cdac28b..0000000 --- a/web/djy_AfrApi/Log/SqlLog/SqlLog_2023-12-27.log +++ /dev/null @@ -1,33 +0,0 @@ --------------------------------- -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/CommonCacheMiddleware.cs b/web/djy_AfrApi/Milldlewares/CommonCacheMiddleware.cs new file mode 100644 index 0000000..b65bf11 --- /dev/null +++ b/web/djy_AfrApi/Milldlewares/CommonCacheMiddleware.cs @@ -0,0 +1,85 @@ +锘縰sing Common.Tools; +using Common.Utilities; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Controllers; +using Newtonsoft.Json; +using System.Diagnostics; +using System; +using System.IO; +using System.Threading.Tasks; +using NPOI.XWPF.UserModel; +using djy_AfrApi.Attributes; + +namespace djy_AfrApi.Milldlewares +{ + public class CommonCacheMiddleware + { + private readonly RequestDelegate next; + + public CommonCacheMiddleware(RequestDelegate next) + { + this.next = next; + } + public async Task InvokeAsync(HttpContext context) + { + var endpoint = context.GetEndpoint(); + + if (endpoint?.Metadata?.GetMetadata() == null) + { + await next(context); + } + else + { + var actionDescriptor = endpoint.Metadata.GetMetadata(); + if (actionDescriptor?.ActionName == null) + { + await next(context); + } + else + { + string redisKey = actionDescriptor.ActionName + "Cache"; + string cacheData = YsRedisHelp.RedisGetString(redisKey); + if (string.IsNullOrEmpty(cacheData)) + { + // 瀛樺偍鍝嶅簲鏁版嵁 + using (MemoryStream memoryStream = new MemoryStream()) + { + // 浣跨敤鑷畾涔夌殑鍝嶅簲娴侊紝灏嗘墍鏈夊啓鍏ラ噸瀹氬悜鍒板唴瀛樻祦 + var originalBodyStream = context.Response.Body; + context.Response.Body = memoryStream; + + try + { + await next(context); + + // 浠庡唴瀛樻祦璇诲彇鍝嶅簲鍐呭 + memoryStream.Seek(0, SeekOrigin.Begin); + string responseBody = new StreamReader(memoryStream).ReadToEnd(); + + Response response = JsonConvert.DeserializeObject(responseBody); + if (response.Code == 200) + { + YsRedisHelp.RedisSet(redisKey, responseBody, 86400); + } + + // 灏嗗搷搴斿唴瀹瑰啓鍥炲師濮嬪搷搴旀祦 + memoryStream.Seek(0, SeekOrigin.Begin); + await memoryStream.CopyToAsync(originalBodyStream); + } + finally + { + // 鎭㈠鍘熷鍝嶅簲娴 + context.Response.Body = originalBodyStream; + } + } + } + else + { + context.Response.ContentType = "application/json"; + await context.Response.WriteAsync(cacheData).ConfigureAwait(false); + } + } + } + } + } +} diff --git a/web/djy_AfrApi/Milldlewares/MiddlewareHelpers.cs b/web/djy_AfrApi/Milldlewares/MiddlewareHelpers.cs index 1a1c303..ee9e033 100644 --- a/web/djy_AfrApi/Milldlewares/MiddlewareHelpers.cs +++ b/web/djy_AfrApi/Milldlewares/MiddlewareHelpers.cs @@ -29,10 +29,20 @@ namespace djy_AfrApi.Middlewares return app.UseMiddleware(); } - // 璁板綍璇锋眰鍜屽搷搴旀暟鎹 + /// + /// 璁板綍璇锋眰鍜屽搷搴旀暟鎹 + /// public static IApplicationBuilder UseRequRespLogMiddleware(this IApplicationBuilder app) { return app.UseMiddleware(); } + + /// + /// 鍏叡鏁版嵁缂撳瓨涓棿浠 + /// + public static IApplicationBuilder UseCommonCacheMiddleware(this IApplicationBuilder app) + { + return app.UseMiddleware(); + } } } diff --git a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs index ab1f868..8cf20a6 100644 --- a/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs +++ b/web/djy_AfrApi/Milldlewares/RequRespLogMiddleware.cs @@ -22,7 +22,8 @@ namespace djy_AfrApi.Milldlewares } public async Task InvokeAsync(HttpContext context) { - if (context.Request.Path.Value.Contains("api")) + // 瀛楀吀鎺ュ彛涓嶈褰曟棩蹇 + if (context.Request.Path.Value.Contains("api") && !context.Request.Path.Value.Contains("/api/Common/")) { _stopwatch.Restart(); @@ -31,9 +32,9 @@ namespace djy_AfrApi.Milldlewares //// 瀛樺偍璇锋眰鏁版嵁 var request = context.Request; var sr = new StreamReader(request.Body); - + 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; diff --git a/web/djy_AfrApi/Properties/launchSettings.json b/web/djy_AfrApi/Properties/launchSettings.json index 341c2b9..1d46bbd 100644 --- a/web/djy_AfrApi/Properties/launchSettings.json +++ b/web/djy_AfrApi/Properties/launchSettings.json @@ -2,7 +2,6 @@ "profiles": { "djy_AfrApi": { "commandName": "Project", - "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/web/djy_AfrApi/Startup.cs b/web/djy_AfrApi/Startup.cs index 3cad23c..d2bbbb5 100644 --- a/web/djy_AfrApi/Startup.cs +++ b/web/djy_AfrApi/Startup.cs @@ -1,7 +1,7 @@ using Common; +using djy.Model; using djy.Service.DjyService; using djy_AfrApi.Filter; -using djy_AfrApi.HttpContextUser; using djy_AfrApi.Middlewares; using FreeRedis; using Microsoft.AspNetCore.Builder; @@ -15,6 +15,8 @@ using Microsoft.OpenApi.Models; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; +using System.IO; +using System; using System.Linq; using System.Reflection; @@ -102,7 +104,17 @@ namespace djy_AfrApi services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "djy_AfrApi", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "AFR Api文档", Version = "v1" }); + + var basePath = AppContext.BaseDirectory; + + var xmlPath = Path.Combine(basePath, "djy_AfrApi.xml"); + c.IncludeXmlComments(xmlPath, true); + + var xmlModelPath = Path.Combine(basePath, "djy.Model.xml"); + c.IncludeXmlComments(xmlModelPath); + + c.UseInlineDefinitionsForEnums(); }); IOC.container = services; } @@ -114,7 +126,7 @@ namespace djy_AfrApi { app.UseDeveloperExceptionPage(); app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "djy_AfrApi v1")); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AFR Api文档 v1")); } // 记录请求响应数据 app.UseRequRespLogMiddleware(); @@ -152,6 +164,9 @@ namespace djy_AfrApi // 二次验证授权,并保存当前登录人User对象(为了和ISF、AMS逻辑保持一致) app.UseNextAuthorizationMiddle(); + // 公共字典数据缓存中间件 + app.UseCommonCacheMiddleware(); + app.UseEndpoints(endpoints => { endpoints.MapControllers(); diff --git a/web/djy_AfrApi/djy_AfrApi.csproj b/web/djy_AfrApi/djy_AfrApi.csproj index 7278c4b..1492708 100644 --- a/web/djy_AfrApi/djy_AfrApi.csproj +++ b/web/djy_AfrApi/djy_AfrApi.csproj @@ -3,6 +3,7 @@ net5.0 false + True