package crontab import ( "kpt-pasture/model" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" "gitee.com/xuyiping_admin/pkg/logger/zaplog" "go.uber.org/zap" ) // FindPastureAllCow 查询所有牧场牛只总数 func (e *Entry) FindPastureAllCow() map[int64]int32 { pastureList := e.FindPastureList() res := make(map[int64]int32) for _, pasture := range pastureList { var count int64 if err := e.DB.Model(&model.Cow{}). Where("pasture_id = ?", pasture.Id). Where("admission_status = ?", pasturePb.AdmissionStatus_Admission). Count(&count).Error; err != nil { zaplog.Error("FindAllCow", zap.Any("pasture_id", pasture.Id), zap.Any("err", err)) } res[pasture.Id] = int32(count) } return res } func (e *Entry) UpdatePastureIndicators(pastureId int64, date, kind, value string) { indicatorsData := &model.IndicatorsData{ PastureId: pastureId, Date: date, Kind: kind, } res := e.DB.Model(indicatorsData). Where(indicatorsData). FirstOrCreate(indicatorsData) if res.Error != nil { zaplog.Error("UpdatePastureIndicators", zap.Any("err", res.Error)) return } if res.RowsAffected == 0 { indicatorsData.Value = value if err := e.DB.Save(indicatorsData).Error; err != nil { zaplog.Error("UpdatePastureIndicators", zap.Any("err", err)) } } }