Explorar o código

feed: 配方不可修改

Yi hai 1 ano
pai
achega
0899a8d53b

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

@@ -30,7 +30,28 @@ func DistributeFeedFormula(c *gin.Context) {
 	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
+	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)
+	}
+
+	if err := group.FeedFormulaIsModifyService(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
+		"success": true,
+	})
 }
 
 // AnalysisAccuracy 准确性分析

+ 1 - 0
http/routers/group_api.go

@@ -14,6 +14,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("dashboard/accuracy_data", group.AnalysisAccuracy)         // 混料准确率数据
 		apiPasture.POST("dashboard/process_analysis", group.ProcessAnalysis)       // 过程分析
 		apiPasture.POST("dashboard/sprinkle_statistics", group.SprinkleStatistics) // 撒料统计

+ 2 - 0
migration/v0001_feedtemplet.sql

@@ -0,0 +1,2 @@
+ALTER TABLE `feedtemplet`
+    ADD COLUMN `is_modify` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否可修改 0 无效 1 是 2 否';

+ 2 - 0
models/feed_templet.go

@@ -9,6 +9,7 @@ type FeedTemplate struct {
 	CCid         int64   `xorm:"ccid"`
 	CCName       string  `xorm:"ccname"`
 	FTType       string  `xorm:"fttype"`
+	FTTypeId     int32   `json:"fttypeid"`
 	Source       string  `xorm:"source"`
 	Remark       string  `xorm:"remark"`
 	Enable       int32   `xorm:"enable"`
@@ -24,6 +25,7 @@ type FeedTemplate struct {
 	IssueId      int64   `xorm:"issueid"`
 	Backup1      string  `xorm:"backup1"`
 	Backup2      string  `xorm:"backup2"`
+	IsModify     int32   `xorm:"is_modify"`
 }
 
 func (f *FeedTemplate) TableName() string {

+ 6 - 0
models/group_data.go

@@ -31,6 +31,12 @@ type FeedFormula struct {
 	UpdatedAt          int64  `json:"updated_at"`
 }
 
+type PastureFeedFormulaIsModifyRequest struct {
+	PastureId     int64 `json:"pasture_id"`
+	FeedFormulaId int64 `json:"feed_formula_id"`
+	IsModify      int32 `json:"is_modify"`
+}
+
 type AnalysisAccuracyRequest struct {
 	CattleParentCategoryId int32  `json:"cattle_Parent_Category_Id"`
 	FeedFormulaId          int32  `json:"feed_formula_id"`

+ 18 - 1
module/group.go

@@ -12,6 +12,23 @@ const (
 	IsNo = 2
 )
 
+// DistributeFeedFormula 集团饲料配方下发
+func DistributeFeedFormula(res []*models.FeedTemplate) error {
+	if _, err := restful.Engine.Insert(res); 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).
+		Update(map[string]interface{}{"is_modify": req.IsModify}); err != nil {
+		return err
+	}
+	return nil
+}
+
 // MixedFodderData 混料准确率和撒料准确率
 func MixedFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFodderDataList, error) {
 	res := make([]*models.MixedFodderDataList, 0)
@@ -38,7 +55,7 @@ func MixedFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFodder
 	return res, nil
 }
 
-// mixedFodderCorrectData 混料正确率
+// MixedFodderCorrectData 混料正确率
 // SELECT
 //SUM(de.`havebuttom`) AS "已混料操作数",de.date,
 //IFNULL(SUM(IF(ABS(de.`actualweightminus`-de.`lweight`)<=de.`feedallowratio` AND de.`actualweightminus`<>0,1,0)),0) AS "混料正确数"

+ 8 - 9
service/group/group.go

@@ -5,7 +5,6 @@ import (
 	"sort"
 	"strings"
 	"time"
-	"tmr-watch/http/handle/restful"
 	"tmr-watch/models"
 	"tmr-watch/module"
 	"tmr-watch/pkg/util"
@@ -22,24 +21,24 @@ func DistributeFeedFormulaService(req *models.PastureBodyRequest) error {
 			TColor:       b.Colour,
 			CCid:         int64(b.CattleCategoryId),
 			CCName:       b.CattleCategoryName,
-			FTType:       "",
-			Source:       "",
+			FTType:       b.FormulaTypeName,
+			FTTypeId:     b.FormulaTypeId,
+			Source:       "集团下发",
 			Remark:       b.Remarks,
 			Enable:       1,
-			Weight:       0,
-			DryWeight:    0,
 			Version:      b.Version,
 			SaveTime:     time.Now().Format("2006-01-02 15:04:05"),
 			IsIssue:      0,
 			IssueVersion: 0,
 			IssueId:      0,
+			IsModify:     b.IsModify,
 		}
 	}
+	return module.DistributeFeedFormula(feedTemplateList)
+}
 
-	if _, err := restful.Engine.Insert(feedTemplateList); err != nil {
-		return err
-	}
-	return nil
+func FeedFormulaIsModifyService(req *models.PastureFeedFormulaIsModifyRequest) error {
+	return module.FeedFormulaIsModify(req)
 }
 
 // AnalysisAccuracyService 首页准确率分析