| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Filters;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using dodohold.core;
- namespace molilian.core
- {
- public partial class ChartDataCore
- {
- public class ChartDataItem
- {
- public string name { get; set; } = string.Empty;
- public int value { get; set; } = 0;
- public decimal increases { get; set; } = 0;
- }
- public class ChartDataRes
- {
- public List<ChartDataItem> data { get; set; } = [];
- public List<ChartDataItem> data2 { get; set; } = [];
- public int total { get; set; } = 0;
- }
- public static ChartDataRes GetJdData(string total_key, string accountName, string report_date)
- {
- ChartDataRes result = new();
- total_key = "parse_total";
- if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "jd";
- string cacheKey = $":{total_key}:{accountName}:{report_date}";
- result.total = TkLogCore.GetTotal(cacheKey);
- if (result.total > 0)
- {
- string[] keys = [];
- cacheKey = $":{total_key}:{accountName}:message:{report_date}";
- string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
- var combinedKeys = keys.Union(message_keys).ToList();
- combinedKeys.RemoveAll(item => item == "fail");
- combinedKeys.RemoveAll(item => item == "OK");
- foreach (var keyname in combinedKeys)
- {
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- if (value == 0) continue;
- result.data.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data = result.data.OrderByDescending(item => item.value).ToList();
- cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
- string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
- foreach (var keyname in reason_keys)
- {
- if ("没有优惠券".Equals(keyname)) continue;
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- //if (value < 50) continue;
- result.data2.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
- }
- return result;
- }
- public static ChartDataRes GetTaobaoData(string total_key, string accountName, string report_date)
- {
- ChartDataRes result = new();
- if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "tb";
- string cacheKey = $":{total_key}:{accountName}:{report_date}";
- result.total = TkLogCore.GetTotal(cacheKey);
- if (result.total > 0)
- {
- string[] keys = ["success"];
- cacheKey = $":{total_key}:{accountName}:message:{report_date}";
- string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
- var combinedKeys = keys.Union(message_keys).ToList();
- combinedKeys.RemoveAll(item => item == "fail");
- combinedKeys.RemoveAll(item => item == "OK");
- foreach (var keyname in combinedKeys)
- {
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- if (value == 0) continue;
- result.data.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data = result.data.OrderByDescending(item => item.value).ToList();
- cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
- string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
- foreach (var keyname in reason_keys)
- {
- if ("没有优惠券".Equals(keyname)) continue;
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- //if (value < 50) continue;
- result.data2.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
- }
- return result;
- }
- public static ChartDataRes GetTaobaoCouponData(string total_key, string accountName, string report_date)
- {
- ChartDataRes result = new();
- if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "tb";
- string cacheKey = $":{total_key}:{accountName}:{report_date}";
- result.total = TkLogCore.GetTotal(cacheKey, false);
- if (result.total > 0)
- {
- string[] keys = ["success"];
- cacheKey = $":{total_key}:{accountName}:message:{report_date}";
- string[] message_keys = TkLogCore.GetTotalKeys(cacheKey, false);
- var combinedKeys = keys.Union(message_keys).ToList();
- combinedKeys.RemoveAll(item => item == "fail");
- combinedKeys.RemoveAll(item => item == "OK");
- foreach (var keyname in combinedKeys)
- {
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey, false);
- if (value == 0) continue;
- result.data.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data = result.data.OrderByDescending(item => item.value).ToList();
- cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
- string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey, false);
- foreach (var keyname in reason_keys)
- {
- if ("没有优惠券".Equals(keyname)) continue;
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey, false);
- //if (value < 50) continue;
- result.data2.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
- }
- return result;
- }
- public static ChartDataRes GetToolData(string total_key, string accountName, string report_date)
- {
- ChartDataRes result = new();
- accountName = "tool";
- total_key = "parse_total";
- string cacheKey = $":{total_key}:{accountName}:{report_date}";
- result.total = TkLogCore.GetTotal(cacheKey);
- if (result.total > 0)
- {
- string[] keys = ["bdpan", "wemeet"];
- foreach (var keyname in keys)
- {
- cacheKey = $":{total_key}:{keyname}:{report_date}";
- var total = TkLogCore.GetTotal(cacheKey);
- cacheKey = $":{total_key}:{keyname}:success:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- if (value == 0) continue;
- result.data.Add(new ChartDataItem
- {
- name = $"{keyname}-成功",
- value = value,
- increases = Math.Round((decimal)value / total * 100, 2)
- });
- cacheKey = $":{total_key}:{keyname}:fail:{report_date}";
- value = TkLogCore.GetTotal(cacheKey);
- if (value == 0) continue;
- result.data.Add(new ChartDataItem
- {
- name = $"{keyname}-失败",
- value = value,
- increases = Math.Round((decimal)value / total * 100, 2)
- });
- }
- cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
- string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
- foreach (var keyname in reason_keys)
- {
- cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
- int value = TkLogCore.GetTotal(cacheKey);
- if (value == 0) continue;
- result.data2.Add(new ChartDataItem
- {
- name = keyname,
- value = value,
- increases = Math.Round((decimal)value / result.total * 100, 2)
- });
- }
- result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
- }
- return result;
- }
- //public static void GetTaobaoData(string accountName, string report_date)
- //{
- // if (string.IsNullOrEmpty(accountName)) accountName = "tb";
- // if (total_key == "tool_total")
- // {
- // accountName = "tool";
- // total_key = "parse_total";
- // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
- // double total = TkLogCore.GetTotal(cacheKey);
- // if (total > 0)
- // {
- // string[] keys = ["bdpan", "wemeet"];
- // foreach (var keyname in keys)
- // {
- // cacheKey = $":{total_key}:{keyname}:{_report_date}";
- // total = TkLogCore.GetTotal(cacheKey);
- // cacheKey = $":{total_key}:{keyname}:success:{_report_date}";
- // int value = TkLogCore.GetTotal(cacheKey);
- // if (value == 0) continue;
- // result.Add(new { name = $"{keyname}-成功", value, increases = Math.Round(value / total * 100, 2) });
- // cacheKey = $":{total_key}:{keyname}:fail:{_report_date}";
- // value = TkLogCore.GetTotal(cacheKey);
- // if (value == 0) continue;
- // result.Add(new { name = $"{keyname}-失败", value, increases = Math.Round(value / total * 100, 2) });
- // }
- // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
- // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
- // foreach (var keyname in reason_keys)
- // {
- // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
- // int value = TkLogCore.GetTotal(cacheKey);
- // if (value == 0) continue;
- // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
- // }
- // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
- // }
- // return new APIResult(new { total, data = result, data2 = reason_result });
- // }
- // else
- // {
- // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
- // double total = TkLogCore.GetTotal(cacheKey);
- // if (total > 0)
- // {
- // string[] keys = ["success"];
- // cacheKey = $":{total_key}:{accountName}:message:{_report_date}";
- // string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
- // var combinedKeys = keys.Union(message_keys).ToList();
- // combinedKeys.RemoveAll(item => item == "fail");
- // foreach (var keyname in combinedKeys)
- // {
- // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
- // int value = TkLogCore.GetTotal(cacheKey);
- // if (value == 0) continue;
- // result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
- // }
- // result = result.OrderByDescending(item => item.value).ToList();
- // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
- // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
- // foreach (var keyname in reason_keys)
- // {
- // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
- // int value = TkLogCore.GetTotal(cacheKey);
- // if (value < 50) continue;
- // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
- // }
- // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
- // }
- // return new APIResult(new { total, data = result, data2 = reason_result });
- // }
- //}
- }
- }
|