ChartDataCore.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 GetToolData(string total_key, string accountName, string report_date)
  116. {
  117. ChartDataRes result = new();
  118. accountName = "tool";
  119. total_key = "parse_total";
  120. string cacheKey = $":{total_key}:{accountName}:{report_date}";
  121. result.total = TkLogCore.GetTotal(cacheKey);
  122. if (result.total > 0)
  123. {
  124. string[] keys = ["bdpan", "wemeet"];
  125. foreach (var keyname in keys)
  126. {
  127. cacheKey = $":{total_key}:{keyname}:{report_date}";
  128. var total = TkLogCore.GetTotal(cacheKey);
  129. cacheKey = $":{total_key}:{keyname}:success:{report_date}";
  130. int value = TkLogCore.GetTotal(cacheKey);
  131. if (value == 0) continue;
  132. result.data.Add(new ChartDataItem
  133. {
  134. name = $"{keyname}-成功",
  135. value = value,
  136. increases = Math.Round((decimal)value / total * 100, 2)
  137. });
  138. cacheKey = $":{total_key}:{keyname}:fail:{report_date}";
  139. value = TkLogCore.GetTotal(cacheKey);
  140. if (value == 0) continue;
  141. result.data.Add(new ChartDataItem
  142. {
  143. name = $"{keyname}-失败",
  144. value = value,
  145. increases = Math.Round((decimal)value / total * 100, 2)
  146. });
  147. }
  148. cacheKey = $":{total_key}:{accountName}:reason:{report_date}";
  149. string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  150. foreach (var keyname in reason_keys)
  151. {
  152. cacheKey = $":{total_key}:{accountName}:{keyname}:{report_date}";
  153. int value = TkLogCore.GetTotal(cacheKey);
  154. if (value == 0) continue;
  155. result.data2.Add(new ChartDataItem
  156. {
  157. name = keyname,
  158. value = value,
  159. increases = Math.Round((decimal)value / result.total * 100, 2)
  160. });
  161. }
  162. result.data2 = result.data2.OrderByDescending(item => item.value).ToList();
  163. }
  164. return result;
  165. }
  166. //public static void GetTaobaoData(string accountName, string report_date)
  167. //{
  168. // if (string.IsNullOrEmpty(accountName)) accountName = "tb";
  169. // if (total_key == "tool_total")
  170. // {
  171. // accountName = "tool";
  172. // total_key = "parse_total";
  173. // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  174. // double total = TkLogCore.GetTotal(cacheKey);
  175. // if (total > 0)
  176. // {
  177. // string[] keys = ["bdpan", "wemeet"];
  178. // foreach (var keyname in keys)
  179. // {
  180. // cacheKey = $":{total_key}:{keyname}:{_report_date}";
  181. // total = TkLogCore.GetTotal(cacheKey);
  182. // cacheKey = $":{total_key}:{keyname}:success:{_report_date}";
  183. // int value = TkLogCore.GetTotal(cacheKey);
  184. // if (value == 0) continue;
  185. // result.Add(new { name = $"{keyname}-成功", value, increases = Math.Round(value / total * 100, 2) });
  186. // cacheKey = $":{total_key}:{keyname}:fail:{_report_date}";
  187. // value = TkLogCore.GetTotal(cacheKey);
  188. // if (value == 0) continue;
  189. // result.Add(new { name = $"{keyname}-失败", value, increases = Math.Round(value / total * 100, 2) });
  190. // }
  191. // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  192. // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  193. // foreach (var keyname in reason_keys)
  194. // {
  195. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  196. // int value = TkLogCore.GetTotal(cacheKey);
  197. // if (value == 0) continue;
  198. // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  199. // }
  200. // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  201. // }
  202. // return new APIResult(new { total, data = result, data2 = reason_result });
  203. // }
  204. // else
  205. // {
  206. // string cacheKey = $":{total_key}:{accountName}:{_report_date}";
  207. // double total = TkLogCore.GetTotal(cacheKey);
  208. // if (total > 0)
  209. // {
  210. // string[] keys = ["success"];
  211. // cacheKey = $":{total_key}:{accountName}:message:{_report_date}";
  212. // string[] message_keys = TkLogCore.GetTotalKeys(cacheKey);
  213. // var combinedKeys = keys.Union(message_keys).ToList();
  214. // combinedKeys.RemoveAll(item => item == "fail");
  215. // foreach (var keyname in combinedKeys)
  216. // {
  217. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  218. // int value = TkLogCore.GetTotal(cacheKey);
  219. // if (value == 0) continue;
  220. // result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  221. // }
  222. // result = result.OrderByDescending(item => item.value).ToList();
  223. // cacheKey = $":{total_key}:{accountName}:reason:{_report_date}";
  224. // string[] reason_keys = TkLogCore.GetTotalKeys(cacheKey);
  225. // foreach (var keyname in reason_keys)
  226. // {
  227. // cacheKey = $":{total_key}:{accountName}:{keyname}:{_report_date}";
  228. // int value = TkLogCore.GetTotal(cacheKey);
  229. // if (value < 50) continue;
  230. // reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
  231. // }
  232. // reason_result = reason_result.OrderByDescending(item => item.value).ToList();
  233. // }
  234. // return new APIResult(new { total, data = result, data2 = reason_result });
  235. // }
  236. //}
  237. }
  238. }