瀏覽代碼

fix:培训考试添加移动端试卷列表接口

liuyaqi 3 年之前
父節點
當前提交
0281005538

+ 21 - 0
handler/learning/testpaper.go

@@ -2,6 +2,7 @@ package learning
 
 import (
 	"context"
+	"lims_adapter/model"
 	"lims_adapter/model/learning"
 	learningSrv "lims_adapter/service/learning"
 
@@ -35,6 +36,26 @@ func (c *LearningTestpaper) List(ctx context.Context, req *learning.LearningTest
 	return nil
 }
 
+func (c *LearningTestpaper) ListMy(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningTestpaper.ListMy request %#v ", *req)
+	s, err := learningSrv.NewLearningTestpaperService(ctx)
+	if err != nil {
+		return err
+	}
+	ent, err := s.ListMy(ctx)
+	_, err, code, msg := myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*learning.LearningTestpaperMy{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = 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)

+ 1 - 1
model/learning/learning_material.go

@@ -44,7 +44,7 @@ type LearningMaterialAddReq struct {
 	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"`                                         // 资料内容
+	Content string                        `json:"content" v:"required#请输入资料内容"`                    // 资料内容
 	File    []*LearningMaterialAddReqFile `json:"file"`                                            // 附件
 }
 

+ 6 - 0
model/learning/learning_testpaper.go

@@ -51,3 +51,9 @@ type LearningTestpaperUpdateReq struct {
 type LearningTestpaperDeleteReq struct {
 	Id []int `json:"id" v:"required#请输入试卷Id"`
 }
+
+type LearningTestpaperMy struct {
+	LearningTestpaper
+	SkillName string `json:"skillName"`
+	LearntAll bool   `json:"learntAll"` // 是否学完所有课程
+}

+ 64 - 0
service/learning/testpaper.go

@@ -18,6 +18,9 @@ type LearningTestpaperService struct {
 	Dao                  *dao.LearningTestpaperDao
 	QuestionDao          *dao.LearningQuestionDao
 	QuestionTestpaperDao *dao.LearningQuestionTestpaperDao
+	SkillDao             *dao.LearningSkillDao
+	LearningMaterialSrv  *LearningMaterialService
+	LearningRecordSrv    *LearningLearningRecordService
 	ExamRecordService    *LearningExamRecordService
 	Tenant               string
 	userInfo             request.UserInfo
@@ -37,10 +40,21 @@ func NewLearningTestpaperService(ctx context.Context) (*LearningTestpaperService
 	if err != nil {
 		return nil, err
 	}
+	lrSrv, err := NewLearningLearningRecordService(ctx)
+	if err != nil {
+		return nil, err
+	}
+	lmSrv, err := NewLearningMaterialService(ctx)
+	if err != nil {
+		return nil, err
+	}
 	return &LearningTestpaperService{
 		Dao:                  dao.NewLearningTestpaperDao(tenant),
 		QuestionDao:          dao.NewLearningQuestionDao(tenant),
 		QuestionTestpaperDao: dao.NewLearningQuestionTestpaperDao(tenant),
+		SkillDao:             dao.NewLearningSkillDao(tenant),
+		LearningMaterialSrv:  lmSrv,
+		LearningRecordSrv:    lrSrv,
 		ExamRecordService:    examRecordService,
 		Tenant:               tenant,
 		userInfo:             userInfo,
@@ -123,6 +137,56 @@ func (s LearningTestpaperService) List(ctx context.Context, req *learning.Learni
 	return total, ent, err
 }
 
+func (s LearningTestpaperService) ListMy(ctx context.Context) ([]*learning.LearningTestpaperMy, error) {
+	enable := 1
+	_, testpaper, err := s.List(ctx, &learning.LearningTestpaperListReq{Enable: &enable})
+	if err != nil {
+		return nil, err
+	}
+	list := []*learning.LearningTestpaperMy{}
+	for _, tp := range testpaper {
+		skill, err := s.SkillDao.Where("Id = ?", tp.SkillId).One()
+		if err != nil {
+			return nil, err
+		}
+		if skill == nil {
+			continue
+		}
+
+		materialIds, err := s.LearningMaterialSrv.MaterialIds(ctx, skill.Id)
+		if err != nil {
+			return nil, err
+		}
+		recordIds, err := s.LearningRecordSrv.LearntMaterialIds(ctx, int(s.userInfo.Id))
+		if err != nil {
+			return nil, err
+		}
+
+		// 如果没有关联的资料,直接算学完了
+		learntAll := true
+		for _, mid := range materialIds {
+			found := false
+			for _, rid := range recordIds {
+				if mid == rid {
+					found = true
+				}
+			}
+			if !found {
+				learntAll = false
+				break
+			}
+		}
+
+		list = append(list, &learning.LearningTestpaperMy{
+			LearningTestpaper: *tp,
+			SkillName:         skill.Name,
+			LearntAll:         learntAll,
+		})
+
+	}
+	return list, nil
+}
+
 func (s LearningTestpaperService) Add(ctx context.Context, req *learning.LearningTestpaperAddReq) (int, error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
 	if validErr != nil {

+ 26 - 0
swaggerui/swagger.yml

@@ -680,6 +680,31 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningTestpaper.ListMy:
+      post:
+        tags:
+          - 考试培训-试卷
+        operationId: LearningTestpaperListMy
+        summary: 我的试卷
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/NoArgs'
+              examples:
+                LearningTestpaperList:
+                  $ref: '#/components/examples/NoArgs'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
     /LearningTestpaper.Add:
       post:
         tags:
@@ -892,6 +917,7 @@ components:
         - name
         - type
         - enable
+        - content
       properties:
           skillId:
             type: integer