浏览代码

feature:培训考试试卷管理

liuyaqi 3 年之前
父节点
当前提交
24f805f454

+ 3 - 3
handler/learning/exam_record.go

@@ -15,7 +15,7 @@ import (
 type LearningExamRecord struct{}
 
 func (c *LearningExamRecord) List(ctx context.Context, req *learning.LearningExamRecordListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningExamRecord.List request %v ", &req)
+	g.Log().Infof("LearningExamRecord.List request %#v ", *req)
 	s, err := learningSrv.NewLearningExamRecordService(ctx)
 	if err != nil {
 		return err
@@ -38,7 +38,7 @@ func (c *LearningExamRecord) List(ctx context.Context, req *learning.LearningExa
 }
 
 func (c *LearningExamRecord) ListMy(ctx context.Context, req *learning.LearningExamRecordListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningExamRecord.List request %v ", &req)
+	g.Log().Infof("LearningExamRecord.ListMy request %#v ", *req)
 	s, err := learningSrv.NewLearningExamRecordService(ctx)
 	if err != nil {
 		return err
@@ -67,7 +67,7 @@ func (c *LearningExamRecord) ListMy(ctx context.Context, req *learning.LearningE
 }
 
 func (c *LearningExamRecord) AddToMy(ctx context.Context, req *learning.LearningExamRecordAddReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningExamRecord.AddToMy request %v ", &req)
+	g.Log().Infof("LearningExamRecord.AddToMy request %#v ", *req)
 	s, err := learningSrv.NewLearningExamRecordService(ctx)
 	if err != nil {
 		return err

+ 3 - 3
handler/learning/learning_record.go

@@ -15,7 +15,7 @@ import (
 type LearningLearningRecord struct{}
 
 func (c *LearningLearningRecord) List(ctx context.Context, req *learning.LearningLearningRecordListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningLearningRecord.List request %v ", &req)
+	g.Log().Infof("LearningLearningRecord.List request %#v ", *req)
 	s, err := learningSrv.NewLearningLearningRecordService(ctx)
 	if err != nil {
 		return err
@@ -38,7 +38,7 @@ func (c *LearningLearningRecord) List(ctx context.Context, req *learning.Learnin
 }
 
 func (c *LearningLearningRecord) ListMy(ctx context.Context, req *learning.LearningLearningRecordListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningLearningRecord.List request %v ", &req)
+	g.Log().Infof("LearningLearningRecord.ListMy request %#v ", *req)
 	s, err := learningSrv.NewLearningLearningRecordService(ctx)
 	if err != nil {
 		return err
@@ -67,7 +67,7 @@ func (c *LearningLearningRecord) ListMy(ctx context.Context, req *learning.Learn
 }
 
 func (c *LearningLearningRecord) AddToMy(ctx context.Context, req *learning.LearningLearningRecordAddReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningLearningRecord.AddToMy request %v ", &req)
+	g.Log().Infof("LearningLearningRecord.AddToMy request %#v ", *req)
 	s, err := learningSrv.NewLearningLearningRecordService(ctx)
 	if err != nil {
 		return err

+ 5 - 5
handler/learning/material.go

@@ -13,7 +13,7 @@ import (
 type LearningMaterial struct{}
 
 func (c *LearningMaterial) List(ctx context.Context, req *learning.LearningMaterialListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningMaterial.List request %v ", &req)
+	g.Log().Infof("LearningMaterial.List request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)
 	if err != nil {
 		return err
@@ -36,7 +36,7 @@ func (c *LearningMaterial) List(ctx context.Context, req *learning.LearningMater
 }
 
 func (c *LearningMaterial) Get(ctx context.Context, req *learning.LearningMaterialGetReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningMaterial.Get request %v ", &req)
+	g.Log().Infof("LearningMaterial.Get request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)
 	if err != nil {
 		return err
@@ -53,7 +53,7 @@ func (c *LearningMaterial) Get(ctx context.Context, req *learning.LearningMateri
 }
 
 func (c *LearningMaterial) Add(ctx context.Context, req *learning.LearningMaterialAddReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	g.Log().Infof("LearningMaterial.Add request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)
 	if err != nil {
 		return err
@@ -70,7 +70,7 @@ func (c *LearningMaterial) Add(ctx context.Context, req *learning.LearningMateri
 }
 
 func (c *LearningMaterial) Update(ctx context.Context, req *learning.LearningMaterialUpdateReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	g.Log().Infof("LearningMaterial.Update request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)
 	if err != nil {
 		return err
@@ -86,7 +86,7 @@ func (c *LearningMaterial) Update(ctx context.Context, req *learning.LearningMat
 }
 
 func (c *LearningMaterial) Delete(ctx context.Context, req *learning.LearningMaterialDeleteReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningMaterial.Add request %v ", &req)
+	g.Log().Infof("LearningMaterial.Delete request %#v ", *req)
 	s, err := learningSrv.NewLearningMaterialService(ctx)
 	if err != nil {
 		return err

+ 5 - 5
handler/learning/question.go

@@ -13,7 +13,7 @@ import (
 type LearningQuestion struct{}
 
 func (c *LearningQuestion) List(ctx context.Context, req *learning.LearningQuestionListReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningQuestion.List request %v ", &req)
+	g.Log().Infof("LearningQuestion.List request %#v ", *req)
 	s, err := learningSrv.NewLearningQuestionService(ctx)
 	if err != nil {
 		return err
@@ -36,7 +36,7 @@ func (c *LearningQuestion) List(ctx context.Context, req *learning.LearningQuest
 }
 
 func (c *LearningQuestion) Get(ctx context.Context, req *learning.LearningQuestionGetReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningQuestion.Get request %v ", &req)
+	g.Log().Infof("LearningQuestion.Get request %#v ", *req)
 	s, err := learningSrv.NewLearningQuestionService(ctx)
 	if err != nil {
 		return err
@@ -53,7 +53,7 @@ func (c *LearningQuestion) Get(ctx context.Context, req *learning.LearningQuesti
 }
 
 func (c *LearningQuestion) Add(ctx context.Context, req *learning.LearningQuestionAddReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningQuestion.Add request %v ", &req)
+	g.Log().Infof("LearningQuestion.Add request %#v ", *req)
 	s, err := learningSrv.NewLearningQuestionService(ctx)
 	if err != nil {
 		return err
@@ -70,7 +70,7 @@ func (c *LearningQuestion) Add(ctx context.Context, req *learning.LearningQuesti
 }
 
 func (c *LearningQuestion) Update(ctx context.Context, req *learning.LearningQuestionUpdateReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningQuestion.Add request %v ", &req)
+	g.Log().Infof("LearningQuestion.Update request %#v ", *req)
 	s, err := learningSrv.NewLearningQuestionService(ctx)
 	if err != nil {
 		return err
@@ -86,7 +86,7 @@ func (c *LearningQuestion) Update(ctx context.Context, req *learning.LearningQue
 }
 
 func (c *LearningQuestion) Delete(ctx context.Context, req *learning.LearningQuestionDeleteReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningQuestion.Add request %v ", &req)
+	g.Log().Infof("LearningQuestion.Delete request %#v ", *req)
 	s, err := learningSrv.NewLearningQuestionService(ctx)
 	if err != nil {
 		return err

+ 5 - 5
handler/learning/skill.go

@@ -14,7 +14,7 @@ import (
 type LearningSkill struct{}
 
 func (c *LearningSkill) List(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningSkill.List request %v ", &req)
+	g.Log().Infof("LearningSkill.List request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)
 	if err != nil {
 		return err
@@ -34,7 +34,7 @@ func (c *LearningSkill) List(ctx context.Context, req *model.EmptyArgs, rsp *com
 }
 
 func (c *LearningSkill) Get(ctx context.Context, req *learning.LearningSkillGetReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningSkill.Get request %v ", &req)
+	g.Log().Infof("LearningSkill.Get request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)
 	if err != nil {
 		return err
@@ -51,7 +51,7 @@ func (c *LearningSkill) Get(ctx context.Context, req *learning.LearningSkillGetR
 }
 
 func (c *LearningSkill) Add(ctx context.Context, req *learning.LearningSkillAddReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	g.Log().Infof("LearningSkill.Add request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)
 	if err != nil {
 		return err
@@ -68,7 +68,7 @@ func (c *LearningSkill) Add(ctx context.Context, req *learning.LearningSkillAddR
 }
 
 func (c *LearningSkill) Update(ctx context.Context, req *learning.LearningSkillUpdateReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	g.Log().Infof("LearningSkill.Update request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)
 	if err != nil {
 		return err
@@ -84,7 +84,7 @@ func (c *LearningSkill) Update(ctx context.Context, req *learning.LearningSkillU
 }
 
 func (c *LearningSkill) Delete(ctx context.Context, req *learning.LearningSkillDeleteReq, rsp *comm_def.CommonMsg) error {
-	g.Log().Infof("LearningSkill.Add request %v ", &req)
+	g.Log().Infof("LearningSkill.Delete request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)
 	if err != nil {
 		return err

+ 102 - 0
handler/learning/testpaper.go

@@ -0,0 +1,102 @@
+package learning
+
+import (
+	"context"
+	"lims_adapter/model/learning"
+	learningSrv "lims_adapter/service/learning"
+
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/micro_libary/myerrors"
+	"github.com/gogf/gf/frame/g"
+)
+
+type LearningTestpaper struct{}
+
+func (c *LearningTestpaper) List(ctx context.Context, req *learning.LearningTestpaperListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.List request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.List(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*learning.LearningTestpaper{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+func (c *LearningTestpaper) Get(ctx context.Context, req *learning.LearningTestpaperGetReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.Get request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	ent, err := s.Get(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = ent
+	return nil
+}
+
+func (c *LearningTestpaper) Add(ctx context.Context, req *learning.LearningTestpaperAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.Add request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	id, err := s.Add(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = id
+	return nil
+}
+
+func (c *LearningTestpaper) Update(ctx context.Context, req *learning.LearningTestpaperUpdateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.Update request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Update(ctx, req)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
+func (c *LearningTestpaper) Delete(ctx context.Context, req *learning.LearningTestpaperDeleteReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.Delete request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Delete(ctx, req.Id)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}

+ 5 - 0
main.go

@@ -10,6 +10,7 @@ import (
 	"github.com/golang/glog"
 
 	_ "lims_adapter/boot"
+	_ "lims_adapter/valid"
 
 	"dashoo.cn/micro_libary/micro_srv"
 	"github.com/gogf/gf/frame/g"
@@ -64,6 +65,10 @@ func main() {
 		new((learning.LearningQuestion)), "")
 	s.RegisterName("LearningExamRecord",
 		new((learning.LearningExamRecord)), "")
+	s.RegisterName("LearningLearningRecord",
+		new((learning.LearningLearningRecord)), "")
+	s.RegisterName("LearningTestpaper",
+		new((learning.LearningTestpaper)), "")
 
 	// 注册auth处理
 	s.AuthFunc = handleAuth

+ 4 - 4
model/learning/learning_exam_record.go

@@ -29,8 +29,8 @@ type LearningExamRecordGetRsp struct {
 }
 
 type LearningExamRecordAddReq struct {
-	UserId      int `json:"userId" v:"required#请输入用户Id"`                 // 用户 Id
-	SkillId     int `json:"skillId" v:"required#请输入技能Id"`                // 技能 Id
-	TestpaperId int `json:"testpaperId" v:"required#请输入试卷Id"`            // 试卷 Id
-	Status      int `json:"status" v:"required#请输入状态 in:1,2#请输入正确的状态类型"` // 状态 1 通过 2 未通过
+	UserId      int `json:"userId" v:"required#请输入用户Id"`                     // 用户 Id
+	SkillId     int `json:"skillId" v:"required#请输入技能Id"`                    // 技能 Id
+	TestpaperId int `json:"testpaperId" v:"required#请输入试卷Id"`                // 试卷 Id
+	Status      int `json:"status" v:"required|int-in:1,2#请输入状态|请输入正确的状态类型"` // 状态 1 通过 2 未通过
 }

+ 3 - 3
model/learning/learning_learning_record.go

@@ -29,7 +29,7 @@ type LearningLearningRecordGetRsp struct {
 }
 
 type LearningLearningRecordAddReq struct {
-	UserId     int `json:"userId" v:"required#请输入用户Id"`               // 用户 Id
-	MaterialId int `json:"materialId" v:"required#请输入资料Id"`           // 资料 Id
-	Status     int `json:"status" v:"required#请输入状态 in:1#请输入正确的状态类型"` // 状态 1 已学习
+	UserId     int `json:"userId" v:"required#请输入用户Id"`                   // 用户 Id
+	MaterialId int `json:"materialId" v:"required#请输入资料Id"`               // 资料 Id
+	Status     int `json:"status" v:"required|int-in:1#请输入正确的状态类型|请输入状态"` // 状态 1 已学习
 }

+ 16 - 16
model/learning/learning_material.go

@@ -39,26 +39,26 @@ type LearningMaterialAddReqFile struct {
 }
 
 type LearningMaterialAddReq struct {
-	SkillId int                           `json:"skillId" v:"required#请输入技能Id"`                // 技能 Id
-	Name    string                        `json:"name" v:"required#请输入资料名称"`                   // 资料名称
-	Type    int                           `json:"type" v:"required#请输入资料类型 in:1,2#请输入正确的资料类型"` // 资料类型 1 资料 2 视频
-	SortNo  int                           `json:"sortNo"`                                      // 排序
-	Enable  int                           `json:"enable" v:"in:0,1#请输入正确的启用类型"`                // 是否启用
-	Content string                        `json:"content"`                                     // 资料内容
-	File    []*LearningMaterialAddReqFile `json:"file"`                                        // 附件
+	SkillId int                           `json:"skillId" v:"required#请输入技能Id"`                    // 技能 Id
+	Name    string                        `json:"name" v:"required#请输入资料名称"`                       // 资料名称
+	Type    int                           `json:"type" v:"required|int-in:1,2#请输入资料类型|请输入正确的资料类型"` // 资料类型 1 资料 2 视频
+	SortNo  int                           `json:"sortNo"`                                          // 排序
+	Enable  int                           `json:"enable" v:"int-in:0,1#请输入正确的启用类型"`                // 是否启用
+	Content string                        `json:"content"`                                         // 资料内容
+	File    []*LearningMaterialAddReqFile `json:"file"`                                            // 附件
 }
 
 type LearningMaterialUpdateReq 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#请输入正确的资料类型"`   // 资料类型 1 资料 2 视频
-	SortNo  *int                          `json:"sortNo"`                       // 排序
-	Enable  *int                          `json:"enable" v:"in:0,1#请输入正确的启用类型"` // 是否启用
-	Content string                        `json:"content"`                      // 资料内容
-	File    []*LearningMaterialAddReqFile `json:"file"`                         // 附件
+	Id      int                           `json:"id" v:"required#请输入资料Id"`          // Id
+	SkillId int                           `json:"skillId"`                          // 技能 Id
+	Name    string                        `json:"name"`                             // 资料名称
+	Type    *int                          `json:"type" v:"int-in:1,2#请输入正确的资料类型"`   // 资料类型 1 资料 2 视频
+	SortNo  *int                          `json:"sortNo"`                           // 排序
+	Enable  *int                          `json:"enable" v:"int-in:0,1#请输入正确的启用类型"` // 是否启用
+	Content string                        `json:"content"`                          // 资料内容
+	File    []*LearningMaterialAddReqFile `json:"file"`                             // 附件
 }
 
 type LearningMaterialDeleteReq struct {
-	Id int `json:"id" v:"required#请输入资料Id"`
+	Id []int `json:"id" v:"required#请输入资料Id"`
 }

+ 18 - 18
model/learning/learning_question.go

@@ -37,28 +37,28 @@ type LearningQuestionListReq struct {
 }
 
 type LearningQuestionAddReq struct {
-	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"`                          // 题目解析图片
+	SkillId          int                      `json:"skillId" v:"required#请输入技能Id"`                  // 技能 Id
+	Name             string                   `json:"name"`                                          // 题目
+	NameImage        string                   `json:"nameImage"`                                     // 题目图片
+	Type             int                      `json:"type" v:"required|int-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"`                       // 题目
-	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"`           // 题目解析图片
+	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:"int-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 {
-	Id int `json:"id" v:"required#请输入题目Id"`
+	Id []int `json:"id" v:"required#请输入题目Id"`
 }

+ 1 - 1
model/learning/learning_skill.go

@@ -36,5 +36,5 @@ type LearningSkillUpdateReq struct {
 }
 
 type LearningSkillDeleteReq struct {
-	Id int `json:"id" v:"required#请输入技能Id"` // 技能名称
+	Id []int `json:"id" v:"required#请输入技能Id"` // 技能名称
 }

+ 39 - 0
model/learning/learning_testpaper.go

@@ -5,6 +5,7 @@
 package learning
 
 import (
+	"lims_adapter/model"
 	"lims_adapter/model/learning/internal"
 )
 
@@ -12,3 +13,41 @@ import (
 type LearningTestpaper internal.LearningTestpaper
 
 // Fill with you ideas below.
+type LearningTestpaperListReq struct {
+	Page    *model.Page    `json:"page"`
+	OrderBy *model.OrderBy `json:"orderBy"`
+	SkillId int            `json:"skillId"`
+	Enable  *int           `json:"enable"` // 是否启用  0 未启用 1 启用
+}
+
+type LearningTestpaperGetReq struct {
+	Id int `json:"id" v:"required#请输入试卷Id"` // 试卷Id
+}
+
+type LearningTestpaperGetRsp struct {
+	LearningTestpaper
+	Question   []int                       `json:"question"`   // 包含的试题
+	ExamRecord []*LearningExamRecordGetRsp `json:"examRecord"` // 考试记录
+}
+
+type LearningTestpaperAddReq struct {
+	SkillId   int    `json:"skillId" v:"required#请输入技能名称"`   // 技能 Id
+	Name      string `json:"name" v:"required#请输入试卷名称"`      // 试卷名称
+	TimeLimit int    `json:"timeLimit" v:"required#请输入答题时间"` // 答题时间/分钟
+	PassLimit int    `json:"passLimit"`                      // 合格标准/题数
+	Question  []int  `json:"question" v:"required#请输入问题列表"`  // 问题
+}
+
+type LearningTestpaperUpdateReq struct {
+	Id        int    `json:"id" v:"required#请输入试卷Id"` // 试卷Id
+	SkillId   int    `json:"skillId"`                 // 技能 Id
+	Name      string `json:"name"`                    // 试卷名称
+	Enable    *int   `json:"enable"`                  // 是否启用  0 未启用 1 启用
+	TimeLimit int    `json:"timeLimit"`               // 答题时间/分钟
+	PassLimit int    `json:"passLimit"`               // 合格标准/题数
+	Question  []int  `json:"question"`                // 问题
+}
+
+type LearningTestpaperDeleteReq struct {
+	Id []int `json:"id" v:"required#请输入试卷Id"`
+}

+ 20 - 26
service/learning/exam_record.go

@@ -41,7 +41,7 @@ func (s LearningExamRecordService) List(ctx context.Context, req *learning.Learn
 	m := s.Dao.DB.
 		Table("learning_exam_record a").
 		LeftJoin("learning_skill b", "a.SkillId=b.Id").
-		LeftJoin("base_user c", "a.SkillId=b.Id")
+		LeftJoin("base_user c", "a.UserId=c.Id")
 	if req.UserId != 0 {
 		m = m.Where("a.UserId = ?", req.UserId)
 	}
@@ -88,34 +88,28 @@ func (s LearningExamRecordService) List(ctx context.Context, req *learning.Learn
 func (s LearningExamRecordService) Add(ctx context.Context, req *learning.LearningExamRecordAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return 0, validErr.Current()
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
-	if req.UserId != 0 {
-		r, err := s.Dao.DB.Table("base_user").Where("Id = ?", req.UserId).One()
-		if err != nil {
-			return 0, err
-		}
-		if r.IsEmpty() {
-			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("用户不存在: %d", req.UserId))
-		}
+	r, err := s.Dao.DB.Table("base_user").Where("Id = ?", req.UserId).One()
+	if err != nil {
+		return 0, err
 	}
-	if req.SkillId != 0 {
-		r, err := s.Dao.DB.Table("learning_skill").Where("Id = ?", req.SkillId).One()
-		if err != nil {
-			return 0, err
-		}
-		if r.IsEmpty() {
-			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
-		}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("用户不存在: %d", req.UserId))
 	}
-	if req.TestpaperId != 0 {
-		r, err := s.Dao.DB.Table("learning_testpaper").Where("Id = ?", req.TestpaperId).One()
-		if err != nil {
-			return 0, err
-		}
-		if r.IsEmpty() {
-			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("试卷不存在: %d", req.TestpaperId))
-		}
+	r, err = s.Dao.DB.Table("learning_skill").Where("Id = ?", req.SkillId).One()
+	if err != nil {
+		return 0, err
+	}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
+	}
+	r, err = s.Dao.DB.Table("learning_testpaper").Where("Id = ?", req.TestpaperId).One()
+	if err != nil {
+		return 0, err
+	}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("试卷不存在: %d", req.TestpaperId))
 	}
 
 	id, err := s.Dao.InsertAndGetId(learning.LearningExamRecord{

+ 14 - 17
service/learning/learning_record.go

@@ -90,25 +90,22 @@ func (s LearningLearningRecordService) List(ctx context.Context, req *learning.L
 func (s LearningLearningRecordService) Add(ctx context.Context, req *learning.LearningLearningRecordAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return 0, validErr.Current()
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
-	if req.UserId != 0 {
-		r, err := s.Dao.DB.Table("base_user").Where("Id = ?", req.UserId).One()
-		if err != nil {
-			return 0, err
-		}
-		if r.IsEmpty() {
-			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("用户不存在: %d", req.UserId))
-		}
+
+	r, err := s.Dao.DB.Table("base_user").Where("Id = ?", req.UserId).One()
+	if err != nil {
+		return 0, err
 	}
-	if req.MaterialId != 0 {
-		r, err := s.Dao.DB.Table("learning_material").Where("Id = ?", req.MaterialId).One()
-		if err != nil {
-			return 0, err
-		}
-		if r.IsEmpty() {
-			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("资料不存在: %d", req.MaterialId))
-		}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("用户不存在: %d", req.UserId))
+	}
+	r, err = s.Dao.DB.Table("learning_material").Where("Id = ?", req.MaterialId).One()
+	if err != nil {
+		return 0, err
+	}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("资料不存在: %d", req.MaterialId))
 	}
 
 	id, err := s.Dao.InsertAndGetId(learning.LearningLearningRecord{

+ 19 - 13
service/learning/material.go

@@ -107,7 +107,14 @@ func (s LearningMaterialService) List(ctx context.Context, req *learning.Learnin
 func (s LearningMaterialService) Add(ctx context.Context, req *learning.LearningMaterialAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return 0, validErr.Current()
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
+	}
+	r, err := s.Dao.DB.Table("learning_skill").Where("Id", req.SkillId).One()
+	if err != nil {
+		return 0, err
+	}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
 	}
 
 	m, err := s.Dao.Where("Name = ?", req.Name).One()
@@ -156,7 +163,7 @@ func (s LearningMaterialService) Add(ctx context.Context, req *learning.Learning
 func (s LearningMaterialService) Update(ctx context.Context, req *learning.LearningMaterialUpdateReq) error {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return validErr.Current()
+		return myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 
 	m, err := s.Dao.Where("Id = ?", req.Id).One()
@@ -207,18 +214,17 @@ func (s LearningMaterialService) Update(ctx context.Context, req *learning.Learn
 	if req.Content != "" {
 		toupdate["Content"] = req.Content
 	}
-	if len(toupdate) == 0 {
-		return nil
-	}
-	toupdate["OperateBy"] = s.userInfo.RealName
-	_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
-	if err != nil {
-		return err
+	if len(toupdate) != 0 {
+		toupdate["OperateBy"] = s.userInfo.RealName
+		_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
+		if err != nil {
+			return err
+		}
 	}
+
 	if req.File == nil {
 		return nil
 	}
-
 	_, err = s.FileDao.Where("MaterialId = ?", req.Id).Delete()
 	if err != nil {
 		return err
@@ -244,11 +250,11 @@ func (s LearningMaterialService) Update(ctx context.Context, req *learning.Learn
 	return err
 }
 
-func (s LearningMaterialService) Delete(ctx context.Context, id int) error {
-	_, err := s.Dao.Where("Id = ?", id).Delete()
+func (s LearningMaterialService) Delete(ctx context.Context, id []int) error {
+	_, err := s.Dao.Where("Id IN (?)", id).Delete()
 	if err != nil {
 		return err
 	}
-	_, err = s.FileDao.Where("MaterialId = ?", id).Delete()
+	_, err = s.FileDao.Where("MaterialId IN (?)", id).Delete()
 	return err
 }

+ 5 - 5
service/learning/question.go

@@ -40,7 +40,7 @@ func NewLearningQuestionService(ctx context.Context) (*LearningQuestionService,
 func (s LearningQuestionService) Get(ctx context.Context, req *learning.LearningQuestionGetReq) (ent *learning.LearningQuestionGetRsp, err error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return nil, validErr.Current()
+		return nil, myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 
 	q, err := s.Dao.Where("Id = ?", req.Id).One()
@@ -111,7 +111,7 @@ func (s LearningQuestionService) List(ctx context.Context, req *learning.Learnin
 func (s LearningQuestionService) Add(ctx context.Context, req *learning.LearningQuestionAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return 0, validErr.Current()
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 	if req.Name == "" && req.NameImage == "" {
 		return 0, myerrors.NewMsgError(nil, "请输入题目或题目图片")
@@ -158,7 +158,7 @@ func (s LearningQuestionService) Add(ctx context.Context, req *learning.Learning
 func (s LearningQuestionService) Update(ctx context.Context, req *learning.LearningQuestionUpdateReq) error {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return validErr.Current()
+		return myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 	if len(req.Content) != 0 {
 		if req.Type == nil {
@@ -238,7 +238,7 @@ func (s LearningQuestionService) Update(ctx context.Context, req *learning.Learn
 	return err
 }
 
-func (s LearningQuestionService) Delete(ctx context.Context, id int) error {
-	_, err := s.Dao.Where("Id = ?", id).Delete()
+func (s LearningQuestionService) Delete(ctx context.Context, id []int) error {
+	_, err := s.Dao.Where("Id IN (?)", id).Delete()
 	return err
 }

+ 5 - 5
service/learning/skill.go

@@ -83,7 +83,7 @@ func (s LearningSkillService) List(ctx context.Context) ([]*learning.LearningSki
 func (s LearningSkillService) Add(ctx context.Context, req *learning.LearningSkillAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return 0, validErr.Current()
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 
 	skill, err := s.LearningSkillDao.Where("Name = ?", req.Name).One()
@@ -125,7 +125,7 @@ func (s LearningSkillService) Update(ctx context.Context, req *learning.Learning
 
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {
-		return validErr.Current()
+		return myerrors.NewMsgError(nil, validErr.Current().Error())
 	}
 
 	skill, err := s.LearningSkillDao.Where("Id = ?", req.Id).One()
@@ -182,11 +182,11 @@ func (s LearningSkillService) Update(ctx context.Context, req *learning.Learning
 	return nil
 }
 
-func (s LearningSkillService) Delete(ctx context.Context, id int) error {
-	_, err := s.LearningSkillInstrumentDao.Where("SkillId = ?", id).Delete()
+func (s LearningSkillService) Delete(ctx context.Context, id []int) error {
+	_, err := s.LearningSkillInstrumentDao.Where("SkillId  IN (?)", id).Delete()
 	if err != nil {
 		return err
 	}
-	_, err = s.LearningSkillDao.Where("Id = ?", id).Delete()
+	_, err = s.LearningSkillDao.Where("Id IN (?)", id).Delete()
 	return err
 }

+ 265 - 0
service/learning/testpaper.go

@@ -0,0 +1,265 @@
+package learning
+
+import (
+	"context"
+	"fmt"
+	"lims_adapter/dao/learning"
+	"lims_adapter/model/learning"
+
+	"dashoo.cn/micro_libary/micro_srv"
+	"dashoo.cn/micro_libary/myerrors"
+	"dashoo.cn/micro_libary/request"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type LearningTestpaperService struct {
+	Dao                  *dao.LearningTestpaperDao
+	QuestionDao          *dao.LearningQuestionDao
+	QuestionTestpaperDao *dao.LearningQuestionTestpaperDao
+	ExamRecordService    *LearningExamRecordService
+	Tenant               string
+	userInfo             request.UserInfo
+}
+
+func NewLearningTestpaperService(ctx context.Context) (*LearningTestpaperService, error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取组合码异常:%s", err.Error())
+	}
+	// 获取用户信息
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+	examRecordService, err := NewLearningExamRecordService(ctx)
+	if err != nil {
+		return nil, err
+	}
+	return &LearningTestpaperService{
+		Dao:                  dao.NewLearningTestpaperDao(tenant),
+		QuestionDao:          dao.NewLearningQuestionDao(tenant),
+		QuestionTestpaperDao: dao.NewLearningQuestionTestpaperDao(tenant),
+		ExamRecordService:    examRecordService,
+		Tenant:               tenant,
+		userInfo:             userInfo,
+	}, nil
+}
+
+func (s LearningTestpaperService) Get(ctx context.Context, req *learning.LearningTestpaperGetReq) (*learning.LearningTestpaperGetRsp, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return nil, myerrors.NewMsgError(nil, validErr.Current().Error())
+	}
+
+	tp, err := s.Dao.Where("Id = ?", req.Id).One()
+	if err != nil {
+		return nil, err
+	}
+	if tp == nil {
+		return nil, myerrors.NewMsgError(nil, "试卷不存在")
+	}
+	_, record, err := s.ExamRecordService.List(ctx,
+		&learning.LearningExamRecordListReq{
+			TestpaperId: tp.Id,
+		})
+	if err != nil {
+		return nil, err
+	}
+	bind, err := s.QuestionTestpaperDao.Where("TestpaperId", req.Id).All()
+	if err != nil {
+		return nil, err
+	}
+	question := []int{}
+	for _, b := range bind {
+		question = append(question, b.QuestionId)
+	}
+
+	return &learning.LearningTestpaperGetRsp{
+		LearningTestpaper: *tp,
+		ExamRecord:        record,
+		Question:          question,
+	}, nil
+}
+
+func (s LearningTestpaperService) List(ctx context.Context, req *learning.LearningTestpaperListReq) (int, []*learning.LearningTestpaper, error) {
+	dao := &s.Dao.LearningTestpaperDao
+	if req.SkillId != 0 {
+		dao = dao.Where("SkillId = ?", req.SkillId)
+	}
+	if req.Enable != nil {
+		dao = dao.Where("Enable = ?", req.Enable)
+	}
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+
+	if req.Page != nil {
+		if req.Page.Current == 0 {
+			req.Page.Current = 1
+		}
+		if req.Page.Size == 0 {
+			req.Page.Size = 10
+		}
+		dao = dao.Page(req.Page.Current, req.Page.Size)
+	}
+
+	if req.OrderBy != nil && req.OrderBy.Value != "" {
+		order := "asc"
+		if req.OrderBy.Type == "desc" {
+			order = "desc"
+		}
+		dao = dao.Order(req.OrderBy.Value, order)
+	}
+	ent, err := dao.All()
+	return total, ent, err
+}
+
+func (s LearningTestpaperService) Add(ctx context.Context, req *learning.LearningTestpaperAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, myerrors.NewMsgError(nil, validErr.Current().Error())
+	}
+	if req.PassLimit > len(req.Question) {
+		return 0, myerrors.NewMsgError(nil, "合格标准大于题目总数量")
+	}
+	r, err := s.Dao.DB.Table("learning_skill").Where("Id = ?", req.SkillId).One()
+	if err != nil {
+		return 0, err
+	}
+	if r.IsEmpty() {
+		return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
+	}
+	for _, qid := range req.Question {
+		q, err := s.QuestionDao.Where("Id = ?", qid).One()
+		if err != nil {
+			return 0, err
+		}
+		if q == nil {
+			return 0, myerrors.NewMsgError(nil, fmt.Sprintf("题目不存在 %d", qid))
+		}
+	}
+
+	id, err := s.Dao.InsertAndGetId(learning.LearningTestpaper{
+		SkillId:   req.SkillId,
+		Name:      req.Name,
+		Enable:    0,
+		TimeLimit: req.TimeLimit,
+		PassLimit: req.PassLimit,
+		CreatedAt: gtime.Now(),
+		UpdatedAt: gtime.Now(),
+	})
+	if err != nil {
+		return 0, err
+	}
+	if len(req.Question) == 0 {
+		return int(id), err
+	}
+
+	bind := []learning.LearningQuestionTestpaper{}
+	for _, qid := range req.Question {
+		bind = append(bind, learning.LearningQuestionTestpaper{
+			QuestionId:  qid,
+			TestpaperId: int(id),
+		})
+	}
+	_, err = s.QuestionTestpaperDao.Insert(bind)
+	return int(id), err
+}
+
+func (s LearningTestpaperService) Update(ctx context.Context, req *learning.LearningTestpaperUpdateReq) error {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.NewMsgError(nil, validErr.Current().Error())
+	}
+	if req.PassLimit > len(req.Question) {
+		return myerrors.NewMsgError(nil, "合格标准大于题目总数量")
+	}
+
+	tp, err := s.Dao.Where("Id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if tp == nil {
+		return myerrors.NewMsgError(nil, fmt.Sprintf("资料不存在: %d", req.Id))
+	}
+
+	if req.SkillId != 0 {
+		r, err := s.Dao.DB.Table("learning_skill").Where("Id", req.SkillId).One()
+		if err != nil {
+			return err
+		}
+		if r.IsEmpty() {
+			return myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
+		}
+	}
+
+	dao := &s.Dao.LearningTestpaperDao
+	toupdate := map[string]interface{}{}
+	if req.SkillId != 0 {
+		toupdate["SkillId"] = req.SkillId
+	}
+	if req.Name != "" {
+		toupdate["Name"] = req.Name
+	}
+	if req.Enable != nil {
+		toupdate["Enable"] = req.Enable
+		// 禁用已启用的试卷
+		if *req.Enable == 1 {
+			_, err = dao.Where("SkillId", tp.SkillId).Data("Enable", 0).Update()
+			if err != nil {
+				return err
+			}
+		}
+	}
+	if req.TimeLimit != 0 {
+		toupdate["TimeLimit"] = req.TimeLimit
+	}
+	if req.PassLimit != 0 {
+		toupdate["PassLimit"] = req.PassLimit
+	}
+	if len(toupdate) != 0 {
+		_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
+		if err != nil {
+			return err
+		}
+	}
+
+	if req.Question == nil {
+		return nil
+	}
+	_, err = s.QuestionTestpaperDao.Where("TestpaperId = ?", req.Id).Delete()
+	if err != nil {
+		return err
+	}
+	if len(req.Question) == 0 {
+		return nil
+	}
+
+	bind := []learning.LearningQuestionTestpaper{}
+	for _, qid := range req.Question {
+		q, err := s.QuestionDao.Where("Id = ?", qid).One()
+		if err != nil {
+			return err
+		}
+		if q == nil {
+			return myerrors.NewMsgError(nil, fmt.Sprintf("题目不存在 %d", qid))
+		}
+		bind = append(bind, learning.LearningQuestionTestpaper{
+			QuestionId:  qid,
+			TestpaperId: tp.Id,
+		})
+	}
+	_, err = s.QuestionTestpaperDao.Insert(bind)
+	return err
+}
+
+func (s LearningTestpaperService) Delete(ctx context.Context, id []int) error {
+	_, err := s.Dao.Where("Id IN (?)", id).Delete()
+	if err != nil {
+		return err
+	}
+	_, err = s.QuestionTestpaperDao.Where("TestpaperId IN (?)", id).Delete()
+	return err
+}

+ 254 - 6
swaggerui/swagger.yml

@@ -142,7 +142,7 @@ paths:
             application/json:
               schema:
                 oneOf:
-                  - $ref: '#/components/schemas/IdReq'
+                  - $ref: '#/components/schemas/IdsReq'
               examples:
                 LearningSkillDelete:
                   $ref: '#/components/examples/LearningSkillDelete'
@@ -267,7 +267,7 @@ paths:
             application/json:
               schema:
                 oneOf:
-                  - $ref: '#/components/schemas/IdReq'
+                  - $ref: '#/components/schemas/IdsReq'
               examples:
                 LearningMaterialDelete:
                   $ref: '#/components/examples/LearningMaterialDelete'
@@ -392,7 +392,7 @@ paths:
             application/json:
               schema:
                 oneOf:
-                  - $ref: '#/components/schemas/IdReq'
+                  - $ref: '#/components/schemas/IdsReq'
               examples:
                 LearningQuestionDelete:
                   $ref: '#/components/examples/LearningQuestionDelete'
@@ -555,6 +555,131 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningTestpaper.Get:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperGet
+        summary: 试卷详情
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/IdReq'
+              examples:
+                LearningTestpaperGet:
+                  $ref: '#/components/examples/LearningTestpaperGet'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningTestpaper.List:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperList
+        summary: 查询试卷
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningTestpaperList'
+              examples:
+                LearningTestpaperList:
+                  $ref: '#/components/examples/LearningTestpaperList'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningTestpaper.Add:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperAdd
+        summary: 添加试卷
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningTestpaperAdd'
+              examples:
+                LearningTestpaperAdd:
+                  $ref: '#/components/examples/LearningTestpaperAdd'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningTestpaper.Update:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperUpdate
+        summary: 更新试卷
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/LearningTestpaperUpdate'
+              examples:
+                LearningTestpaperUpdate:
+                  $ref: '#/components/examples/LearningTestpaperUpdate'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
+    /LearningTestpaper.Delete:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperDelete
+        summary: 删除试卷
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/IdsReq'
+              examples:
+                LearningTestpaperDelete:
+                  $ref: '#/components/examples/LearningTestpaperDelete'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
 
 # 添加这个 swagger ui 会显示授权按钮
 security:
@@ -634,6 +759,16 @@ components:
         id:
           type: integer
           description: ID
+    IdsReq:
+      type: object
+      required:
+        - id
+      properties:
+        id:
+          type: array
+          description: ID
+          items:
+            type: integer
     LearningMaterialList:
       type: object
       properties:
@@ -1050,6 +1185,88 @@ components:
         userId:
           type: integer
           description: 用户 Id
+    LearningTestpaperList:
+      type: object
+      properties:
+        page:
+          type: object
+          description: 分页信息,不传默认不分页,返回所有数据
+          properties:
+            current:
+              type: integer
+              description: 当前页面
+            size:
+              type: integer
+              description: 每页条数
+        orderBy:
+          type: object
+          description: 排序
+          properties:
+            type:
+              type: string
+              description: 排序方式
+              enum:
+                - asc
+                - desc
+            value:
+              type: string
+              description: 字段名
+        skillId:
+          type: integer
+          description: 技能 Id
+        enable:
+          type: integer
+          description: 是否启用 0 未启用 1 启用
+    LearningTestpaperAdd:
+      type: object
+      required:
+        - skillId
+        - name
+        - timeLimit
+        - passLimit
+        - question
+      properties:
+        skillId:
+          type: integer
+          description: 技能 Id
+        name:
+          type: string
+          description: 试卷名称
+        timeLimit:
+          type: string
+          description: 答题时间/分钟
+        passLimit:
+          type: string
+          description: 合格标准/题数
+        question:
+          type: string
+          description: 关联问题 Id 列表
+    LearningTestpaperUpdate:
+      type: object
+      required:
+        - id
+      properties:
+        id:
+          type: integer
+          description: 试卷 id
+        skillId:
+          type: integer
+          description: 技能 Id
+        name:
+          type: string
+          description: 试卷名称
+        timeLimit:
+          type: string
+          description: 答题时间/分钟
+        passLimit:
+          type: string
+          description: 合格标准/题数
+        question:
+          type: string
+          description: 关联问题 Id 列表
+        enable:
+          type: integer
+          description: 是否启用 0 未启用 1 启用
 
   examples:
     success:
@@ -1080,7 +1297,7 @@ components:
         id: 1
     LearningSkillDelete:
       value:
-        id: 1
+        id: [1]
     LearningMaterialList:
       value:
         page:
@@ -1135,7 +1352,7 @@ components:
             extend: .txt
     LearningMaterialDelete:
       value:
-        id: 1
+        id: [1]
     LearningQuestionGet:
       value:
         id: 1
@@ -1192,7 +1409,7 @@ components:
         explanationImage: https://go.dev/images/gophers/pilot-bust.svg
     LearningQuestionDelete:
       value:
-        id: 1
+        id: [1]
     LearningExamRecordAddToMy:
       value:
         skillId: 2
@@ -1214,3 +1431,34 @@ components:
     LearningLearningRecordList:
       value:
         materialId: 2
+    LearningTestpaperGet:
+      value:
+        id: 1
+    LearningTestpaperList:
+      value:
+        page:
+          current: 2
+          size: 2
+        orderBy:
+          type: desc
+          value: id
+        skillId: 2
+    LearningTestpaperAdd:
+      value:
+        skillId: 2
+        name: "试卷"
+        timeLimit: 5
+        passLimit: 2
+        question: [2,3]
+    LearningTestpaperUpdate:
+      value:
+        id: 1
+        skillId: 5
+        name: "测试试卷"
+        timeLimit: 10
+        passLimit: 1
+        question: [4,5,6]
+        enable: 1
+    LearningTestpaperDelete:
+      value:
+        id: [1]

+ 32 - 0
valid/valid.go

@@ -0,0 +1,32 @@
+package valid
+
+import (
+	"context"
+	"strings"
+
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/util/gconv"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+func init() {
+	if err := gvalid.RegisterRule("int-in", IntInChecker); err != nil {
+		panic(err)
+	}
+}
+
+func IntInChecker(ctx context.Context, rule string, value interface{}, message string, data interface{}) error {
+	// rule int-in:1,2
+	v := gconv.String(value)
+	allow := strings.Split(rule, ":")
+	if len(allow) < 2 {
+		return nil
+	}
+	allow = strings.Split(allow[1], ",")
+	for _, a := range allow {
+		if v == a {
+			return nil
+		}
+	}
+	return gerror.New(message)
+}