wangwei 6 years ago
parent
commit
fde075dc26
12 changed files with 548 additions and 486 deletions
  1. 124 50
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/ExamSiteController.java
  2. 0 36
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java
  3. 115 0
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/bean/ExamSiteDomain.java
  4. 9 8
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/ExamSiteRepo.java
  5. 29 11
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/ExamSiteEntity.java
  6. 24 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/ExamSiteService.java
  7. 115 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/ExamSiteInfo.java
  8. 0 124
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseSpeciatlyRelationServiceImpl.java
  9. 0 61
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExamSiteService.java
  10. 132 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExamSiteServiceImpl.java
  11. 0 36
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExportService.java
  12. 0 160
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgServiceImpl.java

+ 124 - 50
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/ExamSiteController.java

@@ -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);
+		}
 	}
+
 }

+ 0 - 36
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -44,7 +44,6 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
 import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
@@ -55,9 +54,7 @@ import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
-import cn.com.qmth.examcloud.core.basic.service.bean.OrgDto;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
-import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
 import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
@@ -515,39 +512,6 @@ public class OrgController extends ControllerSupport {
 		orgRepo.delete(id);
 	}
 
-	/**
-	 * 待重构
-	 *
-	 * @author WANGWEI
-	 * @param request
-	 * @param file
-	 * @return
-	 * @throws Exception
-	 */
-	@ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
-	@PostMapping("/import")
-	public List<ExcelError> importLearnCenter(HttpServletRequest request,
-			@RequestParam CommonsMultipartFile file) throws Exception {
-		User accessUser = getAccessUser();
-
-		List<ExcelError> excelErrors = orgService.importLearnCenter(accessUser.getRootOrgId(),
-				file.getInputStream());
-		return excelErrors;
-	}
-
-	/**
-	 * 待重构
-	 *
-	 * @author WANGWEI
-	 * @param response
-	 */
-	@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
-	@GetMapping("/download")
-	public void importFileTemplate(HttpServletResponse response) {
-		// List<OrgDto> list = new ArrayList<OrgDto>();
-		// ExportService.exportEXCEL("学习中心导入模板", OrgDto.class, list, response);
-	}
-
 	/**
 	 * 方法注释
 	 *

+ 115 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/bean/ExamSiteDomain.java

@@ -0,0 +1,115 @@
+package cn.com.qmth.examcloud.core.basic.api.controller.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月31日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class ExamSiteDomain implements JsonSerializable {
+
+	private static final long serialVersionUID = 1353662143659247163L;
+
+	private Long id;
+
+	private Long rootOrgId;
+
+	private Long orgId;
+
+	private String code;
+
+	private String name;
+
+	private Boolean enable;
+
+	/**
+	 * 联系电话
+	 */
+	private String telephone;
+
+	/**
+	 * 联系人
+	 */
+	private String contacts;
+
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Long getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+	public String getTelephone() {
+		return telephone;
+	}
+
+	public void setTelephone(String telephone) {
+		this.telephone = telephone;
+	}
+
+	public String getContacts() {
+		return contacts;
+	}
+
+	public void setContacts(String contacts) {
+		this.contacts = contacts;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+}

+ 9 - 8
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/ExamSiteRepo.java

@@ -3,21 +3,22 @@ package cn.com.qmth.examcloud.core.basic.dao;
 import java.util.List;
 
 import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
+import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSiteEntity;
 
 /**
  * Created by songyue on 17/1/13.
  */
