|
@@ -6,8 +6,10 @@ using OASystem.Domain.Entities.PersonnelModule;
|
|
|
using OASystem.Domain.ViewModels.PersonnelModule;
|
|
|
using OASystem.Domain.ViewModels.QiYeWeChat;
|
|
|
using OASystem.Infrastructure.Repositories.PersonnelModule;
|
|
|
+using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
using System.Globalization;
|
|
|
+using System.IO;
|
|
|
|
|
|
namespace OASystem.API.Controllers
|
|
|
{
|
|
@@ -624,6 +626,158 @@ namespace OASystem.API.Controllers
|
|
|
return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", new { FileUrl = fileUrl }));
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 上传个税
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> UploadTax(IFormFile file,string yearMonth)
|
|
|
+ {
|
|
|
+
|
|
|
+ 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 "));
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var TypeName = Request.Headers["TypeName"].ToString();
|
|
|
+ if (file != null)
|
|
|
+ {
|
|
|
+ var fileDir = AppSettingsHelper.Get("WageSheetExcelFptPath");
|
|
|
+ //文件名称
|
|
|
+ string projectFileName = file.FileName;
|
|
|
+
|
|
|
+ //上传的文件的路径
|
|
|
+ string filePath = "";
|
|
|
+
|
|
|
+
|
|
|
+ if (!Directory.Exists(fileDir))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(fileDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传的文件的路径
|
|
|
+ filePath = fileDir + $@"\{projectFileName}";
|
|
|
+
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
+ {
|
|
|
+ //删除文件
|
|
|
+ System.IO.File.Delete(filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ using (FileStream fs = System.IO.File.Create(filePath))
|
|
|
+ {
|
|
|
+ file.CopyTo(fs);
|
|
|
+ fs.Flush();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
+ {
|
|
|
+ Workbook book = new Workbook(filePath);
|
|
|
+ DataSet dataSet = new DataSet();
|
|
|
+ if (book.Worksheets.Count > 0)
|
|
|
+ {
|
|
|
+ var sheet = book.Worksheets[0];
|
|
|
+
|
|
|
+ if (sheet != null)
|
|
|
+ {
|
|
|
+ // sheets 中的数据必须存在
|
|
|
+ if (sheet.Cells.MaxDataRow != -1 && sheet.Cells.MaxDataColumn != -1)
|
|
|
+ {
|
|
|
+ // 方法 ExportDataTable 的参数说明
|
|
|
+ // 要导出的第一个单元格的行号。
|
|
|
+ // 要导出的第一个单元格的列号。
|
|
|
+ // 要导入的行数。
|
|
|
+ // 要导入的列数。
|
|
|
+ // 指示第一行的数据是否导出到DataTable的列名。
|
|
|
+ DataTable dataTable = sheet.Cells.ExportDataTable(0, 0, sheet.Cells.MaxDataRow + 1, sheet.Cells.MaxDataColumn + 1, true);
|
|
|
+ dataSet.Tables.Add(dataTable);
|
|
|
+
|
|
|
+ DataTable taxData = dataSet.Tables[0];
|
|
|
+
|
|
|
+ //公司部门
|
|
|
+ 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}'
|
|
|
+ Order By UserId Asc ", yearMonth);
|
|
|
+ var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetItemInfoView>(sql).ToListAsync();
|
|
|
+
|
|
|
+ if (wageSheetList.Count <= 0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, yearMonth + "工资数据不存在,请先添加工资数据!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < taxData.Rows.Count; i++)
|
|
|
+ {
|
|
|
+ string name = taxData.Rows[i][0].ToString().Trim();
|
|
|
+
|
|
|
+ List<WageSheetItemInfoView> wageSheets = new List<WageSheetItemInfoView>();
|
|
|
+ wageSheets = wageSheetList.Where(it => it.Name.Equals(name)).ToList();
|
|
|
+ if (wageSheets.Count > 0)
|
|
|
+ {
|
|
|
+ wageSheetList.Where(it => it.Name.Equals(name))
|
|
|
+ .Select(it =>
|
|
|
+ {
|
|
|
+ it.WithholdingTax = Convert.ToDecimal(taxData.Rows[i][1].ToString());
|
|
|
+ return it;
|
|
|
+ })
|
|
|
+ .ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ List<Pm_WageSheet> wageSheets1 = new List<Pm_WageSheet>();
|
|
|
+ wageSheets1 = _mapper.Map<List<Pm_WageSheet>>(wageSheetList);
|
|
|
+ var updateStatus = _wageSheetRep._sqlSugar
|
|
|
+ .Updateable(wageSheets1)
|
|
|
+ .UpdateColumns(it => it.WithholdingTax)
|
|
|
+ .ExecuteCommand();
|
|
|
+
|
|
|
+ if (updateStatus<0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "操作失败!"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
+ {
|
|
|
+ //删除文件
|
|
|
+ System.IO.File.Delete(filePath);
|
|
|
+ }
|
|
|
+ return Ok(JsonView(true, "操作成功!"));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "工作薄没有数据!"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(JsonView(true, "上传成功!", projectFileName));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "上传失败!"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "程序错误!"));
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ return Ok(JsonView(true, "操作成功!"));
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
}
|