Browse Source

Merge branch 'master' of http://124.70.149.18:10880/sunsheng/cmf

liwei 3 months ago
parent
commit
c196af9e09

+ 1 - 0
pack-cmf/start.sh

@@ -13,6 +13,7 @@ RUN echo -e https://mirrors.ustc.edu.cn/alpine/v3.15/main > /etc/apk/repositorie
 WORKDIR /root/cmf
 
 ADD ./app.yaml ./app.yaml
+ADD  ./token_jwt_key.pem ./token_jwt_key.pem
 ADD ./cmf ./cmf
 
 EXPOSE 8891

+ 2 - 0
src/api/callback.go

@@ -14,12 +14,14 @@ func callback(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	token, err := casdoorsdk.GetOAuthToken(c.Query("code"), c.Query("state"))
 	if err != nil {
 		fmt.Println(err)
+		return err, nil
 	}
 
 	fmt.Println(token.AccessToken)
 	claims, err := casdoorsdk.ParseJwtToken(token.AccessToken)
 	if err != nil {
 		fmt.Println(err)
+		return err, nil
 	}
 	fmt.Println(claims)
 	// c.Redirect(http.StatusFound, "https://auth.3dqueen.cloud")

+ 0 - 98
src/api/decorate.go

@@ -1,98 +0,0 @@
-package api
-
-import (
-	"cmf/db/model"
-	"cmf/db/repo"
-	"cmf/log"
-	"errors"
-	"time"
-
-	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-func Decorate(r *GinRouter) {
-	r.POST("/decorate/create", CreateDecorate)
-	r.POST("/decorate/delete/:id", DeleteDecorate)
-	r.GET("/decorate/list", DecorateList)
-	r.GET("/decorate/detail/:id", DecorateDetail)
-	r.POST("/decorate/update", UpdateDecorate)
-}
-
-func CreateDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var data model.ModelLib
-	err := c.ShouldBindJSON(&data)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	data.CreateTime = time.Now()
-	data.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, &data)
-}
-
-func DeleteDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, _id)
-}
-
-func DecorateList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	page, size, query := UtilQueryPageSize(c)
-	catsConf, err := GetModelLibCategory(apictx)
-	if err != nil {
-		return nil, err
-	}
-	err = ParseCategories(query, apictx.CreateRepoCtx(), catsConf)
-	if err != nil {
-		return nil, err
-	}
-
-	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionDecorate,
-		Page:        page,
-		Size:        size,
-		Query:       query,
-		Sort:        bson.M{"createTime": -1},
-	})
-}
-
-func DecorateDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	box := &model.ModelLib{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionDecorate,
-		Query:       repo.Map{"_id": id},
-	}, box)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-
-	if !found {
-		return nil, errors.New("未找到该数据")
-	}
-	return box, nil
-}
-
-func UpdateDecorate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var box model.ModelLib
-	err := c.ShouldBindJSON(&box)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	if box.Id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionDecorate, box.Id.Hex(), &box)
-}

+ 22 - 24
src/api/nav.go → src/api/finishArtwork.go

@@ -8,60 +8,58 @@ import (
 	"time"
 
 	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-func Nav(r *GinRouter) {
-	r.POSTJWT("/nav/create", CreateNav)
-	r.POSTJWT("/nav/delete/:id", DeleteNav)
-	r.GETJWT("/nav/list", NavList)
-	r.GETJWT("/nav/detail/:id", NavDetail)
-	r.POSTJWT("/nav/update", UpdateNav)
+func FinishArtwork(r *GinRouter) {
+	r.POST("/finish/create", CreateFinishArtwork)
+	r.POST("/finish/delete/:id", DeleteFinishArtwork)
+	r.GET("/finish/list", FinishArtworkList)
+	r.GET("/finish/detail/:id", FinishArtworkDetail)
+	r.POST("/finish/update", UpdateFinishArtwork)
 }
 
-func CreateNav(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var nav model.Nav
-	err := c.ShouldBindJSON(&nav)
+func CreateFinishArtwork(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var finish model.FinishArtwork
+	err := c.ShouldBindJSON(&finish)
 	if err != nil {
 		log.Error(err)
 		return nil, err
 	}
-	nav.CreateTime = time.Now()
-	nav.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionNav, &nav)
+	finish.CreateTime = time.Now()
+	finish.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionFinishArtwork, &finish)
 }
 
-func DeleteNav(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func DeleteFinishArtwork(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
 	id, _ := primitive.ObjectIDFromHex(_id)
 	if id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionNav, _id)
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionFinishArtwork, _id)
 }
 
