2025年4月1日17:56:17
parent
a0cc238ea4
commit
f7e739b115
|
|
@ -0,0 +1,49 @@
|
|||
package com.zhangmeng.online.exam.controller;
|
||||
|
||||
import com.zhangmeng.online.exam.dao.ProfessionDao;
|
||||
import com.zhangmeng.online.exam.dto.Result;
|
||||
import com.zhangmeng.online.exam.entity.Profession;
|
||||
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/4/1 11:23
|
||||
* @version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/profession")
|
||||
public class ProfessionController {
|
||||
|
||||
@Autowired
|
||||
private ProfessionDao professionDao;
|
||||
|
||||
@RequestMapping("/list")
|
||||
public Result userList(Integer pageNum, Integer pageSize) {
|
||||
|
||||
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize, Sort.Direction.DESC, "addTime");
|
||||
Page<Profession> all = professionDao.findAll(pageable);
|
||||
List<Profession> list = all.getContent();
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
for (Profession profession : list) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", profession.getId());
|
||||
map.put("name", profession.getName());
|
||||
resultList.add(map);
|
||||
}
|
||||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
package com.zhangmeng.online.exam.controller;
|
||||
|
||||
import com.zhangmeng.online.exam.dao.QuestionDao;
|
||||
import com.zhangmeng.online.exam.dao.SubjectDao;
|
||||
import com.zhangmeng.online.exam.dto.Result;
|
||||
import com.zhangmeng.online.exam.entity.Permission;
|
||||
import com.zhangmeng.online.exam.entity.Question;
|
||||
import com.zhangmeng.online.exam.entity.Subject;
|
||||
import com.zhangmeng.online.exam.entity.User;
|
||||
import com.zhangmeng.online.exam.utils.PageUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -33,6 +35,9 @@ public class QuestionController {
|
|||
@Autowired
|
||||
private QuestionDao questionDao;
|
||||
|
||||
@Autowired
|
||||
private SubjectDao subjectDao;
|
||||
|
||||
@RequestMapping("/list")
|
||||
public Result list(Integer pageNum, Integer pageSize) {
|
||||
Pageable pageable = PageRequest.of(PageUtils.getPageNum(pageNum), pageSize);
|
||||
|
|
@ -51,6 +56,27 @@ public class QuestionController {
|
|||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||
}
|
||||
|
||||
@RequestMapping("/saveQuestion")
|
||||
public Result saveQuestion(@RequestBody @RequestParam Map<String, Object> params) {
|
||||
String id = params.get("id").toString();
|
||||
Question question = null;
|
||||
if (id.equals("0")){
|
||||
question = new Question();
|
||||
}else {
|
||||
question = questionDao.getById(Long.parseLong(id));
|
||||
}
|
||||
|
||||
question.setName((String) params.get("question"));
|
||||
question.setType(Enum.valueOf(Question.Type.class, (String) params.get("type")));
|
||||
question.setScore(Integer.parseInt((String) params.get("score")));
|
||||
question.setExplanation((String) params.get("explanation"));
|
||||
Subject subject = this.subjectDao.getById(Long.parseLong((String) params.get("subject_id")));
|
||||
question.setSubject(subject);
|
||||
questionDao.save(question);
|
||||
|
||||
return Result.success(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/delete")
|
||||
|
|
@ -59,6 +85,50 @@ public class QuestionController {
|
|||
return Result.success(null);
|
||||
}
|
||||
|
||||
@RequestMapping("/getAllQuestionType")
|
||||
public Result getAllQuestionType() {
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
for (Question.Type type : Question.Type.values()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("index", type.getIndex());
|
||||
map.put("desc", type.getDesc());
|
||||
map.put("type", type);
|
||||
resultList.add(map);
|
||||
}
|
||||
return Result.success(resultList);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/update")
|
||||
public Result update(@RequestBody @RequestParam Map<String, Object> params) {
|
||||
Question question = questionDao.getById(Long.parseLong((String) params.get("id")));
|
||||
String fieldName = (String) params.get("fieldName");
|
||||
String oldValue = (String) params.get("oldValue");
|
||||
String newValue = (String) params.get("newValue");
|
||||
|
||||
if (fieldName.equals("name")){
|
||||
question.setName(newValue);
|
||||
}
|
||||
if (fieldName.equals("score")){
|
||||
question.setScore(Integer.parseInt(newValue));
|
||||
}
|
||||
if (fieldName.equals("explanation")){
|
||||
question.setExplanation(newValue);
|
||||
}
|
||||
questionDao.save(question);
|
||||
return Result.success(null);
|
||||
}
|
||||
|
||||
@RequestMapping("/getQuestionById")
|
||||
public Result getQuestionById(Long id) {
|
||||
Question question = questionDao.getById(id);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", question.getId());
|
||||
map.put("name", question.getName());
|
||||
map.put("type", question.getType().getDesc());
|
||||
map.put("subject", question.getSubject().getName());
|
||||
map.put("score", question.getScore());
|
||||
map.put("explanation", question.getExplanation());
|
||||
return Result.success(map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.zhangmeng.online.exam.controller;
|
|||
|
||||
import com.zhangmeng.online.exam.dao.SubjectDao;
|
||||
import com.zhangmeng.online.exam.dto.Result;
|
||||
import com.zhangmeng.online.exam.entity.Question;
|
||||
import com.zhangmeng.online.exam.entity.Subject;
|
||||
import com.zhangmeng.online.exam.entity.User;
|
||||
import com.zhangmeng.online.exam.utils.PageUtils;
|
||||
|
|
@ -48,4 +49,23 @@ public class SubjectController {
|
|||
return Result.success(pageNum, pageSize, all.getTotalElements(), resultList);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/getALLSubjectType")
|
||||
public Result getALLSubjectType() {
|
||||
|
||||
List<Subject> all = this.subjectDao.findAll();
|
||||
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
for (Subject subject : all) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", subject.getId());
|
||||
map.put("name", subject.getName());
|
||||
map.put("code", subject.getCode());
|
||||
map.put("desc",subject.getDescription());
|
||||
// map.put("profession",subject.getProfession().getName());
|
||||
resultList.add(map);
|
||||
}
|
||||
|
||||
return Result.success(resultList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue