Utility.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions;
  23. var interpreter = new Interpreter(options)
  24. .Reference(typeof(System.Linq.Enumerable));
  25. //System.Diagnostics.Debug.WriteLine(rule.Rule);
  26. try
  27. {
  28. //item.ApplicationType
  29. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(rule.Rule, "p");
  30. bool result = func.Invoke(item);
  31. if (result)
  32. {
  33. var temString = rule.PointExpress;
  34. if (!rule.PointExpress.Contains("."))
  35. {
  36. temString = $"{rule.PointExpress.Trim()}.0";
  37. }
  38. item.BasePoint = (double?)interpreter.Eval(temString);
  39. item.Type = rule.Type;
  40. break;
  41. }
  42. }
  43. catch(Exception ex) {
  44. System.Diagnostics.Debug.WriteLine(ex.Message);
  45. }
  46. }
  47. #endregion
  48. }
  49. public static List<string> GetDoItemCeofficient(PerformanceItem item, List<BasePointRule> rules)
  50. {
  51. List<string> retList = new List<string>();
  52. foreach (BasePointRule rule in rules)
  53. {
  54. Regex r = new System.Text.RegularExpressions.Regex("p.DoItemCoefficient\\s{0,}==\\s{0,}\"(.+?)\"");
  55. Match m = r.Match(rule.Rule);
  56. if (m.Success)
  57. {
  58. string strFeedback = m.Groups[1].Value;
  59. string temRule = rule.Rule.Replace(m.Value, "");
  60. if (string.IsNullOrEmpty(temRule.Trim()))
  61. {
  62. continue;
  63. }
  64. else
  65. {
  66. r = new Regex("&&\\s{1,}&&");
  67. m = r.Match(temRule);
  68. if (m.Success)
  69. {
  70. temRule = temRule.Replace(m.Value, "&&");
  71. }
  72. if (temRule.Trim().EndsWith("&&"))
  73. {
  74. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  75. }
  76. if (temRule.Trim().StartsWith("&&"))
  77. {
  78. temRule = temRule.Substring(2).Trim();
  79. }
  80. var interpreter = new Interpreter();
  81. //item.ApplicationType
  82. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  83. bool result = func.Invoke(item);
  84. if (result)
  85. {
  86. if (!retList.Contains(strFeedback))
  87. {
  88. retList.Add(strFeedback);
  89. }
  90. }
  91. }
  92. }
  93. }
  94. return retList;
  95. }
  96. public static List<string> GetFeedbackMemos(PerformanceItem item, List<BasePointRule> rules)
  97. {
  98. List<string> retList = new List<string>();
  99. foreach(BasePointRule rule in rules)
  100. {
  101. Regex r= new System.Text.RegularExpressions.Regex("p.AgentFeedbackMemo==\"(.+?)\"");
  102. Match m = r.Match(rule.Rule);
  103. if (m.Success)
  104. {
  105. string strFeedback = m.Groups[1].Value;
  106. string temRule = rule.Rule.Replace(m.Value, "");
  107. if (string.IsNullOrEmpty(temRule.Trim()))
  108. {
  109. if (!retList.Contains(strFeedback))
  110. {
  111. retList.Add(strFeedback);
  112. }
  113. }
  114. else
  115. {
  116. r = new Regex("&&\\s{1,}&&");
  117. m = r.Match(temRule);
  118. if (m.Success)
  119. {
  120. temRule = temRule.Replace(m.Value, "&&");
  121. }
  122. if (temRule.Trim().EndsWith("&&"))
  123. {
  124. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  125. }
  126. if (temRule.Trim().StartsWith("&&"))
  127. {
  128. temRule = temRule.Substring(2).Trim();
  129. }
  130. var interpreter = new Interpreter();
  131. //item.ApplicationType
  132. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  133. bool result = func.Invoke(item);
  134. if (result)
  135. {
  136. if (!retList.Contains(strFeedback))
  137. {
  138. retList.Add(strFeedback);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. return retList;
  145. }
  146. }
  147. }