|
@@ -7,6 +7,9 @@ import (
|
|
|
"lims_adapter/dao/learning"
|
|
"lims_adapter/dao/learning"
|
|
|
"lims_adapter/model"
|
|
"lims_adapter/model"
|
|
|
"lims_adapter/model/learning"
|
|
"lims_adapter/model/learning"
|
|
|
|
|
+ "reflect"
|
|
|
|
|
+ "sort"
|
|
|
|
|
+ "strings"
|
|
|
|
|
|
|
|
"dashoo.cn/micro_libary/micro_srv"
|
|
"dashoo.cn/micro_libary/micro_srv"
|
|
|
"dashoo.cn/micro_libary/myerrors"
|
|
"dashoo.cn/micro_libary/myerrors"
|
|
@@ -16,9 +19,11 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type LearningExamRecordService struct {
|
|
type LearningExamRecordService struct {
|
|
|
- Dao *dao.LearningExamRecordDao
|
|
|
|
|
- Tenant string
|
|
|
|
|
- userInfo request.UserInfo
|
|
|
|
|
|
|
+ Dao *dao.LearningExamRecordDao
|
|
|
|
|
+ TestpaperDao *dao.LearningTestpaperDao
|
|
|
|
|
+ QuestionSrv *LearningQuestionService
|
|
|
|
|
+ Tenant string
|
|
|
|
|
+ userInfo request.UserInfo
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func NewLearningExamRecordService(ctx context.Context) (*LearningExamRecordService, error) {
|
|
func NewLearningExamRecordService(ctx context.Context) (*LearningExamRecordService, error) {
|
|
@@ -31,10 +36,16 @@ func NewLearningExamRecordService(ctx context.Context) (*LearningExamRecordServi
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
|
|
return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
|
|
|
}
|
|
}
|
|
|
|
|
+ tps, err := NewLearningQuestionService(ctx)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
return &LearningExamRecordService{
|
|
return &LearningExamRecordService{
|
|
|
- Dao: dao.NewLearningExamRecordDao(tenant),
|
|
|
|
|
- Tenant: tenant,
|
|
|
|
|
- userInfo: userInfo,
|
|
|
|
|
|
|
+ Dao: dao.NewLearningExamRecordDao(tenant),
|
|
|
|
|
+ TestpaperDao: dao.NewLearningTestpaperDao(tenant),
|
|
|
|
|
+ QuestionSrv: tps,
|
|
|
|
|
+ Tenant: tenant,
|
|
|
|
|
+ userInfo: userInfo,
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -95,6 +106,12 @@ func (s LearningExamRecordService) List(ctx context.Context, req *learning.Learn
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
return 0, nil, err
|
|
return 0, nil, err
|
|
|
}
|
|
}
|
|
|
|
|
+ for i := range records {
|
|
|
|
|
+ if records[i].QuestionCount == 0 || records[i].CorrectCount == 0 {
|
|
|
|
|
+ records[i].CorrectRate = "0%"
|
|
|
|
|
+ }
|
|
|
|
|
+ records[i].CorrectRate = fmt.Sprintf("%.f%%", float64(records[i].CorrectCount)/float64(records[i].QuestionCount)*100)
|
|
|
|
|
+ }
|
|
|
return total, records, err
|
|
return total, records, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -117,21 +134,48 @@ func (s LearningExamRecordService) Add(ctx context.Context, req *learning.Learni
|
|
|
if r.IsEmpty() {
|
|
if r.IsEmpty() {
|
|
|
return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
|
|
return 0, myerrors.NewMsgError(nil, fmt.Sprintf("技能不存在: %d", req.SkillId))
|
|
|
}
|
|
}
|
|
|
- r, err = s.Dao.DB.Table("learning_testpaper").Where("Id = ?", req.TestpaperId).One()
|
|
|
|
|
|
|
+
|
|
|
|
|
+ tp, err := s.TestpaperDao.Where("Id = ?", req.TestpaperId).One()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return 0, err
|
|
return 0, err
|
|
|
}
|
|
}
|
|
|
- if r.IsEmpty() {
|
|
|
|
|
|
|
+ if tp == nil {
|
|
|
return 0, myerrors.NewMsgError(nil, fmt.Sprintf("试卷不存在: %d", req.TestpaperId))
|
|
return 0, myerrors.NewMsgError(nil, fmt.Sprintf("试卷不存在: %d", req.TestpaperId))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ qustions, err := s.QuestionSrv.ListByTestpaperId(ctx, req.TestpaperId)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return 0, err
|
|
|
|
|
+ }
|
|
|
|
|
+ questionCount := len(qustions)
|
|
|
|
|
+ correctCount := 0
|
|
|
|
|
+ userAnswerMap := map[int][]string{}
|
|
|
|
|
+ for _, a := range req.Detail {
|
|
|
|
|
+ userAnswerMap[a.QuestionId] = a.Answer
|
|
|
|
|
+ }
|
|
|
|
|
+ for _, q := range qustions {
|
|
|
|
|
+ answer := strings.Split(strings.ToUpper(q.Answer), " ")
|
|
|
|
|
+ userAnswer := userAnswerMap[q.Id]
|
|
|
|
|
+ if len(answer) != len(userAnswer) {
|
|
|
|
|
+ continue
|
|
|
|
|
+ }
|
|
|
|
|
+ sort.Strings(answer)
|
|
|
|
|
+ sort.Strings(userAnswer)
|
|
|
|
|
+ // fmt.Println(q, answer, userAnswer, reflect.DeepEqual(answer, userAnswer))
|
|
|
|
|
+ if reflect.DeepEqual(answer, userAnswer) {
|
|
|
|
|
+ correctCount++
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
id, err := s.Dao.InsertAndGetId(learning.LearningExamRecord{
|
|
id, err := s.Dao.InsertAndGetId(learning.LearningExamRecord{
|
|
|
- UserId: req.UserId,
|
|
|
|
|
- SkillId: req.SkillId,
|
|
|
|
|
- TestpaperId: req.TestpaperId,
|
|
|
|
|
- Status: req.Status,
|
|
|
|
|
- CreatedAt: gtime.Now(),
|
|
|
|
|
- UpdatedAt: gtime.Now(),
|
|
|
|
|
|
|
+ UserId: req.UserId,
|
|
|
|
|
+ SkillId: req.SkillId,
|
|
|
|
|
+ TestpaperId: req.TestpaperId,
|
|
|
|
|
+ QuestionCount: questionCount,
|
|
|
|
|
+ CorrectCount: correctCount,
|
|
|
|
|
+ Status: req.Status,
|
|
|
|
|
+ CreatedAt: gtime.Now(),
|
|
|
|
|
+ UpdatedAt: gtime.Now(),
|
|
|
})
|
|
})
|
|
|
return int(id), err
|
|
return int(id), err
|
|
|
}
|
|
}
|