|
|
@@ -0,0 +1,72 @@ |
|
|
|
package implement |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/super/dao" |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/super/model" |
|
|
|
zhios_order_relate_utils "code.fnuoos.com/zhimeng/model.git/utils" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func NewCountryDb(engine *xorm.Engine) dao.CountryDao { |
|
|
|
return &CountryDb{Db: engine} |
|
|
|
} |
|
|
|
|
|
|
|
type CountryDb struct { |
|
|
|
Db *xorm.Engine |
|
|
|
} |
|
|
|
|
|
|
|
func (c CountryDb) FindAll() (list []map[string]interface{}) { |
|
|
|
var data []model.Country |
|
|
|
c.Db.Find(&data) |
|
|
|
list = make([]map[string]interface{}, 0) |
|
|
|
top := make([]map[string]interface{}, 0) |
|
|
|
first := make(map[int][]map[string]interface{}) |
|
|
|
second := make(map[int][]map[string]interface{}) |
|
|
|
third := make(map[int][]map[string]interface{}) |
|
|
|
for _, v := range data { |
|
|
|
tmp := map[string]interface{}{ |
|
|
|
"id": zhios_order_relate_utils.IntToStr(v.Id), |
|
|
|
"name": v.Name, |
|
|
|
"child": make([]map[string]interface{}, 0), |
|
|
|
} |
|
|
|
if v.Level == 0 { |
|
|
|
top = append(top, tmp) |
|
|
|
} |
|
|
|
if v.Level == 1 { |
|
|
|
_, ok := first[v.Pid] |
|
|
|
if ok == false { |
|
|
|
first[v.Pid] = make([]map[string]interface{}, 0) |
|
|
|
} |
|
|
|
first[v.Pid] = append(first[v.Pid], tmp) |
|
|
|
} |
|
|
|
if v.Level == 2 { |
|
|
|
_, ok := second[v.Pid] |
|
|
|
if ok == false { |
|
|
|
second[v.Pid] = make([]map[string]interface{}, 0) |
|
|
|
} |
|
|
|
second[v.Pid] = append(second[v.Pid], tmp) |
|
|
|
} |
|
|
|
} |
|
|
|
for k, v := range second { |
|
|
|
for k1, v1 := range v { |
|
|
|
id := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(v1["id"])) |
|
|
|
v[k1]["child"] = third[id] |
|
|
|
} |
|
|
|
second[k] = v |
|
|
|
} |
|
|
|
for k, v := range first { |
|
|
|
for k1, v1 := range v { |
|
|
|
id := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(v1["id"])) |
|
|
|
v[k1]["child"] = second[id] |
|
|
|
} |
|
|
|
first[k] = v |
|
|
|
} |
|
|
|
for k, v := range top { |
|
|
|
id := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(v["id"])) |
|
|
|
top[k]["child"] = first[id] |
|
|
|
} |
|
|
|
if len(top) > 0 { |
|
|
|
list = top |
|
|
|
} |
|
|
|
return |
|
|
|
} |