using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IntelligentControlForsx.Service.WindturbineControl.Domain;
using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
namespace IntelligentControlForsx.Common
{
public class CommonMethod
{
#region 字符串处理
public static string GetShortWindturbineId(String wtId)
{
if (wtId != null && wtId.Contains("_"))
{
string[] tmp = wtId.Split('_');
string prefix = tmp[0].Substring(0, 2);
return prefix + tmp[1];
}
return wtId;
}
public static string GetLongWindturbineId(String wtId)
{
String result = wtId.Substring(0, 2);
result += "01_";
result += wtId.Substring(2);
return result;
}
public static string StringCopy(string src, int maxLen)
{
if (src.Length < maxLen)
return src;
else
return src.Substring(0, maxLen);
}
#endregion
#region 日期时间转换
public static DateTime ConvertIntDateTime(long utc)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
startTime = startTime.AddMilliseconds(utc);
//startTime = startTime.AddHours(8);
return startTime;
}
public static long ConvertDateTimeInt(DateTime time)
{
long utc = 0;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
utc = (long)(time - startTime).TotalMilliseconds;
return utc;
}
public static DateTime GetQuarterFloor(DateTime time)
{
var m = time.Minute;
if (m < 15)
return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "00:00");
else if (m < 30)
return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "15:00");
else if (m < 45)
return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "30:00");
else
return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "45:00");
}
///
/// 返回日期几
///
///
public static string DayOfWeek(DateTime dt)
{
switch (dt.DayOfWeek.ToString("D"))
{
case "0":
return "星期日 ";
case "1":
return "星期一 ";
case "2":
return "星期二 ";
case "3":
return "星期三 ";
case "4":
return "星期四 ";
case "5":
return "星期五 ";
case "6":
return "星期六 ";
}
return "";
}
#endregion
///
/// 根据测点数据获取风机当前状态(八种状态)
///
///
///
public static WindturbineStatus GetWindturbineStatus(double statusValue)
{
//0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
if (statusValue == 0)
return WindturbineStatus.Stop;
else if (statusValue == 1)
return WindturbineStatus.OnPower;
else if (statusValue == 2)
return WindturbineStatus.Standby;
else if (statusValue == 3)
return WindturbineStatus.Start;
else if (statusValue == 4)
return WindturbineStatus.Online;
else if (statusValue == 5)
return WindturbineStatus.Fault;
else if (statusValue == 6)
return WindturbineStatus.Maintain;
else if (statusValue == 7)
return WindturbineStatus.Offline;
else
return WindturbineStatus.UnKnow;
}
///
/// 根据测点数据获取风机当前状态(八种状态)
///
///
///
public static string GetWindturbineStatusString(double statusValue)
{
//0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
if (statusValue == 0)
return "停机";
else if (statusValue == 1)
return "上电";
else if (statusValue == 2)
return "待机";
else if (statusValue == 3)
return "启动";
else if (statusValue == 4)
return "并网";
else if (statusValue == 5)
return "故障";
else if (statusValue == 6)
return "维护";
else if (statusValue == 7)
return "离线";
else
return "未知";
}
///
/// 获取限电受累信息(挂牌)
///
///
///
public static HungType GetHungLock(double lockValue)
{
// ;2, "场内受累检修";3, "场内受累故障";4, "场外受累电网";5, "场外受累天气";";7,"故障维修",8,"检修" 0正常
if (lockValue == 0)
return HungType.UnLock;
else if (lockValue == 2)
return HungType.StationCheckLock;
else if (lockValue == 3)
return HungType.StationFaulLockt;
else if (lockValue == 4)
return HungType.StationPowerLineLock;
else if (lockValue == 5)
return HungType.StationWeatherLock;
else if (lockValue == 7)
return HungType.FaultLock;
else if (lockValue == 8)
return HungType.CheckLock;
else
return HungType.UnKnow;
}
public static string GetHungLockString(double lockValue)
{
// ;2, "场内受累检修";3, "场内受累故障";4, "场外受累电网";5, "场外受累天气";";7,"故障维修",8,"检修" 0正常
if (lockValue == 0)
return "正常";
else if (lockValue == 2)
return "场内受累检修";
else if (lockValue == 3)
return "场内受累故障";
else if (lockValue == 4)
return "场外受累电网";
else if (lockValue == 5)
return "场外受累天气";
else if (lockValue == 7)
return "故障检修";
else if (lockValue == 8)
return "检修";
else
return "未知";
}
}
}