Commit 77cc2895 by wyc

接口(dept/compute)结果统计、下载重写

parent ce1931bb
......@@ -667,63 +667,12 @@ public ApiResponse DeptSave(int allotId, string unitType, [FromBody] List<Attend
/// <returns></returns>
[HttpPost]
[Route("dept/compute")]
public ApiResponse<List<AttendanceStatistics>> DeptCompute(int allotId, string unitType, string accountingUnit, string searchTxet, [FromBody] List<AttendanceDept> datas)
public ApiResponse<List<AttendanceDeptReport>> DeptCompute(int allotId, string unitType, string accountingUnit, string searchTxet)
{
if (!Enum.TryParse(unitType, out UnitType unitType1))
throw new PerformanceException("核算组别错误");
List<AttendanceDeptMore> deptDetail = new List<AttendanceDeptMore>();
if (datas?.Any() != true)
{
deptDetail = _attendanceService.DeptDetail(allotId, unitType, accountingUnit, searchTxet)?.Data?.Data ?? new List<AttendanceDeptMore>();
}
else
{
deptDetail = datas.Select(w => new AttendanceDeptMore
{
AllotId = allotId,
Code = "",
UnitType = unitType,
AccountingUnit = accountingUnit,
PersonnelNumber = w.PersonnelNumber,
PersonnelName = w.PersonnelName,
PermanentStaff = w.PermanentStaff,
AuditTime = DateTime.Now,
AuditUser = "",
Day01 = w.Day01,
Day02 = w.Day02,
Day03 = w.Day03,
Day04 = w.Day04,
Day05 = w.Day05,
Day06 = w.Day06,
Day07 = w.Day07,
Day08 = w.Day08,
Day09 = w.Day09,
Day10 = w.Day10,
Day11 = w.Day11,
Day12 = w.Day12,
Day13 = w.Day13,
Day14 = w.Day14,
Day15 = w.Day15,
Day16 = w.Day16,
Day17 = w.Day17,
Day18 = w.Day18,
Day19 = w.Day19,
Day20 = w.Day20,
Day21 = w.Day21,
Day22 = w.Day22,
Day23 = w.Day23,
Day24 = w.Day24,
Day25 = w.Day25,
Day26 = w.Day26,
Day27 = w.Day27,
Day28 = w.Day28,
Day29 = w.Day29,
Day30 = w.Day30,
Day31 = w.Day31,
}).ToList();
}
return _attendanceService.DeptCompute(allotId, deptDetail);
return _attendanceService.DeptComputeReport(allotId, unitType, accountingUnit, searchTxet);
}
/// <summary>
......@@ -749,24 +698,21 @@ public IActionResult DownloadDeptCompute(int allotId, string unitType, string ac
new ExcelDownloadHeads { Alias = "核算单元名称", Name = nameof(AttendanceStatistics.AccountingUnit) },
new ExcelDownloadHeads { Alias = "姓名", Name = nameof(AttendanceStatistics.PersonnelName) },
new ExcelDownloadHeads { Alias = "员工号", Name = nameof(AttendanceStatistics.PersonnelNumber) },
new ExcelDownloadHeads { Alias = "在科开始时问", Name = nameof(AttendanceStatistics.BeginDate) },
new ExcelDownloadHeads { Alias = "在科结束时间", Name = nameof(AttendanceStatistics.EndDate) },
new ExcelDownloadHeads { Alias = "人员系数", Name = nameof(AttendanceStatistics.PermanentStaff) },
};
var type = _attendanceService.GetAttendanceType(allotId);
foreach (var item in type.Data)
var res = _attendanceService.DeptComputeReport(allotId, unitType, accountingUnit, searchTxet);
var result = (res?.Data == null) ? new List<AttendanceDeptReport>() : res.Data;
foreach (var item in result.SelectMany(w => w.Detial).Select(w => w.Title).Distinct())
{
excelDownloadHeads.Add(new ExcelDownloadHeads() { Alias = item.AttendanceName, Name = item.AttendanceName });
excelDownloadHeads.Add(new ExcelDownloadHeads() { Alias = item, Name = item });
}
excelDownloadHeads.Add(new ExcelDownloadHeads() { Alias = "出勤天数", Name = "AttendanceDays" });
var deptDetail = _attendanceService.DeptDetail(allotId, unitType, accountingUnit, searchTxet)?.Data?.Data ?? new List<AttendanceDeptMore>();
var res = _attendanceService.DeptCompute(allotId, deptDetail);
var result = (res?.Data == null) ? new List<AttendanceStatistics>() : res.Data;
var ser = JsonConvert.SerializeObject(result);
var rows = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(ser);
var filepath = _attendanceService.ExcelDownload(rows, "科室上报考勤结果", allotId, excelDownloadHeads);
var filepath = _attendanceService.ExcelDownload(rows, "考勤上报统计", allotId, excelDownloadHeads);
var memoryStream = new MemoryStream();
using (var stream = new FileStream(filepath, FileMode.Open))
......
......@@ -779,7 +779,7 @@
<param name="datas"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AttendanceController.DeptCompute(System.Int32,System.String,System.String,System.String,System.Collections.Generic.List{Performance.DtoModels.Request.AttendanceDept})">
<member name="M:Performance.Api.Controllers.AttendanceController.DeptCompute(System.Int32,System.String,System.String,System.String)">
<summary>
科室考勤上报录入结果统计
</summary>
......@@ -1045,6 +1045,13 @@
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ComputeController.UniteDeptDetail(Performance.DtoModels.DeptDetailRequest)">
<summary>
科室绩效详情
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ComputeController.DeptDetail(Performance.DtoModels.DeptDetailRequest)">
<summary>
科室绩效详情
......
......@@ -2439,7 +2439,47 @@ public ApiResponse<List<AttendanceDeptReport>> DeptReport(int allotId, string un
var names = typeof(per_attendance_dept_report).GetProperties().Select(w => w.Name);
var rows = _service.QueryAttendanceDeptReport(allotId, unitType, accountingUnit, searchTxet);
Func<int?, string> getAattendanceType = (typeId) => typeId > 0 ? types.FirstOrDefault(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : "";
var temp1 = new List<int?>();
foreach (var item in attendances)
{
var Day = new[] {
new { TypeId = item.Day01 },
new { TypeId = item.Day02 },
new { TypeId = item.Day03 },
new { TypeId = item.Day04 },
new { TypeId = item.Day05 },
new { TypeId = item.Day06 },
new { TypeId = item.Day07 },
new { TypeId = item.Day08 },
new { TypeId = item.Day09 },
new { TypeId = item.Day10 },
new { TypeId = item.Day11 },
new { TypeId = item.Day12 },
new { TypeId = item.Day13 },
new { TypeId = item.Day14 },
new { TypeId = item.Day15 },
new { TypeId = item.Day16 },
new { TypeId = item.Day17 },
new { TypeId = item.Day18 },
new { TypeId = item.Day19 },
new { TypeId = item.Day20 },
new { TypeId = item.Day21 },
new { TypeId = item.Day22 },
new { TypeId = item.Day23 },
new { TypeId = item.Day24 },
new { TypeId = item.Day25 },
new { TypeId = item.Day26 },
new { TypeId = item.Day27 },
new { TypeId = item.Day28 },
new { TypeId = item.Day29 },
new { TypeId = item.Day30 },
new { TypeId = item.Day31 },
};
List<int?> temp2 = Day.Where(w => w.TypeId != null).Distinct().Select(w => w.TypeId).ToList();
temp1.AddRange(temp2);
}
var temp3 = temp1.Distinct();
types = types.Where(w => temp3.Contains(w.Id)).ToList();
List<AttendanceDeptReport> items = new List<AttendanceDeptReport>();
foreach (var row in rows)
{
......@@ -2515,6 +2555,146 @@ public ApiResponse<List<AttendanceDeptReport>> DeptReport(int allotId, string un
items = items.OrderBy(w => w.PersonnelNumber).ThenBy(w => w.BeginDate).ToList();
return new ApiResponse<List<AttendanceDeptReport>>(ResponseType.OK, items);
}
public ApiResponse<List<AttendanceDeptReport>> DeptComputeReport(int allotId, string unitType, string accountingUnit, string searchTxet)
{
var allot = perforPerallotRepository.GetEntity(w => w.ID == allotId);
if (allot == null)
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);
Expression<Func<per_attendance_dept, bool>> deptExpression = (w) => w.AllotId == allotId;
if (!string.IsNullOrEmpty(unitType))
deptExpression = deptExpression.And(w => w.UnitType.Equals(unitType));
if (!string.IsNullOrEmpty(accountingUnit))
deptExpression = deptExpression.And(w => w.AccountingUnit.Equals(accountingUnit));
if (!string.IsNullOrEmpty(searchTxet))
deptExpression = deptExpression.And(w => w.PersonnelNumber.Contains(searchTxet) || w.PersonnelName.Contains(searchTxet));
var types = perfoPperAttendanceTypeRepository.GetEntities(t => t.AllotId == allotId) ?? new List<per_attendance_type>();
var attendances = _attendanceDeptRepository.GetEntities(deptExpression) ?? new List<per_attendance_dept>();
var names = typeof(per_attendance_dept_report).GetProperties().Select(w => w.Name);
var rows = _service.QueryAttendanceDeptReportCompute(allotId, unitType, accountingUnit, searchTxet);
Func<int?, string> getAattendanceType = (typeId) => typeId > 0 ? types.FirstOrDefault(w => w.Id == typeId)?.AttendanceName ?? "考勤类型缺失" : "";
var temp1 = new List<int?>();
foreach (var item in attendances)
{
var Day = new[] {
new { TypeId = item.Day01 },
new { TypeId = item.Day02 },
new { TypeId = item.Day03 },
new { TypeId = item.Day04 },
new { TypeId = item.Day05 },
new { TypeId = item.Day06 },
new { TypeId = item.Day07 },
new { TypeId = item.Day08 },
new { TypeId = item.Day09 },
new { TypeId = item.Day10 },
new { TypeId = item.Day11 },
new { TypeId = item.Day12 },
new { TypeId = item.Day13 },
new { TypeId = item.Day14 },
new { TypeId = item.Day15 },
new { TypeId = item.Day16 },
new { TypeId = item.Day17 },
new { TypeId = item.Day18 },
new { TypeId = item.Day19 },
new { TypeId = item.Day20 },
new { TypeId = item.Day21 },
new { TypeId = item.Day22 },
new { TypeId = item.Day23 },
new { TypeId = item.Day24 },
new { TypeId = item.Day25 },
new { TypeId = item.Day26 },
new { TypeId = item.Day27 },
new { TypeId = item.Day28 },
new { TypeId = item.Day29 },
new { TypeId = item.Day30 },
new { TypeId = item.Day31 },
};
List<int?> temp2 = Day.Where(w => w.TypeId != null).Distinct().Select(w => w.TypeId).ToList();
temp1.AddRange(temp2);
}
var temp3 = temp1.Distinct();
types = types.Where(w => temp3.Contains(w.Id)).ToList();
List<AttendanceDeptReport> items = new List<AttendanceDeptReport>();
foreach (var row in rows)
{
AttendanceDeptReport item = JsonHelper.Deserialize<AttendanceDeptReport>(JsonHelper.Serialize(row));
item.Detial = new List<AttendanceDeptReportItem>();
var atte = attendances.FirstOrDefault(w => w.UnitType == item.UnitType && w.AccountingUnit == item.AccountingUnit && w.PersonnelNumber == item.PersonnelNumber) ?? new per_attendance_dept();
var days = new[] {
new { TypeId = atte.Day01 },
new { TypeId = atte.Day02 },
new { TypeId = atte.Day03 },
new { TypeId = atte.Day04 },
new { TypeId = atte.Day05 },
new { TypeId = atte.Day06 },
new { TypeId = atte.Day07 },
new { TypeId = atte.Day08 },
new { TypeId = atte.Day09 },
new { TypeId = atte.Day10 },
new { TypeId = atte.Day11 },
new { TypeId = atte.Day12 },
new { TypeId = atte.Day13 },
new { TypeId = atte.Day14 },
new { TypeId = atte.Day15 },
new { TypeId = atte.Day16 },
new { TypeId = atte.Day17 },
new { TypeId = atte.Day18 },
new { TypeId = atte.Day19 },
new { TypeId = atte.Day20 },
new { TypeId = atte.Day21 },
new { TypeId = atte.Day22 },
new { TypeId = atte.Day23 },
new { TypeId = atte.Day24 },
new { TypeId = atte.Day25 },
new { TypeId = atte.Day26 },
new { TypeId = atte.Day27 },
new { TypeId = atte.Day28 },
new { TypeId = atte.Day29 },
new { TypeId = atte.Day30 },
new { TypeId = atte.Day31 },
};
var arr = days.Where(w => w.TypeId.HasValue && w.TypeId > 0)
.GroupBy(w => w.TypeId)
.Select(w => new { TypeId = w.Key, TypeName = getAattendanceType(w.Key), Value = w.Count() })
.ToList();
foreach (var d in arr)
{
item.Detial.Add(new AttendanceDeptReportItem
{
Title = d.TypeName,
Value = d.Value,
Remark = types.FirstOrDefault(w => w.Id == d.TypeId)?.IsDeduction == (int)Attendance.Deduction.核减 ? "核减" : "不核减",
});
}
foreach (var t in types)
{
if (!item.Detial.Any(w => w.Title == t.AttendanceName))
{
item.Detial.Add(new AttendanceDeptReportItem
{
Title = t.AttendanceName,
Value = 0,
Remark = t.IsDeduction == (int)Attendance.Deduction.核减 ? "核减" : "不核减",
});
}
}
var dic = new RouteValueDictionary(row);
foreach (var dicItem in dic.Where(w => !names.Any(name => name.Equals(w.Key, StringComparison.OrdinalIgnoreCase))))
{
item.Detial.Add(new AttendanceDeptReportItem { Title = dicItem.Key, Remark = "", Value = dicItem.Value ?? 0 });
}
items.Add(item);
}
items = items.OrderBy(w => w.PersonnelNumber).ThenBy(w => w.BeginDate).ToList();
return new ApiResponse<List<AttendanceDeptReport>>(ResponseType.OK, items);
}
#endregion
#region 拆分请假时间段为每个日期
......@@ -2593,10 +2773,13 @@ public string ExcelDownload(List<Dictionary<string, object>> rows, string name,
for (int row = 0; row < data.Count(); row++)
{
var temp = data.ElementAt(row);
var low = temp.Keys.ToString().ToLower();
var value = temp.GetValue(headList[col].Name, "");
worksheet.Cells[row + 3, col + 1].Value = value;
var key = headList[col].Name;
if (!temp.ContainsKey(key))
key = key.ToLower();
temp.TryGetValue(key, out object value);
worksheet.Cells[row + 3, col + 1].Value = value ?? "";
}
}
......
......@@ -525,5 +525,45 @@ public IEnumerable<dynamic> QueryAttendanceDeptReport(int allotId, string unitTy
throw;
}
}
public IEnumerable<dynamic> QueryAttendanceDeptReportCompute(int allotId, string unitType, string accountingUnit, string personnelNameOrNumber)
{
try
{
using (var connection = new MySqlConnection(_options.Value.PerformanceConnectionString))
{
if (connection.State != ConnectionState.Open) connection.Open();
string sql = $@"select * from view_attendance_dept_compute_report where allotID = @allotId";
DynamicParameters parameters = new DynamicParameters();
parameters.Add("@allotId", allotId);
if (unitType?.Any() == true)
{
sql += " and unitType = @unitType";
parameters.Add("@unitType", unitType);
}
if (!string.IsNullOrEmpty(accountingUnit))
{
sql += " and accountingUnit = @accountingUnit";
parameters.Add("@accountingUnit", accountingUnit);
}
if (!string.IsNullOrEmpty(personnelNameOrNumber))
{
sql += " and (personnelNumber like @personnelNameOrNumber or personnelName like @personnelNameOrNumber)";
parameters.Add("@personnelNameOrNumber", $"%{personnelNameOrNumber}%");
}
return connection.Query(sql, parameters, commandTimeout: 60 * 60);
}
}
catch (Exception ex)
{
_logger.LogError($"SQL执行异常:{ex}");
throw;
}
}
}
}
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