2020-10-22 14:59:36 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-12-20 23:14:09 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Infrastructure;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using OpenAuth.App;
|
|
|
|
|
using OpenAuth.App.Interface;
|
|
|
|
|
using OpenAuth.App.Request;
|
|
|
|
|
using OpenAuth.Repository.Domain;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class OpenJobsController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private readonly OpenJobApp _app;
|
|
|
|
|
|
|
|
|
|
public OpenJobsController(OpenJobApp app, IAuth auth) : base(auth)
|
|
|
|
|
{
|
|
|
|
|
_app = app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//主页
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加或修改
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Add(AddOrUpdateOpenJobReq obj)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加或修改
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Update(AddOrUpdateOpenJobReq obj)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.Update(obj);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取本地可执行的任务列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string QueryLocalHandlers()
|
|
|
|
|
{
|
|
|
|
|
var result = new Response<List<string>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
result.Result = _app.QueryLocalHandlers();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.Code = 500;
|
|
|
|
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 改变任务状态,启动/停止
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string ChangeStatus(ChangeJobStatusReq req)
|
|
|
|
|
{
|
|
|
|
|
var result = new Response();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.ChangeJobStatus(req);
|
|
|
|
|
result.Message = "切换成功,可以在系统日志中查看运行结果";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.Code = 500;
|
|
|
|
|
result.Message = ex.InnerException?.Message ?? ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载列表
|
|
|
|
|
/// </summary>
|
2020-12-20 23:14:09 +08:00
|
|
|
|
public async Task<string> Load([FromQuery]QueryOpenJobListReq request)
|
2020-10-22 14:59:36 +08:00
|
|
|
|
{
|
2020-12-20 23:14:09 +08:00
|
|
|
|
var objs = await _app.Load(request);
|
|
|
|
|
return JsonHelper.Instance.Serialize(objs);
|
2020-10-22 14:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string Delete(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_app.Delete(ids);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|