fix: preserve scoped six-module score updates

main
chenyuan 4 weeks ago
parent f96cb66d02
commit 1fa2f14a15

@ -287,7 +287,8 @@ public class ScoreController {
StuRank scoreRank = new StuRank();
scoreRank.setClassName(className);
scoreRank.setSchoolId(teacher.getSchoolId());
List<TeaTrendVo> voList = stuRankMapper.selectFiveAvgTotalScoreBySchoolIdAndClassName(scoreRank);
scoreRank.setSchoolClassId(ownedClass.getSchoolClassId());
List<TeaTrendVo> voList = stuRankMapper.selectFiveAvgTotalScoreBySchoolClassId(scoreRank);
List<BigDecimal> classAverageScoreList = new ArrayList<>();
List<String> startTimeList = new ArrayList<>();
for (int j = voList.size()-1; j >= 0; j--) {

@ -10,6 +10,7 @@ import com.sztzjy.linkCommerce.entity.*;
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
import com.sztzjy.linkCommerce.mapper.StuGradeMapper;
import com.sztzjy.linkCommerce.mapper.StuRankMapper;
import com.sztzjy.linkCommerce.mapper.StudentTrainingAnswerMapper;
import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper;
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
import com.sztzjy.linkCommerce.mapper.WeightMapper;
@ -55,6 +56,8 @@ public class TeaScoreController {
@Autowired
TaskAllocationMapper taskAllocationMapper;
@Autowired(required = false)
StudentTrainingAnswerMapper studentTrainingAnswerMapper;
@Autowired(required = false)
SchoolDefaultTaskService schoolDefaultTaskService;
@Autowired
TeacherScoreService teacherScoreService;
@ -149,7 +152,7 @@ public class TeaScoreController {
@PostMapping("/selectStuScoreDetail")
@ApiOperation("查看学生成绩详情")
@AnonymousAccess
public ResultEntity<List<StuGrade>> selectStuScoreDetail(@RequestParam String userId,
public ResultEntity selectStuScoreDetail(@RequestParam String userId,
@RequestParam(required = false) String classId,
HttpServletRequest request) {
JwtUser teacher = currentUser(request);
@ -157,6 +160,11 @@ public class TeaScoreController {
if (teachingClassStudentMapper.countByStudentUserIdAndTeachingClassId(userId, teachingClass.getSchoolClassId()) == 0) {
return new ResultEntity<>(HttpStatus.FORBIDDEN, "无权查看该学生成绩");
}
if (studentTrainingAnswerMapper != null) {
List<StudentTrainingAnswer> answers = studentTrainingAnswerMapper.selectByStudentAndTeachingClass(userId, classId);
return new ResultEntity<>(HttpStatus.OK, "查看学生成绩详情成功",
answers == null ? Collections.emptyList() : answers);
}
// 定义模块的固定排序顺序
List<String> moduleOrder = Arrays.asList(
"行业需求分析",

@ -35,5 +35,7 @@ public interface StuRankMapper {
List<TeaTrendVo> selectFiveAvgTotalScoreBySchoolIdAndClassName(StuRank scoreRank);
List<TeaTrendVo> selectFiveAvgTotalScoreBySchoolClassId(StuRank scoreRank);
}
}

@ -4,6 +4,7 @@ import com.sztzjy.linkCommerce.entity.*;
import com.sztzjy.linkCommerce.entity.scoreDTO.StuModuleDTO;
import com.sztzjy.linkCommerce.mapper.*;
import com.sztzjy.linkCommerce.service.ScoreRankService;
import com.sztzjy.linkCommerce.service.SchoolDefaultTaskService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
@ -44,6 +45,8 @@ public class ScoreRankServiceImpl implements ScoreRankService {
@Autowired(required = false)
TeachingClassScoreWeightMapper teachingClassScoreWeightMapper;
@Autowired(required = false)
SchoolDefaultTaskService schoolDefaultTaskService;
@Autowired(required = false)
JdbcTemplate jdbcTemplate;
private volatile boolean stuRankIndexesChecked = false;
@ -52,6 +55,15 @@ public class ScoreRankServiceImpl implements ScoreRankService {
@Scheduled(cron = "0 0 1 * * ?")
public Boolean doRank() {
ensureStuRankIndexes();
if (schoolClassMapper != null) {
SchoolClassExample teachingClassExample = new SchoolClassExample();
teachingClassExample.createCriteria().andClassTypeEqualTo("TEACHING");
List<SchoolClass> teachingClasses = schoolClassMapper.selectByExample(teachingClassExample);
for (SchoolClass teachingClass : teachingClasses == null ? Collections.<SchoolClass>emptyList() : teachingClasses) {
doRankTeachingClass(teachingClass.getSchoolId(), teachingClass.getSchoolClassId());
}
return true;
}
//先删除当天所有的数据 防止脏数据
StuRankExample scoreRankExample = new StuRankExample();
scoreRankExample.createCriteria().andUpdateTimeEqualTo(getNowDate());
@ -331,7 +343,9 @@ public class ScoreRankServiceImpl implements ScoreRankService {
}
TaskAllocationExample allocationExample = new TaskAllocationExample();
allocationExample.createCriteria().andClassIdEqualTo(teachingClassId);
List<TaskAllocation> allocations = taskAllocationMapper.selectByExample(allocationExample);
List<TaskAllocation> allocations = schoolDefaultTaskService == null
? taskAllocationMapper.selectByExample(allocationExample)
: schoolDefaultTaskService.resolveForTeachingClass(teachingClassId);
Map<String, List<Integer>> scoresByProject = new HashMap<>();
for (TaskAllocation allocation : allocations == null ? Collections.<TaskAllocation>emptyList() : allocations) {
if (allocation.getDisabledStatus() != null && allocation.getDisabledStatus() == 1

@ -502,4 +502,14 @@
order by update_time desc
LIMIT 5
</select>
</mapper>
<select id="selectFiveAvgTotalScoreBySchoolClassId" parameterType="com.sztzjy.linkCommerce.entity.StuRank" resultMap="teaTrendResultMap">
select s.update_time update_date, avg(score) avg_total_score
from stu_rank s
where school_id = #{schoolId,jdbcType=VARCHAR}
and school_class_id = #{schoolClassId,jdbcType=VARCHAR}
group by s.update_time
order by s.update_time desc
limit 5
</select>
</mapper>

@ -0,0 +1,39 @@
package com.sztzjy.linkCommerce.service.impl;
import com.sztzjy.linkCommerce.entity.SchoolClass;
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
import com.sztzjy.linkCommerce.mapper.StuRankMapper;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class ScoreRankServiceTeachingClassSchedulerTest {
@Test
void scheduledRankingRecalculatesTeachingClassesInsteadOfSchoolWideLegacyRanks() {
ScoreRankServiceImpl service = spy(new ScoreRankServiceImpl());
SchoolClassMapper classMapper = mock(SchoolClassMapper.class);
StuRankMapper rankMapper = mock(StuRankMapper.class);
ReflectionTestUtils.setField(service, "schoolClassMapper", classMapper);
ReflectionTestUtils.setField(service, "stuRankMapper", rankMapper);
SchoolClass teachingClass = new SchoolClass();
teachingClass.setSchoolClassId("class-1");
teachingClass.setSchoolId("school-1");
teachingClass.setClassType("TEACHING");
when(classMapper.selectByExample(any())).thenReturn(Collections.singletonList(teachingClass));
doReturn(true).when(service).doRankTeachingClass("school-1", "class-1");
assertTrue(service.doRank());
verify(service).doRankTeachingClass(eq("school-1"), eq("class-1"));
}
}
Loading…
Cancel
Save