Преглед на файлове

fix:培训考试题库题目和选项支持上传图片

liuyaqi преди 3 години
родител
ревизия
f07d0dd7b8
променени са 6 файла, в които са добавени 117 реда и са изтрити 72 реда
  1. 39 33
      dao/learning/internal/learning_question.go
  2. 13 11
      model/learning/internal/learning_question.go
  3. 18 13
      model/learning/learning_question.go
  4. 22 11
      service/learning/question.go
  5. 3 1
      sql/create.sql
  6. 22 3
      swaggerui/swagger.yml

+ 39 - 33
dao/learning/internal/learning_question.go

@@ -26,17 +26,19 @@ type LearningQuestionDao struct {
 
 // LearningQuestionColumns defines and stores column names for table learning_question.
 type learningQuestionColumns struct {
-	Id          string // Id
-	SkillId     string // 技能 Id
-	Name        string // 题目名称
-	Type        string // 题型 1 单选 2 多选 3 判断
-	Enable      string // 是否启用
-	Content     string // 题目内容
-	Explanation string // 题目解析
-	OperateBy   string // 操作人
-	CreatedAt   string // 创建时间
-	UpdatedAt   string // 更新时间
-	DeletedAt   string // 删除时间
+	Id               string // Id
+	SkillId          string // 技能 Id
+	Name             string // 题目
+	NameImage        string // 题目图片
+	Type             string // 题型 1 单选 2 多选 3 判断
+	Enable           string // 是否启用
+	Content          string // 题目内容
+	Explanation      string // 题目解析
+	ExplanationImage string // 题目解析图片
+	OperateBy        string // 操作人
+	CreatedAt        string // 创建时间
+	UpdatedAt        string // 更新时间
+	DeletedAt        string // 删除时间
 }
 
 var (
@@ -46,17 +48,19 @@ var (
 		DB:    g.DB("default"),
 		Table: "learning_question",
 		Columns: learningQuestionColumns{
-			Id:          "Id",
-			SkillId:     "SkillId",
-			Name:        "Name",
-			Type:        "Type",
-			Enable:      "Enable",
-			Content:     "Content",
-			Explanation: "Explanation",
-			OperateBy:   "OperateBy",
-			CreatedAt:   "CreatedAt",
-			UpdatedAt:   "UpdatedAt",
-			DeletedAt:   "DeletedAt",
+			Id:               "Id",
+			SkillId:          "SkillId",
+			Name:             "Name",
+			NameImage:        "NameImage",
+			Type:             "Type",
+			Enable:           "Enable",
+			Content:          "Content",
+			Explanation:      "Explanation",
+			ExplanationImage: "ExplanationImage",
+			OperateBy:        "OperateBy",
+			CreatedAt:        "CreatedAt",
+			UpdatedAt:        "UpdatedAt",
+			DeletedAt:        "DeletedAt",
 		},
 	}
 )
@@ -68,17 +72,19 @@ func NewLearningQuestionDao(tenant string) LearningQuestionDao {
 		DB:    g.DB(tenant),
 		Table: "learning_question",
 		Columns: learningQuestionColumns{
-			Id:          "Id",
-			SkillId:     "SkillId",
-			Name:        "Name",
-			Type:        "Type",
-			Enable:      "Enable",
-			Content:     "Content",
-			Explanation: "Explanation",
-			OperateBy:   "OperateBy",
-			CreatedAt:   "CreatedAt",
-			UpdatedAt:   "UpdatedAt",
-			DeletedAt:   "DeletedAt",
+			Id:               "Id",
+			SkillId:          "SkillId",
+			Name:             "Name",
+			NameImage:        "NameImage",
+			Type:             "Type",
+			Enable:           "Enable",
+			Content:          "Content",
+			Explanation:      "Explanation",
+			ExplanationImage: "ExplanationImage",
+			OperateBy:        "OperateBy",
+			CreatedAt:        "CreatedAt",
+			UpdatedAt:        "UpdatedAt",
+			DeletedAt:        "DeletedAt",
 		},
 	}
 	return dao

+ 13 - 11
model/learning/internal/learning_question.go

@@ -10,15 +10,17 @@ import (
 
 // LearningQuestion is the golang structure for table learning_question.
 type LearningQuestion struct {
-	Id          int         `orm:"Id,primary"  json:"id"`          // Id
-	SkillId     int         `orm:"SkillId"     json:"skillId"`     // 技能 Id
-	Name        string      `orm:"Name"        json:"name"`        // 题目名称
-	Type        int         `orm:"Type"        json:"type"`        // 题型 1 单选 2 多选 3 判断
-	Enable      int         `orm:"Enable"      json:"enable"`      // 是否启用
-	Content     string      `orm:"Content"     json:"content"`     // 题目内容
-	Explanation string      `orm:"Explanation" json:"explanation"` // 题目解析
-	OperateBy   string      `orm:"OperateBy"   json:"operateBy"`   // 操作人
-	CreatedAt   *gtime.Time `orm:"CreatedAt"   json:"createdAt"`   // 创建时间
-	UpdatedAt   *gtime.Time `orm:"UpdatedAt"   json:"updatedAt"`   // 更新时间
-	DeletedAt   *gtime.Time `orm:"DeletedAt"   json:"deletedAt"`   // 删除时间
+	Id               int         `orm:"Id,primary"       json:"id"`               // Id
+	SkillId          int         `orm:"SkillId"          json:"skillId"`          // 技能 Id
+	Name             string      `orm:"Name"             json:"name"`             // 题目
+	NameImage        string      `orm:"NameImage"        json:"nameImage"`        // 题目图片
+	Type             int         `orm:"Type"             json:"type"`             // 题型 1 单选 2 多选 3 判断
+	Enable           int         `orm:"Enable"           json:"enable"`           // 是否启用
+	Content          string      `orm:"Content"          json:"content"`          // 题目内容
+	Explanation      string      `orm:"Explanation"      json:"explanation"`      // 题目解析
+	ExplanationImage string      `orm:"ExplanationImage" json:"explanationImage"` // 题目解析图片
+	OperateBy        string      `orm:"OperateBy"        json:"operateBy"`        // 操作人
+	CreatedAt        *gtime.Time `orm:"CreatedAt"        json:"createdAt"`        // 创建时间
+	UpdatedAt        *gtime.Time `orm:"UpdatedAt"        json:"updatedAt"`        // 更新时间
+	DeletedAt        *gtime.Time `orm:"DeletedAt"        json:"deletedAt"`        // 删除时间
 }

+ 18 - 13
model/learning/learning_question.go

@@ -19,6 +19,7 @@ type LearningQuestionGetReq struct {
 
 type LearningQuestionOption struct {
 	Name      string `json:"name"`
+	Image     string `json:"image"`
 	Content   string `json:"content"`
 	IsCorrect bool   `json:"isCorrect"`
 }
@@ -36,22 +37,26 @@ type LearningQuestionListReq struct {
 }
 
 type LearningQuestionAddReq struct {
-	SkillId     int                      `json:"skillId" v:"required#请输入技能Id"`              // 技能 Id
-	Name        string                   `json:"name" v:"required#请输入题目内容"`                 // 题目内容
-	Type        int                      `json:"type" v:"required#请输入题型 in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
-	Enable      int                      `json:"enable"`                                    // 是否启用
-	Content     []LearningQuestionOption `json:"content"  v:"required#请输入题目内容"`             // 题目内容
-	Explanation string                   `json:"explanation"`                               // 题目解析
+	SkillId          int                      `json:"skillId" v:"required#请输入技能Id"`              // 技能 Id
+	Name             string                   `json:"name"`                                      // 题目
+	NameImage        string                   `json:"nameImage"`                                 // 题目图片
+	Type             int                      `json:"type" v:"required#请输入题型 in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
+	Enable           int                      `json:"enable"`                                    // 是否启用
+	Content          []LearningQuestionOption `json:"content"  v:"required#请输入题目内容"`             // 题目内容
+	Explanation      string                   `json:"explanation"`                               // 题目解析
+	ExplanationImage string                   `json:"explanationImage"`                          // 题目解析图片
 }
 
 type LearningQuestionUpdateReq struct {
-	Id          int                      `json:"id" v:"required#请输入题目Id"`    // Id
-	SkillId     int                      `json:"skillId"`                    // 技能 Id
-	Name        string                   `json:"name"`                       // 题目内容
-	Type        *int                     `json:"type" v:"in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
-	Enable      *int                     `json:"enable"`                     // 是否启用  0 未启用 1 启用
-	Content     []LearningQuestionOption `json:"content"`                    // 题目内容
-	Explanation string                   `json:"explanation"`                // 题目解析
+	Id               int                      `json:"id" v:"required#请输入题目Id"`    // Id
+	SkillId          int                      `json:"skillId"`                    // 技能 Id
+	Name             *string                  `json:"name"`                       // 题目
+	NameImage        *string                  `json:"nameImage"`                  // 题目图片
+	Type             *int                     `json:"type" v:"in:1,2,3#请输入正确的题型"` // 题型 1 单选 2 多选 3 判断
+	Enable           *int                     `json:"enable"`                     // 是否启用  0 未启用 1 启用
+	Content          []LearningQuestionOption `json:"content"`                    // 题目内容
+	Explanation      *string                  `json:"explanation"`                // 题目解析
+	ExplanationImage *string                  `json:"explanationImage"`           // 题目解析图片
 }
 
 type LearningQuestionDeleteReq struct {

+ 22 - 11
service/learning/question.go

@@ -113,6 +113,9 @@ func (s LearningQuestionService) Add(ctx context.Context, req *learning.Learning
 	if validErr != nil {
 		return 0, validErr.Current()
 	}
+	if req.Name == "" && req.NameImage == "" {
+		return 0, myerrors.NewMsgError(nil, "请输入题目或题目图片")
+	}
 	if len(req.Content) < 2 {
 		return 0, myerrors.NewMsgError(nil, "至少需要两个选项")
 	}
@@ -134,15 +137,17 @@ func (s LearningQuestionService) Add(ctx context.Context, req *learning.Learning
 		return 0, err
 	}
 	id, err := s.Dao.InsertAndGetId(learning.LearningQuestion{
-		SkillId:     req.SkillId,
-		Name:        req.Name,
-		Type:        req.Type,
-		Enable:      req.Enable,
-		Content:     string(content),
-		Explanation: req.Explanation,
-		OperateBy:   s.userInfo.RealName,
-		CreatedAt:   gtime.Now(),
-		UpdatedAt:   gtime.Now(),
+		SkillId:          req.SkillId,
+		Name:             req.Name,
+		NameImage:        req.NameImage,
+		Type:             req.Type,
+		Enable:           req.Enable,
+		Content:          string(content),
+		Explanation:      req.Explanation,
+		ExplanationImage: req.ExplanationImage,
+		OperateBy:        s.userInfo.RealName,
+		CreatedAt:        gtime.Now(),
+		UpdatedAt:        gtime.Now(),
 	})
 	if err != nil {
 		return 0, err
@@ -200,9 +205,12 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 	if req.SkillId != 0 {
 		toupdate["SkillId"] = req.SkillId
 	}
-	if req.Name != "" {
+	if req.Name != nil {
 		toupdate["Name"] = req.Name
 	}
+	if req.NameImage != nil {
+		toupdate["NameImage"] = req.NameImage
+	}
 	if req.Type != nil {
 		toupdate["Type"] = req.Type
 	}
@@ -216,9 +224,12 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 		}
 		toupdate["Content"] = content
 	}
-	if req.Explanation != "" {
+	if req.Explanation != nil {
 		toupdate["Explanation"] = req.Explanation
 	}
+	if req.ExplanationImage != nil {
+		toupdate["ExplanationImage"] = req.ExplanationImage
+	}
 	if len(toupdate) == 0 {
 		return nil
 	}

+ 3 - 1
sql/create.sql

@@ -68,11 +68,13 @@ CREATE TABLE `learning_material_file` (
 CREATE TABLE `learning_question` (
   `Id` int NOT NULL AUTO_INCREMENT COMMENT 'Id',
   `SkillId` int NOT NULL COMMENT '技能 Id',
-  `Name` varchar(512) NOT NULL COMMENT '题目名称',
+  `Name` varchar(512) NOT NULL COMMENT '题目',
+  `NameImage` varchar(512) NOT NULL COMMENT '题目图片',
   `Type` int NOT NULL COMMENT '题型 1 单选 2 多选 3 判断',
   `Enable` tinyint(1) NOT NULL COMMENT '是否启用',
   `Content` text COMMENT '题目内容',
   `Explanation` text COMMENT '题目解析',
+  `ExplanationImage` text COMMENT '题目解析图片',
   `OperateBy` varchar(255) COMMENT '操作人',
   `CreatedAt` datetime COMMENT '创建时间',
   `UpdatedAt` datetime COMMENT '更新时间',

+ 22 - 3
swaggerui/swagger.yml

@@ -648,7 +648,6 @@ components:
       type: object
       required:
         - skillId
-        - name
         - type
         - content
       properties:
@@ -657,7 +656,10 @@ components:
           description: 技能 Id
         name:
           type: string
-          description: 题目名称
+          description: 题目
+        nameImage:
+          type: string
+          description: 题目图片
         type:
           type: integer
           description: 题型 1 单选 2 多选 3 判断
@@ -682,6 +684,9 @@ components:
         explanation:
           type: string
           description: 题目解析
+        explanationImage:
+          type: string
+          description: 题目解析图片
     LearningQuestionUpdate:
       type: object
       required:
@@ -695,7 +700,10 @@ components:
           description: 技能 Id
         name:
           type: string
-          description: 题目名称
+          description: 题目
+        nameImage:
+          type: string
+          description: 题目图片
         type:
           type: integer
           description: 题型 1 单选 2 多选 3 判断
@@ -720,6 +728,9 @@ components:
         explanation:
           type: string
           description: 题目解析
+        explanationImage:
+          type: string
+          description: 题目解析图片
 
   examples:
     success:
@@ -823,35 +834,43 @@ components:
       value:
         skillId: 2
         name: 测试
+        nameImage: https://go.dev/images/gophers/pilot-bust.svg
         type: 1
         enable: 1
         content:
           -
             name: A
             content: 测试A
+            image: https://go.dev/images/gophers/pilot-bust.svg
             isCorrect: true
           -
             name: B
             content: 测试B
+            image: https://go.dev/images/gophers/pilot-bust.svg
             isCorrect: false
         explanation: 测试
+        explanationImage: https://go.dev/images/gophers/pilot-bust.svg
     LearningQuestionUpdate:
       value:
         id: 1
         skillId: 5
         name: 测试修改
+        nameImage: https://go.dev/images/gophers/pilot-bust.svg
         type: 2
         enable: 1
         content:
           -
             name: A
+            image: https://go.dev/images/gophers/pilot-bust.svg
             content: 测试测试修改A
             isCorrect: true
           -
             name: B
+            image: https://go.dev/images/gophers/pilot-bust.svg
             content: 测试测试修改B
             isCorrect: true
         explanation: 测试测试修改
+        explanationImage: https://go.dev/images/gophers/pilot-bust.svg
     LearningQuestionDelete:
       value:
         id: 1