Преглед изворни кода

pasture: 牧场端配方下发接受

Yi пре 1 година
родитељ
комит
970b88d629
7 измењених фајлова са 56 додато и 45 уклоњено
  1. 1 1
      go.mod
  2. 2 0
      go.sum
  3. 7 5
      http/handle/group/feed_formula.go
  4. 31 8
      models/feed_template.go
  5. 0 6
      models/group_data.go
  6. 10 22
      module/group.go
  7. 5 3
      service/group/group.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module tmr-watch
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02
 	gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584
 	github.com/360EntSecGroup-Skylar/excelize v1.4.1
 	github.com/Anderson-Lu/gofasion v0.0.0-20190530065914-6a05b679ee48

+ 2 - 0
go.sum

@@ -5,6 +5,8 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq
 gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8 h1:p6Y97HJ0VYAU+hOWBeOFM7k8UUMi+PmPAkmkVoyg+Uk=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20230814081651-e5b0cb4c72c8/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02 h1:e4BzweXQdP/RdWBeqk1sshUuxBI/jcLUCNDtv/G1mXg=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20230823061528-20b02d357f02/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584 h1:5RE5yrMMvnDITrnoX821mFl7dNYfsFA1osDobUV/TDo=
 gitee.com/xuyiping_admin/pkg v0.0.0-20230816061144-c1f079802584/go.mod h1:VQ7WztVDQRlXE1dUu/Yqo3ZdhKsfv7IGJtV+vqNqJVw=
 github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=

+ 7 - 5
http/handle/group/feed_formula.go

@@ -8,9 +8,11 @@ import (
 	"tmr-watch/pkg/e"
 	"tmr-watch/service/group"
 
-	"gitee.com/xuyiping_admin/pkg/valid"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
 
+	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/valid"
 
 	"github.com/gin-gonic/gin"
 )
