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.
 
 

157 lines
6.4 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Yitter.IdGenerator;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Helpers;
using Znyc.Cloudcar.Admin.Commons.Pages;
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.WebApi.Controllers
{
/// <summary>
/// 数据字典接口
/// </summary>
[ApiController]
[Route("api/Security/[controller]")]
public class StatisticalController : AreaApiController<StatisticalEntity, StatisticalOutputDto, StatisticalInputDto,
IStatisticalService, long>
{
private readonly IApplyJobService _applyJobService;
private readonly ILoginLogsRepository _loginLogsRepository;
private readonly IOrderService _orderService;
private readonly ICloudcarService _CloudcarService;
private readonly IStatisticalService _statisticalService;
private readonly IUserService _userService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="statisticalService"></param>
/// <param name="userService"></param>
/// <param name="CloudcarService"></param>
/// <param name="applyJobService"></param>
/// <param name="loginLogsRepository"></param>
/// <param name="orderDetailService"></param>
/// </summary>
public StatisticalController(IStatisticalService statisticalService,
IUserService userService,
ICloudcarService CloudcarService,
IApplyJobService applyJobService,
ILoginLogsRepository loginLogsRepository,
IOrderService orderService
) : base(statisticalService)
{
_statisticalService = statisticalService;
_applyJobService = applyJobService;
_userService = userService;
_CloudcarService = CloudcarService;
_loginLogsRepository = loginLogsRepository;
_orderService = orderService;
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(StatisticalEntity info)
{
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(StatisticalEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 异步新增数据
/// </summary>
/// <returns></returns>
[HttpPost("InsertAsync")]
[FunctionAuthorize("Add")]
public async Task<IActionResult> InsertAsync()
{
CommonResult result = new CommonResult();
StatisticalEntity statistical = await _statisticalService.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);
}
OnBeforeInsert(info);
long ln = await _service.InsertAsync(info).ConfigureAwait(false);
if (ln > 0)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43001;
result.ErrCode = "43001";
}
return ToJsonContent(result);
}
/// <summary>
/// 异步分页查询
/// </summary>
/// <param name="search"></param>
/// <returns></returns>
[HttpPost("FindWithPagerSearchAsync")]
[FunctionAuthorize("List")]
public async Task<IActionResult> FindWithPagerSearchAsync(SearchUserModel search)
{
CommonResult<PageResult<StatisticalOutputDto>> result = new CommonResult<PageResult<StatisticalOutputDto>>
{
ResData = await _statisticalService.FindWithPagerSearchAsync(search),
ErrCode = ErrCode.successCode
};
return ToJsonContent(result);
}
}
}