2025年4月11日14:53:46
parent
05ce87c182
commit
ea52f361a3
|
|
@ -10,7 +10,9 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -32,7 +34,7 @@ public class QuestionOptionController {
|
||||||
|
|
||||||
@RequestMapping("/list")
|
@RequestMapping("/list")
|
||||||
public Result list(Integer pageNum, Integer pageSize) {
|
public Result list(Integer pageNum, Integer pageSize) {
|
||||||
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize);
|
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize, Sort.by(Sort.Direction.DESC, "id"));
|
||||||
Page<QuestionOption> all = questionOptionDao.findAll(pageable);
|
Page<QuestionOption> all = questionOptionDao.findAll(pageable);
|
||||||
List<QuestionOption> list = all.getContent();
|
List<QuestionOption> list = all.getContent();
|
||||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||||
|
|
@ -43,10 +45,86 @@ public class QuestionOptionController {
|
||||||
map.put("optionContent", option.getOptionContent());
|
map.put("optionContent", option.getOptionContent());
|
||||||
map.put("isAnswer", option.getIsAnswer());
|
map.put("isAnswer", option.getIsAnswer());
|
||||||
map.put("addTime", option.getAddTime());
|
map.put("addTime", option.getAddTime());
|
||||||
map.put("explanation",option.getExplanation());
|
map.put("explanation", option.getExplanation());
|
||||||
resultList.add(map);
|
resultList.add(map);
|
||||||
}
|
}
|
||||||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/delete")
|
||||||
|
public Result delete(Long id) {
|
||||||
|
|
||||||
|
QuestionOption questionOption = questionOptionDao.getById(id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
questionOptionDao.deleteById(id);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/save")
|
||||||
|
public Result save(@RequestBody @RequestParam Map<String, Object> params) {
|
||||||
|
|
||||||
|
String id = params.get("id").toString();
|
||||||
|
String name = params.get("name").toString();
|
||||||
|
String content = params.get("content").toString();
|
||||||
|
String isFlag = params.get("isFlag").toString();
|
||||||
|
String explanation = params.get("explanation").toString();
|
||||||
|
QuestionOption option;
|
||||||
|
if (id != null && !id.isEmpty()) {
|
||||||
|
option = questionOptionDao.findById(Long.parseLong(id)).get();
|
||||||
|
} else {
|
||||||
|
option = new QuestionOption();
|
||||||
|
}
|
||||||
|
option.setOptionName(name);
|
||||||
|
option.setOptionContent(content);
|
||||||
|
option.setIsAnswer(Boolean.parseBoolean(isFlag));
|
||||||
|
option.setExplanation(explanation);
|
||||||
|
questionOptionDao.save(option);
|
||||||
|
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("/getQuestionOptionById")
|
||||||
|
public Result getQuestionOptionById(Long id) {
|
||||||
|
QuestionOption option = questionOptionDao.findById(id).get();
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("id", option.getId());
|
||||||
|
map.put("name", option.getOptionName());
|
||||||
|
map.put("optionContent", option.getOptionContent());
|
||||||
|
map.put("isAnswer", option.getIsAnswer());
|
||||||
|
map.put("addTime", option.getAddTime());
|
||||||
|
map.put("explanation", option.getExplanation());
|
||||||
|
return Result.success(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/update")
|
||||||
|
public Result update(@RequestBody @RequestParam Map<String, Object> params) {
|
||||||
|
String id = params.get("id").toString();
|
||||||
|
String fieldName = params.get("fieldName").toString();
|
||||||
|
String oldValue = params.get("oldValue").toString();
|
||||||
|
String newValue = params.get("newValue").toString();
|
||||||
|
|
||||||
|
QuestionOption option = questionOptionDao.findById(Long.parseLong(id)).get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* map.put("id", option.getId());
|
||||||
|
* map.put("name", option.getOptionName());
|
||||||
|
* map.put("optionContent", option.getOptionContent());
|
||||||
|
* map.put("isAnswer", option.getIsAnswer());
|
||||||
|
* map.put("addTime", option.getAddTime());
|
||||||
|
* map.put("explanation", option.getExplanation());
|
||||||
|
*/
|
||||||
|
|
||||||
|
switch (fieldName) {
|
||||||
|
case "name" -> option.setOptionName(newValue);
|
||||||
|
case "optionContent" -> option.setOptionContent(newValue);
|
||||||
|
case "isAnswer" -> option.setIsAnswer(Boolean.valueOf(newValue));
|
||||||
|
case "explanation" -> option.setExplanation(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
questionOptionDao.save(option);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue