Utility.cs 7.2 KB

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