55 lines
1.9 KiB
Java
55 lines
1.9 KiB
Java
|
|
package com.zhangmeng.online.exam.controller;
|
||
|
|
|
||
|
|
import com.zhangmeng.online.exam.dao.PaperDao;
|
||
|
|
import com.zhangmeng.online.exam.dto.Result;
|
||
|
|
import com.zhangmeng.online.exam.entity.Paper;
|
||
|
|
import com.zhangmeng.online.exam.entity.User;
|
||
|
|
import com.zhangmeng.online.exam.utils.PageUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.data.domain.Page;
|
||
|
|
import org.springframework.data.domain.PageRequest;
|
||
|
|
import org.springframework.data.domain.Pageable;
|
||
|
|
import org.springframework.data.domain.Sort;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
|
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author zm
|
||
|
|
* @date 2025/3/19 11:10
|
||
|
|
* @version: 1.0
|
||
|
|
*/
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/paper")
|
||
|
|
public class PaperController {
|
||
|
|
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private PaperDao paperDao;
|
||
|
|
|
||
|
|
@RequestMapping("/list")
|
||
|
|
public Result list(Integer pageNum, Integer pageSize) {
|
||
|
|
|
||
|
|
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize, Sort.Direction.DESC, "addTime");
|
||
|
|
Page<Paper> all = paperDao.findAll(pageable);
|
||
|
|
List<Paper> list = all.getContent();
|
||
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
||
|
|
for (Paper paper : list) {
|
||
|
|
Map<String, Object> map = new HashMap<>();
|
||
|
|
map.put("id", paper.getId());
|
||
|
|
map.put("name", paper.getName());
|
||
|
|
map.put("creator_username", paper.getCreator().getUsername());
|
||
|
|
map.put("subject_name", paper.getSubject().getName());
|
||
|
|
map.put("totalScore",paper.getTotalScore());//总分
|
||
|
|
map.put("examTime",paper.getExamTime());//考试时间
|
||
|
|
resultList.add(map);
|
||
|
|
}
|
||
|
|
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|