Browse Source

feed: 集团取消配方下发

Yi 1 year ago
parent
commit
d5ca5a9d20
5 changed files with 58 additions and 11 deletions
  1. 24 0
      http/handle/group/feed_formula.go
  2. 12 11
      http/routers/group_api.go
  3. 5 0
      models/group_data.go
  4. 9 0
      module/group.go
  5. 8 0
      service/group/group.go

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

@@ -43,6 +43,30 @@ func DistributeFeedFormula(c *gin.Context) {
 	})
 }
 
+// CancelDistributeFeedFormula 饲料取消配方下发
+func CancelDistributeFeedFormula(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.CancelDistributeFeedFormulaRequest
+	if err := c.BindJSON(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if len(req.PastureDataId) <= 0 {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if err := group.CancelDistributeFeedFormulaService(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
+		"success": true,
+	})
+}
+
 func FeedFormulaIsModify(c *gin.Context) {
 	appG := app.Gin{C: c}
 	var req models.PastureFeedFormulaIsModifyRequest

+ 12 - 11
http/routers/group_api.go

@@ -13,16 +13,17 @@ func GroupAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		}
 		s.NoRoute(group.Handle404)
 		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)    // 撒料统计
-		apiPasture.POST("forage_category/distribute", group.ForageCategoryDistribute) // 饲料分类下发
-		apiPasture.POST("forage_category/delete", group.ForageCategoryDelete)         // 饲料分类删除
-		apiPasture.POST("cattle_category/distribute", group.CowCategoryDistribute)    // 畜牧分类下发
-		apiPasture.POST("cattle_category/delete", group.CowCategoryDelete)            // 畜牧分类删除
-		apiPasture.POST("feed/usage", group.FeedUsage)                                // 配方使用概况
+		apiPasture.POST("feed_formula/distribute", group.DistributeFeedFormula)              // 饲料配方下发
+		apiPasture.POST("feed_formula/cancel/distribute", group.CancelDistributeFeedFormula) // 取消饲料配方下发
+		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)           // 撒料统计
+		apiPasture.POST("forage_category/distribute", group.ForageCategoryDistribute)        // 饲料分类下发
+		apiPasture.POST("forage_category/delete", group.ForageCategoryDelete)                // 饲料分类删除
+		apiPasture.POST("cattle_category/distribute", group.CowCategoryDistribute)           // 畜牧分类下发
+		apiPasture.POST("cattle_category/delete", group.CowCategoryDelete)                   // 畜牧分类删除
+		apiPasture.POST("feed/usage", group.FeedUsage)                                       // 配方使用概况
 	}
 }

+ 5 - 0
models/group_data.go

@@ -9,6 +9,11 @@ type PastureBodyRequest struct {
 	Body      []*FeedFormula `json:"body"`
 }
 
+type CancelDistributeFeedFormulaRequest struct {
+	PastureId     int64   `json:"pasture_id"`
+	PastureDataId []int64 `json:"pasture_data_id"`
+}
+
 type FeedFormula struct {
 	Id                 int64  `json:"id"`
 	Name               string `json:"name"`

+ 9 - 0
module/group.go

@@ -22,6 +22,15 @@ func DistributeFeedFormula(res []*models.FeedTemplate) error {
 	return nil
 }
 
+// CancelDistributeFeedFormula 集团饲料配方取消下发
+func CancelDistributeFeedFormula(pastureId int64, ids []int64) error {
+	if _, err := restful.Engine.Table(new(models.FeedTemplate)).
+		Where("id IN ?", ids).Where("pasture_id = ?", pastureId).Update(map[string]interface{}{"enable": 2, "is_modify": 2}); err != nil {
+		return err
+	}
+	return nil
+}
+
 func FeedFormulaIsModify(req *models.PastureFeedFormulaIsModifyRequest) error {
 	if _, err := restful.Engine.Table(new(models.FeedTemplate)).Cols("is_modify").
 		Where("id = ?", req.FeedFormulaId).And("pastureid = ?", req.PastureId).

+ 8 - 0
service/group/group.go

@@ -43,6 +43,14 @@ func DistributeFeedFormulaService(req *models.PastureBodyRequest) error {
 	return module.DistributeFeedFormula(feedTemplateList)
 }
 
+// CancelDistributeFeedFormulaService 取消饲料配方下发牧场端
+func CancelDistributeFeedFormulaService(req *models.CancelDistributeFeedFormulaRequest) error {
+	if len(req.PastureDataId) <= 0 {
+		return nil
+	}
+	return module.CancelDistributeFeedFormula(req.PastureId, req.PastureDataId)
+}
+
 func FeedFormulaIsModifyService(req *models.PastureFeedFormulaIsModifyRequest) error {
 	return module.FeedFormulaIsModify(req)
 }