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.
132 lines
5.9 KiB
132 lines
5.9 KiB
using System;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
using Znyc.Cloudcar.Admin.Commons.Entitys;
|
|
using Znyc.Cloudcar.Admin.Commons.Helpers;
|
|
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
|
|
{
|
|
public class StatisticalService : BaseService<StatisticalEntity, StatisticalOutputDto, long>, IStatisticalService
|
|
{
|
|
private readonly IApplyJobService _applyJobService;
|
|
private readonly ILoginLogsRepository _loginLogsRepository;
|
|
private readonly IOrderService _orderService;
|
|
private readonly ICloudcarService _CloudcarService;
|
|
private readonly IStatisticalRepository _statisticalRepository;
|
|
private readonly IUserService _userService;
|
|
|
|
public StatisticalService(IStatisticalRepository repository,
|
|
IUserService userService,
|
|
ILoginLogsRepository loginLogsRepository,
|
|
IOrderService orderService,
|
|
IApplyJobService applyJobService,
|
|
ICloudcarService CloudcarService
|
|
) : base(repository)
|
|
{
|
|
_statisticalRepository = repository;
|
|
_userService = userService;
|
|
_loginLogsRepository = loginLogsRepository;
|
|
_orderService = orderService;
|
|
_applyJobService = applyJobService;
|
|
_CloudcarService = CloudcarService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Òì²½·ÖÒ³²éѯ
|
|
/// </summary>
|
|
/// <param name="search"></param>
|
|
/// <returns></returns>
|
|
public async Task<PageResult<StatisticalListOutputDto>> FindWithPagerSearchAsync(SearchUserModel search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (!string.IsNullOrEmpty(search.StartTime))
|
|
{
|
|
@where += " and CreatedTime >='" + search.StartTime + " 00:00:00'";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(search.EndTime))
|
|
{
|
|
@where += " and CreatedTime <='" + search.EndTime + " 23:59:59'";
|
|
}
|
|
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
System.Collections.Generic.List<StatisticalEntity> list = await _statisticalRepository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
|
System.Collections.Generic.List<StatisticalListOutputDto> listDto = list.MapTo<StatisticalListOutputDto>();
|
|
PageResult<StatisticalListOutputDto> pageResult = new PageResult<StatisticalListOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = listDto,
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Òì²½ÐÂÔöÊý¾Ý
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<CommonResult> InsertAsync()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
StatisticalEntity statistical = await GetStatisticalAsync();
|
|
int userAddTotal = await _userService.GetCountByWhereAsync("date_format(CreatedTime,'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d')");
|
|
dynamic todayIncome = await _orderService.GetSumValueByFieldAsync("PaymentMoney",
|
|
"OrderStatus >= 20 and date_format(CreatedTime,'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d')");
|
|
dynamic income = await _orderService.GetSumValueByFieldAsync("PaymentMoney", "OrderStatus >= 20");
|
|
StatisticalEntity info = new StatisticalEntity
|
|
{
|
|
Id = YitIdHelper.NextId(),
|
|
Time = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
UserAddTotal = userAddTotal,
|
|
UserSumTotal = await _userService.GetCountByWhereAsync("IsDeleted = 0"),
|
|
ApplyJobsAddTotal =
|
|
await _applyJobService.GetCountByWhereAsync("date_format(CreatedTime,'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d')"),
|
|
CloudcarAddTotal =
|
|
await _CloudcarService.GetCountByWhereAsync("date_format(CreatedTime,'%Y-%m-%d') = date_format(NOW(),'%Y-%m-%d')"),
|
|
ActiveUserTotal = await _loginLogsRepository.GetActiveUserTotal(),
|
|
TodayIncome = todayIncome.sumVaule,
|
|
Income = income.sumVaule,
|
|
ModifiedTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now
|
|
};
|
|
if (statistical == null)
|
|
{
|
|
info.UserAddTotalPercent = 0;
|
|
info.TodayIncomePercent = 0;
|
|
}
|
|
else
|
|
{
|
|
//UserAddTotalPercent = statistical.UserSumTotal!=0 ? (userAddTotal / statistical.UserSumTotal) * 100 : 0,
|
|
info.UserAddTotalPercent = StringHelper.GetPercent(userAddTotal, statistical.UserSumTotal);
|
|
//TodayIncomePercent = statistical.Income!=0 ? (todayIncome.sumVaule / statistical.Income) * 100 :0,
|
|
info.TodayIncomePercent = StringHelper.GetPercent(todayIncome.sumVaule, statistical.Income);
|
|
}
|
|
long ln = await _statisticalRepository.InsertAsync(info).ConfigureAwait(false);
|
|
result.Success = ln > 0 ? true : false;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// »ñÈ¡×îÐÂÒ»ÌõÊý¾Ý
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<StatisticalEntity> GetStatisticalAsync()
|
|
{
|
|
StatisticalEntity statistical = await _statisticalRepository.GetStatisticalAsync();
|
|
return statistical;
|
|
}
|
|
}
|
|
}
|