Utility.cs 6.8 KB

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