
using New_College.IServices;
using New_College.Model.Models;
using New_College.Services.BASE;
using New_College.IRepository.Base;
using New_College.Model.ViewModels;
using System.Threading.Tasks;
using New_College.Model;
using System.Collections.Generic;
using New_College.IRepository;
using System.Linq;
using LinqKit;
using System;
using System.Text;
using New_College.Repository;
using New_College.Common;

namespace New_College.Services
{
    public class T_EnrollmentPlanedescServices : BaseServices<T_EnrollmentPlanedesc>, IT_EnrollmentPlanedescServices
    {
        private readonly IBaseRepository<T_EnrollmentPlanedesc> _dal;
        private readonly ID_UniversityRepository d_UniversityRepository;
        private readonly IT_EnrollmentBatchRepository t_EnrollmentBatchRepository;
        private readonly IT_EnrollmentPlaneRepository t_EnrollmentPlaneRepository;
        private readonly ID_MajorRepository d_MajorRepository;
        private readonly ID_MajorClassRepository d_MajorClassRepository;
        private readonly ID_MajorCategoryRepository d_MajorCategoryRepository;
    
        private readonly IT_PlanMapTagRepository t_PlanMapTagRepository;
        private readonly IT_RegionScoreRepository t_RegionScoreRepository;
        private readonly IU_ProbabilityHistoryRepository u_ProbabilityHistoryRepository;
        private readonly IU_VolunteerTableRepository u_VolunteerTableRepository;
        private readonly IU_VolunteerTableDetailRepository u_VolunteerTableDetailRepository;
        private readonly IT_GearInfoRepository t_GearInfo;
        private readonly IT_EnrollmentPlanedescRepository t_EnrollmentPlanedesc;
        private readonly IV_CustomerInfoRepository _CustomerInfoRepository;
        public T_EnrollmentPlanedescServices(IBaseRepository<T_EnrollmentPlanedesc> dal
            , ID_UniversityRepository ID_UniversityRepository
            , IT_EnrollmentBatchRepository IT_EnrollmentBatchRepository
            , IT_EnrollmentPlaneRepository IT_EnrollmentPlaneRepository
            , ID_MajorRepository ID_MajorRepository
            , ID_MajorClassRepository ID_MajorClassRepository
            , ID_MajorCategoryRepository ID_MajorCategoryRepository
            , ID_MajorMapUniversityRepository ID_MajorMapUniversityRepository
            , IT_PlanMapTagRepository IT_PlanMapTagRepository
            , IT_RegionScoreRepository IT_RegionScoreRepository
            , IU_ProbabilityHistoryRepository IU_ProbabilityHistoryRepository
            , IU_VolunteerTableRepository IU_VolunteerTableRepository
            , IU_VolunteerTableDetailRepository IU_VolunteerTableDetailRepository
            , ID_UniversityCollectionRepository ID_UniversityCollectionRepository
            , IT_GearInfoRepository IT_GearInfoRepository, IT_EnrollmentPlanedescRepository t_EnrollmentPlanedescServices, IV_CustomerInfoRepository v_CustomerInfoRepository)
        {
            this._dal = dal;
            d_UniversityRepository = ID_UniversityRepository;
            t_EnrollmentBatchRepository = IT_EnrollmentBatchRepository;
            t_EnrollmentPlaneRepository = IT_EnrollmentPlaneRepository;
            d_MajorRepository = ID_MajorRepository;
            d_MajorClassRepository = ID_MajorClassRepository;
            d_MajorCategoryRepository = ID_MajorCategoryRepository;

            t_PlanMapTagRepository = IT_PlanMapTagRepository;
            t_RegionScoreRepository = IT_RegionScoreRepository;
            u_ProbabilityHistoryRepository = IU_ProbabilityHistoryRepository;
            u_VolunteerTableRepository = IU_VolunteerTableRepository;
            u_VolunteerTableDetailRepository = IU_VolunteerTableDetailRepository;
            t_GearInfo = IT_GearInfoRepository;
            base.BaseDal = dal;
            this.t_EnrollmentPlanedesc = t_EnrollmentPlanedescServices;
            this._CustomerInfoRepository = v_CustomerInfoRepository;
        }

        public List<string> permut = new List<string>();

        /// <summary>
        /// 根据分数获取个性推荐学校
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<PageModel<UniversityResult>> GetRecommendUniversity(RecommendUniversityQuery query)
        {

            return await t_EnrollmentPlanedesc.GetRecommendUniversity(query);
            //var maxscore = query.Score + 10;
            //var minscore = query.Score - 10;

            //var custome = (await this._CustomerInfoRepository.QueryById(query.CustomerId));

            //int planId = (await t_EnrollmentPlaneRepository.Query(e => e.Years == custome.Year && e.Area_Id == custome.AreaId)).FirstOrDefault().Id;

            //StringBuilder sb = new StringBuilder();
            //sb.AppendFormat("select Scoreline,UniversityId from T_EnrollmentPlanedesc where IsDelete=0 and Scoreline<={0} and Scoreline>{1}   and PlanId={2}", maxscore, minscore, planId);
            //if (!string.IsNullOrWhiteSpace(query.SubjectClaim))
            //{
            //    var sp = query.SubjectClaim.Split(",");
            //    sb.AppendFormat("  and ( ");
            //    for (var i = 0; i < sp.Length; i++)
            //    {
            //        sb.AppendFormat("    SubjectClaim in('{0}')   or ", sp[i]);
            //    }

            //    sb.AppendFormat(")  ");
            //    sb = sb.Replace("or )", ")");
            //}



            //var desc = await _dal.QuerySql(sb.ToString());
            ////降序求出所符合院校
            //var orderdesc = desc.OrderByDescending(x => x.Scoreline).Select(x => x.UniversityId).Distinct().ToList();
            //var nearids = desc.Select(x => x.UniversityId).Distinct().ToList();

            //var wheres = PredicateBuilder.New<D_University>();
            //wheres = wheres.And(x => x.IsDelete == false && orderdesc.Contains(x.Id));
            //if (!string.IsNullOrEmpty(query.AreaName) && query.AreaName != "全国")
            //    wheres = wheres.And(x => x.Area_Name.Contains(query.AreaName));
            //if (query.SubjectLevel < 2)
            //    wheres = wheres.And(x => x.Subject_Level == query.SubjectLevel);
            //if (query.Type >= 0)
            //    wheres = wheres.And(x => x.Type == query.Type);
            //if (query.Nhef < 2)
            //    wheres = wheres.And(x => x.Nhef == query.Nhef);
            //if (query.Sff < 2)
            //    wheres = wheres.And(x => x.Sff == query.Sff);
            //if (query.Syl < 2)
            //    wheres = wheres.And(x => x.Syl == query.Syl);
            //if (query.Nature > 0)
            //    wheres = wheres.And(x => x.Nature == query.Nature);

            //var info = await d_UniversityRepository.QueryPage(wheres, query.PageIndex, query.PageSize, "Rank Asc");
            //if (info.data.Count <= 0)
            //    return new PageModel<UniversityResult>() { };
            //var collectionuniversity = await d_UniversityCollectionRepository.Query(x => x.CustomerId == query.CustomerId && x.IsDelete == false);
            //List<UniversityResult> list = new List<UniversityResult>() { };
            //foreach (var c in info.data)
            //{
            //    string attribute = "";
            //    if (c.Nhef == 1)
            //        attribute += "985";
            //    if (c.Sff == 1)
            //        attribute += "211";
            //    if (c.Syl == 1)
            //        attribute += "双一流";
            //    list.Add(new UniversityResult
            //    {
            //        Id = c.Id,
            //        Name = c.Name,
            //        Nature = c.Nature,
            //        AscriptionName = c.AscriptionName,
            //        AreaName = c.Area_Name,
            //        Logo = c.Logo,
            //        Syl = c.Syl == 1 ? true : false,
            //        Nhef = c.Nhef == 1 ? true : false,
            //        Sff = c.Sff == 1 ? true : false,
            //        UniversityType = c.Type,
            //        IsNearScore = nearids.Contains(c.Id),

            //        IsContrast = collectionuniversity.Count(x => x.Type == 2 && x.UniversityId == c.Id) > 0
            //    });
            //}
            //return new PageModel<UniversityResult>()
            //{
            //    data = list,
            //    dataCount = info.dataCount,
            //    page = info.page,
            //    pageCount = info.pageCount,
            //    PageSize = info.PageSize
            //};
        }

