mirror of
https://gitee.com/iioter/iotgateway.git
synced 2024-11-29 18:28:09 +08:00
添加了设备的Api
This commit is contained in:
parent
2bc9fcc357
commit
e00c53439a
43
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiBatchVM.cs
Normal file
43
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiBatchVM.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
|
||||||
|
{
|
||||||
|
public partial class DeviceApiBatchVM : BaseBatchVM<Device, DeviceApi_BatchEdit>
|
||||||
|
{
|
||||||
|
public DeviceApiBatchVM()
|
||||||
|
{
|
||||||
|
ListVM = new DeviceApiListVM();
|
||||||
|
LinkedVM = new DeviceApi_BatchEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Class to define batch edit fields
|
||||||
|
/// </summary>
|
||||||
|
public class DeviceApi_BatchEdit : BaseVM
|
||||||
|
{
|
||||||
|
[Display(Name = "AutoStart")]
|
||||||
|
public Boolean? AutoStart { get; set; }
|
||||||
|
[Display(Name = "ChangeUpload")]
|
||||||
|
public Boolean? CgUpload { get; set; }
|
||||||
|
[Display(Name = "EnforcePeriodms")]
|
||||||
|
public UInt32? EnforcePeriod { get; set; }
|
||||||
|
[Display(Name = "CmdPeriodms")]
|
||||||
|
public UInt32? CmdPeriod { get; set; }
|
||||||
|
|
||||||
|
protected override void InitVM()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
|
||||||
|
{
|
||||||
|
public partial class DeviceApiTemplateVM : BaseTemplateVM
|
||||||
|
{
|
||||||
|
[Display(Name = "DeviceName")]
|
||||||
|
public ExcelPropety DeviceName_Excel = ExcelPropety.CreateProperty<Device>(x => x.DeviceName);
|
||||||
|
[Display(Name = "Sort")]
|
||||||
|
public ExcelPropety Index_Excel = ExcelPropety.CreateProperty<Device>(x => x.Index);
|
||||||
|
[Display(Name = "Description")]
|
||||||
|
public ExcelPropety Description_Excel = ExcelPropety.CreateProperty<Device>(x => x.Description);
|
||||||
|
public ExcelPropety Driver_Excel = ExcelPropety.CreateProperty<Device>(x => x.DriverId);
|
||||||
|
[Display(Name = "AutoStart")]
|
||||||
|
public ExcelPropety AutoStart_Excel = ExcelPropety.CreateProperty<Device>(x => x.AutoStart);
|
||||||
|
[Display(Name = "ChangeUpload")]
|
||||||
|
public ExcelPropety CgUpload_Excel = ExcelPropety.CreateProperty<Device>(x => x.CgUpload);
|
||||||
|
[Display(Name = "EnforcePeriodms")]
|
||||||
|
public ExcelPropety EnforcePeriod_Excel = ExcelPropety.CreateProperty<Device>(x => x.EnforcePeriod);
|
||||||
|
[Display(Name = "CmdPeriodms")]
|
||||||
|
public ExcelPropety CmdPeriod_Excel = ExcelPropety.CreateProperty<Device>(x => x.CmdPeriod);
|
||||||
|
[Display(Name = "Type")]
|
||||||
|
public ExcelPropety DeviceTypeEnum_Excel = ExcelPropety.CreateProperty<Device>(x => x.DeviceTypeEnum);
|
||||||
|
[Display(Name = "_Admin.Parent")]
|
||||||
|
public ExcelPropety Parent_Excel = ExcelPropety.CreateProperty<Device>(x => x.ParentId);
|
||||||
|
|
||||||
|
protected override void InitVM()
|
||||||
|
{
|
||||||
|
Driver_Excel.DataType = ColumnDataType.ComboBox;
|
||||||
|
Driver_Excel.ListItems = DC.Set<Driver>().GetSelectListItems(Wtm, y => y.DriverName);
|
||||||
|
Parent_Excel.DataType = ColumnDataType.ComboBox;
|
||||||
|
Parent_Excel.ListItems = DC.Set<Device>().GetSelectListItems(Wtm, y => y.DeviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeviceApiImportVM : BaseImportVM<DeviceApiTemplateVM, Device>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiListVM.cs
Normal file
66
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiListVM.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
|
||||||
|
{
|
||||||
|
public partial class DeviceApiListVM : BasePagedListVM<DeviceApi_View, DeviceApiSearcher>
|
||||||
|
{
|
||||||
|
|
||||||
|
protected override IEnumerable<IGridColumn<DeviceApi_View>> InitGridHeader()
|
||||||
|
{
|
||||||
|
return new List<GridColumn<DeviceApi_View>>{
|
||||||
|
this.MakeGridHeader(x => x.DeviceName),
|
||||||
|
this.MakeGridHeader(x => x.Index),
|
||||||
|
this.MakeGridHeader(x => x.Description),
|
||||||
|
this.MakeGridHeader(x => x.DriverName_view),
|
||||||
|
this.MakeGridHeader(x => x.AutoStart),
|
||||||
|
this.MakeGridHeader(x => x.CgUpload),
|
||||||
|
this.MakeGridHeader(x => x.EnforcePeriod),
|
||||||
|
this.MakeGridHeader(x => x.CmdPeriod),
|
||||||
|
this.MakeGridHeader(x => x.DeviceTypeEnum),
|
||||||
|
this.MakeGridHeader(x => x.DeviceName_view),
|
||||||
|
this.MakeGridHeaderAction(width: 200)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IOrderedQueryable<DeviceApi_View> GetSearchQuery()
|
||||||
|
{
|
||||||
|
var query = DC.Set<Device>()
|
||||||
|
.CheckContain(Searcher.DeviceName, x=>x.DeviceName)
|
||||||
|
.CheckEqual(Searcher.DriverId, x=>x.DriverId)
|
||||||
|
.Select(x => new DeviceApi_View
|
||||||
|
{
|
||||||
|
ID = x.ID,
|
||||||
|
DeviceName = x.DeviceName,
|
||||||
|
Index = x.Index,
|
||||||
|
Description = x.Description,
|
||||||
|
DriverName_view = x.Driver.DriverName,
|
||||||
|
AutoStart = x.AutoStart,
|
||||||
|
CgUpload = x.CgUpload,
|
||||||
|
EnforcePeriod = x.EnforcePeriod,
|
||||||
|
CmdPeriod = x.CmdPeriod,
|
||||||
|
DeviceTypeEnum = x.DeviceTypeEnum,
|
||||||
|
DeviceName_view = x.Parent.DeviceName,
|
||||||
|
})
|
||||||
|
.OrderBy(x => x.ID);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeviceApi_View : Device{
|
||||||
|
[Display(Name = "DriverName")]
|
||||||
|
public String DriverName_view { get; set; }
|
||||||
|
[Display(Name = "DeviceName")]
|
||||||
|
public String DeviceName_view { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
|
||||||
|
{
|
||||||
|
public partial class DeviceApiSearcher : BaseSearcher
|
||||||
|
{
|
||||||
|
[Display(Name = "DeviceName")]
|
||||||
|
public String DeviceName { get; set; }
|
||||||
|
public Guid? DriverId { get; set; }
|
||||||
|
|
||||||
|
protected override void InitVM()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
41
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiVM.cs
Normal file
41
IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiVM.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.ViewModel.BasicData.DeviceVMs
|
||||||
|
{
|
||||||
|
public partial class DeviceApiVM : BaseCRUDVM<Device>
|
||||||
|
{
|
||||||
|
|
||||||
|
public DeviceApiVM()
|
||||||
|
{
|
||||||
|
SetInclude(x => x.Driver);
|
||||||
|
SetInclude(x => x.Parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void InitVM()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DoAdd()
|
||||||
|
{
|
||||||
|
base.DoAdd();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DoEdit(bool updateAllFields = false)
|
||||||
|
{
|
||||||
|
base.DoEdit(updateAllFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DoDelete()
|
||||||
|
{
|
||||||
|
base.DoDelete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
180
IoTGateway/Areas/BasicData/Controllers/DeviceApiController.cs
Normal file
180
IoTGateway/Areas/BasicData/Controllers/DeviceApiController.cs
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using WalkingTec.Mvvm.Mvc;
|
||||||
|
using IoTGateway.ViewModel.BasicData.DeviceVMs;
|
||||||
|
using IoTGateway.Model;
|
||||||
|
|
||||||
|
|
||||||
|
namespace IoTGateway.Controllers
|
||||||
|
{
|
||||||
|
[Area("BasicData")]
|
||||||
|
[AuthorizeJwtWithCookie]
|
||||||
|
[ActionDescription("设备维护Api")]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/Device")]
|
||||||
|
public partial class DeviceApiController : BaseApiController
|
||||||
|
{
|
||||||
|
[ActionDescription("Sys.Search")]
|
||||||
|
[HttpPost("Search")]
|
||||||
|
public IActionResult Search(DeviceApiSearcher searcher)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiListVM>(passInit: true);
|
||||||
|
vm.Searcher = searcher;
|
||||||
|
return Content(vm.GetJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.Get")]
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public DeviceApiVM Get(string id)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiVM>(id);
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.Create")]
|
||||||
|
[HttpPost("Add")]
|
||||||
|
public IActionResult Add(DeviceApiVM vm)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.DoAdd();
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Ok(vm.Entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.Edit")]
|
||||||
|
[HttpPut("Edit")]
|
||||||
|
public IActionResult Edit(DeviceApiVM vm)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.DoEdit(false);
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Ok(vm.Entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("BatchDelete")]
|
||||||
|
[ActionDescription("Sys.Delete")]
|
||||||
|
public IActionResult BatchDelete(string[] ids)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiBatchVM>();
|
||||||
|
if (ids != null && ids.Count() > 0)
|
||||||
|
{
|
||||||
|
vm.Ids = ids;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
if (!ModelState.IsValid || !vm.DoBatchDelete())
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Ok(ids.Count());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[ActionDescription("Sys.Export")]
|
||||||
|
[HttpPost("ExportExcel")]
|
||||||
|
public IActionResult ExportExcel(DeviceApiSearcher searcher)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiListVM>();
|
||||||
|
vm.Searcher = searcher;
|
||||||
|
vm.SearcherMode = ListVMSearchModeEnum.Export;
|
||||||
|
return vm.GetExportData();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.CheckExport")]
|
||||||
|
[HttpPost("ExportExcelByIds")]
|
||||||
|
public IActionResult ExportExcelByIds(string[] ids)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiListVM>();
|
||||||
|
if (ids != null && ids.Count() > 0)
|
||||||
|
{
|
||||||
|
vm.Ids = new List<string>(ids);
|
||||||
|
vm.SearcherMode = ListVMSearchModeEnum.CheckExport;
|
||||||
|
}
|
||||||
|
return vm.GetExportData();
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.DownloadTemplate")]
|
||||||
|
[HttpGet("GetExcelTemplate")]
|
||||||
|
public IActionResult GetExcelTemplate()
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<DeviceApiImportVM>();
|
||||||
|
var qs = new Dictionary<string, string>();
|
||||||
|
foreach (var item in Request.Query.Keys)
|
||||||
|
{
|
||||||
|
qs.Add(item, Request.Query[item]);
|
||||||
|
}
|
||||||
|
vm.SetParms(qs);
|
||||||
|
var data = vm.GenerateTemplate(out string fileName);
|
||||||
|
return File(data, "application/vnd.ms-excel", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ActionDescription("Sys.Import")]
|
||||||
|
[HttpPost("Import")]
|
||||||
|
public ActionResult Import(DeviceApiImportVM vm)
|
||||||
|
{
|
||||||
|
if (vm!=null && (vm.ErrorListVM.EntityList.Count > 0 || !vm.BatchSaveData()))
|
||||||
|
{
|
||||||
|
return BadRequest(vm.GetErrorJson());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Ok(vm?.EntityList?.Count ?? 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("GetDrivers")]
|
||||||
|
public ActionResult GetDrivers()
|
||||||
|
{
|
||||||
|
return Ok(DC.Set<Driver>().GetSelectListItems(Wtm, x => x.DriverName));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("GetDevices")]
|
||||||
|
public ActionResult GetDevices()
|
||||||
|
{
|
||||||
|
return Ok(DC.Set<Device>().GetSelectListItems(Wtm, x => x.DeviceName));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user