ChartDataCore.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. namespace molilian.core
  10. {
  11. public partial class ChartDataCore
  12. {
  13. public class ChartDataItem
  14. {
  15. public string name { get; set; } = string.Empty;
  16. public int value { get; set; } = 0;
  17. public decimal increases { get; set; } = 0;
  18. }
  19. public class ChartDataRes
  20. {
  21. public List<ChartDataItem> data { get; set; } = [];
  22. public List<ChartDataItem> data2 { get; set; } = [];
  23. public int total { get; set; } = 0;
  24. }
  25. public static ChartDataRes GetJdData(string total_key, string accountName, string report_date)
  26. {
  27. ChartDataRes result = new();
  28. total_key = "parse_total";
  29. if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "jd";
  30. string cacheKey = $":{total_key}:{accountName}:{report_date}";
  31. result.total = TkLogCore.GetTotal(cacheKey);
  32. if (result.total > 0)
  33. {
  34. string[] keys = [];
  35. cacheKey = $":{total_key}:{accountName}:message:{report_date}";
  36. string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  37. var combinedKeys = keys.Union(message_keys).ToList();
  38. combinedKeys.RemoveAll(item => item == "fail");
  39. foreach (var keyname in combinedKeys)
  40. {
  41. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  42. int value = TkLogCore.GetTotal(cacheKey);
  43. if (value == 0) continue;
  44. result.data.Add(new ChartDataItem
  45. {
  46. name = keyname,
  47. value = value,
  48. increases = Math.Round((decimal)value / result.total * 100, 2)
  49. });
  50. }
  51. result.data = result.data.OrderByDescending(item => item.value).ToList();
  52. cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
  53. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  54. foreach (var keyname in reason_keys)
  55. {
  56. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  57. int value = TkLogCore.GetTotal(cacheKey);
  58. if (value < 50) continue;
  59. result.data2.Add(new ChartDataItem
  60. {
  61. name = keyname,
  62. value = value,
  63. increases = Math.Round((decimal)value / result.total * 100, 2)
  64. });
  65. }
  66. result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
  67. }
  68. return result;
  69. }
  70. public static ChartDataRes GetTaobaoData(string total_key, string accountName, string report_date)
  71. {
  72. ChartDataRes result = new();
  73. if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "tb";
  74. string cacheKey = $":{total_key}:{accountName}:{report_date}";
  75. result.total = TkLogCore.GetTotal(cacheKey);
  76. if (result.total > 0)
  77. {
  78. string[] keys = ["success"];
  79. cacheKey = $":{total_key}:{accountName}:message:{report_date}";
  80. string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  81. var combinedKeys = keys.Union(message_keys).ToList();
  82. combinedKeys.RemoveAll(item => item == "fail");
  83. combinedKeys.RemoveAll(item => item == "OK");
  84. foreach (var keyname in combinedKeys)
  85. {
  86. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  87. int value = TkLogCore.GetTotal(cacheKey);
  88. if (value == 0) continue;
  89. result.data.Add(new ChartDataItem
  90. {
  91. name = keyname,
  92. value = value,
  93. increases = Math.Round((decimal)value / result.total * 100, 2)
  94. });
  95. }
  96. result.data = result.data.OrderByDescending(item => item.value).ToList();
  97. cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
  98. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  99. foreach (var keyname in reason_keys)
  100. {
  101. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  102. int value = TkLogCore.GetTotal(cacheKey);
  103. //if (value < 50) continue;
  104. result.data2.Add(new ChartDataItem
  105. {
  106. name = keyname,
  107. value = value,
  108. increases = Math.Round((decimal)value / result.total * 100, 2)
  109. });
  110. }
  111. result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
  112. }
  113. return result;
  114. }
  115. public static ChartDataRes GetTaobaoCouponData(string total_key, string accountName, string report_date)
  116. {
  117. ChartDataRes result = new();
  118. if (string.IsNullOrEmpty(accountName) || "all".Equals(accountName)) accountName = "tb";
  119. string cacheKey = $":{total_key}:{accountName}:{report_date}";
  120. result.total = TkLogCore.GetTotal(cacheKey, false);
  121. if (result.total > 0)
  122. {
  123. string[] keys = ["success"];
  124. cacheKey = $":{total_key}:{accountName}:message:{report_date}";
  125. string[] message_keys = TkLogCore.GetTotalKeys(cacheKey, false);
  126. var combinedKeys = keys.Union(message_keys).ToList();
  127. combinedKeys.RemoveAll(item => item == "fail");
  128. combinedKeys.RemoveAll(item => item == "OK");
  129. foreach (var keyname in combinedKeys)
  130. {
  131. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  132. int value = TkLogCore.GetTotal(cacheKey, false);
  133. if (value == 0) continue;
  134. result.data.Add(new ChartDataItem
  135. {
  136. name = keyname,
  137. value = value,
  138. increases = Math.Round((decimal)value / result.total * 100, 2)
  139. });
  140. }
  141. result.data = result.data.OrderByDescending(item => item.value).ToList();
  142. cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
  143. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey, false);
  144. foreach (var keyname in reason_keys)
  145. {
  146. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  147. int value = TkLogCore.GetTotal(cacheKey, false);
  148. if (value < 50) continue;
  149. result.data2.Add(new ChartDataItem
  150. {
  151. name = keyname,
  152. value = value,
  153. increases = Math.Round((decimal)value / result.total * 100, 2)
  154. });
  155. }
  156. result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
  157. }
  158. return result;
  159. }
  160. public static ChartDataRes GetToolData(string total_key, string accountName, string report_date)
  161. {
  162. ChartDataRes result = new();
  163. accountName = "tool";
  164. total_key = "parse_total";
  165. string cacheKey = $":{total_key}:{accountName}:{report_date}";
  166. result.total = TkLogCore.GetTotal(cacheKey);
  167. if (result.total > 0)
  168. {
  169. string[] keys = ["bdpan", "wemeet"];
  170. foreach (var keyname in keys)
  171. {
  172. cacheKey = $":{total_key}:{keyname}:{report_date}";
  173. var total = TkLogCore.GetTotal(cacheKey);
  174. cacheKey = $":{total_key}:{keyname}:success:{report_date}";
  175. int value = TkLogCore.GetTotal(cacheKey);
  176. if (value == 0) continue;
  177. result.data.Add(new ChartDataItem
  178. {
  179. name = $"{keyname}-成功",
  180. value = value,
  181. increases = Math.Round((decimal)value / total * 100, 2)
  182. });
  183. cacheKey = $":{total_key}:{keyname}:fail:{report_date}";
  184. value = TkLogCore.GetTotal(cacheKey);
  185. if (value == 0) continue;
  186. result.data.Add(new ChartDataItem
  187. {
  188. name = $"{keyname}-失败",
  189. value = value,
  190. increases = Math.Round((decimal)value / total * 100, 2)
  191. });
  192. }
  193. cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
  194. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  195. foreach (var keyname in reason_keys)
  196. {
  197. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  198. int value = TkLogCore.GetTotal(cacheKey);
  199. if (value == 0) continue;
  200. result.data2.Add(new ChartDataItem
  201. {
  202. name = keyname,
  203. value = value,
  204. increases = Math.Round((decimal)value / result.total * 100, 2)
  205. });
  206. }
  207. result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
  208. }
  209. return result;
  210. }
  211. //public static void GetTaobaoData(string accountName, string report_date)
  212. //{
  213. // if (string.IsNullOrEmpty(accountName)) accountName = "tb";
  214. // if (total_key == "tool_total")
  215. // {
  216. // accountName = "tool";
  217. // total_key = "parse_total";
  218. // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  219. // double total = TkLogCore.GetTotal(cacheKey);
  220. // if (total > 0)
  221. // {
  222. // string[] keys = ["bdpan", "wemeet"];
  223. // foreach (var keyname in keys)
  224. // {
  225. // cacheKey = $":{total_key}:{keyname}:{_report_date}";
  226. // total = TkLogCore.GetTotal(cacheKey);
  227. // cacheKey = $":{total_key}:{keyname}:success:{_report_date}";
  228. // int value = TkLogCore.GetTotal(cacheKey);
  229. // if (value == 0) continue;
  230. // result.Add(new { name = $"{keyname}-成功", value, increases = Math.Round(value / total * 100, 2) });
  231. // cacheKey = $":{total_key}:{keyname}:fail:{_report_date}";
  232. // value = TkLogCore.GetTotal(cacheKey);
  233. // if (value == 0) continue;
  234. // result.Add(new { name = $"{keyname}-失败", value, increases = Math.Round(value / total * 100, 2) });
  235. // }
  236. // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  237. // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  238. // foreach (var keyname in reason_keys)
  239. // {
  240. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  241. // int value = TkLogCore.GetTotal(cacheKey);
  242. // if (value == 0) continue;
  243. // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  244. // }
  245. // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  246. // }
  247. // return new APIResult(new { total, data = result, data2 = reason_result });
  248. // }
  249. // else
  250. // {
  251. // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  252. // double total = TkLogCore.GetTotal(cacheKey);
  253. // if (total > 0)
  254. // {
  255. // string[] keys = ["success"];
  256. // cacheKey = $":{total_key}:{accountName}:message:{_report_date}";
  257. // string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  258. // var combinedKeys = keys.Union(message_keys).ToList();
  259. // combinedKeys.RemoveAll(item => item == "fail");
  260. // foreach (var keyname in combinedKeys)
  261. // {
  262. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  263. // int value = TkLogCore.GetTotal(cacheKey);
  264. // if (value == 0) continue;
  265. // result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  266. // }
  267. // result = result.OrderByDescending(item => item.value).ToList();
  268. // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  269. // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  270. // foreach (var keyname in reason_keys)
  271. // {
  272. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  273. // int value = TkLogCore.GetTotal(cacheKey);
  274. // if (value < 50) continue;
  275. // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  276. // }
  277. // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  278. // }
  279. // return new APIResult(new { total, data = result, data2 = reason_result });
  280. // }
  281. //}
  282. }
  283. }