|
@@ -19,9 +19,9 @@ import (
|
|
|
)
|
|
|
|
|
|
func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchLavingEventResponse, error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return nil, xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
lavingList := make([]*model.EventCalvingList, 0)
|
|
@@ -30,7 +30,7 @@ func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEvent
|
|
|
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())).
|
|
|
- Where("pasture_id = ?", currentUser.PastureId)
|
|
|
+ Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
if len(req.CowId) > 0 {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("a.cow_id IN ?", cowIds)
|
|
@@ -67,18 +67,18 @@ func (s *StoreEntry) CalvingList(ctx context.Context, req *pasturePb.SearchEvent
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalving) (err error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- cow, err := s.GetCowInfoByCowId(ctx, currentUser.PastureId, int64(req.CowId))
|
|
|
+ cow, err := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, 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, currentUser.PastureId, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("获取操作人员信息失败: %s", err.Error())
|
|
|
}
|
|
@@ -88,15 +88,15 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
defer func() {
|
|
|
if err == nil {
|
|
|
// 母牛事件日志
|
|
|
- cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Calving, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, 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, currentUser.PastureId, int64(v.CowId))
|
|
|
- cowLogs = s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Birth, pasturePb.ExposeEstrusType_Invalid, v)
|
|
|
+ cow, _ = s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, int64(v.CowId))
|
|
|
+ cowLogs = s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Birth, pasturePb.ExposeEstrusType_Invalid, v)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -125,7 +125,7 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
continue
|
|
|
}
|
|
|
// 犊牛信息
|
|
|
- newCalvingCalf := model.NewEventCalvingCalf(currentUser.PastureId, int64(req.CowId), newEventCalving.Id, int64(req.CalvingAt), v)
|
|
|
+ newCalvingCalf := model.NewEventCalvingCalf(userModel.AppPasture.Id, 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 {
|
|
@@ -154,35 +154,35 @@ func (s *StoreEntry) CalvingCreate(ctx context.Context, req *pasturePb.EventCalv
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSameTime) (err error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, currentUser.PastureId, int64(req.CowId))
|
|
|
+ eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, userModel.AppPasture.Id, int64(req.CowId))
|
|
|
if err != nil {
|
|
|
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 {
|
|
|
+ if drugs, err = s.GetDrugsById(ctx, userModel.AppPasture.Id, 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.EventUpdate(drugs, req.Usage, req.Remarks, operationUser, currentUser)
|
|
|
+ eventCowSameTime.EventUpdate(drugs, req.Usage, req.Remarks, operationUser, userModel.SystemUser)
|
|
|
|
|
|
defer func() {
|
|
|
if err == nil {
|
|
|
// 记录牛只事件日志
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, eventCowSameTime.CowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Seme_Time, pasturePb.ExposeEstrusType_Same_Time, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, eventCowSameTime.CowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Seme_Time, pasturePb.ExposeEstrusType_Same_Time, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}()
|
|
@@ -197,19 +197,19 @@ func (s *StoreEntry) SameTimeCreate(ctx context.Context, req *pasturePb.EventSam
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSameTimeBatch) (err error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("异常数据")
|
|
|
}
|
|
|
req.OperationName = operationUser.Name
|
|
|
|
|
|
drugs := &model.Drugs{}
|
|
|
- if drugs, err = s.GetDrugsById(ctx, currentUser.PastureId, int64(req.DrugsId)); err != nil {
|
|
|
+ if drugs, err = s.GetDrugsById(ctx, userModel.AppPasture.Id, int64(req.DrugsId)); err != nil {
|
|
|
zaplog.Error("SameTimeBatch", zap.Any("err", err), zap.Any("req", req))
|
|
|
return xerr.Customf("该药物不存在: %d", req.DrugsId)
|
|
|
}
|
|
@@ -217,7 +217,7 @@ 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, currentUser.PastureId, int64(v))
|
|
|
+ eventCowSameTime, err := s.GetEventCowSameTimeByCowId(ctx, userModel.AppPasture.Id, int64(v))
|
|
|
if err != nil {
|
|
|
zaplog.Error("SameTimeCreate", zap.Any("err", err), zap.Any("req", req))
|
|
|
return xerr.WithStack(err)
|
|
@@ -229,10 +229,10 @@ func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSame
|
|
|
// 记录牛只事件日志
|
|
|
if err == nil {
|
|
|
for _, v := range eventCowSameTimeList {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, v.CowId)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, v.CowId)
|
|
|
cowLogs := s.SubmitEventLog(
|
|
|
ctx,
|
|
|
- currentUser,
|
|
|
+ userModel.AppPasture.Id,
|
|
|
cow,
|
|
|
pasturePb.EventType_Seme_Time,
|
|
|
pasturePb.ExposeEstrusType_Same_Time,
|
|
@@ -257,7 +257,7 @@ func (s *StoreEntry) SameTimeBatch(ctx context.Context, req *pasturePb.EventSame
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
for _, v := range eventCowSameTimeList {
|
|
|
// 更新SameTime
|
|
|
- v.EventUpdate(drugs, req.Usage, req.Remarks, currentUser, operationUser)
|
|
|
+ v.EventUpdate(drugs, req.Usage, req.Remarks, userModel.SystemUser, operationUser)
|
|
|
if err = tx.Model(new(model.EventCowSameTime)).
|
|
|
Select("status", "drugs_id", "unit", "usage", "remarks", "operation_id", "operation_name").
|
|
|
Where("id = ?", v.Id).
|
|
@@ -277,14 +277,14 @@ func (s *StoreEntry) SameTimeList(
|
|
|
req *pasturePb.SearchEventRequest,
|
|
|
pagination *pasturePb.PaginationModel,
|
|
|
) (*pasturePb.SearchSameTimeResponse, error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
cowSameTimeList := make([]*model.EventCowSameTime, 0)
|
|
|
var count int64 = 0
|
|
|
- pref := s.DB.Table(new(model.EventCowSameTime).TableName()).Where("pasture_id = ?", currentUser.PastureId)
|
|
|
+ pref := s.DB.Table(new(model.EventCowSameTime).TableName()).Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
if req.CowId != "" {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
@@ -311,16 +311,16 @@ func (s *StoreEntry) SameTimeList(
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EstrusItemsResponse, error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return nil, xerr.Custom("用户信息错误,请退出重新登录")
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
estrusList := make([]*model.EventEstrus, 0)
|
|
|
var count int64 = 0
|
|
|
pref := s.DB.Table(new(model.EventEstrus).TableName()).
|
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
|
- Where("pasture_id = ?", currentUser.PastureId)
|
|
|
+ Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
if len(req.CowIds) > 0 {
|
|
|
cowIds := strings.Split(util.ArrayInt32ToStrings(req.CowIds, ","), ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
@@ -357,11 +357,11 @@ func (s *StoreEntry) EstrusList(ctx context.Context, req *pasturePb.EstrusItemsR
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.EventEstrus) (err error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.Customf("该用户不存在: %d", req.OperationId)
|
|
|
}
|
|
@@ -376,8 +376,8 @@ func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.Event
|
|
|
return xerr.Custom("牛只信息不存在")
|
|
|
}
|
|
|
|
|
|
- newEventMating := model.NewEventMating(currentUser.PastureId, cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Neck_Ring)
|
|
|
- eventEstrus, ok, err := s.FindEventEstrusByCowId(ctx, currentUser.PastureId, int64(cowId))
|
|
|
+ newEventMating := model.NewEventMating(userModel.AppPasture.Id, cowInfo, time.Now().Unix(), pasturePb.ExposeEstrusType_Neck_Ring)
|
|
|
+ eventEstrus, ok, err := s.FindEventEstrusByCowId(ctx, userModel.AppPasture.Id, int64(cowId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -435,9 +435,9 @@ func (s *StoreEntry) EstrusBatchMating(ctx context.Context, req *pasturePb.Event
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingEventResponse, error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return nil, xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
matingList := make([]*model.EventMating, 0)
|
|
@@ -445,7 +445,7 @@ func (s *StoreEntry) MatingList(ctx context.Context, req *pasturePb.SearchEventR
|
|
|
pref := s.DB.Model(new(model.EventMating)).
|
|
|
Where("mating_result > ?", pasturePb.MatingResult_Invalid).
|
|
|
Where("status = ?", pasturePb.IsShow_No).
|
|
|
- Where("pasture_id = ?", currentUser.PastureId)
|
|
|
+ Where("pasture_id = ?", userModel.AppPasture.Id)
|
|
|
if len(req.CowId) > 0 {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("cow_id IN ?", cowIds)
|
|
@@ -482,18 +482,18 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
for _, cow := range eventCheckModel.CowList {
|
|
|
// 获取牛只最近一次配种信息
|
|
|
- lastEventMating, ok, err := s.FindLastEventMatingByCowId(ctx, eventCheckModel.CurrentUser.PastureId, cow.Id)
|
|
|
+ lastEventMating, ok, err := s.FindLastEventMatingByCowId(ctx, eventCheckModel.UserModel.AppPasture.Id, cow.Id)
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
// 1. 没有配种信息,(第一次参加配种的牛只,并且没有参与同期的牛只 )
|
|
|
if !ok {
|
|
|
- newMating := model.NewEventMatingNaturalEstrus(cow, req, eventCheckModel.CurrentUser)
|
|
|
+ newMating := model.NewEventMatingNaturalEstrus(eventCheckModel.UserModel.AppPasture.Id, cow, req, eventCheckModel.UserModel.SystemUser)
|
|
|
if err = tx.Create(newMating).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
- if err = s.MatingCowUpdate(ctx, cow, eventCheckModel.CurrentUser, req, false); err != nil {
|
|
|
+ if err = s.MatingCowUpdate(ctx, eventCheckModel.UserModel.AppPasture.Id, cow, req, false); err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
continue
|
|
@@ -501,7 +501,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
|
|
|
// 2. 所有有配种数据的牛只
|
|
|
if lastEventMating == nil || lastEventMating.Id <= 0 {
|
|
|
- zaplog.Error("MatingCreate", zap.Any("cow", cow), zap.Any("CurrentUser", eventCheckModel.CurrentUser))
|
|
|
+ zaplog.Error("MatingCreate", zap.Any("cow", cow), zap.Any("UserModel", eventCheckModel.UserModel))
|
|
|
return xerr.Customf("异常牛数据: %d", cow.Id)
|
|
|
}
|
|
|
|
|
@@ -519,7 +519,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
// 2.2. 同期初配
|
|
|
IsMatingUpdate := lastEventMating.IsMatingUpdate()
|
|
|
if IsMatingUpdate {
|
|
|
- lastEventMating.EventUpdate(int64(req.MatingAt), req.FrozenSemenNumber, isReMating, eventCheckModel.OperationUser, eventCheckModel.CurrentUser)
|
|
|
+ lastEventMating.EventUpdate(int64(req.MatingAt), req.FrozenSemenNumber, isReMating, eventCheckModel.OperationUser, eventCheckModel.UserModel.SystemUser)
|
|
|
if err = tx.Model(lastEventMating).
|
|
|
Select("mating_at", "status", "reality_day", "frozen_semen_number", "operation_id", "operation_name", "message_id", "message_name").
|
|
|
Where("id = ?", lastEventMating.Id).
|
|
@@ -540,8 +540,8 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
// 先创建一条新的配种数据
|
|
|
- newMating := model.NewEventMating(eventCheckModel.CurrentUser.PastureId, cow, int64(req.MatingAt), req.ExposeEstrusType)
|
|
|
- newMating.EventUpdate(int64(req.MatingAt), req.FrozenSemenNumber, isReMating, eventCheckModel.OperationUser, eventCheckModel.CurrentUser)
|
|
|
+ newMating := model.NewEventMating(eventCheckModel.UserModel.AppPasture.Id, cow, int64(req.MatingAt), req.ExposeEstrusType)
|
|
|
+ newMating.EventUpdate(int64(req.MatingAt), req.FrozenSemenNumber, isReMating, eventCheckModel.OperationUser, eventCheckModel.UserModel.SystemUser)
|
|
|
if err = tx.Model(newMating).Create(newMating).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -553,7 +553,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
}
|
|
|
|
|
|
// 牛只基本中配种信息更新
|
|
|
- if err = s.MatingCowUpdate(ctx, cow, eventCheckModel.CurrentUser, req, isReMating); err != nil {
|
|
|
+ if err = s.MatingCowUpdate(ctx, eventCheckModel.UserModel.AppPasture.Id, cow, req, isReMating); err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
}
|
|
@@ -580,7 +580,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) MatingCowUpdate(ctx context.Context, cow *model.Cow, currentUser *model.SystemUser, req *pasturePb.EventMating, isReMating bool) error {
|
|
|
+func (s *StoreEntry) MatingCowUpdate(ctx context.Context, pastureId int64, cow *model.Cow, req *pasturePb.EventMating, isReMating bool) error {
|
|
|
// 牛只基本中配种信息更新
|
|
|
cow.EventMatingUpdate(int64(req.MatingAt), req.FrozenSemenNumber, isReMating)
|
|
|
if err := s.DB.Model(cow).
|
|
@@ -590,7 +590,7 @@ func (s *StoreEntry) MatingCowUpdate(ctx context.Context, cow *model.Cow, curren
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
// 记录日志
|
|
|
- cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Mating, req.ExposeEstrusType, req)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, pastureId, cow, pasturePb.EventType_Mating, req.ExposeEstrusType, req)
|
|
|
if err := s.DB.Table(cowLogs.TableName()).Create(cowLogs).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -598,9 +598,9 @@ func (s *StoreEntry) MatingCowUpdate(ctx context.Context, cow *model.Cow, curren
|
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeaningBatchRequest) (err error) {
|
|
|
- currentUser, err := s.GetCurrentSystemUser(ctx)
|
|
|
+ userModel, err := s.GetUserModel(ctx)
|
|
|
if err != nil {
|
|
|
- return xerr.Custom("当前用户信息错误,请退出重新登录")
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
if len(req.Item) <= 0 {
|
|
@@ -621,7 +621,7 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- operation, err := s.GetSystemUserById(ctx, currentUser.PastureId, int64(req.OperationId))
|
|
|
+ operation, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -629,8 +629,8 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
for _, cowId := range cowIds {
|
|
|
- cow, _ := s.GetCowInfoByCowId(ctx, currentUser.PastureId, cowId)
|
|
|
- cowLogs := s.SubmitEventLog(ctx, currentUser, cow, pasturePb.EventType_Weaning, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
+ cow, _ := s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, cowId)
|
|
|
+ cowLogs := s.SubmitEventLog(ctx, userModel.AppPasture.Id, cow, pasturePb.EventType_Weaning, pasturePb.ExposeEstrusType_Invalid, req)
|
|
|
s.DB.Table(cowLogs.TableName()).Create(cowLogs)
|
|
|
}
|
|
|
}
|
|
@@ -639,14 +639,14 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
cowInfo := &model.Cow{}
|
|
|
for _, v := range eventWeaningList {
|
|
|
- v.EventUpdate(int64(req.WeaningAt), req.Remarks, req.PenId, operation, currentUser)
|
|
|
+ v.EventUpdate(int64(req.WeaningAt), req.Remarks, req.PenId, operation, userModel.SystemUser)
|
|
|
if err = tx.Model(new(model.EventWeaning)).
|
|
|
Select("status", "reality_day", "operation_id", "operation_name", "message_id", "message_name", "remarks", "after_pen_id").
|
|
|
Where("id = ?", v.Id).
|
|
|
Updates(v).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
- cowInfo, err = s.GetCowInfoByCowId(ctx, currentUser.PastureId, v.CowId)
|
|
|
+ cowInfo, err = s.GetCowInfoByCowId(ctx, userModel.AppPasture.Id, v.CowId)
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
@@ -659,8 +659,9 @@ func (s *StoreEntry) WeaningBatch(ctx context.Context, req *pasturePb.EventWeani
|
|
|
}
|
|
|
// 创建牛只的体重记录
|
|
|
newEventWeight := model.NewEventWeight(
|
|
|
+ userModel.AppPasture.Id,
|
|
|
cowInfo,
|
|
|
- currentUser,
|
|
|
+ userModel.SystemUser,
|
|
|
int32(cowWeightMap[v.CowId]*1000),
|
|
|
0,
|
|
|
&pasturePb.EventWeight{
|