123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package com.qxgmat.controller.admin;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.PageMessage;
- import com.nuliji.tools.Response;
- import com.nuliji.tools.ResponseHelp;
- import com.nuliji.tools.Transform;
- import com.nuliji.tools.exception.ParameterException;
- import com.qxgmat.data.constants.enums.SettingKey;
- import com.qxgmat.data.dao.entity.SentenceArticle;
- import com.qxgmat.data.dao.entity.SentenceQuestion;
- import com.qxgmat.data.dao.entity.Setting;
- import com.qxgmat.data.relation.entity.SentenceQuestionRelation;
- import com.qxgmat.dto.admin.request.ExerciseStructDto;
- import com.qxgmat.dto.admin.request.SentenceQuestionDto;
- import com.qxgmat.dto.admin.response.SentenceQuestionListDto;
- import com.qxgmat.service.inline.SentencePaperService;
- import com.qxgmat.service.extend.SentenceService;
- import com.qxgmat.service.inline.*;
- import com.qxgmat.task.AsyncTask;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpSession;
- import java.util.List;
- @RestController("AdminSentenceController")
- @RequestMapping("/admin/sentence")
- public class SentenceController {
- @Autowired
- private ManagerLogService managerLogService;
- @Autowired
- private SentenceQuestionService sentenceQuestionService;
- @Autowired
- private SentencePaperService sentencePaperService;
- @Autowired
- private SentenceArticleService sentenceArticleService;
- @Autowired
- private SentenceService sentenceService;
- @Autowired
- private QuestionService questionService;
- @Autowired
- private SettingService settingService;
- @Autowired
- private AsyncTask asyncTask;
- @RequestMapping(value = "/article/add", method = RequestMethod.POST)
- @ApiOperation(value = "添加长难句文章", httpMethod = "POST")
- public Response<SentenceArticle> addArticle(@RequestBody @Validated SentenceArticle dto, HttpServletRequest request) {
- SentenceArticle entity = Transform.convert(dto, SentenceArticle.class);
- entity = sentenceArticleService.add(entity);
- managerLogService.log(request);
- return ResponseHelp.success(Transform.convert(entity, SentenceArticle.class));
- }
- @RequestMapping(value = "/article/edit", method = RequestMethod.PUT)
- @ApiOperation(value = "编辑长难句文章", httpMethod = "PUT")
- public Response<Boolean> editArticle(@RequestBody @Validated SentenceArticle dto, HttpServletRequest request) {
- SentenceArticle entity = Transform.convert(dto, SentenceArticle.class);
- entity = sentenceArticleService.edit(entity);
- managerLogService.log(request);
- return ResponseHelp.success(true);
- }
- @RequestMapping(value = "/article/delete", method = RequestMethod.DELETE)
- @ApiOperation(value = "删除长难句文章", httpMethod = "DELETE")
- public Response<Boolean> deleteArticle(@RequestParam int id, HttpServletRequest request) {
- sentenceArticleService.delete(id);
- managerLogService.log(request);
- return ResponseHelp.success(sentenceArticleService.delete(id));
- }
- @RequestMapping(value = "/article/detail", method = RequestMethod.GET)
- @ApiOperation(value = "获取长难句文章", httpMethod = "GET")
- public Response<SentenceArticle> detailArticle(@RequestParam int id,HttpSession session) {
- SentenceArticle entity = sentenceArticleService.get(id);
- return ResponseHelp.success(Transform.convert(entity, SentenceArticle.class));
- }
- @RequestMapping(value = "/article/list", method = RequestMethod.GET)
- @ApiOperation(value = "长难句文章列表", httpMethod = "GET")
- public Response<PageMessage<SentenceArticle>> listArticle(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- @RequestParam(required = false) Number chapter,
- @RequestParam(required = false) Number part,
- HttpSession session) {
- Page<SentenceArticle> p = sentenceArticleService.select(page, size, chapter, part);
- List<SentenceArticle> pr = Transform.convert(p, SentenceArticle.class);
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- @RequestMapping(value = "/question/add", method = RequestMethod.POST)
- @ApiOperation(value = "添加长难句题目", httpMethod = "POST")
- public Response<SentenceQuestion> addQuestion(@RequestBody @Validated SentenceQuestionDto dto, HttpServletRequest request) {
- SentenceQuestionRelation entity = Transform.dtoToEntity(dto);
- SentenceQuestion entityNew = sentenceService.addQuestion(entity);
- managerLogService.log(request);
- return ResponseHelp.success(entityNew);
- }
- @RequestMapping(value = "/question/edit", method = RequestMethod.PUT)
- @ApiOperation(value = "修改长难句题目", httpMethod = "PUT")
- public Response<Boolean> editQuestion(@RequestBody @Validated SentenceQuestionDto dto, HttpServletRequest request) {
- SentenceQuestionRelation entity = Transform.dtoToEntity(dto);
- sentenceService.editQuestion(entity);
- managerLogService.log(request);
- return ResponseHelp.success(true);
- }
- // @RequestMapping(value = "/question/delete", method = RequestMethod.DELETE)
- // @ApiOperation(value = "删除长难句题目", httpMethod = "DELETE")
- // public Response<Boolean> deleteQuestion(@RequestParam int id, HttpServletRequest request) {
- // managerLogService.log(request);
- // return ResponseHelp.success(sentenceQuestionService.delete(id));
- // }
- @RequestMapping(value = "/question/detail", method = RequestMethod.GET)
- @ApiOperation(value = "获取长难句题目", httpMethod = "GET")
- public Response<SentenceQuestionRelation> detailQuestion(@RequestParam int id, HttpSession session) {
- SentenceQuestion entity = sentenceQuestionService.get(id);
- SentenceQuestionRelation relation = sentenceQuestionService.relation(entity);
- return ResponseHelp.success(relation);
- }
- @RequestMapping(value = "/question/list", method = RequestMethod.GET)
- @ApiOperation(value = "长难句题目列表", httpMethod = "GET")
- public Response<PageMessage<SentenceQuestionListDto>> listQuestion(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- HttpSession session) {
- Page<SentenceQuestion> p = sentenceQuestionService.select(page, size);
- List<SentenceQuestionListDto> pr = Transform.convert(p, SentenceQuestionListDto.class);
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- @RequestMapping(value = "/question/search", method = RequestMethod.GET)
- @ApiOperation(value = "搜索长难句题目列表", httpMethod = "GET")
- public Response<PageMessage<SentenceQuestionListDto>> listQuestion(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "100") int size,
- @RequestParam(required = false) String keyword,
- @RequestParam(required = false) Integer[] ids,
- HttpSession session) {
- Page<SentenceQuestion> p;
- if (ids != null && ids.length > 0){
- p = sentenceQuestionService.select(ids);
- }else{
- p = sentenceQuestionService.searchAdmin(page, size, keyword);
- }
- List<SentenceQuestionListDto> pr = Transform.convert(p, SentenceQuestionListDto.class);
- return ResponseHelp.success(pr, page, size, p.getTotal());
- }
- @RequestMapping(value = "/paper/auto", method = RequestMethod.POST)
- @ApiOperation(value = "自动组卷", httpMethod = "POST")
- public Response<Boolean> autoPaper(@RequestBody @Validated ExerciseStructDto dto, HttpServletRequest request) {
- // 判断当前组卷状态
- Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS);
- JSONObject status = setting.getValue();
- if (status.getInteger("progress")<100){
- throw new ParameterException("组卷进行中,请稍后再试");
- }
- asyncTask.autoSentencePaper();
- return ResponseHelp.success(true);
- }
- @RequestMapping(value = "/paper/auto", method = RequestMethod.GET)
- @ApiOperation(value = "自动组卷状态", httpMethod = "GET")
- public Response<JSONObject> autoPaperStatus(HttpServletRequest request) {
- // 判断当前组卷状态
- Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS);
- JSONObject status = setting.getValue();
- return ResponseHelp.success(status);
- }
- }
|