12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package cownum_sqlserver
- import (
- "fmt"
- "github.com/sirupsen/logrus"
- "kpt.xdmy/apiserver/dao"
- "kpt.xdmy/apiserver/model"
- )
- //var s *Service
- func SyncCownum(s *dao.SqlServer, d *dao.Dao, date string) {
- onlineCownumList := make([]*model.Cownum, 0)
- err := s.DB.Table("Table_cownum").Where("date = ?", date).
- Find(&onlineCownumList).Error
- if err != nil {
- logrus.Error("SyncCownum-1-error: ", err.Error())
- }
- for _, item := range onlineCownumList {
- pasture := new(model.Pasture)
- tx := d.DB.Table("pasture").Where(" name like concat('%',?,'%') ", item.Farm)
- err := tx.First(pasture).Error
- if err != nil {
- logrus.Error("SyncCownum-2-error: ", err.Error())
- continue
- }
- fmt.Println(pasture)
- err = d.DB.Create(&model.FeedSum{
- CowNum: item.Totalcow,
- CowNumM: item.Milkcow,
- FeedDay: date,
- PastureId: int64(pasture.ID),
- }).Error
- if err != nil {
- logrus.Error("SyncCownum-3-error: ", err.Error())
- //return
- }
- }
- }
|