2025年4月11日11:55:45
parent
753e7083ba
commit
05ce87c182
|
|
@ -131,4 +131,6 @@ public class QuestionController {
|
||||||
map.put("explanation", question.getExplanation());
|
map.put("explanation", question.getExplanation());
|
||||||
return Result.success(map);
|
return Result.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,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;
|
||||||
|
|
@ -61,11 +63,80 @@ public class SubjectController {
|
||||||
map.put("id", subject.getId());
|
map.put("id", subject.getId());
|
||||||
map.put("name", subject.getName());
|
map.put("name", subject.getName());
|
||||||
map.put("code", subject.getCode());
|
map.put("code", subject.getCode());
|
||||||
map.put("desc",subject.getDescription());
|
map.put("desc", subject.getDescription());
|
||||||
// map.put("profession",subject.getProfession().getName());
|
// map.put("profession",subject.getProfession().getName());
|
||||||
resultList.add(map);
|
resultList.add(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.success(resultList);
|
return Result.success(resultList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/saveSubject")
|
||||||
|
public Result saveSubject(@RequestBody @RequestParam Map<String, Object> params) {
|
||||||
|
|
||||||
|
String id = (String) params.get("id");
|
||||||
|
String name = (String) params.get("name");
|
||||||
|
String code = (String) params.get("code");
|
||||||
|
String description = (String) params.get("desc");
|
||||||
|
|
||||||
|
Subject subject;
|
||||||
|
if (id != null && !id.isEmpty()) {
|
||||||
|
subject = this.subjectDao.findById(Long.parseLong(id)).get();
|
||||||
|
} else {
|
||||||
|
subject = new Subject();
|
||||||
|
}
|
||||||
|
subject.setName(name);
|
||||||
|
subject.setCode(code);
|
||||||
|
subject.setDescription(description);
|
||||||
|
this.subjectDao.save(subject);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/delete")
|
||||||
|
public Result delete(@RequestParam Long id) {
|
||||||
|
this.subjectDao.deleteById(id);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/getSubjectById")
|
||||||
|
public Result getSubjectById(@RequestParam Long id) {
|
||||||
|
Subject subject = this.subjectDao.findById(id).get();
|
||||||
|
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());
|
||||||
|
return Result.success(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/getSubjectByCode")
|
||||||
|
public Result getSubjectByCode(@RequestParam String code) {
|
||||||
|
Subject subject = this.subjectDao.findByCode(code);
|
||||||
|
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());
|
||||||
|
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();
|
||||||
|
|
||||||
|
Subject subject = subjectDao.findById(Long.parseLong(id)).get();
|
||||||
|
|
||||||
|
switch (fieldName) {
|
||||||
|
case "name" -> subject.setName(newValue);
|
||||||
|
case "code" -> subject.setCode(newValue);
|
||||||
|
case "description" -> subject.setDescription(newValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
subjectDao.save(subject);
|
||||||
|
return Result.success(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue