|
|
|
@ -1280,12 +1280,83 @@ namespace LanShengService
|
|
|
|
|
var TempUnits = new string[] { "year", "month", "day" };
|
|
|
|
|
if (!string.IsNullOrEmpty(report.Unit) && !TempUnits.Any(x => x == report.Unit.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("单元无效");
|
|
|
|
|
throw new BadRequestException("单元无效");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var TempQuery = Db.Queryable<DeviceError>()
|
|
|
|
|
.WhereIF(report.ErrCodes != null, x => report.ErrCodes!.Any(q => q == x.ErrCode))
|
|
|
|
|
.WhereIF(report.DeviceIds != null, x => report.DeviceIds!.Any(q => q == x.DeviceId))
|
|
|
|
|
.Where(x => x.CreateDate >= report.StartDate && x.CreateDate <= report.EndDate);
|
|
|
|
|
DateTime TempStart = (DateTime)report.StartDate!;
|
|
|
|
|
DateTime TempEnd = (DateTime)report.EndDate!;
|
|
|
|
|
if (string.IsNullOrEmpty(report.Unit))
|
|
|
|
|
{
|
|
|
|
|
report.Items = await TempQuery
|
|
|
|
|
.GroupBy(x => new { x.ErrCode, x.ErrMsg })
|
|
|
|
|
.Select(x => new DeviceError
|
|
|
|
|
{
|
|
|
|
|
ErrCode = x.ErrCode,
|
|
|
|
|
ErrMsg = x.ErrMsg,
|
|
|
|
|
Count = SqlFunc.AggregateCount(x.ErrCode)
|
|
|
|
|
})
|
|
|
|
|
.SplitTable(TempStart, TempEnd)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (report.Unit.ToLower() == "year")
|
|
|
|
|
{
|
|
|
|
|
var TempYears = TempEnd.Year - TempStart.Year + 1;
|
|
|
|
|
var TempYearArray = Enumerable.Range(0, TempYears).Select(x => Convert.ToDateTime(TempStart.AddYears(x).ToString("yyyy-MM-dd"))).ToList();
|
|
|
|
|
var TempQueryYear = Db.Reportable(TempYearArray).ToQueryable<DateTime>();
|
|
|
|
|
report.Items = TempQueryYear
|
|
|
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy") == ((DateTime)y.CreateDate!).ToString("yyyy"))
|
|
|
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
|
|
|
.Select((x, y) => new DeviceError
|
|
|
|
|
{
|
|
|
|
|
ErrCode = y.ErrCode,
|
|
|
|
|
ErrMsg = y.ErrMsg,
|
|
|
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
|
|
|
Id = x.ColumnName.ToString("yyyy"),
|
|
|
|
|
CreateDate = x.ColumnName
|
|
|
|
|
})
|
|
|
|
|
.ToList().OrderBy(x => x.Id);
|
|
|
|
|
}
|
|
|
|
|
else if (report.Unit.ToLower() == "month")
|
|
|
|
|
{
|
|
|
|
|
var TempMonths = (TempEnd.Year - TempStart.Year) * 12 + (TempEnd.Month - TempStart.Month + 1);
|
|
|
|
|
var TempMonthArray = Enumerable.Range(0, TempMonths).Select(x => Convert.ToDateTime(TempStart.AddMonths(x).ToString("yyyy-MM-dd"))).ToList();
|
|
|
|
|
var TempQueryMonth = Db.Reportable(TempMonthArray).ToQueryable<DateTime>();
|
|
|
|
|
report.Items = TempQueryMonth
|
|
|
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy-MM") == ((DateTime)y.CreateDate!).ToString("yyyy-MM"))
|
|
|
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
|
|
|
.Select((x, y) => new DeviceError
|
|
|
|
|
{
|
|
|
|
|
ErrCode = y.ErrCode,
|
|
|
|
|
ErrMsg = y.ErrMsg,
|
|
|
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
|
|
|
Id = x.ColumnName.ToString("yyyy-MM"),
|
|
|
|
|
CreateDate = x.ColumnName
|
|
|
|
|
})
|
|
|
|
|
.ToList().OrderBy(x => x.Id);
|
|
|
|
|
}
|
|
|
|
|
else if (report.Unit.ToLower() == "day")
|
|
|
|
|
{
|
|
|
|
|
var TempDays = (TempEnd - TempStart).TotalDays.ToInt();
|
|
|
|
|
var TempDayArray = Enumerable.Range(0, TempDays).Select(x => Convert.ToDateTime(TempStart.AddDays(x).ToString("yyyy-MM-dd"))).ToList();
|
|
|
|
|
var TempQueryDay = Db.Reportable(TempDayArray).ToQueryable<DateTime>();
|
|
|
|
|
report.Items = TempQueryDay
|
|
|
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy-MM-dd") == ((DateTime)y.CreateDate!).ToString("yyyy-MM-dd"))
|
|
|
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
|
|
|
.Select((x, y) => new DeviceError
|
|
|
|
|
{
|
|
|
|
|
ErrCode = y.ErrCode,
|
|
|
|
|
ErrMsg = y.ErrMsg,
|
|
|
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
|
|
|
Id = x.ColumnName.ToString("yyyy-MM-dd"),
|
|
|
|
|
CreateDate = x.ColumnName
|
|
|
|
|
})
|
|
|
|
|
.ToList().OrderBy(x => x.Id);
|
|
|
|
|
}
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|