添加项目文件。
This commit is contained in:
1 parent
05e131ca4e
commit
514d6f5255
1162 files changed
+81255
No files matched your search
@@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Support;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Core.Extensions;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Controllers
|
||||
{
|
||||
[Area("system")]
|
||||
[ActionDescription("定时器")]
|
||||
public partial class SysJobController : BaseController
|
||||
{
|
||||
private readonly IServiceProvider _sp;
|
||||
private readonly GlobalData _gd;
|
||||
private IScheduler _scheduler;
|
||||
private readonly IDataContext _dc;
|
||||
private readonly IUnitWork _unitwork;
|
||||
|
||||
public SysJobController(IServiceProvider sp, GlobalData gd, IDataContext DC, IUnitWork unitwork)
|
||||
{
|
||||
_sp = sp;
|
||||
_gd = gd;
|
||||
_dc = DC;
|
||||
_unitwork = unitwork;
|
||||
}
|
||||
|
||||
#region Search
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
public ActionResult Index()
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobListVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Search")]
|
||||
[HttpPost]
|
||||
public string Search(SysJobSearcher searcher)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobListVM>(passInit: true);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
vm.Searcher = searcher;
|
||||
return vm.GetJson(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
return vm.GetError();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Search
|
||||
|
||||
#region Create
|
||||
|
||||
[ActionDescription("Sys.Create")]
|
||||
public ActionResult Create()
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.Create")]
|
||||
public ActionResult Create(SysJobVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_unitwork.IsExit<SysJob>(x => x.JobName == vm.Entity.JobName))
|
||||
{
|
||||
return FFResult().Alert($"定时器{vm.Entity.JobName}已存在!");
|
||||
}
|
||||
vm.Entity.JobGroup = vm.Entity.JobName;
|
||||
vm.DoAdd();
|
||||
new QuartzService(_sp, _gd, _dc).AddJob(vm.Entity).Wait();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
vm.DoReInit();
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Create
|
||||
|
||||
#region Edit
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
public ActionResult Edit(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Edit")]
|
||||
[HttpPost]
|
||||
[ValidateFormItemOnly]
|
||||
public ActionResult Edit(SysJobVM vm)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
vm.DoEdit();
|
||||
new QuartzService(_sp, _gd, _dc).ModJob(vm.Entity);
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
vm.DoReInit();
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Edit
|
||||
|
||||
#region Delete
|
||||
|
||||
[ActionDescription("Sys.Delete")]
|
||||
public ActionResult Delete(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[ActionDescription("Sys.Delete")]
|
||||
[HttpPost]
|
||||
public ActionResult Delete(string id, IFormCollection nouse)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobVM>(id);
|
||||
vm.DoDelete();
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Delete
|
||||
|
||||
#region Details
|
||||
|
||||
[ActionDescription("Sys.Details")]
|
||||
public ActionResult Details(string id)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobVM>(id);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
#endregion Details
|
||||
|
||||
#region BatchEdit
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.BatchEdit")]
|
||||
public ActionResult BatchEdit(string[] IDs)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobBatchVM>(Ids: IDs);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.BatchEdit")]
|
||||
public ActionResult DoBatchEdit(SysJobBatchVM vm, IFormCollection nouse)
|
||||
{
|
||||
if (!ModelState.IsValid || !vm.DoBatchEdit())
|
||||
{
|
||||
return PartialView("BatchEdit", vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchEditSuccess", vm.Ids.Length]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion BatchEdit
|
||||
|
||||
#region BatchDelete
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.BatchDelete")]
|
||||
public ActionResult BatchDelete(string[] IDs)
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobBatchVM>(Ids: IDs);
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.BatchDelete")]
|
||||
public ActionResult DoBatchDelete(SysJobBatchVM vm, IFormCollection nouse)
|
||||
{
|
||||
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||
{
|
||||
return PartialView("BatchDelete", vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.BatchDeleteSuccess", vm.Ids.Length]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion BatchDelete
|
||||
|
||||
#region Import
|
||||
|
||||
[ActionDescription("Sys.Import")]
|
||||
public ActionResult Import()
|
||||
{
|
||||
var vm = Wtm.CreateVM<SysJobImportVM>();
|
||||
return PartialView(vm);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionDescription("Sys.Import")]
|
||||
public ActionResult Import(SysJobImportVM vm, IFormCollection nouse)
|
||||
{
|
||||
if (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData())
|
||||
{
|
||||
return PartialView(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FFResult().CloseDialog().RefreshGrid().Alert(Localizer["Sys.ImportSuccess", vm.EntityList.Count.ToString()]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Import
|
||||
|
||||
#region Export
|
||||
|
||||
[ActionDescription("Sys.Export")]
|
||||
[HttpPost]
|
||||
public IActionResult ExportExcel(SysJobListVM vm)
|
||||
{
|
||||
return vm.GetExportData();
|
||||
}
|
||||
|
||||
#endregion Export
|
||||
|
||||
/// <summary>
|
||||
/// 执行一次
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult Execute(int id)
|
||||
{
|
||||
var job = _unitwork.FindSingle<SysJob>(x => x.ID == id);
|
||||
new QuartzService(_sp, _gd, _dc).Execute(job);
|
||||
return FFResult().Message("succeed");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用或暂停定时器
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IActionResult> PauseOrResume(int id)
|
||||
{
|
||||
var job = _unitwork.FindSingle<SysJob>(x => x.ID == id);
|
||||
ISchedulerFactory factory = new StdSchedulerFactory();
|
||||
_scheduler = await factory.GetScheduler();
|
||||
|
||||
if (job.Status == SysJobEnum.running)
|
||||
{
|
||||
job.Status = SysJobEnum.stoped;
|
||||
_unitwork.Update(job);
|
||||
_scheduler.PauseJob(new JobKey(job.JobName, job.JobGroup)).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
job.Status = SysJobEnum.running;
|
||||
_unitwork.Update(job);
|
||||
_scheduler.ResumeJob(new JobKey(job.JobName, job.JobGroup)).Wait();
|
||||
}
|
||||
return FFResult().RefreshGrid().Message("succeed");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user