@@ -26,15 +28,15 @@ func Handle404(c *gin.Context) {
 
 // DistributeFeedFormula 饲料配方下发
 func DistributeFeedFormula(c *gin.Context) {
-	var req models.PastureBodyRequest
-	if err := c.BindJSON(&req); err != nil {
+	var req operationPb.DistributeDataRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
 	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.FeedFormula, valid.Required),
-		valid.Field(&req.FeedFormulaDetail, valid.Required),
+		valid.Field(&req.PastureId, valid.Required),
+		valid.Field(&req.FeedFormulaList, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return

+ 31 - 8
models/feed_template.go

@@ -3,6 +3,8 @@ package models
 import (
 	"time"
 
+	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
+
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/pasture"
 )
 
@@ -34,34 +36,55 @@ type FeedTemplate struct {
 	Backup2      string  `xorm:"backup2" json:"backup2"`
 	IsModify     int32   `xorm:"is_modify" json:"is_modify"`
 	GroupDataId  int64   `xorm:"group_data_id" json:"group_data_id"`
+
+	FeedFormulaDetail []*FeedTemplateDetail `xorm:"-" json:"feed_formula_detail"`
 }
 
 func (f *FeedTemplate) TableName() string {
 	return "feedtemplet"
 }
 
-func NewFeedTemplateByGroup(req *FeedFormula) *FeedTemplate {
-	return &FeedTemplate{
-		PastureId:    req.PastureId,
+func NewFeedTemplateByGroup(req *operationPb.DistributeFeedRequest) *FeedTemplate {
+	res := &FeedTemplate{
+		PastureId:    int64(req.PastureId),
 		TCode:        req.EncodeNumber,
 		TName:        req.Name,
 		TColor:       req.Colour,
 		CCid:         int64(req.CattleCategoryId),
 		CCName:       req.CattleCategoryName,
 		FTType:       req.FormulaTypeName,
-		FTTypeId:     req.FormulaTypeId,
+		FTTypeId:     int32(req.FormulaTypeId),
 		Source:       "集团下发",
 		Remark:       req.Remarks,
 		Enable:       1,
-		Version:      req.Version,
+		Version:      int64(req.Version),
 		SaveTime:     time.Now().Format("2006-01-02 15:04:05"),
 		IsIssue:      0,
 		IssueVersion: 0,
 		IssueId:      0,
-		IsModify:     req.IsModify,
-		GroupDataId:  req.Id,
-		GroupVersion: req.Version,
+		IsModify:     int32(req.IsModify),
+		GroupDataId:  int64(req.Id),
+		GroupVersion: int64(req.Version),
 	}
+	res.FeedFormulaDetail = make([]*FeedTemplateDetail, 0)
+	for _, v := range req.FeedFormulaDetail {
+		res.FeedFormulaDetail = append(res.FeedFormulaDetail, &FeedTemplateDetail{
+			PastureId:      int64(req.PastureId),
+			FId:            int64(v.ForageId),
+			FName:          v.ForageName,
+			FWeight:        float64(v.Weight / 100),
+			IsLockCount:    v.IsLockCowCountRatio,
+			Sort:           v.Sort,
+			FeedGroup:      v.ForageGroupName,
+			PreFtId:        int64(v.PreFit),
+			AutoSecond:     v.StirDelay,
+			AutoSecondName: "",
+			SplitFtPreId:   0,
+			Deviation:      v.AllowError,
+			IsModify:       int32(v.IsModify),
+		})
+	}
+	return res
 }
 
 type FeedTemplateSlice []*FeedTemplate

+ 0 - 6
models/group_data.go

@@ -6,12 +6,6 @@ import (
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 )
 
-type PastureBodyRequest struct {
-	PastureId         int64                `json:"pasture_id"`
-	FeedFormula       []*FeedFormula       `json:"feed_formula"`
-	FeedFormulaDetail []*FeedFormulaDetail `json:"feed_formula_detail"`
-}
-
 type CancelDistributeFeedFormulaRequest struct {
 	PastureId     int64   `json:"pasture_id"`
 	PastureDataId []int64 `json:"pasture_data_id"`

+ 10 - 22
module/group.go

@@ -15,36 +15,24 @@ import (
 )
 
 // DistributeFeedFormula 集团饲料配方下发
-func DistributeFeedFormula(pastureId int64, feedTemplateList []*models.FeedTemplate, feedFormulaDetailList []*models.FeedFormulaDetail) error {
-
+func DistributeFeedFormula(pastureId int64, feedTemplateList []*models.FeedTemplate) error {
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
+
 	for _, feedTemplate := range feedTemplateList {
+		// 过滤掉没有饲料详情的配方
+		if len(feedTemplate.FeedFormulaDetail) <= 0 {
+			continue
+		}
 		if _, err := tx.Table(new(models.FeedTemplate)).Insert(feedTemplate); err != nil {
 			return err
 		}
 		feedFormulaDetail := make([]*models.FeedTemplateDetail, 0)
-		for _, f := range feedFormulaDetailList {
-			feedFormulaDetail = append(feedFormulaDetail, &models.FeedTemplateDetail{
-				PastureId:      pastureId,
-				FtId:           feedTemplate.Id,
-				FId:            f.ForageId,
-				FName:          f.ForageName,
-				FWeight:        float64(f.Weight / 100),
-				IsLockCount:    f.IsLockCowCountRatio,
-				Sort:           f.Sort,
-				FeedGroup:      f.ForageGroupName,
-				PreFtId:        f.Prefit,
-				AutoSecond:     f.StirDelay,
-				AutoSecondName: "",
-				SplitFtPreId:   0,
-				Deviation:      f.AllowError,
-				IsModify:       f.IsModify,
-			})
-		}
-		if len(feedFormulaDetail) <= 0 {
-			continue
+		for _, f := range feedTemplate.FeedFormulaDetail {
+			f.FtId = feedTemplate.Id
+			feedFormulaDetail = append(feedFormulaDetail, f)
 		}
+
 		if _, err := tx.Table(new(models.FeedTemplateDetail)).Insert(feedFormulaDetail); err != nil {
 			return err
 		}

+ 5 - 3
service/group/group.go

@@ -8,16 +8,18 @@ import (
 	"tmr-watch/pkg/logger/zaplog"
 	"tmr-watch/pkg/util"
 
+	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
+
 	"go.uber.org/zap"
 )
 
 // DistributeFeedFormulaService 饲料配方下发牧场端
-func DistributeFeedFormulaService(req *models.PastureBodyRequest) error {
+func DistributeFeedFormulaService(req *operationPb.DistributeDataRequest) error {
 	feedTemplateList := make([]*models.FeedTemplate, 0)
-	for _, b := range req.FeedFormula {
+	for _, b := range req.FeedFormulaList {
 		feedTemplateList = append(feedTemplateList, models.NewFeedTemplateByGroup(b))
 	}
-	return module.DistributeFeedFormula(req.PastureId, feedTemplateList, req.FeedFormulaDetail)
+	return module.DistributeFeedFormula(int64(req.PastureId), feedTemplateList)
 }
 
 // CancelDistributeFeedFormulaService 取消饲料配方下发牧场端