人员字典验证完善

parent 1a12ee5c
...@@ -59,9 +59,7 @@ public ApiResponse GetPersons([FromRoute] int allotId, [FromBody] PersonParamsRe ...@@ -59,9 +59,7 @@ public ApiResponse GetPersons([FromRoute] int allotId, [FromBody] PersonParamsRe
public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request) public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request)
{ {
request.CreateUser = claimService.GetUserId(); request.CreateUser = claimService.GetUserId();
var employeee = personService.CreatePerson(request); return personService.CreatePerson(request);
return employeee.Id > 0 ? new ApiResponse(ResponseType.OK, "添加成功!", employeee)
: new ApiResponse(ResponseType.Fail, "添加失败!");
} }
/// <summary> /// <summary>
...@@ -73,9 +71,7 @@ public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request) ...@@ -73,9 +71,7 @@ public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request)
[HttpPost] [HttpPost]
public ApiResponse UpdatePerson([FromBody] PerEmployeeResponse request) public ApiResponse UpdatePerson([FromBody] PerEmployeeResponse request)
{ {
var result = personService.UpdatePerson(request); return personService.UpdatePerson(request);
return result ? new ApiResponse(ResponseType.OK, "修改成功!")
: new ApiResponse(ResponseType.OK, "修改失败!");
} }
/// <summary> /// <summary>
......
...@@ -231,10 +231,38 @@ public PageList<per_employee> GetPersons(int allotId, int userId, PersonParamsRe ...@@ -231,10 +231,38 @@ public PageList<per_employee> GetPersons(int allotId, int userId, PersonParamsRe
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
public per_employee CreatePerson(PerEmployeeResponse request) public ApiResponse CreatePerson(PerEmployeeResponse request)
{ {
var employee = peremployeeRepository.GetEntity(t => t.AllotId == request.AllotId && t.PersonnelNumber == request.PersonnelNumber List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
&& t.DoctorName == request.DoctorName && t.Department == request.Department); var oldEmployees = peremployeeRepository.GetEntities(t => t.AllotId == request.AllotId);
for (int i = 0; i < oldEmployees.Count; i++)
{
if (oldEmployees.Count(w => w.PersonnelNumber == oldEmployees[i].PersonnelNumber) > 1)
{
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "人员工号", oldEmployees[i].PersonnelNumber??"" },
{ "姓名", oldEmployees[i].DoctorName??"" },
{ "错误原因", "“人员工号”重复" },
});
}
}
if (error.Count > 0)
return new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", error);
if (string.IsNullOrEmpty(request.UnitType?.Trim())
|| string.IsNullOrEmpty(request.Department?.Trim())
|| string.IsNullOrEmpty(request.AccountingUnit?.Trim())
|| string.IsNullOrEmpty(request.DoctorName?.Trim())
|| string.IsNullOrEmpty(request.PersonnelNumber?.Trim()))
{
throw new PerformanceException($"“关键信息缺失”请补全!");
}
var employee = peremployeeRepository.GetEntity(t => t.AllotId == request.AllotId && t.PersonnelNumber == request.PersonnelNumber);
if (employee != null) if (employee != null)
throw new PerformanceException($"员工工号为{request.PersonnelNumber}的数据已存在!"); throw new PerformanceException($"员工工号为{request.PersonnelNumber}的数据已存在!");
...@@ -253,7 +281,8 @@ public per_employee CreatePerson(PerEmployeeResponse request) ...@@ -253,7 +281,8 @@ public per_employee CreatePerson(PerEmployeeResponse request)
//CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department); //CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department);
peremployeeRepository.Add(entity); peremployeeRepository.Add(entity);
return entity;
return new ApiResponse(ResponseType.OK, "添加成功", entity);
} }
/// <summary> /// <summary>
...@@ -261,12 +290,44 @@ public per_employee CreatePerson(PerEmployeeResponse request) ...@@ -261,12 +290,44 @@ public per_employee CreatePerson(PerEmployeeResponse request)
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
public bool UpdatePerson(PerEmployeeResponse request) public ApiResponse UpdatePerson(PerEmployeeResponse request)
{ {
var employee = peremployeeRepository.GetEntity(t => t.AllotId == request.AllotId && t.PersonnelNumber == request.PersonnelNumber List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
&& t.DoctorName == request.DoctorName && t.Department == request.Department); var oldEmployees = peremployeeRepository.GetEntities(t => t.AllotId == request.AllotId);
if (employee != null && employee.Id != request.Id)
throw new PerformanceException($"员工工号为{request.PersonnelNumber}的数据已存在!"); for (int i = 0; i < oldEmployees.Count; i++)
{
if (oldEmployees.Count(w => w.PersonnelNumber == oldEmployees[i].PersonnelNumber) > 1)
{
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "人员工号", oldEmployees[i].PersonnelNumber??"" },
{ "姓名", oldEmployees[i].DoctorName??"" },
{ "错误原因", "“人员工号”重复" },
});
}
}
if (error.Count > 0)
return new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", error);
if (string.IsNullOrEmpty(request.UnitType?.Trim())
|| string.IsNullOrEmpty(request.Department?.Trim())
|| string.IsNullOrEmpty(request.AccountingUnit?.Trim())
|| string.IsNullOrEmpty(request.DoctorName?.Trim())
|| string.IsNullOrEmpty(request.PersonnelNumber?.Trim()))
{
throw new PerformanceException($"“关键信息缺失”请补全!");
}
var employees = peremployeeRepository.GetEntities(t => t.AllotId == request.AllotId && t.PersonnelNumber == request.PersonnelNumber);
if (employees == null)
throw new PerformanceException($"员工工号为“{request.PersonnelNumber}”不存在,请重新添加!");
if (employees.Count() > 1)
throw new PerformanceException($"工号为“{request.PersonnelNumber}”存在多条数据,请删除多余数据!");
var unittype = EnumHelper.GetItems<UnitType>().Select(t => t.Description).ToList(); var unittype = EnumHelper.GetItems<UnitType>().Select(t => t.Description).ToList();
unittype.AddRange(EnumHelper.GetItems<AccountUnitType>().Select(t => t.Description)); unittype.AddRange(EnumHelper.GetItems<AccountUnitType>().Select(t => t.Description));
...@@ -274,9 +335,7 @@ public bool UpdatePerson(PerEmployeeResponse request) ...@@ -274,9 +335,7 @@ public bool UpdatePerson(PerEmployeeResponse request)
if (!unittype.Contains(request.UnitType)) if (!unittype.Contains(request.UnitType))
throw new PerformanceException($"人员类别不符合规范!"); throw new PerformanceException($"人员类别不符合规范!");
if (employee == null) var employee = employees.First();
employee = peremployeeRepository.GetEntity(t => t.Id == request.Id) ?? throw new PerformanceException("人员信息无效!");
//_mapper.Map(request, employee, typeof(per_employee), typeof(per_employee)); //_mapper.Map(request, employee, typeof(per_employee), typeof(per_employee));
employee.AccountingUnit = request.AccountingUnit; employee.AccountingUnit = request.AccountingUnit;
...@@ -304,7 +363,9 @@ public bool UpdatePerson(PerEmployeeResponse request) ...@@ -304,7 +363,9 @@ public bool UpdatePerson(PerEmployeeResponse request)
employee.Attendance = Math.Round((request.AttendanceDay ?? 0) / day, 4); employee.Attendance = Math.Round((request.AttendanceDay ?? 0) / day, 4);
//CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department); //CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department);
return peremployeeRepository.Update(employee); var res = peremployeeRepository.Update(employee);
return new ApiResponse(ResponseType.OK, "修改成功");
} }
/// <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