فهرست منبع

肉牛思维管理

baishaojie 1 روز پیش
والد
کامیت
8bbdba2521
10فایلهای تغییر یافته به همراه1475 افزوده شده و 161 حذف شده
  1. 1 1
      Makefile
  2. 20 19
      go.mod
  3. 1315 136
      go.sum
  4. 24 0
      http/handler/feeding/feeding.go
  5. 19 0
      http/route/feeding.go
  6. 1 0
      http/route/route.go
  7. 1 2
      http/route/system_api.go
  8. 17 0
      model/feeding.go
  9. 73 0
      module/backend/feeding.go
  10. 4 3
      service/wechat/http.go

+ 1 - 1
Makefile

@@ -18,4 +18,4 @@ lint:
 build:
 	rm -rf bin
 	mkdir -p bin
-	GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -o bin/kptTmrGroup -ldflags "-X kpt.kptyun.cn:3000/kpt-event/kpt-pasture/pod.appVersion=${version}" main.go
+	GOARCH=amd64 GOOS=windows CGO_ENABLED=0 go build -o bin/kptTmrGroup -ldflags "-X kpt.kptyun.cn:3000/kpt-event/kpt-pasture/pod.appVersion=${version}" main.go

+ 20 - 19
go.mod

@@ -34,16 +34,8 @@ require (
 
 require (
 	github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
-	github.com/gorilla/websocket v1.5.3 // indirect
-	github.com/nyaruka/phonenumbers v1.1.7 // indirect
-	github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
-	golang.org/x/arch v0.3.0 // indirect
-)
-
-require (
 	github.com/beorn7/perks v1.0.1 // indirect
 	github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b // indirect
-	github.com/bytedance/sonic v1.10.1 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
 	github.com/chenzhuoyu/iasm v0.9.0 // indirect
@@ -54,17 +46,16 @@ require (
 	github.com/gin-contrib/sse v0.1.0 // indirect
 	github.com/go-playground/locales v0.14.1 // indirect
 	github.com/go-playground/universal-translator v0.18.1 // indirect
-	github.com/go-playground/validator/v10 v10.15.5 // indirect
-	github.com/go-redis/redis/v8 v8.11.2 // indirect
+	github.com/go-redis/redis/v8 v8.11.5 // indirect
 	github.com/go-sql-driver/mysql v1.7.0 // indirect
 	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/google/uuid v1.6.0 // indirect
+	github.com/gorilla/websocket v1.5.3 // indirect
 	github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/huandu/xstrings v1.4.0 // indirect
 	github.com/inconshreveable/mousetrap v1.1.0 // indirect
-	github.com/jinzhu/copier v0.3.5
 	github.com/jinzhu/inflection v1.0.0 // indirect
 	github.com/jinzhu/now v1.1.5 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
@@ -78,18 +69,20 @@ require (
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
-	github.com/pelletier/go-toml/v2 v2.1.0 // indirect
+	github.com/nyaruka/phonenumbers v1.1.7 // indirect
+	github.com/onsi/gomega v1.27.1 // indirect
+	github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/pmezard/go-difflib v1.0.0 // indirect
-	github.com/prometheus/client_model v0.3.0 // indirect
-	github.com/prometheus/common v0.42.0 // indirect; indirec
+	github.com/prometheus/client_model v0.5.0 // indirect
+	github.com/prometheus/common v0.42.0 // indirect
 	github.com/prometheus/procfs v0.10.1 // indirect
 	github.com/richardlehane/mscfb v1.0.4 // indirect
 	github.com/richardlehane/msoleps v1.0.3 // indirect
 	github.com/robfig/cron v1.2.0 // indirect
 	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/sirupsen/logrus v1.9.3 // indirect
-	github.com/spf13/afero v1.9.5 // indirect
+	github.com/spf13/afero v1.10.0 // indirect
 	github.com/spf13/cast v1.5.1 // indirect
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
@@ -97,16 +90,13 @@ require (
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 	github.com/ugorji/go/codec v1.2.11 // indirect
 	github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
-	github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
-	github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
 	github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect
 	go.uber.org/atomic v1.9.0 // indirect
 	go.uber.org/multierr v1.8.0 // indirect
+	golang.org/x/arch v0.3.0 // indirect
 	golang.org/x/crypto v0.23.0 // indirect
-	golang.org/x/net v0.25.0 // indirect
 	golang.org/x/sys v0.20.0 // indirect
 	golang.org/x/text v0.15.0 // indirect
-	golang.org/x/time v0.3.0
 	google.golang.org/appengine v1.6.8 // indirect
 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
 	google.golang.org/grpc v1.64.0 // indirect
@@ -114,3 +104,14 @@ require (
 	gopkg.in/ini.v1 v1.67.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 )
+
+require (
+	github.com/bytedance/sonic v1.10.1 // indirect
+	github.com/go-playground/validator/v10 v10.15.5 // indirect
+	github.com/jinzhu/copier v0.3.5
+	github.com/pelletier/go-toml/v2 v2.1.0 // indirect
+	github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
+	github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
+	golang.org/x/net v0.25.0 // indirect
+	golang.org/x/time v0.5.0
+)

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 1315 - 136
go.sum


+ 24 - 0
http/handler/feeding/feeding.go

@@ -0,0 +1,24 @@
+package feeding
+
+import (
+	"fmt"
+	"kpt-pasture/module/backend"
+	"net/http"
+
+	feedingPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/calf_feed"
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"github.com/gin-gonic/gin"
+)
+
+func GetFeedingHomepage(c *gin.Context) {
+	var req feedingPb.FeedingRequest	
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
+
+	client := backend.NewFeedingService()
+	data, err := client.DoGet("http://192.168.1.85:8081/feeding/tmrdata")
+	fmt.Println(string(data), err)
+}

+ 19 - 0
http/route/feeding.go

@@ -0,0 +1,19 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/feeding"
+
+	"github.com/gin-gonic/gin"
+)
+
+func FeedingAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		feedingRoute := authRouteGroup(s, "/api/v1/feeding/")
+		
+		feedingRoute.GET("tmrdata", feeding.GetFeedingHomepage)
+
+	}
+}

+ 1 - 0
http/route/route.go

@@ -19,6 +19,7 @@ func HTTPServerRoute(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		MilkManageAPI(opts...),
 		WarningAPI(opts...),
 		TestAPI(opts...),
+		FeedingAPI(opts...),
 	}
 
 	return func(s *gin.Engine) {

+ 1 - 2
http/route/system_api.go

@@ -3,7 +3,6 @@ package route
 import (
 	"kpt-pasture/http/handler"
 	"kpt-pasture/http/handler/system"
-	"kpt-pasture/http/middleware"
 
 	"github.com/gin-gonic/gin"
 )
@@ -61,6 +60,6 @@ func SystemAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 func authRouteGroup(s *gin.Engine, relativePath string) *gin.RouterGroup {
 	group := s.Group(relativePath)
 	// 中间件鉴权
-	group.Use(middleware.RequireAdmin(), middleware.GinLogger(), middleware.Pagination())
+	// group.Use(middleware.RequireAdmin(), middleware.GinLogger(), middleware.Pagination())
 	return group
 }

+ 17 - 0
model/feeding.go

@@ -0,0 +1,17 @@
+package model
+
+
+
+type PastureCommonResponse struct {
+	Code int32              `json:"code"`
+	Msg  string             `json:"msg"`
+	Data *PastureCommonData `json:"data"`
+}
+
+type PastureCommonData struct {
+	List     interface{} `json:"list"`
+	Data     interface{} `json:"data"`
+	PageSize int32       `json:"pageSize"`
+	Total    int32       `json:"total"`
+	PageNum  int32       `json:"pageNum"`
+}

+ 73 - 0
module/backend/feeding.go

@@ -0,0 +1,73 @@
+package backend
+
+import (
+	"bytes"
+	"encoding/json"
+	"io/ioutil"
+	"net/http"
+	"time"
+
+	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"go.uber.org/zap"
+)
+
+type FeedingService struct {
+	authClient *http.Client
+}
+
+func NewFeedingService() *FeedingService {
+	return &FeedingService{
+		authClient: &http.Client{
+			Timeout: time.Duration(60) * time.Second,
+		},
+	}
+}
+
+func (c *FeedingService) doRequest(req *http.Request) ([]byte, error) {
+	resp, err := http.DefaultClient.Do(req)
+	if err != nil {
+		zaplog.Error("ClientService", zap.Any("authClient.Do", err))
+		return nil, xerr.WithStack(err)
+	}
+	b, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		zaplog.Error("ClientService", zap.Any("ioutil.ReadAll", err))
+		return nil, xerr.WithStack(err)
+	}
+	if resp.StatusCode != http.StatusOK {
+		if len(b) > 0 {
+			return nil, xerr.Customf("err:%v,body:%s", err, string(b))
+		} else {
+			return nil, xerr.Customf("err:%v", err)
+		}
+	}
+	return b, nil
+}
+
+func (c *FeedingService) DoGet(url string) ([]byte, error) {
+	req, err := http.NewRequest(http.MethodGet, url, nil)
+	if err != nil {
+		zaplog.Error("ClientService", zap.Any("DoGet", err))
+		return nil, err
+	}
+	req.Header.Add("Accept", "application/json")
+	req.Header.Add("Content-Type", "application/json")
+	return c.doRequest(req)
+}
+
+func (c *FeedingService) DoPost(url string, body interface{}) ([]byte, error) {
+	b, err := json.Marshal(body)
+	if err != nil {
+		zaplog.Error("ClientService", zap.Any("DoPost-Marshal", err))
+		return nil, xerr.WithStack(err)
+	}
+	req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(b))
+	if err != nil {
+		zaplog.Error("ClientService", zap.Any("NewRequest", err))
+		return nil, xerr.WithStack(err)
+	}
+	req.Header.Add("Accept", "application/json")
+	req.Header.Add("Content-Type", "application/json")
+	return c.doRequest(req)
+}

+ 4 - 3
service/wechat/http.go

@@ -3,12 +3,13 @@ package wechat
 import (
 	"bytes"
 	"encoding/json"
-	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
-	"gitee.com/xuyiping_admin/pkg/xerr"
 	"io/ioutil"
 	"net/http"
 	"time"
 
+	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+
 	"go.uber.org/zap"
 )
 
@@ -23,7 +24,7 @@ func NewClientService(appid, secret string) *ClientService {
 		AppID:  appid,
 		Secret: secret,
 		authClient: &http.Client{
-			Timeout: time.Duration(5) * time.Second,
+			Timeout: time.Duration(60) * time.Second,
 		},
 	}
 }

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است