123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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 interpreter = new Interpreter();
- //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";
- }
- item.BasePoint = (double?)interpreter.Eval(temString);
- item.Type = rule.Type;
- break;
- }
- }
- #endregion
- }
- 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;
- }
-
- }
- }
|