-func NavList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func FinishArtworkList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionNav,
+		CollectName: repo.CollectionFinishArtwork,
 		Page:        page,
 		Size:        size,
 		Query:       query,
-		Sort:        bson.D{bson.E{Key: "sort", Value: 1}, bson.E{Key: "createTime", Value: -1}},
 	})
 }
 
-func NavDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func FinishArtworkDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
 	id, _ := primitive.ObjectIDFromHex(_id)
 	if id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	cate := &model.Nav{}
+	cate := &model.FinishArtwork{}
 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionNav,
+		CollectName: repo.CollectionFinishArtwork,
 		Query:       repo.Map{"_id": id},
 	}, cate)
 	if err != nil {
@@ -75,8 +73,8 @@ func NavDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	return cate, nil
 }
 
-func UpdateNav(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var cate model.Nav
+func UpdateFinishArtwork(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var cate model.FinishArtwork
 	err := c.ShouldBindJSON(&cate)
 	if err != nil {
 		log.Error(err)
@@ -85,5 +83,5 @@ func UpdateNav(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if cate.Id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionNav, cate.Id.Hex(), &cate)
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionFinishArtwork, cate.Id.Hex(), &cate)
 }

+ 0 - 89
src/api/gallery.go

@@ -1,89 +0,0 @@
-package api
-
-import (
-	"cmf/db/model"
-	"cmf/db/repo"
-	"cmf/log"
-	"errors"
-	"time"
-
-	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-func Gallery(r *GinRouter) {
-	r.POSTJWT("/gallery/create", CreateGallery)
-	r.POSTJWT("/gallery/delete/:id", DeleteGallery)
-	r.GETJWT("/gallery/list", GalleryList)
-	r.GETJWT("/gallery/detail/:id", GalleryDetail)
-	r.POSTJWT("/gallery/update", UpdateGallery)
-}
-
-func CreateGallery(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var gallery model.Gallery
-	err := c.ShouldBindJSON(&gallery)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	gallery.CreateTime = time.Now()
-	gallery.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionGallery, &gallery)
-}
-
-func DeleteGallery(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionGallery, _id)
-}
-
-func GalleryList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	page, size, query := UtilQueryPageSize(c)
-	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionGallery,
-		Page:        page,
-		Size:        size,
-		Query:       query,
-		Sort:        bson.M{"createTime": -1},
-	})
-}
-
-func GalleryDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	gallery := &model.Gallery{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionGallery,
-		Query:       repo.Map{"_id": id},
-	}, gallery)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-
-	if !found {
-		return nil, errors.New("未找到该数据")
-	}
-	return gallery, nil
-}
-
-func UpdateGallery(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var gallery model.Gallery
-	err := c.ShouldBindJSON(&gallery)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	if gallery.Id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionGallery, gallery.Id.Hex(), &gallery)
-}

+ 3 - 1
src/api/router.go

@@ -41,7 +41,9 @@ func RegRouters(svc *Service) {
 	// Decorate(r)
 	// Scene(r)
 	MatLib(r)
-	Craft(r)
+	// ArtworkColor(r)
+	Shape(r)
+	FinishArtwork(r)
 
 	r.GET("/printr", Printr)
 }

+ 0 - 98
src/api/scene.go

