Ver código fonte

file: upload update

Yi 1 mês atrás
pai
commit
65f3c1e800
1 arquivos alterados com 41 adições e 5 exclusões
  1. 41 5
      module/backend/upload_file.go

+ 41 - 5
module/backend/upload_file.go

@@ -12,6 +12,8 @@ import (
 	"strconv"
 	"time"
 
+	"gorm.io/gorm"
+
 	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
 	"go.uber.org/zap"
 
@@ -81,8 +83,6 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
 	}
 
 	penMap := model.PenMap
-
-	// 验证牧场ID
 	if userModel.AppPasture.Id <= 0 {
 		return xerr.Custom("无效的牧场ID")
 	}
@@ -94,7 +94,12 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
 		if len(row) <= 0 {
 			continue
 		}
-		ts := &pasturePb.EventEnterRequest{}
+		ts := &pasturePb.EventEnterRequest{
+			OperationId:   33,
+			OperationName: "kpt_admin",
+			MessengerId:   33,
+			MessengerName: "kpt_admin",
+		}
 		zaplog.Error("row", zap.Any("row", row))
 		for j, d := range row {
 			switch j {
@@ -188,6 +193,37 @@ func (s *StoreEntry) ImportExcel(ctx context.Context, data [][]string) error {
 	if len(eventEnterList) <= 0 {
 		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
+	})
 }