You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
2.8 KiB
120 lines
2.8 KiB
package Test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
type listItem struct {
|
|
BusinessCode string `json:"business_code"`
|
|
MenuUrl string `json:"menu_url"`
|
|
ParentId string `json:"parent_id"`
|
|
PurviewId string `json:"purview_id"`
|
|
PurviewName string `json:"purview_name"`
|
|
SortId string `json:"sort_id"`
|
|
}
|
|
|
|
type bigJson struct {
|
|
Success bool
|
|
Message string
|
|
Count int
|
|
list []listItem
|
|
}
|
|
|
|
/**
|
|
功能:结构体排序通用办法 按标签排序
|
|
*/
|
|
type SortTagsStructSlice []listItem
|
|
|
|
func (a SortTagsStructSlice) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
func (a SortTagsStructSlice) Swap(i, j int) {
|
|
a[i], a[j] = a[j], a[i]
|
|
}
|
|
|
|
func (a SortTagsStructSlice) Less(i, j int) bool {
|
|
return a[i].SortId < a[j].SortId
|
|
}
|
|
|
|
|
|
func TestSqlBuilder(t *testing.T) {
|
|
jsonStr := `{
|
|
"success": true,
|
|
"message": "操作成功",
|
|
"list": [],
|
|
"count": 7
|
|
}`
|
|
listJson := `[
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "29050385-3E01-4E7D-8805-21B19960351F",
|
|
"purview_id": "321E6A29-6326-4F79-8EEB-40A4A3BB6561",
|
|
"purview_name": "学生用户管理",
|
|
"sort_id": "5"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "00000000-0000-0000-0000-000000000000",
|
|
"purview_id": "E1CB0804-2498-4A99-B419-B732EC7E8E52",
|
|
"purview_name": "组织机构管理",
|
|
"sort_id": "6"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "29050385-3E01-4E7D-8805-21B19960351F",
|
|
"purview_id": "687AD08F-DB9B-4992-A889-179BB3D8C067",
|
|
"purview_name": "教职工用户管理",
|
|
"sort_id": "4"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "E1CB0804-2498-4A99-B419-B732EC7E8E52",
|
|
"purview_id": "DBBA5B31-92D7-4654-A762-51B596E8B2C6",
|
|
"purview_name": "学校信息管理",
|
|
"sort_id": "3"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "E1CB0804-2498-4A99-B419-B732EC7E8E52",
|
|
"purview_id": "D815BF5A-9EB6-4662-A758-21B24041B2D7",
|
|
"purview_name": "教育局信息管理",
|
|
"sort_id": "2"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "E1CB0804-2498-4A99-B419-B732EC7E8E52",
|
|
"purview_id": "F1CEB14D-290F-440F-B583-79CF7DE518F0",
|
|
"purview_name": "教辅单位信息管理",
|
|
"sort_id": "1"
|
|
},
|
|
{
|
|
"business_code": "B00001",
|
|
"menu_url": "#",
|
|
"parent_id": "00000000-0000-0000-0000-000000000000",
|
|
"purview_id": "29050385-3E01-4E7D-8805-21B19960351F",
|
|
"purview_name": "用户信息管理",
|
|
"sort_id": "7"
|
|
}
|
|
]`
|
|
var m1 []listItem
|
|
json.Unmarshal([]byte(listJson), &m1)
|
|
//排序
|
|
sort.Sort(SortTagsStructSlice(m1))
|
|
|
|
var m bigJson
|
|
json.Unmarshal([]byte(jsonStr), &m)
|
|
m.list=m1
|
|
|
|
fmt.Println(m)
|
|
}
|