Utility.cs 8.5 KB

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