        /// <summary>
        /// 霍兰德推荐学校专业
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<TagEnrollmentPlanResult>>> GetEnrollmentTagByPage(TagEnrollmentPlaneQuery query)
        {

            //学校到专业  专业到学校
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo == null)
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            var planid = planinfo.FirstOrDefault().Id;
            if (string.IsNullOrWhiteSpace(query.Tag))
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "Tag传入为空..." };
            var newTags = GetTag(query.Tag).Distinct().ToList();
            var planmaptag = await t_PlanMapTagRepository.Query(x => x.IsDelete == false);
            List<majorlists> majorcolorlists = new List<majorlists>() { };
            List<string> majorlists = new List<string>() { };
            int i = 0;
            foreach (var item in newTags)
            {
                i++;
                majorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => x.Name));
                majorcolorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => new majorlists()
                {
                    MajorName = x.Name,
                    TagColor = TagcolorName(i).ToString()
                }));
            }
            majorlists = majorlists.Distinct().ToList();
            if (majorlists.Count <= 0)
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "标签匹配招生计划专业为空..." };

            var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();

            wheres.Start(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0);
            if (query.AreaId != 821 && query.AreaId != 1047 && query.AreaId != 1965)
            {
                if (query.BatchId > 0)
                {
                    wheres.And(x => x.BatchtypeId == query.BatchId);
                }
            }
            if (query.AreaId == 821)
            {
                if (query.SubjectClaim == "物")
                {
                    var batch = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && x.IsDelete == false && x.Type == "理科");
                    var batchids = batch.Select(x => x.Id).ToList();
                    wheres.And(x => batchids.Contains(x.BatchtypeId));
                }
                else if (query.SubjectClaim == "史")
                {
                    var batch = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && x.IsDelete == false && x.Type == "文科");
                    var batchids = batch.Select(x => x.Id).ToList();
                    wheres.And(x => batchids.Contains(x.BatchtypeId));
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(query.SubjectClaim))
                {
                    if (query.SubjectClaim.Contains("，"))
                    {
                        var cc = query.SubjectClaim.Split("，");
                        if (cc.Length == 2)
                        {
                            var cc1 = cc[0];
                            var cc2 = cc[1];
                            wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true || (x.Subjectclaim.Contains(query.SubjectClaim)) == true);
                        }
                        else if (cc.Length == 3)
                        {
                            var cc1 = cc[0];
                            var cc2 = cc[1];
                            var cc3 = cc[2];
                            wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains(cc3) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true || (x.Subjectclaim.Contains(query.SubjectClaim) == true));
                        }
                    }
                    else
                    {
                        wheres.And(x => x.Subjectclaim.Contains(query.SubjectClaim) && !x.Subjectclaim.Contains("，"));
                    }
                }
            }

            var descinfo = await _dal.Query(wheres);
            if (descinfo.Count <= 0)
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "该标签的对应招生计划为空..." };
            //档位分数处理 自动锁定一个档位
            DTOByTagQuery dTO = new DTOByTagQuery() { };
            var newscore = Convert.ToDecimal(query.Score);
            var gearinfo = await t_GearInfo.Query(x => x.IsDelete == false && x.PlanId == planid && x.AreaId == query.AreaId);
            var newtagColor = "";
            if (gearinfo.Count > 0)
            {
                var nowgearinfo = gearinfo.Where(x => x.GearMinScore <= newscore && x.GearMaxScore >= newscore).FirstOrDefault();
                if (nowgearinfo != null)
                {
                    decimal MaxScore = 0;
                    decimal MinScore = 0;
                    int sort = 0;
                    decimal downMaxScore = 0;
                    decimal downMinScore = 0;
                    MaxScore = nowgearinfo.GearMaxScore;
                    MinScore = nowgearinfo.GearMinScore;
                    sort = nowgearinfo.OrderSort;
                    //下个排序的档位分数
                    int Downsort = sort + 1;
                    if (Downsort == 12)
                    {
                        downMaxScore = MinScore - 1;
                        downMinScore = 0;
                    }
                    else
                    {
                        downMaxScore = gearinfo.Where(m => m.OrderSort == Downsort).Select(m => m.GearMaxScore).FirstOrDefault();
                        downMinScore = gearinfo.Where(m => m.OrderSort == Downsort).Select(m => m.GearMinScore).FirstOrDefault();
                    }
                    dTO.OnMaxScore = MaxScore + 5;
                    dTO.OnMinScore = MaxScore + 1;
                    dTO.MaxScore = MaxScore;
                    dTO.MinScore = MinScore;
                    dTO.DownMaxScore = downMaxScore;
                    dTO.DownMinScore = downMinScore;
                }
                else
                {
                    newtagColor = "bao";
                }
            }

            var universityids = descinfo.OrderByDescending(x => x.Scoreline).Select(x => x.UniversityId).ToList();
            var universityinfo = new List<D_University>();
            if (!string.IsNullOrWhiteSpace(query.SearchAreaName) && query.SearchAreaName != "全国")
            {
                universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false && x.Area_Name == query.SearchAreaName, "Rank Asc");
                if (universityinfo.Count <= 0)
                    return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所选省份推荐院校数据为空" };
            }
            else
            {
                universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false, "Rank Asc");
            }
            if (query.SearchType == 1)
            {
                List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
                foreach (var item in majorcolorlists)
                {
                    var newdesc = descinfo.Where(x => x.MajorName == item.MajorName).ToList();
                    if (newdesc.Count > 0)
                    {
                        var newuniversityids = newdesc.Select(x => x.UniversityId).Distinct().ToList();
                        var newuniversityinfo = universityinfo.Where(x => newuniversityids.Contains(x.Id));

                        List<OtherInfo> nowInfo = new List<OtherInfo>() { };
                        foreach (var s in newuniversityinfo)
                        {
                            var tagColor = "";
                            if (newtagColor == "bao")
                            {
                                tagColor = "bao";
                            }
                            else
                            {
                                var nowlowscore = newdesc.Where(x => x.UniversityId == s.Id && x.Scoreline > 0).OrderBy(x => x.Scoreline).Select(x => x.Scoreline).FirstOrDefault();
                                var nowScoreLine = Convert.ToDecimal(nowlowscore);
                                if (dTO.OnMinScore != 0 && dTO.OnMaxScore != 0)
                                {
                                    if (nowScoreLine >= dTO.OnMinScore && nowScoreLine <= dTO.OnMaxScore)
                                    {
                                        tagColor = "chong";
                                    }
                                    else if (nowScoreLine >= dTO.MinScore && nowScoreLine <= dTO.MaxScore)
                                    {
                                        tagColor = "wen";
                                    }
                                    else if (nowScoreLine < dTO.MinScore)
                                    {
                                        tagColor = "bao";
                                    }
                                }
                            }
                            nowInfo.Add(new OtherInfo()
                            {
                                Id = s.Id,
                                Name = s.Name,
                                Color = tagColor//此处是学校的颜色
                            });

                        }
                        list.Add(new TagEnrollmentPlanResult()
                        {
                            Id = 0,
                            Name = item.MajorName,
                            Color = item.TagColor,
                            Info = nowInfo.OrderByDescending(t => t.Color).ToList()
                        });
                    }
                }
                var datalist = list.OrderBy(x => x.Color).ToList();
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = datalist };
            }
            else
            {
                List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
                foreach (var item in universityinfo)
                {
                    var newdesc = descinfo.Where(x => x.UniversityId == item.Id).ToList();
                    if (newdesc.Count > 0)
                    {
                        List<OtherInfo> otherlist = new List<OtherInfo>() { };
                        foreach (var s in newdesc)
                        {
                            var color = majorcolorlists.Where(x => x.MajorName == s.MajorName).Select(x => x.TagColor).FirstOrDefault();
                            if (string.IsNullOrWhiteSpace(color))
                                color = "d";
                            otherlist.Add(new OtherInfo()
                            {
                                Id = 0,
                                Name = s.MajorName,
                                Color = color
                            });
                        }
                        var newotherlist = otherlist.OrderBy(x => x.Color).ToList();
                        var tagColor = "";
                        if (newtagColor == "bao")
                        {
                            tagColor = "bao";
                        }
                        else
                        {
                            var nowscore = newdesc.Where(x => x.Scoreline > 0).Select(x => x.Scoreline).FirstOrDefault();
                            var nowScoreLine = Convert.ToDecimal(nowscore);
                            if (dTO.OnMinScore != 0 && dTO.OnMaxScore != 0)
                            {
                                if (nowScoreLine >= dTO.OnMinScore && nowScoreLine <= dTO.OnMaxScore)
                                {
                                    tagColor = "chong";
                                }
                                else if (nowScoreLine >= dTO.MinScore && nowScoreLine <= dTO.MaxScore)
                                {
                                    tagColor = "wen";
                                }
                                else if (nowScoreLine < dTO.MinScore)
                                {
                                    tagColor = "bao";
                                }
                            }
                        }
                        list.Add(new TagEnrollmentPlanResult()
                        {
                            Id = item.Id,
                            Name = item.Name,//院校名称
                            Color = tagColor,//院校没有颜色
                            Info = newotherlist
                        });
                    }
                }
                return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = list.OrderByDescending(x => x.Color).ToList() };
            }
        }

        /// <summary>
        /// 设置标签的背景颜色
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public EnumTagColor TagcolorName(int tag)
        {
            var tagcolor = new EnumTagColor();
            switch (tag)
            {
                case 1:
                    tagcolor = EnumTagColor.a;
                    break;
                case 2:
                    tagcolor = EnumTagColor.b;
                    break;
                case 3:
                    tagcolor = EnumTagColor.c;
                    break;
                case 4:
                    tagcolor = EnumTagColor.c;
                    break;
                case 5:
                    tagcolor = EnumTagColor.d;
                    break;
                case 6:
                    tagcolor = EnumTagColor.d;
                    break;
                default:
                    tagcolor = EnumTagColor.d;
                    break;
            }
            return tagcolor;
        }

        #region old 霍兰德推荐学校专业
        ///// <summary>
        ///// 霍兰德推荐学校专业
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public async Task<MessageModel<List<TagEnrollmentPlanResult>>> GetEnrollmentTagByPage(TagEnrollmentPlaneQuery query)
        //{

        //    //学校到专业  专业到学校
        //    var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
        //    if (planinfo == null)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
        //    var planid = planinfo.FirstOrDefault().Id;
        //    if (string.IsNullOrWhiteSpace(query.Tag))
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "Tag传入为空..." };
        //    var newTags = GetTag(query.Tag).Distinct().ToList();
        //    var planmaptag = await t_PlanMapTagRepository.Query(x => x.IsDelete == false);
        //    List<majorlists> majorcolorlists = new List<majorlists>() { };
        //    List<string> majorlists = new List<string>() { };
        //    int i = 0;
        //    foreach (var item in newTags)
        //    {
        //        i++;
        //        majorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => x.Name));
        //        majorcolorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => new majorlists()
        //        {
        //            MajorName = x.Name,
        //            TagColor = TagcolorName(i).ToString()
        //        }));
        //    }
        //    majorlists = majorlists.Distinct().ToList();
        //    if (majorlists.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "标签匹配招生计划专业为空..." };
        //    var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
        //    if (batchinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
        //    var batchids = batchinfo.Select(s => s.Id).ToList();
        //    var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();

        //    wheres.Start(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0 && batchids.Contains(x.BatchtypeId));

        //    if (!string.IsNullOrWhiteSpace(query.SubjectClaim))
        //    {
        //        if (query.SubjectClaim.Contains("，"))
        //        {
        //            var cc = query.SubjectClaim.Split("，");
        //            if (cc.Length == 2)
        //            {
        //                var cc1 = cc[0];
        //                var cc2 = cc[1];
        //                wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true || (x.Subjectclaim.Contains(query.SubjectClaim)) == true);
        //            }
        //            else if (cc.Length == 3)
        //            {
        //                var cc1 = cc[0];
        //                var cc2 = cc[1];
        //                var cc3 = cc[2];
        //                wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains(cc3) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true || (x.Subjectclaim.Contains(query.SubjectClaim) == true));
        //            }
        //        }
        //        else
        //        {
        //            wheres.And(x => x.Subjectclaim.Contains(query.SubjectClaim) && !x.Subjectclaim.Contains("，"));
        //        }
        //    }
        //    var descinfo = await _dal.Query(wheres);
        //    if (descinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "该标签的对应招生计划为空..." };
        //    var universityids = descinfo.OrderByDescending(x => x.Scoreline).Select(x => x.UniversityId).ToList();
        //    var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false);

        //    if (query.SearchType == 1)
        //    {
        //        List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
        //        foreach (var item in majorcolorlists)
        //        {
        //            var newdesc = descinfo.Where(x => x.MajorName == item.MajorName).ToList();
        //            if (newdesc.Count > 0)
        //            {
        //                var newuniversityids = newdesc.Select(x => x.UniversityId).Distinct().ToList();
        //                var newuniversityinfo = universityinfo.Where(x => newuniversityids.Contains(x.Id));
        //                list.Add(new TagEnrollmentPlanResult()
        //                {
        //                    Id = 0,
        //                    Name = item.MajorName,
        //                    Color = item.TagColor,
        //                    Info = newuniversityinfo.Select(x => new OtherInfo()
        //                    {
        //                        Id = x.Id,
        //                        Name = x.Name,
        //                        Color = ""
        //                    }).ToList()
        //                });
        //            }
        //        }
        //        var datalist = list.OrderBy(x => x.Color).ToList();
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = datalist };
        //    }
        //    else
        //    {
        //        List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
        //        foreach (var item in universityinfo)
        //        {
        //            var newdesc = descinfo.Where(x => x.UniversityId == item.Id).ToList();
        //            if (newdesc.Count > 0)
        //            {
        //                List<OtherInfo> otherlist = new List<OtherInfo>() { };
        //                foreach (var s in newdesc)
        //                {
        //                    var color = majorcolorlists.Where(x => x.MajorName == s.MajorName).Select(x => x.TagColor).FirstOrDefault();
        //                    if (string.IsNullOrWhiteSpace(color))
        //                        color = "d_low";
        //                    otherlist.Add(new OtherInfo()
        //                    {
        //                        Id = 0,
        //                        Name = s.MajorName,
        //                        Color = color
        //                    });
        //                }
        //                var newotherlist = otherlist.OrderBy(x => x.Color);
        //                list.Add(new TagEnrollmentPlanResult()
        //                {
        //                    Id = item.Id,
        //                    Name = item.Name,//院校名称
        //                    Color = "",//院校没有颜色
        //                    Info = otherlist
        //                });
        //            }

        //        }
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = list };
        //    }


        //    return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "获取失败" };
        //}

        ///// <summary>
        ///// 霍兰德推荐学校专业
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public async Task<MessageModel<List<TagEnrollmentPlanResult>>> GetEnrollmentTagByPage(TagEnrollmentPlaneQuery query)
        //{
        //    var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
        //    if (planinfo == null)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
        //    var planid = planinfo.FirstOrDefault().Id;
        //    if (string.IsNullOrWhiteSpace(query.Tag))
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "Tag传入为空..." };
        //    var newTags = GetTag(query.Tag);
        //    var planmaptag = await t_PlanMapTagRepository.Query(x => x.IsDelete == false);
        //    List<string> majorlists = new List<string>() { };
        //    foreach (var item in newTags)
        //    {
        //        majorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => x.Name).ToList());
        //    }
        //    majorlists = majorlists.Distinct().ToList();
        //    if (majorlists.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "标签匹配招生计划专业为空..." };
        //    var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
        //    if (batchinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
        //    var batchids = batchinfo.Select(s => s.Id).ToList();

        //    //var descinfoss = await _dal.Query(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0 && batchids.Contains(x.BatchtypeId));
        //    StringBuilder sql = new StringBuilder() { };
        //    StringBuilder sqlparams = new StringBuilder() { };

        //    var newmajorlists = "";
        //    foreach (var item in majorlists)
        //    {
        //        newmajorlists = newmajorlists + "'" + item + "',";
        //    }
        //    newmajorlists = newmajorlists.Substring(0, newmajorlists.Length - 1);
        //    var newbatchids = string.Join(",", batchids);
        //    var cc = query.Claim;
        //    if (!string.IsNullOrWhiteSpace(cc))
        //    {
        //        if (cc.Contains("，"))
        //        {
        //            sql.AppendFormat("SELECT Subjectclaim,UniversityId,MajorName,Scoreline FROM `T_EnrollmentPlanedesc` where PlanId={0} and MajorName in ({1}) and Scoreline<={2} and UniversityId>0 and BatchtypeId in ({3}) and Subjectclaim='无限制' or Subjectclaim='无' or Subjectclaim like '%，%' and (", planid, newmajorlists, query.Score, newbatchids);
        //            var newcc = cc.Split("，");
        //            foreach (var item in newcc)
        //            {
        //                sqlparams.AppendFormat(" Subjectclaim like '%{0}%' or", item);
        //            }
        //            sqlparams.AppendFormat(" 1=1)");
        //            sql.AppendFormat(sqlparams.ToString());
        //            sql.AppendFormat(" union all");
        //            sql.AppendFormat(" SELECT Subjectclaim,UniversityId,MajorName,Scoreline FROM `T_EnrollmentPlanedesc` where PlanId={0} and MajorName in ({1}) and Scoreline<={2} and UniversityId>0 and BatchtypeId in ({3}) and  Subjectclaim='无限制' or Subjectclaim='无' or Subjectclaim like '%/%' and (", planid, newmajorlists, query.Score, newbatchids);
        //            sql.AppendFormat(sqlparams.ToString());
        //            sql.AppendFormat(" union all");
        //            sql.AppendFormat(" SELECT Subjectclaim,UniversityId,MajorName,Scoreline FROM `T_EnrollmentPlanedesc` where  PlanId={0} and MajorName in ({1}) and Scoreline<={2} and UniversityId>0 and BatchtypeId in ({3}) and  Subjectclaim not like '%，%' and Subjectclaim not like '%/%' and Subjectclaim='无限制' or Subjectclaim='无' and (", planid, newmajorlists, query.Score, newbatchids);
        //            sql.AppendFormat(sqlparams.ToString());
        //            //wheres.And(x => x.Subjectclaim.Contains(cc));
        //        }
        //        else
        //        {
        //            sql.AppendFormat("SELECT Subjectclaim,UniversityId,MajorName,Scoreline FROM `T_EnrollmentPlanedesc` where PlanId={0} and MajorName in ({1}) and Scoreline<={2} and UniversityId>0 and BatchtypeId in ({3}) and  Subjectclaim='无限制' or Subjectclaim='无' or Subjectclaim like '%{4}%'", planid, newmajorlists, query.Score, newbatchids, cc);
        //        }
        //    }
        //    sql.AppendFormat(" group by Subjectclaim,UniversityId,MajorName,Scoreline");
        //    var descinfo = await _dal.QuerySql(sql.ToString());
        //    if (descinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "该标签的对应招生计划为空..." };
        //    var universityids = descinfo.OrderByDescending(x => x.Scoreline).Select(x => x.UniversityId).ToList();
        //    var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false);
        //    List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
        //    foreach (var item in majorlists)
        //    {
        //        var newdesc = descinfo.Where(x => x.MajorName == item).ToList();
        //        if (newdesc.Count > 0)
        //        {
        //            var newuniversityids = newdesc.Select(x => x.UniversityId).Distinct().ToList();
        //            var newuniversityinfo = universityinfo.Where(x => newuniversityids.Contains(x.Id));
        //            list.Add(new TagEnrollmentPlanResult()
        //            {
        //                MajorName = item,
        //                SchoolInfo = newuniversityinfo.Select(x => new SchoolInfo()
        //                {
        //                    AscriptionName = x.AscriptionName,
        //                    Logo = x.Logo,
        //                    Nhef = x.Nhef,
        //                    Sff = x.Sff,
        //                    Syl = x.Syl,
        //                    UniversityId = x.Id,
        //                    UniversityName = x.Name
        //                }).ToList()
        //            });
        //        }
        //    }

        //    return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = list };
        //}

        ///// <summary>
        ///// 霍兰德推荐学校专业  old2
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public async Task<MessageModel<List<TagEnrollmentPlanResult>>> GetEnrollmentTagByPage(TagEnrollmentPlaneQuery query)
        //{
        //    var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
        //    if (planinfo == null)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
        //    var planid = planinfo.FirstOrDefault().Id;
        //    if (string.IsNullOrWhiteSpace(query.Tag))
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "Tag传入为空..." };
        //    var newTags = GetTag(query.Tag);
        //    var planmaptag = await t_PlanMapTagRepository.Query(x => x.IsDelete == false);
        //    List<string> majorlists = new List<string>() { };
        //    foreach (var item in newTags)
        //    {
        //        majorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => x.Name).ToList());
        //    }
        //    majorlists = majorlists.Distinct().ToList();
        //    if (majorlists.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "标签匹配招生计划专业为空..." };
        //    var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
        //    if (batchinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
        //    var batchids = batchinfo.Select(s => s.Id).ToList();
        //    var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();

        //    wheres.Start(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0 && batchids.Contains(x.BatchtypeId));

        //    if (!string.IsNullOrWhiteSpace(query.SubjectClaim))
        //    {
        //        if (query.SubjectClaim.Contains("，"))
        //        {
        //            var cc = query.SubjectClaim.Split("，");
        //            if (cc.Length == 2)
        //            {
        //                var cc1 = cc[0];
        //                var cc2 = cc[1];
        //                wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true);
        //            }
        //            else if (cc.Length == 3)
        //            {
        //                var cc1 = cc[0];
        //                var cc2 = cc[1];
        //                var cc3 = cc[2];
        //                wheres.And(x => (x.Subjectclaim.Contains("/") && x.Subjectclaim.Contains(cc1)) == true || (x.Subjectclaim.Contains(cc2) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains(cc3) && x.Subjectclaim.Contains("/")) == true || (x.Subjectclaim.Contains("，") && x.Subjectclaim.Contains(query.SubjectClaim)) == true);
        //            }
        //        }
        //        else
        //        {
        //            wheres.And(x => x.Subjectclaim.Contains(query.SubjectClaim) && !x.Subjectclaim.Contains("，"));
        //        }
        //    }
        //    var descinfo = await _dal.Query(wheres);
        //    if (descinfo.Count <= 0)
        //        return new MessageModel<List<TagEnrollmentPlanResult>>() { success = false, msg = "该标签的对应招生计划为空..." };
        //    var universityids = descinfo.OrderByDescending(x => x.Scoreline).Select(x => x.UniversityId).ToList();
        //    var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false);
        //    List<TagEnrollmentPlanResult> list = new List<TagEnrollmentPlanResult>() { };
        //    foreach (var item in majorlists)
        //    {
        //        var newdesc = descinfo.Where(x => x.MajorName == item).ToList();
        //        if (newdesc.Count > 0)
        //        {
        //            var newuniversityids = newdesc.Select(x => x.UniversityId).Distinct().ToList();
        //            var newuniversityinfo = universityinfo.Where(x => newuniversityids.Contains(x.Id));
        //            list.Add(new TagEnrollmentPlanResult()
        //            {
        //                MajorName = item,
        //                SchoolInfo = newuniversityinfo.Select(x => new SchoolInfo()
        //                {
        //                    AscriptionName = x.AscriptionName,
        //                    Logo = x.Logo,
        //                    Nhef = x.Nhef,
        //                    Sff = x.Sff,
        //                    Syl = x.Syl,
        //                    UniversityId = x.Id,
        //                    UniversityName = x.Name
        //                }).ToList()
        //            });
        //        }
        //    }

        //    return new MessageModel<List<TagEnrollmentPlanResult>>() { success = true, msg = "获取成功", response = list };
        //}
        #endregion


        #region  old懒人模式
        ///// <summary>
        ///// 懒人模式
        ///// 办学性质
        ///// 高校级别
        ///// 专业ids
        ///// </summary>
        ///// <param name="query"></param>
        ///// <returns></returns>
        //public async Task<MessageModel<PageModel<UniversityEnrollmentPlanResult>>> GetEnrollmentLazyByPage(LazyEnrollmentPlaneQuery query)
        //{
        //    if (query.Score <= 0)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "分数不能为0..." };
        //    var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
        //    if (planinfo == null)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
        //    //通过传来的专业分类Id 筛选出所选择的专业的ids
        //    var major = await d_MajorRepository.Query(x => x.IsDelete == false && query.MajorIds.Contains(x.CategoryClass_Id));
        //    if (major.Count() <= 0)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所选专业大类数据完善中..." };
        //    var majornames = major.Select(x => x.MajorName).ToList();
        //    //通过办学性质和高校级别筛选出学校的ids
        //    //string sql = "";
        //    var stringBuilder = new StringBuilder();
        //    stringBuilder.Append("SELECT Id FROM `D_University` where IsDelete=0 ");
        //    if (query.Nature > 0)
        //    {
        //        //sql += " and Nature=" + query.Nature + "";
        //        stringBuilder.AppendFormat(" and Nature={0}", query.Nature);
        //    }

        //    if (query.SchoolLevel > 0)
        //    {
        //        if (query.SchoolLevel == 1)
        //        {
        //            stringBuilder.AppendFormat(" and Nhef=1");
        //            //sql += " and Nhef=1";
        //        }
        //        else if (query.SchoolLevel == 2)
        //        {
        //            stringBuilder.AppendFormat(" and Sff=1");
        //            //sql += " and Sff=1";
        //        }
        //        else
        //        {
        //            stringBuilder.AppendFormat(" and Syl=1");
        //            //sql += " and Syl=1";
        //        }
        //    }
        //    var university = await d_UniversityRepository.QuerySql(stringBuilder.ToString());
        //    if (university.Count <= 0)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所选院校数据完善中..." };
        //    var universityids = university.Select(x => x.Id).ToList();
        //    var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
        //    if (batchinfo.Count <= 0)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
        //    var batchids = batchinfo.Select(s => s.Id).ToList();
        //    //通过条件筛选出所有的
        //    var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();
        //    wheres.And(x => x.Scoreline <= query.Score && majornames.Contains(x.MajorName) && universityids.Contains(x.UniversityId) && x.PlanId == planinfo.FirstOrDefault().Id && batchids.Contains(x.BatchtypeId));
        //    //根据上述所有筛选  求出招生计划
        //    var plandesc = await _dal.Query(wheres, "Scoreline desc");
        //    if (plandesc.Count <= 0)
        //        return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "符合条件招生条件为空..." };
        //    //招生计划内所有的院校Ids
        //    var planuniversityids = plandesc.Select(x => x.UniversityId).ToList().Distinct();
        //    var ids = string.Join(",", planuniversityids);
        //    //var info = await d_UniversityRepository.QueryPage(x => planuniversityids.Contains(x.Id), query.PageIndex, query.PageSize);
        //    var start = query.PageSize * (query.PageIndex - 1);
        //    var end = query.PageIndex * query.PageSize;
        //    var stringBuilderinfo = new StringBuilder();
        //    stringBuilderinfo.AppendFormat("select Id,Name,Logo,Nhef,Sff,Syl,Area_Name,AscriptionName from D_University where IsDelete=0 and Id in ({0}) limit {1},{2}", ids, start, end);
        //    var info = await d_UniversityRepository.QuerySql(stringBuilderinfo.ToString());
        //    List<UniversityEnrollmentPlanResult> list = new List<UniversityEnrollmentPlanResult>() { };
        //    foreach (var item in info)
        //    {
        //        var planids = plandesc.Where(x => x.UniversityId == item.Id).Select(x => x.Id).ToList();
        //        list.Add(new UniversityEnrollmentPlanResult()
        //        {
        //            UniversityName = item.Name,
        //            UniversityId = item.Id,
        //            Logo = item.Logo,
        //            Nhef = item.Nhef,
        //            Sff = item.Sff,
        //            Syl = item.Syl,
        //            planCount = plandesc.Where(x => x.UniversityId == item.Id).Sum(x => x.Plancount),
        //            PlanIds = planids,
        //            AreaName = item.Area_Name,
        //            AscriptionName = item.AscriptionName,
        //            MjaorPlan = plandesc.Count(x => x.UniversityId == item.Id),
        //            Rank = item.Rank <= 0 ? "-" : item.Rank.ToString()
        //        });
        //    }
        //    return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>()
        //    {
        //        success = true,
        //        msg = "获取成功",
        //        response = new PageModel<UniversityEnrollmentPlanResult>()
        //        {
        //            data = list,
        //            dataCount = planuniversityids.Count(),
        //            page = query.PageIndex,
        //            PageSize = query.PageSize,
        //            pageCount = (int)Math.Ceiling(ids.Count() / Convert.ToDecimal(query.PageSize))
        //        }
        //    };
        //}
        #endregion

        /// <summary>
        /// 懒人模式
        /// 办学性质
        /// 高校级别
        /// 专业ids
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<UniversityEnrollmentPlanLazyResult>>> GetEnrollmentLazyByPage(LazyEnrollmentPlaneQuery query)
        {
            if (query.Score <= 0)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "分数不能为0..." };
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo == null)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            //通过传来的专业分类Id 筛选出所选择的专业的ids
            var majorclassinfo = await d_MajorClassRepository.Query(x => query.MajorIds.Contains(x.TradeId) && x.IsDelete == false);
            var CategoryClassids = majorclassinfo.Select(x => x.Id).ToList();
            var major = await d_MajorRepository.Query(x => x.IsDelete == false && CategoryClassids.Contains(x.CategoryClass_Id));
            if (major.Count() <= 0)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "请选择专业大类，或所选专业大类数据完善中..." };
            var majornames = major.Select(x => x.MajorName).ToList();
            //通过办学性质和高校级别筛选出学校的ids
            //string sql = "";
            var stringBuilder = new StringBuilder();
            stringBuilder.Append("SELECT Id FROM `D_University` where IsDelete=0 ");
            if (query.Nature != null && query.Nature.Count > 0)
            {
                var newnature = string.Join(",", query.Nature);
                stringBuilder.AppendFormat(" and Nature in ({0})", newnature);
            }
            if (query.AreaNames != null && query.AreaNames.Count > 0)
            {
                string areanames = "";
                foreach (var item in query.AreaNames)
                {
                    areanames += "'" + item + "',";
                }
                var newnames = areanames.Substring(0, areanames.Length - 1);
                stringBuilder.AppendFormat(" and Area_Name in ({0})", newnames);
            }
            stringBuilder.AppendFormat(" order by rank asc");

            var university = await d_UniversityRepository.QuerySql(stringBuilder.ToString());
            if (university.Count <= 0)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "所选院校数据完善中..." };
            var universityids = university.Select(x => x.Id).ToList();
            var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
            if (batchinfo.Count <= 0)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "所属年份数据批次为空..." };
            var batchids = batchinfo.Select(s => s.Id).ToList();
            //通过条件筛选出所有的
            var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();
            wheres.And(x => x.Scoreline <= query.Score && x.Scoreline > 0 && majornames.Contains(x.MajorName) && universityids.Contains(x.UniversityId) && x.PlanId == planinfo.FirstOrDefault().Id && batchids.Contains(x.BatchtypeId));
            //根据上述所有筛选  求出招生计划
            var plandesc = await _dal.Query(wheres, "Scoreline desc");
            if (plandesc.Count <= 0)
                return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>() { success = false, msg = "符合条件招生条件为空..." };
            //懒人推荐限制
            //院校数量
            var unum = 0;
            //专业数量
            var mnum = 0;
            switch (query.AreaId)
            {
                case 802:
                    unum = 24;
                    mnum = 4;
                    break;
                case 821:
                    unum = 16;
                    mnum = 6;
                    break;
                case 1047:
                    unum = 12;
                    mnum = 6;
                    break;
                case 1376:
                    unum = 96;
                    mnum = 1;
                    break;
                case 1965:
                    unum = 15;
                    mnum = 6;
                    break;
            }

            //招生计划内所有的院校Ids
            var planuniversityids = plandesc.Select(x => x.UniversityId).ToList().Distinct().Take(unum);
            var ids = string.Join(",", planuniversityids);
            //var info = await d_UniversityRepository.QueryPage(x => planuniversityids.Contains(x.Id), query.PageIndex, query.PageSize);

            var stringBuilderinfo = new StringBuilder();
            stringBuilderinfo.AppendFormat("select Id,Name,Logo,Nhef,Sff,Syl,Area_Name,AscriptionName from D_University where IsDelete=0 and Id in ({0}) order by Id asc", ids);
            var info = await d_UniversityRepository.QuerySql(stringBuilderinfo.ToString());
            List<UniversityEnrollmentPlanLazyResult> list = new List<UniversityEnrollmentPlanLazyResult>() { };
            foreach (var item in info)
            {
                var plansinfo = plandesc.Where(x => x.UniversityId == item.Id).ToList().Take(mnum);
                list.Add(new UniversityEnrollmentPlanLazyResult()
                {
                    UniversityName = item.Name,
                    UniversityId = item.Id,
                    Logo = item.Logo,
                    Nhef = item.Nhef,
                    Sff = item.Sff,
                    Syl = item.Syl,
                    AreaName = item.Area_Name,
                    Year = query.Year.ToString(),
                    Infos = plansinfo.Select(x => new PlanInfo()
                    {
                        MajorId = x.Id,
                        Money = x.Tuitionfee,
                        Year = x.Studyyears,
                        YearName = query.Year.ToString(),
                        PlanName = x.MajorName,
                        PlanNum = x.Plancount,
                        Scoreline = x.Scoreline
                    }).ToList(),
                    AscriptionName = item.AscriptionName,
                    Rank = item.Rank <= 0 ? "-" : item.Rank.ToString()
                });
            }
            return new MessageModel<List<UniversityEnrollmentPlanLazyResult>>()
            {
                success = true,
                msg = "获取成功",
                response = list
            };
            //return new MessageModel<PageModel<UniversityEnrollmentPlanLazyResult>>()
            //{
            //    success = true,
            //    msg = "获取成功",
            //    response = new PageModel<UniversityEnrollmentPlanLazyResult>()
            //    {
            //        data = list,
            //        dataCount = planuniversityids.Count(),
            //        page = query.PageIndex,
            //        PageSize = query.PageSize,
            //        pageCount = (int)Math.Ceiling(ids.Count() / Convert.ToDecimal(query.PageSize))
            //    }
            //};
        }

        /// <summary>
        /// 根据计划Ids 获取招生计划 
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<PageModel<PlanDescList>>> GetPlanByUniversity(PlanDetailQuery query)
        {
            if (query.PlanIds != null && query.PlanIds.Count <= 0)
                return new MessageModel<PageModel<PlanDescList>>() { success = false, msg = "传入不能为空" };
            var info = await _dal.QueryPage(x => x.IsDelete == false && query.PlanIds.Contains(x.Id), query.PageIndex, query.PageSize, "Scoreline desc");
            List<PlanDescList> list = new List<PlanDescList>() { };
            foreach (var item in info.data)
            {
                var newname = CheckMajorName(item.MajorName, item.Remark);
                var newmoney = string.IsNullOrWhiteSpace(item.Tuitionfee) || item.Tuitionfee == "0" || item.Tuitionfee == "待定" ? "--" : item.Tuitionfee;
                var newyear = string.IsNullOrWhiteSpace(item.Studyyears) ? "--" : item.Studyyears;
                var count = list.Count(x => x.Name == newname && x.Money == newmoney && x.PlanNum == item.Plancount && x.Scoreline == item.Scoreline);
                if (count > 0)
                    continue;
                list.Add(new PlanDescList()
                {
                    Name = newname,
                    Year = newyear,
                    Money = newmoney,
                    PlanNum = item.Plancount,
                    MajorId = item.Id,
                    Scoreline = item.Scoreline
                    //Subject = GetSub(item.Subjectclaim)
                });
            }
            return new MessageModel<PageModel<PlanDescList>>()
            {
                success = true,
                msg = "获取成功",
                response = new PageModel<PlanDescList>()
                {
                    data = list,
                    dataCount = info.dataCount,
                    page = info.page,
                    pageCount = info.pageCount,
                    PageSize = info.PageSize
                }
            };
        }

        /// <summary>
        /// 校验专业名称
        /// </summary>
        /// <param name="name"></param>
        /// <param name="remake"></param>
        /// <returns></returns>
        public string CheckMajorName(string name, string remake)
        {
            return string.IsNullOrWhiteSpace(remake) ? name : remake.Contains("(") || remake.Contains("（") ? name + remake : name + "(" + remake + ")";
        }



        /// <summary>
        /// 冲稳保获取推荐学校专业
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<CWBEnrollmentPlanResult>>> GetEnrollmentCWBByPage(CWBEnrollmentPlaneQuery query)
        {
            //所选科目  分数 
            if (query.Score <= 0)
                return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "分数不能为0..." };
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Area_Id == query.AreaId && w.Years == query.Year);
            if (planinfo == null)
                return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            //筛选符合条件的院校ids
            var stringBuilder = new StringBuilder();
            stringBuilder.Append("SELECT Id FROM `D_University` where IsDelete=0 ");
            if (query.Nature != null && query.Nature.Count > 0)
            {
                var newnature = string.Join(",", query.Nature);
                stringBuilder.AppendFormat(" and Nature in ({0})", newnature);
            }
            if (query.UniversityAreaName != null && query.UniversityAreaName.Count > 0)
            {
                var newname = "";
                foreach (var item in query.UniversityAreaName)
                {
                    newname += "'" + item + "'" + ",";
                }
                newname = newname.Substring(0, newname.Length - 1);
                stringBuilder.AppendFormat(" and Area_Name in ({0})", newname);
            }
            if (query.SchoolLevel != null && query.SchoolLevel.Count > 0)
            {
                foreach (var item in query.SchoolLevel)
                {
                    if (item == 1)
                    {
                        stringBuilder.AppendFormat(" and Nhef=1");
                    }
                    else if (item == 2)
                    {
                        stringBuilder.AppendFormat(" and Sff=1");
                    }
                    else if (item == 3)
                    {
                        stringBuilder.AppendFormat(" and Syl=1");
                    }
                }
            }
            stringBuilder.AppendFormat(" order by rank asc");
            var university = await d_UniversityRepository.QuerySql(stringBuilder.ToString());
            if (university.Count <= 0)
                return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "所选院校数据完善中..." };
            var universityids = university.Select(x => x.Id).ToList();
            //var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
            //if (batchinfo.Count <= 0)
            //    return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
            //var batchids = batchinfo.Select(s => s.Id).ToList();

            //通过条件筛选出所有的
            var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();
            wheres.And(x => universityids.Contains(x.UniversityId) && x.IsDelete == false && x.PlanId == planinfo.FirstOrDefault().Id && x.BatchtypeId == query.BatchId && x.UniversityId > 0);
            //().Id && batchids.Contains(x.BatchtypeId) && x.UniversityId > 0);
            if (query.TradeIds != null && query.TradeIds.Count > 0)
            {
                //所选专业增加majorids筛选
                //query.MajorIds
                var majorclassinfo = await d_MajorClassRepository.Query(x => query.TradeIds.Contains(x.TradeId) && x.IsDelete == false);
                var CategoryClassids = majorclassinfo.Select(x => x.Id).ToList();
                var major = await d_MajorRepository.Query(x => x.IsDelete == false && CategoryClassids.Contains(x.CategoryClass_Id));
                if (major.Count() <= 0)
                    return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "所选专业大类数据完善中..." };
                var majornames = major.Select(x => x.MajorName).ToList();
                wheres.And(x => majornames.Contains(x.MajorName));
            }
            //根据上述所有筛选  求出招生计划
            var plandesc = await _dal.Query(wheres, "Scoreline desc");
            if (plandesc.Count <= 0)
                return new MessageModel<List<CWBEnrollmentPlanResult>>() { success = false, msg = "符合条件招生条件为空..." };
            List<UniversityEnrollmentPlanResult> c = new List<UniversityEnrollmentPlanResult>() { };
            List<UniversityEnrollmentPlanResult> w = new List<UniversityEnrollmentPlanResult>() { };
            List<UniversityEnrollmentPlanResult> b = new List<UniversityEnrollmentPlanResult>() { };
            var start = query.PageSize * (query.PageIndex - 1);
            var end = query.PageIndex * query.PageSize;
            List<CWBEnrollmentPlanResult> list = new List<CWBEnrollmentPlanResult>() { };
            var chonguIds = plandesc.Where(k => k.Scoreline > 0 && (query.Score + 20 >= k.Scoreline && query.Score < k.Scoreline)).Select(e => e.UniversityId).Distinct().ToList();
            list.Add(new CWBEnrollmentPlanResult()
            {
                Name = "冲",
                Count = chonguIds.Count(),
                UniversityIds = chonguIds
            });
            var wenuIds = plandesc.Where(k => k.Scoreline > 0 && (query.Score >= k.Scoreline && query.Score - 25 <= k.Scoreline)).Select(e => e.UniversityId).Distinct().ToList();
            list.Add(new CWBEnrollmentPlanResult()
            {
                Name = "稳",
                Count = wenuIds.Count(),
                UniversityIds = wenuIds
            });
            var baouIds = plandesc.Where(k => k.Scoreline > 0 && (query.Score - 26 > k.Scoreline)).Select(e => e.UniversityId).Distinct().ToList();
            list.Add(new CWBEnrollmentPlanResult()
            {
                Name = "保",
                Count = baouIds.Count(),
                UniversityIds = baouIds
            });
            return new MessageModel<List<CWBEnrollmentPlanResult>>()
            {
                success = true,
                msg = "获取成功",
                response = list
            };
        }

        /// <summary>
        /// 冲稳保详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<PageModel<UniversityEnrollmentPlanResult>>> GetCWBUniversityDetail(CWBUniversityDetailQuery query)
        {

           // return await this.t_EnrollmentPlanedesc.GetCWBUniversityDetail(query);
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo == null)
                return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            var wheres = PredicateBuilder.New<T_EnrollmentPlanedesc>();
            wheres.And(x => x.IsDelete == false && x.PlanId == planinfo.FirstOrDefault().Id && x.UniversityId > 0);
            wheres.And(x => x.Scoreline > 0);
            if (query.UniversityIds != null && query.UniversityIds.Any())
            {
                wheres.And(x => query.UniversityIds.Contains(x.UniversityId));
            }

            //此处需加冲稳保
            if (query.AreaId != 821 && query.AreaId != 1047 && query.AreaId != 1965)
            {
                if (query.BatchId > 0)
                {
                    wheres.And(x => x.BatchtypeId == query.BatchId);
                }
            }
            //wheres.And(x => x.Scoreline > 0 && (query.Score >= x.Scoreline && query.Score - 25 <= x.Scoreline));
            if (string.IsNullOrWhiteSpace(query.Type))
            {
                wheres.And(x => x.Scoreline > 0 && (x.Scoreline <= query.Score + 15));
            }
            else
            {
                if (query.Type == "冲")
                {
                    wheres.And(x => x.Scoreline > 0 && (x.Scoreline <= query.Score + 15 && x.Scoreline > query.Score + 5));
                }
                else if (query.Type == "稳")
                {
                    wheres.And(x => x.Scoreline > 0 && (x.Scoreline <= query.Score + 5 && x.Scoreline > query.Score - 15));
                }
                else if (query.Type == "保")
                {
                    wheres.And(x => x.Scoreline > 0 && (x.Scoreline < query.Score - 15));
                }
            }
            //().Id && batchids.Contains(x.BatchtypeId) && x.UniversityId > 0);
            if (query.MajorIds != null && query.MajorIds.Count > 0)
            {
                //所选专业增加majorids筛选
                //query.MajorIds
                var major = await d_MajorRepository.Query(x => x.IsDelete == false && query.MajorIds.Contains(x.CategoryClass_Id));
                if (major.Count() <= 0)
                    return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "所选专业大类数据完善中..." };
                var majornames = major.Select(x => x.MajorName).ToList();
                wheres.And(x => majornames.Contains(x.MajorName));
            }
            //根据上述所有筛选  求出招生计划
            var plandesc = await _dal.Query(wheres, "Scoreline desc");
            int universityidcount = 0;
            var start = query.PageSize * (query.PageIndex - 1);
            var end = query.PageIndex * query.PageSize;

            var stringBuilderinfo = new StringBuilder();

            stringBuilderinfo.AppendFormat("select Rank,Id,Name,Logo,Nhef,Sff,Syl,Area_Name,AscriptionName from D_University where IsDelete=0");
            if (query.UniversityIds != null && query.UniversityIds.Count > 0)
            {
                universityidcount = query.UniversityIds.Count;
                string ids = string.Join(",", query.UniversityIds);
                stringBuilderinfo.AppendFormat("  and Id in ({0}) ", ids);
            }
            else
            {
                universityidcount = plandesc.Select(x => x.UniversityId).Distinct().Count();
                string ids = string.Join(",", plandesc.Select(x => x.UniversityId).Distinct().ToList());
                stringBuilderinfo.AppendFormat("  and Id in ({0}) ", ids);
            }
            stringBuilderinfo.AppendFormat("  limit {0},{1}", start, end);

            var sqldata = await d_UniversityRepository.QuerySql(stringBuilderinfo.ToString());
            if (sqldata.Count <= 0)
                return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>() { success = false, msg = "获取失败，数据为空" };
            var Type = query.Type;
            var list = sqldata.Select(item => new UniversityEnrollmentPlanResult()
            {
                UniversityName = item.Name,
                UniversityId = item.Id,
                Logo = item.Logo,
                Nhef = item.Nhef,
                Sff = item.Sff,
                Syl = item.Syl,
                planCount = plandesc.Where(x => x.UniversityId == item.Id).Sum(x => x.Plancount),
                PlanIds = plandesc.Where(x => x.UniversityId == item.Id).Select(x => x.Id).ToList(),
                AreaName = item.Area_Name,
                AscriptionName = item.AscriptionName,
                MjaorPlan = plandesc.Count(x => x.UniversityId == item.Id),
                Rank = item.Rank <= 0 ? "-" : item.Rank.ToString(),
                Type = plandesc.Where(x => x.UniversityId == item.Id && x.Scoreline <= query.Score + 15 && x.Scoreline > query.Score + 5).Any() ? "冲" : (plandesc.Where(x => x.Scoreline <= query.Score + 5 && x.Scoreline > query.Score - 15)).Any() ? "稳" : plandesc.Where(x => x.UniversityId == item.Id && x.Scoreline > 0 && query.Score > x.Scoreline).Any() ? "保" : "其他"
            }).ToList();
            return new MessageModel<PageModel<UniversityEnrollmentPlanResult>>()
            {
                success = true,
                msg = "获取成功",
                response = new PageModel<UniversityEnrollmentPlanResult>()
                {
                    data = list,
                    dataCount = universityidcount,
                    page = query.PageIndex,
                    PageSize = query.PageSize,
                    pageCount = (int)Math.Ceiling(universityidcount / Convert.ToDecimal(query.PageSize))
                }
            };





        }


        #region 转化Tag
        /// <summary>
        /// 转化出标签所有可能
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public List<string> GetTag(string tag)
        {
            var Nums = new List<string>();
            for (int i = 0; i < tag.Length; i++)
            {
                Nums.Add(tag[i].ToString());
            }
            Permutation(Nums.ToArray(), 0, Nums.ToArray().Length);

            //permut = GetTagExtened(tag, permut);
            return permut;
        }

        /// <summary>
        /// 递归实现全排序并输出
        /// </summary>
        /// <param name="nums">待排序的字符数组</param>
        /// <param name="m">输出字符数组的起始位置</param>
        /// <param name="n">输出字符数组的长度</param>
        public void Permutation(string[] nums, int m, int n)
        {
            int i;
            string t;
            if (m < n - 1)
            {
                Permutation(nums, m + 1, n);
                for (i = m + 1; i < n; i++)
                {
                    t = nums[m];
                    nums[m] = nums[i];
                    nums[i] = t;
                    Permutation(nums, m + 1, n);
                    t = nums[m];
                    nums[m] = nums[i];
                    nums[i] = t;
                }
            }
            else
            {
                string kk = string.Empty;
                for (int j = 0; j < nums.Length; j++)
                {
                    kk += nums[j];
                }
                permut.Add(kk);
            }
        }

        ///// <summary>                                                                            
        ///// 判断是否为不常见标签，若是则匹配相关联标签
        ///// </summary>
        ///// <param name="tag"></param>
        ///// <returns></returns>
        //public List<string> GetTagExtened(string tag, List<string> taglist)
        //{
        //    var list = new List<TagExTend>();
        //    var query = yd_tagExInfo.Get(a => a.Enabled == 1 && a.Tags.Equals(tag)).FirstOrDefault();
        //    if (query != null)
        //    {
        //        list = JsonConvert.DeserializeObject<List<TagExTend>>(query.tagEx);
        //    }
        //    if (list.Any() && list.Count() > 0)
        //    {
        //        taglist.AddRange(list.Select(s => s.tag).ToList());
        //    }
        //    return taglist;
        //}
        #endregion

        /// <summary>
        /// 获取分析结果录取概率  获取之后保存一下
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<UniversityProbabilityResult>> GetUniversityProbability(UniversityProbabilityQuery query)
        {
            var universityinfo = await d_UniversityRepository.QueryById(query.UniversityId);
            if (universityinfo == null)
                return new MessageModel<UniversityProbabilityResult>() { success = false, msg = "院校信息不存在" };
            UniversityProbabilityResult model = new UniversityProbabilityResult() { };
            #region  院校信息
            model.Logo = universityinfo.Logo;
            model.Name = universityinfo.Name;
            model.Nature = universityinfo.Nature;
            model.Nhef = universityinfo.Nhef > 0;
            model.Sff = universityinfo.Sff > 0;
            model.Syl = universityinfo.Syl > 0;
            model.AscriptionName = universityinfo.AscriptionName;
            model.Rank = universityinfo.Rank;
            model.AreaName = universityinfo.Area_Name;
            model.SubjectLevel = universityinfo.Subject_Level;
            #endregion
            var planinfobyarea = await t_EnrollmentPlaneRepository.Query(w => w.Area_Id == query.AreaId);
            var planinfo = planinfobyarea.Where(w => w.Years == query.Year);
            if (planinfo.Count() <= 0)
                return new MessageModel<UniversityProbabilityResult>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            var planallids = planinfobyarea.Select(x => x.Id).ToList();
            var planid = planinfo.Select(x => x.Id).FirstOrDefault();
            var descinfobyuniv = await _dal.Query(x => planallids.Contains(x.PlanId) && x.UniversityId == query.UniversityId && x.IsDelete == false);
            float universityminimum = 0;
            //省份的80%分数
            var regionscore = (await t_RegionScoreRepository.Query(x => x.IsDelete == false && x.AreaId == query.AreaId && x.Year == query.Year)).FirstOrDefault();
            var descinfo = descinfobyuniv.Where(x => x.PlanId == planid).ToList();
            if (descinfo.Count <= 0)
            {
                return new MessageModel<UniversityProbabilityResult>()
                {
                    success = false,
                    msg = "此学校最新招生分数线暂未估测成功"
                };
                //Random random = new Random() { };
                //var randomcc = random.Next(6, 8);
                //var newrendom = randomcc / float.Parse(10.ToString()); ;
                //universityminimum = random.Next(6, 8);
            }
            else
            {
                universityminimum = descinfo.OrderByDescending(x => x.Scoreline).Select(x => x.Scoreline).FirstOrDefault();
            }
            //return new MessageModel<UniversityProbabilityResult>() { success = false, msg = "招生计划为空，正在完善中..." };
            var isprobab = await u_ProbabilityHistoryRepository.Query(x => x.CustomerId == query.CustomerId && x.UniversityId == query.UniversityId);
            if (isprobab.Count <= 0)
            {
                //没得话测试
                //院校对该省份的招生最低分
                if (regionscore == null)
                    return new MessageModel<UniversityProbabilityResult>()
                    {
                        success = false,
                        msg = "获取失败，当前省份满分数据为空"
                    };
                var now80score = regionscore.Score * (float)0.8;
                if (universityminimum >= now80score)
                {
                    float num = 50;
                    if (query.Score >= universityminimum)
                    {
                        var cha = query.Score - universityminimum;
                        var add = cha * 2;
                        if (add >= 46)
                        {
                            num = 96;
                        }
                        else
                        {
                            num += add;
                        }
                    }
                    else
                    {
                        var cha = universityminimum - query.Score;
                        if (cha >= 49)
                        {
                            num = 1;
                        }
                        else
                        {
                            num -= cha;
                        }
                    }
                    model.Probability = num;
                    //每 + 0.5分，成功率增加1 %，最高96 %
                    //每 - 1分，成功率减少1 %，最低1 %
                }
                else
                {
                    float num = 50;
                    if (query.Score >= universityminimum)
                    {
                        var cha = query.Score - universityminimum;
                        if (cha >= 46)
                        {
                            num = 96;
                        }
                        else
                        {
                            num += cha;
                        }
                    }
                    else
                    {
                        var cha = universityminimum - query.Score;
                        if (cha >= 49)
                        {
                            num = 1;
                        }
                        else
                        {
                            num -= cha;
                        }
                    }
                    model.Probability = num;
                    //每 + 1分，成功率增加1 %，最高96 %
                    //每 - 1分，成功率减少1 %，最低1 %
                }
                var random = RadomHelper.RandNumZF(1);
                model.EstimateScore = universityminimum + float.Parse(random);

                var addresult = await u_ProbabilityHistoryRepository.Add(new U_ProbabilityHistory()
                {
                    CustomerId = query.CustomerId,
                    EstimateScore = model.EstimateScore,
                    Probability = Convert.ToInt32(model.Probability),
                    UniversityId = query.UniversityId,
                    AreaId = query.AreaId,
                    Year = query.Year
                });
            }
            else
            {
                //有的话从历史数据拿
                var oldinfo = isprobab.FirstOrDefault();
                model.EstimateScore = oldinfo.EstimateScore;
                model.Probability = oldinfo.Probability;
            }
            var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.IsDelete == false);
            var YearBatchScores = new List<YearBatchScore>() { };
            foreach (var item in planinfobyarea.OrderByDescending(x => x.Years).ToList())
            {
                var lowscore = descinfobyuniv.Where(x => x.PlanId == item.Id).OrderBy(x => x.Scoreline).FirstOrDefault();
                if (lowscore != null && lowscore.Scoreline > 0)
                {
                    YearBatchScores.Add(new YearBatchScore()
                    {
                        Year = item.Years,
                        Score = lowscore.Scoreline,
                        BatchName = batchinfo.Where(x => x.Id == lowscore.BatchtypeId).Select(x => x.Batch_name).FirstOrDefault()
                    });
                }
            }
            model.YearBatchScores = YearBatchScores;
            model.Proposal = GetProposal(model.Probability);
            return new MessageModel<UniversityProbabilityResult>()
            {
                success = true,
                msg = "获取成功",
                response = model
            };
        }

        #region  获取Proposal建议
        public string GetProposal(float Probability)
        {
            if (Probability >= 85)
            {
                return "成功几率很高，建议填报";
            }
            else if (Probability >= 65)
            {
                return "成功几率较好，建议可以填报";
            }
            else if (Probability >= 50)
            {
                return "成功几率较低，建议谨慎考虑";
            }
            else if (Probability >= 35)
            {
                return "风险过高，建议谨慎考虑";
            }
            else
            {
                return "风险过高，不建议填报";
            }
        }
        #endregion

        /// <summary>
        /// 获取概率历史记录列表
        /// </summary>
        /// <returns></returns>
        public async Task<MessageModel<PageModel<ProbabilityResult>>> GetProbabilityResult(ProbabilityQuery query)
        {
            var info = await u_ProbabilityHistoryRepository.QueryPage(x => x.IsDelete == false && x.CustomerId == query.CustomerId, query.PageIndex, query.PageSize, "CreateTime desc");
            if (info.data.Count <= 0)
                return new MessageModel<PageModel<ProbabilityResult>>() { success = false, msg = "获取失败，暂未测试录取概率" };
            var universityids = info.data.Select(x => x.UniversityId).ToList();
            var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false, "Rank asc");
            List<ProbabilityResult> list = new List<ProbabilityResult>() { };
            foreach (var item in info.data)
            {
                list.Add(new ProbabilityResult()
                {
                    Id = item.Id,
                    AreaId = item.AreaId,
                    EstimateScore = item.EstimateScore,
                    Probability = item.Probability,
                    UniversityId = item.UniversityId,
                    UniversityName = universityinfo.Where(x => x.Id == item.UniversityId).Select(x => x.Name).FirstOrDefault(),
                    Year = item.Year
                });
            }
            return new MessageModel<PageModel<ProbabilityResult>>()
            {
                success = true,
                msg = "获取成功",
                response = new PageModel<ProbabilityResult>()
                {
                    data = list,
                    dataCount = info.dataCount,
                    page = info.page,
                    pageCount = info.pageCount,
                    PageSize = info.PageSize
                }
            };
        }

        /// <summary>
        /// 保存志愿表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<bool>> SaveVolunteerTable(VolunteerTableQuery query)
        {
            //if (query.TableId > 0)
            //{

            //}
            //u_VolunteerTableRepository   u_VolunteerTableDetailRepository
            var table = await u_VolunteerTableRepository.Query(x => x.IsDelete == false && x.CustomerId == query.CustomerId);
            var num = table.Count() + 1;
            var TableName = "我的志愿表" + num;
            var addtable = await u_VolunteerTableRepository.Add(new U_VolunteerTable()
            {
                CustomerId = query.CustomerId,
                VolunteerTableName = TableName
            });
            if (addtable > 0)
            {
                List<U_VolunteerTableDetail> list = new List<U_VolunteerTableDetail>() { };
                foreach (var item in query.details)
                {
                    list.Add(new U_VolunteerTableDetail()
                    {
                        PlanMajorIds = string.Join(",", item.PlanMagorIds),
                        UniversityId = item.UniversityId,
                        UniversityName = item.UniversityName,
                        VolunteerTableId = addtable
                    });
                }
                var adddetail = await u_VolunteerTableDetailRepository.Add(list);
                if (adddetail > 0)
                {
                    return new MessageModel<bool>() { success = true, msg = "保存成功" };
                }
                else
                {
                    return new MessageModel<bool>() { success = false, msg = "保存失败" };
                }
            }
            return new MessageModel<bool>() { success = true, msg = "保存成功" };
        }

        /// <summary>
        /// 获取个人志愿列表  传Id
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<VolunteerTableListResult>>> GetVolunteerTableList(IdQuery query)
        {
            var info = await u_VolunteerTableRepository.Query(x => x.IsDelete == false && x.CustomerId == query.CustomerId);
            if (info.Count <= 0)
                return new MessageModel<List<VolunteerTableListResult>>() { success = false, msg = "获取失败，暂无志愿表" };
            return new MessageModel<List<VolunteerTableListResult>>()
            {
                success = true,
                msg = "获取成功",
                response = info.Select(x => new VolunteerTableListResult()
                {
                    Id = x.Id,
                    Name = x.VolunteerTableName,
                    CreateTime = x.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")
                }).ToList()
            };
        }

        /// <summary>
        /// 获取志愿表详情  传Id
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<VolunteerTableResult>>> GetVolunteerTableDetail(IdQuery query)
        {
            var info = await u_VolunteerTableDetailRepository.Query(x => x.IsDelete == false && x.VolunteerTableId == query.Id);
            if (info == null)
                return new MessageModel<List<VolunteerTableResult>>() { success = false, msg = "获取失败，数据不存在" };
            List<VolunteerTableResult> list = new List<VolunteerTableResult>() { };
            var planstringids = info.Select(x => x.PlanMajorIds).ToList();
            List<int> PlanIds = new List<int>() { };
            foreach (var item in planstringids)
            {
                if (!string.IsNullOrWhiteSpace(item))
                {
                    var newids = item.Split(",").Select(x => int.Parse(x)).ToList();
                    PlanIds.AddRange(newids);
                }
            }
            var descinfo = await _dal.Query(x => x.IsDelete == false && PlanIds.Contains(x.Id));
            foreach (var item in info)
            {
                if (!string.IsNullOrWhiteSpace(item.PlanMajorIds))
                {
                    var planids = item.PlanMajorIds.Split(",").Select(x => int.Parse(x)).ToList();
                var nowdesc = descinfo.Where(x => planids.Contains(x.Id)).ToList();
                if (nowdesc.Count <= 0)
                    continue;
                //此处处理针对于霍兰德推荐的具有相同学校的案例
                var count = list.Where(x => x.UniversityName == item.UniversityName).ToList();
                    if (count.Count > 0)
                    {
                        var newinfos = nowdesc.Select(x => new PlanInfo()
                        {
                            Money = x.Tuitionfee,
                            Year = x.Studyyears == null ? "-" : x.Studyyears == "" ? "-" : x.Studyyears,
                            PlanName = x.MajorName,
                            PlanNum = x.Plancount,
                            Scoreline = x.Scoreline
                        }).ToList();
                        count.FirstOrDefault().Infos.AddRange(newinfos);

                    }
                    else
                    {
                        string yearname = string.Empty;
                        if (query.CustomerId.HasValue)
                        {
                            yearname = (await this._CustomerInfoRepository.QueryById(query.CustomerId)).Year.ToString();
                        }
                        list.Add(new VolunteerTableResult()
                        {
                            UniversityName = item.UniversityName,

                            Infos = nowdesc.Select(x => new PlanInfo()
                            {
                                Money = x.Tuitionfee,
                                Year = x.Studyyears == null ? "-" : x.Studyyears == "" ? "-" : x.Studyyears,
                                YearName = yearname,
                                PlanName = x.MajorName,
                                PlanNum = x.Plancount,
                                Scoreline = x.Scoreline
                            }).ToList()
                        });
                    }
                }

            }
            return new MessageModel<List<VolunteerTableResult>>() { success = true, msg = "获取成功", response = list };
        }

        /// <summary>
        /// 删除志愿表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<bool>> DeleteVolunteerTable(IdQuery query)
        {
            var info = await u_VolunteerTableRepository.QueryById(query.Id);
            if (info == null)
                return new MessageModel<bool>() { success = false, msg = "删除失败，数据不存在" };
            info.IsDelete = true;
            var result = await u_VolunteerTableRepository.Update(info);
            if (result)
            {
                return new MessageModel<bool>() { success = true, msg = "删除成功" };
            }
            else
            {
                return new MessageModel<bool>() { success = false, msg = "删除失败" };
            }
        }

        /// <summary>
        /// 保存志愿表 霍兰德专用
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<bool>> SaveHollandVolunteer(HollandVolunteerTableQuery query)
        {
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo.Count <= 0)
                return new MessageModel<bool>() { success = false, msg = "传入年份省份有误" };
            var planid = planinfo.Select(x => x.Id).FirstOrDefault();
            var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
            if (batchinfo.Count <= 0)
                return new MessageModel<bool>() { success = false, msg = "传入年份省份有误" };
            var batchids = batchinfo.Select(s => s.Id).ToList();
            var majorlists = query.infos.Select(x => x.MajorName).ToList();
            var descinfo = await _dal.Query(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0 && batchids.Contains(x.BatchtypeId));
            //数据处理添加
            List<U_VolunteerTableDetail> list = new List<U_VolunteerTableDetail>() { };
            var table = await u_VolunteerTableRepository.Query(x => x.IsDelete == false && x.CustomerId == query.CustomerId);
            var num = table.Count() + 1;
            var TableName = "我的志愿表" + num;
            var addtable = await u_VolunteerTableRepository.Add(new U_VolunteerTable()
            {
                CustomerId = query.CustomerId,
                VolunteerTableName = TableName
            });
            if (addtable > 0)
                foreach (var item in query.infos)
                {
                    foreach (var s in item.universitys)
                    {
                        var plandescid = descinfo.Where(x => x.UniversityId == s.UniversityId && x.MajorName == item.MajorName).Select(x => x.Id).FirstOrDefault();
                        list.Add(new U_VolunteerTableDetail()
                        {
                            PlanMajorIds = plandescid.ToString(),
                            UniversityId = s.UniversityId,
                            UniversityName = s.UniversityName,
                            VolunteerTableId = addtable
                        });
                    }
                }
            return new MessageModel<bool>() { success = true, msg = "保存成功" };
        }

        /// <summary>
        /// 获取一键生成的志愿表 
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<SimuVolunteerTableResult>>> GetAutoVolunteerTableDetail(VolunteerTableQuery query)
        {
            if (query.details == null)
                return new MessageModel<List<SimuVolunteerTableResult>>() { success = false, msg = "选择专业院校为空..." };
            List<SimuVolunteerTableResult> list = new List<SimuVolunteerTableResult>() { };
            //var planstringids = query.details.Select(x => x.PlanMagorIds).ToList();
            List<int> PlanIds = new List<int>() { };
            var id = 0;
            foreach (var item in query.details)
            {
                if (item.PlanMagorIds != null && item.PlanMagorIds.Count() > 0)
                {
                    PlanIds.AddRange(item.PlanMagorIds);
                    id = item.PlanMagorIds.First();
                }
            }
            string yearName = string.Empty;
            var plandescmodels = await this.t_EnrollmentPlanedesc.QueryById(id);
            if (plandescmodels != null)
            {
                var planinfo = await this.t_EnrollmentPlaneRepository.QueryById(plandescmodels.PlanId);
                if (planinfo != null)
                    yearName = planinfo.Years.ToString();
            }
            var descinfo = await _dal.Query(x => x.IsDelete == false && PlanIds.Contains(x.Id));
            var universityids = query.details.Select(x => x.UniversityId).ToList();
            var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false, "Rank asc");
            foreach (var item in query.details)
            {
                if (item.PlanMagorIds != null && item.PlanMagorIds.Count() > 0)
                {

                    var nowdesc = descinfo.Where(x => item.PlanMagorIds.Contains(x.Id)).ToList();
                    if (nowdesc.Count <= 0)
                        continue;
                    var nowuniversityinfo = universityinfo.Where(x => x.Id == item.UniversityId).FirstOrDefault();
                    if (nowuniversityinfo == null)
                        continue;
                    //此处处理针对于霍兰德推荐的具有相同学校的案例
                    var count = list.Where(x => x.UniversityName == item.UniversityName).ToList();
                    if (count.Count > 0)
                    {
                        var newinfos = nowdesc.Select(x => new PlanInfo()
                        {
                            MajorId = x.Id,
                            Money = x.Tuitionfee,
                            Year = x.Studyyears,
                            PlanName = x.MajorName,
                            PlanNum = x.Plancount,
                            Scoreline = x.Scoreline
                        }).ToList();
                        count.FirstOrDefault().Infos.AddRange(newinfos);
                    }
                    else
                    {
                        list.Add(new SimuVolunteerTableResult()
                        {
                            Logo = nowuniversityinfo.Logo,
                            Nhef = nowuniversityinfo.Nhef > 0,
                            Rank = nowuniversityinfo.Rank,
                            Sff = nowuniversityinfo.Sff > 0,
                            Syl = nowuniversityinfo.Syl > 0,
                            UniversityId = item.UniversityId,
                            UniversityName = item.UniversityName,
                            Province = nowuniversityinfo.Area_Name,
                            Nature = nowuniversityinfo.Nature,
                            Infos = nowdesc.Select(x => new PlanInfo()
                            {
                                MajorId = x.Id,
                                Money = x.Tuitionfee,
                                Year = x.Studyyears,
                                PlanName = x.MajorName,
                                PlanNum = x.Plancount,
                                Scoreline = x.Scoreline,
                                YearName = yearName
                            }).ToList()
                        });
                    }
                }
            }
            return new MessageModel<List<SimuVolunteerTableResult>>() { success = true, msg = "获取成功", response = list };
        }

        /// <summary>
        /// 获取霍兰德一键生成的志愿表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<SimuVolunteerTableResult>>> GetHollandVolunteerTableDetail(HollandVolunteerTableQuery query)
        {
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo.Count <= 0)
                return new MessageModel<List<SimuVolunteerTableResult>>() { success = false, msg = "传入年份省份有误" };
            var planid = planinfo.Select(x => x.Id).FirstOrDefault();
            var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
            if (batchinfo.Count <= 0)
                return new MessageModel<List<SimuVolunteerTableResult>>() { success = false, msg = "传入年份省份有误" };
            var batchids = batchinfo.Select(s => s.Id).ToList();
            var majorlists = query.infos.Select(x => x.MajorName).ToList();
            var descinfo = await _dal.Query(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.Scoreline <= query.Score && x.UniversityId > 0 && batchids.Contains(x.BatchtypeId));
            //数据处理添加
            var universityids = new List<int>() { };
            foreach (var item in query.infos)
            {
                foreach (var s in item.universitys)
                {
                    universityids.Add(s.UniversityId);
                }
            }
            var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false, "Rank asc");
            List<SimuVolunteerTableResult> list = new List<SimuVolunteerTableResult>() { };
            foreach (var item in query.infos)
            {
                foreach (var s in item.universitys)
                {
                    var nowuniversityinfo = universityinfo.Where(x => x.Id == s.UniversityId).FirstOrDefault();
                    if (nowuniversityinfo == null)
                        continue;
                    var plandescid = descinfo.Where(x => x.UniversityId == s.UniversityId && x.MajorName == item.MajorName).Select(x => x.Id).FirstOrDefault();
                    var nowdesc = descinfo.Where(x => plandescid == x.Id).ToList();
                    var count = list.Where(x => x.UniversityName == s.UniversityName && x.UniversityId == s.UniversityId).ToList();
                    if (count.Count > 0)
                    {
                        var newinfos = nowdesc.Select(x => new PlanInfo()
                        {
                            MajorId = x.Id,
                            Money = x.Tuitionfee,
                            Year = x.Studyyears,
                            PlanName = x.MajorName,
                            PlanNum = x.Plancount,
                            Scoreline = x.Scoreline
                        }).ToList();
                        count.FirstOrDefault().Infos.AddRange(newinfos);
                    }
                    else
                    {
                        list.Add(new SimuVolunteerTableResult()
                        {
                            Logo = nowuniversityinfo.Logo,
                            Nhef = nowuniversityinfo.Nhef > 0,
                            Rank = nowuniversityinfo.Rank,
                            Sff = nowuniversityinfo.Sff > 0,
                            Syl = nowuniversityinfo.Syl > 0,
                            UniversityId = s.UniversityId,
                            UniversityName = s.UniversityName,
                            Infos = nowdesc.Select(x => new PlanInfo()
                            {
                                MajorId = x.Id,
                                Money = x.Tuitionfee,
                                Year = x.Studyyears,
                                PlanName = x.MajorName,
                                PlanNum = x.Plancount,
                                Scoreline = x.Scoreline
                            }).ToList()
                        });
                    }
                }
            }
            return new MessageModel<List<SimuVolunteerTableResult>>() { success = true, msg = "获取成功", response = list };
        }

        /// <summary>
        /// 根据标签推荐选科
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<string>> GetSubjectSelectByTag(ByTagSubjectSelectQuery query)
        {
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo == null)
                return new MessageModel<string>() { success = false, msg = "所选省份年份的招生计划，正在完善中..." };
            var planid = planinfo.FirstOrDefault().Id;
            if (string.IsNullOrWhiteSpace(query.Tag))
                return new MessageModel<string>() { success = false, msg = "标签传入为空,请去测试" };
            var newTags = GetTag(query.Tag);
            var planmaptag = await t_PlanMapTagRepository.Query(x => x.IsDelete == false);
            List<string> majorlists = new List<string>() { };
            foreach (var item in newTags)
            {
                majorlists.AddRange(planmaptag.Where(x => x.Tag.Contains(item)).Select(x => x.Name).ToList());
            }
            majorlists = majorlists.Distinct().ToList();
            var descinfo = await _dal.Query(x => x.IsDelete == false && x.PlanId == planid && majorlists.Contains(x.MajorName) && x.UniversityId > 0);
            List<IdNameResult> list = new List<IdNameResult>() { };
            list.Add(new IdNameResult() { Name = "物", Id = descinfo.Count(x => x.Subjectclaim.Contains("物")) });
            list.Add(new IdNameResult() { Name = "化", Id = descinfo.Count(x => x.Subjectclaim.Contains("化")) });
            list.Add(new IdNameResult() { Name = "生", Id = descinfo.Count(x => x.Subjectclaim.Contains("生")) });
            list.Add(new IdNameResult() { Name = "政", Id = descinfo.Count(x => x.Subjectclaim.Contains("政")) });
            list.Add(new IdNameResult() { Name = "史", Id = descinfo.Count(x => x.Subjectclaim.Contains("史")) });
            list.Add(new IdNameResult() { Name = "地", Id = descinfo.Count(x => x.Subjectclaim.Contains("地")) });

            var result = list.OrderByDescending(x => x.Id).Select(x => x.Name).Take(3);

            return new MessageModel<string>()
            {
                success = true,
                msg = "获取成功",
                response = string.Join("|", result)
            };
        }

        /// <summary>
        /// 获取喜欢的院校
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<LikeSchoolMajor>>> GetLikeSchoolMajor(IdQuery query)
        {
            var table = await u_VolunteerTableRepository.Query(x => x.IsDelete == false && x.CustomerId == query.Id);
            if (table.Count <= 0)
                return new MessageModel<List<LikeSchoolMajor>>() { success = false, msg = "未生成志愿表" };
            var tableids = table.Select(x => x.Id).ToList();
            var detail = await u_VolunteerTableDetailRepository.Query(x => x.IsDelete == false && tableids.Contains(x.VolunteerTableId));
            if (detail.Count <= 0)
                return new MessageModel<List<LikeSchoolMajor>>() { success = false, msg = "数据为空" };
            List<int> ids = new List<int>() { };
            foreach (var item in detail)
            {
                var newplaninfo = item.PlanMajorIds.Split(",").ToList();
                foreach (var s in newplaninfo)
                {
                    int id = Convert.ToInt32(s);
                    ids.Add(id);
                }
            }
            var info = await _dal.Query(x => x.IsDelete == false && ids.Contains(x.Id));
            List<LikeSchoolMajor> list = new List<LikeSchoolMajor>() { };
            foreach (var item in detail)
            {
                var newplaninfo = item.PlanMajorIds.Split(",").ToList();
                foreach (var s in newplaninfo)
                {
                    int id = Convert.ToInt32(s);
                    var planname = info.Where(x => x.Id == id).Select(x => x.MajorName).FirstOrDefault();
                    if (string.IsNullOrWhiteSpace(planname))
                        continue;
                    list.Add(new LikeSchoolMajor()
                    {
                        SchoolName = item.UniversityName,
                        MajorName = planname
                    });
                }
            }
            return new MessageModel<List<LikeSchoolMajor>>() { success = true, msg = "获取成功", response = list };

        }

        /// <summary>
        /// 专业规划
        /// </summary>
        /// <returns></returns>
        public async Task<MessageModel<List<MajorPlanResult>>> GetMajorPlanClaim(CustomerQuery query)
        {
            //查招生计划
            var planinfo = await t_EnrollmentPlaneRepository.Query(w => w.Years == query.Year && w.Area_Id == query.AreaId);
            if (planinfo == null)
                return new MessageModel<List<MajorPlanResult>>() { success = false, msg = "招生计划为空" };
            var planid = planinfo.Select(x => x.Id).FirstOrDefault();
            //12 大类
            var majorcate = await d_MajorCategoryRepository.Query(x => x.IsDelete == false && x.Type == 1);
            //二级类
            var majorcateids = majorcate.Select(x => x.Id).ToList();
            var majorclass = await d_MajorClassRepository.Query(x => x.IsDelete == false && majorcateids.Contains(x.TradeId));
            //三级类
            var majorclassids = majorclass.Select(x => x.Id).ToList();
            var major = await d_MajorRepository.Query(x => x.IsDelete == false && majorclassids.Contains(x.CategoryClass_Id));
            //通过三级类的名称去匹配 subjectclaim 选科信息
            //没有的话就给个无选科要求
            var batchinfo = await t_EnrollmentBatchRepository.Query(x => x.Year == query.Year && x.AreaName == query.AreaName && !x.Batch_name.Contains("提前"));
            if (batchinfo.Count <= 0)
                return new MessageModel<List<MajorPlanResult>>() { success = false, msg = "所属年份数据批次为空..." };
            var batchids = batchinfo.Select(s => s.Id).ToList();
            var plandesc = await _dal.Query(x => x.IsDelete == false && x.PlanId == planid && batchids.Contains(x.BatchtypeId) && x.UniversityId > 0, "Scoreline desc");
            List<MajorPlanResult> list = new List<MajorPlanResult>() { };
            foreach (var item in majorcate)
            {
                List<MajorClaim> majors = new List<MajorClaim>() { };
                var newmajorclassids = majorclass.Where(x => x.TradeId == item.Id).Select(x => x.Id).ToList();
                var newmajorinfo = major.Where(x => newmajorclassids.Contains(x.CategoryClass_Id));
                foreach (var s in newmajorinfo)
                {
                    var claim = plandesc.Where(x => x.MajorName == s.MajorName).Select(x => x.Subjectclaim).FirstOrDefault();
                    majors.Add(new MajorClaim()
                    {
                        MajorName = s.Name,
                        Claim = GetClaim(claim)
                    });
                }
                list.Add(new MajorPlanResult()
                {
                    Name = item.Name,
                    Majors = majors
                });
            }
            return new MessageModel<List<MajorPlanResult>>() { success = true, msg = "获取成功", response = list };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="claim"></param>
        /// <returns></returns>
        public string GetClaim(string claim)
        {
            var returnclaim = claim;
            switch (claim)
            {
                case "不限":
                    returnclaim = "无限制";
                    break;
                case "":
                    returnclaim = "无限制";
                    break;
                case null:
                    returnclaim = "无限制";
                    break;
                case "无限制":
                    returnclaim = "无限制";
                    break;
                default:
                    returnclaim = claim;
                    break;
            }
            return returnclaim;
        }

        /// <summary>
        /// 获取批次
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MessageModel<List<IdNameResult>>> GetBatchByYearArea(YearAreaQuery query)
        {
            var info = await t_EnrollmentBatchRepository.Query(x => x.IsDelete == false && x.AreaName == query.AreaName && x.Year == query.Year && !x.Batch_name.Contains("提前") && !x.Batch_name.Contains("零志愿"));
            if (info.Count <= 0)
                return new MessageModel<List<IdNameResult>>() { success = false, msg = "数据为空" };

            List<IdNameResult> list = new List<IdNameResult>() { };
            foreach (var item in info)
            {
                if (item.Type != "不分文理")
                {
                    list.Add(new IdNameResult()
                    {
                        Id = item.Id,
                        Name = item.Batch_name + "(" + item.Type + ")",
                        Year = item.Year,
                        Score = item.ScoreLine
                    });
                }
                else
                {
                    list.Add(new IdNameResult()
                    {
                        Id = item.Id,
                        Name = item.Batch_name,
                        Year = item.Year,
                        Score = item.ScoreLine
                    });
                }
            }
            return new MessageModel<List<IdNameResult>>()
            {
                success = true,
                msg = "获取成功",
                response = list
            };
        }

        public Task<MessageModel<List<IdNameResult>>> GetBatchByAreaAndYear(BatchQuery query)
        {
            throw new NotImplementedException();
        }
    }
}