123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- package group
- import (
- "net/http"
- "tmr-watch/middleware"
- "tmr-watch/models"
- "tmr-watch/pkg/app"
- "tmr-watch/pkg/e"
- "tmr-watch/service/group"
- "gitee.com/xuyiping_admin/pkg/ginutil"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- "gitee.com/xuyiping_admin/pkg/apierr"
- "gitee.com/xuyiping_admin/pkg/valid"
- "github.com/gin-gonic/gin"
- )
- const (
- FeedCategoryDeleteKey = "feed_delete"
- CowCategoryDeleteKey = "cow_delete"
- )
- func Handle404(c *gin.Context) {
- c.String(http.StatusNotFound, "404 NotFound")
- }
- // DistributeFeedFormula 接受集团饲料配方下发
- func DistributeFeedFormula(c *gin.Context) {
- var req operationPb.DistributeDataRequest
- if err := ginutil.BindProto(c, &req); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := valid.ValidateStruct(&req,
- valid.Field(&req.PastureId, valid.Required),
- valid.Field(&req.FeedFormulaList, valid.Required),
- ); err != nil {
- apierr.AbortBadRequest(c, http.StatusBadRequest, err)
- return
- }
- if err := group.DistributeFeedFormulaService(&req); err != nil {
- apierr.ClassifiedAbort(c, err)
- return
- }
- ginutil.JSONResp(c, &operationPb.CommonOK{
- Code: http.StatusOK,
- Msg: "ok",
- Data: &operationPb.Success{Success: true},
- })
- }
- // 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
- 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 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,
- })
- }
- // FeedFormulaAsyncList 获取配方列表
- func FeedFormulaAsyncList(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.FeedFormulaList(&req)
- if err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
- return
- }
- 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)
- }
- // FeedFormulaDetailList 饲料配方详情
- func FeedFormulaDetailList(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.FeedTemplateDetailList(&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}
- var req models.AnalysisAccuracyRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if res, err := group.AnalysisAccuracyService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, res)
- }
- }
- // ProcessAnalysis 过程分析
- func ProcessAnalysis(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.AnalysisAccuracyRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if res, err := group.ProcessAnalysisService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, res)
- }
- }
- // SprinkleStatistics 撒料统计
- func SprinkleStatistics(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.SprinkleStatisticsRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if res, err := group.SprinkleStatisticsService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- return
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, res)
- }
- }
- // DistributeAccount 账号下发
- func DistributeAccount(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.AccountDistributionRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.AccountDistributionService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
- "success": true,
- })
- }
- }
- // ForageCategoryDistribute 饲料分类下发
- func ForageCategoryDistribute(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.CategoryRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.ForageCategoryDistributeService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
- "success": true,
- })
- }
- }
- func ForageCategoryDelete(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.CategoryDeleteRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.CategoryDeleteService(FeedCategoryDeleteKey, &req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
- "success": true,
- })
- }
- }
- func CowCategoryDistribute(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.CategoryRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.CattleCategoryDistributeService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
- "success": true,
- })
- }
- }
- func CowCategoryDelete(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.CategoryDeleteRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.CategoryDeleteService(CowCategoryDeleteKey, &req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
- "success": true,
- })
- }
- }
- // FeedUsage 配方使用概况
- func FeedUsage(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.FeedFormulaUsageRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if res, err := group.FeedUsageService(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- return
- } else {
- appG.Response(http.StatusOK, e.SUCCESS, res)
- }
- }
- // FeedFormulaVersion 集团端配方信息更新同步
- func FeedFormulaVersion(c *gin.Context) {
- appG := app.Gin{C: c}
- var req models.FeedFormulaUpdateVersionRequest
- if err := c.BindJSON(&req); err != nil {
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- if err := group.FeedFormulaVersionService(int64(c.GetInt(middleware.PastureId)), &req); err != nil {
- appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
- "error": err,
- })
- return
- }
- appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{"success": true})
- }
|