raw_product.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package entity
  2. import (
  3. "log"
  4. . "online_datasync/config"
  5. . "online_datasync/db"
  6. . "app.yhyue.com/moapp/jybase/common"
  7. )
  8. var (
  9. Raw_product *raw_product
  10. )
  11. type raw_product struct {
  12. }
  13. func (r *raw_product) TableName() string {
  14. return "raw_product"
  15. }
  16. //
  17. func (r *raw_product) SaveFields() []string {
  18. return []string{"id", "product_name", "product_code", "parent_code", "level", "product_cost_type"}
  19. }
  20. //
  21. func (r *raw_product) Run(start_unix, end_unix int64, start_layout, end_layout string) {
  22. log.Println("开始同步", r.TableName(), "表。。。")
  23. index := 0
  24. array := []interface{}{}
  25. Mysql_From_Jyactivities.SelectByBath(Config.SelectBathSize, func(l *[]map[string]interface{}) {
  26. for _, v := range *l {
  27. index++
  28. TimeTask.Raw_product_id = Int64All(v["id"])
  29. array = append(array, v["id"], v["productName"], v["productCode"], v["parentCode"], 1, 1)
  30. if index%Config.InsertBathSize == 0 {
  31. log.Println("同步", r.TableName(), "表", index)
  32. Mysql_Main.InsertIgnoreBatch(r.TableName(), r.SaveFields(), array)
  33. array = []interface{}{}
  34. }
  35. }
  36. }, `select id,productName,productCode,parentCode from product where id>? order by id`, TimeTask.Raw_product_id)
  37. if len(array) > 0 {
  38. Mysql_Main.InsertIgnoreBatch(r.TableName(), r.SaveFields(), array)
  39. array = []interface{}{}
  40. }
  41. log.Println("同步", r.TableName(), "表结束。。。", index)
  42. }