full.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "time"
  6. "go-common/app/admin/main/tv/model"
  7. "go-common/library/log"
  8. )
  9. // FullImport .
  10. func (s *Service) FullImport(c context.Context, build int) (result []*model.APKInfo, err error) {
  11. result, err = s.dao.FullImport(c, build)
  12. return
  13. }
  14. func (s *Service) loadSnsproc() {
  15. for {
  16. time.Sleep(time.Duration(s.c.Cfg.LoadSnFre))
  17. s.loadSns(context.Background())
  18. }
  19. }
  20. // loadSns loads all not deleted season Info
  21. func (s *Service) loadSns(c context.Context) (err error) {
  22. var (
  23. rows *sql.Rows
  24. sns = make(map[int64]*model.TVEpSeason)
  25. sidCats = make(map[int][]int64)
  26. )
  27. if rows, err = s.DB.Model(&model.TVEpSeason{}).Where("is_deleted = 0").Select("id, title, category, state, valid, `check`").Rows(); err != nil {
  28. log.Error("rows Err %v", err)
  29. return
  30. }
  31. defer rows.Close()
  32. for rows.Next() {
  33. cont := &model.TVEpSeason{}
  34. if err = rows.Scan(&cont.ID, &cont.Title, &cont.Category, &cont.State, &cont.Valid, &cont.Check); err != nil {
  35. log.Error("rows.Scan error(%v)", err)
  36. return
  37. }
  38. sns[cont.ID] = cont
  39. if dataSet, ok := sidCats[cont.Category]; !ok {
  40. sidCats[cont.Category] = []int64{cont.ID}
  41. } else {
  42. sidCats[cont.Category] = append(dataSet, cont.ID)
  43. }
  44. }
  45. if err = rows.Err(); err != nil {
  46. log.Error("rows.Err %v", err)
  47. return
  48. }
  49. if len(sns) > 0 {
  50. s.snsInfo = sns
  51. s.snsCats = sidCats
  52. }
  53. return
  54. }