autoTask.go 22 KB

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