/// <summary>
        /// 作用:更新名单
        /// 作者:汪建龙
        /// 编写时间:2017年3月7日20:23:56
        /// </summary>
        /// <param name="id"></param>
        /// <param name="systemData"></param>
        /// <param name="degree"></param>
        /// <returns></returns>
        public string Update(int id, SystemData systemData, CreditDegree degree)
        {
            if (degree == CreditDegree.Good)
            {
                return(null);;
            }
            string error = string.Empty;
            var    model = Db.Rolls.FirstOrDefault(e => e.DataId == id && e.SystemData == systemData);

            if (model == null)
            {
                model = new Roll {
                    DataId = id, SystemData = systemData, BREnum = degree == CreditDegree.Less?BREnum.Red:BREnum.Black
                };
                var rid = Save(model);
                if (rid <= 0)
                {
                    error = "添加名单";
                }
            }
            else
            {
                if (model.BREnum == BREnum.Red && degree == CreditDegree.Bad)
                {
                    model.BREnum = BREnum.Black;
                    if (!Edit(model))
                    {
                        error = "更新名单";
                    }
                }
            }
            return(error);
        }
        /// <summary>
        /// 作用:更新诚信次数
        /// 作者:汪建龙
        /// 编写时间:2017年3月7日10:25:58
        /// </summary>
        /// <param name="dataId">对应的Id</param>
        /// <param name="degree">诚信、失信、严重失信</param>
        /// <param name="systemData">企业还是自然人</param>
        /// <param name="IsAdd">是否增加</param>
        /// <returns></returns>
        public bool UpdateCredit(int dataId, CreditDegree degree, SystemData systemData, bool IsAdd)
        {
            if (systemData == SystemData.Enterprise)
            {
                return(UpdateCreditEnterprise(dataId, degree, IsAdd));
            }

            return(UpdateCreditLawyer(dataId, degree, IsAdd));
        }
        private bool UpdateCreditLawyer(int id, CreditDegree degree, bool IsAdd)
        {
            var lawyer = Core.LawyerManager.Get(id);

            if (lawyer == null)
            {
                return(false);
            }
            if (IsAdd)
            {
                lawyer = AddCredit <Lawyer>(lawyer, degree);
            }
            else
            {
                lawyer = ReduceCredit <Lawyer>(lawyer, degree);
            }

            return(Core.LawyerManager.Edit(lawyer));
        }
        private bool UpdateCreditEnterprise(int id, CreditDegree degree, bool IsAdd)
        {
            var enterprise = Core.EnterpriseManager.Get(id);

            if (enterprise == null)
            {
                return(false);
            }
            if (IsAdd)
            {
                enterprise = AddCredit <Enterprise>(enterprise, degree);
            }
            else
            {
                enterprise = ReduceCredit <Enterprise>(enterprise, degree);
            }

            return(Core.EnterpriseManager.Edit(enterprise));
        }
        private T ReduceCredit <T>(T entey, CreditDegree degree) where T : ScoreBase
        {
            if (entey == null)
            {
                return(null);
            }
            switch (degree)
            {
            case CreditDegree.Bad:
                entey.Bad--;
                break;

            case CreditDegree.Good:
                entey.Good--;
                break;

            case CreditDegree.Less:
                entey.Less--;
                break;
            }
            return(entey);
        }
