Utility.cs 7.8 KB

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