forked from kevin-hf/education
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
220 lines (192 loc) · 4.95 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
author: kevin
*/
package main
import (
"os"
"fmt"
"github.com/kongyixueyuan.com/education/sdkInit"
"github.com/kongyixueyuan.com/education/service"
"encoding/json"
"github.com/kongyixueyuan.com/education/web/controller"
"github.com/kongyixueyuan.com/education/web"
)
const (
configFile = "config.yaml"
initialized = false
EduCC = "educc"
)
func main() {
initInfo := &sdkInit.InitInfo{
ChannelID: "kevinkongyixueyuan",
ChannelConfig: os.Getenv("GOPATH") + "/src/github.com/kongyixueyuan.com/education/fixtures/artifacts/channel.tx",
OrgAdmin:"Admin",
OrgName:"Org1",
OrdererOrgName: "orderer.kevin.kongyixueyuan.com",
ChaincodeID: EduCC,
ChaincodeGoPath: os.Getenv("GOPATH"),
ChaincodePath: "github.com/kongyixueyuan.com/education/chaincode/",
UserName:"User1",
}
sdk, err := sdkInit.SetupSDK(configFile, initialized)
if err != nil {
fmt.Printf(err.Error())
return
}
defer sdk.Close()
err = sdkInit.CreateChannel(sdk, initInfo)
if err != nil {
fmt.Println(err.Error())
return
}
channelClient, err := sdkInit.InstallAndInstantiateCC(sdk, initInfo)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(channelClient)
//===========================================//
serviceSetup := service.ServiceSetup{
ChaincodeID:EduCC,
Client:channelClient,
}
edu := service.Education{
Name: "张三",
Gender: "男",
Nation: "汉",
EntityID: "101",
Place: "北京",
BirthDay: "1991年01月01日",
EnrollDate: "2009年9月",
GraduationDate: "2013年7月",
SchoolName: "中国政法大学",
Major: "社会学",
QuaType: "普通",
Length: "四年",
Mode: "普通全日制",
Level: "本科",
Graduation: "毕业",
CertNo: "111",
Photo: "/static/photo/11.png",
}
edu2 := service.Education{
Name: "李四",
Gender: "男",
Nation: "汉",
EntityID: "102",
Place: "上海",
BirthDay: "1992年02月01日",
EnrollDate: "2010年9月",
GraduationDate: "2014年7月",
SchoolName: "中国人民大学",
Major: "行政管理",
QuaType: "普通",
Length: "四年",
Mode: "普通全日制",
Level: "本科",
Graduation: "毕业",
CertNo: "222",
Photo: "/static/photo/22.png",
}
msg, err := serviceSetup.SaveEdu(edu)
if err != nil {
fmt.Println(err.Error())
}else {
fmt.Println("信息发布成功, 交易编号为: " + msg)
}
msg, err = serviceSetup.SaveEdu(edu2)
if err != nil {
fmt.Println(err.Error())
}else {
fmt.Println("信息发布成功, 交易编号为: " + msg)
}
// 根据证书编号与名称查询信息
result, err := serviceSetup.FindEduByCertNoAndName("222","李四")
if err != nil {
fmt.Println(err.Error())
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据证书编号与姓名查询信息成功:")
fmt.Println(edu)
}
// 根据身份证号码查询信息
result, err = serviceSetup.FindEduInfoByEntityID("101")
if err != nil {
fmt.Println(err.Error())
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据身份证号码查询信息成功:")
fmt.Println(edu)
}
// 修改/添加信息
info := service.Education{
Name: "张三",
Gender: "男",
Nation: "汉",
EntityID: "101",
Place: "北京",
BirthDay: "1991年01月01日",
EnrollDate: "2013年9月",
GraduationDate: "2015年7月",
SchoolName: "中国政法大学",
Major: "社会学",
QuaType: "普通",
Length: "两年",
Mode: "普通全日制",
Level: "研究生",
Graduation: "毕业",
CertNo: "333",
Photo: "/static/photo/11.png",
}
msg, err = serviceSetup.ModifyEdu(info)
if err != nil {
fmt.Println(err.Error())
}else {
fmt.Println("信息操作成功, 交易编号为: " + msg)
}
// 根据身份证号码查询信息
result, err = serviceSetup.FindEduInfoByEntityID("101")
if err != nil {
fmt.Println(err.Error())
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据身份证号码查询信息成功:")
fmt.Println(edu)
}
// 根据证书编号与名称查询信息
result, err = serviceSetup.FindEduByCertNoAndName("333","张三")
if err != nil {
fmt.Println(err.Error())
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据证书编号与姓名查询信息成功:")
fmt.Println(edu)
}
/*// 删除信息
msg, err = serviceSetup.DelEdu("101")
if err != nil {
fmt.Println(err.Error())
}else {
fmt.Println("信息删除成功, 交易编号为: " + msg)
}
// 根据身份证号码查询信息
result, err = serviceSetup.FindEduInfoByEntityID("101")
if err != nil {
fmt.Println(err.Error())
fmt.Println("根据身份证号码查询信息失败,指定身份证号码的信息不存在或已被删除...")
} else {
var edu service.Education
json.Unmarshal(result, &edu)
fmt.Println("根据身份证号码查询信息成功:")
fmt.Println(edu)
}*/
//===========================================//
app := controller.Application{
Setup: &serviceSetup,
}
web.WebStart(app)
}