|
@@ -8,6 +8,10 @@ import (
|
|
|
"tmr-watch/pkg/e"
|
|
|
"tmr-watch/service/group"
|
|
|
|
|
|
+ "gitee.com/xuyiping_admin/pkg/valid"
|
|
|
+
|
|
|
+ "gitee.com/xuyiping_admin/pkg/apierr"
|
|
|
+
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
@@ -22,29 +26,26 @@ func Handle404(c *gin.Context) {
|
|
|
|
|
|
// DistributeFeedFormula 饲料配方下发
|
|
|
func DistributeFeedFormula(c *gin.Context) {
|
|
|
- appG := app.Gin{C: c}
|
|
|
var req models.PastureBodyRequest
|
|
|
if err := c.BindJSON(&req); err != nil {
|
|
|
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+ apierr.AbortBadRequest(c, http.StatusBadRequest, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if len(req.FeedFormula) <= 0 {
|
|
|
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if len(req.FeedFormulaDetail) <= 0 {
|
|
|
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
|
|
|
+ if err := valid.ValidateStruct(&req,
|
|
|
+ valid.Field(&req.FeedFormula, valid.Required),
|
|
|
+ valid.Field(&req.FeedFormulaDetail, valid.Required),
|
|
|
+ ); err != nil {
|
|
|
+ apierr.AbortBadRequest(c, http.StatusBadRequest, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if err := group.DistributeFeedFormulaService(&req); err != nil {
|
|
|
- appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
|
|
|
+ apierr.ClassifiedAbort(c, err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
|
|
|
+ c.JSON(http.StatusOK, map[string]bool{
|
|
|
"success": true,
|
|
|
})
|
|
|
}
|