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.
235 lines
9.1 KiB
235 lines
9.1 KiB
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.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 ActivityService : BaseService<ActivityEntity, ActivityOutputDto, long>, IActivityService
|
|
{
|
|
private readonly IActivityRepository _activityRepository;
|
|
private readonly IDictionaryService _dictionaryService;
|
|
|
|
public ActivityService(
|
|
IActivityRepository repository,
|
|
IDictionaryService dictionaryService
|
|
) : base(repository)
|
|
{
|
|
_activityRepository = repository;
|
|
_dictionaryService = dictionaryService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步新增数据
|
|
/// </summary>
|
|
/// <param name="intput">ʵ��</param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> InsertAsync(ActivityEntity 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;
|
|
}
|
|
var list = (await repository.GetListWhereAsync($" ActivityId={input.ActivityId} and State!=2")).MapTo<ActivityEntity>();
|
|
if (list.Count() > 0)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
if (input.StartTime < item.EndTime && input.EndTime > item.StartTime)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Time_Overlap;
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
input.ActivityId = input.ActivityId;
|
|
input.Icon = input.Icon.Substring(input.Icon.LastIndexOf("/") + 1);
|
|
input.StartTime = input.StartTime;
|
|
input.EndTime = input.EndTime;
|
|
input.PicUrl = input.PicUrl.Substring(input.PicUrl.LastIndexOf("/") + 1);
|
|
input.DetailPicUrl = input.DetailPicUrl.Substring(input.DetailPicUrl.LastIndexOf("/") + 1);
|
|
if (input.StartTime > DateTime.Now)
|
|
{
|
|
input.State = (int)ActivityStatusEnum.NotStart;
|
|
}else if(input.StartTime < DateTime.Now && input.EndTime > DateTime.Now)
|
|
{
|
|
input.State = (int)ActivityStatusEnum.Ongoing;
|
|
}
|
|
input.PageUrl = "";
|
|
input.PicDesc = "";
|
|
input.PicPageUrl = "";
|
|
input.TextDesc = input.TextDesc;
|
|
result.Success = await repository.InsertAsync(input) > 0 ? true : false;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageResult<ActivityOutputDto>> FindWithPagerSearchAsync(SearchActivityModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (search.State >= 0)
|
|
{
|
|
@where += $" and State={search.State}";
|
|
}
|
|
|
|
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 TextDesc like %{search.Keywords}%";
|
|
}
|
|
|
|
//if (search.Filter.ActivityId > 0)
|
|
//{
|
|
// @where += $" and ActivityId = {search.Filter.ActivityId}";
|
|
//}
|
|
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
List<ActivityOutputDto> list = (await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order)).MapTo<ActivityOutputDto>();
|
|
List<DictionaryListOutput> dictionaryList = await _dictionaryService.GetListByPidAsync(3);
|
|
foreach (ActivityOutputDto item in list)
|
|
{
|
|
item.Name = dictionaryList.Find(x => x.Id == item.ActivityId).Value;
|
|
item.Icon = CommonConst.Default_Activity_Prefix + item.Icon;
|
|
item.PicUrl = CommonConst.Default_Activity_Prefix + item.PicUrl;
|
|
item.DetailPicUrl = CommonConst.Default_Activity_Prefix + item.DetailPicUrl;
|
|
}
|
|
PageResult<ActivityOutputDto> pageResult = new PageResult<ActivityOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = list,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步更新数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> UpdateAsync(ActivityEntity input)
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
if (input.StartTime >= input.EndTime)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Time_Error;
|
|
return result;
|
|
}
|
|
var list = (await repository.GetListWhereAsync($" ActivityId={input.ActivityId} and State!=2 and Id!={input.Id}")).MapTo<ActivityEntity>();
|
|
if (list.Count() > 0)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
if (input.StartTime < item.EndTime && input.EndTime > item.StartTime)
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Time_Overlap;
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
ActivityEntity info =await repository.GetAsync(input.Id);
|
|
if (!(info?.Id > 0))
|
|
{
|
|
result.Success = false;
|
|
result.ErrMsg = ReturnConst.Not_Exist;
|
|
return result;
|
|
}
|
|
info.Icon = input.Icon.Substring(input.Icon.LastIndexOf("/") + 1);
|
|
info.ActivityId = input.ActivityId;
|
|
info.TextDesc = input.TextDesc;
|
|
info.StartTime = input.StartTime;
|
|
info.EndTime = input.EndTime;
|
|
info.PicUrl = input.PicUrl.Substring(input.PicUrl.LastIndexOf("/") + 1);
|
|
info.DetailPicUrl = input.DetailPicUrl.Substring(input.DetailPicUrl.LastIndexOf("/") + 1);
|
|
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<ActivityEntity> list = (await repository.GetListWhereAsync(" IsDeleted=0 and State!=2")).MapTo<ActivityEntity>();
|
|
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("activity:list");
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|