DefectBillService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GDNXFD.Data;
  7. using log4net;
  8. namespace GDNXFD.WcfService
  9. {
  10. public class DefectBillService : IDefectBillService
  11. {
  12. ILog logger = LogManager.GetLogger("AppLog");
  13. public bool DefectBill(FaultInfo info, string alertText, string userName)
  14. {
  15. try
  16. {
  17. //数据格式:时间(yyyy-MM-dd hh:mm:ss)|场站ID|风机ID|故障类型|报警内容|操作员|故障编码
  18. //string msg = "2019-06-21 12:30:00|MHS_FDC|MG01_01|FJ|故障停机|徐瑞|5001";
  19. if (info == null || String.IsNullOrWhiteSpace(userName))
  20. return false;
  21. logger.Info("1");
  22. StringBuilder sbMsg = new StringBuilder();
  23. sbMsg.Append(info.AlertTime.ToString("yyyy-MM-dd hh:mm:ss"));
  24. logger.Info("2");
  25. sbMsg.Append('|');
  26. sbMsg.Append(info.StationId);
  27. sbMsg.Append('|');
  28. sbMsg.Append(info.WindturbineId);
  29. sbMsg.Append('|');
  30. sbMsg.Append(info.Category1);
  31. sbMsg.Append('|');
  32. sbMsg.Append(alertText);
  33. sbMsg.Append('|');
  34. sbMsg.Append(userName);
  35. sbMsg.Append('|');
  36. sbMsg.Append(info.AlertValue);
  37. byte[] msgB = System.Text.Encoding.UTF8.GetBytes(sbMsg.ToString());
  38. logger.Info(DateTime.Now.ToString() + "===接收数据" + msgB);
  39. System.Diagnostics.Debug.WriteLine(msgB + "===接收数据");
  40. SocetClient.Instance.Send(msgB);
  41. logger.Info(DateTime.Now.ToString()+ "===发送数据完成" + msgB );
  42. System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + "===发送数据完成" + msgB);
  43. }
  44. catch (Exception ex)
  45. {
  46. logger.Info(ex.ToString());
  47. System.Diagnostics.Debug.WriteLine(ex.ToString());
  48. return false;
  49. //
  50. }
  51. return true;
  52. }
  53. }
  54. }