CommonMethod.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using IntelligentControlForsx.Service.WindturbineControl.Domain;
  7. using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd;
  8. namespace IntelligentControlForsx.Common
  9. {
  10. public class CommonMethod
  11. {
  12. #region 字符串处理
  13. public static string GetShortWindturbineId(String wtId)
  14. {
  15. if (wtId != null && wtId.Contains("_"))
  16. {
  17. string[] tmp = wtId.Split('_');
  18. string prefix = tmp[0].Substring(0, 2);
  19. return prefix + tmp[1];
  20. }
  21. return wtId;
  22. }
  23. public static string GetLongWindturbineId(String wtId)
  24. {
  25. String result = wtId.Substring(0, 2);
  26. result += "01_";
  27. result += wtId.Substring(2);
  28. return result;
  29. }
  30. public static string StringCopy(string src, int maxLen)
  31. {
  32. if (src.Length < maxLen)
  33. return src;
  34. else
  35. return src.Substring(0, maxLen);
  36. }
  37. #endregion
  38. #region 日期时间转换
  39. public static DateTime ConvertIntDateTime(long utc)
  40. {
  41. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
  42. startTime = startTime.AddMilliseconds(utc);
  43. //startTime = startTime.AddHours(8);
  44. return startTime;
  45. }
  46. public static long ConvertDateTimeInt(DateTime time)
  47. {
  48. long utc = 0;
  49. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
  50. utc = (long)(time - startTime).TotalMilliseconds;
  51. return utc;
  52. }
  53. public static DateTime GetQuarterFloor(DateTime time)
  54. {
  55. var m = time.Minute;
  56. if (m < 15)
  57. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "00:00");
  58. else if (m < 30)
  59. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "15:00");
  60. else if (m < 45)
  61. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "30:00");
  62. else
  63. return DateTime.Parse(time.ToString("yyyy-MM-dd HH:") + "45:00");
  64. }
  65. /// <summary>
  66. /// 返回日期几
  67. /// </summary>
  68. /// <returns></returns>
  69. public static string DayOfWeek(DateTime dt)
  70. {
  71. switch (dt.DayOfWeek.ToString("D"))
  72. {
  73. case "0":
  74. return "星期日 ";
  75. case "1":
  76. return "星期一 ";
  77. case "2":
  78. return "星期二 ";
  79. case "3":
  80. return "星期三 ";
  81. case "4":
  82. return "星期四 ";
  83. case "5":
  84. return "星期五 ";
  85. case "6":
  86. return "星期六 ";
  87. }
  88. return "";
  89. }
  90. #endregion
  91. /// <summary>
  92. /// 根据测点数据获取风机当前状态(八种状态)
  93. /// </summary>
  94. /// <param name="statusValue"></param>
  95. /// <returns></returns>
  96. public static WindturbineStatus GetWindturbineStatus(double statusValue)
  97. {
  98. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  99. if (statusValue == 0)
  100. return WindturbineStatus.Stop;
  101. else if (statusValue == 1)
  102. return WindturbineStatus.OnPower;
  103. else if (statusValue == 2)
  104. return WindturbineStatus.Standby;
  105. else if (statusValue == 3)
  106. return WindturbineStatus.Start;
  107. else if (statusValue == 4)
  108. return WindturbineStatus.Online;
  109. else if (statusValue == 5)
  110. return WindturbineStatus.Fault;
  111. else if (statusValue == 6)
  112. return WindturbineStatus.Maintain;
  113. else if (statusValue == 7)
  114. return WindturbineStatus.Offline;
  115. else
  116. return WindturbineStatus.UnKnow;
  117. }
  118. /// <summary>
  119. /// 根据测点数据获取风机当前状态(八种状态)
  120. /// </summary>
  121. /// <param name="statusValue"></param>
  122. /// <returns></returns>
  123. public static string GetWindturbineStatusString(double statusValue)
  124. {
  125. //0-停机-TJTS、 1-上电-SDTS、2-待机-DJTS、3-启动-QDTS、4-并网-BWTS、5-故障-GZTS、6-维护-WHTS、 7-离线-LXTS
  126. if (statusValue == 0)
  127. return "停机";
  128. else if (statusValue == 1)
  129. return "上电";
  130. else if (statusValue == 2)
  131. return "待机";
  132. else if (statusValue == 3)
  133. return "启动";
  134. else if (statusValue == 4)
  135. return "并网";
  136. else if (statusValue == 5)
  137. return "故障";
  138. else if (statusValue == 6)
  139. return "维护";
  140. else if (statusValue == 7)
  141. return "离线";
  142. else
  143. return "未知";
  144. }
  145. /// <summary>
  146. /// 获取限电受累信息(挂牌)
  147. /// </summary>
  148. /// <param name="lockValue"></param>
  149. /// <returns></returns>
  150. public static HungType GetHungLock(double lockValue)
  151. {
  152. // ;2, "场内受累检修";3, "场内受累故障";4, "场外受累电网";5, "场外受累天气";";7,"故障维修",8,"检修" 0正常
  153. if (lockValue == 0)
  154. return HungType.UnLock;
  155. else if (lockValue == 2)
  156. return HungType.StationCheckLock;
  157. else if (lockValue == 3)
  158. return HungType.StationFaulLockt;
  159. else if (lockValue == 4)
  160. return HungType.StationPowerLineLock;
  161. else if (lockValue == 5)
  162. return HungType.StationWeatherLock;
  163. else if (lockValue == 7)
  164. return HungType.FaultLock;
  165. else if (lockValue == 8)
  166. return HungType.CheckLock;
  167. else
  168. return HungType.UnKnow;
  169. }
  170. public static string GetHungLockString(double lockValue)
  171. {
  172. // ;2, "场内受累检修";3, "场内受累故障";4, "场外受累电网";5, "场外受累天气";";7,"故障维修",8,"检修" 0正常
  173. if (lockValue == 0)
  174. return "正常";
  175. else if (lockValue == 2)
  176. return "场内受累检修";
  177. else if (lockValue == 3)
  178. return "场内受累故障";
  179. else if (lockValue == 4)
  180. return "场外受累电网";
  181. else if (lockValue == 5)
  182. return "场外受累天气";
  183. else if (lockValue == 7)
  184. return "故障检修";
  185. else if (lockValue == 8)
  186. return "检修";
  187. else
  188. return "未知";
  189. }
  190. }
  191. }