123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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;
- using MS.WebCore.Core;
- using NPOI.SS.UserModel;
- 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
- {
- [Route("api/[controller]")]
- [ApiController]
- public class ReportController : ControllerBase
- {
-
-
-
- readonly static string ReportServerUrl= "ReportServerUrl";
- private readonly 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")]
- [HttpPost]
- public async Task<ExecuteResult> NozzleTotalizer([FromBody] ReportRequest request)
- {
- return await _PosTrxService.NozzleTotalizerShiftReportAsync(request.startTime, request.endTime, request.currentBuId);
- }
-
-
-
-
-
-
-
-
-
-
- [Route("ExportToExcel")]
- [EnableCors("AllowSpecificOrigin")]
- [HttpGet]
- public async Task<FileContentResult> ExportToExcel(string startTime,
- string endTime,
- string currentBuId)
- {
-
- List<NozzleTotalizerDto> nozzleTotalizers = await _PosTrxService.GetListFromSessionAsync(startTime, endTime, currentBuId);
-
- IWorkbook workbook = new XSSFWorkbook();
- ISheet sheet = workbook.CreateSheet("Nozzle Totalizers");
-
- IRow headerRow = sheet.CreateRow(0);
- headerRow.CreateCell(0).SetCellValue("枪号");
- headerRow.CreateCell(1).SetCellValue("油品名称");
- headerRow.CreateCell(2).SetCellValue("单价");
- headerRow.CreateCell(3).SetCellValue("起泵数");
- headerRow.CreateCell(4).SetCellValue("止泵数");
- headerRow.CreateCell(5).SetCellValue("销售升数");
- headerRow.CreateCell(6).SetCellValue("回罐");
- headerRow.CreateCell(7).SetCellValue("自用");
- headerRow.CreateCell(8).SetCellValue("流水升数");
- headerRow.CreateCell(9).SetCellValue("应收款");
- headerRow.CreateCell(10).SetCellValue("折扣");
- headerRow.CreateCell(11).SetCellValue("实收款");
-
- for (int i = 0; i < nozzleTotalizers.Count; i++)
- {
- NozzleTotalizerDto nozzleTotalizer = nozzleTotalizers[i];
- IRow dataRow = sheet.CreateRow(i + 1);
- dataRow.CreateCell(0).SetCellValue((int)nozzleTotalizer.NozzleId);
- dataRow.CreateCell(1).SetCellValue(nozzleTotalizer.GradeName);
- dataRow.CreateCell(2).SetCellValue((double)nozzleTotalizer.CurrentPrice);
- dataRow.CreateCell(3).SetCellValue((double)nozzleTotalizer.VolumeOnPumpStart);
- dataRow.CreateCell(4).SetCellValue((double)nozzleTotalizer.VolumeOnPumpEnd);
- dataRow.CreateCell(5).SetCellValue((double)nozzleTotalizer.VolumeOnPos);
- dataRow.CreateCell(6).SetCellValue((double)nozzleTotalizer.PumpTestVolume);
- dataRow.CreateCell(7).SetCellValue((double)nozzleTotalizer.SelfUseVolume);
- dataRow.CreateCell(8).SetCellValue((double)nozzleTotalizer.TotalVolume);
- dataRow.CreateCell(9).SetCellValue((double)nozzleTotalizer.TotalPaid);
- dataRow.CreateCell(10).SetCellValue((double)nozzleTotalizer.TotalDiscount);
- dataRow.CreateCell(11).SetCellValue((double)nozzleTotalizer.TotalNetAmount);
- }
-
- sheet.SetColumnWidth(0, 10 * 256);
- sheet.SetColumnWidth(1, 15 * 256);
- sheet.SetColumnWidth(2, 15 * 256);
- sheet.SetColumnWidth(3, 20 * 256);
- sheet.SetColumnWidth(4, 20 * 256);
- sheet.SetColumnWidth(5, 15 * 256);
- sheet.SetColumnWidth(6, 15 * 256);
- sheet.SetColumnWidth(7, 15 * 256);
- sheet.SetColumnWidth(8, 15 * 256);
- sheet.SetColumnWidth(9, 15 * 256);
- sheet.SetColumnWidth(10, 15 * 256);
- sheet.SetColumnWidth(11, 15 * 256);
- sheet.SetColumnWidth(12, 20 * 256);
- sheet.SetColumnWidth(13, 15 * 256);
-
- MemoryStream stream = new MemoryStream();
- workbook.Write(stream);
- byte[] bytes = stream.ToArray();
-
- return new FileContentResult(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- }
-
-
-
-
-
-
- [Route("BusinessScopeReportTimeJob")]
- [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}" };
- }
- }
- }
|