|
|
@@ -6,6 +6,7 @@ using System.Net;
|
|
|
using static QRCoder.PayloadGenerator;
|
|
|
using MySqlX.XDevAPI;
|
|
|
using OfficeOpenXml.FormulaParsing.LexicalAnalysis;
|
|
|
+using StackExchange.Redis;
|
|
|
namespace molilian.api.Controllers
|
|
|
{
|
|
|
|
|
|
@@ -321,6 +322,132 @@ namespace molilian.api.Controllers
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ [HttpPost]
|
|
|
+ public ActionResult report_hourlys([FromBody] JsonElement form)
|
|
|
+ {
|
|
|
+ int page = form.Read("current", 1);
|
|
|
+ int size = form.Read("pageSize", 10);
|
|
|
+ bool getTotal = form.Read("getTotal", true);
|
|
|
+ string sort = form.Read<string>("sort");
|
|
|
+ string order = form.Read<string>("order");
|
|
|
+
|
|
|
+ var report_date = form.PathReadArray<string>("query_date[]");
|
|
|
+ var filterHours = form.Read<int?>("filterHours", null);
|
|
|
+ string dailys_accountName = "all";
|
|
|
+ int dailys_accountId = 0;
|
|
|
+
|
|
|
+ string filter = string.Empty;
|
|
|
+ DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
|
|
|
+ if (report_date.Count == 2)
|
|
|
+ {
|
|
|
+ if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
|
|
|
+ {
|
|
|
+ etime = etime.AddDays(1).AddSeconds(-1);
|
|
|
+ filter += $" AND A.report_date BETWEEN @stime AND @etime";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (filterHours != null)
|
|
|
+ {
|
|
|
+ filterHours--;
|
|
|
+ filter += $" AND HOUR(report_date) = @filterHours";
|
|
|
+ }
|
|
|
+
|
|
|
+ filter = filter.StringTrimStart(" AND ");
|
|
|
+
|
|
|
+ //排序
|
|
|
+ string orderBy = "A.report_date DESC";
|
|
|
+ if (!string.IsNullOrEmpty(order))
|
|
|
+ {
|
|
|
+ order = "descending".Equals(order) ? "DESC" : "ASC";
|
|
|
+ orderBy = sort switch
|
|
|
+ {
|
|
|
+ _ => $"A.{sort} {order}",
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ var result = new DBContext.Table("v_tk_report_hourlys")
|
|
|
+ .LeftJoin("daily_logs",
|
|
|
+ "B.log_date = A.report_date AND B.channel=0 AND B.accountId=@dailys_accountId",
|
|
|
+ "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage," +
|
|
|
+ "B.parse_total_count, B.parse_abandon_count, B.parse_success_count, B.parse_abandon_percentage, B.parse_success_percentage," +
|
|
|
+ "B.coupon_total_count, B.coupon_abandon_count, B.coupon_success_count, B.coupon_abandon_percentage, B.coupon_success_percentage," +
|
|
|
+ "B.tool_total_count, B.tool_abandon_count, B.tool_success_count, B.tool_abandon_percentage, B.tool_success_percentage")
|
|
|
+ .Where(filter, new { dailys_accountId, dailys_accountName, filterHours, stime, etime })
|
|
|
+ .Page(size, page)
|
|
|
+ .Order(orderBy)
|
|
|
+ .PageList<TkReportDTO>(getTotal);
|
|
|
+
|
|
|
+ foreach (var item in result.List)
|
|
|
+ {
|
|
|
+ if (item.total_count == 0)
|
|
|
+ {
|
|
|
+ item.total_count = TkLogCore.GetTotal($":total:tb:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.total_count > 0)
|
|
|
+ {
|
|
|
+ item.success_count = TkLogCore.GetTotal($":total:tb:success:{item.report_date:yyyyMMddHH}");
|
|
|
+ item.abandon_count = TkLogCore.GetTotal($":total:tb:放弃转链:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.total_count > 0)
|
|
|
+ {
|
|
|
+ item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
|
|
|
+ item.abandon_percentage = $"{item.abandon_count / (double)item.total_count * 100:f2}%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.parse_total_count == 0)
|
|
|
+ {
|
|
|
+ item.parse_total_count = TkLogCore.GetTotal($":parse_total:tb:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.parse_total_count > 0)
|
|
|
+ {
|
|
|
+ item.parse_success_count = TkLogCore.GetTotal($":parse_total:tb:success:{item.report_date:yyyyMMddHH}");
|
|
|
+ item.parse_abandon_count = TkLogCore.GetTotal($":parse_total:tb:放弃转链:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.parse_total_count > 0)
|
|
|
+ {
|
|
|
+ item.parse_success_percentage = $"{item.parse_success_count / (double)item.parse_total_count * 100:f2}%";
|
|
|
+ item.parse_abandon_percentage = $"{item.parse_abandon_count / (double)item.parse_total_count * 100:f2}%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.coupon_total_count == 0)
|
|
|
+ {
|
|
|
+ item.coupon_total_count = TkLogCore.GetTotal($":coupon_total:tb:{item.report_date:yyyyMMddHH}", false);
|
|
|
+ if (item.coupon_total_count > 0)
|
|
|
+ {
|
|
|
+ item.coupon_success_count = TkLogCore.GetTotal($":coupon_total:tb:success:{item.report_date:yyyyMMddHH}", false);
|
|
|
+ item.coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:tb:放弃转链:{item.report_date:yyyyMMddHH}", false);
|
|
|
+ if (item.coupon_total_count > 0)
|
|
|
+ {
|
|
|
+ item.coupon_success_percentage = $"{item.coupon_success_count / (double)item.coupon_total_count * 100:f2}%";
|
|
|
+ item.coupon_abandon_percentage = $"{item.coupon_abandon_count / (double)item.coupon_total_count * 100:f2}%";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.tool_total_count == 0)
|
|
|
+ {
|
|
|
+ item.tool_total_count = TkLogCore.GetTotal($":parse_total:tool:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.tool_total_count > 0)
|
|
|
+ {
|
|
|
+ item.tool_success_count = TkLogCore.GetTotal($":parse_total:tool:success:{item.report_date:yyyyMMddHH}");
|
|
|
+ item.tool_abandon_count = TkLogCore.GetTotal($":parse_total:tool:放弃转链:{item.report_date:yyyyMMddHH}");
|
|
|
+ if (item.tool_total_count > 0)
|
|
|
+ {
|
|
|
+ item.tool_success_percentage = $"{item.tool_success_count / (double)item.tool_total_count * 100:f2}%";
|
|
|
+ item.tool_abandon_percentage = $"{item.tool_abandon_count / (double)item.tool_total_count * 100:f2}%";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new APIResult(new
|
|
|
+ {
|
|
|
+ data = result
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
[HttpPost]
|
|
|
public ActionResult report_list([FromBody] JsonElement form)
|
|
|
{
|
|
|
@@ -457,11 +584,18 @@ namespace molilian.api.Controllers
|
|
|
bool getTotal = form.Read("getTotal", true);
|
|
|
string sort = form.Read<string>("sort");
|
|
|
string order = form.Read<string>("order");
|
|
|
+ var filterHours = form.Read<int?>("filterHours", null);
|
|
|
+ string accountName = form.Read<string>("accountName");
|
|
|
|
|
|
var report_date = form.PathReadArray<string>("query_date[]");
|
|
|
int accountId = form.Read("accountId", 0);
|
|
|
|
|
|
string filter = string.Empty;
|
|
|
+ if (!string.IsNullOrEmpty(accountName))
|
|
|
+ {
|
|
|
+ filter += $" AND accountName=@accountName";
|
|
|
+ }
|
|
|
+
|
|
|
if (accountId != 0)
|
|
|
{
|
|
|
filter += $" AND accountId=@accountId";
|
|
|
@@ -477,6 +611,11 @@ namespace molilian.api.Controllers
|
|
|
filter += $" AND report_date BETWEEN @stime AND @etime";
|
|
|
}
|
|
|
}
|
|
|
+ if (filterHours != null)
|
|
|
+ {
|
|
|
+ filterHours--;
|
|
|
+ filter += $" AND HOUR(report_date) = @filterHours";
|
|
|
+ }
|
|
|
|
|
|
filter = filter.StringTrimStart(" AND ");
|
|
|
|
|
|
@@ -493,7 +632,8 @@ namespace molilian.api.Controllers
|
|
|
|
|
|
using var conn = DBContext.GetOpenConnection();
|
|
|
var result = new DBContext.Table(conn, "tk_report_hourtrend")
|
|
|
- .Where(filter, new { accountId, stime, etime })
|
|
|
+
|
|
|
+ .Where(filter, new { accountId, stime, etime, accountName, filterHours })
|
|
|
.Page(size, page)
|
|
|
.Order(orderBy)
|
|
|
.PageList<TkReportDTO>(getTotal);
|
|
|
@@ -505,7 +645,7 @@ namespace molilian.api.Controllers
|
|
|
#else
|
|
|
if (item.report_date.Date < DateTime.Now.Date) continue;
|
|
|
#endif
|
|
|
- string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
|
|
|
+ accountName = $"{TkChannelEnum.tb}_{item.accountId}";
|
|
|
if (item.total_count == 0)
|
|
|
{
|
|
|
item.total_count = TkLogCore.GetTotal($":total:{accountName}:{item.report_date:yyyyMMddHH}");
|