Browse Source

Merge branch 'feature/tmr-group' of baishaojie/tmrgo into develop

xuyiping 1 year ago
parent
commit
ec1255bbed
7 changed files with 206 additions and 17 deletions
  1. 0 1
      http/handle/api/ops.go
  2. 81 2
      http/handle/group/feed_formula.go
  3. 14 11
      http/routers/group_api.go
  4. 34 0
      models/feed.go
  5. 19 1
      models/group_data.go
  6. 30 1
      module/group.go
  7. 28 1
      service/group/group.go

+ 0 - 1
http/handle/api/ops.go

@@ -914,7 +914,6 @@ func GetArrList(c *gin.Context) {
 		queryData, err := getDataBySqlT(sql, offset, pagecount, returntype, s_params, tx)
 		if err != nil {
 			appG.Response(http.StatusOK, e.ERROR, err.Error())
-
 		} else {
 			paramslist1 := strings.Split(p1, ",")
 			for index, value := range queryData.(map[string]interface{})["list"].([]map[string]interface{}) {

+ 81 - 2
http/handle/group/feed_formula.go

@@ -43,6 +43,54 @@ 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,
+	})
+}
+
+// EditRecodeFeedFormula 饲料配方修改记录
+func EditRecodeFeedFormula(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
@@ -66,9 +114,10 @@ func FeedFormulaIsModify(c *gin.Context) {
 	})
 }
 
