コード例 #1
0
        /// <summary>
        /// 计算评分
        /// </summary>
        /// <param name="checkTypeKind">检查类型性质</param>
        /// <returns>经销商列表</returns>
        public List <Dealer> GetGrade(bool checkTypeKind = false)
        {
            DataTable calc = new DataTable();

            GetGradeLog = "";
            foreach (Dealer dealer in Dealers)
            {
                if (ReCordLog)
                {
                    GetGradeLog += string.Format(@"经销商信息:{0},{1},{2},{3}", dealer.DealerId, dealer.DealerName, dealer.DealerKind, dealer.DealerType);
                }
                foreach (ScoreGroup group in Scores)
                {
                    if (ReCordLog)
                    {
                        GetGradeLog += string.Format(@"评分组信息:{0},{1}", group.DealerIntranet, group.DealerType);
                    }
                    double totalScore = 0;
                    foreach (Score score in group.ScoreList)
                    {
                        if (ReCordLog)
                        {
                            GetGradeLog += string.Format(@"评分信息:{0},{1}", score.ScoreName, score.Expression);
                        }
                        score.RealScore = 0;
                        string tmpExpression = score.Expression;
                        foreach (Detail detail in score.DetailList)
                        {
                            detail.dataValue = 0;
                        }
                        foreach (Detail detail in score.DetailList)
                        {
                            if (ReCordLog)
                            {
                                GetGradeLog += string.Format(@"详细信息:{0}", detail.Rate);
                            }
                            foreach (Option option in detail.Options)
                            {
                                DealerData dealerData = dealer.DataList.FirstOrDefault(x => x.Variable == option.MatchingVariable);
                                switch (option.MatchingType)
                                {
                                case MatchingType.Range:
                                {
                                    if (dealerData == null || dealerData.Values == null)
                                    {
                                        continue;
                                    }
                                    double dataValue;
                                    if (double.TryParse(dealerData.Values.ToString(), out dataValue) == false)
                                    {
                                        continue;
                                    }
                                    if (option.RangeFrom <= dataValue && option.RangeTo > dataValue)
                                    {
                                        if (ReCordLog)
                                        {
                                            GetGradeLog += string.Format(@"匹配得分:{0},{1},{2},{3},{4},{5}", option.MatchingVariable, Enum.GetName(typeof(MatchingType), option.MatchingType), option.RangeFrom, option.RangeTo, option.Value, dealerData == null ? "null" : dealerData.Values);
                                        }
                                        detail.dataValue += option.Value;
                                    }
                                }
                                break;

                                case MatchingType.Exists:
                                {
                                    if (dealerData == null || dealerData.Values == null)
                                    {
                                        continue;
                                    }
                                    if (!string.IsNullOrWhiteSpace(dealerData.Values.ToString()))
                                    {
                                        if (ReCordLog)
                                        {
                                            GetGradeLog += string.Format(@"匹配得分:{0},{1},{2},{3}", option.MatchingVariable, Enum.GetName(typeof(MatchingType), option.MatchingType), option.Value, dealerData == null ? "null" : dealerData.Values);
                                        }
                                        detail.dataValue += option.Value;
                                    }
                                }
                                break;

                                case MatchingType.NotExists:
                                {
                                    if (dealerData == null || dealerData.Values == null || string.IsNullOrWhiteSpace(dealerData.Values.ToString()))
                                    {
                                        if (ReCordLog)
                                        {
                                            GetGradeLog += string.Format(@"匹配得分:{0},{1},{2}", option.MatchingVariable, Enum.GetName(typeof(MatchingType), option.MatchingType), option.Value);
                                        }
                                        detail.dataValue += option.Value;
                                    }
                                }
                                break;

                                case MatchingType.Equal:
                                {
                                    if (dealerData == null || dealerData.Values == null)
                                    {
                                        continue;
                                    }
                                    switch (dealerData.DealerDataType)
                                    {
                                    case DealerDataType.Single:
                                    {
                                        if (option.EqualText.ToLower() == dealerData.Values.ToString().ToLower())
                                        {
                                            if (ReCordLog)
                                            {
                                                GetGradeLog += string.Format(@"匹配得分:{0},{1},{2},{3},{4}", option.MatchingVariable, Enum.GetName(typeof(MatchingType), option.MatchingType), option.EqualText, option.Value, dealerData == null ? "null" : dealerData.Values);
                                            }
                                            detail.dataValue += option.Value;
                                        }
                                    }
                                    break;

                                    case DealerDataType.Array:
                                    {
                                        List <string> values = dealerData.Values as List <string>;
                                        if (values != null && values.FirstOrDefault(x => x.ToLower() == option.EqualText.ToLower()) != null)
                                        {
                                            string vvvv = "";
                                            foreach (var item in values)
                                            {
                                                vvvv += item + ",";
                                            }
                                            if (ReCordLog)
                                            {
                                                GetGradeLog += string.Format(@"匹配得分:{0},{1},{2},{3},{4}", option.MatchingVariable, Enum.GetName(typeof(MatchingType), option.MatchingType), option.EqualText, option.Value, vvvv);
                                            }
                                            detail.dataValue += option.Value;
                                        }
                                    }
                                    break;
                                    }
                                }
                                break;
                                }
                            }
                            if (ReCordLog)
                            {
                                GetGradeLog += string.Format(@"单项得分:{0}", detail.dataValue);
                            }
                        }

                        double tmpScore;
                        try
                        {
                            int startIndex = tmpExpression.IndexOf('{');
                            while (startIndex >= 0)
                            {
                                int    endIndex = tmpExpression.IndexOf('}', startIndex);
                                string varExp   = tmpExpression.Substring(startIndex + 1, endIndex - startIndex - 1);
                                Detail detail   = score.DetailList.FirstOrDefault(x => x.ObjectId == varExp);
                                tmpExpression = tmpExpression.Replace("{" + varExp + "}", detail == null ? "0" : (detail.dataValue * detail.Rate).ToString());
                                startIndex    = tmpExpression.IndexOf('{', startIndex + 1);
                            }

                            tmpExpression = DivisionZero(tmpExpression, score.DetailList);
                            object transcation = calc.Compute(tmpExpression, "");
                            tmpScore = double.Parse(transcation.ToString());
                        }
                        catch
                        {
                            tmpScore = 0;
                        }
                        if (ReCordLog)
                        {
                            GetGradeLog += string.Format(@"单组未加权得分:{0},{1}", score.ScoreName, tmpScore);
                        }
                        score.RealScore = tmpScore;
                        totalScore     += score.Weight * tmpScore / 100;
                        if (ReCordLog)
                        {
                            GetGradeLog += string.Format(@"单组得加权分:{0},{1},{2}", score.ScoreName, score.Weight, score.Weight * tmpScore / 100);
                        }
                    }
                    if (ReCordLog)
                    {
                        GetGradeLog += string.Format(@"总体得分:{0}", totalScore);
                    }
                    Grade grade = group.GradeList.FirstOrDefault(x => x.ScoreFrom <= totalScore && totalScore <= x.ScoreTo);
                    if (ReCordLog)
                    {
                        GetGradeLog += string.Format(@"匹配等级:{0}", grade == null ? "未匹配" : grade.Name + "," + grade.ScoreFrom + "," + grade.ScoreTo);
                    }
                    List <Score> ss = new List <Score>();
                    foreach (Score item in group.ScoreList)
                    {
                        ss.Add(new Score()
                        {
                            Expression = item.Expression, ObjectId = item.ObjectId, RealScore = item.RealScore, ScoreName = item.ScoreName, Weight = item.Weight
                        });
                    }
                    DealerResult dealerResult = new DealerResult()
                    {
                        DealerIntranet = group.DealerIntranet, DealerType = group.DealerType, ResultGrade = (grade ?? new Grade()
                        {
                            Name = ""
                        }).Name, TotalScore = totalScore, Scores = ss
                    };
                    dealer.ResultList.Add(dealerResult);
                }
                dealer.DataList = new List <DealerData>();
                if (checkTypeKind)
                {
                    for (int i = dealer.ResultList.Count - 1; i >= 0; i--)
                    {
                        if (dealer.DealerKind != null && dealer.DealerType != null && dealer.ResultList[i].DealerIntranet.ToLower() == dealer.DealerKind.ToLower() && dealer.ResultList[i].DealerType.ToLower() == dealer.DealerType.ToLower())
                        {
                            continue;
                        }
                        else
                        {
                            dealer.ResultList.RemoveAt(i);
                        }
                    }
                    while (dealer.ResultList.Count > 1)
                    {
                        dealer.ResultList.RemoveAt(dealer.ResultList.Count - 1);
                    }
                }

                string scoreLog = "";
                foreach (var res in dealer.ResultList)
                {
                    scoreLog += "    " + res.DealerIntranet + "|" + res.DealerType + "[" + res.TotalScore + "|" + res.ResultGrade + "]{";
                    foreach (var score in res.Scores)
                    {
                        scoreLog += "(" + score.ScoreName + "|" + score.RealScore + ")";
                    }
                    scoreLog += @"
";
                }
                if (ReCordLog)
                {
                    GetGradeLog += string.Format(@"经销商最终得分:{0},{1}{2}", dealer.DealerName, dealer.DealerId, scoreLog);
                }
            }
            return(Dealers);
        }
