Utility.cs 8.3 KB

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