|
@@ -6,9 +6,7 @@ import (
|
|
|
"net/http"
|
|
|
|
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
- "go.uber.org/zap"
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
@@ -21,49 +19,9 @@ func (s *StoreEntry) DeathBatch(ctx context.Context, req *pasturePb.EventDeathBa
|
|
|
if len(req.Items) <= 0 {
|
|
|
return xerr.Custom("请选择相关牛只")
|
|
|
}
|
|
|
-
|
|
|
- newEventDeathList := make([]*model.EventDeathModel, 0)
|
|
|
- for _, item := range req.Items {
|
|
|
- cow, err := s.GetCowInfoByEarNumber(ctx, userModel.AppPasture.Id, item.EarNumber)
|
|
|
- if err != nil {
|
|
|
- zaplog.Error("DeathBatch", zap.Any("item", item), zap.Any("err", err))
|
|
|
- return xerr.Customf("获取牛只信息失败: %s", item.EarNumber)
|
|
|
- }
|
|
|
-
|
|
|
- if name, ok := s.DeadReasonMap()[item.DeathReasonKind]; ok {
|
|
|
- item.DeathReasonName = name
|
|
|
- }
|
|
|
-
|
|
|
- operationUser, err := s.GetSystemUserById(ctx, int64(item.OperationId))
|
|
|
- if err != nil {
|
|
|
- zaplog.Error("DeathBatch", zap.Any("item", item), zap.Any("err", err))
|
|
|
- return xerr.Customf("获取操作人员信息失败: %d", item.OperationId)
|
|
|
- }
|
|
|
-
|
|
|
- if name, ok := s.CowDeathDestinationMap()[item.DeathDestinationKind]; ok {
|
|
|
- item.DeathDestinationName = name
|
|
|
- }
|
|
|
-
|
|
|
- newEventDeath := model.NewEventDeath(userModel.AppPasture.Id, cow, item, userModel.SystemUser, operationUser)
|
|
|
- eventDeathModel := &model.EventDeathModel{
|
|
|
- Cow: cow,
|
|
|
- EventDeath: newEventDeath,
|
|
|
- NeckRing: nil,
|
|
|
- CalvingCalf: nil,
|
|
|
- }
|
|
|
-
|
|
|
- // 犊牛死亡更新
|
|
|
- if cow.DayAge <= model.CalfDefaultDayAge {
|
|
|
- calvingCalf, ok := s.IsExistCalvingCalf(userModel.AppPasture.Id, cow.Id)
|
|
|
- if ok && calvingCalf != nil {
|
|
|
- eventDeathModel.CalvingCalf = calvingCalf
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if neckRing, ok := s.NeckRingIsExist(userModel.AppPasture.Id, item.EarNumber); ok && neckRing != nil {
|
|
|
- eventDeathModel.NeckRing = neckRing
|
|
|
- }
|
|
|
- newEventDeathList = append(newEventDeathList, eventDeathModel)
|
|
|
+ newEventDeathList, err := s.DeathCheck(ctx, req, userModel)
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
@@ -92,8 +50,16 @@ func (s *StoreEntry) DeathBatch(ctx context.Context, req *pasturePb.EventDeathBa
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- newNeckRingBindLog := model.NewNeckRingBindLog(userModel.AppPasture.Id, item.NeckRing.NeckRingNumber, item.Cow, userModel.SystemUser, "死亡解绑")
|
|
|
- if err = tx.Model(new(model.NeckRingBindLog)).Create(newNeckRingBindLog).Error; err != nil {
|
|
|
+ newNeckRingBindLog := model.NewNeckRingBindLog(
|
|
|
+ userModel.AppPasture.Id,
|
|
|
+ item.NeckRing.NeckRingNumber,
|
|
|
+ item.Cow,
|
|
|
+ userModel.SystemUser,
|
|
|
+ "死亡解绑",
|
|
|
+ )
|
|
|
+
|
|
|
+ if err = tx.Model(new(model.NeckRingBindLog)).
|
|
|
+ Create(newNeckRingBindLog).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
}
|