人员字典验证完善

parent 1a12ee5c
......@@ -59,9 +59,7 @@ public ApiResponse GetPersons([FromRoute] int allotId, [FromBody] PersonParamsRe
public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request)
{
request.CreateUser = claimService.GetUserId();
var employeee = personService.CreatePerson(request);
return employeee.Id > 0 ? new ApiResponse(ResponseType.OK, "添加成功!", employeee)
: new ApiResponse(ResponseType.Fail, "添加失败!");
return personService.CreatePerson(request);
}
/// <summary>
......@@ -73,9 +71,7 @@ public ApiResponse CreatePerson([FromBody] PerEmployeeResponse request)
[HttpPost]
public ApiResponse UpdatePerson([FromBody] PerEmployeeResponse request)
{
var result = personService.UpdatePerson(request);
return result ? new ApiResponse(ResponseType.OK, "修改成功!")
: new ApiResponse(ResponseType.OK, "修改失败!");
return personService.UpdatePerson(request);
}
/// <summary>
......
......@@ -231,10 +231,38 @@ public PageList<per_employee> GetPersons(int allotId, int userId, PersonParamsRe
/// </summary>
/// <param name="request"></param>
/// <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
&& t.DoctorName == request.DoctorName && t.Department == request.Department);
List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
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)
throw new PerformanceException($"员工工号为{request.PersonnelNumber}的数据已存在!");
......@@ -253,7 +281,8 @@ public per_employee CreatePerson(PerEmployeeResponse request)
//CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department);
peremployeeRepository.Add(entity);
return entity;
return new ApiResponse(ResponseType.OK, "添加成功", entity);
}
/// <summary>
......@@ -261,12 +290,44 @@ public per_employee CreatePerson(PerEmployeeResponse request)
/// </summary>
/// <param name="request"></param>
/// <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
&& t.DoctorName == request.DoctorName && t.Department == request.Department);
if (employee != null && employee.Id != request.Id)
throw new PerformanceException($"员工工号为{request.PersonnelNumber}的数据已存在!");
List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
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 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();
unittype.AddRange(EnumHelper.GetItems<AccountUnitType>().Select(t => t.Description));
......@@ -274,9 +335,7 @@ public bool UpdatePerson(PerEmployeeResponse request)
if (!unittype.Contains(request.UnitType))
throw new PerformanceException($"人员类别不符合规范!");
if (employee == null)
employee = peremployeeRepository.GetEntity(t => t.Id == request.Id) ?? throw new PerformanceException("人员信息无效!");
var employee = employees.First();
//_mapper.Map(request, employee, typeof(per_employee), typeof(per_employee));
employee.AccountingUnit = request.AccountingUnit;
......@@ -304,7 +363,9 @@ public bool UpdatePerson(PerEmployeeResponse request)
employee.Attendance = Math.Round((request.AttendanceDay ?? 0) / day, 4);
//CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department);
return peremployeeRepository.Update(employee);
var res = peremployeeRepository.Update(employee);
return new ApiResponse(ResponseType.OK, "修改成功");
}
/// <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