♻️重新设计返回格式,同Ruoyi保持一致
This commit is contained in:
parent
70371e92b3
commit
44ef55be00
@ -99,6 +99,10 @@ namespace Infrastructure.Controllers
|
|||||||
|
|
||||||
return new ApiResult((int)resultCode, msg, data);
|
return new ApiResult((int)resultCode, msg, data);
|
||||||
}
|
}
|
||||||
|
protected ApiResult Success()
|
||||||
|
{
|
||||||
|
return GetApiResult(ResultCode.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
|||||||
@ -14,13 +14,13 @@ namespace Infrastructure.Model
|
|||||||
|
|
||||||
/** 数据对象 */
|
/** 数据对象 */
|
||||||
public static readonly string DATA_TAG = "data";
|
public static readonly string DATA_TAG = "data";
|
||||||
public int Code { get; set; }
|
//public int Code { get; set; }
|
||||||
public string Msg { get; set; }
|
//public string Msg { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 如果data值为null,则忽略序列化将不会返回data字段
|
/// 如果data值为null,则忽略序列化将不会返回data字段
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
//[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||||
public object Data { get; set; }
|
//public object Data { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化一个新创建的APIResult对象,使其表示一个空消息
|
/// 初始化一个新创建的APIResult对象,使其表示一个空消息
|
||||||
@ -103,9 +103,26 @@ namespace Infrastructure.Model
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ApiResult Error(string msg) { return new ApiResult((int)ResultCode.CUSTOM_ERROR, msg); }
|
public static ApiResult Error(string msg) { return new ApiResult((int)ResultCode.CUSTOM_ERROR, msg); }
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为成功消息
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IsSuccess()
|
||||||
{
|
{
|
||||||
return $"msg={Msg},data={Data}";
|
return HttpStatus.SUCCESS == (int)this[CODE_TAG];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 方便链式调用
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ApiResult Put(string key, object value)
|
||||||
|
{
|
||||||
|
Add(key, value);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace Infrastructure
|
|||||||
public static TSource ToCreate<TSource>(this TSource source, HttpContext? context = null)
|
public static TSource ToCreate<TSource>(this TSource source, HttpContext? context = null)
|
||||||
{
|
{
|
||||||
var types = source?.GetType();
|
var types = source?.GetType();
|
||||||
if (types == null) return source;
|
if (types == null || context == null) return source;
|
||||||
BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
|
BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
|
||||||
|
|
||||||
types.GetProperty("CreateTime", flag)?.SetValue(source, DateTime.Now, null);
|
types.GetProperty("CreateTime", flag)?.SetValue(source, DateTime.Now, null);
|
||||||
@ -26,7 +26,7 @@ namespace Infrastructure
|
|||||||
public static TSource ToUpdate<TSource>(this TSource source, HttpContext? context = null)
|
public static TSource ToUpdate<TSource>(this TSource source, HttpContext? context = null)
|
||||||
{
|
{
|
||||||
var types = source?.GetType();
|
var types = source?.GetType();
|
||||||
if (types == null) return source;
|
if (types == null || context == null) return source;
|
||||||
BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
|
BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
|
||||||
|
|
||||||
types.GetProperty("UpdateTime", flag)?.SetValue(source, DateTime.Now, null);
|
types.GetProperty("UpdateTime", flag)?.SetValue(source, DateTime.Now, null);
|
||||||
|
|||||||
@ -86,7 +86,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
throw new CustomException($"程序集或者类名不能为空");
|
throw new CustomException($"程序集或者类名不能为空");
|
||||||
}
|
}
|
||||||
//从 Dto 映射到 实体
|
//从 Dto 映射到 实体
|
||||||
var tasksQz = parm.Adapt<SysTasks>().ToCreate();
|
var tasksQz = parm.Adapt<SysTasks>().ToCreate(HttpContext);
|
||||||
tasksQz.Create_by = HttpContext.GetName();
|
tasksQz.Create_by = HttpContext.GetName();
|
||||||
tasksQz.ID = SnowFlakeSingle.Instance.NextId().ToString();
|
tasksQz.ID = SnowFlakeSingle.Instance.NextId().ToString();
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||||
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);
|
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);
|
||||||
|
|
||||||
if (taskResult.Code == 200)
|
if (taskResult.IsSuccess())
|
||||||
{
|
{
|
||||||
_tasksQzService.Delete(id);
|
_tasksQzService.Delete(id);
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||||
var taskResult = await _schedulerServer.AddTaskScheduleAsync(tasksQz);
|
var taskResult = await _schedulerServer.AddTaskScheduleAsync(tasksQz);
|
||||||
|
|
||||||
if (taskResult.Code == 200)
|
if (taskResult.IsSuccess())
|
||||||
{
|
{
|
||||||
tasksQz.IsStart = 1;
|
tasksQz.IsStart = 1;
|
||||||
_tasksQzService.Update(tasksQz);
|
_tasksQzService.Update(tasksQz);
|
||||||
@ -218,7 +218,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
var tasksQz = _tasksQzService.GetFirst(m => m.ID == id);
|
||||||
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);//await _schedulerServer.PauseTaskScheduleAsync(tasksQz);
|
var taskResult = await _schedulerServer.DeleteTaskScheduleAsync(tasksQz);//await _schedulerServer.PauseTaskScheduleAsync(tasksQz);
|
||||||
|
|
||||||
if (taskResult.Code == 200)
|
if (taskResult.IsSuccess())
|
||||||
{
|
{
|
||||||
tasksQz.IsStart = 0;
|
tasksQz.IsStart = 0;
|
||||||
_tasksQzService.Update(tasksQz);
|
_tasksQzService.Update(tasksQz);
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
foreach (var task in tasks.Result)
|
foreach (var task in tasks.Result)
|
||||||
{
|
{
|
||||||
var result = _schedulerServer.AddTaskScheduleAsync(task);
|
var result = _schedulerServer.AddTaskScheduleAsync(task);
|
||||||
if (result.Result.Code == 200)
|
if (result.Result.IsSuccess())
|
||||||
{
|
{
|
||||||
Console.WriteLine($"注册任务[{task.Name}]ID:{task.ID}成功");
|
Console.WriteLine($"注册任务[{task.Name}]ID:{task.ID}成功");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,9 +63,7 @@ namespace ZR.Admin.WebApi.Filters
|
|||||||
{
|
{
|
||||||
string msg = $"请求访问[{url}]失败,无法访问系统资源";
|
string msg = $"请求访问[{url}]失败,无法访问系统资源";
|
||||||
//logger.Info(msg);
|
//logger.Info(msg);
|
||||||
var r = new ApiResult((int)ResultCode.DENY, msg);
|
context.Result = new JsonResult(ApiResult.Error(ResultCode.DENY, msg));
|
||||||
|
|
||||||
context.Result = new JsonResult(r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user