1
This commit is contained in:
@@ -130,7 +130,7 @@ namespace DOAN.Admin.WebApi.Controllers
|
||||
return SUCCESS(null);
|
||||
};
|
||||
|
||||
parm.ScheduleDate = parm.ScheduleDate.Date;
|
||||
parm.ScheduleDate = parm.ScheduleDate.Value.Date;
|
||||
var modal = parm.Adapt<GroupSchedule>().ToCreate(HttpContext);
|
||||
|
||||
var response = _GroupScheduleService.AddGroupSchedule(modal);
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace DOAN.Model.MES.group.Dto
|
||||
/// </summary>
|
||||
public class GroupPostDto
|
||||
{
|
||||
[Required(ErrorMessage = "雪花不能为空")]
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "父id不能为空")]
|
||||
|
||||
public string ParentId { get; set; }
|
||||
|
||||
public string PostName { get; set; }
|
||||
|
||||
@@ -26,30 +26,30 @@ namespace DOAN.Model.MES.group.Dto
|
||||
/// </summary>
|
||||
public class GroupScheduleDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
public DateTime ScheduleDate { get; set; }
|
||||
public DateTime? ScheduleDate { get; set; }
|
||||
|
||||
public string GroupName { get; set; }
|
||||
public string? GroupName { get; set; }
|
||||
|
||||
public string GroupCode { get; set; }
|
||||
public string? GroupCode { get; set; }
|
||||
|
||||
|
||||
public int FkShift { get; set; }
|
||||
public string ShiftName { get; set; }
|
||||
public int? FkShift { get; set; }
|
||||
public string? ShiftName { get; set; }
|
||||
|
||||
public string Remark { get; set; }
|
||||
public string? Remark { get; set; }
|
||||
|
||||
public string Status { get; set; }
|
||||
public string? Status { get; set; }
|
||||
|
||||
public string CreatedBy { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
|
||||
public string UpdatedBy { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
|
||||
public decimal WorkHours { get; set; }
|
||||
public decimal? WorkHours { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using NLog;
|
||||
using DOAN.Infrastructure.IPTools;
|
||||
using DOAN.Model.System;
|
||||
using DOAN.ServiceCore.Services;
|
||||
using System.Text;
|
||||
|
||||
namespace DOAN.ServiceCore.Middleware
|
||||
{
|
||||
@@ -29,31 +30,40 @@ namespace DOAN.ServiceCore.Middleware
|
||||
/// <returns></returns>
|
||||
public override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
// 打印请求参数
|
||||
string msg = string.Empty;
|
||||
var values = context.ModelState.Values;
|
||||
foreach (var item in values)
|
||||
// 检查模型校验是否失败
|
||||
if (!context.ModelState.IsValid)
|
||||
{
|
||||
foreach (var err in item.Errors)
|
||||
StringBuilder msgBuilder = new StringBuilder("请求参数错误:");
|
||||
foreach (var key in context.ModelState.Keys)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
var state = context.ModelState[key];
|
||||
if (state.Errors.Any())
|
||||
{
|
||||
msg += " | ";
|
||||
// 获取字段名称
|
||||
msgBuilder.Append($"字段: {key}, ");
|
||||
|
||||
// 获取字段的值
|
||||
var attemptedValue = state.AttemptedValue;
|
||||
msgBuilder.Append($"值: {attemptedValue}, ");
|
||||
|
||||
// 获取错误信息
|
||||
var errors = string.Join(" | ", state.Errors.Select(e => e.ErrorMessage));
|
||||
msgBuilder.Append($"错误: {errors}; ");
|
||||
}
|
||||
}
|
||||
|
||||
msg += err.ErrorMessage;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
logger.Info($"请求参数错误,{msg}");
|
||||
string msg = msgBuilder.ToString();
|
||||
logger.Info(msg);
|
||||
|
||||
// 返回错误响应
|
||||
ApiResult response = new((int)ResultCode.PARAM_ERROR, msg);
|
||||
|
||||
context.Result = new JsonResult(response);
|
||||
|
||||
// 直接返回,不再执行后续逻辑
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 如果模型校验通过,继续执行后续逻辑
|
||||
return base.OnActionExecutionAsync(context, next);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user