|
@@ -5,6 +5,7 @@ import (
|
|
|
"fmt"
|
|
|
"queencount/db/model"
|
|
|
"queencount/db/repo"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
@@ -154,10 +155,16 @@ func GetStepIndex(t time.Time, endTime time.Time, step int) int64 {
|
|
|
func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
var form ReqAssetCount
|
|
|
- err := c.ShouldBindJSON(&form)
|
|
|
+
|
|
|
+ form.DbId = c.Query("dbId")
|
|
|
+ step, err := strconv.Atoi(c.Query("step"))
|
|
|
if err != nil {
|
|
|
- return nil, errors.New("参数错误")
|
|
|
+ return nil, err
|
|
|
}
|
|
|
+ form.Step = step
|
|
|
+
|
|
|
+ form.StartTime = c.Query("startTime")
|
|
|
+ form.EndTime = c.Query("endTime")
|
|
|
|
|
|
if form.Step == 0 {
|
|
|
return nil, errors.New("时间步距不能为空")
|
|
@@ -214,7 +221,25 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
+ typeDefsMap := map[string]*model.DbAsset{}
|
|
|
+ for _, v := range databaseDoc.Assets {
|
|
|
+ typeDefsMap[v.Id] = v
|
|
|
+ }
|
|
|
+
|
|
|
defCountsMap := map[string]*TypeCount{}
|
|
|
+
|
|
|
+ for _, asset := range databaseDoc.Assets {
|
|
|
+ cout, _ := repo.RepoDbCountDoc(apictx.CreateRepoCtx(), databaseDoc.Name, asset.Collection, repo.Map{})
|
|
|
+ defCountsMap[asset.Id] = &TypeCount{Time: []*model.AssetCountV0{
|
|
|
+ {
|
|
|
+ DefId: asset.Id,
|
|
|
+ CreateTime: endTime,
|
|
|
+ Count: int(cout),
|
|
|
+ StepIndex: 0,
|
|
|
+ },
|
|
|
+ }}
|
|
|
+ }
|
|
|
+
|
|
|
listCountIndex := len(listCounts)
|
|
|
for {
|
|
|
if listCountIndex == 0 {
|
|
@@ -226,14 +251,7 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
defId := item.DefId
|
|
|
|
|
|
if defCountsMap[defId] == nil {
|
|
|
- defCountsMap[defId] = &TypeCount{Time: []*model.AssetCountV0{
|
|
|
- {
|
|
|
- DefId: item.DefId,
|
|
|
- CreateTime: item.CreateTime,
|
|
|
- Count: item.Count,
|
|
|
- StepIndex: int(GetStepIndex(item.CreateTime, endTime, form.Step)),
|
|
|
- },
|
|
|
- }}
|
|
|
+ repo.RepoDeleteDbDoc(apictx.CreateRepoCtx(), databaseDoc.Name, repo.CollectionAssetCount, item.Id.Hex())
|
|
|
continue
|
|
|
}
|
|
|
|
|
@@ -254,14 +272,10 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
out := []*TypeCount{}
|
|
|
|
|
|
for defId, _ := range defCountsMap {
|
|
|
- for _, v := range databaseDoc.Assets {
|
|
|
- if v.Id == defId {
|
|
|
- defCountsMap[defId].DefType = v.Type
|
|
|
- defCountsMap[defId].DefName = v.Label
|
|
|
- defCountsMap[defId].DefId = v.Id
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
+ v := typeDefsMap[defId]
|
|
|
+ defCountsMap[defId].DefType = v.Type
|
|
|
+ defCountsMap[defId].DefName = v.Label
|
|
|
+ defCountsMap[defId].DefId = v.Id
|
|
|
out = append(out, defCountsMap[defId])
|
|
|
}
|
|
|
|