70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"docDemo/client"
|
|
"docDemo/model"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/xuri/excelize/v2"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
var AZ = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
|
|
|
|
func TestMap(t *testing.T) {
|
|
|
|
file, err := excelize.OpenFile("result.xlsx")
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
rows, err := file.GetRows("Sheet1")
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for _, row := range rows[1:3] {
|
|
if row[0] == "" {
|
|
break
|
|
}
|
|
|
|
var ques []map[string]string
|
|
for i := range row[2:] {
|
|
ques = append(ques, map[string]string{AZ[i]: row[2:][i]})
|
|
}
|
|
|
|
awssJson, err := json.Marshal(ques)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var Questions model.Question
|
|
Questions.Content = row[1]
|
|
Questions.Answer = string(awssJson)
|
|
Questions.Analysis = "A"
|
|
Questions.CorrectAnswer = "A"
|
|
Questions.Subject = "大学语文"
|
|
|
|
if strings.Contains(row[0], "单选") || strings.Contains(row[0], "单项") {
|
|
Questions.SubjectType = "single"
|
|
}
|
|
if strings.Contains(row[0], "多选") || strings.Contains(row[0], "多项") {
|
|
Questions.SubjectType = "mutil"
|
|
}
|
|
if strings.Contains(row[0], "判断") {
|
|
Questions.SubjectType = "judge"
|
|
}
|
|
if strings.Contains(row[0], "应用") || strings.Contains(row[0], "简答") {
|
|
Questions.SubjectType = "application"
|
|
}
|
|
|
|
err = client.MySQL.Table("sys_question_bank").Create(&Questions).Error
|
|
if err != nil {
|
|
fmt.Println("导入题库失败:", err)
|
|
}
|
|
}
|
|
|
|
}
|