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 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 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 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 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> 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 p = sentenceArticleService.select(page, size, chapter, part); List 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 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 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 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 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> listQuestion( @RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "100") int size, HttpSession session) { Page p = sentenceQuestionService.select(page, size); List 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> 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 p; if (ids != null && ids.length > 0){ p = sentenceQuestionService.select(ids); }else{ p = sentenceQuestionService.searchAdmin(page, size, keyword); } List 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 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 autoPaperStatus(HttpServletRequest request) { // 判断当前组卷状态 Setting setting = settingService.getByKey(SettingKey.SENTENCE_PAPER_STATUS); JSONObject status = setting.getValue(); return ResponseHelp.success(status); } }