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.
138 lines
5.3 KiB
138 lines
5.3 KiB
2 years ago
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using System;
|
||
|
using System.Threading.Tasks;
|
||
|
using Znyc.Admin.AspNetCore.Controllers;
|
||
|
using Znyc.Admin.AspNetCore.Entitys;
|
||
|
using Znyc.Admin.AspNetCore.Mvc;
|
||
|
using Znyc.Admin.Commons.Entitys;
|
||
|
using Znyc.Admin.Commons.Helpers;
|
||
|
using Znyc.Admin.Commons.Pages;
|
||
|
using Znyc.Admin.Security.Dtos;
|
||
|
using Znyc.Admin.Security.Entitys;
|
||
|
using Znyc.Admin.Security.IServices;
|
||
|
|
||
|
namespace Znyc.Admin.WebApi.Controllers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 数据字典接口
|
||
|
/// </summary>
|
||
|
[ApiController]
|
||
|
[Route("api/Security/[controller]")]
|
||
|
public class StatisticalController : AreaApiController<Statistical, StatisticalOutputDto, StatisticalInputDto,
|
||
|
IStatisticalService, long>
|
||
|
{
|
||
|
private readonly IStatisticalService _statisticalService;
|
||
|
private readonly IUserService _userService;
|
||
|
private readonly ICompanyService _companyService;
|
||
|
private readonly IVehicleService _vehicleService;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 构造函数
|
||
|
/// </summary>
|
||
|
/// <param name="statisticalService"></param>
|
||
|
/// <param name="companyService"></param>
|
||
|
/// <param name="vehicleService"></param>
|
||
|
/// <param name="userService"></param>
|
||
|
public StatisticalController(IStatisticalService statisticalService,
|
||
|
ICompanyService companyService,
|
||
|
IVehicleService vehicleService,
|
||
|
IUserService userService
|
||
|
) : base(statisticalService)
|
||
|
{
|
||
|
_statisticalService = statisticalService;
|
||
|
_userService = userService;
|
||
|
_companyService = companyService;
|
||
|
_vehicleService = vehicleService;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 新增前处理数据
|
||
|
/// </summary>
|
||
|
/// <param name="info"></param>
|
||
|
protected override void OnBeforeInsert(Statistical info)
|
||
|
{
|
||
|
info.Id = 0;
|
||
|
info.CreatedTime = DateTime.Now;
|
||
|
info.CreatedUserId = CurrentUser.UserId;
|
||
|
info.IsDeleted = false;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 在更新数据前对数据的修改操作
|
||
|
/// </summary>
|
||
|
/// <param name="info"></param>
|
||
|
/// <returns></returns>
|
||
|
protected override void OnBeforeUpdate(Statistical 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();
|
||
|
var statistical = await _statisticalService.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);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|