|
@@ -1,6 +1,9 @@
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using MS.Component.Aop;
|
|
|
using MS.Models;
|
|
|
using MS.Services;
|
|
|
using MS.Services.PosTrxService;
|
|
@@ -10,6 +13,7 @@ using NPOI.XSSF.UserModel;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using System.Net.Http;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace MS.WebApi.Controllers
|
|
@@ -18,10 +22,20 @@ namespace MS.WebApi.Controllers
|
|
|
[ApiController]
|
|
|
public class ReportController : ControllerBase
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 报表的地址
|
|
|
+ /// </summary>
|
|
|
+ readonly static string ReportServerUrl= "ReportServerUrl";
|
|
|
private readonly IPosTrxService _PosTrxService;
|
|
|
- public ReportController(IPosTrxService posTrxService)
|
|
|
+ private readonly IAccountService _AccountService;
|
|
|
+ private readonly ILogger<ReportController> _logger;
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ public ReportController(IPosTrxService posTrxService, IAccountService accountService, ILogger<ReportController> logger, IConfiguration Configuration)
|
|
|
{
|
|
|
_PosTrxService = posTrxService;
|
|
|
+ _AccountService = accountService;
|
|
|
+ _logger = logger;
|
|
|
+ _configuration = Configuration;
|
|
|
}
|
|
|
[Route("NozzleTotalizer")]
|
|
|
[EnableCors("AllowSpecificOrigin")]
|
|
@@ -50,7 +64,7 @@ namespace MS.WebApi.Controllers
|
|
|
{
|
|
|
// 获取数据源
|
|
|
List<NozzleTotalizerDto> nozzleTotalizers = await _PosTrxService.GetListFromSessionAsync(startTime, endTime, currentBuId); // 异步获取NozzleTotalizers数据
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 创建Excel文档
|
|
|
IWorkbook workbook = new XSSFWorkbook();
|
|
@@ -114,6 +128,67 @@ namespace MS.WebApi.Controllers
|
|
|
// 返回Excel文件
|
|
|
return new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 执行统计报表,日,周,月
|
|
|
+ /// 9999默认初始化全部数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="type"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Route("ExportToExcel")]
|
|
|
+ [EnableCors("AllowSpecificOrigin")]
|
|
|
+ [HttpGet]
|
|
|
+ public async Task<object> BusinessScopeReportTimeJob(int type = 1,string time="",int pagesize=13)
|
|
|
+ {
|
|
|
+ _logger.LogInformation($"{type}--BusinessScopeReportTimeJob start {DateTime.Now}");
|
|
|
+ var buids =await _AccountService.GetBuids();
|
|
|
+ _logger.LogInformation($"buids 个数 {buids} time:{DateTime.Now}");
|
|
|
+ var bassAddress = _configuration.GetSection(ReportServerUrl).Value;
|
|
|
+ HttpClient httpClient = new HttpClient();
|
|
|
+ httpClient.BaseAddress=new Uri(bassAddress);
|
|
|
+ foreach (var buid in buids)
|
|
|
+ {
|
|
|
+ //日执行
|
|
|
+ if (type == 1 || type == 9999)
|
|
|
+ {
|
|
|
+
|
|
|
+ var url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=5&reportType=day&startTime={DateTime.Now.AddDays(-5)}&key=TK2024Cache&buid={buid}";
|
|
|
+ if (type == 9999)
|
|
|
+ {
|
|
|
+ url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=80&reportType=day&startTime={DateTime.Now.AddMonths(-3)}&key=TK2024Cache&buid={buid}";
|
|
|
+ }
|
|
|
+ var result=await httpClient.GetAsync(url);
|
|
|
+ _logger.LogInformation($"{buid}日报表 统计执行完成 {result.StatusCode}-{result.Content.ToString()} time:{DateTime.Now}");
|
|
|
+ }
|
|
|
+ //周执行
|
|
|
+ if (type == 2 || type == 9999)
|
|
|
+ {
|
|
|
+ var url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=2&reportType=week&startTime={DateTime.Now.AddDays(-20)}&key=TK2024Cache&buid={buid}";
|
|
|
+ if (type == 9999)
|
|
|
+ {
|
|
|
+ url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=20&reportType=week&startTime={DateTime.Now.AddMonths(-6)}&key=TK2024Cache&buid={buid}";
|
|
|
+ }
|
|
|
+ var result = await httpClient.GetAsync(url);
|
|
|
+ _logger.LogInformation($"{buid}周报表 统计执行完成 {result.StatusCode}-{result.Content.ToString()} time:{DateTime.Now}");
|
|
|
+
|
|
|
+ }
|
|
|
+ //月执行
|
|
|
+ if (type == 3 || type == 9999)
|
|
|
+ {
|
|
|
+ var url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=2&reportType=month&startTime={DateTime.Now.AddMonths(-2)}&key=TK2024Cache&buid={buid}";
|
|
|
+ if (type == 9999)
|
|
|
+ {
|
|
|
+ url = $"/api/Report/BusinessScopeReportTimeJob?pageNumber=0&pageCount=6&reportType=month&startTime={DateTime.Now.AddMonths(-6)}&key=TK2024Cache&buid={buid}";
|
|
|
+ }
|
|
|
+ var result = await httpClient.GetAsync(url);
|
|
|
+ _logger.LogInformation($"{buid}月报表 统计执行完成 {result.StatusCode}-{result.Content.ToString()} time:{DateTime.Now}");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _logger.LogInformation($"{type}--BusinessScopeReportTimeJob end {DateTime.Now}");
|
|
|
+ return new { message=$"执行完成{DateTime.Now}" };
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|