You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
5.1 KiB
107 lines
5.1 KiB
using Znyc.CloudCar.Auth.HttpContextUser;
|
|
using Znyc.CloudCar.Configuration;
|
|
using Znyc.CloudCar.IRepository.Currency;
|
|
using Znyc.CloudCar.IRepository.Equipment;
|
|
using Znyc.CloudCar.IRepository.EquipmentPicture;
|
|
using Znyc.CloudCar.IRepository.User;
|
|
using Znyc.CloudCar.IServices.Browse;
|
|
using Znyc.CloudCar.IServices.CaChe;
|
|
using Znyc.CloudCar.Model.Dtos.Browse;
|
|
using Znyc.CloudCar.Model.Dtos.EquipmentPicture;
|
|
using Znyc.CloudCar.Model.Entities;
|
|
using Znyc.CloudCar.Model.ViewModels.ReportsCallBack;
|
|
using Znyc.CloudCar.Utility.Helper;
|
|
using static Znyc.CloudCar.Configuration.GlobalEnumVars;
|
|
|
|
namespace Znyc.CloudCar.Services.Browse
|
|
{
|
|
/// <summary>
|
|
/// 浏览记录服务
|
|
/// </summary>
|
|
public class BrowseService : IBrowseService
|
|
{
|
|
private readonly ICacheService _cacheService;
|
|
private readonly IHttpContextUser _httpContextUser;
|
|
private readonly IEquipmentRepository _equipmentRepository;
|
|
private readonly ICurrencyRecordRepository _currencyRecordRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IEquipmentPictureRepository _equipmentPictureRepository;
|
|
|
|
public BrowseService(
|
|
ICacheService cacheService,
|
|
IHttpContextUser httpContextUser,
|
|
IEquipmentRepository equipmentRepository,
|
|
ICurrencyRecordRepository currencyRecordRepository,
|
|
IUserRepository userRepository,
|
|
IEquipmentPictureRepository equipmentPictureRepository
|
|
)
|
|
{
|
|
_cacheService = cacheService;
|
|
_httpContextUser = httpContextUser;
|
|
_equipmentRepository = equipmentRepository;
|
|
_currencyRecordRepository = currencyRecordRepository;
|
|
_userRepository = userRepository;
|
|
_equipmentPictureRepository = equipmentPictureRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询浏览记录列表
|
|
/// </summary>
|
|
/// <param name="currentPage"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public async Task<ResponseOutput> PageAsync(int currentPage, int pageSize)
|
|
{
|
|
long total = await _cacheService.GetBrowseCountAsync(_httpContextUser.Id);
|
|
var list = (await _cacheService.GetBrowseAsync(_httpContextUser.Id)).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
|
|
List<long> equipmentIds = list.ConvertAll(s => long.Parse(s.Key));
|
|
List<BrowseListOutput> browseList = await _equipmentRepository.Select
|
|
.Where(x => equipmentIds.Contains(x.Id))
|
|
.OrderByDescending(x => x.IsTop)
|
|
.OrderByDescending(true, x => x.RefreshDate)
|
|
.Page(currentPage, pageSize)
|
|
.ToListAsync<BrowseListOutput>();
|
|
//积分记录
|
|
List<CurrencyRecordEntity> currencyRecordList = new List<CurrencyRecordEntity>();
|
|
if (_httpContextUser.Id > 0)
|
|
{
|
|
long[] cIds = browseList.Select(x => x.Id).Distinct().ToArray();
|
|
currencyRecordList = await _currencyRecordRepository.Where(x =>
|
|
cIds.Contains(x.CurrencySoureObjectId) &&
|
|
x.CurrencyType == (int)CurrencyType.CallPhone).ToListAsync();
|
|
}
|
|
long[] uIds = browseList.Select(x => x.UserId).Distinct().ToArray();
|
|
List<UserEntity> users = await _userRepository.Select.Where(x => uIds.Contains(x.Id)).ToListAsync();
|
|
//设备图片
|
|
long[] eIds = browseList.Select(x => x.Id).Distinct().ToArray();
|
|
List<EquipmentPictureOutput> equipmentPictures = await _equipmentPictureRepository.Select
|
|
.Where(x => x.IsDeleted == false && eIds.Contains(x.EquipmentId) && x.PictureType == (int)PictureTypeEnum.Equipment)
|
|
.ToListAsync<EquipmentPictureOutput>();
|
|
foreach (var item in browseList)
|
|
{
|
|
item.EquipmentPictures = equipmentPictures.FindAll(x => x.EquipmentId == item.Id);
|
|
UserEntity user = users.FirstOrDefault(x => x.Id == item.UserId);
|
|
item.UserName = user?.UserName ?? GlobalConstVars.User.Default_UserName;
|
|
item.AvatarUrl = GlobalConstVars.User.DefaultImagePrefix + (user?.AvatarUrl ?? GlobalConstVars.User.DefaultAvataUrl);
|
|
item.IsGetPhone = item.UserId == _httpContextUser.Id ? true : currencyRecordList.Exists(x => x.UserId == _httpContextUser.Id && x.CurrencySoureObjectId == item.Id);
|
|
item.ContactPhone = !item.IsGetPhone ? CommonHelper.ToHiddenPhone(item.ContactPhone) : item.ContactPhone;
|
|
item.CallPhoneCurrency = CommonHelper.GetCallPhoneCurrency(Convert.ToInt32(item.SellingPrice));
|
|
item.SellingPrice = item.SellingPrice / 10000;
|
|
|
|
}
|
|
PageOutput<BrowseListOutput> data = new PageOutput<BrowseListOutput>
|
|
{
|
|
List = browseList,
|
|
Total = total
|
|
};
|
|
ResponseOutput response = new ResponseOutput()
|
|
{
|
|
Data = data,
|
|
Successed = true,
|
|
Code = 1
|
|
};
|
|
return response;
|
|
}
|
|
|
|
}
|
|
}
|
|
|