feat:沟通参数,进行修改

backend
poppoppuppylove 1 month ago
parent d26d8eaec7
commit 6ccc9f01f8

@ -47,6 +47,16 @@ public class StudentController {
return ResponseEntity.ok(students);
}
/**
*
* @return
*/
@GetMapping("/names")
public ResponseEntity<String[]> getAllStudentNames() {
String[] studentNames = studentService.getAllStudentNames();
return ResponseEntity.ok(studentNames);
}
//添加学生信息
@PostMapping
public ResponseEntity<String> addStudent(@RequestBody Student student) {

@ -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; // 开启("是")或关闭("否")命运轮盘
}

@ -46,4 +46,11 @@ public interface StudentMapper {
*/
@Select("SELECT * FROM student ORDER BY points DESC LIMIT #{size} OFFSET #{offset}")
List<Student> findStudentsByRanking(@Param("offset") int offset, @Param("size") int size);
/**
*
* @return
*/
@Select("SELECT name FROM student")
String[] findAllStudentNames();
}

@ -19,4 +19,5 @@ public interface StudentService {
void update(Student student);
void delete(Long id);
String[] getAllStudentNames();
}

@ -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<Student> 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() + " 被点了!");

@ -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<Student> 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();
}
}
Loading…
Cancel
Save