Utility.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. if ((item.CaseNo.ToUpper().StartsWith("S") && item.Type == "专案") || item.AgentFeedbackMemo == "特殊点数申诉")
  15. {
  16. return;
  17. }
  18. #region 计算基本点数值及绩效类型
  19. rules.Sort((a, b) =>
  20. {
  21. var o = b.Priority - a.Priority;
  22. return o;
  23. });
  24. if (item.Customer.Name.Contains("宁德") && item.DoItem == "新申请")
  25. {
  26. Console.WriteLine("");
  27. }
  28. foreach (BasePointRule rule in rules)
  29. {
  30. var options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions;
  31. var interpreter = new Interpreter(options)
  32. .Reference(typeof(System.Linq.Enumerable));
  33. try
  34. {
  35. Func<PerformanceItem, Customer, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, Customer, bool>>(rule.Rule, "p", "Customer");
  36. bool result = func.Invoke(item, item.Customer);
  37. if (result)
  38. {
  39. var temString = rule.PointExpress;
  40. if (!rule.PointExpress.Contains("."))
  41. {
  42. temString = $"{rule.PointExpress.Trim()}.0";
  43. }
  44. var target = new Interpreter().SetVariable("p", item);
  45. double? temPoint = (double?)target.Eval(temString);
  46. string temType = rule.Type;
  47. if (temString.Contains("p.WordCount") && item.DoItem == "新申请" && temPoint.HasValue)
  48. {
  49. switch (item.DoItemCoefficient)
  50. {
  51. case "中-德":
  52. if (1.9 > temPoint.Value)
  53. {
  54. temType = "新申请";
  55. temPoint = 1.9;
  56. }
  57. break;
  58. case "中-英":
  59. if (1.8 > temPoint.Value)
  60. {
  61. temType = "新申请";
  62. temPoint = 1.8;
  63. }
  64. break;
  65. case "英-中":
  66. if (1.5 > temPoint.Value)
  67. {
  68. temType = "新申请";
  69. temPoint = 1.5;
  70. }
  71. break;
  72. }
  73. }
  74. if (item.BasePoint != temPoint || item.Type != temType)
  75. {
  76. item.BasePoint = temPoint;
  77. item.Type = temType;
  78. }
  79. break;
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. System.Diagnostics.Debug.WriteLine($"{rule.Rule}\t{ex.Message}");
  85. }
  86. }
  87. #endregion
  88. }
  89. public static List<string> GetDoItemCeofficient(PerformanceItem item, List<BasePointRule> rules)
  90. {
  91. List<string> retList = new List<string>();
  92. foreach (BasePointRule rule in rules)
  93. {
  94. Regex r = new System.Text.RegularExpressions.Regex("p.DoItemCoefficient\\s{0,}==\\s{0,}\"(.+?)\"");
  95. Match m = r.Match(rule.Rule);
  96. if (m.Success)
  97. {
  98. string strFeedback = m.Groups[1].Value;
  99. string temRule = rule.Rule.Replace(m.Value, "");
  100. if (string.IsNullOrEmpty(temRule.Trim()))
  101. {
  102. continue;
  103. }
  104. else
  105. {
  106. r = new Regex("&&\\s{1,}&&");
  107. m = r.Match(temRule);
  108. if (m.Success)
  109. {
  110. temRule = temRule.Replace(m.Value, "&&");
  111. }
  112. if (temRule.Trim().EndsWith("&&"))
  113. {
  114. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  115. }
  116. if (temRule.Trim().StartsWith("&&"))
  117. {
  118. temRule = temRule.Substring(2).Trim();
  119. }
  120. var interpreter = new Interpreter();
  121. //item.ApplicationType
  122. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  123. bool result = func.Invoke(item);
  124. if (result)
  125. {
  126. if (!retList.Contains(strFeedback))
  127. {
  128. retList.Add(strFeedback);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. return retList;
  135. }
  136. public static List<string> GetFeedbackMemos(PerformanceItem item, List<BasePointRule> rules)
  137. {
  138. List<string> retList = new List<string>();
  139. foreach (BasePointRule rule in rules)
  140. {
  141. Regex r = new System.Text.RegularExpressions.Regex("p.AgentFeedbackMemo==\"(.+?)\"");
  142. Match m = r.Match(rule.Rule);
  143. if (m.Success)
  144. {
  145. string strFeedback = m.Groups[1].Value;
  146. string temRule = rule.Rule.Replace(m.Value, "");
  147. if (string.IsNullOrEmpty(temRule.Trim()))
  148. {
  149. if (!retList.Contains(strFeedback))
  150. {
  151. retList.Add(strFeedback);
  152. }
  153. }
  154. else
  155. {
  156. r = new Regex("&&\\s{1,}&&");
  157. m = r.Match(temRule);
  158. if (m.Success)
  159. {
  160. temRule = temRule.Replace(m.Value, "&&");
  161. }
  162. if (temRule.Trim().EndsWith("&&"))
  163. {
  164. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  165. }
  166. if (temRule.Trim().StartsWith("&&"))
  167. {
  168. temRule = temRule.Substring(2).Trim();
  169. }
  170. var interpreter = new Interpreter();
  171. //item.ApplicationType
  172. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  173. bool result = func.Invoke(item);
  174. if (result)
  175. {
  176. if (!retList.Contains(strFeedback))
  177. {
  178. retList.Add(strFeedback);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. return retList;
  185. }
  186. }
  187. }