-func FeedFormulaList(c *gin.Context) {
+// FeedFormulaAsyncList 获取配方列表
+func FeedFormulaAsyncList(c *gin.Context) {
 	appG := app.Gin{C: c}
-	var req models.FeedFormulaListRequest
+	var req models.FeedListRequest
 	if err := c.BindJSON(&req); err != nil {
 		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
 		return
@@ -95,6 +144,36 @@ func FeedFormulaList(c *gin.Context) {
 	appG.Response(http.StatusOK, e.SUCCESS, data)
 }
 
+// FeedAsyncList 获取饲料
+func FeedAsyncList(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.FeedListRequest
+	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.FeedList(&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}

+ 14 - 11
http/routers/group_api.go

@@ -13,16 +13,19 @@ 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/edit_recode/list", group.EditRecodeFeedFormula)        // 饲料配方修改记录
+		apiPasture.POST("feed_formula/is_modify", group.FeedFormulaIsModify)                 // 饲料配方是否可修改
+		apiPasture.POST("feed_formula/async", group.FeedFormulaAsyncList)                    // 获取配方列表
+		apiPasture.POST("feed/async", group.FeedAsyncList)                                   // 获取饲料列表
+		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)                                       // 配方使用概况
 	}
 }

+ 34 - 0
models/feed.go

@@ -0,0 +1,34 @@
+package models
+
+type Feed struct {
+	Id             int64   `xorm:"id" json:"id"`
+	PastureId      int64   `xorm:"pastureid" json:"pasture_id"`
+	FeedCode       string  `xorm:"feedcode" json:"feed_code"`
+	FName          string  `xorm:"fname" json:"f_name"`
+	FClass         string  `xorm:"fclass" json:"f_class"`
+	FClassId       int64   `xorm:"fclassid" json:"f_class_id"`
+	AllowRatio     int64   `xorm:"allowratio" json:"allow_ratio"`
+	PrintGroupId   int64   `xorm:"printgroupid" json:"print_group_id"`
+	PrintGroup     string  `xorm:"printgroup" json:"print_group"`
+	UnitWeight     int64   `xorm:"unitweight" json:"unit_weight"`
+	UPrice         float64 `xorm:"uprice" json:"u_price"`
+	Dry            float64 `xorm:"dry" json:"dry"`
+	AutoZone       int64   `xorm:"autozone" json:"auto_zone"`
+	AutoSecond     int64   `xorm:"autosecond" json:"auto_second"`
+	AutoSecondName string  `xorm:"autosecondname" json:"auto_second_name"`
+	ConfirmStart   int32   `xorm:"confirmstart" json:"confirm_start"`
+	TrgAddress     int32   `xorm:"trgaddress" json:"trg_address"`
+	SmtMrId        int64   `xorm:"smt_mr_id" json:"smt_mr_id"`
+	SmtMrName      string  `xorm:"smtmrname" json:"smt_mr_name"`
+	Sort           int32   `xorm:"sort" json:"sort"`
+	Enable         int32   `xorm:"enable" json:"enable"`
+	Jmp            int32   `xorm:"jmp" json:"jmp"`
+	Source         string  `xorm:"source"`
+	Backup1        string  `xorm:"backup1" json:"backup1"`
+	Backup2        string  `xorm:"backup2" json:"backup2"`
+	Backup3        string  `xorm:"backup3" json:"backup3"`
+}
+
+func (f *Feed) TableName() string {
+	return "feed"
+}

+ 19 - 1
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"`
@@ -161,7 +166,7 @@ type GroupCommonResponse struct {
 	Data interface{} `json:"data"`
 }
 
-type FeedFormulaListRequest struct {
+type FeedListRequest struct {
 	PastureId int32 `json:"pasture_id"`
 	Page      int32 `json:"page"`
 	PageSize  int32 `json:"page_size"`
@@ -180,6 +185,19 @@ type FeedFormulaData struct {
 	List     []*FeedTemplate `json:"list"`
 }
 
+type FeedListResponse struct {
+	Code int32     `json:"code"`
+	Msg  string    `json:"msg"`
+	Data *FeedData `json:"data"`
+}
+
+type FeedData struct {
+	Total    int32   `json:"total"`
+	Page     int32   `json:"page"`
+	PageSize int32   `json:"page_size"`
+	List     []*Feed `json:"list"`
+}
+
 type FeedFormulaUsageRequest struct {
 	PastureId     int32  `json:"pasture_id"`
 	FeedFormulaId int32  `json:"feed_formula_id"`

+ 30 - 1
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).
@@ -296,7 +305,7 @@ func CowCategoryDelete(pastureId, groupId int64) error {
 	return nil
 }
 
-func FeedTemplateList(req *models.FeedFormulaListRequest) ([]*models.FeedTemplate, int64, error) {
+func FeedTemplateList(req *models.FeedListRequest) ([]*models.FeedTemplate, int64, error) {
 	var (
 		res   []*models.FeedTemplate
 		total int64
@@ -316,6 +325,26 @@ func FeedTemplateList(req *models.FeedFormulaListRequest) ([]*models.FeedTemplat
 	return res, total, nil
 }
 
+func FeedList(req *models.FeedListRequest) ([]*models.Feed, int64, error) {
+	var (
+		res   []*models.Feed
+		total int64
+		err   error
+	)
+	newSession := restful.Engine.NewSession()
+	total, err = newSession.Table(new(models.Feed).TableName()).
+		Where("pastureid = ?", req.PastureId).Count(&res)
+	if err != nil {
+		return nil, 0, err
+	}
+
+	if err = newSession.Table(new(models.Feed).TableName()).Limit(int(req.PageSize), int(req.Page-1)*int(req.PageSize)).Find(&res); err != nil {
+		return nil, 0, err
+	}
+
+	return res, total, nil
+}
+
 func FeedTemplateUsageDetail(req *models.FeedFormulaUsageRequest) (*models.FeedFormulaUsageResponse, error) {
 	mixedDetail, err := getMixedDetail(req.PastureId, req.FeedFormulaId, req.StartTime, req.EndTime)
 	if err != nil {

+ 28 - 1
service/group/group.go

@@ -43,11 +43,20 @@ 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)
 }
 
-func FeedFormulaList(req *models.FeedFormulaListRequest) (*models.FeedFormulaData, error) {
+// FeedFormulaList 配方列表数据
+func FeedFormulaList(req *models.FeedListRequest) (*models.FeedFormulaData, error) {
 	res := &models.FeedFormulaData{
 		Total:    0,
 		Page:     req.Page,
@@ -64,6 +73,24 @@ func FeedFormulaList(req *models.FeedFormulaListRequest) (*models.FeedFormulaDat
 	return res, nil
 }
 
+// FeedList 饲料列表数据
+func FeedList(req *models.FeedListRequest) (*models.FeedData, error) {
+	res := &models.FeedData{
+		Total:    0,
+		Page:     req.Page,
+		PageSize: req.PageSize,
+		List:     make([]*models.Feed, 0),
+	}
+
+	dataList, total, err := module.FeedList(req)
+	if err != nil {
+		return nil, err
+	}
+	res.Total = int32(total)
+	res.List = dataList
+	return res, nil
+}
+
 // AnalysisAccuracyService 首页准确率分析
 func AnalysisAccuracyService(req *models.AnalysisAccuracyRequest) (*models.AnalysisAccuracyResponse, error) {
 	response := &models.AnalysisAccuracyResponse{