Utility.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. System.Diagnostics.Debug.WriteLine($"{rule.Rule}\t{ex.Message}" );
  84. }
  85. }
  86. #endregion
  87. }
  88. public static List<string> GetDoItemCeofficient(PerformanceItem item, List<BasePointRule> rules)
  89. {
  90. List<string> retList = new List<string>();
  91. foreach (BasePointRule rule in rules)
  92. {
  93. Regex r = new System.Text.RegularExpressions.Regex("p.DoItemCoefficient\\s{0,}==\\s{0,}\"(.+?)\"");
  94. Match m = r.Match(rule.Rule);
  95. if (m.Success)
  96. {
  97. string strFeedback = m.Groups[1].Value;
  98. string temRule = rule.Rule.Replace(m.Value, "");
  99. if (string.IsNullOrEmpty(temRule.Trim()))
  100. {
  101. continue;
  102. }
  103. else
  104. {
  105. r = new Regex("&&\\s{1,}&&");
  106. m = r.Match(temRule);
  107. if (m.Success)
  108. {
  109. temRule = temRule.Replace(m.Value, "&&");
  110. }
  111. if (temRule.Trim().EndsWith("&&"))
  112. {
  113. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  114. }
  115. if (temRule.Trim().StartsWith("&&"))
  116. {
  117. temRule = temRule.Substring(2).Trim();
  118. }
  119. var interpreter = new Interpreter();
  120. //item.ApplicationType
  121. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  122. bool result = func.Invoke(item);
  123. if (result)
  124. {
  125. if (!retList.Contains(strFeedback))
  126. {
  127. retList.Add(strFeedback);
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return retList;
  134. }
  135. public static List<string> GetFeedbackMemos(PerformanceItem item, List<BasePointRule> rules)
  136. {
  137. List<string> retList = new List<string>();
  138. foreach(BasePointRule rule in rules)
  139. {
  140. Regex r= new System.Text.RegularExpressions.Regex("p.AgentFeedbackMemo==\"(.+?)\"");
  141. Match m = r.Match(rule.Rule);
  142. if (m.Success)
  143. {
  144. string strFeedback = m.Groups[1].Value;
  145. string temRule = rule.Rule.Replace(m.Value, "");
  146. if (string.IsNullOrEmpty(temRule.Trim()))
  147. {
  148. if (!retList.Contains(strFeedback))
  149. {
  150. retList.Add(strFeedback);
  151. }
  152. }
  153. else
  154. {
  155. r = new Regex("&&\\s{1,}&&");
  156. m = r.Match(temRule);
  157. if (m.Success)
  158. {
  159. temRule = temRule.Replace(m.Value, "&&");
  160. }
  161. if (temRule.Trim().EndsWith("&&"))
  162. {
  163. temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim();
  164. }
  165. if (temRule.Trim().StartsWith("&&"))
  166. {
  167. temRule = temRule.Substring(2).Trim();
  168. }
  169. var interpreter = new Interpreter();
  170. //item.ApplicationType
  171. Func<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
  172. bool result = func.Invoke(item);
  173. if (result)
  174. {
  175. if (!retList.Contains(strFeedback))
  176. {
  177. retList.Add(strFeedback);
  178. }
  179. }
  180. }
  181. }
  182. }
  183. return retList;
  184. }
  185. }
  186. }