Commit 71fafeda by lcx

上传人员绩效Id

parent 48546689
using System; using FluentValidation.AspNetCore;
using System.Collections.Generic; using Microsoft.AspNetCore.Hosting;
using System.Linq; using Microsoft.AspNetCore.Http;
using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Internal;
using AutoMapper;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services; using Performance.Services;
using System;
using System.IO;
using System.Linq;
namespace Performance.Api.Controllers namespace Performance.Api.Controllers
{ {
...@@ -15,11 +17,16 @@ namespace Performance.Api.Controllers ...@@ -15,11 +17,16 @@ namespace Performance.Api.Controllers
public class EmployeeController : Controller public class EmployeeController : Controller
{ {
private EmployeeService employeeService; private EmployeeService employeeService;
private AllotService allotService;
private ClaimService claim; private ClaimService claim;
public EmployeeController(EmployeeService employeeService, ClaimService claim) private IHostingEnvironment evn;
public EmployeeController(EmployeeService employeeService, AllotService allotService,
ClaimService claim, IHostingEnvironment evn)
{ {
this.employeeService = employeeService; this.employeeService = employeeService;
this.allotService = allotService;
this.claim = claim; this.claim = claim;
this.evn = evn;
} }
/// <summary> /// <summary>
...@@ -231,5 +238,44 @@ public ApiResponse DeleteApr([FromBody] per_apr_amount request) ...@@ -231,5 +238,44 @@ public ApiResponse DeleteApr([FromBody] per_apr_amount request)
return new ApiResponse(ResponseType.Fail); return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
} }
/// <summary>
/// 上传人员绩效文件
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
[Route("apr/import")]
[HttpPost]
public ApiResponse Import([FromForm] IFormCollection form)
{
var allotid = form.ToDictionary().GetValue("allotid", 0);
if (allotid <= 0)
return new ApiResponse(ResponseType.Fail, "参数错误", "allotid无效");
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
var allot = allotService.GetAllot(allotid);
if (allot == null)
return new ApiResponse(ResponseType.Fail, "allotid不存在");
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(evn.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
using (var stream = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
}
employeeService.ImpoerAprEmployees(allotid, path, claim.GetUserId());
return new ApiResponse(ResponseType.OK);
}
} }
} }
\ No newline at end of file
...@@ -599,6 +599,13 @@ ...@@ -599,6 +599,13 @@
<param name="request"></param> <param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.EmployeeController.Import(Microsoft.AspNetCore.Http.IFormCollection)">
<summary>
上传人员绩效文件
</summary>
<param name="form"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ExConfigController.Extract(Performance.DtoModels.ModModuleRequest)"> <member name="M:Performance.Api.Controllers.ExConfigController.Extract(Performance.DtoModels.ModModuleRequest)">
<summary> <summary>
绩效数据抽取模板 绩效数据抽取模板
......
using AutoMapper; using AutoMapper;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel;
using NPOI.SS.Util; using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
...@@ -23,6 +25,7 @@ public class EmployeeService : IAutoInjection ...@@ -23,6 +25,7 @@ public class EmployeeService : IAutoInjection
private PerforUserhospitalRepository perforUserhospitalRepository; private PerforUserhospitalRepository perforUserhospitalRepository;
private PerforPerallotRepository perallotRepository; private PerforPerallotRepository perallotRepository;
private PerforPerapramountRepository perapramountRepository; private PerforPerapramountRepository perapramountRepository;
private ILogger<EmployeeService> logger;
public EmployeeService(PerforImemployeeRepository perforImemployeeRepository, public EmployeeService(PerforImemployeeRepository perforImemployeeRepository,
PerforPersheetRepository perforPersheetRepository, PerforPersheetRepository perforPersheetRepository,
...@@ -30,7 +33,8 @@ public class EmployeeService : IAutoInjection ...@@ -30,7 +33,8 @@ public class EmployeeService : IAutoInjection
PerforImemployeeclinicRepository perforImemployeeclinicRepository, PerforImemployeeclinicRepository perforImemployeeclinicRepository,
PerforUserhospitalRepository perforUserhospitalRepository, PerforUserhospitalRepository perforUserhospitalRepository,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
PerforPerapramountRepository perapramountRepository) PerforPerapramountRepository perapramountRepository,
ILogger<EmployeeService> logger)
{ {
this.perforImemployeeRepository = perforImemployeeRepository; this.perforImemployeeRepository = perforImemployeeRepository;
this.perforPersheetRepository = perforPersheetRepository; this.perforPersheetRepository = perforPersheetRepository;
...@@ -39,6 +43,7 @@ public class EmployeeService : IAutoInjection ...@@ -39,6 +43,7 @@ public class EmployeeService : IAutoInjection
this.perforUserhospitalRepository = perforUserhospitalRepository; this.perforUserhospitalRepository = perforUserhospitalRepository;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
this.perapramountRepository = perapramountRepository; this.perapramountRepository = perapramountRepository;
this.logger = logger;
} }
#region 行政人员 #region 行政人员
...@@ -316,5 +321,75 @@ public bool DeleteApr(int id) ...@@ -316,5 +321,75 @@ public bool DeleteApr(int id)
return true; return true;
} }
public void ImpoerAprEmployees(int allotid, string path, int userid)
{
var data = perapramountRepository.GetEntities(t => t.AllotId == allotid);
if (data != null && data.Any())
perapramountRepository.RemoveRange(data.ToArray());
try
{
IWorkbook workbook = new XSSFWorkbook(path);
if (workbook == null) return;
var sheet = workbook.GetSheetAt(0);
var firstRow = sheet.GetRow(0);
List<(string, int)> excelheader = new List<(string, int)>();
for (int cellindex = 0; cellindex < firstRow.LastCellNum + 1; cellindex++)
{
var cell = firstRow.GetCell(cellindex);
if (cell == null) continue;
if (!string.IsNullOrEmpty(cell.ToString()))
excelheader.Add((cell.ToString(), cellindex));
}
if (excelheader == null || !excelheader.Any())
throw new PerformanceException("上传excel内容错误");
Dictionary<string, int> dict = new Dictionary<string, int>
{
{ "人员工号", -1 }, { "姓名", -1 }, { "绩效类型", -1 }, { "金额", -1 },
};
List<string> errorHeaders = new List<string>();
foreach (var key in dict.Keys.ToList())
{
if (!excelheader.Select(t => t.Item1).Contains(key)) errorHeaders.Add(key);
else dict[key] = excelheader.First(t => t.Item1 == key).Item2;
}
if (errorHeaders != null && errorHeaders.Any())
throw new PerformanceException($"excel缺少列{string.Join(", ", errorHeaders)}");
var entities = new List<per_apr_amount>();
var createtime = DateTime.Now;
for (int rowindex = 1; rowindex < sheet.LastRowNum + 1; rowindex++)
{
var row = sheet.GetRow(rowindex);
if (row == null) continue;
var entity = new per_apr_amount
{
PersonnelNumber = row.GetCell(dict["人员工号"])?.ToString(),
DoctorName = row.GetCell(dict["姓名"])?.ToString(),
PerforType = row.GetCell(dict["绩效类型"])?.ToString(),
Amount = (decimal)(row.GetCell(dict["金额"])?.NumericCellValue ?? 0),
AllotId = allotid,
CreateDate = createtime,
CreateUser = userid,
};
entities.Add(entity);
}
perapramountRepository.AddRange(entities.ToArray());
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment