题目相关的成绩详情

beetlsql3-dev
Mlxa0324 3 years ago
parent 0133dc2a71
commit 87ae82b4e0

@ -1,10 +1,10 @@
package com.ibeetl.jlw.entity;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ibeetl.admin.core.entity.BaseEntity;
import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
import lombok.Data;
import org.beetl.sql.annotation.entity.Auto;
import org.beetl.sql.annotation.entity.Table;
import org.beetl.sql.fetch.annotation.Fetch;
import org.beetl.sql.fetch.annotation.FetchSql;
@ -21,6 +21,10 @@ import java.util.List;
@Table(name = "teacher_open_course_question_log")
public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
@Auto
private Long teacherOpenCourseQuestionLogId ;
/** ========================================================================= */
/** ========== 这部分数据需要通过BeetlSQL来查询才能自动触发FetchSql 注解 ========== */
//来源类型(枚举)
@ -41,7 +45,7 @@ public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
"left join resources_question_snapshot ta on ta.resources_question_snapshot_id = t.resources_question_snapshot_id " +
"where t.teacher_open_course_question_log_status = 1 " +
"and t.student_id = #studentId# " +
"and t.teacher_open_course_question_log_from_type = #teacherOpenCourseQuestionLogFromType# " +
"and t.teacher_open_course_question_log_from_type = #resourcesQuestionSnapshotFromType# " +
"and CONCAT(t.teacher_open_course_question_log_answer, ',') = ta.question_answer"
)
private int correctCount;
@ -51,7 +55,7 @@ public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
"left join resources_question_snapshot ta on ta.resources_question_snapshot_id = t.resources_question_snapshot_id " +
"where t.teacher_open_course_question_log_status = 1 " +
"and t.student_id = #studentId# " +
"and t.teacher_open_course_question_log_from_type = #teacherOpenCourseQuestionLogFromType# " +
"and t.teacher_open_course_question_log_from_type = #resourcesQuestionSnapshotFromType# " +
"and CONCAT(t.teacher_open_course_question_log_answer, ',') != ta.question_answer"
)
private int wrongCount;
@ -62,7 +66,7 @@ public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
"left join resources_question_snapshot ta on ta.resources_question_snapshot_id = t.resources_question_snapshot_id " +
"where t.teacher_open_course_question_log_status = 1 " +
"and t.student_id = #studentId# " +
"and t.teacher_open_course_question_log_from_type = #teacherOpenCourseQuestionLogFromType# " +
"and t.teacher_open_course_question_log_from_type = #resourcesQuestionSnapshotFromType# " +
"and CONCAT(t.teacher_open_course_question_log_answer, ',') != ta.question_answer"
)
private float totalScore;
@ -81,8 +85,8 @@ public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
"LEFT JOIN resources_question_snapshot ta ON ta.resources_question_snapshot_id = t.resources_question_snapshot_id " +
"WHERE t.teacher_open_course_question_log_status = 1 " +
"and t.student_id = #studentId# " +
"and t.teacher_open_course_question_log_from_type = #teacherOpenCourseQuestionLogFromType# " +
"and t.teacher_open_course_question_log_from_id = #teacherOpenCourseQuestionLogFromId# "
"and t.teacher_open_course_question_log_from_type = #resourcesQuestionSnapshotFromType# " +
"and t.teacher_open_course_question_log_from_id = #resourcesQuestionSnapshotFromId# "
)
private List<TeacherOpenCourseQuestionLog> questionLogList;
@ -100,11 +104,12 @@ public class TeacherOpenCourseQuestionLogScoreInfo extends BaseEntity {
*
*/
private void tryCalcCorrectRate() {
if (ObjectUtil.isAllNotEmpty(this.getCorrectCount(), this.getWrongCount())) {
int temp = this.getCorrectCount() + this.getWrongCount();
if (this.getCorrectCount() > 0 && this.getWrongCount() > 0) {
// 计算正确率, 取小数点后2位数
// 计算规则:正确率 = 正确数量 / (正确数量 + 错误数量) * 100
this.setCorrectRate(NumberUtil
.round(this.getCorrectCount() / (this.getCorrectCount() + this.getWrongCount()) * 100, 0)
.round(NumberUtil.div(this.getCorrectCount(), temp) * 100, 0)
.intValue());
}
}

@ -15,6 +15,7 @@ import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionLogScoreInfo;
import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
import com.ibeetl.jlw.web.query.ResourcesQuestionSnapshotQuery;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.SQLReady;
import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.stereotype.Service;
@ -163,15 +164,17 @@ public class ResourcesQuestionSnapshotService extends CoreBaseService<ResourcesQ
// 查询学生身份
Student student = studentDao.getByUserId(getUserId());
TeacherOpenCourseQuestionLogScoreInfo teacherOpenCourseQuestionLogScoreInfo = new TeacherOpenCourseQuestionLogScoreInfo();
teacherOpenCourseQuestionLogScoreInfo.setStudentId(student.getStudentId());
teacherOpenCourseQuestionLogScoreInfo.setResourcesQuestionSnapshotFromId(snapshotFromId);
teacherOpenCourseQuestionLogScoreInfo.setResourcesQuestionSnapshotFromType(snapshotFromType);
// 查询符合条件的实体
TeacherOpenCourseQuestionLogScoreInfo scoreInfo = sqlManager.execute(
"select * from ",
teacherOpenCourseQuestionLogScoreInfo);
TeacherOpenCourseQuestionLogScoreInfo scoreInfo = sqlManager.executeQueryOne(
new SQLReady("SELECT " +
"? as resources_question_snapshot_from_type, " +
"? as resources_question_snapshot_from_id, " +
"? as student_id ",
snapshotFromType.name(), snapshotFromId, student.getStudentId()
),
TeacherOpenCourseQuestionLogScoreInfo.class
);
return scoreInfo;
}

@ -3,12 +3,15 @@ package com.ibeetl.jlw.service;
import cn.jlw.util.ToolUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ibeetl.admin.core.entity.CoreUser;
import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.admin.core.web.JsonReturnCode;
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao;
import com.ibeetl.jlw.entity.ResourcesQuestionSnapshot;
import com.ibeetl.jlw.entity.Student;
import com.ibeetl.jlw.entity.TeacherOpenCourseQuestionLog;
import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
@ -18,12 +21,13 @@ import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import static cn.hutool.core.util.ArrayUtil.join;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUserId;
import static com.ibeetl.admin.core.util.user.CacheUserUtil.getUser;
/**
* Service
@ -36,6 +40,7 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
@Resource private TeacherOpenCourseQuestionLogDao teacherOpenCourseQuestionLogDao;
@Resource private StudentDao studentDao;
@Resource private ResourcesQuestionSnapshotDao resourcesQuestionSnapshotDao;
public PageQuery<TeacherOpenCourseQuestionLog>queryByCondition(PageQuery query){
PageQuery ret = teacherOpenCourseQuestionLogDao.queryByCondition(query);
@ -160,7 +165,12 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
public void addQuestionLog(Map<Long, TreeSet<String>> questionLogMap, final ResourcesQuestionSnapshotFromTypeEnum fromType) {
// 查询学生身份
Student student = studentDao.getByUserId(getUserId());
final CoreUser user = getUser();
final Student student = studentDao.getByUserId(user.getId());
ResourcesQuestionSnapshot entity = new ResourcesQuestionSnapshot();
entity.setResourcesQuestionSnapshotId(CollectionUtils.firstElement(questionLogMap.keySet()));
ResourcesQuestionSnapshot resourcesQuestionSnapshot = resourcesQuestionSnapshotDao.templateOne(entity);
List<TeacherOpenCourseQuestionLog> list = new ArrayList<>();
@ -171,8 +181,10 @@ public class TeacherOpenCourseQuestionLogService extends CoreBaseService<Teacher
// 构建实体
TeacherOpenCourseQuestionLog questionLog = new TeacherOpenCourseQuestionLog();
questionLog.setTeacherOpenCourseQuestionLogFromType(fromType);
questionLog.setTeacherOpenCourseQuestionLogFromId(resourcesQuestionSnapshotId);
questionLog.setTeacherOpenCourseQuestionLogFromId(resourcesQuestionSnapshot.getResourcesQuestionSnapshotFromId());
questionLog.setTeacherOpenCourseQuestionLogStatus(1);
questionLog.setOrgId(user.getOrgId());
questionLog.setUserId(user.getId());
// 包含/字符,代表是路径地址,是附件类型
if(answersText.contains("/")) {
questionLog.setTeacherOpenCourseQuestionLogUploadFile(answersText);

@ -21,6 +21,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
/**
* <p>
@ -69,6 +70,14 @@ public class BaseTest {
TestEnvUtil.setProperty("user.orgId", student.getOrgId().toString());
}
public void putLoginInfoToEnv(final String userId, final String orgId) throws Exception {
Objects.requireNonNull(userId);
Objects.requireNonNull(orgId);
// 换学生身份登录系统
TestEnvUtil.setProperty("user.id", userId);
TestEnvUtil.setProperty("user.orgId", orgId);
}
/**
* session
* application-test.properties

@ -2,7 +2,6 @@ package com.ibeetl.jlw.web;
import base.BaseTest;
import cn.hutool.core.util.ObjectUtil;
import com.ibeetl.admin.test.util.test.TestEnvUtil;
import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.dao.TeacherOpenCourseQuestionLogDao;
import com.ibeetl.jlw.entity.Student;
@ -54,18 +53,16 @@ class ResourcesQuestionSnapshotControllerTest extends BaseTest {
TeacherOpenCourseQuestionLog questionLog = CollectionUtils.firstElement(questionLogs);
// 模拟登录学生身份
Student student = studentDao.single(questionLog.getStudentId());
TestEnvUtil.setProperty("user.id", student.getUserId().toString());
TestEnvUtil.setProperty("user.orgId", student.getOrgId().toString());
Student student = CollectionUtils.firstElement(studentDao.getByIds(questionLog.getStudentId().toString()));
// 随机取一个学生的登录信息
putStudentLoginInfoToEnv();
putLoginInfoToEnv(student.getUserId().toString(), student.getOrgId().toString());
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/getScoreInfo.json")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("fromType", questionLog.getTeacherOpenCourseQuestionLogFromType().toString())
.param("fromId", questionLog.getTeacherOpenCourseQuestionLogFromId().toString())
.param("snapshotFromType", questionLog.getTeacherOpenCourseQuestionLogFromType().toString())
.param("snapshotFromId", questionLog.getTeacherOpenCourseQuestionLogFromId().toString())
;
//发送请求,验证返回结果

@ -6,20 +6,17 @@ import cn.hutool.core.util.RandomUtil;
import com.ibeetl.jlw.dao.ResourcesQuestionSnapshotDao;
import com.ibeetl.jlw.dao.StudentDao;
import com.ibeetl.jlw.entity.ResourcesQuestionSnapshot;
import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static cn.hutool.json.JSONUtil.toJsonStr;
import static com.ibeetl.admin.test.util.test.RandomUtils.randomSet;
import static org.apache.commons.lang3.StringUtils.join;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -47,12 +44,15 @@ class TeacherOpenCourseQuestionLogControllerTest extends BaseTest {
List<ResourcesQuestionSnapshot> questionSnapshots = resourcesQuestionSnapshotDao.execute(
"select t.*\n" +
" from resources_question_snapshot t\n" +
"where t.question_status = 1\t\n" +
"order by RAND() \n" +
"limit 10 ");
" where t.question_status = 1\n" +
"\tand resources_question_snapshot_from_id = \n" +
"\t\t(select resources_question_snapshot_from_id from resources_question_snapshot ORDER BY RAND() limit 1) \n" +
" order by RAND()");
// 随机取题目ID和答案
// 题目快照ID和答案
Map<Long, TreeSet<String>> answerRandomMap = new ConcurrentHashMap<>();
// 自动选择选项
questionSnapshots.stream().forEach(item -> {
TreeSet<String> answer = new TreeSet<>();
// 单选
@ -80,14 +80,10 @@ class TeacherOpenCourseQuestionLogControllerTest extends BaseTest {
// 随机取一个学生的登录信息
putStudentLoginInfoToEnv();
// 随机来源类型
ResourcesQuestionSnapshotFromTypeEnum fromTypeEnum = CollectionUtils
.firstElement(randomSet(ResourcesQuestionSnapshotFromTypeEnum.class));
//构造请求参数
RequestBuilder rb = MockMvcRequestBuilders.post(MODEL + "/addQuestionLog.json")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.param("fromType", fromTypeEnum.name())
.param("fromType", questionSnapshots.get(0).getResourcesQuestionSnapshotFromType().toString())
.content(toJsonStr(answerRandomMap));
//发送请求,验证返回结果
String result = mvc.perform(rb)

Loading…
Cancel
Save