123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package api
- import (
- "fmt"
- "mats/db/model"
- "mats/db/repo"
- "github.com/gin-gonic/gin"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "infish.cn/comm"
- )
- func RegQueenterUploadApi(router *GinRouter) {
- router.GETJWT("/queenter/upload/category", getUploadCategory)
- router.POSTJWT("/queenter/upload/matgroup", uploadMatGroup)
- }
- func getUploadCategory(c *gin.Context, apictx *ApiSession) (interface{}, error) {
- body := &struct {
- Uuid string //设备uuid
- }{}
- c.ShouldBindJSON(body)
- if len(body.Uuid) < 1 {
- return nil, fmt.Errorf("uuid不能为空")
- }
- //获取设备绑定的数据库
- userId, _ := primitive.ObjectIDFromHex(apictx.User.Parent)
- list := []*model.DeviceQueenter{}
- err := repo.RepoSeachDocs(apictx.CreateRepoCtx(), &repo.DocsSearchOptions{
- CollectName: repo.CollectionQueenters,
- Query: map[string]interface{}{"userId": userId},
- }, &list)
- if err != nil {
- return nil, err
- }
- if len(list) < 1 {
- return nil, fmt.Errorf("后台没有创建设备无法获取分类")
- }
- var queenter *model.DeviceQueenter = nil
- var defaultQueenter *model.DeviceQueenter = nil
- for _, v := range list {
- if v.IsDefaut != nil && *v.IsDefaut && defaultQueenter == nil {
- defaultQueenter = v
- }
- if body.Uuid == v.Uuid {
- queenter = v
- break
- }
- }
- if queenter == nil && defaultQueenter == nil {
- return nil, fmt.Errorf("没有设置默认设备")
- }
- if queenter == nil {
- queenter = defaultQueenter
- }
- if len(queenter.BindOutId) < 1 {
- return nil, fmt.Errorf("当前设备没有绑定输出内容")
- }
- //获取输出配置
- output := &model.DeviceOutput{}
- err = repo.RepoSeachDoc2(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- CollectName: repo.CollectionQueenterOutputs,
- Query: repo.Map{"_id": queenter.BindOutId},
- }, output)
- if err != nil {
- return nil, err
- }
- if output.Type == "queenmat" { //面料库
- hub := &model.HubMat{}
- err = repo.RepoSeachDoc2(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- CollectName: repo.CollectionHubMats,
- Query: repo.Map{"_id": output.QueenMatId},
- }, hub)
- if err != nil {
- return nil, fmt.Errorf("获取面料库失败")
- }
- scope := "queenmat"
- userCaties := &comm.DbCategory{}
- _, err = repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- CollectName: repo.CollectionCategories,
- Query: repo.Map{"userId": userId, "scope": scope},
- }, userCaties)
- if err != nil {
- return nil, err
- }
- userAssetCaties := &comm.DbAssetUserCategory{}
- _, err = repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
- CollectName: repo.CollectionDbAssetCategory,
- Query: repo.Map{"userId": userId, "scope": scope},
- }, userAssetCaties)
- if err != nil {
- return nil, err
- }
- cates := &comm.DbCategory{}
- for _, v := range userAssetCaties.CategoryConfs {
- if v.DbAssetId.Hex() == hub.DefineId {
- for _, id := range v.CategoryIds {
- for _, c := range userCaties.Categories {
- if c.Id == id {
- cates.Categories = append(cates.Categories, c)
- break
- }
- }
- }
- }
- }
- return cates, nil
- }
- return nil, nil
- }
- // 上传面料组
- func uploadMatGroup(c *gin.Context, apictx *ApiSession) (interface{}, error) {
- body := &struct {
- Uuid string //设备uuid
- }{}
- c.ShouldBindJSON(body)
- //获取设备绑定的数据库
- return nil, nil
- }
|