220 lines
10 KiB
C#
220 lines
10 KiB
C#
|
|
using New_College.IServices;
|
|
using New_College.Model.Models;
|
|
using New_College.Services.BASE;
|
|
using New_College.IRepository.Base;
|
|
using New_College.Model;
|
|
using New_College.Model.ViewModels;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using New_College.IRepository;
|
|
using System.Linq;
|
|
using New_College.Common.Helper;
|
|
|
|
namespace New_College.Services
|
|
{
|
|
public class D_UniversityCollectionServices : BaseServices<D_UniversityCollection>, ID_UniversityCollectionServices
|
|
{
|
|
private readonly IBaseRepository<D_UniversityCollection> _dal;
|
|
private readonly ID_UniversityRepository d_UniversityRepository;
|
|
private readonly ID_MajorMapUniversityRepository d_MajorMapUniversityRepository;
|
|
private readonly ISysRegionRepository sysRegionRepository;
|
|
|
|
public D_UniversityCollectionServices(IBaseRepository<D_UniversityCollection> dal
|
|
, ID_UniversityRepository ID_UniversityRepository
|
|
, ID_MajorMapUniversityRepository ID_MajorMapUniversityRepository
|
|
, ISysRegionRepository ISysRegionRepository)
|
|
{
|
|
this._dal = dal;
|
|
d_UniversityRepository = ID_UniversityRepository;
|
|
d_MajorMapUniversityRepository = ID_MajorMapUniversityRepository;
|
|
sysRegionRepository = ISysRegionRepository;
|
|
base.BaseDal = dal;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取收藏和对比
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public async Task<MessageModel<PageModel<UniversityCollectionResult>>> GetUniversityCollection(UniversityCollectionQuery query)
|
|
{
|
|
var info = await _dal.QueryPage(x => x.CustomerId == query.CustomerId && x.IsDelete == false && x.Type == query.Type, query.PageIndex, query.PageSize, "CreateTime desc");
|
|
if (info.data.Count <= 0)
|
|
return new MessageModel<PageModel<UniversityCollectionResult>>() { success = false, msg = "数据为空" };
|
|
var universityids = info.data.Select(x => x.UniversityId).ToList();
|
|
var universityinfo = await d_UniversityRepository.Query(x => x.IsDelete == false && universityids.Contains(x.Id));
|
|
|
|
var HaveContrast = await _dal.Query(x => x.CustomerId == query.CustomerId && x.IsDelete == false && x.Type == 2);
|
|
List<UniversityCollectionResult> list = new List<UniversityCollectionResult>() { };
|
|
foreach (var item in info.data)
|
|
{
|
|
var nowinfo = universityinfo.Where(x => x.Id == item.UniversityId)?.FirstOrDefault();
|
|
if (nowinfo == null)
|
|
continue;
|
|
List<string> attribute = new List<string>() { };
|
|
//if (nowinfo.Nhef == 1)
|
|
// attribute.Add("985");
|
|
//if (nowinfo.Sff == 1)
|
|
// attribute.Add("211");
|
|
//if (nowinfo.Syl == 1)
|
|
// attribute.Add("双一流");
|
|
list.Add(new UniversityCollectionResult()
|
|
{
|
|
Id = item.Id,
|
|
UniversityId = nowinfo.Id,
|
|
Logo = nowinfo.Logo,
|
|
Syl = nowinfo.Syl == 1,
|
|
Nhef = nowinfo.Nhef == 1,
|
|
Sff = nowinfo.Sff == 1,
|
|
//Tags = attribute,
|
|
Name = nowinfo.Name,
|
|
IsContrast = HaveContrast.Count(x => x.UniversityId == item.UniversityId) > 0,
|
|
IsCollection = true,
|
|
AreaName = nowinfo.Area_Name,
|
|
SubjectLevel = nowinfo.Subject_Level
|
|
});
|
|
}
|
|
return new MessageModel<PageModel<UniversityCollectionResult>>()
|
|
{
|
|
success = true,
|
|
msg = "获取成功",
|
|
response = new PageModel<UniversityCollectionResult>()
|
|
{
|
|
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>> DeleteCollection(UniversityCollectionAddQuery query)
|
|
{
|
|
if (query.UniversityId <= 0)
|
|
return new MessageModel<bool>() { success = false, msg = "请先选择删除项" };
|
|
var info = await _dal.Query(x => x.CustomerId == query.CustomerId && x.UniversityId == query.UniversityId && x.Type == query.Type);
|
|
if (info.Count <= 0)
|
|
return new MessageModel<bool>() { success = false, msg = "所选不存在,或已被删除" };
|
|
foreach (var item in info)
|
|
{
|
|
item.IsDelete = true;
|
|
}
|
|
var result = await _dal.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>> AddCollection(UniversityCollectionAddQuery query)
|
|
{
|
|
var info = await _dal.Query(x => x.IsDelete == false && x.CustomerId == query.CustomerId && x.Type == query.Type && x.UniversityId == query.UniversityId);
|
|
if (info.Count() > 0)
|
|
return new MessageModel<bool>() { success = false, msg = "添加失败,所选院校已加入成功" };
|
|
var result = await _dal.Add(new D_UniversityCollection()
|
|
{
|
|
CustomerId = query.CustomerId,
|
|
Type = query.Type,
|
|
UniversityId = query.UniversityId
|
|
});
|
|
if (result > 0)
|
|
{
|
|
return new MessageModel<bool>() { success = true, msg = "添加成功" };
|
|
}
|
|
else
|
|
{
|
|
return new MessageModel<bool>() { success = false, msg = "添加失败" };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取院校对比结果
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<MessageModel<List<UniversitycontrastResult>>> GetUniversityContrasts(IdQuery query)
|
|
{
|
|
if (query.Ids == null || query.Ids.Count <= 0)
|
|
return new MessageModel<List<UniversitycontrastResult>>() { success = false, msg = "请选择需要对比的院校" };
|
|
var info = await d_UniversityRepository.Query(x => x.IsDelete == false && query.Ids.Contains(x.Id));
|
|
if (info.Count <= 0)
|
|
return new MessageModel<List<UniversitycontrastResult>>() { success = false, msg = "需要对比的院校数据为空" };
|
|
var majormap = await d_MajorMapUniversityRepository.Query(x => query.Ids.Contains(x.Universityid) && x.IsDelete == false);
|
|
List<UniversitycontrastResult> list = new List<UniversitycontrastResult>() { };
|
|
foreach (var c in info)
|
|
{
|
|
list.Add(new UniversitycontrastResult
|
|
{
|
|
Id = c.Id,
|
|
Name = c.Name,
|
|
Nature = c.Nature == 0 ? "公办" : c.Nature == 1 ? "民办" : c.Nature == 2 ? "中外合作" : "港澳台合作",
|
|
AscriptionName = string.IsNullOrWhiteSpace(c.AscriptionName) ? "-" : c.AscriptionName,
|
|
Rank = c.Rank,
|
|
AreaName = c.Area_Name,
|
|
Syl = c.Syl == 1 ? "是" : "否",
|
|
Nhef = c.Nhef == 1 ? "是" : "否",
|
|
Sff = c.Sff == 1 ? "是" : "否",
|
|
UniversityType = UniversityTypeRelsove.GetType(c.Type),
|
|
BuildDate = c.Build_Date,
|
|
SubjectLevel = c.Subject_Level == 1 ? "本科" : c.Subject_Level == 2 ? "专科" : "-",
|
|
AcademicianCount = c.Academician_Count <= 0 ? "-" : c.Academician_Count.ToString(),
|
|
DoctorateCount = c.Doctorate_Count <= 0 ? "-" : c.Doctorate_Count.ToString(),
|
|
MasterCount = c.Master_Count.ToString(),
|
|
MajorNum = majormap.Count(x => x.Universityid == c.Id).ToString()
|
|
});
|
|
}
|
|
return new MessageModel<List<UniversitycontrastResult>>()
|
|
{
|
|
success = true,
|
|
msg = "获取成功",
|
|
response = list
|
|
};
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 报告 获取我喜欢的院校
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public async Task<MessageModel<List<UniversityCollectionByMapResult>>> GetUniversityMap(IdQuery query)
|
|
{
|
|
var info = await _dal.Query(x => x.IsDelete == false && x.CustomerId == query.Id && x.Type == 1);
|
|
if (info.Count <= 0)
|
|
return new MessageModel<List<UniversityCollectionByMapResult>>() { success = false, msg = "暂未收藏学校" };
|
|
var universityids = info.Select(x => x.UniversityId).ToList();
|
|
var universityinfo = await d_UniversityRepository.Query(x => universityids.Contains(x.Id) && x.IsDelete == false, "Rank Asc");
|
|
if (universityinfo.Count <= 0)
|
|
return new MessageModel<List<UniversityCollectionByMapResult>>() { success = false, msg = "学校数据为空" };
|
|
var arealist = universityinfo.Select(x => x.Area_Name).Distinct().ToList();
|
|
var regioninfo = await sysRegionRepository.Query(x => arealist.Contains(x.RegionName));
|
|
if (regioninfo.Count <= 0)
|
|
return new MessageModel<List<UniversityCollectionByMapResult>>() { success = false, msg = "省份数据为空" };
|
|
return new MessageModel<List<UniversityCollectionByMapResult>>()
|
|
{
|
|
success = true,
|
|
msg = "获取成功",
|
|
response = regioninfo.Select(x => new UniversityCollectionByMapResult()
|
|
{
|
|
Lat = x.Lat,
|
|
Lng = x.Lng
|
|
}).ToList()
|
|
};
|
|
}
|
|
}
|
|
} |