Commit b9240f81 by wyc

科室考勤上报录入保存(优化)

parent e236fada
......@@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using AutoMapper;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;
......@@ -574,7 +575,7 @@ public ApiResponse DeleteAttendanceType(int id)
/// <param name="allotId"></param>
/// <returns></returns>
/// <exception cref="PerformanceException"></exception>
public ApiResponse GetAttendanceReplenishment(int allotId,int userid)
public ApiResponse GetAttendanceReplenishment(int allotId, int userid)
{
var allot = perforPerallotRepository.GetEntity(w => w.ID == allotId) ?? throw new PerformanceException("当前绩效记录不存在");
var typeDefault = perfoPperAttendanceTypeRepository.GetEntities().Find(f => f.AllotId == allotId && f.IsDefault == (int)Attendance.Default.默认) ?? throw new PerformanceException("未设置默认类型");
......@@ -591,12 +592,13 @@ public ApiResponse GetAttendanceReplenishment(int allotId,int userid)
foreach (var item in attendanceDepts)
{
for (int i = 1; i <= 31; i++)
for (int day = 1; day <= 31; day++)
{
int? dayValue = (int?)typeof(per_attendance_dept).GetProperty($"Day{i:D2}")?.GetValue(item);
string dayPropertyName = $"Day{day:00}";
int? dayValue = (int?)typeof(per_attendance_dept).GetProperty(dayPropertyName)?.GetValue(item);
if (dayValue == null)
{
typeof(per_attendance_dept).GetProperty($"Day{i:D2}")?.SetValue(item, typeDefault.Id);
typeof(per_attendance_dept).GetProperty(dayPropertyName)?.SetValue(item, typeDefault.Id);
}
}
}
......@@ -1511,7 +1513,7 @@ public ApiResponse DeptLoad(int allotId, int userid, string userName)
Func<object, string> getAattendanceType = (value) =>
{
_ = int.TryParse(value == null ? "" : value.ToString(), out int typeId);
return typeId > 0 ? types.FirstOrDefault(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : "";
return typeId > 0 ? types.Find(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : "";
};
List<Dictionary<string, object>> datas = new List<Dictionary<string, object>>();
if (attendances.Any())
......@@ -1555,11 +1557,8 @@ public ApiResponse DeptLoad(int allotId, int userid, string userName)
datas.Add(row);
}
}
handson.Data = datas;
return new ApiResponse(ResponseType.OK, "", handson);
//return new SecondDetailDto { Head = head, Body = handson, Dic = dic };
}
/// <summary>
/// 科室考勤上报录入保存
......@@ -1579,7 +1578,6 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
throw new PerformanceException("当前绩效记录不存在");
var begMonthDate = allot.Month >= 1 && allot.Month <= 12 ? new DateTime(allot.Year, allot.Month, 1) : new DateTime(allot.Year, 12, 1);
var endMonthDate = begMonthDate.AddMonths(1).AddDays(-1);
//当角色对应时过滤
var userInfo = _userRepository.GetUser(userid);
......@@ -1597,8 +1595,7 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
var perAttendanceDepts = _attendanceDeptRepository.GetEntities(w => w.AllotId == allotId) ?? new List<per_attendance_dept>();
var attendances = perAttendanceDepts?.Where((w) => w.AllotId == allotId && unitTypes.Contains(w.UnitType) && accountingUnit.Equals(w.AccountingUnit)).ToList();
var stateCount = attendances.GroupBy(w => w.State).Select(w => new { w.Key, StateCount = w.Count() }).ToList();
if (attendances.Count() > 0 && attendances.Count() == attendances.Count(w => w.State == (int)Attendance.Report.通过))
if (attendances.Count > 0 && attendances.Count == attendances.Count(w => w.State == (int)Attendance.Report.通过))
throw new PerformanceException("当前考勤已审核通过,无法提交!");
//查询是否在其他科室的考勤记录
......@@ -1613,7 +1610,7 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
foreach (var item in datas.Select((row, ind) => (row, ind)))
{
var row = item.row;
if (string.IsNullOrEmpty(row.PersonnelNumber) || string.IsNullOrEmpty(row.PersonnelNumber))
if (string.IsNullOrEmpty(row.PersonnelNumber) || string.IsNullOrEmpty(row.PersonnelName))
{
error.Add(new Dictionary<string, string>
{
......@@ -1639,7 +1636,7 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
});
continue;
}
var emp = employees.FirstOrDefault(w => w.PersonnelNumber == row.PersonnelNumber);
var emp = employees.Find(w => w.PersonnelNumber == row.PersonnelNumber);
if (emp == null || emp.DoctorName != row.PersonnelName)
{
error.Add(new Dictionary<string, string>
......@@ -1666,7 +1663,7 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
});
continue;
}
Func<string, int?> getAattendanceType = (name) => types.FirstOrDefault(w => w.AttendanceName == name)?.Id;
Func<string, int?> getAattendanceType = (name) => types.Find(w => w.AttendanceName == name)?.Id;
var days = new[]
{
new { Date = begMonthDate.AddDays(00), TypeId = getAattendanceType(row.Day01), OrgTypeName = row.Day01 },
......@@ -1702,9 +1699,7 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
new { Date = begMonthDate.AddDays(30), TypeId = getAattendanceType(row.Day31), OrgTypeName = row.Day31 },
};
foreach (var d in days)
{
if (!string.IsNullOrEmpty(d.OrgTypeName) && !d.TypeId.HasValue)
foreach (var d in days.Where(w => !string.IsNullOrEmpty(w.OrgTypeName) && !w.TypeId.HasValue))
{
var title = CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(d.Date.DayOfWeek).Replace("星期", "");
var beaDay = d.Date.Day.ToString().PadLeft(2, '0');
......@@ -1719,16 +1714,14 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
{ "错误原因", $"“{beaDay}({title})”考勤类型“{d.OrgTypeName}”不存在"},
});
}
}
foreach (var attendanceDept in attendanceDepts)
{
if (row.PersonnelNumber.Equals(attendanceDept.PersonnelNumber))
foreach (var attendanceDept in attendanceDepts.Where(a => row.PersonnelNumber.Equals(a.PersonnelNumber)))
{
for (int i = 1; i <= 31; i++)
for (int day = 1; day <= 31; day++)
{
var attendanceDeptValue = typeof(per_attendance_dept).GetProperty("Day" + i.ToString("D2"))?.GetValue(attendanceDept);
var dataValue = typeof(AttendanceDept).GetProperty("Day" + i.ToString("D2"))?.GetValue(row);
string dayPropertyName = $"Day{day:00}";
var attendanceDeptValue = typeof(per_attendance_dept).GetProperty(dayPropertyName)?.GetValue(attendanceDept);
var dataValue = typeof(AttendanceDept).GetProperty(dayPropertyName)?.GetValue(row);
if (!string.IsNullOrEmpty(attendanceDeptValue?.ToString()) && !string.IsNullOrEmpty(dataValue?.ToString()))
{
error.Add(new Dictionary<string, string>
......@@ -1738,15 +1731,14 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
{ "姓名", attendanceDept.PersonnelName ?? "" },
{ "人员系数", attendanceDept.PermanentStaff?.ToString() ?? "" },
{ "考勤类型", "" },
{ "错误原因", $"{i.ToString("D2")}号存在考勤记录,所在科室为:{attendanceDept.AccountingUnit},请核实后重新填写"},
{ "错误原因", $"{day}号存在考勤记录,所在科室为:{attendanceDept.AccountingUnit},请核实后重新填写"},
});
}
}
}
}
var accounting = cofaccounting.FirstOrDefault(p => p.UnitType == unitType && p.AccountingUnit == accountingUnit);
var attendance = attendances.FirstOrDefault(w => w.PersonnelNumber == row.PersonnelNumber && w.UnitType == unitType.ToString() && w.AccountingUnit == accountingUnit);
var accounting = cofaccounting.Find(p => p.UnitType == unitType && p.AccountingUnit == accountingUnit);
var attendance = attendances.Find(w => w.PersonnelNumber == row.PersonnelNumber && w.UnitType == unitType.ToString() && w.AccountingUnit == accountingUnit);
if (attendance == null)
{
attendance = new per_attendance_dept
......@@ -1756,42 +1748,16 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
Code = accounting?.Code ?? "",
UnitType = unitType,
AccountingUnit = accountingUnit,
PersonnelNumber = row.PersonnelNumber,
PersonnelName = row.PersonnelName,
PermanentStaff = row.PermanentStaff ?? emp?.PermanentStaff
};
attendance.PersonnelNumber = row.PersonnelNumber;
attendance.PersonnelName = row.PersonnelName;
attendance.PermanentStaff = row.PermanentStaff ?? emp?.PermanentStaff;
attendance.Day01 = getAattendanceType(row.Day01);
attendance.Day02 = getAattendanceType(row.Day02);
attendance.Day03 = getAattendanceType(row.Day03);
attendance.Day04 = getAattendanceType(row.Day04);
attendance.Day05 = getAattendanceType(row.Day05);
attendance.Day06 = getAattendanceType(row.Day06);
attendance.Day07 = getAattendanceType(row.Day07);
attendance.Day08 = getAattendanceType(row.Day08);
attendance.Day09 = getAattendanceType(row.Day09);
attendance.Day10 = getAattendanceType(row.Day10);
attendance.Day11 = getAattendanceType(row.Day11);
attendance.Day12 = getAattendanceType(row.Day12);
attendance.Day13 = getAattendanceType(row.Day13);
attendance.Day14 = getAattendanceType(row.Day14);
attendance.Day15 = getAattendanceType(row.Day15);
attendance.Day16 = getAattendanceType(row.Day16);
attendance.Day17 = getAattendanceType(row.Day17);
attendance.Day18 = getAattendanceType(row.Day18);
attendance.Day19 = getAattendanceType(row.Day19);
attendance.Day20 = getAattendanceType(row.Day20);
attendance.Day21 = getAattendanceType(row.Day21);
attendance.Day22 = getAattendanceType(row.Day22);
attendance.Day23 = getAattendanceType(row.Day23);
attendance.Day24 = getAattendanceType(row.Day24);
attendance.Day25 = getAattendanceType(row.Day25);
attendance.Day26 = getAattendanceType(row.Day26);
attendance.Day27 = getAattendanceType(row.Day27);
attendance.Day28 = getAattendanceType(row.Day28);
attendance.Day29 = getAattendanceType(row.Day29);
attendance.Day30 = getAattendanceType(row.Day30);
attendance.Day31 = getAattendanceType(row.Day31);
for (int day = 1; day <= 31; day++)
{
string dayPropertyName = $"Day{day:00}";
PropertyInfo attendanceProperty = typeof(per_attendance_dept).GetProperty(dayPropertyName);
attendanceProperty?.SetValue(attendance, getAattendanceType((string)(row.GetType().GetProperty(dayPropertyName)?.GetValue(row))));
}
newAttendanceDepts.Add(attendance);
}
else
......@@ -1799,37 +1765,17 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
attendance.PersonnelNumber = row.PersonnelNumber;
attendance.PersonnelName = row.PersonnelName;
attendance.PermanentStaff = row.PermanentStaff ?? emp?.PermanentStaff;
attendance.Day01 = getAattendanceType(row.Day01);
attendance.Day02 = getAattendanceType(row.Day02);
attendance.Day03 = getAattendanceType(row.Day03);
attendance.Day04 = getAattendanceType(row.Day04);
attendance.Day05 = getAattendanceType(row.Day05);
attendance.Day06 = getAattendanceType(row.Day06);
attendance.Day07 = getAattendanceType(row.Day07);
attendance.Day08 = getAattendanceType(row.Day08);
attendance.Day09 = getAattendanceType(row.Day09);
attendance.Day10 = getAattendanceType(row.Day10);
attendance.Day11 = getAattendanceType(row.Day11);
attendance.Day12 = getAattendanceType(row.Day12);
attendance.Day13 = getAattendanceType(row.Day13);
attendance.Day14 = getAattendanceType(row.Day14);
attendance.Day15 = getAattendanceType(row.Day15);
attendance.Day16 = getAattendanceType(row.Day16);
attendance.Day17 = getAattendanceType(row.Day17);
attendance.Day18 = getAattendanceType(row.Day18);
attendance.Day19 = getAattendanceType(row.Day19);
attendance.Day20 = getAattendanceType(row.Day20);
attendance.Day21 = getAattendanceType(row.Day21);
attendance.Day22 = getAattendanceType(row.Day22);
attendance.Day23 = getAattendanceType(row.Day23);
attendance.Day24 = getAattendanceType(row.Day24);
attendance.Day25 = getAattendanceType(row.Day25);
attendance.Day26 = getAattendanceType(row.Day26);
attendance.Day27 = getAattendanceType(row.Day27);
attendance.Day28 = getAattendanceType(row.Day28);
attendance.Day29 = getAattendanceType(row.Day29);
attendance.Day30 = getAattendanceType(row.Day30);
attendance.Day31 = getAattendanceType(row.Day31);
for (int day = 1; day <= 31; day++)
{
string dayPropertyName = $"Day{day:00}";
PropertyInfo rowProperty = row.GetType().GetProperty(dayPropertyName);
if (rowProperty != null)
{
PropertyInfo attendanceProperty = typeof(per_attendance_dept).GetProperty(dayPropertyName);
attendanceProperty?.SetValue(attendance, getAattendanceType((string)rowProperty.GetValue(row)));
}
}
updAttendanceDepts.Add(attendance);
// 记录不需要删除的历史数据
validAttendanceId.Add(attendance.Id);
......@@ -1843,12 +1789,10 @@ public ApiResponse DeptSave(int allotId, List<AttendanceDept> datas, string unit
_attendanceDeptRepository.AddRange(newAttendanceDepts.ToArray());
if (updAttendanceDepts.Any())
_attendanceDeptRepository.UpdateRange(updAttendanceDepts.ToArray());
var delAttendanceDepts = attendances.Where(w => !validAttendanceId.Contains(w.Id));
if (delAttendanceDepts.Any())
_attendanceDeptRepository.RemoveRange(delAttendanceDepts.ToArray());
return new ApiResponse(ResponseType.OK, "保存成功");
}
/// <summary>
......@@ -1867,7 +1811,6 @@ public ApiResponse<List<AttendanceStatistics>> DeptCompute(int allotId, List<Att
throw new PerformanceException("当前绩效记录不存在");
var begMonthDate = allot.Month >= 1 && allot.Month <= 12 ? new DateTime(allot.Year, allot.Month, 1) : new DateTime(allot.Year, 12, 1);
var endMonthDate = begMonthDate.AddMonths(1).AddDays(-1);
var statistics = new List<AttendanceStatistics>();
var types = perfoPperAttendanceTypeRepository.GetEntities(t => t.AllotId == allotId) ?? new List<per_attendance_type>();
......@@ -1939,7 +1882,7 @@ public ApiResponse<List<AttendanceStatistics>> DeptCompute(int allotId, List<Att
{
Title = w.Key,
Value = w.Count(),
Remark = types.FirstOrDefault(p => p.AttendanceName == w.Key)?.IsDeduction == (int)Attendance.Deduction.核减 ? "核减" : "不核减",
Remark = types.Find(p => p.AttendanceName == w.Key)?.IsDeduction == (int)Attendance.Deduction.核减 ? "核减" : "不核减",
}).ToList();
foreach (var tp in types)
......
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