|
@@ -132,12 +132,18 @@ type ReqAssetCount struct {
|
|
|
|
|
|
const DateTimeLayout = "2006-01-02 15:04:05"
|
|
|
|
|
|
+// 本地时间字符串转化为标准时间
|
|
|
func (req *ReqAssetCount) GetStartTime() (time.Time, error) {
|
|
|
- return time.Parse(DateTimeLayout, req.StartTime)
|
|
|
+ local, err := time.ParseInLocation(DateTimeLayout, req.StartTime, time.Local)
|
|
|
+ localStart := local.UTC()
|
|
|
+ return localStart, err
|
|
|
}
|
|
|
|
|
|
func (req *ReqAssetCount) GetEndTime() (time.Time, error) {
|
|
|
- return time.Parse(DateTimeLayout, req.EndTime)
|
|
|
+ // return time.Parse(DateTimeLayout, req.EndTime)
|
|
|
+ local, err := time.ParseInLocation(DateTimeLayout, req.EndTime, time.Local)
|
|
|
+ localEnd := local.UTC()
|
|
|
+ return localEnd, err
|
|
|
}
|
|
|
|
|
|
type TypeCount struct {
|
|
@@ -214,7 +220,7 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
bson.M{"createTime": bson.M{"$gte": startTime}},
|
|
|
}},
|
|
|
Project: []string{"defId", "createTime", "count"},
|
|
|
- // Sort: bson.M{"createTime": -1}, // 降序 小于等于createTime中取时间最近的 第一条
|
|
|
+ // Sort: bson.M{"createTime": 1}, // 降序 小于等于createTime中取时间最近的 第一条
|
|
|
|
|
|
}, &listCounts)
|
|
|
if err != nil {
|
|
@@ -229,6 +235,7 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
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{
|
|
|
{
|
|
@@ -250,10 +257,10 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
item := listCounts[listCountIndex]
|
|
|
defId := item.DefId
|
|
|
|
|
|
- if defCountsMap[defId] == nil {
|
|
|
- repo.RepoDeleteDbDoc(apictx.CreateRepoCtx(), databaseDoc.Name, repo.CollectionAssetCount, item.Id.Hex())
|
|
|
- continue
|
|
|
- }
|
|
|
+ // if defCountsMap[defId] == nil {
|
|
|
+ // repo.RepoDeleteDbDoc(apictx.CreateRepoCtx(), databaseDoc.Name, repo.CollectionAssetCount, item.Id.Hex())
|
|
|
+ // continue
|
|
|
+ // }
|
|
|
|
|
|
typeList := defCountsMap[defId]
|
|
|
lastType := typeList.Time[len(typeList.Time)-1]
|
|
@@ -266,7 +273,27 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
Count: item.Count,
|
|
|
StepIndex: int(GetStepIndex(item.CreateTime, endTime, form.Step)),
|
|
|
})
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最开始数据
|
|
|
+
|
|
|
+ query := make(map[string]interface{})
|
|
|
+ query["createTime"] = bson.M{"$lte": startTime}
|
|
|
+ for _, asset := range databaseDoc.Assets {
|
|
|
+
|
|
|
+ // 每次最新的数据统计
|
|
|
+ cout, _ := repo.RepoDbCountDoc(apictx.CreateRepoCtx(), databaseDoc.Name, asset.Collection, query)
|
|
|
+
|
|
|
+ defCountsMap[asset.Id].Time = append(defCountsMap[asset.Id].Time, &model.AssetCountV0{
|
|
|
+ DefId: asset.Id,
|
|
|
+ CreateTime: startTime,
|
|
|
+ Count: int(cout),
|
|
|
+ StepIndex: int(GetStepIndex(startTime, endTime, form.Step)),
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
|
|
|
out := []*TypeCount{}
|
|
@@ -281,7 +308,7 @@ func GetInfo(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"types": out,
|
|
|
- "time": time.Now().Sub(searchTime).Seconds(),
|
|
|
+ "time": time.Since(searchTime).Seconds(),
|
|
|
}, nil
|
|
|
|
|
|
}
|