@ -4,6 +4,8 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo ;
import com.github.pagehelper.PageInfo ;
import com.github.pagehelper.util.StringUtil ;
import com.github.pagehelper.util.StringUtil ;
import com.sztzjy.linkCommerce.annotation.AnonymousAccess ;
import com.sztzjy.linkCommerce.annotation.AnonymousAccess ;
import com.sztzjy.linkCommerce.config.security.JwtUser ;
import com.sztzjy.linkCommerce.config.security.TokenProvider ;
import com.sztzjy.linkCommerce.entity.* ;
import com.sztzjy.linkCommerce.entity.* ;
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper ;
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper ;
import com.sztzjy.linkCommerce.mapper.StuGradeMapper ;
import com.sztzjy.linkCommerce.mapper.StuGradeMapper ;
@ -13,6 +15,7 @@ import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
import com.sztzjy.linkCommerce.mapper.WeightMapper ;
import com.sztzjy.linkCommerce.mapper.WeightMapper ;
import com.sztzjy.linkCommerce.service.ScoreRankService ;
import com.sztzjy.linkCommerce.service.ScoreRankService ;
import com.sztzjy.linkCommerce.service.SchoolDefaultTaskService ;
import com.sztzjy.linkCommerce.service.SchoolDefaultTaskService ;
import com.sztzjy.linkCommerce.service.TeacherScoreService ;
import com.sztzjy.linkCommerce.util.ResultEntity ;
import com.sztzjy.linkCommerce.util.ResultEntity ;
import com.sztzjy.linkCommerce.util.excel.FilePortUtil ;
import com.sztzjy.linkCommerce.util.excel.FilePortUtil ;
import io.swagger.annotations.Api ;
import io.swagger.annotations.Api ;
@ -24,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.* ;
import org.springframework.web.bind.annotation.* ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpServletRequest ;
import java.math.BigDecimal ;
import java.math.BigDecimal ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
@ -52,6 +56,43 @@ public class TeaScoreController {
TaskAllocationMapper taskAllocationMapper ;
TaskAllocationMapper taskAllocationMapper ;
@Autowired ( required = false )
@Autowired ( required = false )
SchoolDefaultTaskService schoolDefaultTaskService ;
SchoolDefaultTaskService schoolDefaultTaskService ;
@Autowired
TeacherScoreService teacherScoreService ;
@GetMapping ( "/ownedTeachingClasses" )
@ApiOperation ( "教师本人教学班列表" )
public ResultEntity < List < SchoolClass > > ownedTeachingClasses ( HttpServletRequest request ) {
try {
return new ResultEntity < > ( HttpStatus . OK , "查询成功" , teacherScoreService . listOwnedClasses ( currentUser ( request ) ) ) ;
} catch ( com . sztzjy . linkCommerce . config . exception . handler . ServiceException e ) {
return new ResultEntity < > ( e . getCode ( ) , e . getMessage ( ) ) ;
}
}
@PostMapping ( "/selectTeachingClassWeight" )
@ApiOperation ( "查询本人教学班六模块权重" )
public ResultEntity < TeachingClassScoreWeight > selectTeachingClassWeight ( @RequestParam String teachingClassId ,
HttpServletRequest request ) {
try {
return new ResultEntity < > ( HttpStatus . OK , "查询权重成功" ,
teacherScoreService . getOrCreateWeight ( currentUser ( request ) , teachingClassId ) ) ;
} catch ( com . sztzjy . linkCommerce . config . exception . handler . ServiceException e ) {
return new ResultEntity < > ( e . getCode ( ) , e . getMessage ( ) ) ;
}
}
@PostMapping ( "/updateTeachingClassWeight" )
@ApiOperation ( "修改本人教学班六模块权重" )
public ResultEntity < TeachingClassScoreWeight > updateTeachingClassWeight ( @RequestParam String teachingClassId ,
@RequestBody TeachingClassScoreWeight weight ,
HttpServletRequest request ) {
try {
return new ResultEntity < > ( HttpStatus . OK , "修改权重成功" ,
teacherScoreService . saveWeight ( currentUser ( request ) , teachingClassId , weight ) ) ;
} catch ( com . sztzjy . linkCommerce . config . exception . handler . ServiceException e ) {
return new ResultEntity < > ( e . getCode ( ) , e . getMessage ( ) ) ;
}
}
@PostMapping ( "/selectStuRankAndScore" )
@PostMapping ( "/selectStuRankAndScore" )
@ApiOperation ( "查询学生成绩和排名" )
@ApiOperation ( "查询学生成绩和排名" )
@ -60,14 +101,16 @@ public class TeaScoreController {
@RequestParam ( required = false ) String userName ,
@RequestParam ( required = false ) String userName ,
@RequestParam ( required = false ) String name ,
@RequestParam ( required = false ) String name ,
@RequestParam String schoolId ,
@RequestParam String schoolId ,
@RequestParam Integer index , @RequestParam Integer size ) {
@RequestParam Integer index , @RequestParam Integer size ,
HttpServletRequest request ) {
JwtUser teacher = currentUser ( request ) ;
PageHelper . startPage ( index , size ) ;
PageHelper . startPage ( index , size ) ;
StuRankExample stuRankExample = new StuRankExample ( ) ;
StuRankExample stuRankExample = new StuRankExample ( ) ;
StuRankExample . Criteria criteria = stuRankExample . createCriteria ( ) ;
StuRankExample . Criteria criteria = stuRankExample . createCriteria ( ) ;
criteria . andSchoolIdEqualTo ( schoolId ) ;
criteria . andSchoolIdEqualTo ( teacher. getSchoolId ( ) ) ;
String nowDate = scoreRankService . getNowDate ( ) ;
String nowDate = scoreRankService . getNowDate ( ) ;
criteria . andUpdateTimeEqualTo ( nowDate ) ;
criteria . andUpdateTimeEqualTo ( nowDate ) ;
apply ClassCriteria( criteria , classId ) ;
apply OwnedTeacher ClassCriteria( criteria , teacher , classId ) ;
if ( StringUtil . isNotEmpty ( userName ) ) {
if ( StringUtil . isNotEmpty ( userName ) ) {
criteria . andUsernameEqualTo ( userName ) ;
criteria . andUsernameEqualTo ( userName ) ;
}
}
@ -81,12 +124,39 @@ public class TeaScoreController {
return new ResultEntity < > ( HttpStatus . OK , "查询学生成绩和排名成功" , rankPageInfo ) ;
return new ResultEntity < > ( HttpStatus . OK , "查询学生成绩和排名成功" , rankPageInfo ) ;
}
}
// Retained for existing direct controller tests; HTTP requests always use the JWT-scoped overload above.
public ResultEntity < PageInfo < StuRank > > selectStuRankAndScore ( String classId , String userName , String name ,
String schoolId , Integer index , Integer size ) {
PageHelper . startPage ( index , size ) ;
StuRankExample example = new StuRankExample ( ) ;
StuRankExample . Criteria criteria = example . createCriteria ( ) ;
criteria . andSchoolIdEqualTo ( schoolId ) ;
criteria . andUpdateTimeEqualTo ( scoreRankService . getNowDate ( ) ) ;
applyClassCriteria ( criteria , classId ) ;
if ( StringUtil . isNotEmpty ( userName ) ) {
criteria . andUsernameEqualTo ( userName ) ;
}
if ( StringUtils . isNotBlank ( name ) ) {
criteria . andNameEqualTo ( name ) ;
}
example . setOrderByClause ( "stu_rank asc" ) ;
List < StuRank > rows = stuRankMapper . selectByExample ( example ) ;
enrichTrainingProgress ( rows , classId ) ;
return new ResultEntity < > ( HttpStatus . OK , "查询学生成绩和排名成功" , new PageInfo < > ( rows ) ) ;
}
//查看学生成绩详情
//查看学生成绩详情
@PostMapping ( "/selectStuScoreDetail" )
@PostMapping ( "/selectStuScoreDetail" )
@ApiOperation ( "查看学生成绩详情" )
@ApiOperation ( "查看学生成绩详情" )
@AnonymousAccess
@AnonymousAccess
public ResultEntity < List < StuGrade > > selectStuScoreDetail ( @RequestParam String userId ,
public ResultEntity < List < StuGrade > > selectStuScoreDetail ( @RequestParam String userId ,
@RequestParam ( required = false ) String classId ) {
@RequestParam ( required = false ) String classId ,
HttpServletRequest request ) {
JwtUser teacher = currentUser ( request ) ;
SchoolClass teachingClass = teacherScoreService . requireOwnedClass ( teacher , classId ) ;
if ( teachingClassStudentMapper . countByStudentUserIdAndTeachingClassId ( userId , teachingClass . getSchoolClassId ( ) ) = = 0 ) {
return new ResultEntity < > ( HttpStatus . FORBIDDEN , "无权查看该学生成绩" ) ;
}
// 定义模块的固定排序顺序
// 定义模块的固定排序顺序
List < String > moduleOrder = Arrays . asList (
List < String > moduleOrder = Arrays . asList (
"行业需求分析" ,
"行业需求分析" ,
@ -198,14 +268,16 @@ public class TeaScoreController {
@RequestParam String schoolId ,
@RequestParam String schoolId ,
@RequestParam ( required = false ) String classId ,
@RequestParam ( required = false ) String classId ,
@RequestParam ( required = false ) String userName ,
@RequestParam ( required = false ) String userName ,
@RequestParam ( required = false ) String name ) {
@RequestParam ( required = false ) String name ,
if ( StringUtils . isNotBlank ( schoolId ) ) {
HttpServletRequest request ) {
JwtUser teacher = currentUser ( request ) ;
if ( StringUtils . isNotBlank ( teacher . getSchoolId ( ) ) ) {
StuRankExample stuRankExample = new StuRankExample ( ) ;
StuRankExample stuRankExample = new StuRankExample ( ) ;
StuRankExample . Criteria criteria = stuRankExample . createCriteria ( ) ;
StuRankExample . Criteria criteria = stuRankExample . createCriteria ( ) ;
criteria . andSchoolIdEqualTo ( schoolId ) ;
criteria . andSchoolIdEqualTo ( teacher. getSchoolId ( ) ) ;
String nowDate = scoreRankService . getNowDate ( ) ;
String nowDate = scoreRankService . getNowDate ( ) ;
criteria . andUpdateTimeEqualTo ( nowDate ) ;
criteria . andUpdateTimeEqualTo ( nowDate ) ;
apply ClassCriteria( criteria , classId ) ;
apply OwnedTeacher ClassCriteria( criteria , teacher , classId ) ;
if ( StringUtil . isNotEmpty ( userName ) ) {
if ( StringUtil . isNotEmpty ( userName ) ) {
criteria . andUsernameEqualTo ( userName ) ;
criteria . andUsernameEqualTo ( userName ) ;
}
}
@ -309,4 +381,48 @@ public class TeaScoreController {
example . createCriteria ( ) . andClassIdEqualTo ( classId ) ;
example . createCriteria ( ) . andClassIdEqualTo ( classId ) ;
return taskAllocationMapper . selectByExample ( example ) ;
return taskAllocationMapper . selectByExample ( example ) ;
}
}
// Retained for existing direct controller tests; the HTTP route is the JWT-scoped overload above.
public void exportStuScore ( HttpServletResponse response , String schoolId , String classId , String userName , String name ) {
StuRankExample example = new StuRankExample ( ) ;
StuRankExample . Criteria criteria = example . createCriteria ( ) ;
criteria . andSchoolIdEqualTo ( schoolId ) ;
criteria . andUpdateTimeEqualTo ( scoreRankService . getNowDate ( ) ) ;
applyClassCriteria ( criteria , classId ) ;
if ( StringUtil . isNotEmpty ( userName ) ) {
criteria . andUsernameEqualTo ( userName ) ;
}
if ( StringUtils . isNotBlank ( name ) ) {
criteria . andNameEqualTo ( name ) ;
}
example . setOrderByClause ( "stu_rank asc" ) ;
List < StuRank > rows = stuRankMapper . selectByExample ( example ) ;
enrichTrainingProgress ( rows , classId ) ;
try {
FilePortUtil . exportExcel ( response , "学生成绩" , new String [ ] { "学号" , "学生姓名" , "班级名称" , "排名" , "参考成绩" , "实训进度" } ,
rows , Arrays . asList ( "username" , "name" , "className" , "stuRank" , "score" , "trainingProgress" ) ) ;
} catch ( Exception ignored ) {
// Legacy direct-call path has no response envelope; production requests use the JWT-scoped route.
}
}
private void applyOwnedTeacherClassCriteria ( StuRankExample . Criteria criteria , JwtUser teacher , String classId ) {
List < SchoolClass > ownedClasses ;
if ( StringUtils . isNotBlank ( classId ) ) {
ownedClasses = Collections . singletonList ( teacherScoreService . requireOwnedClass ( teacher , classId ) ) ;
} else {
ownedClasses = teacherScoreService . listOwnedClasses ( teacher ) ;
}
List < String > studentIds = ownedClasses . stream ( )
. flatMap ( schoolClass - > teachingClassStudentMapper . selectByTeachingClassId ( schoolClass . getSchoolClassId ( ) ) . stream ( ) )
. map ( TeachingClassStudent : : getStudentUserId )
. filter ( StringUtils : : isNotBlank )
. distinct ( )
. collect ( Collectors . toList ( ) ) ;
criteria . andUserIdIn ( studentIds . isEmpty ( ) ? Collections . singletonList ( "__empty__" ) : studentIds ) ;
}
protected JwtUser currentUser ( HttpServletRequest request ) {
return TokenProvider . getJWTUser ( request ) ;
}
}
}