TaskController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. namespace molilian.api.Controllers
  9. {
  10. [ApiController]
  11. [Route("[controller]_70160bd632/[action]")]
  12. public class TaskController : ControllerBase
  13. {
  14. protected IHttpContextAccessor _accessor;
  15. public TaskController(IHttpContextAccessor accessor)
  16. {
  17. _accessor = accessor;
  18. }
  19. [HttpGet]
  20. public ActionResult BatchInsertLogDB(int limit = 100)
  21. {
  22. int total = TkLogCore.BatchInsertLogDB(limit);
  23. return new APIResult(new { success = true, message = "ok", limit, total });
  24. }
  25. [HttpGet]
  26. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  27. {
  28. var list = TkPoolCore.List();
  29. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  30. string message = string.Empty;
  31. int total = 0;
  32. foreach (var account in list)
  33. {
  34. #if DEBUG
  35. if (13 != account.id) continue;
  36. #endif
  37. try
  38. {
  39. var alimama = new AlimamaPlus(account);
  40. total += alimama.GetSettleBills(sleep);
  41. }
  42. catch (Exception ex)
  43. {
  44. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  45. NotifyCore.Notify(new NifyMessage
  46. {
  47. message = message,
  48. priority = NifyMessagePriority.high,
  49. tags = ["red_circle"]
  50. });
  51. continue;
  52. }
  53. }
  54. return new APIResult(new { success = true, message = "ok", total });
  55. }
  56. [HttpGet]
  57. public async Task<ActionResult> GetHistoryOrders(int id, int sleep = 2000)
  58. {
  59. var list = TkPoolCore.List();
  60. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  61. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  62. string message = string.Empty;
  63. int total = 0;
  64. foreach (var account in list)
  65. {
  66. if (id != account.id) continue;
  67. try
  68. {
  69. var alimama = new AlimamaPlus(account);
  70. total += alimama.GetHistoryOrders(sleep);
  71. }
  72. catch (Exception ex)
  73. {
  74. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  75. NotifyCore.Notify(new NifyMessage
  76. {
  77. message = message,
  78. priority = NifyMessagePriority.high,
  79. tags = ["red_circle"]
  80. });
  81. continue;
  82. }
  83. }
  84. return new APIResult(new { success = true, message = "ok", total });
  85. }
  86. [HttpGet]
  87. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  88. {
  89. var list = TkPoolCore.List();
  90. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  91. string message = string.Empty;
  92. int total = 0;
  93. foreach (var account in list)
  94. {
  95. #if DEBUG
  96. if (account.id != 17) continue;
  97. #endif
  98. try
  99. {
  100. var alimama = new AlimamaPlus(account);
  101. total += alimama.GetIncyOrders(sleep);
  102. }
  103. catch (Exception ex)
  104. {
  105. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  106. NotifyCore.Notify(new NifyMessage
  107. {
  108. message = message,
  109. priority = NifyMessagePriority.high,
  110. tags = ["red_circle"]
  111. });
  112. continue;
  113. }
  114. }
  115. return new APIResult(new { success = true, message = "ok", total });
  116. }
  117. [HttpGet]
  118. public async Task<ActionResult> GetViolationuWarning()
  119. {
  120. var list = TkPoolCore.List();
  121. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  122. string message = string.Empty;
  123. foreach (var account in list)
  124. {
  125. try
  126. {
  127. var alimama = new AlimamaPlus(account);
  128. alimama.GetViolationuWarning();
  129. }
  130. catch (Exception ex)
  131. {
  132. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  133. NotifyCore.Notify(new NifyMessage
  134. {
  135. message = message,
  136. priority = NifyMessagePriority.high,
  137. tags = ["red_circle"]
  138. });
  139. continue;
  140. }
  141. }
  142. return new APIResult(new { success = true, message = "ok" });
  143. }
  144. [HttpGet]
  145. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  146. {
  147. try
  148. {
  149. AlimamaPlus.DailyLogs(intervalDay);
  150. }
  151. catch (Exception ex)
  152. {
  153. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  154. NotifyCore.Notify(new NifyMessage
  155. {
  156. message = message,
  157. priority = NifyMessagePriority.high,
  158. tags = ["red_circle"]
  159. });
  160. }
  161. return new APIResult(new { success = true, message = "ok" });
  162. }
  163. [HttpGet]
  164. public async Task<ActionResult> GetDrawBalance()
  165. {
  166. var list = TkPoolCore.List();
  167. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  168. string message = string.Empty;
  169. foreach (var account in list)
  170. {
  171. try
  172. {
  173. var alimama = new AlimamaPlus(account);
  174. alimama.GetDrawBalance();
  175. }
  176. catch (Exception ex)
  177. {
  178. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  179. NotifyCore.Notify(new NifyMessage
  180. {
  181. message = message,
  182. priority = NifyMessagePriority.high,
  183. tags = ["red_circle"]
  184. });
  185. continue;
  186. }
  187. }
  188. return new APIResult(new { success = true, message = "ok" });
  189. }
  190. [HttpGet]
  191. public ActionResult FastReport()
  192. {
  193. var list = TkPoolCore.List();
  194. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  195. string message = string.Empty;
  196. foreach (var account in list)
  197. {
  198. #if DEBUG
  199. if (account.id != 5) continue;
  200. #endif
  201. try
  202. {
  203. var alimama = new AlimamaPlus(account);
  204. alimama.SaveReportOverview();
  205. }
  206. catch (Exception ex)
  207. {
  208. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  209. NotifyCore.Notify(new NifyMessage
  210. {
  211. message = message,
  212. priority = NifyMessagePriority.high,
  213. tags = ["red_circle"]
  214. });
  215. continue;
  216. }
  217. }
  218. return new APIResult(new { success = true, message = "ok" });
  219. }
  220. [HttpGet]
  221. public async Task<ActionResult> SaveReport()
  222. {
  223. var list = TkPoolCore.List();
  224. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  225. string message = string.Empty;
  226. foreach (var account in list)
  227. {
  228. #if DEBUG
  229. if (account.id != 5) continue;
  230. #endif
  231. try
  232. {
  233. var alimama = new AlimamaPlus(account);
  234. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  235. alimama.SaveReportHourtrend(DateTime.Now);
  236. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  237. {
  238. DateTime date = DateTime.Now.AddDays(-1);
  239. alimama.FixReport(date);
  240. }
  241. }
  242. catch (Exception ex)
  243. {
  244. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  245. NotifyCore.Notify(new NifyMessage
  246. {
  247. message = message,
  248. priority = NifyMessagePriority.high,
  249. tags = ["red_circle"]
  250. });
  251. continue;
  252. }
  253. }
  254. return new APIResult(new { success = true, message = "ok" });
  255. }
  256. [HttpGet]
  257. public async Task<ActionResult> FixReport(string dt)
  258. {
  259. if (!DateTime.TryParse(dt, out DateTime date))
  260. {
  261. return new APIResult(new { success = false, message = "日期错误", });
  262. }
  263. var list = TkPoolCore.List();
  264. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  265. string message = string.Empty;
  266. foreach (var account in list)
  267. {
  268. #if DEBUG
  269. if (account.id != 5) continue;
  270. #endif
  271. try
  272. {
  273. var alimama = new AlimamaPlus(account);
  274. while (date.Date < DateTime.Now.Date)
  275. {
  276. alimama.FixReport(date);
  277. date = date.AddDays(1);
  278. }
  279. }
  280. catch (Exception ex)
  281. {
  282. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  283. NotifyCore.Notify(new NifyMessage
  284. {
  285. message = message,
  286. priority = NifyMessagePriority.high,
  287. tags = ["red_circle"]
  288. });
  289. continue;
  290. }
  291. }
  292. return new APIResult(new { success = true, message = "ok" });
  293. }
  294. [HttpGet]
  295. public ActionResult RenewCookie(string name)
  296. {
  297. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  298. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  299. var alimama = new AlimamaPlus(account);
  300. (bool success, string message) = alimama.RenewCookie();
  301. return new APIResult(new { success, message });
  302. }
  303. }
  304. }