ChartDataCore.cs 14 KB

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