-public interface ExamSiteRepo extends JpaRepository<ExamSite,Long>,QueryByExampleExecutor<ExamSite>{
+public interface ExamSiteRepo
+		extends
+			JpaRepository<ExamSiteEntity, Long>,
+			QueryByExampleExecutor<ExamSiteEntity>,
+			JpaSpecificationExecutor<ExamSiteEntity> {
 
-    List<ExamSite> findByOrgId(Long orgId);
-
-    @Query(nativeQuery = true,value = "select *from ecs_core_exam_site where org_id=:orgId and code=:code")
-    ExamSite findFirstByOrgIdAndCode(@Param("orgId") Long orgId, @Param("code")String code);
+	List<ExamSiteEntity> findByRootOrgId(Long rootOrgId);
 
+	ExamSiteEntity findByRootOrgIdAndCode(Long rootOrgId, String code);
 
 }

+ 29 - 11
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/ExamSite.java → examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/ExamSiteEntity.java

@@ -1,10 +1,11 @@
 package cn.com.qmth.examcloud.core.basic.dao.entity;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Index;
 import javax.persistence.Table;
-import javax.validation.constraints.NotNull;
 
 import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 
@@ -12,35 +13,44 @@ import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
  * Created by songyue on 17/7/27.
  */
 @Entity
-@Table(name = "ecs_core_exam_site")
-public class ExamSite extends JpaEntity {
+@Table(name = "EC_B_EXAM_SITE", indexes = {
+		@Index(name = "IDX_B_E_S_003001", columnList = "rootOrgId,code", unique = true),
+		@Index(name = "IDX_B_E_S_003002", columnList = "rootOrgId,name", unique = false)})
+public class ExamSiteEntity extends JpaEntity {
 	private static final long serialVersionUID = 8042526239290337481L;
 
 	@Id
 	@GeneratedValue
 	private Long id;
 
-	@NotNull
+	@Column(nullable = false)
+	private Long rootOrgId;
+
+	@Column(nullable = false)
 	private Long orgId;
 
-	@NotNull
+	@Column(nullable = false)
 	private String code;
 
-	@NotNull
+	@Column(nullable = false)
 	private String name;
 
+	@Column(nullable = false)
 	private Boolean enable;
 
 	/**
 	 * 联系电话
 	 */
-	private String telphone;
+	private String telephone;
 
 	/**
 	 * 联系人
 	 */
 	private String contacts;
 
+	/**
+	 * 备注
+	 */
 	private String remark;
 
 	public Long getId() {
@@ -51,6 +61,14 @@ public class ExamSite extends JpaEntity {
 		this.id = id;
 	}
 
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
 	public Long getOrgId() {
 		return orgId;
 	}
@@ -83,12 +101,12 @@ public class ExamSite extends JpaEntity {
 		this.enable = enable;
 	}
 
-	public String getTelphone() {
-		return telphone;
+	public String getTelephone() {
+		return telephone;
 	}
 
-	public void setTelphone(String telphone) {
-		this.telphone = telphone;
+	public void setTelephone(String telephone) {
+		this.telephone = telephone;
 	}
 
 	public String getContacts() {

+ 24 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/ExamSiteService.java

@@ -0,0 +1,24 @@
+package cn.com.qmth.examcloud.core.basic.service;
+
+import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSiteEntity;
+import cn.com.qmth.examcloud.core.basic.service.bean.ExamSiteInfo;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月31日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface ExamSiteService {
+
+	/**
+	 * 保存考点
+	 *
+	 * @author WANGWEI
+	 * @param info
+	 * @return
+	 */
+	ExamSiteEntity saveExamSite(ExamSiteInfo info);
+
+}

+ 115 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/ExamSiteInfo.java

@@ -0,0 +1,115 @@
+package cn.com.qmth.examcloud.core.basic.service.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月31日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class ExamSiteInfo implements JsonSerializable {
+
+	private static final long serialVersionUID = 1353662143659247163L;
+
+	private Long id;
+
+	private Long rootOrgId;
+
+	private Long orgId;
+
+	private String code;
+
+	private String name;
+
+	private Boolean enable;
+
+	/**
+	 * 联系电话
+	 */
+	private String telephone;
+
+	/**
+	 * 联系人
+	 */
+	private String contacts;
+
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Long getOrgId() {
+		return orgId;
+	}
+
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+	public String getTelephone() {
+		return telephone;
+	}
+
+	public void setTelephone(String telephone) {
+		this.telephone = telephone;
+	}
+
+	public String getContacts() {
+		return contacts;
+	}
+
+	public void setContacts(String contacts) {
+		this.contacts = contacts;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
+}

+ 0 - 124
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseSpeciatlyRelationServiceImpl.java

@@ -1,124 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.service.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
-import cn.com.qmth.examcloud.core.basic.dao.CourseSpeciatlyRelationRepo;
-import cn.com.qmth.examcloud.core.basic.dao.SpecialtyRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
-
-@Service
-public class CourseSpeciatlyRelationServiceImpl {
-
-	@Autowired
-	CourseSpeciatlyRelationRepo courseSpeciatlyRepo;
-
-	@Autowired
-	CourseRepo courseRepo;
-
-	@Autowired
-	SpecialtyRepo specialtyRepo;
-
-	/**
-	 * 根据专业ID查询关联课程
-	 * 
-	 * @param speciatlyId
-	 * @return
-	 */
-	public List<CourseEntity> getAllCoursesBySpeciatlyId(String speciatlyId) {
-		// 根据专业id查询 专业课程
-		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo
-				.findBySpecialtyId(Long.parseLong(speciatlyId));
-		List<CourseEntity> courses = new ArrayList<CourseEntity>();
-		if (list == null) {
-			return null;
-		}
-		courses = getCoursesByCourseSpeciatly(list);
-		return courses;
-	}
-
-	// 根据课程专业查询课程集合
-	public List<CourseEntity> getCoursesByCourseSpeciatly(
-			List<CourseSpeciatlyRelationEntity> list) {
-		List<CourseEntity> courses = new ArrayList<CourseEntity>();
-		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
-			CourseEntity course = courseRepo.findOne(courseSpeciatly.getCourseId());
-			courses.add(course);
-		}
-		return courses;
-	}
-
-	/**
-	 * 获取未关联的课程
-	 * 
-	 * @param courses
-	 * @return
-	 */
-	public List<CourseEntity> getCoursesNotInSpeciatly(List<CourseEntity> courses) {
-		List<CourseEntity> list = new ArrayList<CourseEntity>();
-		if (courses == null || courses.size() < 1) {
-			list = courseRepo.findAll();
-			return list;
-		}
-		List<Long> ids = new ArrayList<Long>();
-		for (CourseEntity course : courses) {
-			ids.add(course.getId());
-		}
-		list = courseRepo.findByIdNotIn(ids);
-		return list;
-	}
-
-	public void addCourseSpecialty(Long userId, List<String> courseIds, String speciallyId) {
-		// 首先判断该专业是否有关联的课程
-		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo
-				.findBySpecialtyId(Long.parseLong(speciallyId));
-		if (list != null || list.size() > 0) {
-			for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
-				courseSpeciatlyRepo.delete(courseSpeciatly);
-			}
-		}
-		// 保存新关联的课程
-		for (String courseId : courseIds) {
-			CourseSpeciatlyRelationEntity courseSpeciatly = new CourseSpeciatlyRelationEntity();
-			courseSpeciatly.setCourseId(Long.parseLong(courseId));
-			courseSpeciatly.setSpecialtyId(Long.parseLong(speciallyId));
-			courseSpeciatly.setCreator(userId);
-			courseSpeciatlyRepo.save(courseSpeciatly);
-		}
-	}
-
-	public List<SpecialtyEntity> getAllSpecialtyByCourseId(Long courseId) {
-		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo.findByCourseId(courseId);
-		List<SpecialtyEntity> specialties = new ArrayList<SpecialtyEntity>();
-		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
-			SpecialtyEntity one = specialtyRepo.findOne(courseSpeciatly.getSpecialtyId());
-			if (null != one) {
-				specialties.add(one);
-			}
-		}
-		return specialties;
-	}
-
-	public void addCourse(Long userId, List<String> SpecialtyIds, Long courseId) {
-		// 首先判断该专业是否有关联的课程
-		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo.findByCourseId(courseId);
-		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
-			courseSpeciatlyRepo.delete(courseSpeciatly);
-		}
-		// 保存新关联的课程
-		for (String specialtyId : SpecialtyIds) {
-			CourseSpeciatlyRelationEntity courseSpeciatly = new CourseSpeciatlyRelationEntity();
-			courseSpeciatly.setCourseId(courseId);
-			courseSpeciatly.setSpecialtyId(Long.parseLong(specialtyId));
-			courseSpeciatly.setCreator(userId);
-			courseSpeciatlyRepo.save(courseSpeciatly);
-		}
-
-	}
-}

+ 0 - 61
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExamSiteService.java

@@ -1,61 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.service.impl;
-
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
-
-import java.util.Date;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
-
-@Service
-public class ExamSiteService {
-
-	@Autowired
-	ExamSiteRepo examSiteRepo;
-
-	public Page<ExamSite> findAll(ExamSite examSiteCriteria, Pageable pageable) {
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains())
-				.withMatcher("code", contains()).withMatcher("orgId", exact());
-		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria, exampleMatcher);
-		return examSiteRepo.findAll(examSiteExample, pageable);
-	}
-
-	public List<ExamSite> findAll(ExamSite examSiteCriteria) {
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains())
-				.withMatcher("code", contains()).withMatcher("orgId", exact());
-		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria, exampleMatcher);
-		return examSiteRepo.findAll(examSiteExample);
-	}
-
-	public ExamSite save(ExamSite examSite) {
-		checkCode(examSite.getOrgId(), examSite.getCode());
-		return examSiteRepo.save(examSite);
-	}
-
-	private void checkCode(Long orgId, String code) {
-		ExamSite old = examSiteRepo.findFirstByOrgIdAndCode(orgId, code);
-		if (old != null) {
-			throw new StatusException("B-710002", "考点代码已存在");
-		}
-	}
-
-	public ExamSite update(Long id, ExamSite examSite) {
-		ExamSite old = examSiteRepo.findOne(id);
-		if (!old.getCode().equals(examSite.getCode())) {
-			checkCode(examSite.getOrgId(), examSite.getCode());
-		}
-		examSite.setUpdateTime(new Date());
-		return examSiteRepo.save(examSite);
-	}
-
-}

