|
@@ -1,511 +0,0 @@
|
|
|
-// package api
|
|
|
-
|
|
|
-// import (
|
|
|
-// "queencount/db/model"
|
|
|
-// "queencount/db/repo"
|
|
|
-// "errors"
|
|
|
-// "fmt"
|
|
|
-// "time"
|
|
|
-
|
|
|
-// "github.com/gin-gonic/gin"
|
|
|
-// )
|
|
|
-
|
|
|
-// func AssetCount(router *GinRouter) {
|
|
|
-// router.GETJWT("/count/info", GetAssetCount)
|
|
|
-// // 统计总图表
|
|
|
-// router.GET("/count/info/chart", GetInfoChart)
|
|
|
-// // 定义模型图表
|
|
|
-// router.GET("/count/def/chart", GetDefModelChart)
|
|
|
-// // 定义模型分类
|
|
|
-// router.GET("/count/def/cate", GetDefModelCate)
|
|
|
-// }
|
|
|
-
|
|
|
-// const SKU3D_DB = "sku3d-tree"
|
|
|
-
|
|
|
-// type AssetDefCountInfo struct {
|
|
|
-// Mesh []CountDefItem `json:"mesh"`
|
|
|
-// Image []CountDefItem `json:"image"`
|
|
|
-// Material []CountDefItem `json:"material"`
|
|
|
-// Env3d []CountDefItem `json:"env3d"`
|
|
|
-// }
|
|
|
-
|
|
|
-// type CountDefItem struct {
|
|
|
-// DefItemNum int `json:"defItemNum"`
|
|
|
-// DefName string `json:"defName"`
|
|
|
-// DefKey string `json:"defKey"`
|
|
|
-// }
|
|
|
-
|
|
|
-// func GetAssetCount(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// // databases := []string{"mesh", "image", "material", "env3d"}
|
|
|
-// // 定义模型数量
|
|
|
-
|
|
|
-// query := make(map[string]interface{})
|
|
|
-// query["userId"] = apictx.User.ID
|
|
|
-
|
|
|
-// option := &repo.DocSearchOptions{
|
|
|
-// CollectName: repo.CollectionDatabase,
|
|
|
-// Query: query,
|
|
|
-// Project: []string{"_id", "assets"},
|
|
|
-// }
|
|
|
-// var datbaseDoc model.Database
|
|
|
-
|
|
|
-// found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), option, &datbaseDoc)
|
|
|
-// if err != nil {
|
|
|
-// return nil, err
|
|
|
-// }
|
|
|
-// if !found {
|
|
|
-// return nil, err
|
|
|
-// }
|
|
|
-
|
|
|
-// var countDefitem CountDefItem
|
|
|
-// var assetDefCountInfo AssetDefCountInfo
|
|
|
-
|
|
|
-// defMeshSet := make([]CountDefItem, 0)
|
|
|
-// defImageSet := make([]CountDefItem, 0)
|
|
|
-// defMaterialSet := make([]CountDefItem, 0)
|
|
|
-// defEnv3dSet := make([]CountDefItem, 0)
|
|
|
-
|
|
|
-// for _, v := range datbaseDoc.Assets {
|
|
|
-// // 模型
|
|
|
-// if v.Type == 10 {
|
|
|
-// countDefitem.DefKey = v.Collection
|
|
|
-// countDefitem.DefName = v.Label
|
|
|
-
|
|
|
-// parm := &repo.DbDocsSearchOptions{
|
|
|
-// Db: SKU3D_DB,
|
|
|
-// Query: map[string]interface{}{"ownerId": apictx.User.ID},
|
|
|
-// CollectName: v.Collection,
|
|
|
-// Project: []string{"_id"},
|
|
|
-// }
|
|
|
-
|
|
|
-// ok, res := repo.DbRepoSeachDocsMap(apictx.CreateRepoCtx(), parm)
|
|
|
-// if ok {
|
|
|
-// countDefitem.DefItemNum = len(res)
|
|
|
-// defMeshSet = append(defMeshSet, countDefitem)
|
|
|
-// assetDefCountInfo.Mesh = defMeshSet
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-// if v.Type == 20 {
|
|
|
-// countDefitem.DefKey = v.Collection
|
|
|
-// countDefitem.DefName = v.Label
|
|
|
-
|
|
|
-// parm := &repo.DbDocsSearchOptions{
|
|
|
-// Db: SKU3D_DB,
|
|
|
-// Query: map[string]interface{}{"ownerId": apictx.User.ID},
|
|
|
-// CollectName: v.Collection,
|
|
|
-// Project: []string{"_id"},
|
|
|
-// }
|
|
|
-
|
|
|
-// ok, res := repo.DbRepoSeachDocsMap(apictx.CreateRepoCtx(), parm)
|
|
|
-// if ok {
|
|
|
-// countDefitem.DefItemNum = len(res)
|
|
|
-// defImageSet = append(defImageSet, countDefitem)
|
|
|
-// assetDefCountInfo.Image = defImageSet
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-// if v.Type == 30 {
|
|
|
-// countDefitem.DefKey = v.Collection
|
|
|
-// countDefitem.DefName = v.Label
|
|
|
-
|
|
|
-// parm := &repo.DbDocsSearchOptions{
|
|
|
-// Db: SKU3D_DB,
|
|
|
-// Query: map[string]interface{}{"ownerId": apictx.User.ID},
|
|
|
-// CollectName: v.Collection,
|
|
|
-// Project: []string{"_id"},
|
|
|
-// }
|
|
|
-
|
|
|
-// ok, res := repo.DbRepoSeachDocsMap(apictx.CreateRepoCtx(), parm)
|
|
|
-// if ok {
|
|
|
-// countDefitem.DefItemNum = len(res)
|
|
|
-// defMaterialSet = append(defMaterialSet, countDefitem)
|
|
|
-// assetDefCountInfo.Material = defMaterialSet
|
|
|
-
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if v.Type == 40 {
|
|
|
-// countDefitem.DefKey = v.Collection
|
|
|
-// countDefitem.DefName = v.Label
|
|
|
-
|
|
|
-// parm := &repo.DbDocsSearchOptions{
|
|
|
-// Db: SKU3D_DB,
|
|
|
-// Query: map[string]interface{}{"ownerId": apictx.User.ID},
|
|
|
-// CollectName: v.Collection,
|
|
|
-// Project: []string{"_id"},
|
|
|
-// }
|
|
|
-
|
|
|
-// ok, res := repo.DbRepoSeachDocsMap(apictx.CreateRepoCtx(), parm)
|
|
|
-// if ok {
|
|
|
-// countDefitem.DefItemNum = len(res)
|
|
|
-// defEnv3dSet = append(defEnv3dSet, countDefitem)
|
|
|
-// assetDefCountInfo.Env3d = defEnv3dSet
|
|
|
-
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// return assetDefCountInfo, nil
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// // 增量时间段
|
|
|
-// type IncrementDuration struct {
|
|
|
-// Start time.Time
|
|
|
-// End time.Time
|
|
|
-// }
|
|
|
-
|
|
|
-// // 增量时间段集合
|
|
|
-// type IncrementTimes []IncrementDuration
|
|
|
-
|
|
|
-// type ReqFrom struct {
|
|
|
-// TimeType string `json:"timeType"` // day
|
|
|
-// TimeStep string `json:"timeStep"` // 1h
|
|
|
-// }
|
|
|
-
|
|
|
-// type ListItem struct {
|
|
|
-// Type string `json:"type"`
|
|
|
-// Data []int `json:"data"`
|
|
|
-// }
|
|
|
-// type ResultData struct {
|
|
|
-// Step string `json:"step"`
|
|
|
-// Time []time.Time `json:"time"`
|
|
|
-// List []ListItem `json:"list"`
|
|
|
-// }
|
|
|
-
|
|
|
-// // 步距代表的小时数
|
|
|
-// var step2HourTimes = map[string]int32{"1h": 1, "1d": 24, "1w": 24 * 7, "1M": 24 * 30}
|
|
|
-
|
|
|
-// // 类型代表的小时数
|
|
|
-// var type2HourTimes = map[string]int32{"day": 24, "threeDay": 24, "week": 24 * 30, "month": 30 * 24, "year": 365 * 24, "all": 120 * 24}
|
|
|
-
|
|
|
-// // 获取统计信息图表需要的信息
|
|
|
-// func GetInfoChart(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// var form ReqFrom
|
|
|
-// // err := c.ShouldBindJSON(&form)
|
|
|
-// // if err != nil {
|
|
|
-// // return nil, err
|
|
|
-// // }
|
|
|
-// form.TimeStep = "1h"
|
|
|
-// form.TimeType = "day"
|
|
|
-// if form.TimeType == "" {
|
|
|
-// return nil, errors.New("时间类型不能为空")
|
|
|
-// }
|
|
|
-// if form.TimeStep == "" {
|
|
|
-// return nil, errors.New("时间步距不能为空")
|
|
|
-// }
|
|
|
-
|
|
|
-// ctx := apictx.CreateRepoCtx()
|
|
|
-// userId := apictx.User.ID
|
|
|
-// var list ResultData
|
|
|
-
|
|
|
-// incrementTimes, timeSet := GetIncrementTimes(form.TimeType, form.TimeStep)
|
|
|
-
|
|
|
-// countCollection := "assetcount"
|
|
|
-// query := make(map[string]interface{})
|
|
|
-// query["userId"] = userId
|
|
|
-
|
|
|
-// parm := &repo.DocsSearchOptions{
|
|
|
-// CollectName: countCollection,
|
|
|
-// Project: []string{"_id", "productId", "type", "defKey", "defName", "createTime"},
|
|
|
-// }
|
|
|
-
|
|
|
-// // "mesh"
|
|
|
-// var meshItem ListItem
|
|
|
-// meshItem.Type = "mesh"
|
|
|
-// for _, incrementTime := range incrementTimes {
|
|
|
-// // 拼接条件 查询各个增量时间段的数据
|
|
|
-// query["$gt"] = incrementTime.Start
|
|
|
-// query["$lte"] = incrementTime.End
|
|
|
-// query["type"] = "mesh"
|
|
|
-// parm.Query = query
|
|
|
-// ok, res := repo.RepoSeachDocsMap(ctx, parm)
|
|
|
-// if ok {
|
|
|
-// meshItem.Data = append(meshItem.Data, len(res))
|
|
|
-// }
|
|
|
-// }
|
|
|
-// list.List = append(list.List, meshItem)
|
|
|
-
|
|
|
-// // "image"
|
|
|
-// var imageItem ListItem
|
|
|
-// imageItem.Type = "image"
|
|
|
-// for _, incrementTime := range incrementTimes {
|
|
|
-// // 拼接条件 查询各个增量时间段的数据
|
|
|
-// query["$gt"] = incrementTime.Start
|
|
|
-// query["$lte"] = incrementTime.End
|
|
|
-// query["type"] = "image"
|
|
|
-// parm.Query = query
|
|
|
-// ok, res := repo.RepoSeachDocsMap(ctx, parm)
|
|
|
-// if ok {
|
|
|
-// imageItem.Data = append(imageItem.Data, len(res))
|
|
|
-// }
|
|
|
-// }
|
|
|
-// list.List = append(list.List, imageItem)
|
|
|
-
|
|
|
-// // "material"
|
|
|
-// var materialItem ListItem
|
|
|
-// materialItem.Type = "material"
|
|
|
-
|
|
|
-// for _, incrementTime := range incrementTimes {
|
|
|
-// // 拼接条件 查询各个增量时间段的数据
|
|
|
-// query["$gt"] = incrementTime.Start
|
|
|
-// query["$lte"] = incrementTime.End
|
|
|
-// query["type"] = "material"
|
|
|
-// parm.Query = query
|
|
|
-// ok, res := repo.RepoSeachDocsMap(ctx, parm)
|
|
|
-// if ok {
|
|
|
-// materialItem.Data = append(materialItem.Data, len(res))
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// list.List = append(list.List, materialItem)
|
|
|
-
|
|
|
-// // "env3d"
|
|
|
-// var env3dItem ListItem
|
|
|
-// env3dItem.Type = "env3d"
|
|
|
-// for _, incrementTime := range incrementTimes {
|
|
|
-// // 拼接条件 查询各个增量时间段的数据
|
|
|
-// query["$gt"] = incrementTime.Start
|
|
|
-// query["$lte"] = incrementTime.End
|
|
|
-// query["type"] = "env3d"
|
|
|
-// parm.Query = query
|
|
|
-// ok, res := repo.RepoSeachDocsMap(ctx, parm)
|
|
|
-// if ok {
|
|
|
-// env3dItem.Data = append(env3dItem.Data, len(res))
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// list.List = append(list.List, env3dItem)
|
|
|
-// list.Step = form.TimeStep
|
|
|
-// list.Time = timeSet
|
|
|
-
|
|
|
-// return list, nil
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// type ItemCountResult struct {
|
|
|
-// Step string `json:"step"`
|
|
|
-// Time []time.Time `json:"time"`
|
|
|
-// Data ItemCount `json:"data"`
|
|
|
-// }
|
|
|
-
|
|
|
-// type ItemCount struct {
|
|
|
-// DefKey string `json:"defKey"`
|
|
|
-// DefName string `json:"defName"`
|
|
|
-// Data []int `json:"data"`
|
|
|
-// }
|
|
|
-
|
|
|
-// // 获取定义模型的统计数据
|
|
|
-// func GetDefModelChart(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-// // 接受timeType timeStep type defKey
|
|
|
-// var form struct {
|
|
|
-// TimeType string `json:"timeType"`
|
|
|
-// TimeStep string `json:"timeStep"`
|
|
|
-// Type string `json:"type"`
|
|
|
-// DefKey string `json:"defKey"`
|
|
|
-// }
|
|
|
-// // err := c.ShouldBindJSON(&form)
|
|
|
-// // if err != nil {
|
|
|
-// // return nil, err
|
|
|
-// // }
|
|
|
-// form.TimeStep = "1h"
|
|
|
-// form.TimeType = "day"
|
|
|
-// if form.TimeType == "" {
|
|
|
-// return nil, errors.New("时间类型不能为空")
|
|
|
-// }
|
|
|
-// if form.TimeStep == "" {
|
|
|
-// return nil, errors.New("时间步距不能为空")
|
|
|
-// }
|
|
|
-// if form.Type == "" {
|
|
|
-// return nil, errors.New("时间类型不能为空")
|
|
|
-// }
|
|
|
-// if form.TimeStep == "" {
|
|
|
-// return nil, errors.New("时间步距不能为空")
|
|
|
-// }
|
|
|
-
|
|
|
-// ctx := apictx.CreateRepoCtx()
|
|
|
-// userId := apictx.User.ID
|
|
|
-// var result ItemCountResult
|
|
|
-// var data ItemCount
|
|
|
-// data.DefKey = form.DefKey
|
|
|
-
|
|
|
-// incrementTimes, timeSet := GetIncrementTimes(form.TimeType, form.TimeStep)
|
|
|
-// result.Time = timeSet
|
|
|
-
|
|
|
-// countCollection := "assetcount"
|
|
|
-// query := make(map[string]interface{})
|
|
|
-// query["userId"] = userId
|
|
|
-
|
|
|
-// parm := &repo.DocsSearchOptions{
|
|
|
-// CollectName: countCollection,
|
|
|
-// Project: []string{"_id", "productId", "type", "defKey", "defName", "createTime"},
|
|
|
-// }
|
|
|
-
|
|
|
-// for _, incrementTime := range incrementTimes {
|
|
|
-// // 拼接条件 查询各个增量时间段的数据
|
|
|
-// query["$gt"] = incrementTime.Start
|
|
|
-// query["$lte"] = incrementTime.End
|
|
|
-// query["type"] = form.Type
|
|
|
-// query["defKey"] = form.DefKey
|
|
|
-// parm.Query = query
|
|
|
-// ok, res := repo.RepoSeachDocsMap(ctx, parm)
|
|
|
-// if ok {
|
|
|
-// data.Data = append(data.Data, len(res))
|
|
|
-// }
|
|
|
-// }
|
|
|
-// result.Data = data
|
|
|
-
|
|
|
-// return result, nil
|
|
|
-// }
|
|
|
-
|
|
|
-// type DefInfo struct {
|
|
|
-// DefName string `json:"defName"`
|
|
|
-// DefKey string `json:"defKey"`
|
|
|
-// }
|
|
|
-
|
|
|
-// type DefCateInfo struct {
|
|
|
-// Mesh []DefInfo
|
|
|
-// Image []DefInfo
|
|
|
-// Material []DefInfo
|
|
|
-// Env3d []DefInfo
|
|
|
-// }
|
|
|
-
|
|
|
-// // 获取用户定义类型分类
|
|
|
-// func GetDefModelCate(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
-
|
|
|
-// var form struct {
|
|
|
-// Name string `json:"name"`
|
|
|
-// }
|
|
|
-// err := c.ShouldBindJSON(&form)
|
|
|
-// if err != nil {
|
|
|
-// return nil, errors.New("参数错误")
|
|
|
-// }
|
|
|
-// if form.Name == "" {
|
|
|
-// return nil, errors.New("资产库名不能为空")
|
|
|
-// }
|
|
|
-// // 查询 database 根据name 和用户id查找用户的asset资产
|
|
|
-// // 遍历资产信息,根据type获取对应类型的资产集合
|
|
|
-// // 62f05931ae8ddfeb72cf684e sku3d-tree
|
|
|
-// var database model.Database
|
|
|
-// ctx := apictx.CreateRepoCtx()
|
|
|
-// var defCateInfo DefCateInfo
|
|
|
-// var defInfo DefInfo
|
|
|
-// query := make(map[string]interface{})
|
|
|
-// // query["userId"] = apictx.User.ID
|
|
|
-// query["userId"] = "62f05931ae8ddfeb72cf684e"
|
|
|
-// // query["name"] = form.Name
|
|
|
-// query["name"] = "sku3d-tree"
|
|
|
-
|
|
|
-// param := &repo.DocSearchOptions{
|
|
|
-// CollectName: repo.CollectionDatabase,
|
|
|
-// Query: query,
|
|
|
-// Project: []string{"_id", "assets"},
|
|
|
-// }
|
|
|
-// ok, err := repo.RepoSeachDoc(ctx, param, &database)
|
|
|
-// if err != nil || !ok {
|
|
|
-// return nil, errors.New("查询数据错误")
|
|
|
-// }
|
|
|
-
|
|
|
-// for _, v := range database.Assets {
|
|
|
-// if v.Type == 10 {
|
|
|
-// defInfo.DefKey = v.Collection
|
|
|
-// defInfo.DefName = v.Label
|
|
|
-// defCateInfo.Mesh = append(defCateInfo.Mesh, defInfo)
|
|
|
-// }
|
|
|
-// if v.Type == 20 {
|
|
|
-// defInfo.DefKey = v.Collection
|
|
|
-// defInfo.DefName = v.Label
|
|
|
-// defCateInfo.Image = append(defCateInfo.Image, defInfo)
|
|
|
-// }
|
|
|
-// if v.Type == 30 {
|
|
|
-// defInfo.DefKey = v.Collection
|
|
|
-// defInfo.DefName = v.Label
|
|
|
-// defCateInfo.Material = append(defCateInfo.Material, defInfo)
|
|
|
-// }
|
|
|
-// if v.Type == 40 {
|
|
|
-// defInfo.DefKey = v.Collection
|
|
|
-// defInfo.DefName = v.Label
|
|
|
-// defCateInfo.Env3d = append(defCateInfo.Env3d, defInfo)
|
|
|
-// }
|
|
|
-
|
|
|
-// }
|
|
|
-
|
|
|
-// return defCateInfo, nil
|
|
|
-// }
|
|
|
-
|
|
|
-// // 根据时间段进行范围查找
|
|
|
-// // [
|
|
|
-// // {
|
|
|
-// // "Start": "2022-10-13T15:35:11.072184706+08:00",
|
|
|
-// // "End": "2022-10-13T17:35:11.072184706+08:00"
|
|
|
-// // }
|
|
|
-// // ]
|
|
|
-
|
|
|
-// // 获取当前用户各个资源类型的
|
|
|
-
|
|
|
-// // f := bson.M{"orderId": bson.M{"$gte": minId, "$lt": maxId}, "type": item["type"].(string)}
|
|
|
-// // filters = append(filters, f)
|
|
|
-
|
|
|
-// // ok, extendsItems := RepoSeachDocsMap(ctx, &DocsSearchOptions{CollectName: CollectionLibCategory, Query: Map{"$or": filters}, Project: []string{"_id"}})
|
|
|
-
|
|
|
-// // // return nil, nil
|
|
|
-// // 今天用mongodb查昨天某个collection产生的记录数量,在mysql里面可以用between..and..或者 >、>=、<、<=来查
|
|
|
-// // 询指定的时间范围数据,但是mongodb有自己的语法。mongodb里比较,用 "$gt" 、"$gte"、 "$lt"、 "$lte"(分别对应">"、 ">=" 、"<" 、"<="),
|
|
|
-// // 组合起来可以进行范围的查找。比如查昨天的,就可以用
|
|
|
-
|
|
|
-// // db.CollectionAAA.find({ "CreateTime" : { "$gte" : ISODate("2017-04-20T00:00:00Z")
|
|
|
-// // , "$lt" : ISODate("2017-04-21T00:00:00Z") } }).count()
|
|
|
-// // 注意,开始的时候日期使用 "2017-04-20" 和"2017-04-21",但是返回结果为空,应该日期字段需要指定格式吧,看了下存在库里的数据为ISODate类型,所以直接写成ISODate的方式,结果就正常了。
|
|
|
-
|
|
|
-// // }
|
|
|
-
|
|
|
-// // 根据类型/步距 = 时间点个数
|
|
|
-
|
|
|
-// // 获取时间集合 用于统计查询
|
|
|
-// func GetIncrementTimes(timeType string, timeStep string) (incrementTimes IncrementTimes, timeSet []time.Time) {
|
|
|
-// // key 对应 时间段 day threeDay ...
|
|
|
-// step, ok := step2HourTimes[timeStep]
|
|
|
-// if !ok {
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// typev, ok := type2HourTimes[timeType]
|
|
|
-// fmt.Println(typev)
|
|
|
-// if !ok {
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// // 这个类型有多少个记录点
|
|
|
-// times := typev/step + 1
|
|
|
-
|
|
|
-// now := time.Now() //获取当前时间
|
|
|
-// incrementDuration := IncrementDuration{}
|
|
|
-
|
|
|
-// // 24小时之前
|
|
|
-// // a, _ := time.ParseDuration(fmt.Sprintf("%dh", -counts))
|
|
|
-// // start := now.Add(a)
|
|
|
-
|
|
|
-// for i := times; i > 0; i-- {
|
|
|
-// if timeStep == "1d" {
|
|
|
-// i = i * 24
|
|
|
-// }
|
|
|
-// if timeStep == "1w" {
|
|
|
-// i = i * 24 * 7
|
|
|
-// }
|
|
|
-// if timeStep == "1M" {
|
|
|
-// i = i * 24 * 30
|
|
|
-// }
|
|
|
-// a, _ := time.ParseDuration(fmt.Sprintf("%dh", -i))
|
|
|
-// b, _ := time.ParseDuration(fmt.Sprintf("%dh", -i+1))
|
|
|
-// start := now.Add(a)
|
|
|
-// end := now.Add(b)
|
|
|
-// incrementDuration.Start = start
|
|
|
-// incrementDuration.End = end
|
|
|
-// incrementTimes = append(incrementTimes, incrementDuration)
|
|
|
-// timeSet = append(timeSet, end)
|
|
|
-// }
|
|
|
-// return incrementTimes, timeSet
|
|
|
-
|
|
|
-// }
|