浏览代码

feed: 牧场饲料同步

Yi 1 年之前
父节点
当前提交
54a49be48b
共有 7 个文件被更改,包括 149 次插入7 次删除
  1. 0 1
      http/handle/api/ops.go
  2. 57 2
      http/handle/group/feed_formula.go
  3. 3 1
      http/routers/group_api.go
  4. 34 0
      models/feed.go
  5. 14 1
      models/group_data.go
  6. 21 1
      module/group.go
  7. 20 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{}) {

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

@@ -67,6 +67,30 @@ func CancelDistributeFeedFormula(c *gin.Context) {
 	})
 }
 
+// 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
@@ -90,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
@@ -119,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}

+ 3 - 1
http/routers/group_api.go

@@ -15,8 +15,10 @@ 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/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/list", group.FeedFormulaList)                          // 获取配方列表
+		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)           // 撒料统计

+ 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"
+}

+ 14 - 1
models/group_data.go

@@ -166,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"`
@@ -185,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"`

+ 21 - 1
module/group.go

@@ -305,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
@@ -325,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 {

+ 20 - 1
service/group/group.go

@@ -55,7 +55,8 @@ func FeedFormulaIsModifyService(req *models.PastureFeedFormulaIsModifyRequest) e
 	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,
@@ -72,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{