diff --git a/src/main/java/com/example/attendance/controller/StudentController.java b/src/main/java/com/example/attendance/controller/StudentController.java index 0cc0444..df1e891 100644 --- a/src/main/java/com/example/attendance/controller/StudentController.java +++ b/src/main/java/com/example/attendance/controller/StudentController.java @@ -47,6 +47,16 @@ public class StudentController { return ResponseEntity.ok(students); } + /** + * 获取所有学生的姓名 + * @return 学生姓名的字符串数组 + */ + @GetMapping("/names") + public ResponseEntity getAllStudentNames() { + String[] studentNames = studentService.getAllStudentNames(); + return ResponseEntity.ok(studentNames); + } + //添加学生信息 @PostMapping public ResponseEntity addStudent(@RequestBody Student student) { diff --git a/src/main/java/com/example/attendance/entity/RollCallSettings.java b/src/main/java/com/example/attendance/entity/RollCallSettings.java index 352ae8d..cec85d4 100644 --- a/src/main/java/com/example/attendance/entity/RollCallSettings.java +++ b/src/main/java/com/example/attendance/entity/RollCallSettings.java @@ -8,8 +8,8 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @Data public class RollCallSettings { - private boolean isRollCall; // 点名(true)或提问(false) - private boolean triggerRandomEvent; // 是否触发随机事件 - private boolean wheelOfFortune; // 是否开启命运轮盘 - + private String rollCallMode; // 点名("点名")或提问("提问") + private String triggerRandomEvent; // 触发("触发")或不触发("不触发")随机事件 + private String wheelOfFortune; // 开启("是")或关闭("否")命运轮盘 } + diff --git a/src/main/java/com/example/attendance/mapper/StudentMapper.java b/src/main/java/com/example/attendance/mapper/StudentMapper.java index 7249c6d..afca05a 100644 --- a/src/main/java/com/example/attendance/mapper/StudentMapper.java +++ b/src/main/java/com/example/attendance/mapper/StudentMapper.java @@ -46,4 +46,11 @@ public interface StudentMapper { */ @Select("SELECT * FROM student ORDER BY points DESC LIMIT #{size} OFFSET #{offset}") List findStudentsByRanking(@Param("offset") int offset, @Param("size") int size); + + /** + * 查询所有学生的姓名 + * @return 学生姓名的字符串数组 + */ + @Select("SELECT name FROM student") + String[] findAllStudentNames(); } diff --git a/src/main/java/com/example/attendance/service/StudentService.java b/src/main/java/com/example/attendance/service/StudentService.java index 6d5416b..ed977b7 100644 --- a/src/main/java/com/example/attendance/service/StudentService.java +++ b/src/main/java/com/example/attendance/service/StudentService.java @@ -19,4 +19,5 @@ public interface StudentService { void update(Student student); void delete(Long id); + String[] getAllStudentNames(); } diff --git a/src/main/java/com/example/attendance/service/impl/RollCallServiceImpl.java b/src/main/java/com/example/attendance/service/impl/RollCallServiceImpl.java index 2a97d9c..4a9d55f 100644 --- a/src/main/java/com/example/attendance/service/impl/RollCallServiceImpl.java +++ b/src/main/java/com/example/attendance/service/impl/RollCallServiceImpl.java @@ -6,7 +6,6 @@ import com.example.attendance.entity.Student; import com.example.attendance.service.RollCallService; import org.springframework.stereotype.Service; -import java.math.BigDecimal; import java.util.List; import java.util.Random; @@ -16,11 +15,11 @@ public class RollCallServiceImpl implements RollCallService { @Override public RollCallResponse startRollCall(List students, RollCallSettings settings) { // 1. 根据设定选择点名或提问模式 - String mode = settings.isRollCall() ? "点名" : "提问"; + String mode = "点名".equals(settings.getRollCallMode()) ? "点名" : "提问"; System.out.println("当前模式:" + mode); // 2. 处理命运轮盘 (所有人概率相等) - if (settings.isWheelOfFortune()) { + if ("是".equals(settings.getWheelOfFortune())) { return handleWheelOfFortune(students); } @@ -32,7 +31,7 @@ public class RollCallServiceImpl implements RollCallService { response.setPoints(selectedStudent.getPoints()); // 4. 判断是否触发随机事件 - if (settings.isTriggerRandomEvent()) { + if ("触发".equals(settings.getTriggerRandomEvent())) { response.setMessage("触发了随机事件: " + triggerRandomEvent()); } else { response.setMessage("没有触发随机事件," + selectedStudent.getName() + " 被点了!"); diff --git a/src/main/java/com/example/attendance/service/impl/StudentServiceImpl.java b/src/main/java/com/example/attendance/service/impl/StudentServiceImpl.java index b46f396..fa4ce1c 100644 --- a/src/main/java/com/example/attendance/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/example/attendance/service/impl/StudentServiceImpl.java @@ -98,6 +98,7 @@ public class StudentServiceImpl implements StudentService { * @param studentNumber 学生编号 * @param pointsDelta 要加或减的积分值 */ + @Override public void adjustPoints(String studentNumber, BigDecimal pointsDelta) { Student student = studentMapper.findByStudentNumber(studentNumber); if (student == null) { @@ -114,6 +115,7 @@ public class StudentServiceImpl implements StudentService { * @param size 每页显示的记录数 * @return 学生排行榜 */ + @Override public List getStudentRanking(int page, int size) { int offset = page * size; return studentMapper.findStudentsByRanking(offset, size); @@ -148,4 +150,13 @@ public class StudentServiceImpl implements StudentService { public void delete(Long id) { studentMapper.delete(id); } + + /** + * 获取所有学生的姓名 + * @return 学生姓名的字符串数组 + */ + @Override + public String[] getAllStudentNames() { + return studentMapper.findAllStudentNames(); + } } \ No newline at end of file