package dao import ( "demo/internal/model" "github.com/pkg/errors" "github.com/siddontang/go/log" ) func (d *Dao) GetBarList(index, pagesize int64, barName, pastureid string) ([]*model.Bar, int64, error) { dataList := make([]*model.Bar, 0) rows := d.db.NewSession() defer rows.Close() if pastureid != "" { rows.Where("FARM_UUID = ?", pastureid) } if barName != "" { rows.Where("HOUSE_NAME = ?", barName) } if index != 0 && pagesize != 0 { first := (index - 1) * pagesize rows.Limit(int(pagesize), int(first)) } count, err := rows.FindAndCount(&dataList) if err != nil { err = errors.Wrap(err, "GetBarList-db-error") log.Error(err) return dataList, count, err } return dataList, count, nil } func (d *Dao) GetPastureList(index, pagesize int64) ([]*model.Pasture, int64, error) { dataList := make([]*model.Pasture, 0) rows := d.db.NewSession() defer rows.Close() if index != 0 && pagesize != 0 { first := (index - 1) * pagesize rows.Limit(int(pagesize), int(first)) } count, err := rows.FindAndCount(&dataList) if err != nil { err = errors.Wrap(err, "GetPastureList-db-error") log.Error(err) return dataList, count, err } return dataList, count, nil } func (d *Dao) GetHousephyList(index, pagesize int64, pastureId string) ([]*model.Housephy, int64, error) { dataList := make([]*model.Housephy, 0) rows := d.db.NewSession() defer rows.Close() if index != 0 && pagesize != 0 { first := (index - 1) * pagesize rows.Limit(int(pagesize), int(first)) } rows.Where("FARM_UUID = ?", pastureId) rows.Where("DEL = 0") count, err := rows.OrderBy("PHYSICALCODE").FindAndCount(&dataList) if err != nil { err = errors.Wrap(err, "GetHousephyList-db-error") log.Error(err) return dataList, count, err } return dataList, count, nil } func (d *Dao) UpdateHousephyImage(housephy *model.Housephy) error { rows := d.db.NewSession() defer rows.Close() _, err := rows.Cols("image").Where("UUID = ? ", housephy.Id).Update(housephy) if err != nil { err = errors.Wrap(err, "UpdateHousephyImage-db-error") log.Error(err) return err } return nil } func (d *Dao) GetHousephyImage(id string) (*model.Housephy, error) { rows := d.db.NewSession() defer rows.Close() housephy := new(model.Housephy) _, err := rows.Where("UUID = ? ", id).Get(housephy) if err != nil { err = errors.Wrap(err, "GetHousephyImage-db-error") log.Error(err) return nil, err } return housephy, nil }