|
@@ -1,183 +0,0 @@
|
|
|
-package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
-
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-
|
|
|
-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.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.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.api.commons.security.bean.User;
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-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.ExamSiteEntity;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.ExamSiteInfo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.ExamSiteServiceImpl;
|
|
|
-import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
-/**
|
|
|
- * 考点服务API Created by songyue on 17/1/14.
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("${$rmp.ctr.basic}/examSite")
|
|
|
-public class ExamSiteController extends ControllerSupport {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamSiteRepo examSiteRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamSiteServiceImpl examSiteService;
|
|
|
-
|
|
|
- @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 = PageRequest.of(curPage, pageSize,
|
|
|
- new Sort(Direction.DESC, "updateTime", "id"));
|
|
|
-
|
|
|
- Page<ExamSiteEntity> page = examSiteRepo.findAll(specification, pageRequest);
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修正
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param domain
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "新增考点", notes = "新增")
|
|
|
- @PostMapping
|
|
|
- @Transactional
|
|
|
- public Long addExamSite(@RequestBody ExamSiteDomain domain) {
|
|
|
- trim(domain, true);
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
- Long rootOrgId = accessUser.getRootOrgId();
|
|
|
-
|
|
|
- String code = domain.getCode();
|
|
|
- Long orgId = domain.getOrgId();
|
|
|
-
|
|
|
- if (StringUtils.isBlank(code)) {
|
|
|
- throw new StatusException("620001", "code is blank");
|
|
|
- }
|
|
|
- if (null == orgId) {
|
|
|
- throw new StatusException("620002", "orgId is null");
|
|
|
- }
|
|
|
-
|
|
|
- ExamSiteEntity es = examSiteRepo.findByOrgIdAndCode(orgId, code);
|
|
|
- if (null != es) {
|
|
|
- throw new StatusException("620003", "考点代码已被占用");
|
|
|
- }
|
|
|
-
|
|
|
- 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
|
|
|
- @Transactional
|
|
|
- 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 = "删除考点", notes = "删除")
|
|
|
- @DeleteMapping("{ids}")
|
|
|
- @Transactional
|
|
|
- public void deleteExamSite(@PathVariable String ids) {
|
|
|
- List<Long> examSiteIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (Long id : examSiteIds) {
|
|
|
- ExamSiteEntity one = GlobalHelper.getEntity(examSiteRepo, id, ExamSiteEntity.class);
|
|
|
- if (null == one) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- validateRootOrgIsolation(one.getRootOrgId());
|
|
|
- examSiteRepo.delete(one);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|