cownum.go 967 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package cownum_sqlserver
  2. import (
  3. "fmt"
  4. "github.com/sirupsen/logrus"
  5. "kpt.xdmy/apiserver/dao"
  6. "kpt.xdmy/apiserver/model"
  7. )
  8. //var s *Service
  9. func SyncCownum(s *dao.SqlServer, d *dao.Dao, date string) {
  10. onlineCownumList := make([]*model.Cownum, 0)
  11. err := s.DB.Table("Table_cownum").Where("date = ?", date).
  12. Find(&onlineCownumList).Error
  13. if err != nil {
  14. logrus.Error("SyncCownum-1-error: ", err.Error())
  15. }
  16. for _, item := range onlineCownumList {
  17. pasture := new(model.Pasture)
  18. tx := d.DB.Table("pasture").Where(" name like concat('%',?,'%') ", item.Farm)
  19. err := tx.First(pasture).Error
  20. if err != nil {
  21. logrus.Error("SyncCownum-2-error: ", err.Error())
  22. continue
  23. }
  24. fmt.Println(pasture)
  25. err = d.DB.Create(&model.FeedSum{
  26. CowNum: item.Totalcow,
  27. CowNumM: item.Milkcow,
  28. FeedDay: date,
  29. PastureId: int64(pasture.ID),
  30. }).Error
  31. if err != nil {
  32. logrus.Error("SyncCownum-3-error: ", err.Error())
  33. //return
  34. }
  35. }
  36. }