liwei 2 years ago
parent
commit
743018e852
4 changed files with 35 additions and 4 deletions
  1. 3 0
      boxcost/api/router.go
  2. 26 0
      boxcost/api/setting.go
  3. 3 2
      boxcost/app.yaml
  4. 3 2
      boxcost/db/model/material.go

+ 3 - 0
boxcost/api/router.go

@@ -36,6 +36,9 @@ func RegRouters(svc *Service) {
 
 	// 单据管理
 	Bill(boxcost)
+
+	//设置
+	Setting(boxcost)
 }
 
 func Logger() gin.HandlerFunc {

+ 26 - 0
boxcost/api/setting.go

@@ -0,0 +1,26 @@
+package api
+
+import (
+	"box-cost/db/model"
+	"time"
+
+	"github.com/gin-gonic/gin"
+)
+
+func Setting(router *GinRouter) {
+
+	CreateCRUD(router, "/units", &CRUDOption{
+		Collection: "units",
+		NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+			entity := &model.Unit{}
+			c.ShouldBindJSON(entity)
+			entity.CreateTime = time.Now()
+			return entity, nil
+		},
+		EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
+			return &model.Unit{}
+		},
+		JWT:           true,
+		SearchProject: []string{"name", "createTime"},
+	})
+}

+ 3 - 2
boxcost/app.yaml

@@ -20,6 +20,7 @@ debug:
   UserRole: string
 
 nats:
-  url: nats://124.71.139.24:14300
+  #url: nats://124.71.139.24:14300
+  url: nats://127.0.0.1:14300
   maxReconnect: 1000
-  reconnDelaySecond: 5
+  reconnDelaySecond: 5

+ 3 - 2
boxcost/db/model/material.go

@@ -8,8 +8,9 @@ import (
 
 // 单位
 type Unit struct {
-	Id   primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name string             `bson:"name,omitempty" json:"name"`
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name       string             `bson:"name,omitempty" json:"name"`
+	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
 }
 
 // 材料只能添加,不能修改