基本信息
源码名称:把每天分成12个时间段,每个时间段是两个小时
源码大小:0.85KB
文件格式:.rar
开发语言:C#
更新时间:2024-10-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 10 元×
微信扫码支付:10 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
/// <summary>
/// 按每天12个时间段统计数据
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <param name="codeBoxID"></param>
/// <param name="type"></param>
/// <returns></returns>
[HttpGet]
public async Task<ResponseMsg> TimeSlotTwoHours(int? year, int? month, string? codeBoxID, AlarmType? type)
{
ResponseMsg_data msg = new ResponseMsg_data();
Dictionary<string, string> dic = new Dictionary<string, string>();
List<TimeCount> lists = new List<TimeCount>();
if (year == null || year == 0)
{
year = DateTime.Now.Year;
}
try
{
//按年统计
if (month == 0 || month == null)
{
YearlyTimeSlotStats yearlyStats = new YearlyTimeSlotStats();
var list = await sql.Select<View_FMXModel_Track>()
.Where(t => t.ReportTime.Year == year)
.Where(t => (!string.IsNullOrEmpty(codeBoxID) && codeBoxID != "0") ? t.CodeBoxID == codeBoxID : true)
.Where(t => (type != null) ? t.AlarmType == type : true)
.ToListAsync(t => new { key = t.ReportTime });
foreach (var item in list)
{
yearlyStats.AddCount(item.key, int.Parse(year.GetValueOrDefault().ToString()));
}
dic = yearlyStats.PrintStats();
foreach (var dict in dic)
{
TimeCount tc = new TimeCount();
tc.key = dict.Key;
tc.count = dict.Value;
lists.Add(tc);
}
msg.Code = 200;
msg.Message = "按年统计时间段的数据";
msg.Data = lists;
}
else
{
MonthlyTimeSlotStats monthlyStats = new MonthlyTimeSlotStats();
var list = await sql.Select<View_FMXModel_Track>()
.Where(t => t.ReportTime.Year == year && t.ReportTime.Month == month)
.Where(t => (!string.IsNullOrEmpty(codeBoxID) && codeBoxID != "0") ? t.CodeBoxID == codeBoxID : true)
.Where(t => (type != null) ? t.AlarmType == type : true)
.ToListAsync(t => new { key = t.ReportTime });
foreach (var item in list)
{
monthlyStats.AddCount(item.key);
}
dic = monthlyStats.PrintStats();
foreach (var dict in dic)
{
TimeCount tc = new TimeCount();
tc.key = dict.Key;
tc.count = dict.Value;
lists.Add(tc);
}
msg.Code = 200;
msg.Message = "按年月统计时间段的数据!!!";
msg.Data = lists;
}
}
catch (Exception ex)
{
WriteLog.Log("时间段统计", "TimeSlotTwoHours 按每天12个时间段统计数据 " ex.ToString());
}
return msg;
}
/// <summary>
/// 按每天12个时间段统计数据
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <param name="codeBoxID"></param>
/// <param name="type"></param>
/// <returns></returns>
[HttpGet]
public async Task<ResponseMsg> TimeSlotTwoHours(int? year, int? month, string? codeBoxID, AlarmType? type)
{
ResponseMsg_data msg = new ResponseMsg_data();
Dictionary<string, string> dic = new Dictionary<string, string>();
List<TimeCount> lists = new List<TimeCount>();
if (year == null || year == 0)
{
year = DateTime.Now.Year;
}
try
{
//按年统计
if (month == 0 || month == null)
{
YearlyTimeSlotStats yearlyStats = new YearlyTimeSlotStats();
var list = await sql.Select<View_FMXModel_Track>()
.Where(t => t.ReportTime.Year == year)
.Where(t => (!string.IsNullOrEmpty(codeBoxID) && codeBoxID != "0") ? t.CodeBoxID == codeBoxID : true)
.Where(t => (type != null) ? t.AlarmType == type : true)
.ToListAsync(t => new { key = t.ReportTime });
foreach (var item in list)
{
yearlyStats.AddCount(item.key, int.Parse(year.GetValueOrDefault().ToString()));
}
dic = yearlyStats.PrintStats();
foreach (var dict in dic)
{
TimeCount tc = new TimeCount();
tc.key = dict.Key;
tc.count = dict.Value;
lists.Add(tc);
}
msg.Code = 200;
msg.Message = "按年统计时间段的数据";
msg.Data = lists;
}
else
{
MonthlyTimeSlotStats monthlyStats = new MonthlyTimeSlotStats();
var list = await sql.Select<View_FMXModel_Track>()
.Where(t => t.ReportTime.Year == year && t.ReportTime.Month == month)
.Where(t => (!string.IsNullOrEmpty(codeBoxID) && codeBoxID != "0") ? t.CodeBoxID == codeBoxID : true)
.Where(t => (type != null) ? t.AlarmType == type : true)
.ToListAsync(t => new { key = t.ReportTime });
foreach (var item in list)
{
monthlyStats.AddCount(item.key);
}
dic = monthlyStats.PrintStats();
foreach (var dict in dic)
{
TimeCount tc = new TimeCount();
tc.key = dict.Key;
tc.count = dict.Value;
lists.Add(tc);
}
msg.Code = 200;
msg.Message = "按年月统计时间段的数据!!!";
msg.Data = lists;
}
}
catch (Exception ex)
{
WriteLog.Log("时间段统计", "TimeSlotTwoHours 按每天12个时间段统计数据 " ex.ToString());
}
return msg;
}