AdviceService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.Model;
  7. using System.ServiceModel.Activation;
  8. using log4net;
  9. using GDNXFD.Data.Repositories;
  10. namespace GDNXFD.WcfService
  11. {
  12. public class AdviceService : IAdviceService
  13. {
  14. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  15. public bool ExecuteAdvice(IList<AdviceModel> executeList,string userId,string userName)
  16. {
  17. try
  18. {
  19. for (int i = 0; i < executeList.Count; i++)
  20. {
  21. AdviceModel m = AdviceCache.Instance.AdviceList.Where(s => s.WindturbineId == executeList[i].WindturbineId).FirstOrDefault();
  22. if (m != null && m.Status == 1)
  23. {
  24. //如果用户执行推荐动作
  25. if (executeList[i].Status == 2)
  26. {
  27. m.Status = executeList[i].Status;
  28. m.ExecuteTime = executeList[i].ExecuteTime;
  29. m.ExecuteOperation = m.AdviseOperation;
  30. m.Operater = executeList[i].Operater;
  31. AdviceCache.Instance.UpdateAdviceModelHistory(m.WindturbineId,2,userName,userId);
  32. }
  33. //如果用户取消推荐动作
  34. else if (executeList[i].Status == 3)
  35. {
  36. m.Status = executeList[i].Status;
  37. m.ExecuteTime = executeList[i].ExecuteTime;
  38. m.ExecuteOperation = OperateStyle.Unknow;
  39. m.Operater = executeList[i].Operater;
  40. AdviceCache.Instance.UpdateAdviceModelHistory(m.WindturbineId, 3, userName, userId);
  41. }
  42. }
  43. }
  44. Console.WriteLine("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
  45. IList<AdviceModel> cancelList = AdviceCache.Instance.AdviceList.Where(s => s.Status == 3).ToList();
  46. IList<AdviceModel> doItList = AdviceCache.Instance.AdviceList.Where(s => s.Status == 2).ToList();
  47. for (int i = 0; i < cancelList.Count; i++)
  48. {
  49. Console.WriteLine(cancelList[i].WindturbineId + "-" + cancelList[i].Status + "-取消时间" + (cancelList[i].ExecuteTime.HasValue ? cancelList[i].ExecuteTime.Value.ToString() : "") + "-建议动作:" + cancelList[i].AdviseOperation.ToString() + "-实际动作" + cancelList[i].ExecuteOperation.ToString());
  50. }
  51. Console.WriteLine("-----------------------------");
  52. for (int i = 0; i < doItList.Count; i++)
  53. {
  54. Console.WriteLine(doItList[i].WindturbineId + "-" + doItList[i].Status + "-执行时间" + (doItList[i].ExecuteTime.HasValue ? doItList[i].ExecuteTime.Value.ToString() : "") + "-建议动作:" + doItList[i].AdviseOperation.ToString() + "-实际动作" + doItList[i].ExecuteOperation.ToString());
  55. }
  56. Console.WriteLine("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
  57. }
  58. catch (Exception ex)
  59. {
  60. throw;
  61. }
  62. return true;
  63. }
  64. public IList<AdviceModel> GetAdvice(string stationId, OperateStyle? adviseOperation = null)
  65. {
  66. var tmp = AdviceCache.Instance.AdviceList;
  67. if (tmp != null && tmp.Count > 0)
  68. {
  69. var r1 = tmp.AsQueryable().Where(s => s.Status == 1);
  70. if (!string.IsNullOrWhiteSpace(stationId))
  71. {
  72. r1 = r1.Where(q => q.StationId == stationId);
  73. }
  74. if (adviseOperation.HasValue)
  75. {
  76. r1 = r1.Where(q => q.AdviseOperation == adviseOperation);
  77. }
  78. IList<AdviceModel> lst = r1.ToList();
  79. return lst;
  80. }
  81. return null;
  82. }
  83. public IList<AdviceHistoryModel> GetAdviceHistoryPage(string filter, int pageIndex, int pageSize, ref int total)
  84. {
  85. IList<AdviceHistoryModel> list = new List<AdviceHistoryModel>();
  86. list = AdviceHistoryModelRepository.GetHistoryList(filter, pageIndex, pageSize, ref total);
  87. return list;
  88. }
  89. public string GetTest(string s)
  90. {
  91. string ss = s + "响应内容" + DateTime.Now.ToString(); ;
  92. return ss;
  93. }
  94. }
  95. }