+ 132 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExamSiteServiceImpl.java

@@ -0,0 +1,132 @@
+package cn.com.qmth.examcloud.core.basic.service.impl;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSiteEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
+import cn.com.qmth.examcloud.core.basic.service.ExamSiteService;
+import cn.com.qmth.examcloud.core.basic.service.bean.ExamSiteInfo;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月31日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Service
+public class ExamSiteServiceImpl implements ExamSiteService {
+
+	@Autowired
+	ExamSiteRepo examSiteRepo;
+
+	@Autowired
+	OrgRepo orgRepo;
+
+	@Override
+	public ExamSiteEntity saveExamSite(ExamSiteInfo info) {
+		Long rootOrgId = info.getRootOrgId();
+		Long orgId = info.getOrgId();
+		Long id = info.getId();
+		String code = info.getCode();
+		Boolean enable = info.getEnable();
+		String name = info.getName();
+		String remark = info.getRemark();
+		String contacts = info.getContacts();
+		String telephone = info.getTelephone();
+
+		if (null == rootOrgId) {
+			throw new StatusException("B-160000", "rootOrgId is null");
+		}
+		if (null == orgId) {
+			throw new StatusException("B-160001", "rootOrgId is null");
+		}
+		OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
+		if (null == rootOrg) {
+			throw new StatusException("B-160002", "顶级机构不存在");
+		}
+		if (null != rootOrg.getParentId()) {
+			throw new StatusException("B-160003", "顶级机构错误");
+		}
+
+		OrgEntity org = orgRepo.findOne(orgId);
+		if (null == org) {
+			throw new StatusException("B-160004", "机构不存在");
+		}
+		if (!org.getParentId().equals(rootOrgId)) {
+			throw new StatusException("B-160005", "rootOrgId and orgId is not matched");
+		}
+
+		ExamSiteEntity entity = null;
+
+		if (null != id) {
+			entity = examSiteRepo.findOne(id);
+
+			if (null == entity) {
+				throw new StatusException("B-160006", "考点ID错误");
+			}
+
+			if (!rootOrgId.equals(entity.getRootOrgId())) {
+				throw new StatusException("B-160007", "顶级机构错误");
+			}
+
+		} else if (StringUtils.isNotBlank(code)) {
+
+			entity = examSiteRepo.findByRootOrgIdAndCode(rootOrgId, code);
+
+			if (null != entity) {
+				if (null == entity.getEnable()) {
+					entity.setEnable(true);
+				}
+			} else {
+				entity = new ExamSiteEntity();
+				entity.setRootOrgId(rootOrgId);
+				entity.setOrgId(orgId);
+				entity.setCode(code);
+				entity.setEnable(true);
+
+				if (StringUtils.isBlank(name)) {
+					throw new StatusException("B-160008", "name is blank");
+				}
+			}
+
+		} else {
+			throw new StatusException("B-160009", "id,code can not be all null");
+		}
+
+		if (null != enable) {
+			entity.setEnable(enable);
+		}
+
+		if (null != name) {
+			if (StringUtils.isBlank(name)) {
+				throw new StatusException("B-160008", "name is blank");
+			} else {
+				entity.setName(name);
+			}
+
+		}
+
+		if (null != telephone) {
+			entity.setTelephone(telephone);
+		}
+
+		if (null != contacts) {
+			entity.setContacts(contacts);
+		}
+
+		if (null != remark) {
+			entity.setRemark(remark);
+		}
+
+		ExamSiteEntity saved = examSiteRepo.saveAndFlush(entity);
+
+		return saved;
+	}
+
+}