@@ -1,98 +0,0 @@
-package api
-
-import (
-	"cmf/db/model"
-	"cmf/db/repo"
-	"cmf/log"
-	"errors"
-	"time"
-
-	"github.com/gin-gonic/gin"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-func Scene(r *GinRouter) {
-	r.POST("/scene/create", CreateScene)
-	r.POST("/scene/delete/:id", DeleteScene)
-	r.GET("/scene/list", SceneList)
-	r.GET("/scene/detail/:id", SceneDetail)
-	r.POST("/scene/update", UpdateScene)
-}
-
-func CreateScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var data model.ModelLib
-	err := c.ShouldBindJSON(&data)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	data.CreateTime = time.Now()
-	data.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionScene, &data)
-}
-
-func DeleteScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionScene, _id)
-}
-
-func SceneList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	page, size, query := UtilQueryPageSize(c)
-	catsConf, err := GetModelLibCategory(apictx)
-	if err != nil {
-		return nil, err
-	}
-	err = ParseCategories(query, apictx.CreateRepoCtx(), catsConf)
-	if err != nil {
-		return nil, err
-	}
-
-	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionScene,
-		Page:        page,
-		Size:        size,
-		Query:       query,
-		Sort:        bson.M{"createTime": -1},
-	})
-}
-
-func SceneDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	_id := c.Param("id")
-	id, _ := primitive.ObjectIDFromHex(_id)
-	if id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	box := &model.ModelLib{}
-	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionScene,
-		Query:       repo.Map{"_id": id},
-	}, box)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-
-	if !found {
-		return nil, errors.New("未找到该数据")
-	}
-	return box, nil
-}
-
-func UpdateScene(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var box model.ModelLib
-	err := c.ShouldBindJSON(&box)
-	if err != nil {
-		log.Error(err)
-		return nil, err
-	}
-	if box.Id.IsZero() {
-		return nil, errors.New("id错误")
-	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionScene, box.Id.Hex(), &box)
-}

+ 22 - 22
src/api/craft.go → src/api/shape.go

@@ -11,55 +11,55 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
-func Craft(r *GinRouter) {
-	r.POST("/craft/create", CreateCraft)
-	r.POST("/craft/delete/:id", DeleteCraft)
-	r.GET("/craft/list", CraftList)
-	r.GET("/craft/detail/:id", CraftDetail)
-	r.POST("/craft/update", UpdateCraft)
+func Shape(r *GinRouter) {
+	r.POST("/shape/create", CreateShape)
+	r.POST("/shape/delete/:id", DeleteShape)
+	r.GET("/shape/list", ShapeList)
+	r.GET("/shape/detail/:id", ShapeDetail)
+	r.POST("/shape/update", UpdateShape)
 }
 
-func CreateCraft(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var craft model.Craft
-	err := c.ShouldBindJSON(&craft)
+func CreateShape(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var shape model.Shape
+	err := c.ShouldBindJSON(&shape)
 	if err != nil {
 		log.Error(err)
 		return nil, err
 	}
-	craft.CreateTime = time.Now()
-	craft.UpdateTime = time.Now()
-	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionCraft, &craft)
+	shape.CreateTime = time.Now()
+	shape.UpdateTime = time.Now()
+	return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionShape, &shape)
 }
 
-func DeleteCraft(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func DeleteShape(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
 	id, _ := primitive.ObjectIDFromHex(_id)
 	if id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionCraft, _id)
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionShape, _id)
 }
 
-func CraftList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func ShapeList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 
 	page, size, query := UtilQueryPageSize(c)
 	return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
-		CollectName: repo.CollectionCraft,
+		CollectName: repo.CollectionShape,
 		Page:        page,
 		Size:        size,
 		Query:       query,
 	})
 }
 
-func CraftDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+func ShapeDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	_id := c.Param("id")
 	id, _ := primitive.ObjectIDFromHex(_id)
 	if id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	cate := &model.Craft{}
+	cate := &model.Shape{}
 	found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
-		CollectName: repo.CollectionCraft,
+		CollectName: repo.CollectionShape,
 		Query:       repo.Map{"_id": id},
 	}, cate)
 	if err != nil {
@@ -73,8 +73,8 @@ func CraftDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	return cate, nil
 }
 
