123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- package com.qmth.themis.backend.api;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import javax.annotation.Resource;
- import com.qmth.themis.business.util.ServletUtil;
- import org.springframework.dao.DuplicateKeyException;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.qmth.themis.business.config.SystemConfig;
- import com.qmth.themis.business.constant.SystemConstant;
- import com.qmth.themis.business.entity.TBAttachment;
- import com.qmth.themis.business.entity.TBTaskHistory;
- import com.qmth.themis.business.entity.TBUser;
- import com.qmth.themis.business.entity.TEExam;
- import com.qmth.themis.business.entity.TEExamPaper;
- import com.qmth.themis.business.enums.FieldUniqueEnum;
- import com.qmth.themis.business.enums.MqEnum;
- import com.qmth.themis.business.enums.TaskStatusEnum;
- import com.qmth.themis.business.enums.TaskTypeEnum;
- import com.qmth.themis.business.service.TBAttachmentService;
- import com.qmth.themis.business.service.TBTaskHistoryService;
- import com.qmth.themis.business.service.TEExamPaperService;
- import com.qmth.themis.business.service.TEExamService;
- import com.qmth.themis.business.util.JacksonUtil;
- import com.qmth.themis.common.contanst.Constants;
- import com.qmth.themis.common.enums.ExceptionResultEnum;
- import com.qmth.themis.common.exception.BusinessException;
- import com.qmth.themis.common.util.Result;
- import com.qmth.themis.common.util.ResultUtil;
- import com.qmth.themis.mq.dto.MqDto;
- import com.qmth.themis.mq.enums.MqTagEnum;
- import com.qmth.themis.mq.enums.MqTopicEnum;
- import com.qmth.themis.mq.service.MqDtoService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import io.swagger.annotations.ApiResponse;
- import io.swagger.annotations.ApiResponses;
- @Api(tags = "考试试卷Controller")
- @RestController
- @RequestMapping("/${prefix.url.admin}/paper")
- public class TEExamPaperController {
- @Resource
- TEExamPaperService teExamPaperService;
- @Resource
- TBTaskHistoryService taskHistoryService;
- @Resource
- TEExamService teExamService;
- @Resource
- TBAttachmentService tbAttachmentService;
- @Resource
- MqDtoService mqDtoService;
- @Resource
- SystemConfig systemConfig;
- @ApiOperation(value = "考试试卷查询接口")
- @RequestMapping(value = "/query", method = RequestMethod.POST)
- @ApiResponses({@ApiResponse(code = 200, message = "考试科目信息", response = TEExamPaper.class)})
- public Result query(@ApiParam(value = "考试批次id", required = true) @RequestParam Long examId, @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode) {
- if (Objects.isNull(examId) || Objects.equals(examId, "")) {
- throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
- }
- if (Objects.isNull(courseCode) || Objects.equals(courseCode, "")) {
- throw new BusinessException(ExceptionResultEnum.COURSE_CODE_IS_NULL);
- }
- QueryWrapper<TEExamPaper> teExamPaperQueryWrapper = new QueryWrapper<>();
- teExamPaperQueryWrapper.lambda().eq(TEExamPaper::getExamId, examId).eq(TEExamPaper::getCourseCode, courseCode);
- List<TEExamPaper> teExamPaperList = teExamPaperService.list(teExamPaperQueryWrapper);
- Map<String, List<TEExamPaper>> map = new HashMap<String, List<TEExamPaper>>();
- map.put(SystemConstant.RECORDS, teExamPaperList);
- return ResultUtil.ok(map);
- }
- @ApiOperation(value = "考试试卷参数修改接口")
- @RequestMapping(value = "/save", method = RequestMethod.POST)
- @Transactional
- @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
- public Result save(@ApiParam(value = "考试试卷信息", required = true) @RequestBody List<TEExamPaper> teExamPaperList) {
- if (Objects.isNull(teExamPaperList) || teExamPaperList.size() == 0) {
- throw new BusinessException(ExceptionResultEnum.PAPER_INFO_IS_NULL);
- }
- try {
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
- teExamPaperList.forEach(s -> {
- if (Objects.nonNull(s.getId())) {
- s.setUpdateId(tbUser.getId());
- } else {
- s.setId(Constants.idGen.next());
- s.setCreateId(tbUser.getId());
- }
- });
- teExamPaperService.saveOrUpdateBatch(teExamPaperList);
- } catch (Exception e) {
- e.printStackTrace();
- if (e instanceof DuplicateKeyException) {
- String errorColumn = e.getCause().toString();
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
- throw new BusinessException("机构id[" + teExamPaperList.get(0).getExamId() + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
- } else if (e instanceof BusinessException) {
- throw new BusinessException(e.getMessage());
- } else {
- throw new RuntimeException(e);
- }
- }
- return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
- }
- @ApiOperation(value = "考试试卷数据包上传接口")
- @RequestMapping(value = "/import", method = RequestMethod.POST)
- @Transactional
- @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0}", response = Result.class)})
- public Result importData(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file
- , @ApiParam(value = "批次ID", required = true) @RequestParam Long examId
- , @ApiParam(value = "客观题乱序", required = false) @RequestParam Boolean objectiveShuffle
- , @ApiParam(value = "选项乱序", required = false) @RequestParam Boolean optionShuffle
- , @ApiParam(value = "音频播放次数", required = false) @RequestParam Integer audioPlayCount
- ,@ApiParam(value = "解析试卷", required = true) @RequestParam Boolean processPaper
- ,@ApiParam(value = "解析标答", required = true) @RequestParam Boolean processAnswer) {
- if (file == null) {
- throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
- }
- if (examId == null) {
- throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
- }
- Map<String, Object> mapParameter = systemConfig.getOssEnv(3);
- TBAttachment tbAttachment = null;
- TBTaskHistory tbTaskHistory = null;
- Map<String, Object> transMap = new HashMap<String, Object>();
- try {
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
- tbAttachment = tbAttachmentService.saveAttachment(file, ServletUtil.getRequestMd5(), ServletUtil.getRequestPath(), mapParameter, tbUser.getOrgId(), tbUser.getId());
- if (Objects.isNull(tbAttachment)) {
- throw new BusinessException(ExceptionResultEnum.ATTACHMENT_ERROR);
- } else {
-
- tbTaskHistory = new TBTaskHistory(TaskTypeEnum.IMPORT_EXAM_PAPER, tbAttachment.getId(), TaskStatusEnum.INIT, SystemConstant.IMPORT_INIT, 0d, tbAttachment.getName(), tbAttachment.getRemark(), tbUser.getId());
- taskHistoryService.save(tbTaskHistory);
- transMap.put("tbTaskHistory", tbTaskHistory);
- }
- transMap.put("examId", examId);
- transMap.put("createId", tbUser.getId());
-
- TEExam teExam = teExamService.getById(examId);
- if (Objects.isNull(teExam)) {
- throw new BusinessException(ExceptionResultEnum.EXAM_NO);
- }
- transMap.put("objectiveShuffle", objectiveShuffle);
- transMap.put("optionShuffle", optionShuffle);
- transMap.put("audioPlayCount", audioPlayCount);
- transMap.put("processPaper", processPaper);
- transMap.put("processAnswer", processAnswer);
- transMap.put("remark", tbAttachment.getRemark());
-
- MqDto mqDto = new MqDto(MqTopicEnum.themisTopic.getCode(), MqTagEnum.examPaperImport.name(), transMap, MqEnum.TASK_LOG, String.valueOf(tbTaskHistory.getId()), tbUser.getName());
- mqDtoService.assembleSendOneWayMsg(mqDto);
-
- } catch (Exception e) {
- if (Objects.nonNull(tbAttachment)) {
- tbAttachmentService.deleteAttachment(mapParameter, tbAttachment);
- }
- if (e instanceof BusinessException) {
- throw new BusinessException(e.getMessage());
- } else {
- throw new RuntimeException(e);
- }
- }
- Map<String, Long> map = new HashMap<String, Long>();
- map.put(SystemConstant.TASK_ID, tbTaskHistory.getId());
- return ResultUtil.ok(map);
- }
- }
|