|
|
@@ -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
|
|
|
+}
|