|
@@ -19,18 +19,24 @@ import (
|
|
|
)
|
|
|
|
|
|
func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchLavingEventResponse, error) {
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
lavingList := make([]*model.EventCalvingList, 0)
|
|
|
var count int64 = 0
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
|
|
|
Select(`a.*,b.name as pen_name,c.name as staff_member_name`).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS b on a.pen_id = b.id", new(model.Pen).TableName())).
|
|
|
- Joins(fmt.Sprintf("JOIN %s AS c on a.operation_id = c.id", new(model.SystemUser).TableName()))
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS c on a.operation_id = c.id", new(model.SystemUser).TableName())).
|
|
|
+ Where("pasture_id = ?", currentUser.PastureId)
|
|
|
if len(req.CowId) > 0 {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("a.cow_id IN ?", cowIds)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("a.id desc").
|
|
|
+ if err = pref.Order("a.id desc").
|
|
|
Count(&count).Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&lavingList).Error; err != nil {
|
|
@@ -42,7 +48,7 @@ func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEvent
|
|
|
calvingIds = append(calvingIds, v.Id)
|
|
|
}
|
|
|
calvingCalfList := make([]*model.CalvingCalf, 0)
|
|
|
- if err := s.DB.Model(new(model.CalvingCalf)).
|
|
|
+ if err = s.DB.Model(new(model.CalvingCalf)).
|
|
|
Where("calving_id IN ?", calvingIds).
|
|
|
Find(&calvingCalfList).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
@@ -61,13 +67,18 @@ func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEvent
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalving) (err error) {
|
|
|
- cow, err := s.GetCowInfoByCowId(ctx, int64(req.CowId))
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
+ cow, err := s.GetCowInfoByCowId(ctx, currentUser.PastureId, int64(req.CowId))
|
|
|
if err != nil {
|
|
|
zaplog.Error("CalvingCreate", zap.Any("cow_id", req.CowId), zap.Any("err", err))
|
|
|
return xerr.Custom("请选择相关牛只")
|
|
|
}
|
|
|
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("获取操作人员信息失败: %s", err.Error())
|
|
|
}
|
|
@@ -77,15 +88,15 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
defer func() {
|
|
|
if err == nil {
|
|
|
// 母牛事件日志
|
|
|
- cowLogs := s.SubmitEventLog(ctx, cow, pasturePb.EventType_Calving, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Calving, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
// 犊牛事件日志
|
|
|
for _, v := range req.CalfItemList {
|
|
|
if v.IsLive == pasturePb.IsShow_No || v.IsAdoption == pasturePb.IsShow_No {
|
|
|
continue
|
|
|
}
|
|
|
- cow, _ = s.GetCowInfoByCowId(ctx, int64(v.CowId))
|
|
|
- cowLogs = s.SubmitEventLog(ctx, cow, pasturePb.EventType_Birth, pasturePb.ExposeEstrusType_Invalid, v)
|
|
|
+ cow, _ = s.GetCowInfoByCowId(ctx, currentUser.PastureId, int64(v.CowId))
|
|
|
+ cowLogs = s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Birth, pasturePb.ExposeEstrusType_Invalid, v)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -112,7 +123,7 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
continue
|
|
|
}
|
|
|
// 犊牛信息
|
|
|
- newCalvingCalf := model.NewEventCalvingCalf(int64(req.CowId), newEventCalving.Id, int64(req.CalvingAt), v)
|
|
|
+ newCalvingCalf := model.NewEventCalvingCalf(currentUser.PastureId, int64(req.CowId), newEventCalving.Id, int64(req.CalvingAt), v)
|
|
|
// 留养犊牛
|
|
|
newCow := model.NewCalfCow(cow.Id, cow.LastBullNumber, newCalvingCalf)
|
|
|
if err = tx.Create(newCow).Error; err != nil {
|
|
@@ -141,10 +152,16 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusItemsResponse, error) {
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
estrusList := make([]*model.EventEstrus, 0)
|
|
|
var count int64 = 0
|
|
|
pref := s.DB.Table(new(model.EventEstrus).TableName()).
|
|
|
- Where("is_show = ?", pasturePb.IsShow_Ok)
|
|
|
+ Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
|
+ Where("pasture_id = ?", currentUser.PastureId)
|
|
|
if len(req.CowIds) > 0 {
|
|
|
cowIds := strings.Split(util.ArrayInt32ToStrings(req.CowIds, ","), ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
@@ -159,7 +176,7 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
|
|
|
pref.Where("pen_id IN ?", penIds)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("id desc").
|
|
|
+ if err = pref.Order("id desc").
|
|
|
Count(&count).Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&estrusList).Error; err != nil {
|
|
@@ -183,9 +200,9 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
|
|
|
func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrus) (err error) {
|
|
|
currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误")
|
|
|
+ return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
}
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("该用户不存在: %d", req.OperationId)
|
|
|
}
|
|
@@ -199,8 +216,8 @@ func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrus
|
|
|
return xerr.Custom("牛只信息不存在")
|
|
|
}
|
|
|
|
|
|
- newEventMating := model.NewEventMating(cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Neck_Ring)
|
|
|
- eventEstrus, ok := s.EventEstrusIsExist(ctx, int64(cowId))
|
|
|
+ newEventMating := model.NewEventMating(currentUser.PastureId, cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Neck_Ring)
|
|
|
+ eventEstrus, ok := s.EventEstrusIsExist(ctx, currentUser.PastureId, int64(cowId))
|
|
|
if ok {
|
|
|
newEventMating.EventEstrusId = eventEstrus.Id
|
|
|
newEventMating.MatingTimes = cowInfo.MatingTimes + 1
|
|
@@ -223,8 +240,8 @@ func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrus
|
|
|
// 记录牛只事件日志
|
|
|
if err == nil {
|
|
|
for _, v := range eventMatingList {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, v.CowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, cow, pasturePb.EventType_Mating, pasturePb.ExposeEstrusType_Neck_Ring, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, v.CowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Mating, pasturePb.ExposeEstrusType_Neck_Ring, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -255,44 +272,36 @@ func (s *StoreEntry) EstrusBatch(ctx context.Context, req *pasturePb.EventEstrus
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) (err error) {
|
|
|
- eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, int64(req.CowId))
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
if err != nil {
|
|
|
- zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
- return xerr.Customf("异常数据")
|
|
|
+ return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
}
|
|
|
|
|
|
- drugs := &model.Drugs{}
|
|
|
- if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
|
|
|
- zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
- return xerr.Customf("该药品不存在: %d", req.DrugsId)
|
|
|
- }
|
|
|
- req.DrugsName = drugs.Name
|
|
|
-
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, currentUser.PastureId, int64(req.CowId))
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误")
|
|
|
+ zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
+ return xerr.Customf("异常数据")
|
|
|
}
|
|
|
|
|
|
+ drugs := &model.Drugs{}
|
|
|
+ if drugs, err = s.GetDrugsById(ctx, currentUser.PastureId, int64(req.DrugsId)); err != nil {
|
|
|
+ zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
+ return xerr.Customf("该药品不存在: %d", req.DrugsId)
|
|
|
+ }
|
|
|
+ req.DrugsName = drugs.Name
|
|
|
eventCowSameTime.Update(drugs, req.Usage, req.Remarks, operationUser, currentUser)
|
|
|
+
|
|
|
defer func() {
|
|
|
if err == nil {
|
|
|
// 记录牛只事件日志
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, eventCowSameTime.CowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, cow, pasturePb.EventType_Seme_Time, pasturePb.ExposeEstrusType_Same_Time, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, eventCowSameTime.CowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Seme_Time, pasturePb.ExposeEstrusType_Same_Time, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
-
|
|
|
- if err = s.DB.Model(new(model.CowSameTime)).
|
|
|
- Where("cow_id = ?", eventCowSameTime.CowId).
|
|
|
- Where("same_time_id = ?", eventCowSameTime.Id).
|
|
|
- Where("same_time_status = ?", pasturePb.SameTimeStatus_No_Start).
|
|
|
- Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
|
|
|
- zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
- }
|
|
|
}
|
|
|
}()
|
|
|
|
|
@@ -306,18 +315,19 @@ func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSam
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSameTimeBatch) (err error) {
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Customf("异常数据")
|
|
|
+ return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
}
|
|
|
- req.OperationName = operationUser.Name
|
|
|
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("异常数据")
|
|
|
}
|
|
|
+ req.OperationName = operationUser.Name
|
|
|
+
|
|
|
drugs := &model.Drugs{}
|
|
|
- if drugs, err = s.GetDrugsById(ctx, int64(req.DrugsId)); err != nil {
|
|
|
+ if drugs, err = s.GetDrugsById(ctx, currentUser.PastureId, int64(req.DrugsId)); err != nil {
|
|
|
zaplog.Error("SameTimeBatch", zap.Any("err", err), zap.Any("req", req))
|
|
|
return xerr.Customf("该药物不存在: %d", req.DrugsId)
|
|
|
}
|
|
@@ -325,20 +335,22 @@ func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSame
|
|
|
|
|
|
eventCowSameTimeList := make([]*model.EventCowSameTime, 0)
|
|
|
for _, v := range req.CowIds {
|
|
|
- eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, int64(v))
|
|
|
+ eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, currentUser.PastureId, int64(v))
|
|
|
if err != nil {
|
|
|
zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
eventCowSameTimeList = append(eventCowSameTimeList, eventCowSameTime)
|
|
|
}
|
|
|
+
|
|
|
defer func() {
|
|
|
// 记录牛只事件日志
|
|
|
if err == nil {
|
|
|
for _, v := range eventCowSameTimeList {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, v.CowId)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, v.CowId)
|
|
|
cowLogs := s.SubmitEventLog(
|
|
|
ctx,
|
|
|
+ currentUser,
|
|
|
cow,
|
|
|
pasturePb.EventType_Seme_Time,
|
|
|
pasturePb.ExposeEstrusType_Same_Time,
|
|
@@ -362,14 +374,6 @@ func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSame
|
|
|
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
for _, v := range eventCowSameTimeList {
|
|
|
- if err = tx.Model(new(model.CowSameTime)).
|
|
|
- Where("cow_id = ?", v.CowId).
|
|
|
- Where("same_time_id = ?", v.Id).
|
|
|
- Where("same_time_status = ?", pasturePb.SameTimeStatus_No_Start).
|
|
|
- Update("same_time_status", pasturePb.SameTimeStatus_In_Progress).Error; err != nil {
|
|
|
- zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
- }
|
|
|
-
|
|
|
// 更新SameTime
|
|
|
v.Update(drugs, req.Usage, req.Remarks, currentUser, operationUser)
|
|
|
if err = tx.Model(new(model.EventCowSameTime)).
|
|
@@ -391,15 +395,20 @@ func (s *StoreEntry) SameTimeList(
|
|
|
req *pasturePb.SearchEventRequest,
|
|
|
pagination *pasturePb.PaginationModel,
|
|
|
) (*pasturePb.SearchSameTimeResponse, error) {
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
cowSameTimeList := make([]*model.EventCowSameTime, 0)
|
|
|
var count int64 = 0
|
|
|
- pref := s.DB.Table(new(model.EventCowSameTime).TableName())
|
|
|
+ pref := s.DB.Table(new(model.EventCowSameTime).TableName()).Where("pasture_id = ?", currentUser.PastureId)
|
|
|
if req.CowId != "" {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Count(&count).
|
|
|
+ if err = pref.Count(&count).
|
|
|
Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&cowSameTimeList).Error; err != nil {
|
|
@@ -420,17 +429,23 @@ func (s *StoreEntry) SameTimeList(
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error) {
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
matingList := make([]*model.EventMating, 0)
|
|
|
var count int64 = 0
|
|
|
pref := s.DB.Model(new(model.EventMating)).
|
|
|
Where("mating_result > ?", pasturePb.MatingResult_Invalid).
|
|
|
- Where("status = ?", pasturePb.IsShow_No)
|
|
|
+ Where("status = ?", pasturePb.IsShow_No).
|
|
|
+ Where("pasture_id = ?", currentUser.PastureId)
|
|
|
if len(req.CowId) > 0 {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
|
}
|
|
|
|
|
|
- if err := pref.Order("id desc").
|
|
|
+ if err = pref.Order("id desc").
|
|
|
Count(&count).Limit(int(pagination.PageSize)).
|
|
|
Offset(int(pagination.PageOffset)).
|
|
|
Find(&matingList).Error; err != nil {
|
|
@@ -539,8 +554,8 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
if err != nil {
|
|
|
// 记录事件日志
|
|
|
for _, cowId := range cowIds {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, cowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, cow, pasturePb.EventType_Mating, req.ExposeEstrusType, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, eventCheckModel.CurrentUser.PastureId, cowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, eventCheckModel.CurrentUser, cow, pasturePb.EventType_Mating, req.ExposeEstrusType, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -594,13 +609,6 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- // 如果有同期牛只,则修改为已结束状态
|
|
|
- if err = tx.Model(new(model.CowSameTime)).
|
|
|
- Where("cow_id IN ?", cowIds).
|
|
|
- UpdateColumn("same_time_status", pasturePb.SameTimeStatus_End).Error; err != nil {
|
|
|
- return xerr.WithStack(err)
|
|
|
- }
|
|
|
-
|
|
|
// 更新牛只的繁殖状态为配种
|
|
|
if err = tx.Model(new(model.Cow)).
|
|
|
Where("id IN ?", cowIds).
|
|
@@ -650,6 +658,11 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeaningBatchRequest) (err error) {
|
|
|
+ currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ }
|
|
|
+
|
|
|
if len(req.Item) <= 0 {
|
|
|
return nil
|
|
|
}
|
|
@@ -668,12 +681,7 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- operation, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
- if err != nil {
|
|
|
- return xerr.WithStack(err)
|
|
|
- }
|
|
|
-
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ operation, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -681,8 +689,8 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
for _, cowId := range cowIds {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, cowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, cow, pasturePb.EventType_Weaning, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, cowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Weaning, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -698,7 +706,7 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
Updates(v).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
- cowInfo, err = s.GetCowInfoByCowId(ctx, v.CowId)
|
|
|
+ cowInfo, err = s.GetCowInfoByCowId(ctx, currentUser.PastureId, v.CowId)
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|