+ 0 - 36
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExportService.java

@@ -1,36 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.service.impl;
-
-import java.net.URLEncoder;
-import java.util.Collection;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelWriter;
-
-/*
- * excel导出工具
- */
-public class ExportService {
-
-    private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
-
-    private static final String DEFALUT_EXT = ".xlsx";
-
-    public static void exportEXCEL(String fileName,Class<?> dataClass,
-                             Collection<?> dataset,HttpServletResponse response) {
-        try {
-        	
-            response.setHeader("Content-Disposition", "inline; filename="
-                    +URLEncoder.encode(fileName, "UTF-8") + DEFALUT_EXT);
-            response.setContentType(DEFALUT_CONTENT_TYPE);
-            ServletOutputStream outputStream = response.getOutputStream();
-            ExcelWriter excelExporter = new ExcelWriter(dataClass);
-            excelExporter.write("sheet1",dataset,outputStream);
-            outputStream.flush();
-            outputStream.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-}

+ 0 - 160
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgServiceImpl.java

@@ -1,45 +1,27 @@
 package cn.com.qmth.examcloud.core.basic.service.impl;
 
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
-
-import java.io.InputStream;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.base.helpers.DynamicEnumManager;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
-import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
 import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRoleRelationRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.UserRoleRelationEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
 import cn.com.qmth.examcloud.core.basic.service.OrgService;
-import cn.com.qmth.examcloud.core.basic.service.bean.OrgDto;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
 
 @Service
@@ -63,148 +45,6 @@ public class OrgServiceImpl implements OrgService {
 	@Autowired
 	OrgPropertyRepo orgPropertyRepo;
 
-	@Transactional
-	public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
-		ExcelReader excelReader = new ExcelReader(OrgDto.class);
-		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
-			@Override
-			public ExcelError handle(Object obj) {
-				OrgDto dto = (OrgDto) obj;
-				dto.setParentId(orgId);
-				dto.setRootId(orgId);
-				ExcelError error = importCheck(dto);
-				if (error == null) {
-					saveOrgAndExamSite(dto);
-				}
-				return error;
-			}
-		});
-		return excelErrors;
-	}
-
-	/**
-	 * 保存学习中心和考点
-	 * 
-	 * @param orgDto
-	 */
-	private void saveOrgAndExamSite(OrgDto orgDto) {
-		OrgEntity org = orgRepo.findByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
-		if (org == null) {
-			OrgEntity tempOrg = orgRepo.save(orgAssembler(orgDto));
-			orgDto.setId(tempOrg.getId());
-			examSiteRepo.save(examSiteAssembler(orgDto));
-			createLearnerCenterUser(tempOrg);
-		} else {
-			org.setName(orgDto.getName());
-			org.setContacts(orgDto.getContacts());
-			org.setTelephone(orgDto.getTelphone());
-			orgRepo.save(org);
-
-			orgDto.setId(org.getId());
-			ExamSite examSite = examSiteRepo.findFirstByOrgIdAndCode(org.getId(),
-					orgDto.getExamSiteCode());
-			if (examSite == null) {
-				examSiteRepo.save(examSiteAssembler(orgDto));
-			} else {
-				examSite.setName(orgDto.getExamSiteName());
-				examSiteRepo.save(examSite);
-			}
-		}
-
-	}
-
-	/**
-	 * 创建学习中心用户
-	 * 
-	 * @param org
-	 */
-	public void createLearnerCenterUser(OrgEntity org) {
-		UserEntity user = userRepo.findByLoginName(org.getCode());
-		if (null != user) {
-			return;
-		}
-		user = new UserEntity();
-		user.setRootOrgId(org.getRootId());
-		user.setOrgId(org.getId());
-		user.setLoginName(org.getCode());
-		user.setName(org.getContacts());
-		user.setPhoneNumber(org.getTelephone());
-		user.setEnable(true);
-		user.setPassword(BasicConsts.DEFAULT_PASSWORD);
-		UserEntity saved = userRepo.save(user);
-		List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
-		RoleEntity role = roleRepo.findByCode(RoleMeta.LC_USER.name());
-		UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(), role.getId(),
-				role.getCode());
-		userRoles.add(relation);
-		userRoleRelationRepo.save(userRoles);
-	}
-
-	private OrgEntity orgAssembler(OrgDto orgDto) {
-		OrgEntity org = new OrgEntity();
-		org.setRootId(orgDto.getRootId());
-		org.setParentId(orgDto.getParentId());
-		org.setCode(orgDto.getCode());
-		org.setName(orgDto.getName());
-		org.setContacts(orgDto.getContacts());
-		org.setTelephone(orgDto.getTelphone());
-		org.setEnable(true);
-		return org;
-	}
-
-	private ExamSite examSiteAssembler(OrgDto orgDto) {
-		ExamSite examSite = new ExamSite();
-		examSite.setCode(orgDto.getExamSiteCode());
-		examSite.setName(orgDto.getExamSiteName());
-		examSite.setOrgId(orgDto.getId());
-		examSite.setEnable(true);
-		return examSite;
-	}
-
-	private ExcelError importCheck(OrgDto dto) {
-		if (StringUtils.isBlank(dto.getCode())) {
-			return new ExcelError("中心代码不能为空");
-		}
-		if (StringUtils.isBlank(dto.getName())) {
-			return new ExcelError("中心名称不能为空");
-		}
-		if (StringUtils.isBlank(dto.getExamSiteCode())) {
-			return new ExcelError("考点代码不能为空");
-		}
-		if (StringUtils.isBlank(dto.getExamSiteName())) {
-			return new ExcelError("考点名称不能为空");
-		}
-		if (StringUtils.isBlank(dto.getContacts())) {
-			return new ExcelError("联系人不能为空");
-		}
-		if (StringUtils.isBlank(dto.getTelphone())) {
-			return new ExcelError("联系电话不能为空");
-		}
-		return null;
-	}
-
-	/**
-	 * 启用/禁用机构;禁用机构时禁用该机构下的所有用户
-	 * 
-	 * @param id
-	 * @param enable
-	 * @return
-	 */
-	@Transactional
-	public OrgEntity enableSchool(Long id, boolean enable) {
-		OrgEntity org = orgRepo.findOne(id);
-		org.setEnable(enable);
-		orgRepo.save(org);
-		return org;
-	}
-
-	public List<OrgEntity> findAll(OrgEntity orgCriteria) {
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains())
-				.withMatcher("code", contains());
-		Example<OrgEntity> examExample = Example.of(orgCriteria, exampleMatcher);
-		return orgRepo.findAll(examExample);
-	}
-
 	/*
 	 * 保存顶级机构
 	 *