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.
179 lines
6.4 KiB
179 lines
6.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
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.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>
|
|
/// Banner服务
|
|
/// </summary>
|
|
public class BannerService : BaseService<BannerEntity, BannerOutputDto, long>, IBannerService
|
|
{
|
|
private readonly IBannerRepository _bannerRepository;
|
|
|
|
public BannerService(
|
|
IBannerRepository bannerRepository
|
|
) : base(bannerRepository)
|
|
{
|
|
_bannerRepository = bannerRepository;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref=""></exception>
|
|
public async Task<PageResult<BannerOutputDto>> FindWithPagerSearchAsync(SearchBannerModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
//关键字查询
|
|
if (!string.IsNullOrEmpty(search.Keywords))
|
|
{
|
|
@where += $" and (PicDesc like '%{search.Keywords}%')";
|
|
}
|
|
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
//查询Banner表
|
|
List<BannerOutputDto> list = (await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order)).MapTo<BannerOutputDto>();
|
|
foreach (BannerOutputDto item in list)
|
|
{
|
|
item.PicUrl = CommonConst.Default_Banner_Prefix + item.PicUrl;
|
|
}
|
|
PageResult<BannerOutputDto> pageResult = new PageResult<BannerOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = list,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步新增数据
|
|
/// </summary>
|
|
/// <param name="intput">ʵ��</param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> InsertAsync(BannerEntity input)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
if (input.StartTime >= input.EndTime)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Time_Error;
|
|
return result;
|
|
}
|
|
if (input.EndTime < DateTime.Now)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.EndTime_Error;
|
|
return result;
|
|
}
|
|
input.PicUrl = input.PicUrl.Substring(input.PicUrl.LastIndexOf("/") + 1);
|
|
input.TextDesc = "";
|
|
if (input.StartTime > DateTime.Now)
|
|
{
|
|
input.State = (int)ActivityStatusEnum.NotStart;
|
|
}
|
|
if (input.StartTime < DateTime.Now && input.EndTime > DateTime.Now)
|
|
{
|
|
input.State = (int)ActivityStatusEnum.Ongoing;
|
|
}
|
|
result.Success = await repository.InsertAsync(input) > 0 ? true : false;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新Banner数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public async Task<CommonResult> UpdateAsync(BannerEntity input)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
if (input.StartTime >= input.EndTime)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Time_Error;
|
|
return result;
|
|
}
|
|
BannerEntity info = await repository.GetAsync(input.Id);
|
|
if (!(info?.Id > 0))
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Not_Exist;
|
|
return result;
|
|
}
|
|
info.PicUrl = input.PicUrl.Substring(input.PicUrl.LastIndexOf("/") + 1);
|
|
info.Name = input.Name;
|
|
info.Type = input.Type;
|
|
info.PageUrl = input.PageUrl;
|
|
info.Phone = input.Phone;
|
|
info.StartTime = input.StartTime;
|
|
info.EndTime = input.EndTime;
|
|
if (input.StartTime > DateTime.Now)
|
|
{
|
|
info.State = (int)ActivityStatusEnum.NotStart;
|
|
}
|
|
if (input.EndTime < DateTime.Now)
|
|
{
|
|
info.State = (int)ActivityStatusEnum.End;
|
|
}
|
|
if (input.StartTime < DateTime.Now && input.EndTime > DateTime.Now)
|
|
{
|
|
info.State = (int)ActivityStatusEnum.Ongoing;
|
|
}
|
|
info.ModifiedTime = input.ModifiedTime;
|
|
info.ModifiedUserId = input.ModifiedUserId;
|
|
await repository.UpdateAsync(info, input.Id).ConfigureAwait(false);
|
|
result.Success = true;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改广告状态
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> UpdateStatusAsync()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
List<BannerEntity> list = (await repository.GetListWhereAsync(" IsDeleted=0")).MapTo<BannerEntity>();
|
|
foreach (var item in list)
|
|
{
|
|
if (item.EndTime <= DateTime.Now)
|
|
{
|
|
item.State = (int)ActivityStatusEnum.End;
|
|
}
|
|
if (item.StartTime < DateTime.Now && item.EndTime > DateTime.Now)
|
|
{
|
|
item.State = (int)ActivityStatusEnum.Ongoing;
|
|
}
|
|
await repository.UpdateAsync(item, item.Id).ConfigureAwait(false);
|
|
}
|
|
cacheHelper.Remove("banner:list");
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|