123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 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");
- }
- /// <summary>
- /// 返回日期几
- /// </summary>
- /// <returns></returns>
- 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
- /// <summary>
- /// 根据测点数据获取风机当前状态(八种状态)
- /// </summary>
- /// <param name="statusValue"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 根据测点数据获取风机当前状态(八种状态)
- /// </summary>
- /// <param name="statusValue"></param>
- /// <returns></returns>
- 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 "未知";
- }
- /// <summary>
- /// 获取限电受累信息(挂牌)
- /// </summary>
- /// <param name="lockValue"></param>
- /// <returns></returns>
- 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 "未知";
- }
- }
- }
|