Utility.cs 8.0 KB

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