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.
165 lines
6.8 KiB
165 lines
6.8 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Cloudcar.Admin.Commons;
|
|
using Znyc.Cloudcar.Admin.Commons.Cache;
|
|
using Znyc.Cloudcar.Admin.Commons.Entitys;
|
|
using Znyc.Cloudcar.Admin.Commons.Enums;
|
|
using Znyc.Cloudcar.Admin.Commons.Extensions;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Pages;
|
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
|
|
|
|
|
|
|
|
|
namespace Znyc.Cloudcar.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class EquipmentService : BaseService<EquipmentEntity, EquipmentOutputDto, long>, IEquipmentService
|
|
{
|
|
private readonly IEquipmentRepository _equipmentRepository;
|
|
private readonly IDictionaryRepository _dictionaryRepository;
|
|
private readonly IUserRepository _userRepository;
|
|
private readonly IWxUnifyUserRepository _wxUnifyUserRepository;
|
|
private readonly IEquipmentPictureRepository _equipmentPictureRepository;
|
|
public EquipmentService(
|
|
IEquipmentRepository equipmentRepository,
|
|
IDictionaryRepository dictionaryRepository,
|
|
IUserRepository userRepository ,
|
|
IWxUnifyUserRepository wxUnifyUserRepository,
|
|
IEquipmentPictureRepository equipmentPictureRepository
|
|
) : base(equipmentRepository)
|
|
{
|
|
_userRepository = userRepository;
|
|
_equipmentRepository = equipmentRepository;
|
|
_dictionaryRepository = dictionaryRepository;
|
|
_wxUnifyUserRepository = wxUnifyUserRepository;
|
|
_equipmentPictureRepository = equipmentPictureRepository;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageResult<EquipmentOutputDto>> FindWithPagerSearchAsync(SearchEquipmentModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (!string.IsNullOrEmpty(search.StartTime))
|
|
{
|
|
@where += $" and StartTime >='{search.StartTime} 00:00:00'";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(search.EndTime))
|
|
{
|
|
@where += $" or EndTime <='{search.EndTime} 23:59:59'";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(search.Keywords))
|
|
{
|
|
@where += $" and Introduction like '%{search.Keywords}%'";
|
|
}
|
|
if (search.State > -1)
|
|
{
|
|
@where += $" and State={search.State}";
|
|
}
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
var equipments = (await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order)).MapTo<EquipmentOutputDto>();
|
|
if (equipments.Count > 0)
|
|
{
|
|
var users = await _userRepository.GetListWhereAsync();
|
|
var dictionarys = await _dictionaryRepository.GetListWhereAsync();
|
|
var wxUsers = await _wxUnifyUserRepository.GetListWhereAsync();
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
foreach (var equipment in equipments)
|
|
{
|
|
equipment.NickName = "";
|
|
var user = users.FirstOrDefault(x => x.Id == equipment.UserId);
|
|
if (user != null)
|
|
{
|
|
equipment.UserName = user?.UserName;
|
|
equipment.Avatar = user?.AvatarUrl;
|
|
var wxUser = wxUsers.FirstOrDefault(x => x.UnionId == user?.UnionId);
|
|
if (wxUser != null)
|
|
{
|
|
equipment.NickName = wxUser?.NickName;
|
|
}
|
|
equipment.IsPromote = user.IsPromote;
|
|
}
|
|
equipment.EquipmentTypeName = dictionarys.FirstOrDefault(x => x.Id == equipment.EquipmentType)?.Name;
|
|
equipment.EquipmentBrandName = dictionarys.FirstOrDefault(x => x.Id == equipment.EquipmentBrand)?.Name;
|
|
equipment.BoomLengthName = dictionarys.FirstOrDefault(x => x.Id == equipment.BoomLength)?.Name;
|
|
equipment.AutomobileChassisName = dictionarys.FirstOrDefault(x => x.Id == equipment.AutomobileChassis)?.Name;
|
|
equipment.StateName = typeof(EquipmentState).GetDescription((int)equipment.State);
|
|
var equipmentPictures = await _equipmentPictureRepository.GetListWhereAsync($" EquipmentId={equipment.Id}");
|
|
if (equipmentPictures != null && equipmentPictures.Any())
|
|
{
|
|
//设备图片
|
|
equipment.EquipmentPictures = equipmentPictures.Where(x => x.PictureType == 10).ToList();
|
|
//行驶证
|
|
equipment.DrivingPictures = equipmentPictures.Where(x => x.PictureType == 20).ToList();
|
|
}
|
|
|
|
//equipment.PageView =(await cacheHelper.HGetAsync("PageView", equipment.Id.ToString())).ToInt();
|
|
}
|
|
}
|
|
var pageResult = new PageResult<EquipmentOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = equipments,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下架
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> CancelAsync(long id)
|
|
{
|
|
|
|
CommonResult result = new CommonResult();
|
|
var equipment = await _equipmentRepository.GetAsync(id);
|
|
if (equipment != null)
|
|
{
|
|
equipment.State = (int)EquipmentState.Shelved;
|
|
result.Success = await _equipmentRepository.UpdateAsync(equipment, equipment.Id).ConfigureAwait(false);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public async Task<CommonResult> CompleteAsync(long id)
|
|
{
|
|
|
|
CommonResult result = new CommonResult();
|
|
var equipment = await _equipmentRepository.GetAsync(id);
|
|
if (equipment != null)
|
|
{
|
|
equipment.State = (int)EquipmentState.Traded;
|
|
result.Success = await _equipmentRepository.UpdateAsync(equipment, equipment.Id).ConfigureAwait(false);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|