using DynamicExpresso; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using wispro.sp.entity; namespace wispro.sp.api.Utility { public class Utility { public static void CalBasePoint(PerformanceItem item, List rules) { #region 计算基本点数值及绩效类型 rules.Sort((a, b) => { var o = b.Priority - a.Priority; return o; }); foreach (BasePointRule rule in rules) { var options = InterpreterOptions.Default | InterpreterOptions.LambdaExpressions; var interpreter = new Interpreter(options) .Reference(typeof(System.Linq.Enumerable)); System.Diagnostics.Debug.WriteLine(rule.Rule); try { //item.ApplicationType Func func = interpreter.ParseAsDelegate>(rule.Rule, "p"); bool result = func.Invoke(item); if (result) { var temString = rule.PointExpress; if (!rule.PointExpress.Contains(".")) { temString = $"{rule.PointExpress.Trim()}.0"; } var target = new Interpreter().SetVariable("p", item); item.BasePoint = (double?)target.Eval(temString); item.Type = rule.Type; break; } } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } #endregion if(item.DoItem =="处理审查意见" && item.ApplicationType == "发明" && item.PreOastaffId != null) { if(item.ItemStaffs.Where(s=>s.DoPersonId == item.PreOastaffId).Count() == 0) { switch (item.DoItemCoefficient) { case "实质": item.BasePoint = 0.5; break; case "形式": item.BasePoint = 0.2; break; case "非实质": item.BasePoint = 0.3; break; } } } } public static List GetDoItemCeofficient(PerformanceItem item, List rules) { List retList = new List(); foreach (BasePointRule rule in rules) { Regex r = new System.Text.RegularExpressions.Regex("p.DoItemCoefficient\\s{0,}==\\s{0,}\"(.+?)\""); Match m = r.Match(rule.Rule); if (m.Success) { string strFeedback = m.Groups[1].Value; string temRule = rule.Rule.Replace(m.Value, ""); if (string.IsNullOrEmpty(temRule.Trim())) { continue; } else { r = new Regex("&&\\s{1,}&&"); m = r.Match(temRule); if (m.Success) { temRule = temRule.Replace(m.Value, "&&"); } if (temRule.Trim().EndsWith("&&")) { temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim(); } if (temRule.Trim().StartsWith("&&")) { temRule = temRule.Substring(2).Trim(); } var interpreter = new Interpreter(); //item.ApplicationType Func func = interpreter.ParseAsDelegate>(temRule, "p"); bool result = func.Invoke(item); if (result) { if (!retList.Contains(strFeedback)) { retList.Add(strFeedback); } } } } } return retList; } public static List GetFeedbackMemos(PerformanceItem item, List rules) { List retList = new List(); foreach(BasePointRule rule in rules) { Regex r= new System.Text.RegularExpressions.Regex("p.AgentFeedbackMemo==\"(.+?)\""); Match m = r.Match(rule.Rule); if (m.Success) { string strFeedback = m.Groups[1].Value; string temRule = rule.Rule.Replace(m.Value, ""); if (string.IsNullOrEmpty(temRule.Trim())) { if (!retList.Contains(strFeedback)) { retList.Add(strFeedback); } } else { r = new Regex("&&\\s{1,}&&"); m = r.Match(temRule); if (m.Success) { temRule = temRule.Replace(m.Value, "&&"); } if (temRule.Trim().EndsWith("&&")) { temRule = temRule.Trim().Substring(0, temRule.Trim().Length - 2).Trim(); } if (temRule.Trim().StartsWith("&&")) { temRule = temRule.Substring(2).Trim(); } var interpreter = new Interpreter(); //item.ApplicationType Func func = interpreter.ParseAsDelegate>(temRule, "p"); bool result = func.Invoke(item); if (result) { if (!retList.Contains(strFeedback)) { retList.Add(strFeedback); } } } } } return retList; } } }