上传导入医院其他绩效功能重新优化

parent a1fc57ce
...@@ -478,9 +478,7 @@ public ApiResponse Import([FromForm] IFormCollection form) ...@@ -478,9 +478,7 @@ public ApiResponse Import([FromForm] IFormCollection form)
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败"); return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
} }
var result = employeeService.ImportAprEmployees(allotid, path, claim.GetUserId()); var result = employeeService.ImportAprEmployees(allotid, path, claim.GetUserId());
return result != null && result.Count > 0 return result;
? new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", result)
: new ApiResponse(ResponseType.OK);
} }
/// <summary> /// <summary>
...@@ -849,10 +847,8 @@ public ApiResponse ImportAprHide([FromForm] IFormCollection form) ...@@ -849,10 +847,8 @@ public ApiResponse ImportAprHide([FromForm] IFormCollection form)
if (!FileHelper.CreateFile(path, bytes)) if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败"); return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
} }
var result = employeeService.ImportAprHideEmployees(allotid, path, claim.GetUserId()); var res = employeeService.ImportAprHideEmployees(allotid, path, claim.GetUserId());
return result != null && result.Count > 0 return res;
? new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", result)
: new ApiResponse(ResponseType.OK);
} }
/// <summary> /// <summary>
......
...@@ -74,6 +74,31 @@ ...@@ -74,6 +74,31 @@
Post请求地址 Post请求地址
</summary> </summary>
</member> </member>
<member name="P:Performance.DtoModels.AprAmount.PersonnelNumber">
<summary>
人员工号
</summary>
</member>
<member name="P:Performance.DtoModels.AprAmount.DoctorName">
<summary>
医生姓名
</summary>
</member>
<member name="P:Performance.DtoModels.AprAmount.PerforType">
<summary>
</summary>
</member>
<member name="P:Performance.DtoModels.AprAmount.Amount">
<summary>
金额
</summary>
</member>
<member name="P:Performance.DtoModels.AprAmount.Remark">
<summary>
备注
</summary>
</member>
<member name="M:Performance.DtoModels.CustomValidator.IsMobile(System.String)"> <member name="M:Performance.DtoModels.CustomValidator.IsMobile(System.String)">
<summary> <summary>
判断输入的字符串是否是一个合法的手机号 判断输入的字符串是否是一个合法的手机号
......
...@@ -671,12 +671,10 @@ public ApiResponse ConfirmAudit(int userid, AprAmountAuditRequest request) ...@@ -671,12 +671,10 @@ public ApiResponse ConfirmAudit(int userid, AprAmountAuditRequest request)
/// <returns></returns> /// <returns></returns>
public ApiResponse AprMark(int userid, AprAmountMarkRequest request) public ApiResponse AprMark(int userid, AprAmountMarkRequest request)
{ {
List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
if (request?.TypeInDepartments == null || !request.TypeInDepartments.Any()) if (request?.TypeInDepartments == null || !request.TypeInDepartments.Any())
throw new PerformanceException("审计信息无效,请确认"); throw new PerformanceException("审计信息无效,请确认");
var allApramounts = perapramountRepository.GetEntities(t => t.AllotId == request.AllotId);
foreach (var department in request.TypeInDepartments) foreach (var department in request.TypeInDepartments)
{ {
string update = "update per_apr_amount set MarkStatus=@MarkStatus,MarkUser=@MarkUser,MarkTime=@MarkTime where TypeInDepartment=@TypeInDepartment and AllotId=@AllotId; "; string update = "update per_apr_amount set MarkStatus=@MarkStatus,MarkUser=@MarkUser,MarkTime=@MarkTime where TypeInDepartment=@TypeInDepartment and AllotId=@AllotId; ";
...@@ -690,14 +688,42 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request) ...@@ -690,14 +688,42 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request)
/// <param name="allotid"></param> /// <param name="allotid"></param>
/// <param name="path"></param> /// <param name="path"></param>
/// <param name="userid"></param> /// <param name="userid"></param>
public List<Dictionary<string, string>> ImportAprEmployees(int allotid, string path, int userid) public ApiResponse ImportAprEmployees(int allotid, string path, int userid)
{ {
var userrole = userroleRepository.GetEntity(t => t.UserID == userid); var userrole = userroleRepository.GetEntity(t => t.UserID == userid);
if (userrole == null) throw new PerformanceException("用户未绑定角色"); if (userrole == null) throw new PerformanceException("用户未绑定角色");
List<Dictionary<string, string>> errors = new List<Dictionary<string, string>>(); List<per_apr_amount> entities = new List<per_apr_amount>();
var typeIn = GetTypeInDepartment(userid); var typeIn = GetTypeInDepartment(userid);
var createtime = DateTime.Now;
var res = OpenAndReadAprAmountExcel(allotid, path, entities);
if (res.State == ResponseType.OK)
{
if (!entities.Any()) throw new PerformanceException("未能找到有效数据,请检查后重试!");
foreach (var entity in entities)
{
entity.Status = 1;
entity.TypeInDepartment = typeIn;
entity.AllotId = allotid;
entity.CreateDate = createtime;
entity.CreateUser = userid;
}
perapramountRepository.AddRange(entities.ToArray());
}
return res;
}
/// <summary>
/// 上传导入医院其他绩效
/// </summary>
/// <param name="allotid"></param>
/// <param name="path"></param>
/// <param name="userid"></param>
private ApiResponse OpenAndReadAprAmountExcel(int allotid, string path, List<per_apr_amount> entities)
{
entities ??= new List<per_apr_amount>();
try try
{ {
IWorkbook workbook = null; IWorkbook workbook = null;
...@@ -707,7 +733,7 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request) ...@@ -707,7 +733,7 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request)
{ {
workbook = version == ExcelVersion.xlsx ? new XSSFWorkbook(fs) : new HSSFWorkbook(fs); workbook = version == ExcelVersion.xlsx ? new XSSFWorkbook(fs) : new HSSFWorkbook(fs);
} }
if (workbook == null) return errors; if (workbook == null) throw new PerformanceException("Excel读取失败,请稍后重试");
var sheet = workbook.GetSheetAt(0); var sheet = workbook.GetSheetAt(0);
var firstRow = sheet.GetRow(0); var firstRow = sheet.GetRow(0);
...@@ -727,16 +753,19 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request) ...@@ -727,16 +753,19 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request)
{ "人员工号", -1 }, { "姓名", -1 }, { "绩效类型", -1 }, { "金额", -1 }, { "备注", -1 }, { "人员工号", -1 }, { "姓名", -1 }, { "绩效类型", -1 }, { "金额", -1 }, { "备注", -1 },
}; };
foreach (var key in dict.Keys.ToList()) foreach (var key in dict.Keys.Where(key => excelheader.Any(w => w.Value == key)))
{ {
if (excelheader.Any(w => w.Value == key))
dict[key] = excelheader.First(w => w.Value == key).Key; dict[key] = excelheader.First(w => w.Value == key).Key;
} }
var entities = new List<per_apr_amount>(); List<Dictionary<string, string>> errors = new List<Dictionary<string, string>>();
var createtime = DateTime.Now; foreach (var key in dict.Where(w => w.Value < 0).Select(w => w.Key))
var employees = peremployeeRepository.GetEntities(t => t.AllotId == allotid); {
errors.Add(new Dictionary<string, string> { { "列名", key }, { "来源", "上传文件" }, { "错误原因", $"“{key}”列不存在" } });
}
if (errors.Count > 0) return new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", errors);
var employees = peremployeeRepository.GetEntities(t => t.AllotId == allotid) ?? new List<per_employee>();
for (int rowindex = 1; rowindex < sheet.LastRowNum + 1; rowindex++) for (int rowindex = 1; rowindex < sheet.LastRowNum + 1; rowindex++)
{ {
var row = sheet.GetRow(rowindex); var row = sheet.GetRow(rowindex);
...@@ -744,67 +773,72 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request) ...@@ -744,67 +773,72 @@ public ApiResponse AprMark(int userid, AprAmountMarkRequest request)
var entity = new per_apr_amount var entity = new per_apr_amount
{ {
Status = 1,
PersonnelNumber = dict["人员工号"] < 0 ? "" : row.GetCell(dict["人员工号"]).GetValue(), PersonnelNumber = dict["人员工号"] < 0 ? "" : row.GetCell(dict["人员工号"]).GetValue(),
DoctorName = dict["姓名"] < 0 ? "" : row.GetCell(dict["姓名"]).GetValue(), DoctorName = dict["姓名"] < 0 ? "" : row.GetCell(dict["姓名"]).GetValue(),
PerforType = dict["绩效类型"] < 0 ? "" : row.GetCell(dict["绩效类型"]).GetValue(), PerforType = dict["绩效类型"] < 0 ? "" : row.GetCell(dict["绩效类型"]).GetValue(),
Amount = dict["金额"] < 0 ? 0 : ConvertHelper.To<decimal>(row.GetCell(dict["金额"]).GetValue(), 0), Amount = dict["金额"] < 0 ? 0 : ConvertHelper.To<decimal>(row.GetCell(dict["金额"]).GetValue(), 0),
Remark = dict["备注"] < 0 ? "" : row.GetCell(dict["备注"]).GetValue(), Remark = dict["备注"] < 0 ? "" : row.GetCell(dict["备注"]).GetValue(),
TypeInDepartment = typeIn,
AllotId = allotid,
CreateDate = createtime,
CreateUser = userid,
}; };
if (string.IsNullOrEmpty(entity.DoctorName) && string.IsNullOrEmpty(entity.PersonnelNumber) && string.IsNullOrEmpty(entity.PerforType) && entity.Amount == 0)
if (string.IsNullOrEmpty(entity.DoctorName) && string.IsNullOrEmpty(entity.PersonnelNumber) && string.IsNullOrEmpty(entity.PerforType) && entity.Amount == 0 && string.IsNullOrEmpty(entity.Remark))
continue; continue;
if (string.IsNullOrEmpty(entity.DoctorName) || string.IsNullOrEmpty(entity.PersonnelNumber)) if (string.IsNullOrEmpty(entity.DoctorName) || string.IsNullOrEmpty(entity.PersonnelNumber))
{
errors.Add(new Dictionary<string, string>
{
{ "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName },
{ "来源", "上传文件" },
{ "错误原因", "“人员工号/姓名”信息缺失,请补全或删除" },
});
}
if (entity.Amount == 0)
{
errors.Add(new Dictionary<string, string> errors.Add(new Dictionary<string, string>
{ {
{ "行号", $"第{rowindex}行" }, { "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber }, { "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName }, { "姓名", entity.DoctorName },
{ "来源", "上传文件" }, { "来源", "上传文件" },
{ "错误原因", "“关键信息缺失”请补全或删除" }, { "错误原因", "“金额”不能为“0”,请补全或删除" },
}); });
}
var employee = employees.FirstOrDefault(w => w.PersonnelNumber == entity.PersonnelNumber); var employee = employees.FirstOrDefault(w => w.PersonnelNumber == entity.PersonnelNumber);
if (employee == null) if (employee == null)
{
errors.Add(new Dictionary<string, string> errors.Add(new Dictionary<string, string>
{ {
{ "行号", $"第{rowindex}行" }, { "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber }, { "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName }, { "姓名", entity.DoctorName },
{ "来源", "上传文件" }, { "来源", "上传文件" },
{ "错误原因","“人员工号”错误,请修改或删除" }, { "错误原因","“人员工号”在人员字典中不存在,请修改或删除" },
}); });
}
else if (employee.DoctorName != entity.DoctorName) else if (employee.DoctorName != entity.DoctorName)
{
errors.Add(new Dictionary<string, string> errors.Add(new Dictionary<string, string>
{ {
{ "行号", $"第{rowindex}行" }, { "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber }, { "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName }, { "姓名", entity.DoctorName },
{ "来源", "上传文件" }, { "来源", "上传文件" },
{ "错误原因", "“姓名”错误,请修改或删除" }, { "错误原因", "“姓名”与人员字典不一致,请修改或删除" },
}); });
entities.Add(entity);
} }
// 补充核算单元 entities.Add(entity);
if (errors.Count == 0 && entities.Any())
perapramountRepository.AddRange(entities.ToArray());
} }
catch (PerformanceException ex) if (errors.Count > 0) return new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", errors);
{
throw ex;
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex.ToString()); logger.LogError(ex.ToString());
} }
return errors; return new ApiResponse(ResponseType.OK);
} }
/// <summary> /// <summary>
...@@ -1233,118 +1267,42 @@ public ApiResponse AprMarkHide(int userid, AprAmountMarkRequest request) ...@@ -1233,118 +1267,42 @@ public ApiResponse AprMarkHide(int userid, AprAmountMarkRequest request)
/// <param name="allotid"></param> /// <param name="allotid"></param>
/// <param name="path"></param> /// <param name="path"></param>
/// <param name="userid"></param> /// <param name="userid"></param>
public List<Dictionary<string, string>> ImportAprHideEmployees(int allotid, string path, int userid) public ApiResponse ImportAprHideEmployees(int allotid, string path, int userid)
{ {
var userrole = userroleRepository.GetEntity(t => t.UserID == userid); var userrole = userroleRepository.GetEntity(t => t.UserID == userid);
if (userrole == null) throw new PerformanceException("用户未绑定角色"); if (userrole == null) throw new PerformanceException("用户未绑定角色");
List<Dictionary<string, string>> errors = new List<Dictionary<string, string>>(); List<per_apr_amount> entities = new List<per_apr_amount>();
var typeIn = GetTypeInDepartment(userid); var typeIn = GetTypeInDepartment(userid);
try var createtime = DateTime.Now;
{
IWorkbook workbook = null;
var version = FileHelper.GetExtension(path) == ".xlsx" ? ExcelVersion.xlsx : ExcelVersion.xls; var res = OpenAndReadAprAmountExcel(allotid, path, entities);
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) if (res.State == ResponseType.OK)
{ {
workbook = version == ExcelVersion.xlsx ? new XSSFWorkbook(fs) : new HSSFWorkbook(fs); if (!entities.Any()) throw new PerformanceException("未能找到有效数据,请检查后重试!");
}
if (workbook == null) return errors;
var sheet = workbook.GetSheetAt(0);
var firstRow = sheet.GetRow(0); List<per_apr_amount_hide> newEntities = new List<per_apr_amount_hide>();
Dictionary<int, string> excelheader = new Dictionary<int, string>();
for (int cellindex = 0; cellindex < firstRow.LastCellNum + 1; cellindex++)
{
var value = firstRow.GetCell(cellindex).GetValue();
if (!string.IsNullOrEmpty(value) && !excelheader.ContainsKey(cellindex))
excelheader.Add(cellindex, value);
}
if (excelheader == null || excelheader.Count == 0)
throw new PerformanceException("上传excel内容错误");
Dictionary<string, int> dict = new Dictionary<string, int> foreach (var entity in entities)
{
{ "人员工号", -1 }, { "姓名", -1 }, { "绩效类型", -1 }, { "金额", -1 }, { "备注", -1 },
};
foreach (var key in dict.Keys.ToList())
{ {
if (excelheader.Any(w => w.Value == key)) newEntities.Add(new per_apr_amount_hide
dict[key] = excelheader.First(w => w.Value == key).Key;
}
var employees = peremployeeRepository.GetEntities(t => t.AllotId == allotid);
var entities = new List<per_apr_amount_hide>();
var createtime = DateTime.Now;
for (int rowindex = 1; rowindex < sheet.LastRowNum + 1; rowindex++)
{ {
var row = sheet.GetRow(rowindex); PersonnelNumber = entity.PersonnelNumber,
if (row == null) continue; DoctorName = entity.DoctorName,
PerforType = entity.PerforType,
Amount = entity.Amount,
Remark = entity.Remark,
var entity = new per_apr_amount_hide
{
Status = 1, Status = 1,
PersonnelNumber = dict["人员工号"] < 0 ? "" : row.GetCell(dict["人员工号"]).GetValue(),
DoctorName = dict["姓名"] < 0 ? "" : row.GetCell(dict["姓名"]).GetValue(),
PerforType = dict["绩效类型"] < 0 ? "" : row.GetCell(dict["绩效类型"]).GetValue(),
Amount = dict["金额"] < 0 ? 0 : ConvertHelper.To<decimal>(row.GetCell(dict["金额"]).GetValue(), 0),
Remark = dict["备注"] < 0 ? "" : row.GetCell(dict["备注"]).GetValue(),
TypeInDepartment = typeIn, TypeInDepartment = typeIn,
AllotId = allotid, AllotId = allotid,
CreateDate = createtime, CreateDate = createtime,
CreateUser = userid, CreateUser = userid,
};
if (string.IsNullOrEmpty(entity.DoctorName) && string.IsNullOrEmpty(entity.PersonnelNumber) && string.IsNullOrEmpty(entity.PerforType) && entity.Amount == 0 && string.IsNullOrEmpty(entity.Remark))
continue;
if (string.IsNullOrEmpty(entity.DoctorName) || string.IsNullOrEmpty(entity.PersonnelNumber))
errors.Add(new Dictionary<string, string>
{
{ "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName },
{ "来源", "上传文件" },
{ "错误原因", "“关键信息缺失”请补全或删除" },
});
var employee = employees.FirstOrDefault(w => w.PersonnelNumber == entity.PersonnelNumber);
if (employee == null)
errors.Add(new Dictionary<string, string>
{
{ "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName },
{ "来源", "上传文件" },
{ "错误原因","“人员工号”错误,请修改或删除" },
}); });
else if (employee.DoctorName != entity.DoctorName)
errors.Add(new Dictionary<string, string>
{
{ "行号", $"第{rowindex}行" },
{ "人员工号", entity.PersonnelNumber },
{ "姓名", entity.DoctorName },
{ "来源", "上传文件" },
{ "错误原因", "“姓名”错误,请修改或删除" },
});
entities.Add(entity);
} }
_hideRepository.AddRange(newEntities.ToArray());
if (errors.Count == 0 && entities.Any())
_hideRepository.AddRange(entities.ToArray());
}
catch (PerformanceException ex)
{
throw ex;
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
} }
return errors; return res;
} }
/// <summary> /// <summary>
......
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