Commit 2bc83756 by wyc

考勤上报和加载上月(bug修复)

parent 200beeee
...@@ -2429,7 +2429,7 @@ public void DeptReportRefresh(per_allot allot, int state, List<per_attendance_de ...@@ -2429,7 +2429,7 @@ public void DeptReportRefresh(per_allot allot, int state, List<per_attendance_de
attendances ??= new List<per_attendance_dept>(); attendances ??= new List<per_attendance_dept>();
var types = perfoPperAttendanceTypeRepository.GetEntities(t => t.AllotId == allot.ID) ?? new List<per_attendance_type>(); var types = perfoPperAttendanceTypeRepository.GetEntities(t => t.AllotId == allot.ID) ?? new List<per_attendance_type>();
Func<int?, string> getAattendanceType = (typeId) => typeId > 0 ? types.FirstOrDefault(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : ""; Func<int?, string> getAattendanceType = (typeId) => typeId > 0 ? types.FirstOrDefault(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : "";
List<AttendanceDeptMore> datas = attendances.Select(w => new AttendanceDeptMore List<AttendanceDeptMore> datas = attendances.Where(w => w.State == state).Select(w => new AttendanceDeptMore
{ {
AllotId = allot.ID, AllotId = allot.ID,
Code = w.Code, Code = w.Code,
...@@ -2498,14 +2498,12 @@ public void DeptReportRefresh(per_allot allot, int state, List<per_attendance_de ...@@ -2498,14 +2498,12 @@ public void DeptReportRefresh(per_allot allot, int state, List<per_attendance_de
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
}; };
}); });
var unitTypes = attendances.Select(w => w.UnitType).Distinct().ToList(); var oldEntities = _perforPerAttendanceDeptReportRepository.GetEntities(w => w.AllotId == allot.ID).ToList();
var accountingUnits = attendances.Select(w => w.AccountingUnit).Distinct().ToList(); if (oldEntities.Any())
var oldEntities = _perforPerAttendanceDeptReportRepository.GetEntities(w => w.AllotId == allot.ID && unitTypes.Contains(w.UnitType) && accountingUnits.Contains(w.AccountingUnit));
if (oldEntities?.Any() == true)
{ {
_perforPerAttendanceDeptReportRepository.RemoveRange(oldEntities.ToArray()); _perforPerAttendanceDeptReportRepository.RemoveRange(oldEntities.ToArray());
} }
if (state == (int)Attendance.Report.通过 && newEntities?.Any() == true) if (state == (int)Attendance.Report.通过 && newEntities.Any())
{ {
_perforPerAttendanceDeptReportRepository.AddRange(newEntities.ToArray()); _perforPerAttendanceDeptReportRepository.AddRange(newEntities.ToArray());
} }
......
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.EntityModels.Entity; using Performance.EntityModels.Entity;
using Performance.EntityModels.Other;
using Performance.Repository; using Performance.Repository;
using Performance.Repository.Repository; using Performance.Repository.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
namespace Performance.Services namespace Performance.Services
{ {
...@@ -325,11 +327,12 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId) ...@@ -325,11 +327,12 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId)
var prevAttTypes = attendanceTypes.Where(w => w.AllotId == prevAllotId).ToList(); var prevAttTypes = attendanceTypes.Where(w => w.AllotId == prevAllotId).ToList();
if (!prevAttTypes.Any()) return; if (!prevAttTypes.Any()) return;
// 删除当月的考勤类型 // 修改当月的考勤类型,加载上月完成在删除
var delAttTypes = attendanceTypes.Where(w => w.AllotId == allot.ID).ToList(); var updataAttTypes = attendanceTypes.Where(w => w.AllotId == allot.ID).ToList();
if (delAttTypes.Any()) if (updataAttTypes.Any())
{ {
_pperAttendanceTypeRepository.RemoveRange(delAttTypes.ToArray()); updataAttTypes.ForEach(w => w.AllotId = 0);
_pperAttendanceTypeRepository.UpdateRange(updataAttTypes.ToArray());
} }
//插入上月的考勤类型 //插入上月的考勤类型
var newAttTypes = prevAttTypes.Select(t => new per_attendance_type var newAttTypes = prevAttTypes.Select(t => new per_attendance_type
...@@ -349,12 +352,32 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId) ...@@ -349,12 +352,32 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId)
var prevPerEmployee = _perforPeremployeeRepository.GetEntities(g => g.AllotId == prevAllotId); var prevPerEmployee = _perforPeremployeeRepository.GetEntities(g => g.AllotId == prevAllotId);
if (!prevPerEmployee.Any()) return; if (!prevPerEmployee.Any()) return;
// 删除当月的考勤上报 var attendance_Types = _pperAttendanceTypeRepository.GetEntities(g => g.AllotId == 0).ToList();
var delAttDepts = _perforPerAttendanceDeptRepository.GetEntities(w => w.AllotId == allot.ID).ToList(); // 修改当月的考勤上报
if (delAttDepts.Any()) var updataAttDepts = _perforPerAttendanceDeptRepository.GetEntities(w => w.AllotId == allot.ID).ToList();
if (updataAttDepts.Any())
{ {
_perforPerAttendanceDeptRepository.RemoveRange(delAttDepts.ToArray()); foreach (var att in updataAttDepts)
{
for (int day = 1; day <= 31; day++)
{
string dayPropertyName = $"Day{day:00}";
PropertyInfo dayProperty = typeof(per_attendance_dept).GetProperty(dayPropertyName);
if (dayProperty != null)
{
int? dayValue = (int?)dayProperty.GetValue(att);
var oldDayPropertyName = attendance_Types.FirstOrDefault(w => w.Id == dayValue)?.AttendanceName ?? "考勤类型缺失";
var newDayPropertyName = newAttTypes.FirstOrDefault(w => w.AttendanceName == oldDayPropertyName)?.Id;
if (newDayPropertyName != null)
{
dayProperty.SetValue(att, newDayPropertyName);
}
}
}
}
_perforPerAttendanceDeptRepository.UpdateRange(updataAttDepts.ToArray());
} }
//查询默认考勤类型 //查询默认考勤类型
var typeDefault = newAttTypes.Find(f => f.IsDefault == (int)Attendance.Default.默认); var typeDefault = newAttTypes.Find(f => f.IsDefault == (int)Attendance.Default.默认);
var cofaccounting = _cofaccountingRepository.GetEntities(g => g.AllotId == prevAllotId); var cofaccounting = _cofaccountingRepository.GetEntities(g => g.AllotId == prevAllotId);
...@@ -387,7 +410,9 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId) ...@@ -387,7 +410,9 @@ public void Copy_AttendanceType(per_allot allot, int prevAllotId)
}).ToList(); }).ToList();
_perforPerAttendanceDeptRepository.AddRange(newAttDepts.ToArray()); _perforPerAttendanceDeptRepository.AddRange(newAttDepts.ToArray());
_pperAttendanceTypeRepository.RemoveRange(attendance_Types.ToArray());
} }
} }
/// <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