|
@@ -0,0 +1,108 @@
|
|
|
+package cn.com.qmth.examcloud.service.core.api;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
|
|
|
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
|
|
|
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
|
|
|
+import cn.com.qmth.examcloud.service.core.service.ExamSiteService;
|
|
|
+import cn.com.qmth.examcloud.service.core.service.ExamSiteService;
|
|
|
+import cn.com.qmth.examcloud.service.core.util.ExportUtils;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考点服务API
|
|
|
+ * Created by songyue on 17/1/14.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.root}/examsite")
|
|
|
+public class ExamSiteApi {
|
|
|
+
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(ExamSiteApi.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamSiteRepo examSiteRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamSiteService examSiteService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考点分页带查询", notes = "分页带查询")
|
|
|
+ @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllExamSite(@ModelAttribute ExamSite examSiteCriteria,
|
|
|
+ HttpServletRequest request,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize) {
|
|
|
+ return new ResponseEntity(examSiteService.findAll(examSiteCriteria, new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询考点不分页带查询", notes = "不分页带查询")
|
|
|
+ @GetMapping("/all")
|
|
|
+ public ResponseEntity getAllExam(@ModelAttribute ExamSite examSiteCriteria,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if (accessUser != null) {
|
|
|
+ return new ResponseEntity(examSiteRepo.findByOrgId(accessUser.getOrgId()), HttpStatus.OK);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(new ArrayList<ExamSite>(), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按ID查询考点", notes = "ID查询")
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public ResponseEntity<ExamSite> getExamSiteById(@PathVariable Long id) {
|
|
|
+ return new ResponseEntity(examSiteRepo.findOne(id), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增考点", notes = "新增")
|
|
|
+ @PostMapping
|
|
|
+ public ResponseEntity addExamSite(@RequestBody ExamSite examSite, HttpServletRequest request) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ examSite.setCreateTime(new Date());
|
|
|
+ return new ResponseEntity(examSiteService.save(examSite), HttpStatus.CREATED);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新考点", notes = "更新")
|
|
|
+ @PutMapping
|
|
|
+ public ResponseEntity updateExamSite(@RequestBody ExamSite examSite,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ try {
|
|
|
+ return new ResponseEntity(examSiteService.update(examSite.getId(), examSite), HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "按ID删除考点", notes = "删除")
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ public ResponseEntity deleteExamSite(@PathVariable String id) {
|
|
|
+ List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ examSiteRepo.deleteInBatch(examSiteRepo.findAll(examStuIds));
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+}
|