Utility.cs 7.0 KB

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