Bläddra i källkod

project: ci-cd

Yi 1 år sedan
förälder
incheckning
76ec7a896a

+ 42 - 0
.drone.yml

@@ -0,0 +1,42 @@
+kind: pipeline
+type: docker
+name: kpt-tmr
+
+steps:
+  - name: build
+    image: plugins/docker
+    volumes:
+      - name: hosts
+        path: /etc/hosts
+      - name: docker-ca
+        path: /etc/docker
+      - name: docker-sock
+        path: /var/run/docker.sock
+    settings:
+      dockerfile: /drone/src/Dockerfile
+      username:
+        from_secret: aliyun_name
+      password:
+        from_secret: aliyun_password
+      repo: registry.cn-hangzhou.aliyuncs.com/kpt-event/kpt-tmr
+      registry: registry.cn-hangzhou.aliyuncs.com
+      tags: [ 1.0.0,latest ]
+
+trigger:
+  branch:
+    include:
+      - develop
+  event:
+    include:
+      - push
+
+volumes:
+  - name: host
+    host:
+      path: /etc/host
+  - name: docker-ca
+    host:
+      path: /ect/docker
+  - name: docker-sock
+    host:
+      path: /var/run/docker.sock

+ 15 - 0
Dockerfile

@@ -0,0 +1,15 @@
+FROM alpine:latest
+
+LABEL name="kpt-tmr" \
+description="pt service" \
+owner="yiping.xu"
+
+WORKDIR /bin
+
+ADD ./bin/kptTmr /bin/kptTmr
+COPY config/ /bin/config/
+
+EXPOSE 8081
+VOLUME /bin/logger
+
+CMD ["/bin/kptTmr"]

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

@@ -43,6 +43,7 @@ type auth struct {
 // @Router /auth  [POST]
 func Auth(c *gin.Context) {
 
+	fmt.Println("=======Auth========", Auth)
 	appG := app.Gin{C: c}
 	var reqInfo auth
 	err := c.BindJSON(&reqInfo)

+ 58 - 0
http/handle/group/feed_formula.go

@@ -0,0 +1,58 @@
+package group
+
+import (
+	"net/http"
+	"time"
+	"tmr-watch/http/handle/restful"
+	"tmr-watch/models"
+	"tmr-watch/pkg/app"
+	"tmr-watch/pkg/e"
+
+	"github.com/gin-gonic/gin"
+)
+
+func DistributeFeedFormula(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.PastureBody
+	if err := c.BindJSON(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	if len(req.Body) <= 0 {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+	}
+
+	feedTemplateList := make([]*models.FeedTemplate, len(req.Body))
+	for i, b := range req.Body {
+		feedTemplateList[i] = &models.FeedTemplate{
+			PastureId:    req.PastureId,
+			TCode:        b.EncodeNumber,
+			TName:        b.Name,
+			TColor:       b.Colour,
+			CCid:         int64(b.CattleCategoryId),
+			CCName:       b.CattleCategoryName,
+			FTType:       "",
+			Source:       "",
+			Remark:       b.Remarks,
+			Enable:       1,
+			Weight:       0,
+			DryWeight:    0,
+			Version:      b.Version,
+			SaveTime:     time.Now().Format("2006-01-02 15:04:05"),
+			IsIssue:      0,
+			IssueVersion: 0,
+			IssueId:      0,
+		}
+	}
+
+	if _, err := restful.Engine.Insert(feedTemplateList); err != nil {
+		appG.Response(http.StatusBadRequest, e.ERROR_ADD_FAIL, nil)
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
+		"success": true,
+	})
+
+}

+ 18 - 0
http/routers/group_api.go

@@ -0,0 +1,18 @@
+package routers
+
+import (
+	"tmr-watch/http/handle/group"
+
+	"github.com/gin-gonic/gin"
+)
+
+func GroupAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+
+		apiPasture := s.Group("/pasture")
+		apiPasture.POST("feed_formula/distribute", group.DistributeFeedFormula) // 饲料配方下发
+	}
+}

+ 1 - 0
http/routers/router.go

@@ -9,6 +9,7 @@ func HTTPServerRoute(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 	routes := []func(s *gin.Engine){
 		Root(opts...),
 		AppAPI(opts...),
+		GroupAPI(opts...),
 	}
 
 	return func(s *gin.Engine) {

+ 31 - 0
models/feed_templet.go

@@ -0,0 +1,31 @@
+package models
+
+type FeedTemplate struct {
+	Id           int64   `xorm:"id"`
+	PastureId    int64   `xorm:"pastureid"`
+	TCode        string  `xorm:"tcode"`
+	TName        string  `xorm:"tname"`
+	TColor       string  `xorm:"tcolor"`
+	CCid         int64   `xorm:"ccid"`
+	CCName       string  `xorm:"ccname"`
+	FTType       string  `xorm:"fttype"`
+	Source       string  `xorm:"source"`
+	Remark       string  `xorm:"remark"`
+	Enable       int32   `xorm:"enable"`
+	Sort         int64   `xorm:"sort"`
+	Owner        string  `xorm:"owner"`
+	Weight       float64 `xorm:"weight"`
+	DryWeight    float64 `xorm:"dryweight"`
+	IsDelete     int32   `xorm:"isdelete"`
+	Version      int64   `xorm:"version"`
+	SaveTime     string  `xorm:"savetime"`
+	IsIssue      int32   `xorm:"isissue"`
+	IssueVersion int32   `xorm:"issueversion"`
+	IssueId      int64   `xorm:"issueid"`
+	Backup1      string  `xorm:"backup1"`
+	Backup2      string  `xorm:"backup2"`
+}
+
+func (f *FeedTemplate) TableName() string {
+	return "feedtemplet"
+}

+ 28 - 0
models/group_data.go

@@ -0,0 +1,28 @@
+package models
+
+type PastureBody struct {
+	PastureId int64          `json:"pasture_id"`
+	Body      []*FeedFormula `json:"body"`
+}
+
+type FeedFormula struct {
+	Id                 int64  `json:"id"`
+	Name               string `json:"name"`
+	Colour             string `json:"colour"`
+	EncodeNumber       string `json:"encode_number"`
+	CattleCategoryId   int32  `json:"cattle_category_id"`
+	CattleCategoryName string `json:"cattle_category_name"`
+	FormulaTypeId      int32  `json:"formula_type_id"`
+	FormulaTypeName    string `json:"formula_type_name"`
+	DataSourceId       int32  `json:"data_source_id"`
+	DataSourceName     string `json:"data_source_name"`
+	Remarks            string `json:"remarks"`
+	Version            int64  `json:"version"`
+	PastureId          int64  `json:"pasture_id"`
+	PastureName        string `json:"pasture_name"`
+	IsShow             int32  `json:"is_show"`
+	IsModify           int32  `json:"is_modify"`
+	IsDelete           int32  `json:"is_delete"`
+	CreatedAt          int64  `json:"created_at"`
+	UpdatedAt          int64  `json:"updated_at"`
+}