neck_ring.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package crontab
  2. import (
  3. "kpt-pasture/config"
  4. "kpt-pasture/model"
  5. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  6. "gitee.com/xuyiping_admin/pkg/xerr"
  7. )
  8. func (e *Entry) NeckRingData() error {
  9. cfg := config.Options()
  10. limit := cfg.NeckRingLimit
  11. if limit <= 0 {
  12. limit = 10000
  13. }
  14. neckRingList := make([]*model.NeckRingOriginalData, 0)
  15. if err := e.DB.Model(new(model.NeckRingOriginalData)).
  16. Where("is_show = ?", pasturePb.IsShow_No).
  17. Order("id asc").Limit(int(limit)).
  18. Find(&neckRingList).Error; err != nil {
  19. return xerr.WithStack(err)
  20. }
  21. if len(neckRingList) <= 0 {
  22. return nil
  23. }
  24. neckRingIds := make([]int64, len(neckRingList))
  25. // 更新已处理过的id
  26. defer func() {
  27. if len(neckRingIds) > 0 {
  28. e.DB.Model(new(model.NeckRingOriginalData)).
  29. Where("id IN ?", neckRingIds).
  30. Update("is_show", pasturePb.IsShow_Ok)
  31. }
  32. }()
  33. for i, v := range neckRingList {
  34. neckRingIds[i] = v.Id
  35. if v.Imei == "" {
  36. continue
  37. }
  38. }
  39. return nil
  40. }
  41. func (e *Entry) NeckRingOriginalDataMerge(dataList []*model.NeckRingLog) {
  42. if len(dataList) <= 0 {
  43. return
  44. }
  45. }