Example #6
0
        //public List<Daily> GradeEnterprise(DateTime BeginTime,int userId,List<Grade> grades)
        //{
        //    var dailys = new List<Daily>();
        //    var list = Core.EnterpriseManager.Search(new Parameters.EnterpriseParameter());
        //    foreach(var item in list)
        //    {
        //        var grade = Analyze(grades, BeginTime,SystemData.Enterprise,item.ID);
        //        if (grade == null)
        //        {
        //            dailys.Add(new Daily { Name = "信用评级", Description = string.Format("企业:{0}没有得到评级结果", item.Name), UserID = userId });
        //            continue;
        //        }
        //        item.Level = grade.Name;
        //        item.LevelDescription = grade.Content;
        //        item.GradeTime = DateTime.Now;
        //        if (!Core.EnterpriseManager.Edit(item))
        //        {
        //            dailys.Add(new Daily { Name = "信用评级", Description = string.Format("企业:{0}得到满足{1}的{2},但是更新失败", item.Name, grade.Content, grade.Name),UserID=userId });
        //        }
        //    }
        //    return dailys;
        //}
        //public List<Daily> GradeLawyer(DateTime BeginTime,int userId,List<Grade> grades)
        //{
        //    var dailys = new List<Daily>();
        //    var list = Core.LawyerManager.Search(new Parameters.LawyerParameter());
        //    foreach(var item in list)
        //    {
        //        var grade = Analyze(grades, BeginTime, SystemData.Lawyer, item.ID);
        //        if (grade == null)
        //        {
        //            dailys.Add(new Daily { Name = "信用评级", Description = string.Format("自然人:{0}没有得到评级结果", item.Name), UserID = userId });
        //            continue;
        //        }
        //        item.Level = grade.Name;
        //        item.LevelDescription = grade.Content;
        //        item.GradeTime = DateTime.Now;
        //        if (!Core.LawyerManager.Edit(item))
        //        {
        //            dailys.Add(new Daily { Name = "信用评级", Description = string.Format("自然人:{0}得到满足{1}的{2},但是更新失败", item.Name, grade.Content, grade.Name), UserID = userId });
        //        }
        //    }
        //    return dailys;
        //}

        /// <summary>
        /// 作用:分析企业/自然人在某段时间之后  符合某一种级别
        /// 作者:汪建龙
        /// 编写时间:2017年3月8日20:37:24
        /// </summary>
        /// <param name="enterprise"></param>
        /// <param name="Grades"></param>
        /// <param name="BeginTime"></param>
        /// <returns></returns>
        //public Grade Analyze(List<Grade> Grades,DateTime BeginTime,SystemData systemData,int dataId)
        //{
        //    var conducts = Db.Conducts.Where(e => e.SystemData == systemData && e.DataId == dataId && e.CreateTime >= BeginTime&&e.State==BaseState.Argee).ToList();
        //    return Analyze(conducts, Grades, BeginTime);
        //}

        //private Grade Analyze(List<Conduct> conducts,List<Grade> grades,DateTime BeginTime)
        //{
        //    foreach (var grade in grades)
        //    {
        //        if (Valiate(conducts, grade))
        //        {
        //            return grade;
        //        }
        //    }
        //    return null;
        //}

        /// <summary>
        /// 作用:验证企业是否属于这一级别
        /// 作者:汪建龙
        /// 编写时间:2017年3月8日20:36:13
        /// </summary>
        /// <param name="conducts"></param>
        /// <param name="grade"></param>
        /// <returns></returns>
        //private bool Valiate(List<Conduct> conducts,Grade grade)
        //{
        //    if (grade.Bad.HasValue)
        //    {
        //        if (grade.Bad.Value != 0 && Exist(conducts, CreditDegree.Bad, grade.Bad.Value))
        //        {
        //            return true;
        //        }
        //    }
        //    else
        //    {
        //        if (Exist(conducts, CreditDegree.Bad))
        //        {
        //            return true;
        //        }
        //    }
        //    if (grade.Less.HasValue)
        //    {
        //        if (grade.Less.Value != 0 && Exist(conducts, CreditDegree.Less, grade.Less.Value))
        //        {
        //            return true;
        //        }
        //    }
        //    else
        //    {
        //        if (Exist(conducts, CreditDegree.Less))
        //        {
        //            return true;
        //        }
        //    }

        //    if (grade.Litter.HasValue)
        //    {
        //        if (grade.Litter.Value != 0 && Exist(conducts, CreditDegree.Good, grade.Litter.Value))
        //        {
        //            return true;
        //        }
        //    }
        //    else
        //    {
        //        if (Exist(conducts, CreditDegree.Good))
        //        {
        //            return true;
        //        }
        //    }
        //    var score = 100 - conducts.Where(e => e.Degree == CreditDegree.Good).Sum(e => e.Score);
        //    if (grade.MinScore.HasValue&& score >= grade.MinScore.Value )
        //    {
        //        if (grade.MaxScore.HasValue)
        //        {
        //            if(score <= grade.MaxScore.Value)
        //            {
        //                return true;
        //            }
        //        }
        //        else
        //        {
        //            return true;
        //        }

        //    }

        //    if (grade.MaxScore.HasValue && score <= grade.MaxScore.Value)
        //    {
        //        return true;
        //    }
        //    return false;
        //}
        private bool Exist(List <Conduct> conducts, CreditDegree degree, int?count = null)
        {
            return(count.HasValue ? conducts.Where(e => e.Degree == degree).Count() > count.Value : conducts.Any(e => e.Degree == degree));
        }