|
@@ -12,6 +12,8 @@ import (
|
|
"strconv"
|
|
"strconv"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
+ "gorm.io/gorm"
|
|
|
|
+
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap"
|
|
|
|
|
|
@@ -81,8 +83,6 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
|
|
}
|
|
}
|
|
|
|
|
|
penMap := model.PenMap
|
|
penMap := model.PenMap
|
|
-
|
|
|
|
- // 验证牧场ID
|
|
|
|
if userModel.AppPasture.Id <= 0 {
|
|
if userModel.AppPasture.Id <= 0 {
|
|
return xerr.Custom("无效的牧场ID")
|
|
return xerr.Custom("无效的牧场ID")
|
|
}
|
|
}
|
|
@@ -94,7 +94,12 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
|
|
if len(row) <= 0 {
|
|
if len(row) <= 0 {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- ts := &pasturePb.EventEnterRequest{}
|
|
|
|
|
|
+ ts := &pasturePb.EventEnterRequest{
|
|
|
|
+ OperationId: 33,
|
|
|
|
+ OperationName: "kpt_admin",
|
|
|
|
+ MessengerId: 33,
|
|
|
|
+ MessengerName: "kpt_admin",
|
|
|
|
+ }
|
|
zaplog.Error("row", zap.Any("row", row))
|
|
zaplog.Error("row", zap.Any("row", row))
|
|
for j, d := range row {
|
|
for j, d := range row {
|
|
switch j {
|
|
switch j {
|
|
@@ -188,6 +193,37 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
|
|
if len(eventEnterList) <= 0 {
|
|
if len(eventEnterList) <= 0 {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- zaplog.Error("eventEnterList", zap.Any("eventEnterList", eventEnterList))
|
|
|
|
- return nil
|
|
|
|
|
|
+
|
|
|
|
+ pastureId := userModel.AppPasture.Id
|
|
|
|
+ if pastureId != 4 {
|
|
|
|
+ pastureId = 4
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return s.ExecExcelData(ctx, pastureId, eventEnterList)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (s *StoreEntry) ExecExcelData(ctx context.Context, pastureId int64, dataList []*pasturePb.EventEnterRequest) error {
|
|
|
|
+ if len(dataList) <= 0 {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
+ for _, data := range dataList {
|
|
|
|
+ var count int64
|
|
|
|
+ if err := tx.Model(new(model.Cow)).
|
|
|
|
+ Where("pasture_id = ?", pastureId).
|
|
|
|
+ Where("ear_number = ?", data.EarNumber).
|
|
|
|
+ Count(&count).Error; err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if count > 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err := s.CreateEnter(ctx, data); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ })
|
|
}
|
|
}
|