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.
118 lines
4.9 KiB
118 lines
4.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Admin.Commons.Entitys;
|
|
using Znyc.Admin.Commons.Helpers;
|
|
using Znyc.Admin.Commons.Mapping;
|
|
using Znyc.Admin.Commons.Pages;
|
|
using Znyc.Admin.Commons.Services;
|
|
using Znyc.Admin.Security.Dtos;
|
|
using Znyc.Admin.Security.Entitys;
|
|
using Znyc.Admin.Security.IRepositories;
|
|
using Znyc.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Admin.Security.Services
|
|
{
|
|
public class StatisticalService : BaseService<Statistical, StatisticalOutputDto, long>, IStatisticalService
|
|
{
|
|
private readonly IStatisticalRepository _statisticalRepository;
|
|
private readonly IUserService _userService;
|
|
private readonly ICompanyService _companyService;
|
|
private readonly IVehicleService _vehicleService;
|
|
|
|
public StatisticalService(IStatisticalRepository repository,
|
|
IUserService userService,
|
|
ICompanyService companyService,
|
|
IVehicleService vehicleService
|
|
) : base(repository)
|
|
{
|
|
_statisticalRepository = repository;
|
|
_userService = userService;
|
|
_companyService = companyService;
|
|
_vehicleService = vehicleService;
|
|
}
|
|
|
|
/// <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
|
|
};
|
|
List<Statistical> list = await _statisticalRepository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
|
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();
|
|
var statistical = await _statisticalRepository.GetStatisticalAsync();
|
|
var userAddTotal = await _userService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())");
|
|
Statistical info = new Statistical()
|
|
{
|
|
Id = Yitter.IdGenerator.YitIdHelper.NextId(),
|
|
Time = DateTime.Now.ToString("yyyy-MM-dd"),
|
|
UserAddTotal = userAddTotal,
|
|
UserSumTotal = await _userService.GetCountByWhereAsync(" Status=1"),
|
|
CompanyAddTotal = await _companyService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())"),
|
|
CompanySumTotal = await _companyService.GetCountByWhereAsync("Status = 1"),
|
|
VehicleAddTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(CreatedTime) = dayofmonth(now())"),
|
|
VehicleSumTotal = await _vehicleService.GetCountByWhereAsync("Status = 1"),
|
|
ExpireAddTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(ExpireTime) = dayofmonth(now()) and Status=1"),
|
|
ExpireSumTotal = await _vehicleService.GetCountByWhereAsync("dayofmonth(ExpireTime) < dayofmonth(now()) and Status=1"),
|
|
ModifiedTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now
|
|
};
|
|
if (statistical == null)
|
|
{
|
|
info.UserAddTotalPercent = 0;
|
|
}
|
|
else
|
|
{
|
|
info.UserAddTotalPercent = StringHelper.GetPercent(userAddTotal, statistical.UserSumTotal);
|
|
}
|
|
long ln = await _statisticalRepository.InsertAsync(info).ConfigureAwait(false);
|
|
result.Success = ln > 0 ? true : false;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// »ñÈ¡×îÐÂÒ»ÌõÊý¾Ý
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Statistical> GetStatisticalAsync()
|
|
{
|
|
var statistical = await _statisticalRepository.GetStatisticalAsync();
|
|
return statistical;
|
|
}
|
|
}
|
|
}
|