|
@@ -0,0 +1,123 @@
|
|
|
+package com.qmth.themis.backend.api;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.qmth.themis.backend.util.ServletUtil;
|
|
|
+import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TBExamInvigilateUser;
|
|
|
+import com.qmth.themis.business.entity.TBOrg;
|
|
|
+import com.qmth.themis.business.entity.TEExamStudent;
|
|
|
+import com.qmth.themis.business.enums.FieldUniqueEnum;
|
|
|
+import com.qmth.themis.business.service.TBExamInvigilateUserService;
|
|
|
+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.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.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 监考员设置 前端控制器
|
|
|
+ * @Param:
|
|
|
+ * @return:
|
|
|
+ * @Author: wangliang
|
|
|
+ * @Date: 2020/6/25
|
|
|
+ */
|
|
|
+@Api(tags = "监考员设置Controller")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/${prefix.url.admin}/invigilateUser")
|
|
|
+public class TBExamInvigilateUserController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TBExamInvigilateUserService tbExamInvigilateUserService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "监考员查询接口")
|
|
|
+ @RequestMapping(value = "/query", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "监考员信息", response = TEExamStudent.class)})
|
|
|
+ public Result query(@ApiParam(value = "考场代码", required = false) @RequestParam(required = false) String roomCode, @ApiParam(value = "用户id", required = false) @RequestParam(required = false) Long userId, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
|
|
|
+ IPage<Map> examInvigilateUserQuery = tbExamInvigilateUserService.examInvigilateUserQuery(new Page<>(pageNumber, pageSize), roomCode, userId);
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ map.put(SystemConstant.RECORDS, examInvigilateUserQuery);
|
|
|
+ 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 Map<String, Object> mapParameter) {
|
|
|
+ String roomCode = null;
|
|
|
+ try {
|
|
|
+ if (Objects.isNull(mapParameter.get("roomCode")) || Objects.equals(mapParameter.get("roomCode"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.ROOMCODE_IS_NULL);
|
|
|
+ }
|
|
|
+ roomCode = String.valueOf(mapParameter.get("roomCode"));
|
|
|
+ if (Objects.isNull(mapParameter.get("userId")) || Objects.equals(mapParameter.get("userId"), "")) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.USER_ID_IS_NULL);
|
|
|
+ }
|
|
|
+ String userId = String.valueOf(mapParameter.get("userId"));
|
|
|
+ String[] userIds = userId.split(",");
|
|
|
+ if (userIds.length > 3) {
|
|
|
+ throw new BusinessException(ExceptionResultEnum.ERROR.getCode(), "一个考场最多设置3名监考员");
|
|
|
+ }
|
|
|
+ HttpServletRequest request = ServletUtil.getRequest();
|
|
|
+ TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg(request);
|
|
|
+ QueryWrapper<TBExamInvigilateUser> tbExamInvigilateUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ tbExamInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getRoomCode, roomCode);
|
|
|
+ Long orgId = null;
|
|
|
+ if (Objects.nonNull(tbOrg)) {
|
|
|
+ tbExamInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getOrgId, tbOrg.getId());
|
|
|
+ orgId = tbOrg.getId();
|
|
|
+ }
|
|
|
+ List<TBExamInvigilateUser> tbExamInvigilateUserList = tbExamInvigilateUserService.list(tbExamInvigilateUserQueryWrapper);
|
|
|
+ List<String> roomNameList = tbExamInvigilateUserList.stream().map(s -> s.getRoomName()).collect(Collectors.toList());
|
|
|
+ tbExamInvigilateUserService.remove(tbExamInvigilateUserQueryWrapper);
|
|
|
+ if (userIds.length > 0) {
|
|
|
+ tbExamInvigilateUserList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < userIds.length; i++) {
|
|
|
+ TBExamInvigilateUser tbExamInvigilateUser = new TBExamInvigilateUser(orgId, Long.parseLong(userIds[i]), roomCode, roomNameList.get(0));
|
|
|
+ tbExamInvigilateUserList.add(tbExamInvigilateUser);
|
|
|
+ }
|
|
|
+ tbExamInvigilateUserService.saveBatch(tbExamInvigilateUserList);
|
|
|
+ }
|
|
|
+ } 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("考场代码[" + roomCode + "]下的" + 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) {
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "监考员导出接口")
|
|
|
+ @RequestMapping(value = "/export", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0", response = Result.class)})
|
|
|
+ public Result export(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) {
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
+}
|