wangzelong
2022-09-22 a5d1c559861e75db9568cb0a04d23b229aa66fc0
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
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>
    /// FlowMeter
    /// </summary>
    [Route("Dma/FlowMeter/Logic")]
    [ApiDescriptionSettings("Dma", Name = "流量计(业务)", Order = 70)]
    public class FlowMeter_LogicController : IDynamicApiController
    {
 
        /// <summary>
        /// 通过 CorpID 获取列表(业务)
        /// </summary>
        [Route("GetListByCorpID@V1.0")]
        [HttpGet]
        public List<FlowMeterLogicDto> GetListByCorpID([FromQuery][Required] CorpIDInput input)
        {
            var corpId = input.CorpID;
            var cacheKey = $"Dma_FlowMeter_Logic_GetListByCorpID_{corpId}";
 
            var vmList = MemoryCacheHelper.GetSet(cacheKey, () =>
            {
                var siteList=new Service.DmaSite().GetByCorpID(corpId);
                if (siteList == null || siteList.Count < 1)
                    return default;
                var serviceBinding = new Service.DmaSiteBinding();
                var serviceProduct = new Service.Product();
                var serviceManu = new Service.Manufacturer();
                var serviceMapping = new Service.DmaSiteMapping();
                var serviceDma = new Service.DmaArea();
                var vmCacheList = new List<FlowMeterLogicDto>();
                foreach (var site in siteList)
                {
                    var binding = serviceBinding.GetUseByDmaSiteID(site.CorpID, site.ID);
                    if (binding == null)
                        continue;
                    var product = serviceProduct.GetByID(binding.CorpID, binding.FlowMeterID);
                    if (product == null)
                        continue;
                    var manu = serviceManu.GetByID(product.CorpID,product.ManufacturerID);
                    var vm = new FlowMeterLogicDto(product,manu?.Name);
                    vmCacheList.Add(vm);
                    var mappingList = serviceMapping.GetByDmaSiteID(site.CorpID,site.ID);
                    if (mappingList != null && mappingList.Count > 0)
                    {
                        var flowIn = mappingList.Find(t=>t.Direction==Model.eDmaDirection.FlowIn);
                        if (flowIn != null)
                        {
                            var flowInDma = serviceDma.GetByID(flowIn.CorpID,flowIn.DmaAreaID);
                            vm.FlowIn = flowInDma?.Name;
                        }
                        var flowOut = mappingList.Find(t=>t.Direction==Model.eDmaDirection.FlowOut);
                        if (flowOut != null)
                        {
                            var flowOutDma = serviceDma.GetByID(flowOut.CorpID, flowOut.DmaAreaID);
                            vm.FlowOut = flowOutDma?.Name;
                        }
                    }
                }
                return vmCacheList;
            }, CacheHelper.CacheLevel2);
 
            return vmList;
        }
 
 
 
    }
}