From ddc460c2a4bef958a67689fd485ef4bd2815ded4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=81=9A=E7=A0=81=E5=86=9C?= <599854767@qq.com> Date: Mon, 15 Aug 2022 20:22:19 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Anull=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommonController.cs | 2 +- .../System/CodeGeneratorController.cs | 2 +- .../Controllers/System/TasksController.cs | 2 +- ZR.Admin.WebApi/Extensions/EntityExtension.cs | 26 +++++++++---------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/CommonController.cs b/ZR.Admin.WebApi/Controllers/CommonController.cs index f841c74..8854422 100644 --- a/ZR.Admin.WebApi/Controllers/CommonController.cs +++ b/ZR.Admin.WebApi/Controllers/CommonController.cs @@ -178,6 +178,6 @@ namespace ZR.Admin.WebApi.Controllers /// 文件名生成类型 1 原文件名 2 自定义 3 自动生成 /// public int FileNameType { get; set; } - public IFormFile File { get; set; } + public IFormFile? File { get; set; } } } diff --git a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs index 867637d..b356982 100644 --- a/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs +++ b/ZR.Admin.WebApi/Controllers/System/CodeGeneratorController.cs @@ -256,7 +256,7 @@ namespace ZR.Admin.WebApi.Controllers [ActionPermissionFilter(Permission = "tool:gen:code")] public IActionResult CodeGenerate([FromBody] GenerateDto dto) { - if (dto?.TableId <= 0) + if (dto == null || dto.TableId <= 0) { throw new CustomException(ResultCode.CUSTOM_ERROR, "请求参数为空"); } diff --git a/ZR.Admin.WebApi/Controllers/System/TasksController.cs b/ZR.Admin.WebApi/Controllers/System/TasksController.cs index cbabbb0..fc99400 100644 --- a/ZR.Admin.WebApi/Controllers/System/TasksController.cs +++ b/ZR.Admin.WebApi/Controllers/System/TasksController.cs @@ -70,7 +70,7 @@ namespace ZR.Admin.WebApi.Controllers { return SUCCESS(_tasksQzService.GetId(id)); } - return SUCCESS(null); + return SUCCESS(0); } /// diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs index 734d1ca..81bb60d 100644 --- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs +++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs @@ -9,52 +9,52 @@ namespace ZR.Admin.WebApi.Extensions public static TSource ToCreate(this TSource source, HttpContext? context = null) { var types = source?.GetType(); + if (types == null) return source; if (types.GetProperty("CreateTime") != null) { - types.GetProperty("CreateTime").SetValue(source, DateTime.Now, null); + types.GetProperty("CreateTime")?.SetValue(source, DateTime.Now, null); } if (types.GetProperty("AddTime") != null) { - types.GetProperty("AddTime").SetValue(source, DateTime.Now, null); + types.GetProperty("AddTime")?.SetValue(source, DateTime.Now, null); } if (types.GetProperty("UpdateTime") != null) { - types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); } if (types.GetProperty("Create_by") != null && context != null) { - types.GetProperty("Create_by").SetValue(source, context.GetName(), null); + types.GetProperty("Create_by")?.SetValue(source, context.GetName(), null); } if (types.GetProperty("UserId") != null && context != null) { - types.GetProperty("UserId").SetValue(source, context.GetUId(), null); + types.GetProperty("UserId")?.SetValue(source, context.GetUId(), null); } return source; } - public static TSource ToUpdate(this TSource source, HttpContext context = null) + public static TSource ToUpdate(this TSource source, HttpContext? context = null) { - var types = source.GetType(); + var types = source?.GetType(); + if (types == null) return source; if (types.GetProperty("UpdateTime") != null) { - types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null); + types.GetProperty("UpdateTime")?.SetValue(source, DateTime.Now, null); } if (types.GetProperty("Update_time") != null) { - types.GetProperty("Update_time").SetValue(source, DateTime.Now, null); + types.GetProperty("Update_time")?.SetValue(source, DateTime.Now, null); } - if (types.GetProperty("UpdateBy") != null) { - types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null); + types.GetProperty("UpdateBy")?.SetValue(source, context?.GetName(), null); } if (types.GetProperty("Update_by") != null) { - types.GetProperty("Update_by").SetValue(source, context.GetName(), null); + types.GetProperty("Update_by")?.SetValue(source, context?.GetName(), null); } - return source; }