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
|
{
|
/// <summary>
|
/// 生产运营
|
/// </summary>
|
[AllowAnonymous]
|
[Route("LargeScreen/Szjt/Scyy")]
|
[ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(生产运营)", Order = 999)]
|
public class SzjtScyy_Controller : IDynamicApiController, ITransient
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
/// <summary>
|
///
|
/// </summary>
|
public SzjtScyy_Controller(IHttpContextAccessor httpContextAccessor)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
}
|
|
#region const
|
|
private const long _corpid = 3;//客户标识
|
|
private const long _stationId = 23;//泵站标识
|
|
private const long _tlpointid_23 = 1688;//累积流量
|
private const long _tlsignalid_23 = 2388;//累积流量信号
|
|
private const long _lpointid_23 = 1687;//瞬时流量
|
private const long _lsignalid_23 = 2387;//瞬时流量信号
|
|
private const long _zdpointId_23 = 1692;//浊度
|
private const long _zdsignalid_23 = 2392;//浊度信号
|
|
private const long _ylpointid_23 = 1693;//余氯
|
private const long _ylsignalid_23 = 2393;//余氯信号
|
|
private const long _ckylpointid_23 = 1690;//出口压力
|
private const long _ckylsignalid_23 = 2390;//出口压力信号
|
|
|
#endregion
|
|
|
/// <summary>
|
/// 制水生产 (左上部分)
|
/// </summary>
|
[Route("GetLeftTopInfo")]
|
[HttpGet]
|
public SzjtScyyLeftTopInfoDto GetLeftTopInfo()
|
{
|
var info_list = new SzjtScyyLeftTopInfoDto();
|
|
var servive_record = new Service.MonitorRealRecord();
|
|
//昨日累积供水量
|
var tl_yes_firstValue = servive_record.GetFirstBySignalIDOfDay(_corpid,_tlpointid_23,_tlsignalid_23, DateTime.Now.AddDays(-1));
|
var tl_yes_lastVlaue = servive_record.GetLastBySignalIDOfDay(_corpid, _tlpointid_23, _tlsignalid_23, DateTime.Now.AddDays(-1));
|
if (tl_yes_firstValue != null)
|
{
|
if (double.TryParse(tl_yes_firstValue.DataValue, out double tl_yes_first_value))
|
{
|
if (tl_yes_lastVlaue != null)
|
{
|
if (double.TryParse(tl_yes_lastVlaue.DataValue, out double tl_yes_last_value))
|
{
|
info_list.YesterdayTotalSupplyWater = NumberHelper.Round(tl_yes_last_value - tl_yes_first_value, 2);
|
}
|
}
|
}
|
}
|
|
//今日累积供水量
|
var tl_lastValue = servive_record.GetLastRecord(_corpid,_tlpointid_23,_tlsignalid_23);
|
if (tl_lastValue != null)
|
{
|
if (double.TryParse(tl_lastValue.DataValue, out double tl_last_value))
|
{
|
if (tl_yes_lastVlaue != null)
|
{
|
if (double.TryParse(tl_yes_lastVlaue.DataValue, out double tl_yes_last_value))
|
{
|
info_list.TodayTotalSupplyWater = NumberHelper.Round(tl_last_value - tl_yes_last_value, 2);
|
}
|
}
|
}
|
}
|
|
//当前瞬时流量
|
var l_lastValue = servive_record.GetLastRecord(_corpid, _lpointid_23,_lsignalid_23);
|
if (l_lastValue != null)
|
{
|
if (double.TryParse(l_lastValue.DataValue, out double l_last_value))
|
{
|
info_list.CurrentFlow = NumberHelper.Round(l_last_value, 1);
|
}
|
}
|
|
//浊度
|
var zh_lastValue = servive_record.GetLastRecord(_corpid, _zdpointId_23,_zdsignalid_23);
|
if (zh_lastValue != null)
|
{
|
if (double.TryParse(zh_lastValue.DataValue, out double zh_last_value))
|
{
|
info_list.CurrentTurbidity = NumberHelper.Round(zh_last_value, 2);
|
}
|
}
|
|
//余氯
|
var yu_lastValue = servive_record.GetLastRecord(_corpid, _ylpointid_23,_zdsignalid_23);
|
if (yu_lastValue != null)
|
{
|
if (double.TryParse(yu_lastValue.DataValue, out double yl_last_value))
|
{
|
info_list.CurrentResidualChlorine = NumberHelper.Round(yl_last_value, 2);
|
}
|
}
|
|
return info_list;
|
}
|
|
/// <summary>
|
/// 获取当前压力 (左中部分:当前压力)
|
/// </summary>
|
[Route("GetLeftMiddleInfo1")]
|
[HttpGet]
|
public double? GetLeftMiddleInfo1()
|
{
|
var service_record = new Service.MonitorRealRecord();
|
var lastRecord = service_record.GetLastNormalRecord(_corpid, _ckylpointid_23,_ckylsignalid_23);
|
if (lastRecord == null)
|
return default;
|
return NumberHelper.Round(double.Parse(lastRecord.DataValue),3);
|
|
//var r = new Random();
|
//var v = r.Next(2503, 2710) / 1000.0;
|
//return new Result<double>(v);
|
}
|
|
/// <summary>
|
/// 管网压力 (左中部分)
|
/// </summary>
|
[Route("GetLeftMiddleInfo2")]
|
[HttpGet]
|
public SzjtScyyLeftMiddleInfoDto GetLeftMiddleInfo2()
|
{
|
var info = new SzjtScyyLeftMiddleInfoDto();
|
|
var service_record = new Service.MonitorRealRecord();
|
|
//单前压力
|
//var lastValue = service_record.GetLastRecordValue(_ckylpointid_13);
|
//info.Current = lastValue;
|
|
//昨日压力列表
|
var yesterday = service_record.GetBySignalIDOfDay(_corpid, _ckylpointid_23,_ckylsignalid_23, DateTime.Now.AddDays(-1));
|
if (yesterday != null && yesterday.Count > 0)
|
{
|
info.Yesterday = new List<SzjtScyyGeneralRecord>();
|
foreach (var item in yesterday)
|
{
|
var vm = new SzjtScyyGeneralRecord();
|
vm.RecordStatus = 0;
|
vm.RecordTime = item.DataTime;
|
vm.RecordValue = item.DataValue;
|
info.Yesterday.Add(vm);
|
}
|
}
|
|
//今日压力列表
|
var today = service_record.GetBySignalIDOfDay(_corpid, _ckylpointid_23, _ckylsignalid_23, DateTime.Now);
|
if (today != null && today.Count > 0)
|
{
|
info.Today = new List<SzjtScyyGeneralRecord>();
|
foreach (var item in today)
|
{
|
var vm = new SzjtScyyGeneralRecord();
|
vm.RecordStatus = 0;
|
vm.RecordTime = item.DataTime;
|
vm.RecordValue = item.DataValue;
|
info.Today.Add(vm);
|
}
|
}
|
|
return info;
|
|
//var r = new Random();
|
//List<LeftMiddleItemInfo> info_list = new List<LeftMiddleItemInfo>();
|
|
//for (int hour = 0; hour < DateTime.Now.Hour; hour++)
|
//{
|
// LeftMiddleItemInfo item = new LeftMiddleItemInfo();
|
// item.Label = hour.ToString();
|
// item.Yesterday = r.Next(2401, 2705) / 1000.0;
|
// item.Today = r.Next(2402, 2706) / 1000.0;
|
// info_list.Add(item);
|
//}
|
|
// return new Result<List<LeftMiddleItemInfo>>(info_list);
|
}
|
|
/// <summary>
|
/// 泵站分析 (左下部分 )
|
/// </summary>
|
/// <param name="StaticType">汇总类型(1按日 2 按周 3 按月 4 按年)</param>
|
[Route("GetLeftBottomInfo")]
|
[HttpGet]
|
public List<SzjtScyyLeftBottomItemInfoDto> GetLeftBottomInfo(int StaticType)
|
{
|
var info_list = new List<SzjtScyyLeftBottomItemInfoDto>();
|
var service_station = new Service.Station();
|
var service_record = new Service.MonitorRealRecord();
|
|
var station_list = service_station.GetByCorpID(_corpid);
|
|
foreach (var station in station_list)
|
{
|
var item = new SzjtScyyLeftBottomItemInfoDto();
|
item.ID = station.ID;
|
item.Name = station.Name;
|
if (station.ID == _stationId)
|
{
|
item.Flow = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _lpointid_23, _lsignalid_23).DataValue), 2);
|
item.Press = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _ckylpointid_23, _ckylsignalid_23).DataValue), 2);
|
item.ResidualChlorine = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _ylpointid_23, _ylsignalid_23).DataValue), 3);
|
item.Turbidity = NumberHelper.RoundString(double.Parse(service_record.GetLastRecord(_corpid, _zdpointId_23, _zdsignalid_23).DataValue), 3);
|
}
|
info_list.Add(item);
|
}
|
|
//var r = new Random();
|
//List<LeftBottomItemInfo> info_list = new List<LeftBottomItemInfo>();
|
|
//var all_station = new Service.StationBase().GetByCorpID(1);
|
|
//foreach (var station in all_station)
|
//{
|
// LeftBottomItemInfo item = new LeftBottomItemInfo();
|
// item.ID = station.ID;
|
// item.Name = station.Name;
|
// item.Flow = r.Next(2600, 2800) / 100.0;
|
// item.Press = r.Next(211, 225) / 1000.0;
|
// item.WaterQuality = r.Next(210, 225) / 100.0;
|
|
// info_list.Add(item);
|
|
//}
|
return info_list;
|
}
|
|
/// <summary>
|
/// 获取首页报警和信息公告(中间底部)
|
/// </summary>
|
/// <param name="InfoType">信息类型(1信息 2报警)</param>
|
[Route("GetCenterBottomInfo")]
|
[HttpGet]
|
public List<SzjtScyyCenterBottomInfoDto> GetCenterBottomInfo(int InfoType)
|
{
|
var info_list = new List<SzjtScyyCenterBottomInfoDto>();
|
|
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 SzjtScyyCenterBottomInfoDto();
|
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 SzjtScyyCenterBottomInfoDto();
|
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;
|
}
|
|
/// <summary>
|
/// 获取报修(中间底部)
|
/// </summary>
|
/// <param name="ID"> (RequesFormID)</param>
|
[Route("GetRepairRequesFormDetalInfo")]
|
[HttpGet]
|
public SzjtScyyRepairRequesFormDetalInfoDto 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 SzjtScyyRepairRequesFormDetalInfoDto();
|
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;
|
}
|
|
/// <summary>
|
/// 获取报警(中间底部)
|
/// </summary>
|
/// <param name="ID"> (RequesFormID)</param>
|
/// <returns></returns>
|
[Route("GetAlarmDataDetalInfo")]
|
[HttpGet]
|
public SzjtScyyAlarmDetalInfoDto GetAlarmDataDetalInfo(long ID)
|
{
|
var service = new Service.MonitorAlarmRecord();
|
var alarm = service.GetByID(_corpid, ID);
|
if (alarm == null)
|
{
|
throw new Exception("警报不存在");
|
}
|
|
var station_list = new Service.Station().GetByCorpID(_corpid);
|
var point = new Service.MonitorPoint().GetByID(_corpid,alarm.MonitorPointID);
|
|
var view_model = new SzjtScyyAlarmDetalInfoDto();
|
if (point.BelongType == IStation.ObjectType.Station)
|
{
|
view_model.StaionName = (from x in station_list where x.ID == point.BelongID select x.Name).FirstOrDefault();
|
}
|
|
|
view_model.RecordName = point.Name;
|
view_model.AlarmTime = alarm.AlarmTime.ToString("MM月dd日 HH时mm分ss秒");
|
//view_model.RecoveryTime = alarm.RecoveryTime == null?"":((DateTime)alarm.RecoveryTime).ToString("MM月dd日 HH时mm分ss秒");
|
view_model.RecordValue = alarm.DataValue.ToString();
|
view_model.ThresholdValue = alarm.ThresholdValue.ToString();
|
|
|
return view_model;
|
}
|
|
/// <summary>
|
/// 工单数量 (右部上 )
|
/// </summary>
|
/// <returns></returns>
|
[Route("GetRightTopInfo")]
|
[HttpGet]
|
public SzjtScyyRightTopInfoDto GetRightTopInfo()
|
{
|
var start = new DateTime(DateTime.Now.Year,DateTime.Now.Month,1);
|
var taskFormList = new Service.RepairTaskForm().GetFluzzyList(_corpid,null,null,null,null,null,null,null,start,null);
|
var taskFormCount = new Service.RepairTaskForm().GetCountByCorpID(_corpid);
|
var requestPendingCount=new Service.RepairRequestForm().GetPendingCountByCorpID(_corpid);
|
|
var vm = new SzjtScyyRightTopInfoDto();
|
vm.UnProcessingForm = requestPendingCount;
|
if (taskFormList == null || taskFormList.Count < 1)
|
{
|
vm.HistoryTotalForm = taskFormCount;
|
}
|
else
|
{
|
vm.TotalForm = taskFormList.Count;
|
vm.HistoryTotalForm = taskFormCount - vm.TotalForm;
|
vm.ProcessedForm = taskFormList.Where(x => x.Item1.FormStatus == Model.Repair.eTaskStatus.Accepted).Count();
|
vm.ProcessingForm = taskFormList.Where(x => x.Item1.FormStatus > Model.Repair.eTaskStatus.Accepted && x.Item1.FormStatus < Model.Repair.eTaskStatus.Succeed).Count();
|
vm.CheckedForm = taskFormList.Where(x => x.Item1.FormStatus >= Model.Repair.eTaskStatus.Succeed).Count();
|
}
|
|
return vm;
|
|
}
|
|
|
/// <summary>
|
/// 产销差 (右部中)
|
/// </summary>
|
/// <returns></returns>
|
[Route("GetRightCenterInfo")]
|
[HttpGet]
|
public List<SzjtScyyRightCenterInfoDto> GetRightCenterInfo()
|
{
|
var r = new Random();
|
|
List<SzjtScyyRightCenterInfoDto> info_list = new List<SzjtScyyRightCenterInfoDto>();
|
if (DateTime.Now.Month < 2)
|
{
|
for (int month = 1; month <= 12; month++)
|
{
|
SzjtScyyRightCenterInfoDto m = new SzjtScyyRightCenterInfoDto();
|
}
|
}
|
else
|
{
|
for (int month = 1; month <= DateTime.Now.Month; month++)
|
{
|
SzjtScyyRightCenterInfoDto m = new SzjtScyyRightCenterInfoDto();
|
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;
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
}
|