|
@@ -2,25 +2,34 @@ package com.qmth.themis.backend.api;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.qmth.themis.backend.constant.BackendConstant;
|
|
|
import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.annotation.ApiJsonObject;
|
|
|
import com.qmth.themis.business.annotation.ApiJsonProperty;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TBAttachment;
|
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
import com.qmth.themis.business.entity.TEExamStudent;
|
|
|
+import com.qmth.themis.business.service.TBAttachmentService;
|
|
|
import com.qmth.themis.business.service.TEExamStudentService;
|
|
|
+import com.qmth.themis.business.templete.TaskImportTemplete;
|
|
|
+import com.qmth.themis.business.templete.impl.ExamStudentTemplete;
|
|
|
+import com.qmth.themis.business.util.ExcelUtil;
|
|
|
import com.qmth.themis.business.util.JacksonUtil;
|
|
|
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 io.swagger.annotations.*;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -34,14 +43,21 @@ import java.util.*;
|
|
|
@RestController
|
|
|
@RequestMapping("/${prefix.url.admin}/examStudent")
|
|
|
public class TEExamStudentController {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TEExamStudentController.class);
|
|
|
|
|
|
@Resource
|
|
|
TEExamStudentService teExamStudentService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ TBAttachmentService tbAttachmentService;
|
|
|
+
|
|
|
@ApiOperation(value = "考生查询接口")
|
|
|
@RequestMapping(value = "/query", method = RequestMethod.GET)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TEExamStudent.class)})
|
|
|
public Result query(@ApiParam(value = "考试批次id", required = true) @RequestParam Long examId, @ApiParam(value = "考试批次id", required = false) @RequestParam(required = false) Long activityId, @ApiParam(value = "证件号", required = false) @RequestParam(required = false) String identity, @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name, @ApiParam(value = "考场代码", required = false) @RequestParam(required = false) String roomCode, @ApiParam(value = "科目代码", required = false) @RequestParam(required = false) String courseCode, @ApiParam(value = "年级", required = false) @RequestParam String grade, @ApiParam(value = "是否启用", required = false) @RequestParam(required = false) Integer enable, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
|
|
|
+ if (Objects.isNull(examId) || Objects.equals(examId, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
|
|
|
+ }
|
|
|
IPage<Map> teExamStudentIPage = teExamStudentService.examStudentQuery(new Page<>(pageNumber, pageSize), examId, activityId, identity, name, roomCode, courseCode, grade, enable);
|
|
|
Map map = new HashMap<>();
|
|
|
map.put(SystemConstant.RECORDS, teExamStudentIPage);
|
|
@@ -59,8 +75,7 @@ public class TEExamStudentController {
|
|
|
if (Objects.isNull(mapParameter) || mapParameter.size() == 0) {
|
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STUDENT_INFO_IS_NULL);
|
|
|
}
|
|
|
- HttpServletRequest request = ServletUtil.getRequest();
|
|
|
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount(request);
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
List<TEExamStudent> teExamStudentList = new ArrayList<>();
|
|
|
for (int i = 0; i < mapParameter.size(); i++) {
|
|
|
Map map = mapParameter.get(i);
|
|
@@ -81,7 +96,7 @@ public class TEExamStudentController {
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
@Transactional
|
|
|
public Result save(@ApiParam(value = "考生信息", required = true) @RequestBody List<TEExamStudent> teExamStudentList) {
|
|
|
- if (Objects.isNull(teExamStudentList)) {
|
|
|
+ if (Objects.isNull(teExamStudentList) || teExamStudentList.size() == 0) {
|
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STUDENT_INFO_IS_NULL);
|
|
|
}
|
|
|
teExamStudentService.updateBatchById(teExamStudentList);
|
|
@@ -93,7 +108,7 @@ public class TEExamStudentController {
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
@Transactional
|
|
|
public Result delete(@ApiParam(value = "考生id", required = true) @RequestBody List<Long> ids) {
|
|
|
- if (Objects.isNull(ids)) {
|
|
|
+ if (Objects.isNull(ids) || ids.size() == 0) {
|
|
|
throw new BusinessException(ExceptionResultEnum.EXAM_STUDENT_ID_IS_NULL);
|
|
|
}
|
|
|
teExamStudentService.removeByIds(ids);
|
|
@@ -104,7 +119,40 @@ public class TEExamStudentController {
|
|
|
@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) {
|
|
|
+ public Result importData(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file, @RequestParam Integer type) throws IOException {
|
|
|
+ if (Objects.isNull(file) || Objects.equals(file, "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.ATTACHMENT_IS_NULL);
|
|
|
+ }
|
|
|
+ log.info("开始考生导入");
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ Map<String, Object> mapParameter = BackendConstant.getAttachmentEnv(type);
|
|
|
+ TBAttachment tbAttachment = null;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ TaskImportTemplete examStudentTemplete = new ExamStudentTemplete();
|
|
|
+ examStudentTemplete.importTask(file);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("考生导入结束,============耗时============:{}秒", (end - start) / 1000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ if (Objects.nonNull(tbAttachment)) {
|
|
|
+ tbAttachmentService.deleteAttachment(mapParameter, tbAttachment);
|
|
|
+ }
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+// String errorColumn = e.getCause().toString();
|
|
|
+// String column = errorColumn.substring(errorColumn.indexOf("'") + 1, errorColumn.lastIndexOf("-"));
|
|
|
+// String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+// throw new BusinessException(AttachmentErrorEnum.convertToCode(columnStr) + "-" + column + ",数据不允许重复插入");
|
|
|
+ } else if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
}
|
|
|
}
|