|
|
@@ -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 {
|