autoTask.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/robfig/cron/v3"
  6. log "github.com/sirupsen/logrus"
  7. "time"
  8. "youngee_b_api/app/service"
  9. "youngee_b_api/db"
  10. "youngee_b_api/model/gorm_model"
  11. )
  12. func AutoTask() error {
  13. c := cron.New(cron.WithSeconds())
  14. //spec := "0 */30 * * * ?" //cron表达式,每半小时执行一次
  15. //spec := "0 */2 * * * ?" //cron表达式,每1分钟一次
  16. //spec := "*/10 * * * * ?" //cron表达式,每10秒一次
  17. spec := "0 0 8,20 * * ?" // 每天8:00和20:00各执行一次
  18. /*
  19. _, err1 := c.AddFunc(spec, AutoTaskUpdateStatus)
  20. if err1 != nil {
  21. log.Println("service [AutoTaskUpdateStatus] error:", err1)
  22. return err1
  23. }
  24. _, err2 := c.AddFunc("@midnight", AutoTaskUpdateApplyTimes)
  25. if err2 != nil {
  26. log.Println("service [AutoTaskUpdateApplyTimes] error:", err2)
  27. return err2
  28. }
  29. _, err3 := c.AddFunc(spec, AutoTaskCompleteSelection)
  30. if err3 != nil {
  31. log.Println("service [AutoTaskCompleteSecTask] error:", err2)
  32. return err3
  33. }
  34. */
  35. _, err4 := c.AddFunc(spec, GetAutoDraftDefaultTask)
  36. if err4 != nil {
  37. log.Println("service [GetAutoDraftDefaultTask] error:", err4)
  38. return err4
  39. }
  40. _, err5 := c.AddFunc(spec, GetAutoLinkDefaultTask)
  41. if err5 != nil {
  42. log.Println("service [GetAutoLinkDefaultTask] error:", err5)
  43. return err5
  44. }
  45. _, err6 := c.AddFunc(spec, GetAutoCaseCloseDefaultTask)
  46. if err6 != nil {
  47. log.Println("service [GetAutoCaseCloseDefaultTask] error:", err6)
  48. return err6
  49. }
  50. _, err7 := c.AddFunc(spec, UpdateProjectTaskRedBookLinkData)
  51. if err7 != nil {
  52. log.Println("service [UpdateProjectTaskRedBookLinkData] error:", err7)
  53. return err7
  54. }
  55. _, err8 := c.AddFunc(spec, UpdateLocalTaskRedBookLinkData)
  56. if err8 != nil {
  57. log.Println("service [UpdateLocalTaskRedBookLinkData] error:", err8)
  58. return err8
  59. }
  60. _, err9 := c.AddFunc(spec, UpdateProjectTaskWeiBoLinkData)
  61. if err9 != nil {
  62. log.Println("service [UpdateProjectTaskWeiBoLinkData] error:", err9)
  63. return err9
  64. }
  65. _, err10 := c.AddFunc(spec, UpdateLocalTaskWeiBoLinkData)
  66. if err10 != nil {
  67. log.Println("service [UpdateProjectTaskWeiBoLinkData] error:", err10)
  68. return err10
  69. }
  70. _, err11 := c.AddFunc(spec, UpdateProjectTaskDouyinLinkData)
  71. if err11 != nil {
  72. log.Println("service [UpdateProjectTaskDouyinLinkData] error:", err11)
  73. return err11
  74. }
  75. _, err12 := c.AddFunc(spec, UpdateLocalTaskDouyinLinkData)
  76. if err12 != nil {
  77. log.Println("service [UpdateLocalTaskDouyinLinkData] error:", err12)
  78. return err12
  79. }
  80. _, err13 := c.AddFunc(spec, UpdateProjectTaskKuaishouLinkData)
  81. if err13 != nil {
  82. log.Println("service [UpdateProjectTaskKuaishouLinkData] error:", err13)
  83. return err13
  84. }
  85. _, err14 := c.AddFunc(spec, UpdateLocalTaskKuaishouLinkData)
  86. if err14 != nil {
  87. log.Println("service [UpdateLocalTaskKuaishouLinkData] error:", err14)
  88. return err14
  89. }
  90. _, err15 := c.AddFunc(spec, UpdateProjectTaskBilibiliLinkData)
  91. if err15 != nil {
  92. log.Println("service [UpdateProjectTaskBilibiliLinkData] error:", err15)
  93. return err15
  94. }
  95. _, err16 := c.AddFunc(spec, UpdateLocalTaskBilibiliLinkData)
  96. if err16 != nil {
  97. log.Println("service [UpdateLocalTaskBilibiliLinkData] error:", err16)
  98. return err16
  99. }
  100. fmt.Println(spec)
  101. c.Start()
  102. return nil
  103. }
  104. func AutoTaskUpdateStatus() {
  105. err := db.AutoUpdateStatus()
  106. log.Println("AutoTaskUpdateStatus is running ,Time :", time.Now())
  107. if err != nil {
  108. log.Println("AutoTaskUpdateStatus error : ", err)
  109. }
  110. }
  111. func AutoTaskUpdateApplyTimes() {
  112. err := db.AutoUpdateApplyTimes()
  113. log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now())
  114. if err != nil {
  115. log.Println("AutoUpdateApplyTimes error : ", err)
  116. }
  117. }
  118. func AutoTaskCompleteSelection() {
  119. err := db.AutoCompleteSelection()
  120. log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now())
  121. if err != nil {
  122. log.Println("AutoUpdateApplyTimes error : ", err)
  123. }
  124. }
  125. // GetAutoDraftDefaultTask 初稿超时违约
  126. func GetAutoDraftDefaultTask() {
  127. err := db.GetAutoDraftDefaultTask()
  128. log.Println("GetAutoDraftDefaultInPicTask is running ,Time :", time.Now())
  129. if err != nil {
  130. log.Println("GetAutoDraftDefaultInPicTask error : ", err)
  131. }
  132. }
  133. // GetAutoLinkDefaultTask 链接超时违约
  134. func GetAutoLinkDefaultTask() {
  135. err := db.GetAutoLinkDefaultTask()
  136. log.Println("GetAutoLinkDefaultTask is running ,Time :", time.Now())
  137. if err != nil {
  138. log.Println("GetAutoDraftDefaultInPicTask error : ", err)
  139. }
  140. }
  141. // GetAutoCaseCloseDefaultTask 数据超时违约
  142. func GetAutoCaseCloseDefaultTask() {
  143. err := db.GetAutoCaseCloseDefaultTask()
  144. log.Println("GetAutoCaseCloseDefaultTask is running ,Time :", time.Now())
  145. if err != nil {
  146. log.Println("GetAutoCaseCloseDefaultTask error : ", err)
  147. }
  148. }
  149. // UpdateProjectTaskRedBookLinkData 定时拉取小红书平台,种草子任务链接数据
  150. func UpdateProjectTaskRedBookLinkData() {
  151. log.Println("UpdateProjectTaskRedBookLinkData is running ,Time :", time.Now())
  152. // 1. 符合条件的project
  153. ctx := context.Background()
  154. projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 1)
  155. if projectIdListErr != nil {
  156. log.Println("GetProjectIdList error : ", projectIdListErr)
  157. return
  158. }
  159. // 2. 符合条件的task
  160. if projectIdList != nil && projectIdListTotal != 0 {
  161. for _, projectId := range projectIdList {
  162. taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId)
  163. if taskIdErr != nil {
  164. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  165. continue
  166. }
  167. if taskIdList != nil && taskIdTotal != 0 {
  168. for _, taskId := range taskIdList {
  169. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  170. if linkErr != nil {
  171. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  172. continue
  173. }
  174. if linkInfo != "" {
  175. like, comment, collect, share, moreApiErr := GetRedBookLinkDetail(ctx, linkInfo)
  176. if moreApiErr != nil {
  177. log.Println("GetRedBookLinkDetail error : ", moreApiErr)
  178. continue
  179. }
  180. createData := gorm_model.ProjectTaskLinkStatistic{
  181. ProjectId: projectId,
  182. TaskId: taskId,
  183. PlatformId: 1,
  184. VoteCount: like,
  185. CommitCount: comment,
  186. CollectionCount: collect,
  187. ViewCount: share,
  188. }
  189. createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData)
  190. if createErr != nil {
  191. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  192. continue
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. // UpdateLocalTaskRedBookLinkData 定时拉取小红书平台,本地生活子任务链接数据
  201. func UpdateLocalTaskRedBookLinkData() {
  202. log.Println("UpdateLocalTaskRedBookLinkData is running ,Time :", time.Now())
  203. // 1. 符合条件的local
  204. ctx := context.Background()
  205. localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 1)
  206. if localIdListErr != nil {
  207. log.Println("GetLocalIdList error : ", localIdListErr)
  208. return
  209. }
  210. // 2. 符合条件的task
  211. if localIdList != nil && localIdListTotal != 0 {
  212. for _, localId := range localIdList {
  213. taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId)
  214. if taskIdErr != nil {
  215. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  216. continue
  217. }
  218. if taskIdList != nil && taskIdTotal != 0 {
  219. for _, taskId := range taskIdList {
  220. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  221. if linkErr != nil {
  222. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  223. continue
  224. }
  225. if linkInfo != "" {
  226. like, comment, collect, share, moreApiErr := GetRedBookLinkDetail(ctx, linkInfo)
  227. if moreApiErr != nil {
  228. log.Println("GetRedBookLinkDetail error : ", moreApiErr)
  229. continue
  230. }
  231. createData := gorm_model.LocalTaskLinkStatistic{
  232. LocalId: localId,
  233. TaskId: taskId,
  234. PlatformId: 1,
  235. VoteCount: like,
  236. CommitCount: comment,
  237. CollectionCount: collect,
  238. ViewCount: share,
  239. }
  240. createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData)
  241. if createErr != nil {
  242. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  243. continue
  244. }
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }
  251. // UpdateProjectTaskWeiBoLinkData 定时拉取微博平台,种草子任务链接数据
  252. func UpdateProjectTaskWeiBoLinkData() {
  253. log.Println("UpdateProjectTaskWeiBoLinkData is running ,Time :", time.Now())
  254. // 1. 符合条件的project
  255. ctx := context.Background()
  256. projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 3)
  257. if projectIdListErr != nil {
  258. log.Println("GetProjectIdList error : ", projectIdListErr)
  259. return
  260. }
  261. // 2. 符合条件的task
  262. if projectIdList != nil && projectIdListTotal != 0 {
  263. for _, projectId := range projectIdList {
  264. taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId)
  265. if taskIdErr != nil {
  266. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  267. continue
  268. }
  269. if taskIdList != nil && taskIdTotal != 0 {
  270. for _, taskId := range taskIdList {
  271. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  272. if linkErr != nil {
  273. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  274. continue
  275. }
  276. if linkInfo != "" {
  277. like, comment, collect, share, moreApiErr := GetWeiBoLinkDetail(ctx, linkInfo)
  278. if moreApiErr != nil {
  279. log.Println("GetWeiBoLinkDetail error : ", moreApiErr)
  280. continue
  281. }
  282. createData := gorm_model.ProjectTaskLinkStatistic{
  283. ProjectId: projectId,
  284. TaskId: taskId,
  285. PlatformId: 3,
  286. VoteCount: like,
  287. CommitCount: comment,
  288. CollectionCount: collect,
  289. ViewCount: share,
  290. }
  291. createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData)
  292. if createErr != nil {
  293. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  294. continue
  295. }
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. // UpdateLocalTaskWeiBoLinkData 定时拉取微博平台,本地生活子任务链接数据
  303. func UpdateLocalTaskWeiBoLinkData() {
  304. log.Println("UpdateLocalTaskWeiBoLinkData is running ,Time :", time.Now())
  305. // 1. 符合条件的local
  306. ctx := context.Background()
  307. localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 3)
  308. if localIdListErr != nil {
  309. log.Println("GetLocalIdList error : ", localIdListErr)
  310. return
  311. }
  312. // 2. 符合条件的task
  313. if localIdList != nil && localIdListTotal != 0 {
  314. for _, localId := range localIdList {
  315. taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId)
  316. if taskIdErr != nil {
  317. log.Println("UpdateLocalTaskWeiBoLinkData error : ", taskIdErr)
  318. continue
  319. }
  320. if taskIdList != nil && taskIdTotal != 0 {
  321. for _, taskId := range taskIdList {
  322. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  323. if linkErr != nil {
  324. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  325. continue
  326. }
  327. if linkInfo != "" {
  328. like, comment, collect, share, moreApiErr := GetWeiBoLinkDetail(ctx, linkInfo)
  329. if moreApiErr != nil {
  330. log.Println("GetWeiBoLinkDetail error : ", moreApiErr)
  331. continue
  332. }
  333. createData := gorm_model.LocalTaskLinkStatistic{
  334. LocalId: localId,
  335. TaskId: taskId,
  336. PlatformId: 3,
  337. VoteCount: like,
  338. CommitCount: comment,
  339. CollectionCount: collect,
  340. ViewCount: share,
  341. }
  342. createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData)
  343. if createErr != nil {
  344. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  345. continue
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }
  353. // UpdateProjectTaskDouyinLinkData 定时拉取抖音平台,种草子任务链接数据
  354. func UpdateProjectTaskDouyinLinkData() {
  355. log.Println("UpdateProjectTaskDouyinLinkData is running ,Time :", time.Now())
  356. // 1. 符合条件的project
  357. ctx := context.Background()
  358. projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 2)
  359. if projectIdListErr != nil {
  360. log.Println("GetProjectIdList error : ", projectIdListErr)
  361. return
  362. }
  363. // 2. 符合条件的task
  364. if projectIdList != nil && projectIdListTotal != 0 {
  365. for _, projectId := range projectIdList {
  366. taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId)
  367. if taskIdErr != nil {
  368. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  369. continue
  370. }
  371. if taskIdList != nil && taskIdTotal != 0 {
  372. for _, taskId := range taskIdList {
  373. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  374. if linkErr != nil {
  375. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  376. continue
  377. }
  378. if linkInfo != "" {
  379. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetDouyinStatistic(linkInfo)
  380. if moreApiErr != nil {
  381. log.Println("GetDouyinStatistic error : ", moreApiErr)
  382. continue
  383. }
  384. createData := gorm_model.ProjectTaskLinkStatistic{
  385. ProjectId: projectId,
  386. TaskId: taskId,
  387. PlatformId: 2,
  388. VoteCount: like,
  389. CommitCount: comment,
  390. CollectionCount: collect,
  391. ViewCount: share,
  392. }
  393. createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData)
  394. if createErr != nil {
  395. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  396. continue
  397. }
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. // UpdateLocalTaskDouyinLinkData 定时拉取抖音平台,本地生活子任务链接数据
  405. func UpdateLocalTaskDouyinLinkData() {
  406. log.Println("UpdateLocalTaskDouyinLinkData is running ,Time :", time.Now())
  407. // 1. 符合条件的local
  408. ctx := context.Background()
  409. localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 2)
  410. if localIdListErr != nil {
  411. log.Println("GetLocalIdList error : ", localIdListErr)
  412. return
  413. }
  414. // 2. 符合条件的task
  415. if localIdList != nil && localIdListTotal != 0 {
  416. for _, localId := range localIdList {
  417. taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId)
  418. if taskIdErr != nil {
  419. log.Println("GetLocalTaskIdList error : ", taskIdErr)
  420. continue
  421. }
  422. if taskIdList != nil && taskIdTotal != 0 {
  423. for _, taskId := range taskIdList {
  424. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  425. if linkErr != nil {
  426. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  427. continue
  428. }
  429. if linkInfo != "" {
  430. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetDouyinStatistic(linkInfo)
  431. if moreApiErr != nil {
  432. log.Println("GetWeiBoLinkDetail error : ", moreApiErr)
  433. continue
  434. }
  435. createData := gorm_model.LocalTaskLinkStatistic{
  436. LocalId: localId,
  437. TaskId: taskId,
  438. PlatformId: 2,
  439. VoteCount: like,
  440. CommitCount: comment,
  441. CollectionCount: collect,
  442. ViewCount: share,
  443. }
  444. createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData)
  445. if createErr != nil {
  446. log.Println("CreateLocalTaskLinkStatistic error : ", createErr)
  447. continue
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. // UpdateProjectTaskKuaishouLinkData 定时拉取快手平台,种草子任务链接数据
  456. func UpdateProjectTaskKuaishouLinkData() {
  457. log.Println("UpdateProjectTaskKuaishouLinkData is running ,Time :", time.Now())
  458. // 1. 符合条件的project
  459. ctx := context.Background()
  460. projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 4)
  461. if projectIdListErr != nil {
  462. log.Println("GetProjectIdList error : ", projectIdListErr)
  463. return
  464. }
  465. // 2. 符合条件的task
  466. if projectIdList != nil && projectIdListTotal != 0 {
  467. for _, projectId := range projectIdList {
  468. taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId)
  469. if taskIdErr != nil {
  470. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  471. continue
  472. }
  473. if taskIdList != nil && taskIdTotal != 0 {
  474. for _, taskId := range taskIdList {
  475. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  476. if linkErr != nil {
  477. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  478. continue
  479. }
  480. if linkInfo != "" {
  481. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetKuaishouStatistic(linkInfo)
  482. if moreApiErr != nil {
  483. log.Println("GetKuaishouStatistic error : ", moreApiErr)
  484. continue
  485. }
  486. createData := gorm_model.ProjectTaskLinkStatistic{
  487. ProjectId: projectId,
  488. TaskId: taskId,
  489. PlatformId: 4,
  490. VoteCount: like,
  491. CommitCount: comment,
  492. CollectionCount: collect,
  493. ViewCount: share,
  494. }
  495. createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData)
  496. if createErr != nil {
  497. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  498. continue
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. // UpdateLocalTaskKuaishouLinkData 定时拉取快手平台,本地生活子任务链接数据
  507. func UpdateLocalTaskKuaishouLinkData() {
  508. log.Println("UpdateLocalTaskKuaishouLinkData is running ,Time :", time.Now())
  509. // 1. 符合条件的local
  510. ctx := context.Background()
  511. localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 4)
  512. if localIdListErr != nil {
  513. log.Println("GetLocalIdList error : ", localIdListErr)
  514. return
  515. }
  516. // 2. 符合条件的task
  517. if localIdList != nil && localIdListTotal != 0 {
  518. for _, localId := range localIdList {
  519. taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId)
  520. if taskIdErr != nil {
  521. log.Println("GetLocalTaskIdList error : ", taskIdErr)
  522. continue
  523. }
  524. if taskIdList != nil && taskIdTotal != 0 {
  525. for _, taskId := range taskIdList {
  526. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  527. if linkErr != nil {
  528. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  529. continue
  530. }
  531. if linkInfo != "" {
  532. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetKuaishouStatistic(linkInfo)
  533. if moreApiErr != nil {
  534. log.Println("GetKuaishouStatistic error : ", moreApiErr)
  535. continue
  536. }
  537. createData := gorm_model.LocalTaskLinkStatistic{
  538. LocalId: localId,
  539. TaskId: taskId,
  540. PlatformId: 4,
  541. VoteCount: like,
  542. CommitCount: comment,
  543. CollectionCount: collect,
  544. ViewCount: share,
  545. }
  546. createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData)
  547. if createErr != nil {
  548. log.Println("CreateLocalTaskLinkStatistic error : ", createErr)
  549. continue
  550. }
  551. }
  552. }
  553. }
  554. }
  555. }
  556. }
  557. // UpdateProjectTaskBilibiliLinkData 定时拉取b站平台,种草子任务链接数据
  558. func UpdateProjectTaskBilibiliLinkData() {
  559. log.Println("UpdateProjectTaskBilibiliLinkData is running ,Time :", time.Now())
  560. // 1. 符合条件的project
  561. ctx := context.Background()
  562. projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 5)
  563. if projectIdListErr != nil {
  564. log.Println("GetProjectIdList error : ", projectIdListErr)
  565. return
  566. }
  567. // 2. 符合条件的task
  568. if projectIdList != nil && projectIdListTotal != 0 {
  569. for _, projectId := range projectIdList {
  570. taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId)
  571. if taskIdErr != nil {
  572. log.Println("GetProjectTaskIdList error : ", taskIdErr)
  573. continue
  574. }
  575. if taskIdList != nil && taskIdTotal != 0 {
  576. for _, taskId := range taskIdList {
  577. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  578. if linkErr != nil {
  579. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  580. continue
  581. }
  582. if linkInfo != "" {
  583. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetBilibiliStatistic(linkInfo)
  584. if moreApiErr != nil {
  585. log.Println("GetBilibiliStatistic error : ", moreApiErr)
  586. continue
  587. }
  588. createData := gorm_model.ProjectTaskLinkStatistic{
  589. ProjectId: projectId,
  590. TaskId: taskId,
  591. PlatformId: 5,
  592. VoteCount: like,
  593. CommitCount: comment,
  594. CollectionCount: collect,
  595. ViewCount: share,
  596. }
  597. createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData)
  598. if createErr != nil {
  599. log.Println("CreateProjectTaskLinkStatistic error : ", createErr)
  600. continue
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
  608. // UpdateLocalTaskBilibiliLinkData 定时拉取b站平台,本地生活子任务链接数据
  609. func UpdateLocalTaskBilibiliLinkData() {
  610. log.Println("UpdateLocalTaskBilibiliLinkData is running ,Time :", time.Now())
  611. // 1. 符合条件的local
  612. ctx := context.Background()
  613. localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 5)
  614. if localIdListErr != nil {
  615. log.Println("GetLocalIdList error : ", localIdListErr)
  616. return
  617. }
  618. // 2. 符合条件的task
  619. if localIdList != nil && localIdListTotal != 0 {
  620. for _, localId := range localIdList {
  621. taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId)
  622. if taskIdErr != nil {
  623. log.Println("GetLocalTaskIdList error : ", taskIdErr)
  624. continue
  625. }
  626. if taskIdList != nil && taskIdTotal != 0 {
  627. for _, taskId := range taskIdList {
  628. linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1)
  629. if linkErr != nil {
  630. log.Println("GetProjectTaskLinkInfo error : ", linkErr)
  631. continue
  632. }
  633. if linkInfo != "" {
  634. like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetBilibiliStatistic(linkInfo)
  635. if moreApiErr != nil {
  636. log.Println("GetKuaishouStatistic error : ", moreApiErr)
  637. continue
  638. }
  639. createData := gorm_model.LocalTaskLinkStatistic{
  640. LocalId: localId,
  641. TaskId: taskId,
  642. PlatformId: 5,
  643. VoteCount: like,
  644. CommitCount: comment,
  645. CollectionCount: collect,
  646. ViewCount: share,
  647. }
  648. createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData)
  649. if createErr != nil {
  650. log.Println("CreateLocalTaskLinkStatistic error : ", createErr)
  651. continue
  652. }
  653. }
  654. }
  655. }
  656. }
  657. }
  658. }