diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiBatchVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiBatchVM.cs new file mode 100644 index 0000000..182e835 --- /dev/null +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiBatchVM.cs @@ -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 + { + public DeviceApiBatchVM() + { + ListVM = new DeviceApiListVM(); + LinkedVM = new DeviceApi_BatchEdit(); + } + + } + + /// + /// Class to define batch edit fields + /// + 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() + { + } + + } + +} diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiImportVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiImportVM.cs new file mode 100644 index 0000000..37984cf --- /dev/null +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiImportVM.cs @@ -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(x => x.DeviceName); + [Display(Name = "Sort")] + public ExcelPropety Index_Excel = ExcelPropety.CreateProperty(x => x.Index); + [Display(Name = "Description")] + public ExcelPropety Description_Excel = ExcelPropety.CreateProperty(x => x.Description); + public ExcelPropety Driver_Excel = ExcelPropety.CreateProperty(x => x.DriverId); + [Display(Name = "AutoStart")] + public ExcelPropety AutoStart_Excel = ExcelPropety.CreateProperty(x => x.AutoStart); + [Display(Name = "ChangeUpload")] + public ExcelPropety CgUpload_Excel = ExcelPropety.CreateProperty(x => x.CgUpload); + [Display(Name = "EnforcePeriodms")] + public ExcelPropety EnforcePeriod_Excel = ExcelPropety.CreateProperty(x => x.EnforcePeriod); + [Display(Name = "CmdPeriodms")] + public ExcelPropety CmdPeriod_Excel = ExcelPropety.CreateProperty(x => x.CmdPeriod); + [Display(Name = "Type")] + public ExcelPropety DeviceTypeEnum_Excel = ExcelPropety.CreateProperty(x => x.DeviceTypeEnum); + [Display(Name = "_Admin.Parent")] + public ExcelPropety Parent_Excel = ExcelPropety.CreateProperty(x => x.ParentId); + + protected override void InitVM() + { + Driver_Excel.DataType = ColumnDataType.ComboBox; + Driver_Excel.ListItems = DC.Set().GetSelectListItems(Wtm, y => y.DriverName); + Parent_Excel.DataType = ColumnDataType.ComboBox; + Parent_Excel.ListItems = DC.Set().GetSelectListItems(Wtm, y => y.DeviceName); + } + + } + + public class DeviceApiImportVM : BaseImportVM + { + + } + +} diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiListVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiListVM.cs new file mode 100644 index 0000000..a072a6c --- /dev/null +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiListVM.cs @@ -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 + { + + protected override IEnumerable> InitGridHeader() + { + return new List>{ + 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 GetSearchQuery() + { + var query = DC.Set() + .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; } + + } +} diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiSearcher.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiSearcher.cs new file mode 100644 index 0000000..35dc8c6 --- /dev/null +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiSearcher.cs @@ -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() + { + } + + } +} diff --git a/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiVM.cs b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiVM.cs new file mode 100644 index 0000000..5a25bb7 --- /dev/null +++ b/IoTGateway.ViewModel/BasicData/DeviceVMs/DeviceApiVM.cs @@ -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 + { + + 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(); + } + } +} diff --git a/IoTGateway/Areas/BasicData/Controllers/DeviceApiController.cs b/IoTGateway/Areas/BasicData/Controllers/DeviceApiController.cs new file mode 100644 index 0000000..ef39cec --- /dev/null +++ b/IoTGateway/Areas/BasicData/Controllers/DeviceApiController.cs @@ -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(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(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(); + 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(); + vm.Searcher = searcher; + vm.SearcherMode = ListVMSearchModeEnum.Export; + return vm.GetExportData(); + } + + [ActionDescription("Sys.CheckExport")] + [HttpPost("ExportExcelByIds")] + public IActionResult ExportExcelByIds(string[] ids) + { + var vm = Wtm.CreateVM(); + if (ids != null && ids.Count() > 0) + { + vm.Ids = new List(ids); + vm.SearcherMode = ListVMSearchModeEnum.CheckExport; + } + return vm.GetExportData(); + } + + [ActionDescription("Sys.DownloadTemplate")] + [HttpGet("GetExcelTemplate")] + public IActionResult GetExcelTemplate() + { + var vm = Wtm.CreateVM(); + var qs = new Dictionary(); + 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().GetSelectListItems(Wtm, x => x.DriverName)); + } + + [HttpGet("GetDevices")] + public ActionResult GetDevices() + { + return Ok(DC.Set().GetSelectListItems(Wtm, x => x.DeviceName)); + } + + } +} diff --git a/IoTGateway/data/iotgateway.db b/IoTGateway/data/iotgateway.db index d538f51..efd69cd 100644 Binary files a/IoTGateway/data/iotgateway.db and b/IoTGateway/data/iotgateway.db differ