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; using Microsoft.AspNetCore.Http; using Furion.DependencyInjection; using Microsoft.AspNetCore.Authorization; using Furion.DataEncryption; using Furion.FriendlyException; namespace IStation.Application { /// /// 机泵 /// [AllowAnonymous] [Route("LargeScreen/Demo/EnginePump")] [ApiDescriptionSettings("LargeScreen", Name = "Demo(机泵)", Order = 666)] public class DemoEnginePump_Controller : IDynamicApiController, ITransient { private readonly IHttpContextAccessor _httpContextAccessor; /// /// /// public DemoEnginePump_Controller(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } /// /// 获取机组主页信息 (左上部分) /// /// 机组ID [Route("GetLeftTopInfo")] [HttpGet] public DemoEnginePumpLeftTopInfoDto GetLeftTopInfo(long ProductID) { var pumpInfo = new DemoEnginePumpLeftTopInfoDto(); var r = new Random(); pumpInfo.ID = ProductID; pumpInfo.CorpID = 2; pumpInfo.Name = "一号机泵"; pumpInfo.Manufacturer = "KSB"; pumpInfo.Rated_Q = 80; pumpInfo.Unit_Rated_Q = "m³/h"; pumpInfo.MotorPower = 45; pumpInfo.Unit_MotorPower = "Kw"; pumpInfo.Rated_H = 50; pumpInfo.Unit_Rated_H = "m"; pumpInfo.UWP = r.Next(200, 210); pumpInfo.Unit_UWP = "kW/千吨水"; pumpInfo.RunDurationTime = string.Format("{0}小时{1}分钟", r.Next(1, 8), r.Next(1, 55)); pumpInfo.SafeDurationTime = string.Format("{0}小时 ", r.Next(100, 188) + 1000); return pumpInfo; } /// /// 获取机组供水数据分析数据 (左中部分) /// /// 机组ID /// 汇总类型(1按日 2 按周 3 按月 4 按年) [Route("GetLeftMiddleInfo")] [HttpGet] public DemoEnginePumpLeftMiddleInfoDto GetLeftMiddleInfo(long ProductID, int StaticType) { var r = new Random(); var info = new DemoEnginePumpLeftMiddleInfoDto(); info.TotalSupplyWater = r.Next(21500, 22350); List info_list = new List(); if (StaticType == 1 || StaticType <= 0) { info.CurrentValueLabel = "昨日供水量"; info.CurrentSupplyWater = r.Next(760, 780); for (DateTime day = DateTime.Today.AddMonths(-1); day < DateTime.Today; day = day.AddDays(1)) { DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto(); item.Label = day.ToString("yyyy-MM-dd"); item.SupplyWater = r.Next(60, 80); item.EnergyConsumption = r.Next(80, 95); info_list.Add(item); } info.Details = info_list; } else if (StaticType == 3 || StaticType == 2) {//2 按周 3 按月 info.CurrentValueLabel = "本月供水量"; info.CurrentSupplyWater = r.Next(760, 780) * 20; for (int month = 1; month < DateTime.Today.Month; month = month + 1) { DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto(); item.Label = month.ToString(); item.SupplyWater = r.Next(60, 80) * 30; item.EnergyConsumption = r.Next(20, 35) * 30; info_list.Add(item); } info.Details = info_list; } else {//4 按年 info.CurrentValueLabel = "今年供水量"; info.CurrentSupplyWater = r.Next(760, 780) * 300; for (int year = 1; year < 4; year = year + 1) { DemoEnginePumpLeftMiddleItemInfoDto item = new DemoEnginePumpLeftMiddleItemInfoDto(); item.Label = (DateTime.Today.Year - 3 + year).ToString(); item.SupplyWater = r.Next(60, 80) * 270; item.EnergyConsumption = r.Next(20, 35) * 270; info_list.Add(item); } info.Details = info_list; } return info; } /// /// 获取机组性能曲线数据 (左下部分) /// /// 机组ID [Route("GetLeftBottomInfo")] [HttpGet] public DemoEnginePumpLeftBottomInfoDto GetLeftBottomInfo(long ProductID) { var r = new Random(); var ratedParas = new Model.GroupPoint(); ratedParas.Q = 1200; ratedParas.H = 50; ratedParas.E = 88; ratedParas.P = Common.PumpParaHelper.CalculateP(ratedParas.Q, ratedParas.H, ratedParas.E); List grp_points = new List(); Common.DimensionlessCurvesHelper.CalcPoints(ratedParas, 1450, ref grp_points, true, 1); var info = new DemoEnginePumpLeftBottomInfoDto(); info.CurveInfoQH = (from x in grp_points select new Model.CurvePoint(x.Q, x.H)).ToList(); info.CurveInfoQE = (from x in grp_points select new Model.CurvePoint(x.Q, x.E)).ToList(); info.CurveInfoQP = (from x in grp_points select new Model.CurvePoint(x.Q, x.P)).ToList(); info.HistoryRunPointQH = new List(); info.HistoryRunPointQE = new List(); info.HistoryRunPointQP = new List(); for (int i = 0; i < 100; i++) { var q = r.Next(800, 1200) * ratedParas.Q / 1000.0; var h = Model.FitCurveHelper.GetFitPointY(info.CurveInfoQH, q) * 0.95; var e = Model.FitCurveHelper.GetFitPointY(info.CurveInfoQE, q) * 0.95; var p = Common.PumpParaHelper.CalculateP(q, h, e); info.HistoryRunPointQH.Add(new Model.CurvePoint(q, h)); info.HistoryRunPointQE.Add(new Model.CurvePoint(q, e)); info.HistoryRunPointQP.Add(new Model.CurvePoint(q, p)); } return info; } /// /// 获取首页报警和信息公告(中间底部) /// /// 机泵ID /// 信息类型(1公告信息 2报警信息) [Route("GetCenterBottomInfo")] [HttpGet] public List GetCenterBottomInfo(long ProductID, int InfoType) { var r = new Random(); List info_list = new List(); if (InfoType == 1) { DemoEnginePumpCenterBottomItemInfoDto item1 = new DemoEnginePumpCenterBottomItemInfoDto(); item1.Title = "大修"; item1.UserName = "管理员"; item1.Content = "2020年8月26日,控江路管道维修抢修完成。"; info_list.Add(item1); DemoEnginePumpCenterBottomItemInfoDto item2 = new DemoEnginePumpCenterBottomItemInfoDto(); item2.Title = "维护"; item2.UserName = "管理员"; item2.Content = "2020年9月11日,二号泵电机振动过大,进行大修。"; info_list.Add(item2); DemoEnginePumpCenterBottomItemInfoDto item3 = new DemoEnginePumpCenterBottomItemInfoDto(); item3.Title = "故障"; item3.UserName = "管理员"; item3.Content = "2020年9月22日,发生振动。"; info_list.Add(item2); } else { DemoEnginePumpCenterBottomItemInfoDto item1 = new DemoEnginePumpCenterBottomItemInfoDto(); item1.Title = "二号泵"; item1.UserName = "李三林"; item1.Content = "2020年9月20日 12时30分,漏水严重。"; info_list.Add(item1); DemoEnginePumpCenterBottomItemInfoDto item2 = new DemoEnginePumpCenterBottomItemInfoDto(); item2.Title = "二号泵"; item2.UserName = "李三林"; item2.Content = "2020年9月21日 12时30分,漏水严重。"; info_list.Add(item2); DemoEnginePumpCenterBottomItemInfoDto item3 = new DemoEnginePumpCenterBottomItemInfoDto(); item3.Title = "二号泵"; item3.UserName = "管理员"; item3.Content = "2020年9月25日 12时30分,电流超标。"; info_list.Add(item2); } return info_list; } /// /// 获取表单状态统计占比(右部上) /// /// 机泵ID /// 统计类型(1成本 暂时又有一个) [Route("GetRightTopInfo")] [HttpGet] public List GetRightTopInfo(long ProductID, int StaticType) { var r = new Random(); List info_list = new List(); int ratio = 1; DemoEnginePumpRightTopInfoDto item1 = new DemoEnginePumpRightTopInfoDto(); item1.Label = "总电费"; item1.Number = r.Next(1221, 3453) * ratio + 150000; info_list.Add(item1); DemoEnginePumpRightTopInfoDto item2 = new DemoEnginePumpRightTopInfoDto(); item2.Label = "总维护费"; item2.Number = r.Next(1230, 4233) * ratio + 10000; info_list.Add(item2); DemoEnginePumpRightTopInfoDto item3 = new DemoEnginePumpRightTopInfoDto(); item3.Label = "采购费用"; item3.Number = r.Next(100, 120) * 100 + 100000; info_list.Add(item3); DemoEnginePumpRightTopInfoDto item5 = new DemoEnginePumpRightTopInfoDto(); item5.Label = "其他费用"; item5.Number = r.Next(123, 125) * 20 + 10000; info_list.Add(item5); return info_list; } /// /// 获取表单类型统计占比(右部中) /// /// 机泵ID /// 页面序号 /// [Route("GetRightCenterInfo")] [HttpGet] public DemoEnginePumpRightCenterInfoDto GetRightCenterInfo(long ProductID, int PageIndex) { // var r = new Random(); List item_list = new List(); if (PageIndex == 0) { DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto(); item5.Time = "2020-9-11"; item5.Type = "维修"; item5.Content = "漏水,更换机封"; item5.UserName = "机修二组"; item_list.Add(item5); DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto(); item4.Time = "2020-8-22"; item4.Type = "保养"; item4.Content = "更换易损件"; item4.UserName = "机修一组"; item_list.Add(item4); DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto(); item3.Time = "2020-8-21"; item3.Type = "维修"; item3.Content = "漏水,更换机封"; item3.UserName = "机修一组"; item_list.Add(item3); DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto(); item2.Time = "2020-8-11"; item2.Type = "保养"; item2.Content = "更换易损件"; item2.UserName = "机修一组"; item_list.Add(item2); DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto(); item1.Time = "2020-7-20"; item1.Type = "维修"; item1.Content = "漏水,更换机封"; item1.UserName = "机修一组"; item_list.Add(item1); } else if (PageIndex == 1) { DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto(); item1.Time = "2020-6-20"; item1.Type = "维修"; item1.Content = "漏水,更换机封"; item1.UserName = "机修一组"; item_list.Add(item1); DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto(); item2.Time = "2020-6-11"; item2.Type = "保养"; item2.Content = "更换机油"; item2.UserName = "机修一组"; item_list.Add(item2); DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto(); item3.Time = "2020-5-21"; item3.Type = "维修"; item3.Content = "漏水,更换电机机油"; item3.UserName = "机修一组"; item_list.Add(item3); DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto(); item4.Time = "2020-5-19"; item4.Type = "保养"; item4.Content = "更换易损件"; item4.UserName = "机修一组"; item_list.Add(item4); DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto(); item5.Time = "2020-5-2"; item5.Type = "维修"; item5.Content = "漏水,更换机封"; item5.UserName = "机修二组"; item_list.Add(item5); } else { DemoEnginePumpRightCenterItemInfoDto item1 = new DemoEnginePumpRightCenterItemInfoDto(); item1.Time = "2020-4-30"; item1.Type = "维修"; item1.Content = "漏水,更换机封"; item1.UserName = "机修一组"; item_list.Add(item1); DemoEnginePumpRightCenterItemInfoDto item2 = new DemoEnginePumpRightCenterItemInfoDto(); item2.Time = "2020-4-21"; item2.Type = "保养"; item2.Content = "更换易损件"; item2.UserName = "机修一组"; item_list.Add(item2); DemoEnginePumpRightCenterItemInfoDto item3 = new DemoEnginePumpRightCenterItemInfoDto(); item3.Time = "2020-4-20"; item3.Type = "维修"; item3.Content = "漏水,更换机封"; item3.UserName = "机修一组"; item_list.Add(item3); DemoEnginePumpRightCenterItemInfoDto item4 = new DemoEnginePumpRightCenterItemInfoDto(); item4.Time = "2020-4-15"; item4.Type = "保养"; item4.Content = "更换易损件"; item4.UserName = "机修一组"; item_list.Add(item4); DemoEnginePumpRightCenterItemInfoDto item5 = new DemoEnginePumpRightCenterItemInfoDto(); item5.Time = "2020-4-10"; item5.Type = "维修"; item5.Content = "漏水,更换机封"; item5.UserName = "机修二组"; item_list.Add(item5); } DemoEnginePumpRightCenterInfoDto info = new DemoEnginePumpRightCenterInfoDto(); info.PageNumber = 3; info.Details = item_list; return info; } /// /// 通过 StationID 获取简单列表 /// [Route("GetSimpleListByStationID")] [HttpGet] public List GetSimpleListByStationID([FromQuery][Required] StationIDUnderCorpInput input) { var corpId = input.CorpID; var stationId = input.StationID; var cacheKey = $"LargeScreen_Demo_EnginePump_GetSimpleListByStationID_{corpId}_{stationId}"; var vmList = MemoryCacheHelper.GetSet(cacheKey, () => { var serviceProduct = new Service.Product(); var productList = serviceProduct.GetByBelongTypeAndBelongID(corpId, ObjectType.Station, stationId); var enginePumpList = productList?.Where(x => x.Catalog == Product.Catalog_JiBeng).ToList(); if (enginePumpList == null || enginePumpList.Count < 1) return default; var vmCacheList = enginePumpList.Select(x => new DemoEnginePumpSimpleDto(x)).ToList(); return vmCacheList; }, CacheHelper.CacheLevel3); return vmList; } /// /// 通过 ID 获取详细 /// [Route("GetDetailByID")] [HttpGet] public DemoEnginePumpDetailDto GetDetailByID([FromQuery][Required] IDUnderCorpInput input) { var corpId = input.CorpID; var id = input.ID; var cacheKey = $"LargeScreen_Demo_EnginePump_GetDetailByID_{corpId}_{id}"; var vm = MemoryCacheHelper.GetSet(cacheKey, () => { var serviceProduct = new Service.Product(); var enginePump = serviceProduct.GetEnginePumpByProductID(corpId, id); if (enginePump == null) return default; var serviceProperty = new Service.ProductTypePropertyGroup(); var enginePumpPropertyList = serviceProperty.GetExItemsByProductTypeID(enginePump.CorpID, enginePump.ProductTypeID); var vmCache = new DemoEnginePumpDetailDto(enginePump, enginePumpPropertyList); var pump = serviceProduct.GetChildPumpByEnginePumpID(enginePump.CorpID, enginePump.ID); if (pump != null) { var pumpPropertyList = serviceProperty.GetExItemsByProductTypeID(pump.CorpID, pump.ProductTypeID); vmCache.Pump = new DemoPumpDetailDto(pump, pumpPropertyList); } var motor = serviceProduct.GetChildMotorByEnginePumpID(enginePump.CorpID, enginePump.ID); if (motor != null) { var motorPropertyList = serviceProperty.GetExItemsByProductTypeID(motor.CorpID, motor.ID); vmCache.Motor = new DemoMotorDetailDto(motor, motorPropertyList); } return vmCache; }, CacheHelper.CacheLevel4); return vm; } } }