user_prize.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package entity
  2. import (
  3. "log"
  4. . "online_datasync/config"
  5. . "online_datasync/db"
  6. . "app.yhyue.com/moapp/jybase/date"
  7. )
  8. var (
  9. User_prize *user_prize
  10. )
  11. type user_prize struct {
  12. }
  13. func (u *user_prize) TableName() string {
  14. return "user_prize"
  15. }
  16. //
  17. func (u *user_prize) SaveFields() []string {
  18. return []string{"id", "userId", "prizeId", "validityDates", "beginDate", "endDate", "useDate", "prizeType", "appId", "lotteryId", "createTime", "name", "full", "reduce", "userName", "orderCode", "timestamp"}
  19. }
  20. //
  21. func (u *user_prize) Run(start_unix, end_unix int64, start_layout, end_layout string) {
  22. TimeTask.User_prize_id = sync_add(Mysql_From_Jyactivities, u.TableName(), u.SaveFields(), TimeTask.User_prize_id, nil)
  23. if start_unix > 0 {
  24. u.update(start_layout, end_layout)
  25. }
  26. }
  27. //
  28. func (u *user_prize) update(start_layout, end_layout string) {
  29. log.Println("开始同步更新", u.TableName(), "表 。。。")
  30. index := 0
  31. array := [][]interface{}{}
  32. fields := []string{"prizeType", "timestamp"}
  33. Mysql_From_Jyactivities.SelectByBath(Config.SelectBathSize, func(l *[]map[string]interface{}) {
  34. for _, v := range *l {
  35. index++
  36. array = append(array, []interface{}{v["prizeType"], NowFormat(Date_Full_Layout)})
  37. if index%Config.UpdateBathSize == 0 {
  38. log.Println("同步更新", u.TableName(), "表", index)
  39. Mysql_Main.UpdateBath(u.TableName(), fields, array)
  40. array = [][]interface{}{}
  41. }
  42. }
  43. }, `select prizeType from user_prize where useDate>=? and useDate<?`, start_layout, end_layout)
  44. if len(array) > 0 {
  45. Mysql_Main.UpdateBath(u.TableName(), fields, array)
  46. array = [][]interface{}{}
  47. }
  48. log.Println("同步更新", u.TableName(), "表结束。。。", index)
  49. }