using Microsoft.AspNetCore.Mvc;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.AspNetCore.Http.Extensions;
using IStation.Untity;
using Furion.DynamicApiController;
using System.ComponentModel.DataAnnotations;
using Mapster;
namespace IStation.Application
{
///
/// Meter
///
[Route("Product/Meter/Mobile")]
[ApiDescriptionSettings("Product", Name = "仪器仪表", Order = 598)]
public class Meter_MobileController : IDynamicApiController
{
///
/// 通过 CorpID 获取(手机)
///
[Route("GetByCorpID@V1.0")]
[HttpGet]
public List GetByCorpID([FromQuery][Required] CorpIDInput input)
{
var corpId = input.CorpID;
var cacheKey = $"Product_Meter_Mobile_GetByCorpID_{corpId}";
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
{
var productList = new Service.Product().GetByCorpID(corpId);
if (productList == null || productList.Count < 1)
return default;
var vmCacheList = new List();
//流量计
var flowMeterList = productList.Where(x => x.Catalog == Product.Catalog_LiuLiangJi).OrderBy(x => x.SortCode).ToList();
if (flowMeterList != null && flowMeterList.Count > 0)
{
vmCacheList.AddRange(flowMeterList.Select(x=>new MeterMobileDto(x)));
}
//压力计
var pressureMeterList = productList.Where(x => x.Catalog == Product.Catalog_YaLiJi).OrderBy(x => x.SortCode).ToList();
if (pressureMeterList != null && pressureMeterList.Count > 0)
{
vmCacheList.AddRange(pressureMeterList.Select(x => new MeterMobileDto(x)));
}
//功率表
var powerMeterList = productList.Where(x => x.Catalog == Product.Catalog_GongLvBiao).OrderBy(x => x.SortCode).ToList();
if (powerMeterList != null && powerMeterList.Count > 0)
{
vmCacheList.AddRange(powerMeterList.Select(x => new MeterMobileDto(x)));
}
//水质仪
var qualityMeterList = productList.Where(x => x.Catalog == Product.Catalog_ShuiZhiYi).OrderBy(x => x.SortCode).ToList();
if (qualityMeterList != null && qualityMeterList.Count > 0)
{
vmCacheList.AddRange(qualityMeterList.Select(x => new MeterMobileDto(x)));
}
return vmCacheList;
}, CacheHelper.CacheLevel1);
return vm_list;
}
///
/// 通过 Catalog 获取(手机)
///
[Route("GetByCatalog@V1.0")]
[HttpGet]
public List GetByCatalog([FromQuery][Required] CatalogUnderCorpInput input)
{
var corpId = input.CorpID;
var catalog = input.Catalog;
var cacheKey = $"Product_Meter_Mobile_GetByCatalog_{corpId}_{catalog}";
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
{
var productList = new Service.Product().GetByCorpID(corpId);
if (productList == null || productList.Count < 1)
return default;
var vmCacheList = new List();
var meterList = productList.Where(x => x.Catalog == catalog).OrderBy(x => x.SortCode).ToList();
if (meterList != null && meterList.Count > 0)
{
vmCacheList.AddRange(meterList.Select(x => new MeterMobileDto(x)));
}
return vmCacheList;
}, CacheHelper.CacheLevel2);
return vm_list;
}
}
}