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/Szjt/Glfq")]
[ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(管网分区)", Order = 999)]
public class SzjtGlfq_Controller : IDynamicApiController, ITransient
{
private readonly IHttpContextAccessor _httpContextAccessor;
///
///
///
public SzjtGlfq_Controller(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
private const long _corpid = 3;
///
/// 管网概况 (左上部分 )
///
///
[Route("GetLeftTopInfo")]
[HttpGet]
public SzjtGlfqLeftTopInfoDto GetLeftTopInfo()
{
SzjtGlfqLeftTopInfoDto info_list = new SzjtGlfqLeftTopInfoDto();
var r = new Random();
info_list.Area = 310;
info_list.Length = 15 + 25 + 35 + 25 + 23 + 45 + 35;
info_list.Items = new List();
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "铸铁", Length = 15, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "钢管", Length = 25, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "PE", Length = 35, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "混凝土", Length = 25, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "PVC", Length = 23, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "SN", Length = 45, Ratio = Math.Round(15 / info_list.Length, 1) });
info_list.Items.Add(new SzjtGlfqLeftTopItemInfoDto() { Label = "其他", Length = 35, Ratio = Math.Round(15 / info_list.Length, 1) });
return info_list;
}
///
/// 获取泵站数据分析汇总信息(左中部分)
///
/// 汇总类型(1按日 2 按周 3 按月 4 按年)
[Route("GetLeftMiddleInfo")]
[HttpGet]
public List GetLeftMiddleInfo(int StaticType)
{
var r = new Random();
List info_list = new List();
int ratio = 1;
if (StaticType == 2)
ratio = 5;
if (StaticType == 3)
ratio = 20;
if (StaticType == 4)
ratio = 250;
SzjtGlfqLeftMiddleItemInfoDto item1 = new SzjtGlfqLeftMiddleItemInfoDto();
item1.Label = "机组故障";
item1.Number = r.Next(8, 11) * ratio;
info_list.Add(item1);
SzjtGlfqLeftMiddleItemInfoDto item2 = new SzjtGlfqLeftMiddleItemInfoDto();
item2.Label = "管道维修";
item2.Number = r.Next(2, 5) * ratio;
info_list.Add(item2);
SzjtGlfqLeftMiddleItemInfoDto item3 = new SzjtGlfqLeftMiddleItemInfoDto();
item3.Label = "阀门维修";
item3.Number = r.Next(1, 3) * ratio;
info_list.Add(item3);
SzjtGlfqLeftMiddleItemInfoDto item4 = new SzjtGlfqLeftMiddleItemInfoDto();
item4.Label = "仪表";
item4.Number = r.Next(2, 4) * ratio;
info_list.Add(item4);
SzjtGlfqLeftMiddleItemInfoDto item5 = new SzjtGlfqLeftMiddleItemInfoDto();
item5.Label = "其他";
item5.Number = r.Next(5, 12) * ratio;
info_list.Add(item5);
return info_list;
}
///
/// 左面板信息(左):管网管理
///
///
[Route("GetLeftBottomInfo")]
[HttpGet]
public List GetLeftBottomInfo()
{
var r = new Random();
List info_list = new List();
SzjtGlfqLeftBottomItemInfoDto item1 = new SzjtGlfqLeftBottomItemInfoDto();
item1.Time = "2020-10-01";
item1.Type = "巡检**路段";
item1.UserName = "张三";
info_list.Add(item1);
SzjtGlfqLeftBottomItemInfoDto item2 = new SzjtGlfqLeftBottomItemInfoDto();
item2.Time = "2020-10-01";
item2.Type = "巡检**路段";
item2.UserName = "张三";
info_list.Add(item2);
SzjtGlfqLeftBottomItemInfoDto item3 = new SzjtGlfqLeftBottomItemInfoDto();
item3.Time = "2020-10-01";
item3.Type = "巡检**路段";
item3.UserName = "张三";
info_list.Add(item3);
SzjtGlfqLeftBottomItemInfoDto item4 = new SzjtGlfqLeftBottomItemInfoDto();
item4.Time = "2020-10-01";
item4.Type = "巡检**路段";
item4.UserName = "张三";
info_list.Add(item4);
SzjtGlfqLeftBottomItemInfoDto item5 = new SzjtGlfqLeftBottomItemInfoDto();
item5.Time = "2020-10-01";
item5.Type = "巡检**路段";
item5.UserName = "张三";
info_list.Add(item5);
SzjtGlfqLeftBottomItemInfoDto item6 = new SzjtGlfqLeftBottomItemInfoDto();
item6.Time = "2020-10-01";
item6.Type = "巡检**路段";
item6.UserName = "张三";
info_list.Add(item6);
SzjtGlfqLeftBottomItemInfoDto item7 = new SzjtGlfqLeftBottomItemInfoDto();
item7.Time = "2020-10-07";
item7.Type = "巡检**路段";
item7.UserName = "张三";
info_list.Add(item7);
return info_list;
}
///
/// 获取首页报警和信息公告(中间底部)
///
/// 信息类型(1信息 2报警)
[Route("GetCenterBottomInfo")]
[HttpGet]
public List GetCenterBottomInfo(int InfoType)
{
var r = new Random();
List info_list = new List();
if (InfoType == 1)
{
var service = new Service.RepairRequestForm();
var forms = service.GetLastByCorpID(_corpid, 8);
foreach (var f in forms)
{
var station_list = new Service.Station().GetByCorpID(_corpid);
var product_list = new Service.Product().GetByCorpID(_corpid);
var user_list = new Service.User().GetByCorpID(_corpid);
if (f.BelongType == ObjectType.Station)
{
var item1 = new SzjtGlfqCenterBottomItemInfoDto();
item1.ID = f.ID;
item1.Title = station_list?.Find(t => t.ID == f.BelongID)?.Name;
item1.UserName = user_list?.Find(t => t.ID == f.CreateUserID)?.RealName;
item1.Content = string.Format("{0} {1}发生:{2}", f.CreateTime.ToString("MM月dd日,HH时"), product_list?.Find(t => t.ID == f.ProductID)?.Name, f.Question);
info_list.Add(item1);
}
}
}
else
{
var service = new Service.MonitorAlarmRecord();
var serice_point = new IStation.Service.MonitorPoint();
var alarms = service.GetLastByCorpID(_corpid, 8);
if (alarms != null && alarms.Count > 0)
{
var station_list = new Service.Station().GetByCorpID(_corpid);
var point_list = new Service.MonitorPoint().GetByCorpID(_corpid);
foreach (var alarm in alarms)
{
var point = point_list?.Find(t => t.ID == alarm.MonitorPointID);
if (point == null)
continue;
string belong_name = "";
if (point.BelongType == IStation.ObjectType.Station)
{
belong_name = string.Format("{0}的{1}",
(from x in station_list where x.ID == point.BelongID select x.Name).FirstOrDefault(),
point.Name);
}
var item1 = new SzjtGlfqCenterBottomItemInfoDto();
item1.ID = alarm.ID;
item1.Title = belong_name;
item1.Content = string.Format("{0} {1}的值为:{2},超过设定{3}",
alarm.AlarmTime.ToString("MM月dd日,HH时"),
point.Name,
alarm.DataValue == null ? "" : Math.Round(double.Parse(alarm.DataValue), 4).ToString(),
alarm.ThresholdValue);
info_list.Add(item1);
}
}
}
return info_list;
}
///
/// 获取报修(中间底部)
///
/// (RequesFormID)
///
[Route("GetRepairRequesFormDetalInfo")]
[HttpGet]
public SzjtGlfqRepairRequestFormDetailInfoDto GetRepairRequesFormDetalInfo(long ID)
{
var service = new Service.RepairRequestForm();
var form = service.GetByID(_corpid, ID);
if (form == null)
{
throw new Exception("表单不存在");
}
var station_list = new Service.Station().GetByCorpID(_corpid);
var product_list = new Service.Product().GetByCorpID(_corpid);
var user_list = new Service.User().GetByCorpID(_corpid);
var view_model = new SzjtGlfqRepairRequestFormDetailInfoDto();
view_model.BelongName = (from x in station_list where x.ID == form.BelongID select x.Name).FirstOrDefault();
view_model.ReportUserName = (from x in user_list where x.ID == form.CreateUserID select x.RealName).FirstOrDefault();
view_model.ObjectName = product_list?.Find(t => t.ID == form.ProductID)?.Name;
view_model.ReportTime = form.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
view_model.ProblemDescription = form.Question;
view_model.FormSource = "小程序";
if (form.FormStatus == Model.Repair.eRequestStatus.Pending)
view_model.RequestFormStatus = "待受理";
if (form.FormStatus == Model.Repair.eRequestStatus.Accepted)
view_model.RequestFormStatus = "已受理";
if (form.FormStatus == Model.Repair.eRequestStatus.Rejected)
view_model.RequestFormStatus = "已驳回";
return view_model;
}
///
/// 分区管理(右部上)
///
///
[Route("GetRightTopInfo")]
[HttpGet]
public SzjtGlfqRightTopInfoDto GetRightTopInfo()
{
var r = new Random();
SzjtGlfqRightTopInfoDto item1 = new SzjtGlfqRightTopInfoDto();
item1.DmaNumber = 8;
item1.LastTotalSupplyWater = r.Next(2504, 2580);
item1.LastMonthLeakRatio = 50.8;
item1.ThisYearLeakRatio = 48.9;
return item1;
}
///
/// 漏损分析 (右部中:)
///
/// 统计类型(1按日 2 按周 3 按月 4 按年)
[Route("GetRightCenterInfo")]
[HttpGet]
public List GetRightCenterInfo(int StaticType)
{
var r = new Random();
List info_list = new List();
if (DateTime.Now.Month < 2)
{
for (int month = 1; month <= 12; month++)
{
SzjtGlfqRightCenterInfoDto m = new SzjtGlfqRightCenterInfoDto();
}
}
else
{
for (int month = 1; month <= DateTime.Now.Month; month++)
{
SzjtGlfqRightCenterInfoDto m = new SzjtGlfqRightCenterInfoDto();
m.Label = month.ToString();
m.ThisSupplyWater = r.Next(2000, 3000);
m.LastSupplyWater = r.Next(2000, 3000);
m.ThisSaleWater = r.Next(1800, 2500);
m.LastSaleWater = r.Next(1800, 2500);
if (m.ThisSupplyWater < m.ThisSaleWater)
{
double temp = m.ThisSaleWater;
m.ThisSaleWater = m.ThisSupplyWater;
m.ThisSupplyWater = temp;
}
if (m.LastSupplyWater < m.LastSaleWater)
{
double temp = m.LastSaleWater;
m.LastSaleWater = m.LastSupplyWater;
m.LastSupplyWater = temp;
}
m.ThisDistributionLosses = Math.Round(m.ThisSupplyWater * 100 / m.ThisSaleWater, 1);
m.LastDistributionLosses = Math.Round(m.LastSupplyWater * 100 / m.LastSaleWater, 1);
info_list.Add(m);
}
}
return info_list;
}
///
/// 流量曲綫
///
///
///
[Route("GetRightBottomInfo")]
[HttpGet]
public SzjtGlfqRightBottomInfoDto GetRightBottomInfo(int StaticType)
{
var now = DateTime.Now;
List today_records = new List();
var r = new Random();
for (int h = 0; h < now.Hour; h++)
{
for (int m = 0; m < 60; m++)
{
var dt = new DateTime(now.Year, now.Month, now.Day, h, m, 0);
today_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
}
}
for (int m = 0; m < now.Minute; m++)
{
var dt = new DateTime(now.Year, now.Month, now.Day, now.Hour, m, 0);
today_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
}
var yest = DateTime.Now.AddDays(-1);
List yest_records = new List();
for (int h = 0; h < 24; h++)
{
for (int m = 0; m < 60; m++)
{
var dt = new DateTime(yest.Year, yest.Month, yest.Day, h, m, 0);
yest_records.Add(new SzjtGlfqRecordBaseDto() { RecordTime = dt.ToString("yyyy-MM-dd HH:mm:ss"), RecordValue = r.Next(1000, 1100) / 100.0 });
}
}
SzjtGlfqRightBottomInfoDto info = new SzjtGlfqRightBottomInfoDto();
info.TodayFlowCurve = today_records;
info.YesterdayFlowCurve = yest_records;
return info;
}
}
}