-func UpdateCraft(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	var cate model.Craft
+func UpdateShape(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var cate model.Shape
 	err := c.ShouldBindJSON(&cate)
 	if err != nil {
 		log.Error(err)
@@ -83,5 +83,5 @@ func UpdateCraft(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if cate.Id.IsZero() {
 		return nil, errors.New("id错误")
 	}
-	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionCraft, cate.Id.Hex(), &cate)
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionShape, cate.Id.Hex(), &cate)
 }

+ 3 - 3
src/app.yaml

@@ -1,4 +1,4 @@
-port: 3000
+port: 3001
 name: cmf
 version: 1.0.0
 saveType: obs
@@ -18,8 +18,8 @@ debug:
   UserRole: string
 
 nats:
-  # url: nats://124.71.139.24:14309
-  url: nats://127.0.0.1:14224
+  url: nats://124.71.139.24:14226
+  # url: nats://127.0.0.1:14224
   maxReconnect: 1000
   reconnDelaySecond: 5
 

+ 1 - 1
src/db/db.go

@@ -38,7 +38,7 @@ func (db *MongoDB) GetOrCreateDatabase(name string) *mongo.Database {
 
 func NewMongoDB(bus *comm.NatsBus) *MongoDB {
 
-	inst, err := bus.NewMongoDBFromConfig("cmf-mongo")
+	inst, err := bus.NewMongoDBFromConfigDev("cmf-mongo")
 
 	if err != nil {
 		fmt.Println(err)

+ 0 - 17
src/db/model/Craft.go

@@ -1,17 +0,0 @@
-package model
-
-import (
-	"time"
-
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-type Craft struct {
-	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name       string             `bson:"name,omitempty" json:"name"`
-	Desc       string             `bson:"desc,omitempty" json:"desc"`
-	SurfArt    string             `bson:"surfArt,omitempty" json:"surfArt"`
-	ShapArt    string             `bson:"shapArt,omitempty" json:"shapArt"`
-	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
-}

+ 30 - 1
src/db/model/MatLib.go

@@ -6,9 +6,30 @@ import (
 	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
+type ArtworkColor struct {
+	RGBA   []float32 `bson:"rgba,omitempty" json:"rgba"`
+	Name   string    `bson:"name,omitempty" json:"name"`
+	MatKey string    `bson:"matkey,omitempty" json:"matkey"`
+}
+
+type FinishArtwork struct {
+	Id            primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name          string             `bson:"name,omitempty" json:"name"`
+	Thumb         string             `bson:"thumb,omitempty" json:"thumb"`
+	FinishId      string             `bson:"finishId,omitempty" json:"finishId"`
+	MeshId        string             `bson:"meshId,omitempty" json:"meshId"`
+	MatKey        string             `bson:"matkey,omitempty" json:"matkey"`
+	IsCanCusColor bool               `bson:"isCanCusColor,omitempty" json:"isCanCusColor"` //是否支持定义颜色
+	Colors        []ArtworkColor     `bson:"colors,omitempty" json:"colors"`               //支持的颜色
+	ShapeIds      []string           `bson:"shapeIds,omitempty" json:"shapeIds"`           //支持成型工艺
+	CreateTime    time.Time          `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime    time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+}
+
 type MatLib struct {
 	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	CraftId    primitive.ObjectID `bson:"craftId,omitempty" json:"craftId"`
+	Finishes   []FinishArtwork    `bson:"finishes,omitempty" json:"finishes"`
+	ShapeIds   []string           `bson:"shapeIds,omitempty" json:"shapeIds"` //支持成型工艺
 	Name       string             `bson:"name,omitempty" json:"name"`
 	CusNum     string             `bson:"cusNum,omitempty" json:"cusNum"`
 	Cover      string             `bson:"cover,omitempty" json:"cover"`
@@ -19,3 +40,11 @@ type MatLib struct {
 	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
 	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
 }
+
+type Shape struct {
+	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
+	Name       string             `bson:"name,omitempty" json:"name"`
+	Desc       string             `bson:"desc,omitempty" json:"desc"`
+	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+}

+ 0 - 17
src/db/model/gallery.go

@@ -1,17 +0,0 @@
-package model
-
-import (
-	"time"
-
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-// 画廊
-type Gallery struct {
-	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Title      string             `bson:"title,omitempty" json:"title"`
-	Cover      string             `bson:"cover,omitempty" json:"cover"`
-	Images     []string           `bson:"images,omitempty" json:"images"`
-	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
-}

+ 11 - 10
src/db/model/modelLib.go

@@ -8,14 +8,15 @@ import (
 
 // 模型库
 type ModelLib struct {
-	Id         primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	Name       string             `bson:"name,omitempty" json:"name"`
-	CusNum     string             `bson:"cusNum,omitempty" json:"cusNum"`
-	Cover      string             `bson:"cover,omitempty" json:"cover"`
-	Order      int32              `bson:"order,omitempty" json:"order"`
-	DotQueen   string             `bson:"dotqueen,omitempty" json:"dotqueen"`
-	Blend      string             `bson:"blend,omitempty" json:"blend"`
-	Categories []string           `bson:"categories,omitempty" json:"categories"`
-	CreateTime time.Time          `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime time.Time          `bson:"updateTime,omitempty" json:"updateTime"`
+	Id         primitive.ObjectID   `bson:"_id,omitempty" json:"_id"`
+	MatIds     []primitive.ObjectID `bson:"matIds,omitempty" json:"matIds"`
+	Name       string               `bson:"name,omitempty" json:"name"`
+	CusNum     string               `bson:"cusNum,omitempty" json:"cusNum"`
+	Cover      string               `bson:"cover,omitempty" json:"cover"`
+	Order      int32                `bson:"order,omitempty" json:"order"`
+	DotQueen   string               `bson:"dotqueen,omitempty" json:"dotqueen"`
+	Blend      string               `bson:"blend,omitempty" json:"blend"`
+	Categories []string             `bson:"categories,omitempty" json:"categories"`
+	CreateTime time.Time            `bson:"createTime,omitempty" json:"createTime"`
+	UpdateTime time.Time            `bson:"updateTime,omitempty" json:"updateTime"`
 }

+ 0 - 21
src/db/model/nav.go

@@ -1,21 +0,0 @@
-package model
-
-import (
-	"time"
-
-	"go.mongodb.org/mongo-driver/bson/primitive"
-)
-
-// db.getCollection(banner).createIndexes([{aid: 1}, {isHome: 1}])
-type Nav struct {
-	Id primitive.ObjectID `bson:"_id,omitempty" json:"_id"`
-	// Aid        primitive.ObjectID `bson:"aid,omitempty" json:"aid"` // 内联id
-	Url   string `bson:"url,omitempty" json:"url"` // 外联url
-	Name  string `bson:"name,omitempty" json:"name"`
-	Cover string `bson:"cover,omitempty" json:"cover"`
-	// Lang       string             `bson:"lang,omitempty" json:"lang"`     // cn en
-	Sort *int `bson:"sort,omitempty" json:"sort"` // 排序,使用创建时间联合排序。排序按升序排,默认为0
-	// IsHome     *bool              `bson:"isHome,omitempty" json:"isHome"` // 是否展示到首页
-	CreateTime time.Time `bson:"createTime,omitempty" json:"createTime"`
-	UpdateTime time.Time `bson:"updateTime,omitempty" json:"updateTime"`
-}

+ 5 - 4
src/db/repo/repo.go

@@ -23,10 +23,11 @@ const (
 	CollectionDecorate = "decorate"
 	CollectionScene    = "scene"
 
-	CollectionCategories = "categories"
-	CollectionModelLib   = "models"
-	CollectionMat        = "mats"
-	CollectionCraft      = "crafts"
+	CollectionCategories    = "categories"
+	CollectionModelLib      = "models"
+	CollectionMat           = "mats"
+	CollectionShape         = "Shapes"
+	CollectionFinishArtwork = "finishes"
 )
 
 type Map map[string]interface{}

+ 1 - 3
src/go.mod

@@ -1,9 +1,8 @@
 module cmf
 
-go 1.21
+go 1.20
 
 require (
-	github.com/appleboy/gin-jwt/v2 v2.7.0
 	github.com/casdoor/casdoor-go-sdk v1.3.0
 	github.com/gin-contrib/cors v1.3.1
 	github.com/gin-gonic/gin v1.7.4
@@ -61,7 +60,6 @@ require (
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
 	github.com/subosito/gotenv v1.2.0 // indirect
-	github.com/tidwall/gjson v1.14.1 // indirect
 	github.com/ugorji/go/codec v1.1.7 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect

+ 0 - 18
src/go.sum

@@ -122,10 +122,6 @@ github.com/alexflint/go-filemutex v1.1.0/go.mod h1:7P4iRhttt/nUvUOrYIhcpMzv2G6CY
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64/go.mod h1:2qMFB56yOP3KzkB3PbYZ4AlUFg3a88F67TIx5lB/WwY=
 github.com/apache/arrow/go/arrow v0.0.0-20211013220434-5962184e7a30/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs=
-github.com/appleboy/gin-jwt/v2 v2.7.0 h1:MjbX0OVC1hmb+cYNSW7yrlG8KfIN/X0qn5kqhAsHinY=
-github.com/appleboy/gin-jwt/v2 v2.7.0/go.mod h1:AP2pmslwuqdHcjua9m8APdgqX9Ksx0ZM34d5RGvUYBU=
-github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4=
-github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw=
 github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
 github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
@@ -598,7 +594,6 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
-github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0=
 github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
 github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
@@ -918,7 +913,6 @@ github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6Yf
 github.com/nats-io/jwt/v2 v2.3.0 h1:z2mA1a7tIf5ShggOFlR1oBPgd6hGqcDYsISxZByUzdI=
 github.com/nats-io/jwt/v2 v2.3.0/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k=
 github.com/nats-io/nats-server/v2 v2.9.10 h1:LMC46Oi9E6BUx/xBsaCVZgofliAqKQzRPU6eKWkN8jE=
-github.com/nats-io/nats-server/v2 v2.9.10/go.mod h1:AB6hAnGZDlYfqb7CTAm66ZKMZy9DpfierY1/PbpvI2g=
 github.com/nats-io/nats.go v1.22.1 h1:XzfqDspY0RNufzdrB8c4hFR+R3dahkxlpWe5+IWJzbE=
 github.com/nats-io/nats.go v1.22.1/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
 github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
@@ -946,7 +940,6 @@ github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1ls
 github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
 github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
 github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
-github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
 github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
 github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
 github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
@@ -957,7 +950,6 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
 github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
 github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
 github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
-github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
 github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
 github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
 github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
@@ -1136,14 +1128,7 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG
 github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
 github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
-github.com/tidwall/gjson v1.9.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
-github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
-github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
-github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
-github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
-github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
-github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -1598,7 +1583,6 @@ golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxb
 golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
-golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -1681,7 +1665,6 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
-golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
 golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -1902,7 +1885,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
 gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
 gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=

+ 6 - 0
src/middleware/auth.go

@@ -3,6 +3,7 @@ package middleware
 import (
 	"net/http"
 	"strings"
+	"time"
 
 	"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
 	"github.com/gin-gonic/gin"
@@ -37,6 +38,11 @@ func CasdoorAuthMiddleware() gin.HandlerFunc {
 			c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Invalid token: " + err.Error()})
 			return
 		}
+		// 检查 token 是否过期
+		if claims.ExpiresAt.Compare(time.Now()) < 0 {
+			c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Token has expired"})
+			return
+		}
 
 		// 将用户信息存储在上下文中,以便后续使用
 		c.Set("casdoor_user", claims)