using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model.ViewModel.DEV; using Ropin.Inspection.Model; using Ropin.Inspection.Service.DEV.Interface; using System.Threading.Tasks; using System; using log4net; using Ropin.Inspection.Model.SearchModel.DEV; namespace Ropin.Inspection.Api.Controllers.DEV { public class DEVCmdController : BaseController { private static readonly ILog log = LogManager.GetLogger(typeof(DEVCmdController)); private readonly IDEVCmdService _repository; /// /// 构造函数 /// /// public DEVCmdController(IDEVCmdService repository) { _repository = repository; } #region 命令 /// /// 创建命令信息 /// /// /// [HttpPost("CreateCmdAsync")] public async Task CreateCmdAsync(DevCmdViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _repository.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除命令信息 /// /// /// [HttpDelete("DeleteCmdAsync/{id}")] public async Task DeleteCmdAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 禁用命令信息 /// /// /// [HttpDelete("DisableCmdAsync/{id}")] public async Task DisableCmdAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.DisableAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新命令信息 /// /// /// /// [HttpPut("UpdateCmdAsync/{id}")] [AllowAnonymous] public async Task UpdateCmdAsync(string id, DevCmdViewModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 获取命令信息 /// /// [HttpPost("GetCmdConditionAsync")] [AllowAnonymous] public async Task GetCmdConditionAsync(DevCmdSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _repository.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过id获取命令信息 /// /// [HttpPost("GetCmdByIDAsync")] [AllowAnonymous] public async Task GetCmdByIDAsync(string Id) { if (string.IsNullOrEmpty(Id)) { return new ApiResult(ReturnCode.ArgsError); } try { DevCmdViewModel data = new DevCmdViewModel(); data = await _repository.GetByIdAsync(Id); return new ApiResult(data); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } #endregion #region 指令 /// /// 创建指令信息 /// /// /// [HttpPost("InstructionCreateOneAsync")] public async Task InstructionCreateOneAsync(DevInstructionViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _repository.InstructionCreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除指令信息 /// /// /// [HttpDelete("DeleteInstructionAsync/{id}")] public async Task DeleteInstructionAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.InstructionDeleteAsync(id,true); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 禁用指令信息 /// /// /// [HttpDelete("DisableInstructionAsync/{id}")] public async Task DisableInstructionAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.InstructionDeleteAsync(id,false); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新指令信息 /// /// /// /// [HttpPut("InstructionUpdateAsync/{id}")] [AllowAnonymous] public async Task InstructionUpdateAsync(string id, DevInstructionViewModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.InstructionUpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 获取指令信息 /// /// [HttpPost("GetInstructionConditionAsync")] [AllowAnonymous] public async Task GetInstructionConditionAsync(DevInstructionSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _repository.GetInstructionConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过id获取指令信息 /// /// [HttpPost("GetInstructionByIdAsync")] [AllowAnonymous] public async Task GetInstructionByIdAsync(string Id) { if (string.IsNullOrEmpty(Id)) { return new ApiResult(ReturnCode.ArgsError); } try { DevInstructionViewModel data = new DevInstructionViewModel(); data = await _repository.GetInstructionByIdAsync(Id); return new ApiResult(data); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } #endregion #region 命令-指令 /// /// 创建命令-指令信息 /// /// /// [HttpPost("CmdInstructionCreateOneAsync")] public async Task CmdInstructionCreateOneAsync(DevCmdInstructionViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _repository.CmdInstructionCreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除命令-指令信息 /// /// /// [HttpDelete("CmdInstructionDeleteAsync/{id}")] public async Task CmdInstructionDeleteAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.CmdInstructionDeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新命令-指令信息 /// /// /// /// [HttpPut("CmdInstructionUpdateAsync/{id}")] [AllowAnonymous] public async Task CmdInstructionUpdateAsync(string id, DevCmdInstructionViewModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.CmdInstructionUpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 获取命令-指令信息 /// /// [HttpPost("GetCmdInstructionConditionAsync")] [AllowAnonymous] public async Task GetCmdInstructionConditionAsync(DevCmdInstructionSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _repository.GetCmdInstructionConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过id获取命令-指令信息 /// /// [HttpPost("GetCmdInstructionByIdAsync")] [AllowAnonymous] public async Task GetCmdInstructionByIdAsync(string Id) { if (string.IsNullOrEmpty(Id)) { return new ApiResult(ReturnCode.ArgsError); } try { DevCmdInstructionViewModel data = new DevCmdInstructionViewModel(); data = await _repository.GetCmdInstructionByIdAsync(Id); return new ApiResult(data); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } #endregion } }