123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- 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<BasePointRule> 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<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(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<ItemStaff>(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<string> GetDoItemCeofficient(PerformanceItem item, List<BasePointRule> rules)
- {
- List<string> retList = new List<string>();
- 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<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
- bool result = func.Invoke(item);
- if (result)
- {
- if (!retList.Contains(strFeedback))
- {
- retList.Add(strFeedback);
- }
- }
- }
- }
- }
- return retList;
- }
- public static List<string> GetFeedbackMemos(PerformanceItem item, List<BasePointRule> rules)
- {
- List<string> retList = new List<string>();
- 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<PerformanceItem, bool> func = interpreter.ParseAsDelegate<Func<PerformanceItem, bool>>(temRule, "p");
- bool result = func.Invoke(item);
- if (result)
- {
- if (!retList.Contains(strFeedback))
- {
- retList.Add(strFeedback);
- }
- }
- }
- }
- }
- return retList;
- }
-
- }
- }
|