完成根据学生id查询班级id接口、根据班级id查询作业题目相关字段接口;学生端作业查询列表界面基本完成,剩作业状态栏查询未完成;
This commit is contained in:
parent
4e7fa68ddf
commit
a4ca782ccc
|
|
@ -24,6 +24,6 @@ export default {
|
||||||
|
|
||||||
|
|
||||||
//作业题目部分
|
//作业题目部分
|
||||||
getExamList: (data) =>request.post('/problem/getExamList')//学生获取作业列表
|
getExamList: (config) =>request.get('/problem/getExamList',config)//学生获取作业列表
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,18 @@ export function formatDateTimeNoSecond(time = undefined, format = 'YYYY-MM-DD HH
|
||||||
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
|
export function formatDate(date = undefined, format = 'YYYY-MM-DD') {
|
||||||
return formatDateTime(date, format)
|
return formatDateTime(date, format)
|
||||||
}
|
}
|
||||||
|
export function formatTimestamp(timestamp){
|
||||||
|
if (timestamp) {
|
||||||
|
const date = new Date(timestamp);
|
||||||
|
return date.getFullYear() + '-' +
|
||||||
|
('0' + (date.getMonth() + 1)).slice(-2) + '-' +
|
||||||
|
('0' + date.getDate()).slice(-2) + ' ' +
|
||||||
|
('0' + date.getHours()).slice(-2) + ':' +
|
||||||
|
('0' + date.getMinutes()).slice(-2) + ':' +
|
||||||
|
('0' + date.getSeconds()).slice(-2);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @desc 函数节流
|
* @desc 函数节流
|
||||||
* @param {Function} fn
|
* @param {Function} fn
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
import api from '@/api/user'
|
import api from '@/api/user'
|
||||||
import ExamActions from './components/exam-actions.vue'
|
import ExamActions from './components/exam-actions.vue'
|
||||||
import { formatDateTime, getToken } from '@/utils'
|
import {formatTimestamp, getToken} from '@/utils'
|
||||||
import { useUserStore } from '@/store'
|
import { useUserStore } from '@/store'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useCountdown } from '@/composables'
|
import { useCountdown } from '@/composables'
|
||||||
|
|
@ -92,7 +92,7 @@ const onViewScore = (exam) => {//点击成绩控件的逻辑
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
key: 'name',
|
key: 'title',
|
||||||
title: '作业名称',
|
title: '作业名称',
|
||||||
fixed: 'left',
|
fixed: 'left',
|
||||||
width: 150,
|
width: 150,
|
||||||
|
|
@ -101,23 +101,24 @@ const columns = [
|
||||||
{
|
{
|
||||||
key: 'description',
|
key: 'description',
|
||||||
title: '描述信息',
|
title: '描述信息',
|
||||||
|
align: 'center',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'starttime',
|
key: 'startTime',
|
||||||
title: '开始时间',
|
title: '开始时间',
|
||||||
width: '108',
|
width: '108',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return row['starttime'] ? formatDateTime(row['starttime']) : ''
|
return row['startTime'] ? formatTimestamp(row['startTime']) : ''
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'endtime',
|
key: 'endTime',
|
||||||
title: '结束时间',
|
title: '结束时间',
|
||||||
width: '108',
|
width: '108',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (row) => {
|
render: (row) => {
|
||||||
return row['endtime'] ? formatDateTime(row['endtime']) : ''
|
return row['endTime'] ? formatTimestamp(row['endTime']) : ''
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -125,6 +126,7 @@ const columns = [
|
||||||
key: 'status',
|
key: 'status',
|
||||||
title: '状态',
|
title: '状态',
|
||||||
width: '116',
|
width: '116',
|
||||||
|
align: 'center',
|
||||||
render: (row, idx) => {
|
render: (row, idx) => {
|
||||||
if (countdownControllers[row.id]) {
|
if (countdownControllers[row.id]) {
|
||||||
const { leftTime, minute, second } = countdownControllers[row.id]
|
const { leftTime, minute, second } = countdownControllers[row.id]
|
||||||
|
|
@ -151,8 +153,8 @@ const columns = [
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
const queryByPage = async (currentPage) => {
|
const queryByPage = async (currentPage) => {
|
||||||
|
|
@ -163,8 +165,7 @@ const queryByPage = async (currentPage) => {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await api.getExamList({
|
const res = await api.getExamList({
|
||||||
pageNum: currentPage,
|
params: { pageNum: currentPage, pageSize: paginationReactive.pageSize },
|
||||||
pageSize: paginationReactive.pageSize,
|
|
||||||
})
|
})
|
||||||
examList.value = res.data // 假设返回的数据在 res.data 中
|
examList.value = res.data // 假设返回的数据在 res.data 中
|
||||||
const { pageNum, pageSize, total, list } = res.data
|
const { pageNum, pageSize, total, list } = res.data
|
||||||
|
|
@ -217,7 +218,4 @@ onBeforeUnmount(() => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,12 @@ public class HttpInterceptorConfig extends WebMvcConfigurationSupport {
|
||||||
.excludePathPatterns("/api/login/student","/api/login/admin","/api/login","/api/user/signUser",
|
.excludePathPatterns("/api/login/student","/api/login/admin","/api/login","/api/user/signUser",
|
||||||
"/api/user" +
|
"/api/user" +
|
||||||
"/findStudentByusername","/api/user/findStudentByStudentNo","/api/adminusers/findAdminuserByno","/api/adminusers/findAdminuserByAccountInRePwInfo",
|
"/findStudentByusername","/api/user/findStudentByStudentNo","/api/adminusers/findAdminuserByno","/api/adminusers/findAdminuserByAccountInRePwInfo",
|
||||||
|
"/api/problem/getExamList",
|
||||||
"/api/adminusers" +
|
"/api/adminusers" +
|
||||||
"/signTeacher",
|
"/signTeacher",
|
||||||
"/api/adminusers" +
|
"/api/adminusers" +
|
||||||
"/confirmQuestionAnswer","/api/adminusers/updatePasswordByAccount","/api/adminusers/findAdminuserByAccount");
|
"/confirmQuestionAnswer","/api/adminusers/updatePasswordByAccount","/api/adminusers/findAdminuserByAccount"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,12 @@ public class ProblemController {
|
||||||
public RespBean getExamList(Integer pageNum,Integer pageSize, HttpServletRequest request) {
|
public RespBean getExamList(Integer pageNum,Integer pageSize, HttpServletRequest request) {
|
||||||
if (pageNum < 1 || pageSize < 1)
|
if (pageNum < 1 || pageSize < 1)
|
||||||
return RespBean.error("参数错误!");
|
return RespBean.error("参数错误!");
|
||||||
|
PMProblem pMproblem = new PMProblem();
|
||||||
// PMProblem pMproblem = new PMProblem();
|
pMproblem.setPageNum(pageNum);
|
||||||
// pMproblem.setPageNum(pageNum);
|
pMproblem.setPageSize(pageSize);
|
||||||
// pMproblem.setPageSize(pageSize);
|
|
||||||
|
|
||||||
DecodeToken decodeToken = new DecodeToken(request);
|
DecodeToken decodeToken = new DecodeToken(request);
|
||||||
String userId = decodeToken.getUserId();
|
String userId = decodeToken.getUserId();
|
||||||
|
pMproblem.setStudentId(Integer.parseInt(userId));
|
||||||
|
|
||||||
// 根据学生id查找班级id
|
// 根据学生id查找班级id
|
||||||
List<Classstudents> classstudentsList = classesServiceI.findClassIdByStudentId(Integer.parseInt(userId));
|
List<Classstudents> classstudentsList = classesServiceI.findClassIdByStudentId(Integer.parseInt(userId));
|
||||||
|
|
@ -67,10 +66,12 @@ public class ProblemController {
|
||||||
classIds.add(classstudent.getClassId());
|
classIds.add(classstudent.getClassId());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PMProblem> pMproblems = problemServiceI.getProblemsByClassIds(classIds);
|
List<PMProblem> pMproblems = problemServiceI.getProblemsByClassIds(classIds);//根据班级id查询所有作业
|
||||||
|
//分页处理,左为已有的作业列表,右为从前端获取的作业类,包含分页信息
|
||||||
|
DataGrid dataGrid = problemServiceI.dataGrid(pMproblems,pMproblem);
|
||||||
|
|
||||||
if (pMproblems != null) {
|
if (dataGrid != null) {
|
||||||
return RespBean.ok("获取作业列表成功!",pMproblems);
|
return RespBean.ok("获取作业列表成功!",dataGrid);
|
||||||
} else {
|
} else {
|
||||||
return RespBean.error("获取作业列表失败!");
|
return RespBean.error("获取作业列表失败!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Repository("ProblemDao")
|
@Repository("ProblemDao")
|
||||||
|
|
@ -21,25 +22,34 @@ public class ProblemDaoImpl extends BaseDaoImpl<Problem> implements ProblemDaoI{
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PMProblem> findProblemsByClassIds(List<Integer> classIds){
|
public List<PMProblem> findProblemsByClassIds(List<Integer> classIds) {
|
||||||
// SQL查询,根据classIds获取problemId, startTime, endTime
|
// 检查classIds是否为空或没有元素
|
||||||
String sql = "SELECT p.problem_id AS problemId, pp.start_time AS startTime, pp.end_time AS endTime " +
|
if (classIds == null || classIds.isEmpty()) {
|
||||||
"FROM postproblem pp " +
|
return Collections.emptyList();
|
||||||
"JOIN problem p ON pp.problem_id = p.id " +
|
}
|
||||||
"WHERE pp.class_id IN (?)";
|
|
||||||
|
|
||||||
// 将classIds转换为逗号分隔的字符串
|
String sql = "SELECT pr.id AS Id, pp.startTime AS startTime, pp.endTime AS endTime, " +
|
||||||
String classIdsStr = classIds.toString().replace("[", "").replace("]", "");
|
"pr.title AS title, pr.description AS description " +
|
||||||
|
"FROM postproblem pp " +
|
||||||
|
"JOIN problem pr ON pp.problemId = pr.id " +
|
||||||
|
"WHERE pp.classId IN (?)";
|
||||||
|
|
||||||
|
// 将classIds转换为逗号分隔的字符串,并用问号替换,因为jdbcTemplate会处理参数绑定
|
||||||
|
String inSql = String.join(",", Collections.nCopies(classIds.size(), "?"));
|
||||||
|
|
||||||
|
// 替换SQL中的问号
|
||||||
|
sql = sql.replace("(?)", "(" + inSql + ")");
|
||||||
|
|
||||||
// 执行查询
|
// 执行查询
|
||||||
List<PMProblem> problems = jdbcTemplate.query(
|
List<PMProblem> problems = jdbcTemplate.query(
|
||||||
sql,
|
sql,
|
||||||
new Object[]{classIdsStr},
|
classIds.toArray(), // 将List转换为数组,因为jdbcTemplate.query接受数组或可变参数
|
||||||
new BeanPropertyRowMapper<>(PMProblem.class)
|
new BeanPropertyRowMapper<>(PMProblem.class)
|
||||||
);
|
);
|
||||||
|
|
||||||
return problems;
|
return problems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addScoringRubric(PMScoringRubric pmScoringRubric){
|
public void addScoringRubric(PMScoringRubric pmScoringRubric){
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.example.aes.problem.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataGrid implements java.io.Serializable {//用于实现分页类
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1538274527426L;
|
||||||
|
|
||||||
|
// 总的记录行数
|
||||||
|
// private long totalLines;
|
||||||
|
private long total; // 原totalLines
|
||||||
|
|
||||||
|
// 总的页数
|
||||||
|
@JsonIgnore
|
||||||
|
private long totalPages;
|
||||||
|
|
||||||
|
// 每页显示多少行
|
||||||
|
// private long pageLines;
|
||||||
|
|
||||||
|
// 每页显示的行数
|
||||||
|
private long pageSize;
|
||||||
|
// 当前所在页
|
||||||
|
private long pageNum;
|
||||||
|
|
||||||
|
// 当前页的数据行数量,只有在最后一页时会和每页显示多少行可能不同
|
||||||
|
@JsonIgnore
|
||||||
|
private long currentPageLineNum;
|
||||||
|
|
||||||
|
// 当前页的所有数据行
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
// private List<?> rows = new ArrayList();
|
||||||
|
private List<?> list = new ArrayList(); // 原rows
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,7 @@ public class PMProblem extends Problem implements java.io.Serializable{//继承P
|
||||||
private String status;//最后在页面显示的状态,取决于上面三个参数。
|
private String status;//最后在页面显示的状态,取决于上面三个参数。
|
||||||
|
|
||||||
//(作业列表)页面需要的后台数据
|
//(作业列表)页面需要的后台数据
|
||||||
private int studentId;//学生id
|
private Integer studentId;//学生id
|
||||||
private int classId;//班级id
|
private int classId;//班级id
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.example.aes.problem.model.PMScoringRubric;
|
||||||
import com.example.aes.problem.model.ScoringRubric;
|
import com.example.aes.problem.model.ScoringRubric;
|
||||||
import com.example.aes.problem.model.UScoringRubric;
|
import com.example.aes.problem.model.UScoringRubric;
|
||||||
import com.example.aes.problem.service.ProblemServiceI;
|
import com.example.aes.problem.service.ProblemServiceI;
|
||||||
|
import com.example.aes.user.model.Classstudents;
|
||||||
import com.example.aes.user.model.Course;
|
import com.example.aes.user.model.Course;
|
||||||
import com.example.aes.user.model.DataGrid;
|
import com.example.aes.user.model.DataGrid;
|
||||||
import com.example.aes.user.model.PMCourse;
|
import com.example.aes.user.model.PMCourse;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@Service
|
@Service
|
||||||
public class ProblemServiceImpl implements ProblemServiceI {
|
public class ProblemServiceImpl implements ProblemServiceI {
|
||||||
|
|
@ -53,7 +55,56 @@ public class ProblemServiceImpl implements ProblemServiceI {
|
||||||
return uScoringRubricList;
|
return uScoringRubricList;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataGrid dataGrid(List<PMProblem> pMproblems, PMProblem pMproblem) {
|
||||||
|
DataGrid dg = new DataGrid();
|
||||||
|
long totalLines;// 总记录行数
|
||||||
|
List<PMProblem> pagedPMProblems;
|
||||||
|
|
||||||
|
// 设置总记录行数
|
||||||
|
totalLines = (long) pMproblems.size();
|
||||||
|
|
||||||
|
// 计算分页信息
|
||||||
|
int pageSize = pMproblem.getPageSize();
|
||||||
|
int pageNum = pMproblem.getPageNum();
|
||||||
|
int fromIndex = (pageNum - 1) * pageSize;
|
||||||
|
int toIndex = fromIndex + pageSize;
|
||||||
|
|
||||||
|
// 对问题列表进行分页处理
|
||||||
|
if (fromIndex < pMproblems.size()) {
|
||||||
|
if (toIndex > pMproblems.size()) {
|
||||||
|
toIndex = pMproblems.size();
|
||||||
|
}
|
||||||
|
pagedPMProblems = pMproblems.subList(fromIndex, toIndex);
|
||||||
|
} else {
|
||||||
|
pagedPMProblems = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果分页后的列表为空
|
||||||
|
if (pagedPMProblems.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
// 这里可以添加额外的处理逻辑,比如设置每个 PMProblem 的额外属性
|
||||||
|
|
||||||
|
// 设置总的记录行数
|
||||||
|
dg.setTotal(totalLines);
|
||||||
|
// 设置每页显示多少行
|
||||||
|
dg.setPageSize(pageSize);
|
||||||
|
// 设置总的页数,总页数 = (总行数 / 每页显示多少行) 向上取整
|
||||||
|
dg.setTotalPages((long) Math.ceil((double) totalLines / (double) pageSize));
|
||||||
|
// 设置当前显示第几页
|
||||||
|
dg.setPageNum(pageNum);
|
||||||
|
// 设置当前页的数据行数量
|
||||||
|
dg.setCurrentPageLineNum(pagedPMProblems.size());
|
||||||
|
// 设置当前页的所有数据行
|
||||||
|
dg.setList(pagedPMProblems);
|
||||||
|
return dg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
private void changeModel1(List<ScoringRubric> l,
|
private void changeModel1(List<ScoringRubric> l,
|
||||||
List<PMScoringRubric> nl) {
|
List<PMScoringRubric> nl) {
|
||||||
if (l != null && l.size() > 0) {
|
if (l != null && l.size() > 0) {
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,5 @@ public interface ProblemServiceI {
|
||||||
public void addScoringRubric(PMScoringRubric pmscoringRubric);
|
public void addScoringRubric(PMScoringRubric pmscoringRubric);
|
||||||
public List<UScoringRubric> findScoringRubricNoStandardId();
|
public List<UScoringRubric> findScoringRubricNoStandardId();
|
||||||
|
|
||||||
|
DataGrid dataGrid(List<PMProblem> pMproblems, PMProblem pMproblem);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue