Utility.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using DynamicExpresso;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using wispro.sp.entity;
  8. namespace wispro.sp.api.Utility
  9. {
  10. public class Utility
  11. {
  12. public static void CalBasePoint(PerformanceItem item, List<BasePointRule> rules)
  13. {
  14. #region 计算基本点数值及绩效类型
  15. rules.Sort((a, b) =>
  16. {
  17. var o = b.Priority - a.Priority;
  18. return o;
  19. });
  20. foreach (BasePointRule rule in rules)
  21. {
  22. var interpreter = new Interpreter();
  23. //item.ApplicationType
  24. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  25. bool result = func.Invoke(item);
  26. if (result)
  27. {
  28. var temString = rule.PointExpress;
  29. if (!rule.PointExpress.Contains("."))
  30. {
  31. temString = $"{rule.PointExpress.Trim()}.0";
  32. }
  33. item.BasePoint = (double?)interpreter.Eval(temString);
  34. item.Type = rule.Type;
  35. break;
  36. }
  37. }
  38. #endregion
  39. }
  40. public static List<string> GetDoItemCeofficient(PerformanceItem item, List<BasePointRule> rules)
  41. {
  42. List<string> retList = new List<string>();
  43. foreach (BasePointRule rule in rules)
  44. {
  45. Regex r = new System.Text.RegularExpressions.Regex("p.DoItemCoefficient\\s{0,}==\\s{0,}\"(.+?)\"");
  46. Match m = r.Match(rule.Rule);
  47. if (m.Success)
  48. {
  49. string strFeedback = m.Groups[1].Value;
  50. string temRule = rule.Rule.Replace(m.Value, "");
  51. if (string.IsNullOrEmpty(temRule.Trim()))
  52. {
  53. continue;
  54. }
  55. else
  56. {
  57. r = new Regex("&&\\s{1,}&&");
  58. m = r.Match(temRule);
  59. if (m.Success)
  60. {
  61. temRule = temRule.Replace(m.Value, "&&");
  62. }
  63. if (temRule.Trim().EndsWith("&&"))
  64. {
  65. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  66. }
  67. if (temRule.Trim().StartsWith("&&"))
  68. {
  69. temRule = temRule.Substring(2).Trim();
  70. }
  71. var interpreter = new Interpreter();
  72. //item.ApplicationType
  73. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  74. bool result = func.Invoke(item);
  75. if (result)
  76. {
  77. if (!retList.Contains(strFeedback))
  78. {
  79. retList.Add(strFeedback);
  80. }
  81. }
  82. }
  83. }
  84. }
  85. return retList;
  86. }
  87. public static List<string> GetFeedbackMemos(PerformanceItem item, List<BasePointRule> rules)
  88. {
  89. List<string> retList = new List<string>();
  90. foreach(BasePointRule rule in rules)
  91. {
  92. Regex r= new System.Text.RegularExpressions.Regex("p.AgentFeedbackMemo==\"(.+?)\"");
  93. Match m = r.Match(rule.Rule);
  94. if (m.Success)
  95. {
  96. string strFeedback = m.Groups[1].Value;
  97. string temRule = rule.Rule.Replace(m.Value, "");
  98. if (string.IsNullOrEmpty(temRule.Trim()))
  99. {
  100. if (!retList.Contains(strFeedback))
  101. {
  102. retList.Add(strFeedback);
  103. }
  104. }
  105. else
  106. {
  107. r = new Regex("&&\\s{1,}&&");
  108. m = r.Match(temRule);
  109. if (m.Success)
  110. {
  111. temRule = temRule.Replace(m.Value, "&&");
  112. }
  113. if (temRule.Trim().EndsWith("&&"))
  114. {
  115. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  116. }
  117. if (temRule.Trim().StartsWith("&&"))
  118. {
  119. temRule = temRule.Substring(2).Trim();
  120. }
  121. var interpreter = new Interpreter();
  122. //item.ApplicationType
  123. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  124. bool result = func.Invoke(item);
  125. if (result)
  126. {
  127. if (!retList.Contains(strFeedback))
  128. {
  129. retList.Add(strFeedback);
  130. }
  131. }
  132. }
  133. }
  134. }
  135. return retList;
  136. }
  137. }
  138. }