-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (64 loc) · 1.55 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
package main
import (
_ "beego_survey/routers"
"beego_survey/utils"
"strings"
"beego_survey/models"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
)
func init() {
models.RegisterDB()
}
func split(in string) (out []string) {
out = strings.Split(in, "#op%")
return
}
func addOne(in int) (out int) {
out = in + 1
return
}
func printResolution(record models.Records, question models.Questions, paperType int) (out string) {
answers, _ := models.FindAnswersByQuestionIDandRecordID(question.QuestionID, record.RecordID)
out = ""
if len(answers) > 0 {
out += "您的答案:"
switch question.Type {
case 0:
out += " " + utils.ToString(answers[0].AnswerNo)
case 1:
for _, v := range answers {
out += " " + utils.ToString(v.AnswerNo)
}
case 2:
out += " " + answers[0].AnswerText
}
}
if paperType == 1 {
standards, _ := models.FindStandardsByQuestion(&question)
if len(standards) > 0 {
out += "<br>标准答案:"
switch question.Type {
case 0:
out += " " + utils.ToString(standards[0].StandardNo)
case 1:
for _, v := range standards {
out += " " + utils.ToString(v.StandardNo)
}
case 2:
out += " " + standards[0].StandardText
}
}
if len(answers) > 0 {
out += "<br> 得分:" + utils.ToString(answers[0].Scores)
}
}
return out
}
func main() {
orm.RunSyncdb("default", false, true) //自动建表 表名 强制建表 打印相关信息
beego.AddFuncMap("split", split)
beego.AddFuncMap("addOne", addOne)
beego.AddFuncMap("printResolution", printResolution)
beego.Run()
}