commit ci file
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
loser 2022-06-15 11:57:45 +08:00
parent c011fe69c8
commit 05f8043672
4 changed files with 13 additions and 138 deletions

View File

@ -1,17 +1,24 @@
FROM golang:1.18 as builder
# 启用go module
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct
WORKDIR /builder
COPY . .
RUN go mod download && go build -o app && upx -9 app
RUN ls -lh && chmod +x ./app
COPY . .
# 指定OS等并go build
RUN GOOS=linux GOARCH=amd64 go build .
# 运行阶段指定scratch作为基础镜像
FROM alpine
# 指定创建的基础镜像
FROM alpine as runner
# 替换阿里云的源
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories
RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories
WORKDIR /app
COPY --from=builder /builder/app ./app
CMD ./app
CMD ./app
ENTRYPOINT ["./app"]

View File

@ -1,6 +1,5 @@
package main
import "C"
import (
"docDemo/router"
"fmt"

View File

@ -1,69 +0,0 @@
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)
}
}
}

View File

@ -1,62 +0,0 @@
package utils
import (
"docDemo/model"
"errors"
"fmt"
"gitee.ltd/lxh/logger/log"
"github.com/xuri/excelize/v2"
"strings"
)
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"}
type excel struct{}
func ExcelUtils() *excel {
return &excel{}
}
// ParseQuestion 转换Excel为量表问题答案信息
func (e excel) ParseQuestion(ef *excelize.File) (es []model.Question, err error) {
// 获取指定sheet
rows, err := ef.GetRows("question")
if err != nil {
return
}
log.Debugf("读取成功,共%d行%d列数据", len(rows), len(rows[0]))
// 循环行,处理为结构体,不处理第一行,因为是标题
for i, row := range rows[1:] {
// 如果问题出现空行,终止解析
if row[0] == "" {
break
}
// 创建一个问题结构体
var q model.Question
q.QuestionSerial = i + 1
q.Question = row[0]
// 开始解析答案
var answers []model.AnswerEntity
for j, a := range row[1:] {
// 如果答案出现空行,终止解析
if a == "" {
break
}
// 拆开答案,获取答案和分值
if !strings.Contains(a, "|") {
log.Errorf("异常数据: %v", a)
err = errors.New(fmt.Sprintf("模板文件格式错误(%v行%v列),答案和分值必须以|隔开", i+2, j+2))
return
}
answerInfo := strings.Split(a, "|")
answers = append(answers, model.AnswerEntity{
Code: AZ[j],
Answer: answerInfo[0],
Score: StrToInt(answerInfo[1]),
})
}
q.Answers = answers
es = append(es, q)
}
return
}