Przeglądaj źródła

feed: 配方数据同步集团端

Yi 1 rok temu
rodzic
commit
f77ccd3af3

+ 29 - 0
http/handle/group/feed_formula.go

@@ -66,6 +66,35 @@ func FeedFormulaIsModify(c *gin.Context) {
 	})
 }
 
+func FeedFormulaList(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.FeedFormulaListRequest
+	if err := c.BindJSON(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if req.PastureId <= 0 {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if req.Page <= 0 {
+		req.Page = 1
+	}
+
+	if req.PageSize <= 0 {
+		req.PageSize = 50
+	}
+
+	data, err := group.FeedFormulaList(&req)
+	if err != nil {
+		appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
+		return
+	}
+	appG.Response(http.StatusOK, e.SUCCESS, data)
+}
+
 // AnalysisAccuracy 准确性分析
 func AnalysisAccuracy(c *gin.Context) {
 	appG := app.Gin{C: c}

+ 1 - 0
http/routers/group_api.go

@@ -15,6 +15,7 @@ func GroupAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		apiPasture := s.Group("/pasture")
 		apiPasture.POST("feed_formula/distribute", group.DistributeFeedFormula)       // 饲料配方下发
 		apiPasture.POST("feed_formula/is_modify", group.FeedFormulaIsModify)          // 饲料配方是否可修改
+		apiPasture.POST("feed_formula/list", group.FeedFormulaList)                   // 获取配方列表
 		apiPasture.POST("dashboard/accuracy_data", group.AnalysisAccuracy)            // 混料准确率数据
 		apiPasture.POST("dashboard/process_analysis", group.ProcessAnalysis)          // 过程分析
 		apiPasture.POST("dashboard/sprinkle_statistics", group.SprinkleStatistics)    // 撒料统计

+ 19 - 0
models/group_data.go

@@ -164,3 +164,22 @@ type GroupCommonResponse struct {
 	Msg  string      `json:"msg"`
 	Data interface{} `json:"data"`
 }
+
+type FeedFormulaListRequest struct {
+	PastureId int32 `json:"pasture_id"`
+	Page      int32 `json:"page"`
+	PageSize  int32 `json:"page_size"`
+}
+
+type FeedFormulaListResponse struct {
+	Code int32            `json:"code"`
+	Msg  string           `json:"msg"`
+	Data *FeedFormulaData `json:"data"`
+}
+
+type FeedFormulaData struct {
+	Total    int32           `json:"total"`
+	Page     int32           `json:"page"`
+	PageSize int32           `json:"page_size"`
+	List     []*FeedTemplate `json:"list"`
+}

+ 16 - 0
module/group.go

@@ -334,3 +334,19 @@ func CowCategoryDelete(pastureId, groupId int64) error {
 	}
 	return nil
 }
+
+func FeedTemplateList(req *models.FeedFormulaListRequest) ([]*models.FeedTemplate, int64, error) {
+	var (
+		res   []*models.FeedTemplate
+		total int64
+		err   error
+	)
+
+	total, err = restful.Engine.Table(new(models.FeedTemplate).TableName()).
+		Where("pastureid = ?", req.PastureId).
+		Limit(int(req.PageSize), int(req.Page-1)*int(req.PageSize)).Count(&res)
+	if err != nil {
+		return nil, 0, err
+	}
+	return res, total, nil
+}

+ 22 - 0
service/group/group.go

@@ -2,6 +2,7 @@ package group
 
 import (
 	"fmt"
+	"net/http"
 	"sort"
 	"time"
 	"tmr-watch/models"
@@ -44,6 +45,27 @@ func FeedFormulaIsModifyService(req *models.PastureFeedFormulaIsModifyRequest) e
 	return module.FeedFormulaIsModify(req)
 }
 
+func FeedFormulaList(req *models.FeedFormulaListRequest) (*models.FeedFormulaListResponse, error) {
+	res := &models.FeedFormulaListResponse{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &models.FeedFormulaData{
+			Total:    0,
+			Page:     req.Page,
+			PageSize: req.PageSize,
+			List:     make([]*models.FeedTemplate, 0),
+		},
+	}
+
+	dataList, total, err := module.FeedTemplateList(req)
+	if err != nil {
+		return nil, err
+	}
+	res.Data.Total = int32(total)
+	res.Data.List = dataList
+	return res, nil
+}
+
 // AnalysisAccuracyService 首页准确率分析
 func AnalysisAccuracyService(req *models.AnalysisAccuracyRequest) (*models.AnalysisAccuracyResponse, error) {
 	response := &models.AnalysisAccuracyResponse{