فهرست منبع

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

liuyaqi 3 سال پیش
والد
کامیت
c3ba46262a

+ 20 - 0
handler/learning/skill.go

@@ -33,6 +33,26 @@ func (c *LearningSkill) List(ctx context.Context, req *model.EmptyArgs, rsp *com
 	return nil
 }
 
+func (c *LearningSkill) ListMy(ctx context.Context, req *model.EmptyArgs, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("LearningSkill.ListMy request %#v ", *req)
+	s, err := learningSrv.NewLearningSkillService(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.LearningSkillMy{}
+	}
+	rsp.Code = code
+	rsp.Msg = msg
+	rsp.Data = ent
+	return nil
+}
+
 func (c *LearningSkill) Get(ctx context.Context, req *learning.LearningSkillGetReq, rsp *comm_def.CommonMsg) error {
 	g.Log().Infof("LearningSkill.Get request %#v ", *req)
 	s, err := learningSrv.NewLearningSkillService(ctx)

+ 1 - 1
model/learning/learning_learning_record.go

@@ -31,5 +31,5 @@ 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|int-in:1#请输入正确的状态类型|请输入状态"` // 状态 1 已学习
+	Status     int `json:"status" v:"required|int-in:1#请输入状态|请输入正确的状态类型"` // 状态 1 已学习
 }

+ 5 - 0
model/learning/learning_skill.go

@@ -38,3 +38,8 @@ type LearningSkillUpdateReq struct {
 type LearningSkillDeleteReq struct {
 	Id []int `json:"id" v:"required#请输入技能Id"` // 技能名称
 }
+
+type LearningSkillMy struct {
+	LearningSkill
+	LearntAll bool `json:"learntAll"` // 是否学完所有课程
+}

+ 15 - 0
service/learning/learning_record.go

@@ -117,3 +117,18 @@ func (s LearningLearningRecordService) Add(ctx context.Context, req *learning.Le
 	})
 	return int(id), err
 }
+
+func (s LearningLearningRecordService) LearntMaterialIds(ctx context.Context, userId int) ([]int, error) {
+	_, records, err := s.List(ctx, &learning.LearningLearningRecordListReq{
+		UserId: userId,
+		Status: 1,
+	})
+	if err != nil {
+		return nil, err
+	}
+	ids := []int{}
+	for _, r := range records {
+		ids = append(ids, r.MaterialId)
+	}
+	return ids, err
+}

+ 14 - 0
service/learning/material.go

@@ -267,3 +267,17 @@ func (s LearningMaterialService) Delete(ctx context.Context, id []int) error {
 	_, err = s.FileDao.Where("MaterialId IN (?)", id).Delete()
 	return err
 }
+
+func (s LearningMaterialService) MaterialIds(ctx context.Context, skillId int) ([]int, error) {
+	_, materials, err := s.List(ctx, &learning.LearningMaterialListReq{
+		SkillId: skillId,
+	})
+	if err != nil {
+		return nil, err
+	}
+	materialIds := []int{}
+	for _, m := range materials {
+		materialIds = append(materialIds, m.Id)
+	}
+	return materialIds, err
+}

+ 51 - 0
service/learning/skill.go

@@ -19,6 +19,8 @@ import (
 type LearningSkillService struct {
 	LearningSkillDao           *dao.LearningSkillDao
 	LearningSkillInstrumentDao *dao.LearningSkillInstrumentDao
+	LearningMaterialSrv        *LearningMaterialService
+	LearningRecordSrv          *LearningLearningRecordService
 	Tenant                     string
 	userInfo                   request.UserInfo
 }
@@ -33,9 +35,19 @@ func NewLearningSkillService(ctx context.Context) (*LearningSkillService, error)
 	if err != nil {
 		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
 	}
+	lrSrv, err := NewLearningLearningRecordService(ctx)
+	if err != nil {
+		return nil, err
+	}
+	lmSrv, err := NewLearningMaterialService(ctx)
+	if err != nil {
+		return nil, err
+	}
 	return &LearningSkillService{
 		LearningSkillDao:           dao.NewLearningSkillDao(tenant),
 		LearningSkillInstrumentDao: dao.NewLearningSkillInstrumentDao(tenant),
+		LearningMaterialSrv:        lmSrv,
+		LearningRecordSrv:          lrSrv,
 		Tenant:                     tenant,
 		userInfo:                   userInfo,
 	}, nil
@@ -190,3 +202,42 @@ func (s LearningSkillService) Delete(ctx context.Context, id []int) error {
 	_, err = s.LearningSkillDao.Where("Id IN (?)", id).Delete()
 	return err
 }
+
+func (s LearningSkillService) ListMy(ctx context.Context) ([]*learning.LearningSkillMy, error) {
+	ent, err := s.LearningSkillDao.All()
+	if err != nil {
+		return nil, err
+	}
+	list := []*learning.LearningSkillMy{}
+	for _, skill := range ent {
+		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
+			}
+		}
+		// fmt.Println(skill.Id, materialIds, recordIds, learntAll)
+		list = append(list, &learning.LearningSkillMy{
+			LearningSkill: *skill,
+			LearntAll:     learntAll,
+		})
+	}
+	return list, err
+}

+ 27 - 2
swaggerui/swagger.yml

@@ -34,7 +34,7 @@ paths:
       post:
         tags:
           - 考试培训-技能
-        operationId: LearningSkill.List
+        operationId: LearningSkillList
         summary: 技能列表
         requestBody:
           required: true
@@ -55,6 +55,31 @@ paths:
                   success:
                     $ref: "#/components/examples/success"
 
+    /LearningSkill.ListMy:
+      post:
+        tags:
+          - 考试培训-技能
+        operationId: LearningSkillListMy
+        summary: 我的技能列表
+        requestBody:
+          required: true
+          content:
+            application/json:
+              schema:
+                oneOf:
+                  - $ref: '#/components/schemas/NoArgs'
+              examples:
+                NoArgs:
+                  $ref: '#/components/examples/NoArgs'
+        responses:
+          200:
+            description: 请求成功
+            content:
+              application/json:
+                examples:
+                  success:
+                    $ref: "#/components/examples/success"
+
     /LearningSkill.Get:
       post:
         tags:
@@ -1486,7 +1511,7 @@ components:
     LearningLearningRecordAddToMy:
       value:
         materialId: 2
-        status: 2
+        status: 1
     LearningLearningRecordListMy:
       value:
         materialId: 2