コード例 #2
0
 /// <summary>
 /// 读取评分结构
 /// </summary>
 /// <param name="row">行数据</param>
 /// <param name="structNames">字段结构</param>
 public void PushScoreIntoGroup(DataRow row, StructNames structNames)
 {
     try
     {
         ScoreGroup group = Scores.FirstOrDefault(x => x.ObjectId == row[structNames.GroupNames.ObjectId].ToString());
         if (group == null)
         {
             group = new ScoreGroup()
             {
                 ObjectId       = row[structNames.GroupNames.ObjectId].ToString(),
                 DealerIntranet = row[structNames.GroupNames.DealerIntranet].ToString(),
                 DealerType     = row[structNames.GroupNames.DealerType].ToString()
             };
             Scores.Add(group);
         }
         Score score = group.ScoreList.FirstOrDefault(x => x.ObjectId == row[structNames.ScoreNames.ObjectId].ToString());
         if (score == null)
         {
             float weight;
             if (!float.TryParse(row[structNames.ScoreNames.Weight].ToString(), out weight))
             {
                 weight = 0;
             }
             score = new Score()
             {
                 ObjectId   = row[structNames.ScoreNames.ObjectId].ToString(),
                 Expression = row[structNames.ScoreNames.Expression].ToString(),
                 ScoreName  = row[structNames.ScoreNames.ScoreName].ToString(),
                 Weight     = weight
             };
             group.ScoreList.Add(score);
         }
         Detail detail = score.DetailList.FirstOrDefault(x => x.ObjectId == row[structNames.DetailNames.ObjectId].ToString());
         if (detail == null)
         {
             float rate;
             if (!float.TryParse(row[structNames.DetailNames.Rate].ToString(), out rate))
             {
                 rate = 0;
             }
             detail = new Detail()
             {
                 ObjectId = row[structNames.DetailNames.ObjectId].ToString(),
                 Rate     = rate
             };
             score.DetailList.Add(detail);
         }
         Option option = detail.Options.FirstOrDefault(x => x.ObjectId == row[structNames.OptionNames.ObjectId].ToString());
         if (option == null)
         {
             double value;
             if (!double.TryParse(row[structNames.OptionNames.Value].ToString(), out value))
             {
                 value = 0;
             }
             option = new Option()
             {
                 ObjectId = row[structNames.OptionNames.ObjectId].ToString(),
                 Memo     = row[structNames.OptionNames.Memo].ToString(),
                 Value    = value
             };
             detail.Options.Add(option);
         }
     }
     catch (Exception ex)
     {
         Scores = new List <ScoreGroup>();
     }
 }