123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- 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<TprdProductController> _logger;
- private readonly ITprdProductService _TprdProductService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TprdProductService"></param>
- /// <param name="logger"></param>
- public TprdProductController(ITprdProductService TprdProductService, ILogger<TprdProductController> logger)
- {
- _TprdProductService = TprdProductService;
- _logger = logger;
- }
- /// <summary>
- /// 通过ID获取器具信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetProductAsync/{id}")]
- public async Task<ApiResult> GetProductAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TprdProductService.GetByIdAsync(id);
- return new ApiResult<TprdProductViewModel>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有器具
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetProductsAsync")]
- public async Task<ApiResult> GetProductsAsync()
- {
- try
- {
- var contentList = await _TprdProductService.GetAllAsync();
- return new ApiResult<IEnumerable<TprdProductViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过各个条件查询器具
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetProductsByAsync")]
- public async Task<ApiResult> 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<IEnumerable<TprdProductViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取器具设备数
- /// </summary>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetDeviceCountByAsync/{storeCode}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetDeviceCountByAsync(string storeCode)
- {
- if (string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var count = await _TprdProductService.GetDeviceCountByAsync(storeCode);
- return new ApiResult<int>(count);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取异常器具设备数
- /// </summary>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetAlertDeviceCountByAsync/{storeCode}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetAlertDeviceCountByAsync(string storeCode)
- {
- if (string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var count = await _TprdProductService.GetAlertDeviceCountByAsync(storeCode);
- return new ApiResult<int>(count);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取异常器具设备列表
- /// </summary>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetAlertProductsByAsync/{storeCode}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetAlertProductsByAsync(string storeCode)
- {
- if (string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var items = await _TprdProductService.GetAlertProductsByAsync(storeCode);
- return new ApiResult<IEnumerable<TprdProductViewModel>>(items);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取超过有效期器具列表
- /// </summary>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetValiDateProductsByAsync/{storeCode}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetValiDateProductsByAsync(string storeCode)
- {
- if (string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var items = await _TprdProductService.GetValiDateProductsByAsync(storeCode);
- return new ApiResult<IEnumerable<TprdProductViewModel>>(items);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过code取异常设备信息
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- [HttpGet("GetAlertProductByCodeAsync/{code}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetAlertProductByCodeAsync(Guid code)
- {
- if (Guid.Empty.Equals(code) )
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var items = await _TprdProductService.GetAlertProductByCodeAsync(code);
- return new ApiResult<TprdProductViewModel>(items);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过code取过期设备信息
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- [HttpGet("GetValiDateProductByCodeAsync/{code}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetValiDateProductByCodeAsync(Guid code)
- {
- if (Guid.Empty.Equals(code))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var items = await _TprdProductService.GetValiDateProductByCodeAsync(code);
- return new ApiResult<TprdProductViewModel>(items);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过网点取设备及运行的数据
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetProductWithDataByAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> 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<IEnumerable<AllProductWithDevViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 根据网点区域取设备
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDeviceByAreaCode")]
- [AllowAnonymous]
- public async Task<ApiResult> 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<IEnumerable<TprdDeviceByAreaViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建器具
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateProductAsync")]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 扫巡二维码获取器具
- /// </summary>
- /// <param name="QRCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetProductByQRCodeAsync/{QRCode}/{storeCode}")]
- public async Task<ApiResult> 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<TprdProductViewModel>(item);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 删除器具
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteProductAsync/{id}")]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 更新器具
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateProductAsync/{id}")]
- public async Task<ApiResult> 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);
- }
- }
- }
|