|
@@ -5,29 +5,34 @@ import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.ExamSiteDomain;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.ExamSiteService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSiteEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.ExamSiteInfo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.ExamSiteServiceImpl;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
@@ -35,66 +40,135 @@ import io.swagger.annotations.ApiOperation;
|
|
|
*/
|
|
|
@Transactional
|
|
|
@RestController
|
|
|
-@RequestMapping("${$rmp.ctr.basic}/examsite")
|
|
|
+@RequestMapping("${$rmp.ctr.basic}/examSite")
|
|
|
public class ExamSiteController extends ControllerSupport {
|
|
|
|
|
|
- private static final Logger LOG = LoggerFactory.getLogger(ExamSiteController.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);
|
|
|
- }
|
|
|
+ ExamSiteServiceImpl examSiteService;
|
|
|
|
|
|
- @ApiOperation(value = "查询考点不分页带查询", notes = "不分页带查询")
|
|
|
- @GetMapping("/all")
|
|
|
- public ResponseEntity getAllExam(@ModelAttribute ExamSite examSiteCriteria,
|
|
|
- HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- if (accessUser != null) {
|
|
|
- return new ResponseEntity(examSiteRepo.findByOrgId(accessUser.getOrgId()),
|
|
|
- HttpStatus.OK);
|
|
|
- }
|
|
|
- return new ResponseEntity(new ArrayList<ExamSite>(), HttpStatus.OK);
|
|
|
- }
|
|
|
+ @ApiOperation(value = "分页查询考点")
|
|
|
+ @GetMapping("examSitePage/{curPage}/{pageSize}")
|
|
|
+ public Page<ExamSiteEntity> getExamSitePage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String code, @RequestParam(required = true) Long orgId,
|
|
|
+ @RequestParam(required = false) Boolean enable) {
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ Specification<ExamSiteEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
+
|
|
|
+ if (null != orgId) {
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), orgId));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(code)) {
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
+ }
|
|
|
+ if (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = new PageRequest(curPage, pageSize,
|
|
|
+ new Sort(Direction.DESC, "updateTime"));
|
|
|
|
|
|
- @ApiOperation(value = "按ID查询考点", notes = "ID查询")
|
|
|
- @GetMapping("/{id}")
|
|
|
- public ResponseEntity<ExamSite> getExamSiteById(@PathVariable Long id) {
|
|
|
- return new ResponseEntity(examSiteRepo.findOne(id), HttpStatus.OK);
|
|
|
+ Page<ExamSiteEntity> page = examSiteRepo.findAll(specification, pageRequest);
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修正
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "新增考点", notes = "新增")
|
|
|
@PostMapping
|
|
|
- public ExamSite addExamSite(@RequestBody ExamSite examSite) {
|
|
|
- trim(examSite);
|
|
|
- return examSiteService.save(examSite);
|
|
|
+ public Long addExamSite(@RequestBody ExamSiteDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+
|
|
|
+ String code = domain.getCode();
|
|
|
+ if (StringUtils.isBlank(code)) {
|
|
|
+ throw new StatusException("B-620001", "code is blank");
|
|
|
+ }
|
|
|
+ ExamSiteEntity course = examSiteRepo.findByRootOrgIdAndCode(rootOrgId, code);
|
|
|
+ if (null != course) {
|
|
|
+ throw new StatusException("B-620002", "考点编码已被占用");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamSiteInfo info = new ExamSiteInfo();
|
|
|
+ info.setRootOrgId(rootOrgId);
|
|
|
+ info.setOrgId(domain.getOrgId());
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setEnable(domain.getEnable());
|
|
|
+ info.setId(domain.getId());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+
|
|
|
+ ExamSiteEntity saved = examSiteService.saveExamSite(info);
|
|
|
+ return saved.getId();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 修正
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param domain
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "更新考点", notes = "更新")
|
|
|
@PutMapping
|
|
|
- public ExamSite updateExamSite(@RequestBody ExamSite examSite) {
|
|
|
- trim(examSite);
|
|
|
- ExamSite updated = examSiteService.update(examSite.getId(), examSite);
|
|
|
- return updated;
|
|
|
+ public Long updateCourse(@RequestBody ExamSiteDomain domain) {
|
|
|
+ trim(domain, true);
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+
|
|
|
+ ExamSiteInfo info = new ExamSiteInfo();
|
|
|
+ info.setRootOrgId(rootOrgId);
|
|
|
+ info.setOrgId(domain.getOrgId());
|
|
|
+ info.setCode(domain.getCode());
|
|
|
+ info.setEnable(domain.getEnable());
|
|
|
+ info.setId(domain.getId());
|
|
|
+ info.setName(domain.getName());
|
|
|
+ info.setRemark(domain.getRemark());
|
|
|
+ info.setTelephone(domain.getTelephone());
|
|
|
+ info.setContacts(domain.getContacts());
|
|
|
+
|
|
|
+ ExamSiteEntity saved = examSiteService.saveExamSite(info);
|
|
|
+ return saved.getId();
|
|
|
}
|
|
|
|
|
|
- @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()))
|
|
|
+ @ApiOperation(value = "删除考点", notes = "删除")
|
|
|
+ @DeleteMapping("{ids}")
|
|
|
+ public void deleteExamSite(@PathVariable String ids) {
|
|
|
+ List<Long> examSiteIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
.collect(Collectors.toList());
|
|
|
- examSiteRepo.deleteInBatch(examSiteRepo.findAll(examStuIds));
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
+ for (Long id : examSiteIds) {
|
|
|
+ ExamSiteEntity one = examSiteRepo.findOne(id);
|
|
|
+ if (null == one) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ validateRootOrgIsolation(one.getRootOrgId());
|
|
|
+ examSiteRepo.delete(one);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|