You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.6 KiB
103 lines
3.6 KiB
1 month ago
|
/*
|
||
|
按天排序的
|
||
|
*/
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Globalization;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.IO;
|
||
|
using System.Text;
|
||
|
using Google.Protobuf.WellKnownTypes;
|
||
|
|
||
|
using Sog;
|
||
|
|
||
|
namespace bill_statistics
|
||
|
{
|
||
|
|
||
|
public static class BillStatistics
|
||
|
{
|
||
|
//细分统计数据
|
||
|
public static List<Hourly_Statistics> m_Hourlydata = new List<Hourly_Statistics>();
|
||
|
|
||
|
public static void AddData(Hourly_Statistics statistics)
|
||
|
{
|
||
|
m_Hourlydata.Add(statistics);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 保存数据至数据库
|
||
|
/// </summary>
|
||
|
/// <param name="statistics_Type"></param>
|
||
|
/// <param name="mySqlDB"></param>
|
||
|
public static void SaveDataToDB(Statistics_type statistics_Type, MySqlDB mySqlDB)
|
||
|
{
|
||
|
var m_HourlyTypedata = m_Hourlydata.FindAll(f => f.type == statistics_Type);
|
||
|
foreach (var d in m_HourlyTypedata)
|
||
|
{
|
||
|
d.minute -= (d.minute % 10);
|
||
|
}
|
||
|
List<Hourly_Statistics> temp_data = new List<Hourly_Statistics>();
|
||
|
|
||
|
StringBuilder strsql = new StringBuilder();
|
||
|
foreach (var h in m_HourlyTypedata)
|
||
|
{
|
||
|
//已添加跳过
|
||
|
var minutedata = temp_data.FindAll(e => e.year == h.year && e.month == h.month && e.day == h.day &&
|
||
|
e.hour == h.hour && e.minute == h.minute);
|
||
|
if (minutedata.Count != 0)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
//汇总统计
|
||
|
var quantity = 0;
|
||
|
switch (statistics_Type)
|
||
|
{
|
||
|
//注册
|
||
|
case Statistics_type.register:
|
||
|
quantity = m_HourlyTypedata.Count(s => s.year == h.year && s.month == h.month && s.day == h.day &&
|
||
|
s.hour == h.hour && s.minute == h.minute);
|
||
|
break;
|
||
|
//充值
|
||
|
case Statistics_type.recharge:
|
||
|
quantity = m_HourlyTypedata.FindAll(s => s.year == h.year && s.month == h.month && s.day == h.day &&
|
||
|
s.hour == h.hour && s.minute == h.minute).Sum(s => s.quantity);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
temp_data.Add(new Hourly_Statistics()
|
||
|
{
|
||
|
year = h.year,
|
||
|
month = h.month,
|
||
|
day = h.day,
|
||
|
hour = h.hour,
|
||
|
minute = h.minute,
|
||
|
type = statistics_Type,
|
||
|
quantity = quantity
|
||
|
});
|
||
|
}
|
||
|
int i = 0;
|
||
|
int sqlnum = 5;
|
||
|
foreach (var t in temp_data)
|
||
|
{
|
||
|
++i;
|
||
|
strsql.AppendLine($"DELETE FROM hourly_statistics WHERE `year` ={t.year} and `month`={t.month} and `day`={t.day} and `hour`={t.hour} and `minute`={t.minute} and `Type`={(int)t.type}; INSERT INTO hourly_statistics (`year`,`month`,`day`,`hour`,`minute`,`Type`,`quantity`) VALUES ({t.year},{t.month},{t.day},{t.hour},{t.minute},{(int)t.type},{t.quantity});");
|
||
|
if (i > sqlnum)
|
||
|
{
|
||
|
Console.WriteLine(strsql.ToString());
|
||
|
mySqlDB.ExecNonQuery(strsql.ToString());
|
||
|
i = 0;
|
||
|
strsql.Clear();
|
||
|
}
|
||
|
}
|
||
|
if (strsql.Length != 0)
|
||
|
{
|
||
|
|
||
|
Console.WriteLine(strsql.ToString());
|
||
|
mySqlDB.ExecNonQuery(strsql.ToString());
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|