|
@@ -40,9 +40,9 @@ func getSortInt(apictx *ApiSession, collection string) int {
|
|
|
out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: collection,
|
|
|
Page: 1,
|
|
|
- Size: 2,
|
|
|
+ Size: 1,
|
|
|
// 降序,越大的在前面
|
|
|
- Sort: repo.Map{"Sort": -1},
|
|
|
+ Sort: repo.Map{"sort": -1},
|
|
|
})
|
|
|
if err != nil {
|
|
|
return 0
|
|
@@ -50,9 +50,9 @@ func getSortInt(apictx *ApiSession, collection string) int {
|
|
|
if len(out.List) < 1 {
|
|
|
return 0
|
|
|
}
|
|
|
- sort := out.List[0]["sort"].(int)
|
|
|
+ sort := out.List[0]["sort"].(int32)
|
|
|
fmt.Println("getSortInt: ", sort)
|
|
|
- return sort
|
|
|
+ return int(sort)
|
|
|
}
|
|
|
|
|
|
// 排序置顶
|
|
@@ -64,9 +64,9 @@ func SortTop(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: ClickType,
|
|
|
Page: 1,
|
|
|
- Size: 2,
|
|
|
+ Size: 1,
|
|
|
// 降序,越大的在前面
|
|
|
- Sort: repo.Map{"Sort": -1},
|
|
|
+ Sort: repo.Map{"sort": -1},
|
|
|
})
|
|
|
// 出错false
|
|
|
if err != nil {
|
|
@@ -83,8 +83,8 @@ func SortTop(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
} else {
|
|
|
//如果不是自己
|
|
|
// 更新sort值为: 最大sort的值+1
|
|
|
- sort := out.List[0]["sort"].(int) + 1
|
|
|
- _, err := repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": sort})
|
|
|
+ sort := out.List[0]["sort"].(int32) + 1
|
|
|
+ _, err := repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": int(sort)})
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -107,15 +107,15 @@ func SortPrev(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
CollectName: ClickType,
|
|
|
Query: repo.Map{"_id": id},
|
|
|
})
|
|
|
- currentSort := result["sort"].(int)
|
|
|
+ currentSort := result["sort"].(int32)
|
|
|
// 获取当前数据的上一条数据的sort
|
|
|
out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: ClickType,
|
|
|
- Query: repo.Map{"sort": repo.Map{"$gt": currentSort}},
|
|
|
+ Query: repo.Map{"sort": repo.Map{"$gt": int(currentSort)}},
|
|
|
Page: 1,
|
|
|
- Size: 2,
|
|
|
+ Size: 1,
|
|
|
// 升序,越小的在前面
|
|
|
- Sort: repo.Map{"Sort": 1},
|
|
|
+ Sort: repo.Map{"sort": 1},
|
|
|
})
|
|
|
// 出错false
|
|
|
if err != nil {
|
|
@@ -126,14 +126,14 @@ func SortPrev(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return true, nil
|
|
|
}
|
|
|
// 有数据
|
|
|
- prevSort := out.List[0]["sort"].(int)
|
|
|
- prevId := out.List[0]["sort"].(primitive.ObjectID)
|
|
|
+ prevSort := out.List[0]["sort"].(int32)
|
|
|
+ prevId := out.List[0]["_id"].(primitive.ObjectID)
|
|
|
// 交换id
|
|
|
- _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": prevSort})
|
|
|
+ _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": int(prevSort)})
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
|
- _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, prevId.Hex(), bson.M{"sort": currentSort})
|
|
|
+ _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, prevId.Hex(), bson.M{"sort": int(currentSort)})
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -143,7 +143,7 @@ func SortPrev(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// sort 上移
|
|
|
+// sort 下移
|
|
|
func SortNext(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
// 根据id,type查询获取数据
|
|
|
ClickType := c.Query("type")
|
|
@@ -154,15 +154,15 @@ func SortNext(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
CollectName: ClickType,
|
|
|
Query: repo.Map{"_id": id},
|
|
|
})
|
|
|
- currentSort := result["sort"].(int)
|
|
|
+ currentSort := result["sort"].(int32)
|
|
|
// 获取当前数据的上一条数据的sort
|
|
|
out, err := repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
CollectName: ClickType,
|
|
|
- Query: repo.Map{"sort": repo.Map{"$lt": currentSort}},
|
|
|
+ Query: repo.Map{"sort": repo.Map{"$lt": int(currentSort)}},
|
|
|
Page: 1,
|
|
|
- Size: 2,
|
|
|
+ Size: 1,
|
|
|
// 降序,越大的在前面
|
|
|
- Sort: repo.Map{"Sort": -1},
|
|
|
+ Sort: repo.Map{"sort": -1},
|
|
|
})
|
|
|
// 出错false
|
|
|
if err != nil {
|
|
@@ -173,14 +173,14 @@ func SortNext(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
return true, nil
|
|
|
}
|
|
|
// 有数据
|
|
|
- prevSort := out.List[0]["sort"].(int)
|
|
|
- prevId := out.List[0]["sort"].(primitive.ObjectID)
|
|
|
+ nextSort := out.List[0]["sort"].(int32)
|
|
|
+ nextId := out.List[0]["_id"].(primitive.ObjectID)
|
|
|
// 交换id
|
|
|
- _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": prevSort})
|
|
|
+ _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, id, bson.M{"sort": int(nextSort)})
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
|
- _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, prevId.Hex(), bson.M{"sort": currentSort})
|
|
|
+ _, err = repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), ClickType, nextId.Hex(), bson.M{"sort": int(currentSort)})
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|