|
@@ -1,4 +1,6 @@
|
|
|
-using Autofac.Diagnostics;
|
|
|
+using Aspose.Cells;
|
|
|
+using Autofac.Diagnostics;
|
|
|
+using MathNet.Numerics.Statistics.Mcmc;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
using OASystem.API.OAMethodLib;
|
|
@@ -6,7 +8,10 @@ using OASystem.API.OAMethodLib.QiYeWeChatAPI;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.PersonnelModule;
|
|
|
using OASystem.Domain.Dtos.QiYeWeChat;
|
|
|
+using OASystem.Domain.Entities.Business;
|
|
|
+using OASystem.Domain.Entities.Groups;
|
|
|
using OASystem.Domain.Entities.PersonnelModule;
|
|
|
+using OASystem.Domain.ViewModels.Business;
|
|
|
using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
@@ -16,6 +21,8 @@ using StackExchange.Redis;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.Globalization;
|
|
|
+using System.IO;
|
|
|
+using System.Web;
|
|
|
|
|
|
namespace OASystem.API.Controllers
|
|
|
{
|
|
@@ -374,6 +381,79 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 导出工资单
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> ExportWageCard(string yearMonth)
|
|
|
+ {
|
|
|
+ Result result = new Result();
|
|
|
+ Stopwatch sw = new Stopwatch();
|
|
|
+ sw.Start();
|
|
|
+
|
|
|
+ //参数处理
|
|
|
+ string ymFormat = "yyyy-MM";
|
|
|
+ DateTime yearMonthDt;
|
|
|
+ bool yearMonthDtIsValid = DateTime.TryParseExact(yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
|
|
|
+
|
|
|
+ if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
|
|
|
+ //公司部门
|
|
|
+ string sql = string.Format(@"Select row_number() over(order by pm_ws.Id) as Row_Number,
|
|
|
+ sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
|
|
|
+ sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
|
|
|
+ From Pm_WageSheet pm_ws
|
|
|
+ Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
|
|
|
+ Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
|
|
|
+ Left Join Sys_Company sc On sys_u1.companyId = sc.Id
|
|
|
+ Left Join Sys_Department sd On sys_u1.DepId = sd.Id
|
|
|
+ Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'", yearMonth);
|
|
|
+ var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<ExportWageSheetItemView>(sql).ToListAsync();
|
|
|
+
|
|
|
+ if (wageSheetList.Count <= 0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, yearMonth + "暂无工资数据!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ decimal SumPrice = 0.00M;
|
|
|
+ foreach (var item in wageSheetList)
|
|
|
+ {
|
|
|
+ SumPrice += item.AfterTax;
|
|
|
+ }
|
|
|
+
|
|
|
+ WorkbookDesigner designer = new WorkbookDesigner();
|
|
|
+ //string tepUrl = string.Format("http://132.232.92.186:24/Server/File/OA2023/Office/Excel/Template/工资详细清单.xlsx");
|
|
|
+ //designer.Workbook = new Workbook(tepUrl);
|
|
|
+ designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/工资详细清单.xlsx");
|
|
|
+
|
|
|
+ designer.SetDataSource("YearMonth", yearMonth);
|
|
|
+ designer.SetDataSource("StartEndDt", wageSheetList[0].StartDate +" - "+ wageSheetList[0].EndDate);
|
|
|
+ designer.SetDataSource("WorkDays", wageSheetList[0].WorkDays);
|
|
|
+ designer.SetDataSource("SumPrice", SumPrice);
|
|
|
+
|
|
|
+ designer.Process();
|
|
|
+ string fileName = "WageCard/" + HttpUtility.UrlEncode(yearMonth + "工资单") + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
|
|
|
+ string path = AppSettingsHelper.Get("ExcelBasePath");
|
|
|
+ designer.Workbook.Save(path + fileName);
|
|
|
+ designer = null;
|
|
|
+
|
|
|
+ string excelPath = AppSettingsHelper.Get("ExcelFtpPath") + fileName;
|
|
|
+ string url = AppSettingsHelper.Get("ExcelBaseUrl");
|
|
|
+
|
|
|
+ string fileUrl = url + excelPath;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sw.Stop();
|
|
|
+ return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", new { FileUrl = fileUrl }));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
}
|