Эх сурвалжийг харах

Merge branch 'master' of http://dev.hsfuel.com:3000/wei.chen/SmartFuelTool

DOVER-GLOBAL\11047086 1 жил өмнө
parent
commit
d0043743f6

+ 3 - 2
.gitignore

@@ -107,7 +107,8 @@ Generated_Code #added for RIA/Silverlight projects
 _UpgradeReport_Files/
 Backup*/
 UpgradeLog*.XML
-
 .vs/
+.vs/*
 *.suo
-*.user
+*.user
+

+ 15 - 0
src/MS.Services/Account/AccountService.cs

@@ -1092,6 +1092,21 @@ SELECT subquery.belong_to,subquery.accountId, count(*) count from (SELECT trx.ac
             return v;
         }
 
+
+        /// <summary>
+        /// 获取buid 
+        /// </summary>
+        /// <returns></returns>
+        /// <exception cref="NotImplementedException"></exception>
+        public async Task<IEnumerable<string>> GetBuids()
+        {
+            var businessUnitInfos =await _AuthContext.GetRepository<BusinessUnitInfo>().GetAll()
+                .Where(p => !p.BuName.Contains("集团")).Where(o => !o.BuName.Contains("公司")).ToListAsync();
+            if (businessUnitInfos!=null&&businessUnitInfos.Any()) {
+                return businessUnitInfos.Select(p => p.Id.ToString()).ToList();
+            }
+            return null;
+        }
     }
     public class CardCollect
     {

+ 9 - 1
src/MS.Services/Account/IAccountService.cs

@@ -1,6 +1,7 @@
 using MS.Component.Jwt.UserClaim;
 using MS.Models.ViewModel;
 using MS.WebCore.Core;
+using System.Collections.Generic;
 using System.Threading.Tasks;
 
 namespace MS.Services
@@ -10,6 +11,13 @@ namespace MS.Services
         Task<ExecuteResult<UserData>> Login(LoginViewModel viewModel);
         Task<ExecuteResult<UserData>> syncFromVersion(long versionNo,bool excludingCurrentBu, string specificHeader);
 
-         Task AddEmployeeCardMonthlySummaryToRedisAsync(string buid, string date);
+        Task AddEmployeeCardMonthlySummaryToRedisAsync(string buid, string date);
+
+
+        /// <summary>
+        /// 获取全部buid 
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<string>> GetBuids();
     }
 }

+ 78 - 3
src/MS.WebApi/Controllers/ReportController.cs

@@ -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}" };
+        }
     }
-   
+
 }