forked from ixre/go2o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
china_dao.go
53 lines (48 loc) · 1.03 KB
/
china_dao.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright 2014 @ z3q.net.
* name :
* author : jarryliu
* date : 2014-02-05 21:53
* description :
* history :
*/
package dao
import (
"database/sql"
"github.com/jsix/gof/db"
"github.com/jsix/gof/web/ui/tree"
"go2o/src/core/ording/dao/entity"
)
type commDao struct {
db.Connector
}
func (this *commDao) GetChinaTree() *tree.TreeNode {
var nodes []tree.TreeNode = []tree.TreeNode{}
this.Connector.Query(`SELECT
Id,
Pid,
Name,
Id as Value
FROM china`,
func(rows *sql.Rows) {
for rows.Next() {
node := tree.TreeNode{}
rows.Scan(&node.Id, &node.Pid, &node.Text, &node.Value)
nodes = append(nodes, node)
}
rows.Close()
})
return tree.List2Tree(nodes)
}
//获取父级位置
func (this *commDao) GetParentPlace(id int) *entity.Area {
var e *entity.Area
this.Connector.QueryRow(`SELECT Id, Pid, Name FROM china
WHERE Id = (SELECT china2.Pid
FROM china china2 WHERE china2.Id=?)`,
func(row *sql.Row) {
e = &entity.Area{}
row.Scan(&e.Id, &e.Pid, &e.Name)
}, id)
return e
}