using log4net; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Api.Controllers.LGS; using Ropin.Inspection.Model.SearchModel.LGS; using Ropin.Inspection.Model.ViewModel.LGS; using Ropin.Inspection.Model; using Ropin.Inspection.Service.LGS.Interface; using Ropin.Inspection.Service.VMC.Interface; using System.Threading.Tasks; using System; using Ropin.Inspection.Model.ViewModel.VMC; using Ropin.Inspection.Model.SearchModel.VMC; namespace Ropin.Inspection.Api.Controllers.VMC { public class VmcCameraTemplateController : BaseController { private readonly IVmcCameraTemplateService _repository; private static readonly ILog log = LogManager.GetLogger(typeof(VmcCameraTemplateController)); /// /// 构造函数 /// /// public VmcCameraTemplateController(IVmcCameraTemplateService repository) { _repository = repository; } /// /// 创建模板 /// /// /// [HttpPost("CreateTemplateAsync")] public async Task CreateTemplateAsync(VmcCameraTemplateViewModel 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("DeleteTemplateAsync/{id}")] public async Task DeleteTemplateAsync(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); } /// /// 禁用模板 /// /// /// [HttpPut("ForbiddenTemplateAsync/{id}")] public async Task ForbiddenTemplateAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.ForbiddenAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新模板 /// /// /// /// [HttpPut("UpdateTemplateAsync/{id}")] [AllowAnonymous] public async Task UpdateTemplateAsync(string id, VmcCameraTemplateViewModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _repository.UpdateAsync(updateModel, id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 获取模板列表 /// /// [HttpPost("PageAsync")] [AllowAnonymous] public async Task PageAsync(VmcCameraTemplateSearch 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获取大模板详情 /// /// [HttpGet("DetailsAsync")] [AllowAnonymous] public async Task DetailsAsync(string Id) { if (string.IsNullOrEmpty(Id)) { return new ApiResult(ReturnCode.ArgsError); } try { VmcCameraTemplateViewModel data = await _repository.GetByIdAsync(Id); return new ApiResult(data); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } } }