using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { public class TprdProductController : BaseController { private readonly ILogger _logger; private readonly ITprdProductService _TprdProductService; /// /// 构造函数 /// /// /// public TprdProductController(ITprdProductService TprdProductService, ILogger logger) { _TprdProductService = TprdProductService; _logger = logger; } /// /// 通过ID获取器具信息 /// /// /// [HttpGet("GetProductAsync/{id}")] public async Task GetProductAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TprdProductService.GetByIdAsync(id); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有器具 /// /// [HttpGet("GetProductsAsync")] public async Task GetProductsAsync() { try { var contentList = await _TprdProductService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过各个条件查询器具 /// /// /// [HttpPost("GetProductsByAsync")] public async Task GetProductsByAsync(TprdProductSearchModel searchModel) { if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TprdProductService.GetConditionAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取器具设备数 /// /// /// [HttpGet("GetDeviceCountByAsync/{storeCode}")] [AllowAnonymous] public async Task GetDeviceCountByAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var count = await _TprdProductService.GetDeviceCountByAsync(storeCode); return new ApiResult(count); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取异常器具设备数 /// /// /// [HttpGet("GetAlertDeviceCountByAsync/{storeCode}")] [AllowAnonymous] public async Task GetAlertDeviceCountByAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var count = await _TprdProductService.GetAlertDeviceCountByAsync(storeCode); return new ApiResult(count); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取异常器具设备列表 /// /// /// [HttpGet("GetAlertProductsByAsync/{storeCode}")] [AllowAnonymous] public async Task GetAlertProductsByAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var items = await _TprdProductService.GetAlertProductsByAsync(storeCode); return new ApiResult>(items); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取超过有效期器具列表 /// /// /// [HttpGet("GetValiDateProductsByAsync/{storeCode}")] [AllowAnonymous] public async Task GetValiDateProductsByAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var items = await _TprdProductService.GetValiDateProductsByAsync(storeCode); return new ApiResult>(items); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过code取异常设备信息 /// /// /// [HttpGet("GetAlertProductByCodeAsync/{code}")] [AllowAnonymous] public async Task GetAlertProductByCodeAsync(Guid code) { if (Guid.Empty.Equals(code) ) { return new ApiResult(ReturnCode.ArgsError); } try { var items = await _TprdProductService.GetAlertProductByCodeAsync(code); return new ApiResult(items); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过code取过期设备信息 /// /// /// [HttpGet("GetValiDateProductByCodeAsync/{code}")] [AllowAnonymous] public async Task GetValiDateProductByCodeAsync(Guid code) { if (Guid.Empty.Equals(code)) { return new ApiResult(ReturnCode.ArgsError); } try { var items = await _TprdProductService.GetValiDateProductByCodeAsync(code); return new ApiResult(items); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过网点取设备及运行的数据 /// /// /// [HttpPost("GetProductWithDataByAsync")] [AllowAnonymous] public async Task GetProductWithDataByAsync(TprdProductWithDataSearchModel searchModel) { if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TprdProductService.GetProductWithDataByAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 根据网点区域取设备 /// /// /// [HttpPost("GetDeviceByAreaCode")] [AllowAnonymous] public async Task GetDeviceByAreaCode(TprdDeviceByAreaSearchModel searchModel) { if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _TprdProductService.GetDeviceByAreaCode(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建器具 /// /// /// [HttpPost("CreateProductAsync")] public async Task CreateProductAsync(TprdProductViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TprdProductService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 扫巡二维码获取器具 /// /// /// /// [HttpGet("GetProductByQRCodeAsync/{QRCode}/{storeCode}")] public async Task GetProductByQRCodeAsync(string QRCode, string storeCode) { try { if (string.IsNullOrEmpty(QRCode) || string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.GeneralError); } TprdProductViewModel item = await _TprdProductService.GetProductByQRCodeAsync(QRCode, storeCode); return new ApiResult(item); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 删除器具 /// /// /// [HttpDelete("DeleteProductAsync/{id}")] public async Task DeleteProductAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _TprdProductService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新器具 /// /// /// /// [HttpPut("UpdateProductAsync/{id}")] public async Task UpdateProductAsync(Guid id, TprdProductUpdateModel updateModel) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _TprdProductService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }