ningshuxia
2022-12-01 ad494f13d2ddf31f142cf7fb908b3a6e90395a1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
{
    /// <summary>
    /// Meter
    /// </summary>
    [Route("Product/Meter/Mobile")]
    [ApiDescriptionSettings("Product", Name = "仪器仪表", Order = 598)]
    public class Meter_MobileController : IDynamicApiController
    {
 
        /// <summary>
        /// 通过 CorpID 获取(手机)
        /// </summary>
        [Route("GetByCorpID@V1.0")]
        [HttpGet]
        public List<MeterMobileDto> 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<MeterMobileDto>();
                //流量计
                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;
        }
 
        /// <summary>
        /// 通过 Catalog 获取(手机)
        /// </summary>
        [Route("GetByCatalog@V1.0")]
        [HttpGet]
        public List<MeterMobileDto> 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<MeterMobileDto>();
                
                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;
 
        }
 
    }
}