wangwei 7 سال پیش
والد
کامیت
6f94aef095
20فایلهای تغییر یافته به همراه2347 افزوده شده و 2346 حذف شده
  1. 1 62
      examcloud-core-basic-export/pom.xml
  2. 62 0
      examcloud-core-basic-service/pom.xml
  3. 203 203
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java
  4. 124 124
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseSpeciatlyService.java
  5. 66 66
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/ExamSiteService.java
  6. 42 42
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/FaceSetTokenService.java
  7. 48 48
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgConfigService.java
  8. 280 280
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java
  9. 68 68
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionService.java
  10. 109 109
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionServiceImpl.java
  11. 50 50
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationService.java
  12. 148 148
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationServiceImpl.java
  13. 182 182
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/SpecialtyService.java
  14. 68 68
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java
  15. 228 228
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java
  16. 92 92
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/UserRoleService.java
  17. 474 474
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java
  18. 20 20
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataReceiveService.java
  19. 46 46
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataSendService.java
  20. 36 36
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/util/ExportUtils.java

+ 1 - 62
examcloud-core-basic-export/pom.xml

@@ -22,68 +22,7 @@
 			<artifactId>examcloud-core-basic-service</artifactId>
 			<version>${examcloud.version}</version>
 		</dependency>
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-util</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-dto</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-uac</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-config</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-test</artifactId>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.cloud</groupId>
-			<artifactId>spring-cloud-starter-feign</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.cloud</groupId>
-			<artifactId>spring-cloud-starter-eureka</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-web</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-data-redis</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>io.springfox</groupId>
-			<artifactId>springfox-swagger2</artifactId>
-			<version>2.6.1</version>
-		</dependency>
-		<dependency>
-			<groupId>io.springfox</groupId>
-			<artifactId>springfox-swagger-ui</artifactId>
-			<version>2.6.1</version>
-		</dependency>
-		<dependency>
-			<groupId>commons-fileupload</groupId>
-			<artifactId>commons-fileupload</artifactId>
-			<version>1.3.2</version>
-		</dependency>
-		<dependency>
-			<groupId>com.qmth.commons</groupId>
-			<artifactId>data-sync-rabbit</artifactId>
-			<version>1.0-SNAPSHOT</version>
-		</dependency>
+	
 	</dependencies>
 
 </project>

+ 62 - 0
examcloud-core-basic-service/pom.xml

@@ -17,6 +17,68 @@
 			<artifactId>examcloud-core-basic-dao</artifactId>
 			<version>${examcloud.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-util</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-dto</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-uac</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-config</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-feign</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-eureka</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-data-redis</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger2</artifactId>
+			<version>2.6.1</version>
+		</dependency>
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger-ui</artifactId>
+			<version>2.6.1</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-fileupload</groupId>
+			<artifactId>commons-fileupload</artifactId>
+			<version>1.3.2</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.commons</groupId>
+			<artifactId>data-sync-rabbit</artifactId>
+			<version>1.0-SNAPSHOT</version>
+		</dependency>
 	</dependencies>
 
 </project>

+ 203 - 203
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java

@@ -1,203 +1,203 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.criteria.Subquery;
-import javax.transaction.Transactional;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-
-import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
-import cn.com.qmth.examcloud.common.util.excel.ExcelError;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.service.core.dto.CourseDto;
-import cn.com.qmth.examcloud.service.core.entity.Course;
-import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.service.core.repo.CourseRepo;
-import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
-
-@Service
-public class CourseService {
-
-    @Autowired
-    CourseRepo courseRepo;
-
-	@Autowired
-	DataSendService dataSendService;
-
-    @Transactional
-	public List<ExcelError> importCourse(Long orgId,InputStream inputStream) {
-		List<Course> list = new ArrayList<Course>();
-		ExcelReader excelReader = new ExcelReader(CourseDto.class);
-        List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
-            @Override
-            public ExcelError handle(Object obj) {
-            	CourseDto dto = (CourseDto) obj;
-            	Course course = new Course(dto.getName(),dto.getCode());
-            	course.setOrgId(orgId);
-            	course.setCreateTime(new Date());
-				course.setEnable(true);
-            	if("ZSB".equalsIgnoreCase(dto.getLevel())){
-            		course.setLevel(CourseLevel.ZSB);
-            	}
-            	if("GQZ".equalsIgnoreCase(dto.getLevel())){
-            		course.setLevel(CourseLevel.GQZ);
-            	}
-				if("GQB".equalsIgnoreCase(dto.getLevel())){
-					course.setLevel(CourseLevel.GQB);
-				}
-            	if("ALL".equalsIgnoreCase(dto.getLevel())){
-            		course.setLevel(CourseLevel.ALL);
-            	}
-                ExcelError error = importCheck(course);
-                if (error == null) {
-					addCourse(course);
-                }
-                return error;
-            }
-        });
-		return excelErrors;
-	}
-
-	private void addCourse(Course course){
-		Course old = courseRepo.findByOrgIdAndCode(course.getOrgId(),course.getCode());
-		if(old == null){
-			Course tempCourse = courseRepo.save(course);
-			dataSendService.sendCourse(tempCourse);
-		}else{
-			old.setName(course.getName());
-			old.setLevel(course.getLevel());
-			old.setUpdateTime(new Date());
-			Course tempCourse = courseRepo.save(old);
-			dataSendService.sendCourse(tempCourse);
-		}
-	}
-
-	private ExcelError importCheck(Course course) {
-		if(StringUtils.isEmpty(course.getCode())){
-			return new ExcelError("代码不能为空");
-		}
-		if(StringUtils.isEmpty(course.getName())){
-			return new ExcelError("名称不能为空");
-		}
-		if(null == course.getLevel()){
-			return new ExcelError("层次不能为空");
-		}
-		return null;
-	}
-	
-	public Page<Course> findAll(Course courseCriteria,Long specialtyId, Pageable pageable) {
-//		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-//				.withMatcher("name", startsWith())
-//				.withMatcher("code", startsWith()).withIgnoreNullValues();
-//		Example<Course> examExamStudentple = Example.of(orgCriteria,
-//				exampleMatcher);
-//		return courseRepo.findAll(examExamStudentple, pageable);
-		Specification<Course> specification = getSpecification(courseCriteria,specialtyId);
-		Page<Course> examStudents = courseRepo.findAll(specification,pageable);
-		return examStudents;
-	}
-
-	private Specification<Course> getSpecification(Course courseCriteria,Long specialtyId) {
-		Specification<Course> specification = (root, query, cb) -> {
-		    List<Predicate> predicates = new ArrayList<>();
-		    if(!StringUtils.isEmpty(courseCriteria.getOrgId())){
-		    	predicates.add(cb.equal(root.get("orgId"),courseCriteria.getOrgId()));
-		    }
-		    if(!StringUtils.isEmpty(courseCriteria.getName())){
-		    	predicates.add(cb.like(root.get("name"),"%"+courseCriteria.getName()+"%"));
-		    }
-		    if(!StringUtils.isEmpty(courseCriteria.getCode())){
-		    	predicates.add(cb.like(root.get("code"),"%"+courseCriteria.getCode()+"%"));
-		    }
-		    if(!StringUtils.isEmpty(courseCriteria.getLevel())){
-		    	predicates.add(cb.equal(root.get("level"),courseCriteria.getLevel()));
-		    }
-		    if(!StringUtils.isEmpty(courseCriteria.getEnable())){
-		    	predicates.add(cb.equal(root.get("enable"),courseCriteria.getEnable()));
-		    }
-		    if(specialtyId!=null){
-		    	Subquery<CourseSpeciatly> relationshipSubquery = query.subquery(CourseSpeciatly.class);
-		    	Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery.from(CourseSpeciatly.class);
-		    	relationshipSubquery.select(residencyRelationshipSubqueryRoot);
-		    	Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"), specialtyId);
-		    	Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"), root.get("id"));
-		    	relationshipSubquery.where(cb.and(predicate,predicate2));
-		    	predicates.add(cb.exists(relationshipSubquery));
-		    }
-		    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-
-	public List<Course> findAll(Course courseCriteria) {
-//		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-//				.withMatcher("name", startsWith())
-//				.withMatcher("code", startsWith()).withIgnoreNullValues();
-//        Example<Course> examExample = Example.of(orgCriteria,exampleMatcher);
-//		List<Course> courseList = courseRepo.findAll(examExample);
-//        return courseList;
-		Specification<Course> specification = getSpecification(courseCriteria,null);
-        return courseRepo.findAll(specification);
-	}
-
-	public Course save(Course course) throws Exception{
-		checkCode(course.getOrgId(),course.getCode());
-		course.setCreateTime(new Date());
-		Course reCourse = courseRepo.saveAndFlush(course);
-		dataSendService.sendCourse(reCourse);
-		return reCourse;
-	}
-
-	private void checkCode(Long orgId,String code) {
-		Course old = courseRepo.findByOrgIdAndCode(orgId,code);
-		if(old!=null){
-			throw new RuntimeException("代码已存在");
-		}
-	}
-
-	@Transactional
-	public void enableCourse(List<Long> courseIds, boolean enable) {
-		for (Long courseId : courseIds) {
-			Course course = courseRepo.findOne(courseId);
-			course.setEnable(enable);
-			course.setUpdateTime(new Date());
-			Course reCourse = courseRepo.saveAndFlush(course);
-			dataSendService.sendCourse(reCourse);
-		}
-	}
-	
-	@Transactional
-	public void delete(String ids) {
-		List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
-                .collect(Collectors.toList());
-        for(Long courseId:courseIds){
-        	courseRepo.delete(courseId);
-        }
-	}
-
-	public Course update(Long id, Course course) {
-		Course old = courseRepo.findOne(id);
-		if(!old.getCode().equals(course.getCode())){
-			checkCode(course.getOrgId(),course.getCode());
-		}
-		course.setUpdateTime(new Date());
-		Course reCourse = courseRepo.saveAndFlush(course);
-		dataSendService.sendCourse(reCourse);
-		return reCourse;
-	}
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+import javax.transaction.Transactional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
+import cn.com.qmth.examcloud.service.core.dto.CourseDto;
+import cn.com.qmth.examcloud.service.core.entity.Course;
+import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
+import cn.com.qmth.examcloud.service.core.repo.CourseRepo;
+import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
+
+@Service
+public class CourseService {
+
+    @Autowired
+    CourseRepo courseRepo;
+
+	@Autowired
+	DataSendService dataSendService;
+
+    @Transactional
+	public List<ExcelError> importCourse(Long orgId,InputStream inputStream) {
+		List<Course> list = new ArrayList<Course>();
+		ExcelReader excelReader = new ExcelReader(CourseDto.class);
+        List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
+            @Override
+            public ExcelError handle(Object obj) {
+            	CourseDto dto = (CourseDto) obj;
+            	Course course = new Course(dto.getName(),dto.getCode());
+            	course.setOrgId(orgId);
+            	course.setCreateTime(new Date());
+				course.setEnable(true);
+            	if("ZSB".equalsIgnoreCase(dto.getLevel())){
+            		course.setLevel(CourseLevel.ZSB);
+            	}
+            	if("GQZ".equalsIgnoreCase(dto.getLevel())){
+            		course.setLevel(CourseLevel.GQZ);
+            	}
+				if("GQB".equalsIgnoreCase(dto.getLevel())){
+					course.setLevel(CourseLevel.GQB);
+				}
+            	if("ALL".equalsIgnoreCase(dto.getLevel())){
+            		course.setLevel(CourseLevel.ALL);
+            	}
+                ExcelError error = importCheck(course);
+                if (error == null) {
+					addCourse(course);
+                }
+                return error;
+            }
+        });
+		return excelErrors;
+	}
+
+	private void addCourse(Course course){
+		Course old = courseRepo.findByOrgIdAndCode(course.getOrgId(),course.getCode());
+		if(old == null){
+			Course tempCourse = courseRepo.save(course);
+			dataSendService.sendCourse(tempCourse);
+		}else{
+			old.setName(course.getName());
+			old.setLevel(course.getLevel());
+			old.setUpdateTime(new Date());
+			Course tempCourse = courseRepo.save(old);
+			dataSendService.sendCourse(tempCourse);
+		}
+	}
+
+	private ExcelError importCheck(Course course) {
+		if(StringUtils.isEmpty(course.getCode())){
+			return new ExcelError("代码不能为空");
+		}
+		if(StringUtils.isEmpty(course.getName())){
+			return new ExcelError("名称不能为空");
+		}
+		if(null == course.getLevel()){
+			return new ExcelError("层次不能为空");
+		}
+		return null;
+	}
+	
+	public Page<Course> findAll(Course courseCriteria,Long specialtyId, Pageable pageable) {
+//		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+//				.withMatcher("name", startsWith())
+//				.withMatcher("code", startsWith()).withIgnoreNullValues();
+//		Example<Course> examExamStudentple = Example.of(orgCriteria,
+//				exampleMatcher);
+//		return courseRepo.findAll(examExamStudentple, pageable);
+		Specification<Course> specification = getSpecification(courseCriteria,specialtyId);
+		Page<Course> examStudents = courseRepo.findAll(specification,pageable);
+		return examStudents;
+	}
+
+	private Specification<Course> getSpecification(Course courseCriteria,Long specialtyId) {
+		Specification<Course> specification = (root, query, cb) -> {
+		    List<Predicate> predicates = new ArrayList<>();
+		    if(!StringUtils.isEmpty(courseCriteria.getOrgId())){
+		    	predicates.add(cb.equal(root.get("orgId"),courseCriteria.getOrgId()));
+		    }
+		    if(!StringUtils.isEmpty(courseCriteria.getName())){
+		    	predicates.add(cb.like(root.get("name"),"%"+courseCriteria.getName()+"%"));
+		    }
+		    if(!StringUtils.isEmpty(courseCriteria.getCode())){
+		    	predicates.add(cb.like(root.get("code"),"%"+courseCriteria.getCode()+"%"));
+		    }
+		    if(!StringUtils.isEmpty(courseCriteria.getLevel())){
+		    	predicates.add(cb.equal(root.get("level"),courseCriteria.getLevel()));
+		    }
+		    if(!StringUtils.isEmpty(courseCriteria.getEnable())){
+		    	predicates.add(cb.equal(root.get("enable"),courseCriteria.getEnable()));
+		    }
+		    if(specialtyId!=null){
+		    	Subquery<CourseSpeciatly> relationshipSubquery = query.subquery(CourseSpeciatly.class);
+		    	Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery.from(CourseSpeciatly.class);
+		    	relationshipSubquery.select(residencyRelationshipSubqueryRoot);
+		    	Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"), specialtyId);
+		    	Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"), root.get("id"));
+		    	relationshipSubquery.where(cb.and(predicate,predicate2));
+		    	predicates.add(cb.exists(relationshipSubquery));
+		    }
+		    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+
+	public List<Course> findAll(Course courseCriteria) {
+//		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+//				.withMatcher("name", startsWith())
+//				.withMatcher("code", startsWith()).withIgnoreNullValues();
+//        Example<Course> examExample = Example.of(orgCriteria,exampleMatcher);
+//		List<Course> courseList = courseRepo.findAll(examExample);
+//        return courseList;
+		Specification<Course> specification = getSpecification(courseCriteria,null);
+        return courseRepo.findAll(specification);
+	}
+
+	public Course save(Course course) throws Exception{
+		checkCode(course.getOrgId(),course.getCode());
+		course.setCreateTime(new Date());
+		Course reCourse = courseRepo.saveAndFlush(course);
+		dataSendService.sendCourse(reCourse);
+		return reCourse;
+	}
+
+	private void checkCode(Long orgId,String code) {
+		Course old = courseRepo.findByOrgIdAndCode(orgId,code);
+		if(old!=null){
+			throw new RuntimeException("代码已存在");
+		}
+	}
+
+	@Transactional
+	public void enableCourse(List<Long> courseIds, boolean enable) {
+		for (Long courseId : courseIds) {
+			Course course = courseRepo.findOne(courseId);
+			course.setEnable(enable);
+			course.setUpdateTime(new Date());
+			Course reCourse = courseRepo.saveAndFlush(course);
+			dataSendService.sendCourse(reCourse);
+		}
+	}
+	
+	@Transactional
+	public void delete(String ids) {
+		List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long courseId:courseIds){
+        	courseRepo.delete(courseId);
+        }
+	}
+
+	public Course update(Long id, Course course) {
+		Course old = courseRepo.findOne(id);
+		if(!old.getCode().equals(course.getCode())){
+			checkCode(course.getOrgId(),course.getCode());
+		}
+		course.setUpdateTime(new Date());
+		Course reCourse = courseRepo.saveAndFlush(course);
+		dataSendService.sendCourse(reCourse);
+		return reCourse;
+	}
+
+}

+ 124 - 124
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseSpeciatlyService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseSpeciatlyService.java

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

+ 66 - 66
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/ExamSiteService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/ExamSiteService.java

@@ -1,66 +1,66 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import cn.com.qmth.examcloud.service.core.entity.ExamSite;
-import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
-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 java.util.Date;
-import java.util.List;
-
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
-
-@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) throws Exception{
-		checkCode(examSite.getOrgId(),examSite.getCode());
-		examSite.setCreateTime(new Date());
-		return examSiteRepo.save(examSite);
-	}
-
-	private void checkCode(Long orgId,String code) {
-		ExamSite old = examSiteRepo.findFirstByOrgIdAndCode(orgId,code);
-		if(old!=null){
-			throw new RuntimeException("代码已存在");
-		}
-	}
-
-	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);
-	}
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
+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 java.util.Date;
+import java.util.List;
+
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
+
+@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) throws Exception{
+		checkCode(examSite.getOrgId(),examSite.getCode());
+		examSite.setCreateTime(new Date());
+		return examSiteRepo.save(examSite);
+	}
+
+	private void checkCode(Long orgId,String code) {
+		ExamSite old = examSiteRepo.findFirstByOrgIdAndCode(orgId,code);
+		if(old!=null){
+			throw new RuntimeException("代码已存在");
+		}
+	}
+
+	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);
+	}
+
+}

+ 42 - 42
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/FaceSetTokenService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/FaceSetTokenService.java

@@ -1,42 +1,42 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.service.core.entity.FaceSetToken;
-import cn.com.qmth.examcloud.service.core.repo.FaceSetTokenRepo;
-
-/**
- * @author  	chenken
- * @date    	2018年1月23日 上午11:05:49
- * @company 	QMTH
- * @description FaceSetTokenService.java
- */
-@Service("faceSetTokenService")
-public class FaceSetTokenService {
-	
-	@Autowired
-	private FaceSetTokenRepo faceSetTokenRepo;
-	
-	@Autowired
-	private StudentFaceInfoService studentFaceInfoService;
-	
-	/**
-	 * 获取可用的faceSet
-	 * @return
-	 */
-	public String getEnableFaceSet(){
-		List<FaceSetToken> faceSetList = faceSetTokenRepo.findAll();
-		for(FaceSetToken faceSetToken:faceSetList){
-			String faceSet = faceSetToken.getFaceSetToken();
-			if(studentFaceInfoService.judgeFaceSetIsAvailable(faceSet)){
-				return faceSet;
-			}
-		}
-		return null;
-	}
-	
-}
-
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.service.core.entity.FaceSetToken;
+import cn.com.qmth.examcloud.service.core.repo.FaceSetTokenRepo;
+
+/**
+ * @author  	chenken
+ * @date    	2018年1月23日 上午11:05:49
+ * @company 	QMTH
+ * @description FaceSetTokenService.java
+ */
+@Service("faceSetTokenService")
+public class FaceSetTokenService {
+	
+	@Autowired
+	private FaceSetTokenRepo faceSetTokenRepo;
+	
+	@Autowired
+	private StudentFaceInfoService studentFaceInfoService;
+	
+	/**
+	 * 获取可用的faceSet
+	 * @return
+	 */
+	public String getEnableFaceSet(){
+		List<FaceSetToken> faceSetList = faceSetTokenRepo.findAll();
+		for(FaceSetToken faceSetToken:faceSetList){
+			String faceSet = faceSetToken.getFaceSetToken();
+			if(studentFaceInfoService.judgeFaceSetIsAvailable(faceSet)){
+				return faceSet;
+			}
+		}
+		return null;
+	}
+	
+}
+

+ 48 - 48
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgConfigService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgConfigService.java

@@ -1,48 +1,48 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Service;
-import org.springframework.web.bind.annotation.PathVariable;
-
-@Service
-public class OrgConfigService {
-
-	@Autowired
-	private JdbcTemplate jdbcTemplate;
-
-	/**
-	 * @param id
-	 * @param key
-	 * @return
-	 */
-	public String getOrgConfig(@PathVariable Long id, @PathVariable String key) {
-
-		List<Map<String, Object>> dataList = jdbcTemplate
-				.queryForList(" SELECT t.value from ecs_core_org_config t where t.org_id=? and t.key=?", id, key);
-
-		String value = "";
-		if (1 == dataList.size()) {
-			Map<String, Object> map = dataList.get(0);
-			value = (String) map.get("value");
-		}
-
-		return value;
-	}
-
-	/**
-	 * @param orgId
-	 * @param key
-	 * @param value
-	 */
-	public void setOrgConfig(Long orgId, String key, String value) {
-
-		jdbcTemplate.update(
-				"INSERT INTO ecs_core_org_config (org_id,`key`,`value`) VALUES (?,?,?) ON DUPLICATE KEY UPDATE `value`=?", orgId,
-				key, value, value);
-	}
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.PathVariable;
+
+@Service
+public class OrgConfigService {
+
+	@Autowired
+	private JdbcTemplate jdbcTemplate;
+
+	/**
+	 * @param id
+	 * @param key
+	 * @return
+	 */
+	public String getOrgConfig(@PathVariable Long id, @PathVariable String key) {
+
+		List<Map<String, Object>> dataList = jdbcTemplate
+				.queryForList(" SELECT t.value from ecs_core_org_config t where t.org_id=? and t.key=?", id, key);
+
+		String value = "";
+		if (1 == dataList.size()) {
+			Map<String, Object> map = dataList.get(0);
+			value = (String) map.get("value");
+		}
+
+		return value;
+	}
+
+	/**
+	 * @param orgId
+	 * @param key
+	 * @param value
+	 */
+	public void setOrgConfig(Long orgId, String key, String value) {
+
+		jdbcTemplate.update(
+				"INSERT INTO ecs_core_org_config (org_id,`key`,`value`) VALUES (?,?,?) ON DUPLICATE KEY UPDATE `value`=?", orgId,
+				key, value, value);
+	}
+
+}

+ 280 - 280
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java

@@ -1,280 +1,280 @@
-package cn.com.qmth.examcloud.service.core.service;
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.criteria.Subquery;
-
-import cn.com.qmth.examcloud.service.core.dto.OrgDto;
-import cn.com.qmth.examcloud.service.core.entity.Course;
-import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.service.core.entity.ExamSite;
-import cn.com.qmth.examcloud.service.core.entity.UserRole;
-import cn.com.qmth.examcloud.service.core.enums.OrgType;
-import cn.com.qmth.examcloud.service.core.enums.UserScope;
-import cn.com.qmth.examcloud.service.core.enums.UserType;
-import cn.com.qmth.examcloud.service.core.params.UserParam;
-import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
-import cn.com.qmth.examcloud.service.core.repo.memory.OrgMemRepo;
-import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
-
-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.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import cn.com.qmth.examcloud.common.util.excel.ExcelError;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.service.core.entity.Org;
-import cn.com.qmth.examcloud.service.core.entity.User;
-import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserRepo;
-
-@Service
-public class OrgService {
-
-    @Autowired
-    OrgRepo orgRepo;
-
-    @Autowired
-    UserRepo userRepo;
-
-	@Autowired
-	ExamSiteRepo examSiteRepo;
-
-	@Autowired
-	DataSendService dataSendService;
-
-	@Autowired
-	OrgMemRepo orgMemRepo;
-
-    @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) {
-		Org org = orgRepo.findFirstByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
-		if (org == null) {
-
-			Org tempOrg = orgRepo.save(orgAssembler(orgDto));
-			orgDto.setId(tempOrg.getId());
-			examSiteRepo.save(examSiteAssembler(orgDto));
-			createOrgUser(tempOrg);
-
-		} else {
-
-			org.setName(orgDto.getName());
-			org.setContacts(orgDto.getContacts());
-			org.setTelphone(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());
-//				examSite.setContacts(orgDto.getContacts());
-//				examSite.setTelphone(orgDto.getTelphone());
-				examSiteRepo.save(examSite);
-			}
-		}
-
-	}
-
-	/**
-	 * 创建学习中心用户
-	 * @param tempOrg
-     */
-	private void createOrgUser(Org tempOrg){
-		User user = new User(tempOrg.getName(), UserScope.ORG, tempOrg.getRootId(), tempOrg.getId(), UserType.NOT_STUDENT);
-		user.setLoginName(tempOrg.getCode());
-		user.setEnable(true);
-		user.setCreateTime(new Date());
-		user.setPassword(UserParam.DEFAULT_PASSWORD);
-		List<UserRole> userRoles = new ArrayList<UserRole>();
-		userRoles.add(new UserRole("ecs_exam_work", "LC_USER"));
-		user.setUserRoles(userRoles);
-		userRepo.save(user);
-	}
-
-	private Org orgAssembler(OrgDto orgDto){
-		Org org = new Org();
-		org.setRootId(orgDto.getRootId());
-		org.setParentId(orgDto.getParentId());
-		org.setCode(orgDto.getCode());
-		org.setName(orgDto.getName());
-		org.setContacts(orgDto.getContacts());
-		org.setTelphone(orgDto.getTelphone());
-		org.setCreateTime(new Date());
-		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.setContacts(orgDto.getContacts());
-//		examSite.setTelphone(orgDto.getTelphone());
-		examSite.setCreateTime(new Date());
-		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 Org enableSchool(Long id, boolean enable) {
-		Org org = orgRepo.findOne(id);
-		org.setEnable(enable);
-		orgRepo.save(org);
-		if(enable == false){
-			List<User> users = userRepo.findByOrgId(id);
-			for (User user : users) {
-				user.setEnable(false);
-				userRepo.save(user);
-			}
-		}
-		return org;
-	}
-
-	public Page<Org> findAll(Org orgCriteria, Pageable pageable) {
-		if(orgCriteria.getType() == null){
-			Specification<Org> specification = getSpecification(orgCriteria);
-			return orgRepo.findAll(specification,pageable);
-		}
-		//orgCriteria.setType(OrgType.SCHOOL);
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-				.withMatcher("name", contains())
-				.withMatcher("code", contains());
-		Example<Org> examExamStudentple = Example.of(orgCriteria,
-				exampleMatcher);
-		return orgRepo.findAll(examExamStudentple, pageable);
-	}
-	
-	private Specification<Org> getSpecification(Org orgCriteria) {
-		Specification<Org> specification = (root, query, cb) -> {
-		    List<Predicate> predicates = new ArrayList<>();
-		    if(!StringUtils.isEmpty(orgCriteria.getName())){
-		    	predicates.add(cb.equal(root.get("name"),orgCriteria.getName()));
-		    }
-		    if(!StringUtils.isEmpty(orgCriteria.getCode())){
-		    	predicates.add(cb.equal(root.get("code"),orgCriteria.getCode()));
-		    }
-		    predicates.add(cb.notEqual(root.get("type"), OrgType.SCHOOL));
-		    predicates.add(cb.equal(root.get("parentId"),orgCriteria.getParentId()));
-		    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-
-	public List<Org> findAll(Org orgCriteria) {
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-				.withMatcher("name", contains())
-				.withMatcher("code", contains());
-        Example<Org> examExample = Example.of(orgCriteria,exampleMatcher);
-        return orgRepo.findAll(examExample);
-	}
-
-	public Org save(Org org) throws Exception{
-		checkCode(org.getParentId(),org.getCode());
-		org.setCreateTime(new Date());
-		Org reOrg = orgRepo.save(org);
-		dataSendService.sendOrg(reOrg);
-		//删除缓存
-		orgMemRepo.remove(reOrg.getId());
-		return reOrg;
-	}
-
-	private void checkCode(Long parentId,String code) {
-		Org old = orgRepo.findFirstByParentIdAndCode(parentId,code);
-		if(old!=null){
-			throw new RuntimeException("代码已存在");
-		}
-	}
-
-	public Org update(Long id, Org org) {
-		Org old = orgRepo.findOne(id);
-		if(!old.getCode().equals(org.getCode())){
-			checkCode(org.getParentId(),org.getCode());
-		}
-		org.setUpdateTime(new Date());
-		Org reOrg = orgRepo.save(org);
-		dataSendService.sendOrg(reOrg);
-		//删除缓存
-		orgMemRepo.remove(reOrg.getId());
-		return reOrg;
-	}
-
-	public Org findOne(Long id){
-		Org cacheOrg = orgMemRepo.get(id);
-		if(cacheOrg != null){
-			return cacheOrg;
-		}else{
-			Org org = orgRepo.findOne(id);
-			if(org != null){
-				orgMemRepo.set(id,org);
-			}
-			return org;
-		}
-	}
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+
+import cn.com.qmth.examcloud.service.core.dto.OrgDto;
+import cn.com.qmth.examcloud.service.core.entity.Course;
+import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
+import cn.com.qmth.examcloud.service.core.entity.UserRole;
+import cn.com.qmth.examcloud.service.core.enums.OrgType;
+import cn.com.qmth.examcloud.service.core.enums.UserScope;
+import cn.com.qmth.examcloud.service.core.enums.UserType;
+import cn.com.qmth.examcloud.service.core.params.UserParam;
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
+import cn.com.qmth.examcloud.service.core.repo.memory.OrgMemRepo;
+import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
+
+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.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import cn.com.qmth.examcloud.service.core.entity.User;
+import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
+
+@Service
+public class OrgService {
+
+    @Autowired
+    OrgRepo orgRepo;
+
+    @Autowired
+    UserRepo userRepo;
+
+	@Autowired
+	ExamSiteRepo examSiteRepo;
+
+	@Autowired
+	DataSendService dataSendService;
+
+	@Autowired
+	OrgMemRepo orgMemRepo;
+
+    @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) {
+		Org org = orgRepo.findFirstByParentIdAndCode(orgDto.getParentId(), orgDto.getCode());
+		if (org == null) {
+
+			Org tempOrg = orgRepo.save(orgAssembler(orgDto));
+			orgDto.setId(tempOrg.getId());
+			examSiteRepo.save(examSiteAssembler(orgDto));
+			createOrgUser(tempOrg);
+
+		} else {
+
+			org.setName(orgDto.getName());
+			org.setContacts(orgDto.getContacts());
+			org.setTelphone(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());
+//				examSite.setContacts(orgDto.getContacts());
+//				examSite.setTelphone(orgDto.getTelphone());
+				examSiteRepo.save(examSite);
+			}
+		}
+
+	}
+
+	/**
+	 * 创建学习中心用户
+	 * @param tempOrg
+     */
+	private void createOrgUser(Org tempOrg){
+		User user = new User(tempOrg.getName(), UserScope.ORG, tempOrg.getRootId(), tempOrg.getId(), UserType.NOT_STUDENT);
+		user.setLoginName(tempOrg.getCode());
+		user.setEnable(true);
+		user.setCreateTime(new Date());
+		user.setPassword(UserParam.DEFAULT_PASSWORD);
+		List<UserRole> userRoles = new ArrayList<UserRole>();
+		userRoles.add(new UserRole("ecs_exam_work", "LC_USER"));
+		user.setUserRoles(userRoles);
+		userRepo.save(user);
+	}
+
+	private Org orgAssembler(OrgDto orgDto){
+		Org org = new Org();
+		org.setRootId(orgDto.getRootId());
+		org.setParentId(orgDto.getParentId());
+		org.setCode(orgDto.getCode());
+		org.setName(orgDto.getName());
+		org.setContacts(orgDto.getContacts());
+		org.setTelphone(orgDto.getTelphone());
+		org.setCreateTime(new Date());
+		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.setContacts(orgDto.getContacts());
+//		examSite.setTelphone(orgDto.getTelphone());
+		examSite.setCreateTime(new Date());
+		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 Org enableSchool(Long id, boolean enable) {
+		Org org = orgRepo.findOne(id);
+		org.setEnable(enable);
+		orgRepo.save(org);
+		if(enable == false){
+			List<User> users = userRepo.findByOrgId(id);
+			for (User user : users) {
+				user.setEnable(false);
+				userRepo.save(user);
+			}
+		}
+		return org;
+	}
+
+	public Page<Org> findAll(Org orgCriteria, Pageable pageable) {
+		if(orgCriteria.getType() == null){
+			Specification<Org> specification = getSpecification(orgCriteria);
+			return orgRepo.findAll(specification,pageable);
+		}
+		//orgCriteria.setType(OrgType.SCHOOL);
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
+		Example<Org> examExamStudentple = Example.of(orgCriteria,
+				exampleMatcher);
+		return orgRepo.findAll(examExamStudentple, pageable);
+	}
+	
+	private Specification<Org> getSpecification(Org orgCriteria) {
+		Specification<Org> specification = (root, query, cb) -> {
+		    List<Predicate> predicates = new ArrayList<>();
+		    if(!StringUtils.isEmpty(orgCriteria.getName())){
+		    	predicates.add(cb.equal(root.get("name"),orgCriteria.getName()));
+		    }
+		    if(!StringUtils.isEmpty(orgCriteria.getCode())){
+		    	predicates.add(cb.equal(root.get("code"),orgCriteria.getCode()));
+		    }
+		    predicates.add(cb.notEqual(root.get("type"), OrgType.SCHOOL));
+		    predicates.add(cb.equal(root.get("parentId"),orgCriteria.getParentId()));
+		    return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+
+	public List<Org> findAll(Org orgCriteria) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
+        Example<Org> examExample = Example.of(orgCriteria,exampleMatcher);
+        return orgRepo.findAll(examExample);
+	}
+
+	public Org save(Org org) throws Exception{
+		checkCode(org.getParentId(),org.getCode());
+		org.setCreateTime(new Date());
+		Org reOrg = orgRepo.save(org);
+		dataSendService.sendOrg(reOrg);
+		//删除缓存
+		orgMemRepo.remove(reOrg.getId());
+		return reOrg;
+	}
+
+	private void checkCode(Long parentId,String code) {
+		Org old = orgRepo.findFirstByParentIdAndCode(parentId,code);
+		if(old!=null){
+			throw new RuntimeException("代码已存在");
+		}
+	}
+
+	public Org update(Long id, Org org) {
+		Org old = orgRepo.findOne(id);
+		if(!old.getCode().equals(org.getCode())){
+			checkCode(org.getParentId(),org.getCode());
+		}
+		org.setUpdateTime(new Date());
+		Org reOrg = orgRepo.save(org);
+		dataSendService.sendOrg(reOrg);
+		//删除缓存
+		orgMemRepo.remove(reOrg.getId());
+		return reOrg;
+	}
+
+	public Org findOne(Long id){
+		Org cacheOrg = orgMemRepo.get(id);
+		if(cacheOrg != null){
+			return cacheOrg;
+		}else{
+			Org org = orgRepo.findOne(id);
+			if(org != null){
+				orgMemRepo.set(id,org);
+			}
+			return org;
+		}
+	}
+
+}

+ 68 - 68
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionService.java

@@ -1,68 +1,68 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.List;
-import java.util.Map;
-
-import cn.com.qmth.examcloud.service.core.entity.Permission;
-
-
-/**
- * 
- * @author  	chenken
- * @date    	2017年6月15日下午3:27:59
- * @company 	QMTH
- * @description
- */
-public interface PermissionService {
-	/**
-	 * 保存权限
-	 * @param permission
-	 */
-	public void savePermission(Permission permission);
-	
-	/**
-	 * 按照对象查询
-	 * @param permission
-	 * @return
-	 */
-	public List<Permission> findByPermission(Permission permission);
-	
-	/**
-	 * 按系统取出权限
-	 * @param systemName
-	 * @return
-	 */
-	public Map<String,List<Permission>> findPermissionsBySystem(String systemName);
-	/**
-	 * 按ID查询权限
-	 * @return
-	 */
-	public Permission findById(int id);
-	/**
-	 * 按ID集合查询权限 IDS
-	 * @param ids
-	 * @return
-	 */
-	public List<Permission> findPermissionByIds(List<Integer> ids);
-	
-	//by weiwenhai
-	/**
-	 * 根据id删除权限
-	 * @param id
-	 */
-	public void deletePermissionById(Integer id);
-	
-	/**
-	 * 根据父级权限id查询所有子权限
-	 * @param id
-	 * @return
-	 */
-	public List<Permission> findPermissionByParentId(Integer id);
-	
-	/**
-	 * 根据权限id删除权限
-	 * @param id
-	 * @return
-	 */
-	public Map<String,String> deletePermission(Integer id);
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+import java.util.Map;
+
+import cn.com.qmth.examcloud.service.core.entity.Permission;
+
+
+/**
+ * 
+ * @author  	chenken
+ * @date    	2017年6月15日下午3:27:59
+ * @company 	QMTH
+ * @description
+ */
+public interface PermissionService {
+	/**
+	 * 保存权限
+	 * @param permission
+	 */
+	public void savePermission(Permission permission);
+	
+	/**
+	 * 按照对象查询
+	 * @param permission
+	 * @return
+	 */
+	public List<Permission> findByPermission(Permission permission);
+	
+	/**
+	 * 按系统取出权限
+	 * @param systemName
+	 * @return
+	 */
+	public Map<String,List<Permission>> findPermissionsBySystem(String systemName);
+	/**
+	 * 按ID查询权限
+	 * @return
+	 */
+	public Permission findById(int id);
+	/**
+	 * 按ID集合查询权限 IDS
+	 * @param ids
+	 * @return
+	 */
+	public List<Permission> findPermissionByIds(List<Integer> ids);
+	
+	//by weiwenhai
+	/**
+	 * 根据id删除权限
+	 * @param id
+	 */
+	public void deletePermissionById(Integer id);
+	
+	/**
+	 * 根据父级权限id查询所有子权限
+	 * @param id
+	 * @return
+	 */
+	public List<Permission> findPermissionByParentId(Integer id);
+	
+	/**
+	 * 根据权限id删除权限
+	 * @param id
+	 * @return
+	 */
+	public Map<String,String> deletePermission(Integer id);
+}

+ 109 - 109
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionServiceImpl.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/PermissionServiceImpl.java

@@ -1,109 +1,109 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.service.core.entity.Permission;
-import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
-import cn.com.qmth.examcloud.service.core.enums.PermissionType;
-import cn.com.qmth.examcloud.service.core.repo.PermissionRepo;
-
-/**
- * 
- * @author  	chenken
- * @date    	2017年6月15日下午3:06:45
- * @company 	QMTH
- * @description	权限service
- */
-@Service("permissionService")
-public class PermissionServiceImpl implements PermissionService{
-	
-	@Autowired
-	private PermissionRepo permissionRepo;
-	
-	@Autowired
-	private RolePermissionRelationService rolePermissionRelationService;
-	
-	@Override
-	public void savePermission(Permission permission) {
-		permissionRepo.save(permission);
-	}
-
-	@Override
-	public Map<String,List<Permission>> findPermissionsBySystem(String systemName) {
-		Map<String,List<Permission>> returnMap = new HashMap<String, List<Permission>>();
-		String menuType = PermissionType.MENU.name();
-		returnMap.put(menuType, permissionRepo.findBySystemNameAndType(systemName,menuType));
-		String pageType = PermissionType.PAGE.name();
-		returnMap.put(pageType, permissionRepo.findBySystemNameAndType(systemName,pageType));
-		return returnMap;
-	}
-
-	@Override
-	public Permission findById(int id) {
-		return permissionRepo.findOne(id);
-	}
-
-	@Override
-	public List<Permission> findPermissionByIds(List<Integer> ids) {
-		return permissionRepo.findByIdIn(ids);
-	}
-
-	@Override
-	public List<Permission> findByPermission(Permission permission) {
-		return permissionRepo.findAll(Example.of(permission));
-	}
-
-	//by weiwenhai 根据id删除权限
-	@Override
-	public void deletePermissionById(Integer id) {
-		permissionRepo.delete(id);
-	}
-
-	//根据父级权限id查询所有子权限
-	@Override
-	public List<Permission> findPermissionByParentId(Integer id) {
-		return permissionRepo.findByParentId(id);
-	}
-
-	@Override
-	public Map<String, String> deletePermission(Integer id) {
-		Map<String,String> map = new HashMap<String,String>();
-		List<RolePermissionRelation> rolePermissionRelations = rolePermissionRelationService.findRolePermissionRelationByPermissonId(id);
-		//首先判断该权限能否删除
-		if(rolePermissionRelations.size()>0){
-			map.put("message", "该权限在使用中,无法删除");
-			map.put("messageType", "warning");
-			return map;
-		}else{
-			Permission permission = findById(id);
-			//然后判断该权限是否有父级
-			if(permission.getParentId()!= null){
-				deletePermissionById(id);
-				map.put("message", "删除成功");
-				map.put("messageType", "success");
-				return map;
-			}else{
-				//最后判断父级下的权限是否删除
-				List<Permission> permission_son = findPermissionByParentId(id);
-				if(permission_son.size()>0){
-					map.put("message", "存在子级菜单,无法删除");
-					map.put("messageType", "warning");
-					return map;
-				}
-				deletePermissionById(id);
-				map.put("message", "删除成功");
-				map.put("messageType", "success");
-				return map;
-			}
-		}
-	}
-	
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.service.core.entity.Permission;
+import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
+import cn.com.qmth.examcloud.service.core.enums.PermissionType;
+import cn.com.qmth.examcloud.service.core.repo.PermissionRepo;
+
+/**
+ * 
+ * @author  	chenken
+ * @date    	2017年6月15日下午3:06:45
+ * @company 	QMTH
+ * @description	权限service
+ */
+@Service("permissionService")
+public class PermissionServiceImpl implements PermissionService{
+	
+	@Autowired
+	private PermissionRepo permissionRepo;
+	
+	@Autowired
+	private RolePermissionRelationService rolePermissionRelationService;
+	
+	@Override
+	public void savePermission(Permission permission) {
+		permissionRepo.save(permission);
+	}
+
+	@Override
+	public Map<String,List<Permission>> findPermissionsBySystem(String systemName) {
+		Map<String,List<Permission>> returnMap = new HashMap<String, List<Permission>>();
+		String menuType = PermissionType.MENU.name();
+		returnMap.put(menuType, permissionRepo.findBySystemNameAndType(systemName,menuType));
+		String pageType = PermissionType.PAGE.name();
+		returnMap.put(pageType, permissionRepo.findBySystemNameAndType(systemName,pageType));
+		return returnMap;
+	}
+
+	@Override
+	public Permission findById(int id) {
+		return permissionRepo.findOne(id);
+	}
+
+	@Override
+	public List<Permission> findPermissionByIds(List<Integer> ids) {
+		return permissionRepo.findByIdIn(ids);
+	}
+
+	@Override
+	public List<Permission> findByPermission(Permission permission) {
+		return permissionRepo.findAll(Example.of(permission));
+	}
+
+	//by weiwenhai 根据id删除权限
+	@Override
+	public void deletePermissionById(Integer id) {
+		permissionRepo.delete(id);
+	}
+
+	//根据父级权限id查询所有子权限
+	@Override
+	public List<Permission> findPermissionByParentId(Integer id) {
+		return permissionRepo.findByParentId(id);
+	}
+
+	@Override
+	public Map<String, String> deletePermission(Integer id) {
+		Map<String,String> map = new HashMap<String,String>();
+		List<RolePermissionRelation> rolePermissionRelations = rolePermissionRelationService.findRolePermissionRelationByPermissonId(id);
+		//首先判断该权限能否删除
+		if(rolePermissionRelations.size()>0){
+			map.put("message", "该权限在使用中,无法删除");
+			map.put("messageType", "warning");
+			return map;
+		}else{
+			Permission permission = findById(id);
+			//然后判断该权限是否有父级
+			if(permission.getParentId()!= null){
+				deletePermissionById(id);
+				map.put("message", "删除成功");
+				map.put("messageType", "success");
+				return map;
+			}else{
+				//最后判断父级下的权限是否删除
+				List<Permission> permission_son = findPermissionByParentId(id);
+				if(permission_son.size()>0){
+					map.put("message", "存在子级菜单,无法删除");
+					map.put("messageType", "warning");
+					return map;
+				}
+				deletePermissionById(id);
+				map.put("message", "删除成功");
+				map.put("messageType", "success");
+				return map;
+			}
+		}
+	}
+	
+}

+ 50 - 50
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationService.java

@@ -1,50 +1,50 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.List;
-import java.util.Map;
-
-import cn.com.qmth.examcloud.service.core.entity.Permission;
-import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
-
-/**
- * 
- * @author  	chenken
- * @date    	2017年6月15日下午5:26:13
- * @company 	QMTH
- * @description 角色权限关联
- */
-public interface RolePermissionRelationService {
-	/**
-	 * 根据角色查询权限
-	 * @param roleName
-	 * @param systemName
-	 * @return
-	 */
-	public Map<String,List<Permission>> findPermissionByRole(RolePermissionRelation rolePermissionRelation);
-	/**
-	 * 保存角色权限
-	 * @param rolePermissionRelation
-	 */
-	public void saveRolePermission(RolePermissionRelation rolePermissionRelation);
-	/**
-	 * 删除角色权限
-	 * @param roleName
-	 * @param systemName
-	 */
-	public void deleteRolePermission(String roleName,String systemName,String permissionType);
-	/**
-	 * 根据角色和系统查询
-	 * @param systemName
-	 * @param roleCode
-	 * @return
-	 */
-	public List<RolePermissionRelation> findPermission(String systemName,String roleCode,String permissionType);
-	
-	//by weiwenhai
-	/**
-	 * 根据权限id查询权限角色
-	 * @param id
-	 * @return
-	 */
-	public List<RolePermissionRelation> findRolePermissionRelationByPermissonId(Integer id);
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+import java.util.Map;
+
+import cn.com.qmth.examcloud.service.core.entity.Permission;
+import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
+
+/**
+ * 
+ * @author  	chenken
+ * @date    	2017年6月15日下午5:26:13
+ * @company 	QMTH
+ * @description 角色权限关联
+ */
+public interface RolePermissionRelationService {
+	/**
+	 * 根据角色查询权限
+	 * @param roleName
+	 * @param systemName
+	 * @return
+	 */
+	public Map<String,List<Permission>> findPermissionByRole(RolePermissionRelation rolePermissionRelation);
+	/**
+	 * 保存角色权限
+	 * @param rolePermissionRelation
+	 */
+	public void saveRolePermission(RolePermissionRelation rolePermissionRelation);
+	/**
+	 * 删除角色权限
+	 * @param roleName
+	 * @param systemName
+	 */
+	public void deleteRolePermission(String roleName,String systemName,String permissionType);
+	/**
+	 * 根据角色和系统查询
+	 * @param systemName
+	 * @param roleCode
+	 * @return
+	 */
+	public List<RolePermissionRelation> findPermission(String systemName,String roleCode,String permissionType);
+	
+	//by weiwenhai
+	/**
+	 * 根据权限id查询权限角色
+	 * @param id
+	 * @return
+	 */
+	public List<RolePermissionRelation> findRolePermissionRelationByPermissonId(Integer id);
+}

+ 148 - 148
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationServiceImpl.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/RolePermissionRelationServiceImpl.java

@@ -1,148 +1,148 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.Assert;
-
-import cn.com.qmth.examcloud.service.core.entity.Permission;
-import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
-import cn.com.qmth.examcloud.service.core.enums.PermissionType;
-import cn.com.qmth.examcloud.service.core.repo.RolePermissionRelationRepo;
-
-
-/**
- * 
- * @author  	chenken
- * @date    	2017年6月15日下午3:15:53
- * @company 	QMTH
- * @description
- */
-@Service("rolePermissionRelationService")
-public class RolePermissionRelationServiceImpl implements RolePermissionRelationService{
-
-	@Autowired
-	private RolePermissionRelationRepo rolePermissionRelationRepo;
-	@Autowired
-	private PermissionService permissionService;
-	
-	@Override
-	public Map<String,List<Permission>> findPermissionByRole(RolePermissionRelation rolePermissionRelation) {
-		Map<String,List<Permission>> returnMap = new HashMap<String, List<Permission>>();
-		String menuType = PermissionType.MENU.name();
-		returnMap.put(menuType,findMenuPermissionByRole(rolePermissionRelation));
-		String pageType = PermissionType.PAGE.name();
-		returnMap.put(pageType,findPagePermissionByRole(rolePermissionRelation));
-		return returnMap;
-	}
-	
-	/**
-	 * 查询菜单权限
-	 * @param rolePermissionRelation
-	 * @return
-	 */
-	private List<Permission> findMenuPermissionByRole(RolePermissionRelation rolePermissionRelation){ 
-		List<String> roleCodes = rolePermissionRelation.getRoleCodes();
-		List<RolePermissionRelation> relations = new ArrayList<RolePermissionRelation>();
-		for(String roleCode:roleCodes){
-			String systemName = rolePermissionRelation.getSystemName();
-			String permissionType = PermissionType.MENU.name();
-			relations.addAll(rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType));
-		}
-		Set<Integer> permissionIds = new HashSet<Integer>();
-		for(RolePermissionRelation relation:relations){
-			permissionIds.add(relation.getPermissionId());
-		}
-		List<Integer> ids = new ArrayList<Integer>(permissionIds);
-		List<Permission> permissions = permissionService.findPermissionByIds(ids);
-		//组装树形关系结构
-		Map<Integer,Permission> permissionMap = new HashMap<Integer, Permission>();
-		for(Permission permission:permissions){
-			permissionMap.put(permission.getId(), permission);
-		}
-		for(Permission p:permissions){
-			Permission permission = permissionMap.get(p.getParentId());
-			if(permission!=null){
-				if(permission.getSubPermissions()==null){
-					permission.setSubPermissions(new ArrayList<Permission>());
-				}
-				permission.getSubPermissions().add(p);
-			}
-		}
-		 // 返回一级节点
-		List<Permission> permissionNodes = new ArrayList<Permission>();
-		for(Permission permission:permissions){
-			if(permission.getParentId()==null){
-				permissionNodes.add(permission);
-			}
-		}
-		return permissionNodes;
-	}
-
-	/**
-	 * 查询菜单权限
-	 * @param rolePermissionRelation
-	 * @return
-	 */
-	private List<Permission> findPagePermissionByRole(RolePermissionRelation rolePermissionRelation){ 
-		List<String> roleCodes = rolePermissionRelation.getRoleCodes();
-		List<RolePermissionRelation> relations = new ArrayList<RolePermissionRelation>();
-		for(String roleCode:roleCodes){
-			String systemName = rolePermissionRelation.getSystemName();
-			String permissionType = PermissionType.PAGE.name();
-			relations.addAll(rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType));
-		}
-		Set<Integer> permissionIds = new HashSet<Integer>();
-		for(RolePermissionRelation relation:relations){
-			permissionIds.add(relation.getPermissionId());
-		}
-		List<Integer> ids = new ArrayList<Integer>(permissionIds);
-		List<Permission> permissions = permissionService.findPermissionByIds(ids);
-		return permissions;
-	}
-	
-	@Override
-	@Transactional
-	public void saveRolePermission(RolePermissionRelation rolePermissionRelation) {
-		String roleCode = rolePermissionRelation.getRoleCode();
-		String systemName = rolePermissionRelation.getSystemName();
-		String permissionType = rolePermissionRelation.getPermissionType();
-		deleteRolePermission(roleCode, systemName,permissionType);
-		List<RolePermissionRelation> relationList = new ArrayList<RolePermissionRelation>(); 
-		for(Integer permissionId:rolePermissionRelation.getPermissionIds()){
-			RolePermissionRelation relation = new RolePermissionRelation();
-			relation.setRoleCode(roleCode);
-			relation.setSystemName(systemName);
-			relation.setPermissionType(permissionType);
-			relation.setPermissionId(permissionId);
-			relationList.add(relation);
-		}
-		rolePermissionRelationRepo.save(relationList);
-	}
-
-	@Override
-	public void deleteRolePermission(String roleCode, String systemName,String permissionType) {
-		rolePermissionRelationRepo.deleteByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType);
-	}
-
-	@Override
-	public List<RolePermissionRelation> findPermission(String systemName,String roleCode,String permissionType) {
-		Assert.hasLength(systemName, "systemName 不能为空");		
-		Assert.hasLength(roleCode, "roleCode 不能为空");		
-		return rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName, permissionType);
-	}
-
-	//by weiwenhai 根据权限id查询权限角色
-	@Override
-	public List<RolePermissionRelation> findRolePermissionRelationByPermissonId(Integer id) {
-		return rolePermissionRelationRepo.findByPermissionId(id);
-	}
-	
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
+
+import cn.com.qmth.examcloud.service.core.entity.Permission;
+import cn.com.qmth.examcloud.service.core.entity.RolePermissionRelation;
+import cn.com.qmth.examcloud.service.core.enums.PermissionType;
+import cn.com.qmth.examcloud.service.core.repo.RolePermissionRelationRepo;
+
+
+/**
+ * 
+ * @author  	chenken
+ * @date    	2017年6月15日下午3:15:53
+ * @company 	QMTH
+ * @description
+ */
+@Service("rolePermissionRelationService")
+public class RolePermissionRelationServiceImpl implements RolePermissionRelationService{
+
+	@Autowired
+	private RolePermissionRelationRepo rolePermissionRelationRepo;
+	@Autowired
+	private PermissionService permissionService;
+	
+	@Override
+	public Map<String,List<Permission>> findPermissionByRole(RolePermissionRelation rolePermissionRelation) {
+		Map<String,List<Permission>> returnMap = new HashMap<String, List<Permission>>();
+		String menuType = PermissionType.MENU.name();
+		returnMap.put(menuType,findMenuPermissionByRole(rolePermissionRelation));
+		String pageType = PermissionType.PAGE.name();
+		returnMap.put(pageType,findPagePermissionByRole(rolePermissionRelation));
+		return returnMap;
+	}
+	
+	/**
+	 * 查询菜单权限
+	 * @param rolePermissionRelation
+	 * @return
+	 */
+	private List<Permission> findMenuPermissionByRole(RolePermissionRelation rolePermissionRelation){ 
+		List<String> roleCodes = rolePermissionRelation.getRoleCodes();
+		List<RolePermissionRelation> relations = new ArrayList<RolePermissionRelation>();
+		for(String roleCode:roleCodes){
+			String systemName = rolePermissionRelation.getSystemName();
+			String permissionType = PermissionType.MENU.name();
+			relations.addAll(rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType));
+		}
+		Set<Integer> permissionIds = new HashSet<Integer>();
+		for(RolePermissionRelation relation:relations){
+			permissionIds.add(relation.getPermissionId());
+		}
+		List<Integer> ids = new ArrayList<Integer>(permissionIds);
+		List<Permission> permissions = permissionService.findPermissionByIds(ids);
+		//组装树形关系结构
+		Map<Integer,Permission> permissionMap = new HashMap<Integer, Permission>();
+		for(Permission permission:permissions){
+			permissionMap.put(permission.getId(), permission);
+		}
+		for(Permission p:permissions){
+			Permission permission = permissionMap.get(p.getParentId());
+			if(permission!=null){
+				if(permission.getSubPermissions()==null){
+					permission.setSubPermissions(new ArrayList<Permission>());
+				}
+				permission.getSubPermissions().add(p);
+			}
+		}
+		 // 返回一级节点
+		List<Permission> permissionNodes = new ArrayList<Permission>();
+		for(Permission permission:permissions){
+			if(permission.getParentId()==null){
+				permissionNodes.add(permission);
+			}
+		}
+		return permissionNodes;
+	}
+
+	/**
+	 * 查询菜单权限
+	 * @param rolePermissionRelation
+	 * @return
+	 */
+	private List<Permission> findPagePermissionByRole(RolePermissionRelation rolePermissionRelation){ 
+		List<String> roleCodes = rolePermissionRelation.getRoleCodes();
+		List<RolePermissionRelation> relations = new ArrayList<RolePermissionRelation>();
+		for(String roleCode:roleCodes){
+			String systemName = rolePermissionRelation.getSystemName();
+			String permissionType = PermissionType.PAGE.name();
+			relations.addAll(rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType));
+		}
+		Set<Integer> permissionIds = new HashSet<Integer>();
+		for(RolePermissionRelation relation:relations){
+			permissionIds.add(relation.getPermissionId());
+		}
+		List<Integer> ids = new ArrayList<Integer>(permissionIds);
+		List<Permission> permissions = permissionService.findPermissionByIds(ids);
+		return permissions;
+	}
+	
+	@Override
+	@Transactional
+	public void saveRolePermission(RolePermissionRelation rolePermissionRelation) {
+		String roleCode = rolePermissionRelation.getRoleCode();
+		String systemName = rolePermissionRelation.getSystemName();
+		String permissionType = rolePermissionRelation.getPermissionType();
+		deleteRolePermission(roleCode, systemName,permissionType);
+		List<RolePermissionRelation> relationList = new ArrayList<RolePermissionRelation>(); 
+		for(Integer permissionId:rolePermissionRelation.getPermissionIds()){
+			RolePermissionRelation relation = new RolePermissionRelation();
+			relation.setRoleCode(roleCode);
+			relation.setSystemName(systemName);
+			relation.setPermissionType(permissionType);
+			relation.setPermissionId(permissionId);
+			relationList.add(relation);
+		}
+		rolePermissionRelationRepo.save(relationList);
+	}
+
+	@Override
+	public void deleteRolePermission(String roleCode, String systemName,String permissionType) {
+		rolePermissionRelationRepo.deleteByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName,permissionType);
+	}
+
+	@Override
+	public List<RolePermissionRelation> findPermission(String systemName,String roleCode,String permissionType) {
+		Assert.hasLength(systemName, "systemName 不能为空");		
+		Assert.hasLength(roleCode, "roleCode 不能为空");		
+		return rolePermissionRelationRepo.findByRoleCodeAndSystemNameAndPermissionType(roleCode, systemName, permissionType);
+	}
+
+	//by weiwenhai 根据权限id查询权限角色
+	@Override
+	public List<RolePermissionRelation> findRolePermissionRelationByPermissonId(Integer id) {
+		return rolePermissionRelationRepo.findByPermissionId(id);
+	}
+	
+}

+ 182 - 182
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/SpecialtyService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/SpecialtyService.java

@@ -1,182 +1,182 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.criteria.Subquery;
-import javax.transaction.Transactional;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-
-import cn.com.qmth.examcloud.common.util.excel.ExcelError;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.service.core.dto.SpecialtyDto;
-import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.service.core.entity.Specialty;
-import cn.com.qmth.examcloud.service.core.repo.SpecialtyRepo;
-import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
-
-@Service
-public class SpecialtyService {
-
-	@Autowired
-	SpecialtyRepo specialtyRepo;
-	@Autowired
-	DataSendService dataSendService;
-
-
-	@Transactional
-	public List<ExcelError> importSpecialty(Long orgId, InputStream inputStream) {
-		List<Specialty> list = new ArrayList<Specialty>();
-		ExcelReader excelReader = new ExcelReader(SpecialtyDto.class);
-		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
-			@Override
-			public ExcelError handle(Object obj) {
-				SpecialtyDto dto = (SpecialtyDto) obj;
-				Specialty specialty = new Specialty(dto.getCode(),dto.getName());
-				specialty.setOrgId(orgId);
-				specialty.setCreateTime(new Date());
-				specialty.setEnable(true);
-				ExcelError error = importCheck(specialty);
-				if (error == null) {
-					addSpecialty(specialty);
-				}
-				return error;
-			}
-		});
-		return excelErrors;
-	}
-
-	private void addSpecialty(Specialty specialty){
-		Specialty old = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(),specialty.getCode());
-		if(old == null){
-			Specialty tempSpecialty = specialtyRepo.save(specialty);
-			dataSendService.sendSpecialty(tempSpecialty);
-		}else{
-			old.setName(specialty.getName());
-			old.setUpdateTime(new Date());
-			Specialty tempSpecialty = specialtyRepo.save(old);
-			dataSendService.sendSpecialty(tempSpecialty);
-		}
-	}
-
-	private ExcelError importCheck(Specialty specialty) {
-		if(StringUtils.isEmpty(specialty.getCode())){
-			return new ExcelError("代码不能为空");
-		}
-		if(StringUtils.isEmpty(specialty.getName())){
-			return new ExcelError("名称不能为空");
-		}
-		return null;
-	}
-	
-	/**
-	 * 带分页查询专业
-	 * @param specialty
-	 * @param pageable
-	 * @return
-	 */
-	public Page<Specialty> findAll(Specialty specialty,Long courseId,Pageable pageable){
-		Specification<Specialty> specification = getSpecification(specialty,courseId);
-		Page<Specialty> specialties = specialtyRepo.findAll(specification, pageable);
-		return specialties;
-	}
-	
-	public Specification<Specialty> getSpecification(Specialty specialty,Long courseId){
-		Specification<Specialty> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			if(!StringUtils.isEmpty(specialty.getOrgId())){
-				predicates.add(cb.equal(root.get("orgId"),specialty.getOrgId()));
-			}
-			if(!StringUtils.isEmpty(specialty.getName())){
-		    	predicates.add(cb.like(root.get("name"),"%"+specialty.getName()+"%"));
-		    }
-		    if(!StringUtils.isEmpty(specialty.getCode())){
-		    	predicates.add(cb.like(root.get("code"),"%"+specialty.getCode()+"%"));
-		    }
-		    if(!StringUtils.isEmpty(specialty.getEnable())){
-		    	predicates.add(cb.equal(root.get("enable"),specialty.getEnable()));
-		    }
-		    if(courseId!=null){
-		    	Subquery<CourseSpeciatly> relationshipSubquery = query.subquery(CourseSpeciatly.class);
-		    	Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery.from(CourseSpeciatly.class);
-		    	relationshipSubquery.select(residencyRelationshipSubqueryRoot);
-		    	Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"), courseId);
-		    	Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"), root.get("id"));
-		    	relationshipSubquery.where(cb.and(predicate,predicate2));
-		    	predicates.add(cb.exists(relationshipSubquery));
-		    }
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-	
-	/**
-	 * 查询专业不带分页
-	 * @param specialty
-	 * @return
-	 */
-	public List<Specialty> findAll(Specialty specialty){
-		Specification<Specialty> specification = getSpecification(specialty,null);
-		return specialtyRepo.findAll(specification);
-	}
-	
-	/**
-	 * 保存专业
-	 * @param specialty
-	 * @return
-	 */
-	public void save(Specialty specialty){
-		checkCode(specialty.getOrgId(), specialty.getCode());
-		specialty.setCreateTime(new Date());
-		specialty.setEnable(true);
-		specialtyRepo.save(specialty);
-		dataSendService.sendSpecialty(specialty);
-	}
-	
-	//验证专业代码是否存在
-	private void checkCode(Long orgId,String code){
-		Specialty specialty = specialtyRepo.findByOrgIdAndCode(orgId, code);
-		if(specialty != null){
-			throw new RuntimeException("专业代码已存在");
-		}
-	}
-	
-	/**
-	 * 更新专业
-	 * @param specialty
-	 */
-	public void updateSpecialty(Specialty specialty){
-		Specialty oldSpecialty = specialtyRepo.findOne(specialty.getId());
-		if(!oldSpecialty.getCode().equals(specialty.getCode())){
-			checkCode(specialty.getOrgId(), specialty.getCode());
-		}
-		specialty.setUpdateTime(new Date());
-		specialtyRepo.save(specialty);
-		dataSendService.sendSpecialty(specialty);
-	}
-	
-	/**
-	 * 根据Id删除专业
-	 * @param ids
-	 */
-	public void deleteSpecialty(String ids){
-		List<Long> specialtyIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
-                .collect(Collectors.toList());
-		for(Long specialtyId: specialtyIds){
-			specialtyRepo.delete(specialtyId);
-		}
-	}
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+import javax.transaction.Transactional;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
+import cn.com.qmth.examcloud.service.core.dto.SpecialtyDto;
+import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
+import cn.com.qmth.examcloud.service.core.entity.Specialty;
+import cn.com.qmth.examcloud.service.core.repo.SpecialtyRepo;
+import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
+
+@Service
+public class SpecialtyService {
+
+	@Autowired
+	SpecialtyRepo specialtyRepo;
+	@Autowired
+	DataSendService dataSendService;
+
+
+	@Transactional
+	public List<ExcelError> importSpecialty(Long orgId, InputStream inputStream) {
+		List<Specialty> list = new ArrayList<Specialty>();
+		ExcelReader excelReader = new ExcelReader(SpecialtyDto.class);
+		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
+			@Override
+			public ExcelError handle(Object obj) {
+				SpecialtyDto dto = (SpecialtyDto) obj;
+				Specialty specialty = new Specialty(dto.getCode(),dto.getName());
+				specialty.setOrgId(orgId);
+				specialty.setCreateTime(new Date());
+				specialty.setEnable(true);
+				ExcelError error = importCheck(specialty);
+				if (error == null) {
+					addSpecialty(specialty);
+				}
+				return error;
+			}
+		});
+		return excelErrors;
+	}
+
+	private void addSpecialty(Specialty specialty){
+		Specialty old = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(),specialty.getCode());
+		if(old == null){
+			Specialty tempSpecialty = specialtyRepo.save(specialty);
+			dataSendService.sendSpecialty(tempSpecialty);
+		}else{
+			old.setName(specialty.getName());
+			old.setUpdateTime(new Date());
+			Specialty tempSpecialty = specialtyRepo.save(old);
+			dataSendService.sendSpecialty(tempSpecialty);
+		}
+	}
+
+	private ExcelError importCheck(Specialty specialty) {
+		if(StringUtils.isEmpty(specialty.getCode())){
+			return new ExcelError("代码不能为空");
+		}
+		if(StringUtils.isEmpty(specialty.getName())){
+			return new ExcelError("名称不能为空");
+		}
+		return null;
+	}
+	
+	/**
+	 * 带分页查询专业
+	 * @param specialty
+	 * @param pageable
+	 * @return
+	 */
+	public Page<Specialty> findAll(Specialty specialty,Long courseId,Pageable pageable){
+		Specification<Specialty> specification = getSpecification(specialty,courseId);
+		Page<Specialty> specialties = specialtyRepo.findAll(specification, pageable);
+		return specialties;
+	}
+	
+	public Specification<Specialty> getSpecification(Specialty specialty,Long courseId){
+		Specification<Specialty> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			if(!StringUtils.isEmpty(specialty.getOrgId())){
+				predicates.add(cb.equal(root.get("orgId"),specialty.getOrgId()));
+			}
+			if(!StringUtils.isEmpty(specialty.getName())){
+		    	predicates.add(cb.like(root.get("name"),"%"+specialty.getName()+"%"));
+		    }
+		    if(!StringUtils.isEmpty(specialty.getCode())){
+		    	predicates.add(cb.like(root.get("code"),"%"+specialty.getCode()+"%"));
+		    }
+		    if(!StringUtils.isEmpty(specialty.getEnable())){
+		    	predicates.add(cb.equal(root.get("enable"),specialty.getEnable()));
+		    }
+		    if(courseId!=null){
+		    	Subquery<CourseSpeciatly> relationshipSubquery = query.subquery(CourseSpeciatly.class);
+		    	Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery.from(CourseSpeciatly.class);
+		    	relationshipSubquery.select(residencyRelationshipSubqueryRoot);
+		    	Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"), courseId);
+		    	Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"), root.get("id"));
+		    	relationshipSubquery.where(cb.and(predicate,predicate2));
+		    	predicates.add(cb.exists(relationshipSubquery));
+		    }
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+	
+	/**
+	 * 查询专业不带分页
+	 * @param specialty
+	 * @return
+	 */
+	public List<Specialty> findAll(Specialty specialty){
+		Specification<Specialty> specification = getSpecification(specialty,null);
+		return specialtyRepo.findAll(specification);
+	}
+	
+	/**
+	 * 保存专业
+	 * @param specialty
+	 * @return
+	 */
+	public void save(Specialty specialty){
+		checkCode(specialty.getOrgId(), specialty.getCode());
+		specialty.setCreateTime(new Date());
+		specialty.setEnable(true);
+		specialtyRepo.save(specialty);
+		dataSendService.sendSpecialty(specialty);
+	}
+	
+	//验证专业代码是否存在
+	private void checkCode(Long orgId,String code){
+		Specialty specialty = specialtyRepo.findByOrgIdAndCode(orgId, code);
+		if(specialty != null){
+			throw new RuntimeException("专业代码已存在");
+		}
+	}
+	
+	/**
+	 * 更新专业
+	 * @param specialty
+	 */
+	public void updateSpecialty(Specialty specialty){
+		Specialty oldSpecialty = specialtyRepo.findOne(specialty.getId());
+		if(!oldSpecialty.getCode().equals(specialty.getCode())){
+			checkCode(specialty.getOrgId(), specialty.getCode());
+		}
+		specialty.setUpdateTime(new Date());
+		specialtyRepo.save(specialty);
+		dataSendService.sendSpecialty(specialty);
+	}
+	
+	/**
+	 * 根据Id删除专业
+	 * @param ids
+	 */
+	public void deleteSpecialty(String ids){
+		List<Long> specialtyIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+		for(Long specialtyId: specialtyIds){
+			specialtyRepo.delete(specialtyId);
+		}
+	}
+}

+ 68 - 68
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java

@@ -1,68 +1,68 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.transaction.Transactional;
-
-import cn.com.qmth.examcloud.service.core.entity.Student;
-import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.service.core.entity.StudentFaceInfo;
-import cn.com.qmth.examcloud.service.core.repo.StudentFaceInfoRepo;
-
-
-@Service
-public class StudentFaceInfoService {
-
-    @Autowired
-    StudentFaceInfoRepo studentFaceInfoRepo;
-
-	@Autowired
-	StudentRepo studentRepo;
-
-    @Transactional
-    public StudentFaceInfo save(StudentFaceInfo studentFaceInfo) {
-    	StudentFaceInfo old = studentFaceInfoRepo.findByStudentId(studentFaceInfo.getStudent().getId());
-
-		Student student = studentRepo.findOne(studentFaceInfo.getStudent().getId());
-		if(student != null){
-			student.setPhotoPath(student.getIdentityNumber()+"/"+studentFaceInfo.getPhotoMD5());
-			studentRepo.save(student);
-		}
-		
-    	if(old == null){
-			studentFaceInfo.setCreateTime(new Date());
-			return studentFaceInfoRepo.save(studentFaceInfo);
-    	}
-    	old.setUpdateTime(new Date());
-    	old.setUpdateUser(studentFaceInfo.getUpdateUser());
-    	old.setFaceSetToken(studentFaceInfo.getFaceSetToken());
-    	old.setFaceToken(studentFaceInfo.getFaceToken());
-    	old.setPhotoMD5(studentFaceInfo.getPhotoMD5());
-    	old.setCreateType(studentFaceInfo.getCreateType());
-        return studentFaceInfoRepo.save(old);
-    }
-    
-    /**
-     * 判断faceSet是否可用
-     * faceSet在ecs_core_student_face_info表中的记录数不允许超过8000
-     * @param faceSet
-     * @return
-     */
-    public boolean judgeFaceSetIsAvailable(String faceSet){
-    	if(StringUtils.isBlank(faceSet)){
-    		return false;
-    	}
-    	List<StudentFaceInfo> studentFaceInfos = studentFaceInfoRepo.findByFaceSetToken(faceSet);
-    	if(studentFaceInfos==null||studentFaceInfos.size()<=8000){
-    		return true;
-    	}
-    	return false;
-    }
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.transaction.Transactional;
+
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.service.core.entity.StudentFaceInfo;
+import cn.com.qmth.examcloud.service.core.repo.StudentFaceInfoRepo;
+
+
+@Service
+public class StudentFaceInfoService {
+
+    @Autowired
+    StudentFaceInfoRepo studentFaceInfoRepo;
+
+	@Autowired
+	StudentRepo studentRepo;
+
+    @Transactional
+    public StudentFaceInfo save(StudentFaceInfo studentFaceInfo) {
+    	StudentFaceInfo old = studentFaceInfoRepo.findByStudentId(studentFaceInfo.getStudent().getId());
+
+		Student student = studentRepo.findOne(studentFaceInfo.getStudent().getId());
+		if(student != null){
+			student.setPhotoPath(student.getIdentityNumber()+"/"+studentFaceInfo.getPhotoMD5());
+			studentRepo.save(student);
+		}
+		
+    	if(old == null){
+			studentFaceInfo.setCreateTime(new Date());
+			return studentFaceInfoRepo.save(studentFaceInfo);
+    	}
+    	old.setUpdateTime(new Date());
+    	old.setUpdateUser(studentFaceInfo.getUpdateUser());
+    	old.setFaceSetToken(studentFaceInfo.getFaceSetToken());
+    	old.setFaceToken(studentFaceInfo.getFaceToken());
+    	old.setPhotoMD5(studentFaceInfo.getPhotoMD5());
+    	old.setCreateType(studentFaceInfo.getCreateType());
+        return studentFaceInfoRepo.save(old);
+    }
+    
+    /**
+     * 判断faceSet是否可用
+     * faceSet在ecs_core_student_face_info表中的记录数不允许超过8000
+     * @param faceSet
+     * @return
+     */
+    public boolean judgeFaceSetIsAvailable(String faceSet){
+    	if(StringUtils.isBlank(faceSet)){
+    		return false;
+    	}
+    	List<StudentFaceInfo> studentFaceInfos = studentFaceInfoRepo.findByFaceSetToken(faceSet);
+    	if(studentFaceInfos==null||studentFaceInfos.size()<=8000){
+    		return true;
+    	}
+    	return false;
+    }
+
+}

+ 228 - 228
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -1,228 +1,228 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import javax.transaction.Transactional;
-
-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 org.springframework.util.StringUtils;
-
-import cn.com.qmth.examcloud.common.uac.AccessCtrlUtil;
-import cn.com.qmth.examcloud.common.util.ErrorMsg;
-import cn.com.qmth.examcloud.service.core.dto.UserInfo;
-import cn.com.qmth.examcloud.service.core.entity.Org;
-import cn.com.qmth.examcloud.service.core.entity.Student;
-import cn.com.qmth.examcloud.service.core.entity.User;
-import cn.com.qmth.examcloud.service.core.entity.UserRole;
-import cn.com.qmth.examcloud.service.core.enums.LoginType;
-import cn.com.qmth.examcloud.service.core.enums.UserScope;
-import cn.com.qmth.examcloud.service.core.enums.UserType;
-import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
-import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserRepo;
-import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
-
-/**
- * 学生服务类
- * Created by songyue on 17/1/14.
- */
-@Service
-public class StudentService {
-
-    @Autowired
-    StudentRepo studentRepo;
-
-    @Autowired
-    UserRepo userRepo;
-
-    @Autowired
-    UserService userService;
-
-    @Autowired
-    OrgRepo orgRepo;
-
-    @Autowired
-    DataSendService dataSendService;
-
-    private static final String JPG = ".jpg";
-
-    /**
-     * 获取所有学生(分页)
-     *
-     * @param studentCriteria
-     * @param pageable
-     * @return
-     */
-    public Page<Student> getAllStudent(Student studentCriteria, Pageable pageable) {
-        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-                .withMatcher("name", contains())
-                .withMatcher("studentCode", contains())
-                .withMatcher("identityNumber", contains()).withIgnoreNullValues();
-        Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
-        return studentRepo.findAll(studentExample, pageable);
-    }
-
-    /**
-     * 获取所有学生
-     *
-     * @param studentCriteria
-     * @return
-     */
-    public List<Student> getAllStudent(Student studentCriteria) {
-        ExampleMatcher exampleMatcher = ExampleMatcher.matching();
-        Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
-        return studentRepo.findAll(studentExample);
-    }
-
-    /**
-     * 绑定学生照片
-     *
-     * @return
-     */
-    public List<ErrorMsg> photopBundled(Long rootOrgId, File directory) {
-        List<ErrorMsg> list = new ArrayList<ErrorMsg>();
-        if (directory.isDirectory()) {
-            for (File file : directory.listFiles()) {
-                if (!file.getName().endsWith(JPG)) {
-                    list.add(new ErrorMsg(file.getName() + "格式错误,文件名格式必须是jpg(小写)"));
-                }
-                String fileName = file.getName().split(JPG)[0];
-                //先查学号
-                Student student = studentRepo.findByStudentCodeAndRootOrgId(fileName, rootOrgId);
-                if (student == null) {//学号不存在查身份证号
-                    student = studentRepo.findByIdentityNumber(fileName);
-                }
-                if (student != null) {//学生存在则绑定照片
-                    student.setPhotoPath(student.getUser().getRootOrgId() + File.separator + "photo" + File.separator + fileName);
-                    studentRepo.save(student);
-                    dataSendService.sendStudent(student);
-                }
-            }
-        } else {
-            list.add(new ErrorMsg("文件路径不正确"));
-        }
-        return list;
-    }
-
-    @Transactional
-    public Student save(Student student) {
-        if (student.getUser() == null || null == student.getUser().getId()) {//判断是否有用户
-            //判断是否有该学生,
-            if (!StringUtils.isEmpty(student.getStudentCode())) {
-                Student domain = studentRepo.findByRootOrgIdAndStudentCode(student.getUser().getRootOrgId(), student.getStudentCode());
-                if (domain != null) {//学号查找不为空,更新身份证号
-                    domain.setIdentityNumber(student.getIdentityNumber());
-                    domain.setUpdateTime(new Date());
-                    domain.setName(student.getName());
-                    domain.setOrgId(student.getOrgId());
-                    domain = studentRepo.save(domain);
-                    dataSendService.sendStudent(domain);
-                    return domain;
-                }
-            }
-
-            Student entity = studentRepo.findByIdentityNumberAndRootOrgId(student.getIdentityNumber(), student.getRootOrgId());
-            if (entity != null) {//身份证查找不为空,更新学号
-                entity.setStudentCode(student.getStudentCode());
-                entity.setUpdateTime(new Date());
-                entity.setName(student.getName());
-                entity.setOrgId(student.getOrgId());
-                entity = studentRepo.save(entity);
-                dataSendService.sendStudent(entity);
-                return entity;
-            }
-            student.setOrgId(student.getUser().getOrgId());
-            student.setRootOrgId(student.getUser().getRootOrgId());
-            //新建用户和学生
-            User user = new User(student.getName(), UserScope.ORG, student.getUser().getRootOrgId(), student.getUser().getOrgId(), UserType.STUDENT);
-            user.setEnable(student.getUser().getEnable() == null ? true : student.getUser().getEnable());
-            String password = null;
-            if (!StringUtils.isEmpty(student.getIdentityNumber())) {//身份证号后6位
-                if (!StringUtils.isEmpty(student.getStudentCode())) {
-                    user.setLoginName(student.getStudentCode());
-                } else {
-                    user.setLoginName(student.getIdentityNumber());
-                }
-                password = student.getIdentityNumber().substring(student.getIdentityNumber().length() - 6, student.getIdentityNumber().length());
-            }
-            user.setPassword(password);
-            List<UserRole> userRoles = new ArrayList<UserRole>();
-            userRoles.add(new UserRole("ecs_oe", "STUDENT"));
-            user.setUserRoles(userRoles);
-            userRepo.save(user);
-            student.setUser(user);
-        }
-        student = studentRepo.save(student);
-        dataSendService.sendStudent(student);
-        return student;
-    }
-
-    /**
-     * 二级登录
-     *
-     * @param orgId
-     * @param loginName
-     * @param password
-     * @return
-     */
-    public UserInfo login(String orgId,
-                          String loginName,
-                          String password,
-                          LoginType loginType) throws Exception {
-        Org org = orgRepo.findFirstByParentIdAndCode((long) 0, orgId);
-        if (org == null) {
-            throw new RuntimeException("学校不存在");
-        }
-        Student student = null;
-        if (LoginType.STUDENT_CODE.equals(loginType)) {
-            student = studentRepo.findByStudentCodeAndRootOrgId(loginName, org.getId());
-        }else if (LoginType.IDENTITY_NUMBER.equals(loginType)) {
-            student = studentRepo.findByIdentityNumberAndRootOrgId(loginName, org.getId());
-        }
-        if (student == null) {
-            throw new RuntimeException("该用户不存在");
-        }
-        return this.loginProcess(student, password);
-    }
-
-    private UserInfo loginProcess(Student student, String password) throws Exception {
-        if (student.getUser() == null) {
-            throw new RuntimeException("该用户不存在");
-        } else if (!student.getUser().getPassword().equals(password)) {
-            throw new RuntimeException("密码错误");
-        } else if (!student.getUser().getEnable()) {
-            throw new RuntimeException("该用户被禁用");
-        } else {
-            String token = AccessCtrlUtil.buildToken();
-            userService.initUserLogin(student.getUser());
-            userService.createAccessUser(token, student.getUser(), student.getId());
-            userService.createUserLogin(token, student.getUser());
-            UserInfo userInfo = userService.getUserInfo(student.getUser(), token);
-            userInfo.setStudentId(student.getId());
-            userInfo.setIdentityNumber(student.getIdentityNumber());
-            userInfo.setStudentCode(student.getStudentCode());
-            return userInfo;
-        }
-    }
-
-    public Student update(Student student) {
-        student.setUpdateTime(new Date());
-        User user = userRepo.findOne(student.getUser().getId());
-        user.setName(student.getName());
-        student.setUser(user);
-        student = studentRepo.save(student);
-        dataSendService.sendStudent(student);
-        return student;
-    }
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.transaction.Transactional;
+
+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 org.springframework.util.StringUtils;
+
+import cn.com.qmth.examcloud.common.uac.AccessCtrlUtil;
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
+import cn.com.qmth.examcloud.service.core.dto.UserInfo;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.entity.User;
+import cn.com.qmth.examcloud.service.core.entity.UserRole;
+import cn.com.qmth.examcloud.service.core.enums.LoginType;
+import cn.com.qmth.examcloud.service.core.enums.UserScope;
+import cn.com.qmth.examcloud.service.core.enums.UserType;
+import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
+import cn.com.qmth.examcloud.service.core.service.sync.DataSendService;
+
+/**
+ * 学生服务类
+ * Created by songyue on 17/1/14.
+ */
+@Service
+public class StudentService {
+
+    @Autowired
+    StudentRepo studentRepo;
+
+    @Autowired
+    UserRepo userRepo;
+
+    @Autowired
+    UserService userService;
+
+    @Autowired
+    OrgRepo orgRepo;
+
+    @Autowired
+    DataSendService dataSendService;
+
+    private static final String JPG = ".jpg";
+
+    /**
+     * 获取所有学生(分页)
+     *
+     * @param studentCriteria
+     * @param pageable
+     * @return
+     */
+    public Page<Student> getAllStudent(Student studentCriteria, Pageable pageable) {
+        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+                .withMatcher("name", contains())
+                .withMatcher("studentCode", contains())
+                .withMatcher("identityNumber", contains()).withIgnoreNullValues();
+        Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
+        return studentRepo.findAll(studentExample, pageable);
+    }
+
+    /**
+     * 获取所有学生
+     *
+     * @param studentCriteria
+     * @return
+     */
+    public List<Student> getAllStudent(Student studentCriteria) {
+        ExampleMatcher exampleMatcher = ExampleMatcher.matching();
+        Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
+        return studentRepo.findAll(studentExample);
+    }
+
+    /**
+     * 绑定学生照片
+     *
+     * @return
+     */
+    public List<ErrorMsg> photopBundled(Long rootOrgId, File directory) {
+        List<ErrorMsg> list = new ArrayList<ErrorMsg>();
+        if (directory.isDirectory()) {
+            for (File file : directory.listFiles()) {
+                if (!file.getName().endsWith(JPG)) {
+                    list.add(new ErrorMsg(file.getName() + "格式错误,文件名格式必须是jpg(小写)"));
+                }
+                String fileName = file.getName().split(JPG)[0];
+                //先查学号
+                Student student = studentRepo.findByStudentCodeAndRootOrgId(fileName, rootOrgId);
+                if (student == null) {//学号不存在查身份证号
+                    student = studentRepo.findByIdentityNumber(fileName);
+                }
+                if (student != null) {//学生存在则绑定照片
+                    student.setPhotoPath(student.getUser().getRootOrgId() + File.separator + "photo" + File.separator + fileName);
+                    studentRepo.save(student);
+                    dataSendService.sendStudent(student);
+                }
+            }
+        } else {
+            list.add(new ErrorMsg("文件路径不正确"));
+        }
+        return list;
+    }
+
+    @Transactional
+    public Student save(Student student) {
+        if (student.getUser() == null || null == student.getUser().getId()) {//判断是否有用户
+            //判断是否有该学生,
+            if (!StringUtils.isEmpty(student.getStudentCode())) {
+                Student domain = studentRepo.findByRootOrgIdAndStudentCode(student.getUser().getRootOrgId(), student.getStudentCode());
+                if (domain != null) {//学号查找不为空,更新身份证号
+                    domain.setIdentityNumber(student.getIdentityNumber());
+                    domain.setUpdateTime(new Date());
+                    domain.setName(student.getName());
+                    domain.setOrgId(student.getOrgId());
+                    domain = studentRepo.save(domain);
+                    dataSendService.sendStudent(domain);
+                    return domain;
+                }
+            }
+
+            Student entity = studentRepo.findByIdentityNumberAndRootOrgId(student.getIdentityNumber(), student.getRootOrgId());
+            if (entity != null) {//身份证查找不为空,更新学号
+                entity.setStudentCode(student.getStudentCode());
+                entity.setUpdateTime(new Date());
+                entity.setName(student.getName());
+                entity.setOrgId(student.getOrgId());
+                entity = studentRepo.save(entity);
+                dataSendService.sendStudent(entity);
+                return entity;
+            }
+            student.setOrgId(student.getUser().getOrgId());
+            student.setRootOrgId(student.getUser().getRootOrgId());
+            //新建用户和学生
+            User user = new User(student.getName(), UserScope.ORG, student.getUser().getRootOrgId(), student.getUser().getOrgId(), UserType.STUDENT);
+            user.setEnable(student.getUser().getEnable() == null ? true : student.getUser().getEnable());
+            String password = null;
+            if (!StringUtils.isEmpty(student.getIdentityNumber())) {//身份证号后6位
+                if (!StringUtils.isEmpty(student.getStudentCode())) {
+                    user.setLoginName(student.getStudentCode());
+                } else {
+                    user.setLoginName(student.getIdentityNumber());
+                }
+                password = student.getIdentityNumber().substring(student.getIdentityNumber().length() - 6, student.getIdentityNumber().length());
+            }
+            user.setPassword(password);
+            List<UserRole> userRoles = new ArrayList<UserRole>();
+            userRoles.add(new UserRole("ecs_oe", "STUDENT"));
+            user.setUserRoles(userRoles);
+            userRepo.save(user);
+            student.setUser(user);
+        }
+        student = studentRepo.save(student);
+        dataSendService.sendStudent(student);
+        return student;
+    }
+
+    /**
+     * 二级登录
+     *
+     * @param orgId
+     * @param loginName
+     * @param password
+     * @return
+     */
+    public UserInfo login(String orgId,
+                          String loginName,
+                          String password,
+                          LoginType loginType) throws Exception {
+        Org org = orgRepo.findFirstByParentIdAndCode((long) 0, orgId);
+        if (org == null) {
+            throw new RuntimeException("学校不存在");
+        }
+        Student student = null;
+        if (LoginType.STUDENT_CODE.equals(loginType)) {
+            student = studentRepo.findByStudentCodeAndRootOrgId(loginName, org.getId());
+        }else if (LoginType.IDENTITY_NUMBER.equals(loginType)) {
+            student = studentRepo.findByIdentityNumberAndRootOrgId(loginName, org.getId());
+        }
+        if (student == null) {
+            throw new RuntimeException("该用户不存在");
+        }
+        return this.loginProcess(student, password);
+    }
+
+    private UserInfo loginProcess(Student student, String password) throws Exception {
+        if (student.getUser() == null) {
+            throw new RuntimeException("该用户不存在");
+        } else if (!student.getUser().getPassword().equals(password)) {
+            throw new RuntimeException("密码错误");
+        } else if (!student.getUser().getEnable()) {
+            throw new RuntimeException("该用户被禁用");
+        } else {
+            String token = AccessCtrlUtil.buildToken();
+            userService.initUserLogin(student.getUser());
+            userService.createAccessUser(token, student.getUser(), student.getId());
+            userService.createUserLogin(token, student.getUser());
+            UserInfo userInfo = userService.getUserInfo(student.getUser(), token);
+            userInfo.setStudentId(student.getId());
+            userInfo.setIdentityNumber(student.getIdentityNumber());
+            userInfo.setStudentCode(student.getStudentCode());
+            return userInfo;
+        }
+    }
+
+    public Student update(Student student) {
+        student.setUpdateTime(new Date());
+        User user = userRepo.findOne(student.getUser().getId());
+        user.setName(student.getName());
+        student.setUser(user);
+        student = studentRepo.save(student);
+        dataSendService.sendStudent(student);
+        return student;
+    }
+
+}

+ 92 - 92
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/UserRoleService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/UserRoleService.java

@@ -1,92 +1,92 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import cn.com.qmth.examcloud.common.uac.entity.Role;
-import cn.com.qmth.examcloud.common.uac.entity.RolesService;
-import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
-import cn.com.qmth.examcloud.service.core.repo.UserRoleRepo;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * 用户角色服务类
- * Created by songyue on 17/2/22.
- */
-@Service
-public class UserRoleService{
-
-    @Autowired
-    UserRoleRepo userRoleRepo;
-
-
-    /**
-     * 获取全部角色
-     * @return
-     */
-    public List<Role> findAllRoles(){
-        return RolesService.ROLE_LIST;
-    }
-
-    public List<Role> findMarkerRoles(){
-        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
-        tempRoles = tempRoles.stream()
-                .filter(role -> role.getCode().equals(RoleMeta.MARKER.name()))
-                .collect(Collectors.toList());
-        return tempRoles;
-    }
-    
-    public List<Role> findNonMarkerRoles(){
-        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
-        tempRoles = tempRoles.stream()
-                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.SALES_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.IMPLEMENTERS_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.PROJECT_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
-                .collect(Collectors.toList());
-        return tempRoles;
-    }
-
-    public List<Role> findAdminRoles(){
-        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
-        tempRoles = tempRoles.stream()
-                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
-                .collect(Collectors.toList());
-        return tempRoles;
-    }
-    
-    public List<Role> findQmthRoles(){
-        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
-        tempRoles = tempRoles.stream()
-                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.MARKING_ADMIN.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.QUESTION_ADMIN.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.OE_ADMIN.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
-                .collect(Collectors.toList());
-        return tempRoles;
-    }
-    
-    public List<Role> findSchoolRoles(){
-    	List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
-        tempRoles = tempRoles.stream()
-                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.SALES_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.IMPLEMENTERS_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.PROJECT_MANAGER.name()))
-                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
-                .collect(Collectors.toList());
-        return tempRoles;
-    }
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import cn.com.qmth.examcloud.common.uac.entity.Role;
+import cn.com.qmth.examcloud.common.uac.entity.RolesService;
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
+import cn.com.qmth.examcloud.service.core.repo.UserRoleRepo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 用户角色服务类
+ * Created by songyue on 17/2/22.
+ */
+@Service
+public class UserRoleService{
+
+    @Autowired
+    UserRoleRepo userRoleRepo;
+
+
+    /**
+     * 获取全部角色
+     * @return
+     */
+    public List<Role> findAllRoles(){
+        return RolesService.ROLE_LIST;
+    }
+
+    public List<Role> findMarkerRoles(){
+        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
+        tempRoles = tempRoles.stream()
+                .filter(role -> role.getCode().equals(RoleMeta.MARKER.name()))
+                .collect(Collectors.toList());
+        return tempRoles;
+    }
+    
+    public List<Role> findNonMarkerRoles(){
+        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
+        tempRoles = tempRoles.stream()
+                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.SALES_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.IMPLEMENTERS_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.PROJECT_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
+                .collect(Collectors.toList());
+        return tempRoles;
+    }
+
+    public List<Role> findAdminRoles(){
+        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
+        tempRoles = tempRoles.stream()
+                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
+                .collect(Collectors.toList());
+        return tempRoles;
+    }
+    
+    public List<Role> findQmthRoles(){
+        List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
+        tempRoles = tempRoles.stream()
+                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.MARKING_ADMIN.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.QUESTION_ADMIN.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.OE_ADMIN.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
+                .collect(Collectors.toList());
+        return tempRoles;
+    }
+    
+    public List<Role> findSchoolRoles(){
+    	List<Role> tempRoles = new ArrayList<>(RolesService.ROLE_LIST);
+        tempRoles = tempRoles.stream()
+                .filter(role -> !role.getCode().equals(RoleMeta.MARKER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.STUDENT.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.LC_USER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.SALES_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.IMPLEMENTERS_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.PROJECT_MANAGER.name()))
+                .filter(role -> !role.getCode().equals(RoleMeta.PRINT_MANAGER.name()))
+                .collect(Collectors.toList());
+        return tempRoles;
+    }
+
+}

+ 474 - 474
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java

@@ -1,474 +1,474 @@
-package cn.com.qmth.examcloud.service.core.service;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import javax.persistence.criteria.*;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.*;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import ch.qos.logback.core.net.LoginAuthenticator;
-import cn.com.qmth.examcloud.common.uac.AccessCtrlUtil;
-import cn.com.qmth.examcloud.common.uac.AccessUserOps;
-import cn.com.qmth.examcloud.common.uac.AccessUserOpsForRedis;
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
-import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
-import cn.com.qmth.examcloud.service.core.dto.UserInfo;
-import cn.com.qmth.examcloud.service.core.entity.Org;
-import cn.com.qmth.examcloud.service.core.entity.Student;
-import cn.com.qmth.examcloud.service.core.entity.User;
-import cn.com.qmth.examcloud.service.core.entity.UserLogin;
-import cn.com.qmth.examcloud.service.core.entity.UserOpsLog;
-import cn.com.qmth.examcloud.service.core.entity.UserRole;
-import cn.com.qmth.examcloud.service.core.enums.OrgType;
-import cn.com.qmth.examcloud.service.core.enums.UserScope;
-import cn.com.qmth.examcloud.service.core.enums.UserType;
-import cn.com.qmth.examcloud.service.core.params.UserParam;
-import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
-import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserLoginRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserOpsLogRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserRepo;
-import cn.com.qmth.examcloud.service.core.repo.UserRoleRepo;
-
-/**
- * 用户服务类
- * Created by songyue on 17/1/13.
- */
-@Service
-public class UserService {
-
-    @Autowired
-    UserRepo userRepo;
-
-    @Autowired
-    StudentRepo studentRepo;
-
-    @Autowired
-    OrgRepo orgRepo;
-
-    @Autowired
-    OrgService orgService;
-
-    @Autowired
-    UserRoleRepo userRoleRepo;
-
-    @Autowired
-    UserLoginRepo userLoginRepo;
-
-    @Autowired
-    UserOpsLogRepo userOpsLogRepo;
-
-    RedisTemplate redisTemplate;
-
-    AccessUserOps accessUserOps;
-
-    @Autowired
-    public UserService(RedisTemplate redisTemplate){
-        this.redisTemplate = redisTemplate;
-        this.accessUserOps = new AccessUserOpsForRedis(redisTemplate);
-    }
-
-    /**
-     * 查询所有用户
-     * @param userCriteria
-     * @param pageable
-     * @return
-     */
-    public Page<User> findAll(User userCriteria, Pageable pageable){
-        Specification<User> userSpecification = (root, query, cb) -> {
-            List<Predicate> predicates = new ArrayList<>();
-            predicates.add(cb.equal(root.get("type"),userCriteria.getType()));
-            predicates.add(cb.equal(root.get("rootOrgId"),userCriteria.getRootOrgId()));
-            if(StringUtils.isNotEmpty(userCriteria.getLoginName())){
-                predicates.add(cb.like(root.get("loginName"),"%"+userCriteria.getLoginName()+"%"));
-            }
-            if(StringUtils.isNotEmpty(userCriteria.getName())){
-                predicates.add(cb.like(root.get("name"),"%"+userCriteria.getName()+"%"));
-            }
-            if(userCriteria.getOrgId() != null){
-                predicates.add(cb.equal(root.get("orgId"),userCriteria.getOrgId()));
-            }
-            if(userCriteria.getEnable() != null){
-                predicates.add(cb.equal(root.get("enable"),userCriteria.getEnable()));
-            }
-            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-        };
-        List<User> users = userRepo.findAll(userSpecification);
-        int pageNumber = pageable.getPageNumber();
-        int pageSize = pageable.getPageSize();
-        users = users.stream()
-                .filter(user -> filterNonMarkerUser(user))
-                .collect(Collectors.toList());
-        long total = users.size();
-        users = users.stream()
-                .skip(pageNumber * pageSize)
-                .limit(pageSize)
-                .collect(Collectors.toList());
-        Page<User> userPage = new PageImpl<User>(users,pageable,total);
-        return userPage;
-    }
-
-    /**
-     * 过滤非评卷员
-     * @param user
-     * @return
-     */
-    private boolean filterNonMarkerUser(User user){
-        List<UserRole> userRoles = user.getUserRoles();
-        if(userRoles != null){
-            if(userRoles.size() == 1 && userRoles.get(0).getRoleCode().equals(RoleMeta.MARKER.name())){
-                return false;
-            }
-            return true;
-        }else{
-            return false;
-        }
-    }
-
-    /**
-     * 过滤管理角色
-     * @param user
-     * @return
-     */
-    private boolean filterAdminUser(User user){
-        List<UserRole> userRoles = user.getUserRoles();
-        if(userRoles != null){
-            for(UserRole userRole:userRoles){
-                if(userRole.getRoleCode().equals(RoleMeta.MARKER.name())
-                        || userRole.getRoleCode().equals(RoleMeta.STUDENT.name())
-                        || userRole.getRoleCode().equals(RoleMeta.LC_USER.name())){
-                    return false;
-                }
-            }
-            return true;
-        }else{
-            return false;
-        }
-    }
-
-    /**
-     * 查询所有机构用户
-     * @param userCriteria
-     * @param pageable
-     * @return
-     */
-    public Page<User> findOrgUser(User userCriteria,Pageable pageable){
-        Specification<User> userSpecification = (root, query, cb) -> {
-            List<Predicate> predicates = new ArrayList<>();
-            predicates.add(cb.equal(root.get("rootOrgId"),root.get("orgId")));
-            predicates.add(cb.equal(root.get("type"),userCriteria.getType()));
-            if(userCriteria.getOrgId() != null){
-                predicates.add(cb.equal(root.get("rootOrgId"),userCriteria.getOrgId()));
-            }
-            if(StringUtils.isNotEmpty(userCriteria.getLoginName())){
-                predicates.add(cb.like(root.get("loginName"),"%"+userCriteria.getLoginName()+"%"));
-            }
-            if(StringUtils.isNotEmpty(userCriteria.getName())){
-                predicates.add(cb.like(root.get("name"),"%"+userCriteria.getName()+"%"));
-            }
-            if(userCriteria.getEnable() != null){
-                predicates.add(cb.equal(root.get("enable"),userCriteria.getEnable()));
-            }
-            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-        };
-        List<User> users = userRepo.findAll(userSpecification);
-        int pageNumber = pageable.getPageNumber();
-        int pageSize = pageable.getPageSize();
-        users = users.stream()
-                .filter(user -> filterAdminUser(user))
-                .collect(Collectors.toList());
-        long total = users.size();
-        users = users.stream()
-                .skip(pageNumber * pageSize)
-                .limit(pageSize)
-                .collect(Collectors.toList());
-        Page<User> userPage = new PageImpl<User>(users,pageable,total);
-        return userPage;
-    }
-
-    /**
-     * 初始化密码
-     * @param userId
-     */
-    public void initPassword(long userId){
-        User user = userRepo.findOne(userId);
-        //根据用户类型采用不同的初始化策略
-        if(user.getType() == UserType.NOT_STUDENT){
-            //初始化为默认密码
-            user.setPassword(UserParam.DEFAULT_PASSWORD);
-
-        }else if(user.getType() == UserType.STUDENT){
-            //截取身份证后6位为学生登录密码
-            Student student = studentRepo.findByUserId(userId);
-            String identityNumber = student.getIdentityNumber();
-            if(StringUtils.isNotEmpty(identityNumber)){
-                user.setPassword(StringUtils.substring(identityNumber,-6,identityNumber.length()));
-            }else{
-                user.setPassword(UserParam.DEFAULT_PASSWORD);
-            }
-        }
-        user.setUpdateTime(new Date());
-        userRepo.save(user);
-    }
-
-
-    /**
-     * 一般登录
-     * @param loginName
-     * @param password
-     * @return
-     */
-    public UserInfo login(String loginName,
-                          String password)throws Exception{
-        User user = userRepo.findByLoginName(loginName);
-        return loginProcess(user,password);
-
-    }
-    
-    /**
-     * 二级登录
-     * @param orgId
-     * @param loginName
-     * @param password
-     * @return
-     */
-    public UserInfo login(long orgId,
-                          String loginName,
-                          String password)throws Exception{
-        User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
-        return loginProcess(user,password);
-    }
-
-    /**
-     * 登录处理
-     * @param user
-     * @param password
-     * @return
-     */
-    public UserInfo loginProcess(User user, String password)throws Exception{
-        if(user == null){
-        	throw new RuntimeException("该用户不存在");
-        }else if(!user.getPassword().equals(password)){
-        	throw new RuntimeException("密码错误");
-        }else if(!user.getEnable()){
-            throw new RuntimeException("该用户被禁用");
-        }else{
-            String token = AccessCtrlUtil.buildToken();
-            initUserLogin(user);
-            createAccessUser(token,user,null);
-            createUserLogin(token,user);
-            return getUserInfo(user,token);
-        }
-    }
-
-    /**
-     * 初始化用户登录
-     * @param user
-     */
-    public void initUserLogin(User user){
-        //判断是否已登录,若已登录则强制已登录用户退出
-        UserLogin userLogin= userLoginRepo.findFirstByUserId(user.getId());
-        if(userLogin != null){
-            accessUserOps.delete(userLogin.getToken());
-            userLoginRepo.deleteByUserId(userLogin.getUserId());
-        }
-    }
-
-    /**
-     * 创建用户操作日志
-     * @param user
-     * @param action
-     */
-    public void createUserOpsLog(User user,String action){
-        UserOpsLog userOpsLog = new UserOpsLog(action,user.getId(),user.getName(),new Date());
-        userOpsLogRepo.save(userOpsLog);
-    }
-
-    /**
-     * 创建用户登录记录
-     * @param token
-     * @param user
-     */
-    public void createUserLogin(String token,User user){
-        UserLogin userLogin = new UserLogin();
-        userLogin.setLoginTime(new Date());
-        userLogin.setUserId(user.getId());
-        userLogin.setToken(token);
-        userLoginRepo.save(userLogin);
-    }
-
-    /**
-     * 创建访问用户并加入K/V缓存
-     * @param token
-     * @param user
-     */
-    public void createAccessUser(String token,User user,Long studentId)throws Exception{
-        AccessUser accessUser = new AccessUser();
-        Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());
-        Org org = orgService.findOne(user.getRootOrgId());
-        Map<String,Set<String>> rolesMap = userRoleSet.stream()
-                .collect(Collectors.groupingBy(UserRole::getAppCode,
-                        Collectors.mapping(UserRole::getRoleCode,Collectors.toSet())));
-        accessUser.setLoginName(user.getLoginName());
-        accessUser.setName(user.getName());
-        accessUser.setOrgId(user.getOrgId());
-        accessUser.setRootOrgId(user.getRootOrgId());
-        if(org != null){
-            accessUser.setRootOrgName(org.getName());
-        }
-        accessUser.setUserId(user.getId());
-        accessUser.setRoles(rolesMap);
-        accessUser.setToken(token);
-        accessUser.setStudentId(studentId);
-        accessUserOps.set(token,accessUser);
-    }
-
-    /**
-     * 获取用户信息DTO
-     * @param user
-     * @param token
-     * @return
-     */
-    public UserInfo getUserInfo(User user,String token)throws Exception{
-        UserInfo userInfo = new UserInfo();
-        Org org = orgService.findOne(user.getOrgId());
-        Org rootOrg = orgService.findOne(user.getRootOrgId());
-        userInfo.setUserId(user.getId());
-        userInfo.setOrgId(user.getOrgId());
-        userInfo.setRootOrgId(user.getRootOrgId());
-        userInfo.setName(user.getName());
-        userInfo.setAvatar(user.getAvatar());
-        userInfo.setLoginName(user.getLoginName());
-        if(org != null){
-            userInfo.setOrgName(org.getName());
-        }
-        if(rootOrg != null){
-            userInfo.setRootOrgLogo(rootOrg.getLogo());
-            userInfo.setRootOrgName(rootOrg.getName());
-        }
-        userInfo.setToken(token);
-        userInfo.setType(user.getType().toString());
-        userInfo.setUserRoles(user.getUserRoles());
-        userInfo.setRoleNames(getRoleNames(user.getUserRoles()));
-        return userInfo;
-    }
-
-    /**
-     * 获取角色名称
-     * @param userRoles
-     * @return
-     */
-    public List<String> getRoleNames(List<UserRole> userRoles){
-
-        List<String> roleNameList = userRoles.stream()
-                .map(userRole -> RoleMeta.valueOf(userRole.getRoleCode()).getCnName())
-                .collect(Collectors.toList());
-        return roleNameList;
-
-    }
-
-    /**
-     * 登出
-     * @param accessUser
-     */
-	public void logout(AccessUser accessUser) {
-        accessUserOps.delete(accessUser.getToken());
-        userLoginRepo.deleteByUserId(accessUser.getUserId());
-	}
-
-	public List<User> getMarker(Long rootOrgId) {
-		return userRepo.findMarkerByRootOrgId(rootOrgId);
-	}
-	
-	/**
-	 * 查询评卷员带分页
-	 * @param user
-	 * @param pageable
-	 * @return
-	 */
-	public Page<User> getAllMaker(User user,Pageable pageable){
-		Specification<User> specification = getSpecification(user);
-		return userRepo.findAll(specification,pageable);
-	}
-
-	public Specification<User> getSpecification(User user){
-		Specification<User> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			predicates.add(cb.equal(root.get("type"),UserType.NOT_STUDENT));
-            predicates.add(cb.equal(root.get("rootOrgId"),user.getRootOrgId()));
-            Join join = root.join("userRoles");
-            predicates.add(cb.equal(join.get("roleCode"), RoleMeta.MARKER.name()));
-            if(StringUtils.isNotEmpty(user.getLoginName())){
-                predicates.add(cb.like(root.get("loginName"),"%"+user.getLoginName()+"%"));
-            }
-            if(StringUtils.isNotEmpty(user.getName())){
-                predicates.add(cb.like(root.get("name"),"%"+user.getName()+"%"));
-            }
-            if(user.getEnable() != null){
-                predicates.add(cb.equal(root.get("enable"),user.getEnable()));
-            }
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-	
-	public User save(User user) throws Exception{
-        user.setScope(UserScope.ORG);
-        user.setCreateTime(new Date());
-		checkLoginName(user.getRootOrgId(), user.getLoginName());
-		return userRepo.save(user);
-	}
-
-	private void checkLoginName(Long rootOrgId,String loginName) {
-		User old = userRepo.findByRootOrgIdAndLoginName(rootOrgId,loginName);
-		if(old!=null){
-			throw new RuntimeException("用户名已存在");
-		}else if("admin".equalsIgnoreCase(loginName)){
-		    throw new RuntimeException("不能创建admin用户");
-        }
-	}
-
-	public User update(Long id, User user) {
-		User old =  userRepo.findOne(id);
-		if(!old.getLoginName().equals(user.getLoginName())){
-			checkLoginName(user.getRootOrgId(), user.getLoginName());
-		}
-		user.setUpdateTime(new Date());
-		return userRepo.save(user);
-	}
-
-	public User saveMarker(Long rootOrgId, String loginName,String name) {
-		User old = userRepo.findByRootOrgIdAndLoginName(rootOrgId,loginName);
-		if(old!=null){
-			return old;
-		}
-		User user = new User();
-		user.setName(name);
-		user.setLoginName(loginName);
-		user.setEnable(true);
-		user.setOrgId(rootOrgId);
-		user.setRootOrgId(rootOrgId);
-		user.setPassword(loginName);
-		UserRole userRole = new UserRole(RoleMeta.MARKER.getAppCode(), RoleMeta.MARKER.toString());
-		List<UserRole> userRoles = new LinkedList<UserRole>();
-		userRoles.add(userRole);
-		user.setUserRoles(userRoles);
-		user.setScope(UserScope.ORG);
-		user.setType(UserType.NOT_STUDENT);
-		user.setCreateTime(new Date());
-		return userRepo.save(user);
-	}
-
-}
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.persistence.criteria.*;
+
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.*;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import ch.qos.logback.core.net.LoginAuthenticator;
+import cn.com.qmth.examcloud.common.uac.AccessCtrlUtil;
+import cn.com.qmth.examcloud.common.uac.AccessUserOps;
+import cn.com.qmth.examcloud.common.uac.AccessUserOpsForRedis;
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.uac.enums.RoleMeta;
+import cn.com.qmth.examcloud.service.core.dto.UserInfo;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.entity.User;
+import cn.com.qmth.examcloud.service.core.entity.UserLogin;
+import cn.com.qmth.examcloud.service.core.entity.UserOpsLog;
+import cn.com.qmth.examcloud.service.core.entity.UserRole;
+import cn.com.qmth.examcloud.service.core.enums.OrgType;
+import cn.com.qmth.examcloud.service.core.enums.UserScope;
+import cn.com.qmth.examcloud.service.core.enums.UserType;
+import cn.com.qmth.examcloud.service.core.params.UserParam;
+import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserLoginRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserOpsLogRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRoleRepo;
+
+/**
+ * 用户服务类
+ * Created by songyue on 17/1/13.
+ */
+@Service
+public class UserService {
+
+    @Autowired
+    UserRepo userRepo;
+
+    @Autowired
+    StudentRepo studentRepo;
+
+    @Autowired
+    OrgRepo orgRepo;
+
+    @Autowired
+    OrgService orgService;
+
+    @Autowired
+    UserRoleRepo userRoleRepo;
+
+    @Autowired
+    UserLoginRepo userLoginRepo;
+
+    @Autowired
+    UserOpsLogRepo userOpsLogRepo;
+
+    RedisTemplate redisTemplate;
+
+    AccessUserOps accessUserOps;
+
+    @Autowired
+    public UserService(RedisTemplate redisTemplate){
+        this.redisTemplate = redisTemplate;
+        this.accessUserOps = new AccessUserOpsForRedis(redisTemplate);
+    }
+
+    /**
+     * 查询所有用户
+     * @param userCriteria
+     * @param pageable
+     * @return
+     */
+    public Page<User> findAll(User userCriteria, Pageable pageable){
+        Specification<User> userSpecification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            predicates.add(cb.equal(root.get("type"),userCriteria.getType()));
+            predicates.add(cb.equal(root.get("rootOrgId"),userCriteria.getRootOrgId()));
+            if(StringUtils.isNotEmpty(userCriteria.getLoginName())){
+                predicates.add(cb.like(root.get("loginName"),"%"+userCriteria.getLoginName()+"%"));
+            }
+            if(StringUtils.isNotEmpty(userCriteria.getName())){
+                predicates.add(cb.like(root.get("name"),"%"+userCriteria.getName()+"%"));
+            }
+            if(userCriteria.getOrgId() != null){
+                predicates.add(cb.equal(root.get("orgId"),userCriteria.getOrgId()));
+            }
+            if(userCriteria.getEnable() != null){
+                predicates.add(cb.equal(root.get("enable"),userCriteria.getEnable()));
+            }
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+        List<User> users = userRepo.findAll(userSpecification);
+        int pageNumber = pageable.getPageNumber();
+        int pageSize = pageable.getPageSize();
+        users = users.stream()
+                .filter(user -> filterNonMarkerUser(user))
+                .collect(Collectors.toList());
+        long total = users.size();
+        users = users.stream()
+                .skip(pageNumber * pageSize)
+                .limit(pageSize)
+                .collect(Collectors.toList());
+        Page<User> userPage = new PageImpl<User>(users,pageable,total);
+        return userPage;
+    }
+
+    /**
+     * 过滤非评卷员
+     * @param user
+     * @return
+     */
+    private boolean filterNonMarkerUser(User user){
+        List<UserRole> userRoles = user.getUserRoles();
+        if(userRoles != null){
+            if(userRoles.size() == 1 && userRoles.get(0).getRoleCode().equals(RoleMeta.MARKER.name())){
+                return false;
+            }
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    /**
+     * 过滤管理角色
+     * @param user
+     * @return
+     */
+    private boolean filterAdminUser(User user){
+        List<UserRole> userRoles = user.getUserRoles();
+        if(userRoles != null){
+            for(UserRole userRole:userRoles){
+                if(userRole.getRoleCode().equals(RoleMeta.MARKER.name())
+                        || userRole.getRoleCode().equals(RoleMeta.STUDENT.name())
+                        || userRole.getRoleCode().equals(RoleMeta.LC_USER.name())){
+                    return false;
+                }
+            }
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    /**
+     * 查询所有机构用户
+     * @param userCriteria
+     * @param pageable
+     * @return
+     */
+    public Page<User> findOrgUser(User userCriteria,Pageable pageable){
+        Specification<User> userSpecification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            predicates.add(cb.equal(root.get("rootOrgId"),root.get("orgId")));
+            predicates.add(cb.equal(root.get("type"),userCriteria.getType()));
+            if(userCriteria.getOrgId() != null){
+                predicates.add(cb.equal(root.get("rootOrgId"),userCriteria.getOrgId()));
+            }
+            if(StringUtils.isNotEmpty(userCriteria.getLoginName())){
+                predicates.add(cb.like(root.get("loginName"),"%"+userCriteria.getLoginName()+"%"));
+            }
+            if(StringUtils.isNotEmpty(userCriteria.getName())){
+                predicates.add(cb.like(root.get("name"),"%"+userCriteria.getName()+"%"));
+            }
+            if(userCriteria.getEnable() != null){
+                predicates.add(cb.equal(root.get("enable"),userCriteria.getEnable()));
+            }
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+        List<User> users = userRepo.findAll(userSpecification);
+        int pageNumber = pageable.getPageNumber();
+        int pageSize = pageable.getPageSize();
+        users = users.stream()
+                .filter(user -> filterAdminUser(user))
+                .collect(Collectors.toList());
+        long total = users.size();
+        users = users.stream()
+                .skip(pageNumber * pageSize)
+                .limit(pageSize)
+                .collect(Collectors.toList());
+        Page<User> userPage = new PageImpl<User>(users,pageable,total);
+        return userPage;
+    }
+
+    /**
+     * 初始化密码
+     * @param userId
+     */
+    public void initPassword(long userId){
+        User user = userRepo.findOne(userId);
+        //根据用户类型采用不同的初始化策略
+        if(user.getType() == UserType.NOT_STUDENT){
+            //初始化为默认密码
+            user.setPassword(UserParam.DEFAULT_PASSWORD);
+
+        }else if(user.getType() == UserType.STUDENT){
+            //截取身份证后6位为学生登录密码
+            Student student = studentRepo.findByUserId(userId);
+            String identityNumber = student.getIdentityNumber();
+            if(StringUtils.isNotEmpty(identityNumber)){
+                user.setPassword(StringUtils.substring(identityNumber,-6,identityNumber.length()));
+            }else{
+                user.setPassword(UserParam.DEFAULT_PASSWORD);
+            }
+        }
+        user.setUpdateTime(new Date());
+        userRepo.save(user);
+    }
+
+
+    /**
+     * 一般登录
+     * @param loginName
+     * @param password
+     * @return
+     */
+    public UserInfo login(String loginName,
+                          String password)throws Exception{
+        User user = userRepo.findByLoginName(loginName);
+        return loginProcess(user,password);
+
+    }
+    
+    /**
+     * 二级登录
+     * @param orgId
+     * @param loginName
+     * @param password
+     * @return
+     */
+    public UserInfo login(long orgId,
+                          String loginName,
+                          String password)throws Exception{
+        User user = userRepo.findByRootOrgIdAndLoginName(orgId,loginName);
+        return loginProcess(user,password);
+    }
+
+    /**
+     * 登录处理
+     * @param user
+     * @param password
+     * @return
+     */
+    public UserInfo loginProcess(User user, String password)throws Exception{
+        if(user == null){
+        	throw new RuntimeException("该用户不存在");
+        }else if(!user.getPassword().equals(password)){
+        	throw new RuntimeException("密码错误");
+        }else if(!user.getEnable()){
+            throw new RuntimeException("该用户被禁用");
+        }else{
+            String token = AccessCtrlUtil.buildToken();
+            initUserLogin(user);
+            createAccessUser(token,user,null);
+            createUserLogin(token,user);
+            return getUserInfo(user,token);
+        }
+    }
+
+    /**
+     * 初始化用户登录
+     * @param user
+     */
+    public void initUserLogin(User user){
+        //判断是否已登录,若已登录则强制已登录用户退出
+        UserLogin userLogin= userLoginRepo.findFirstByUserId(user.getId());
+        if(userLogin != null){
+            accessUserOps.delete(userLogin.getToken());
+            userLoginRepo.deleteByUserId(userLogin.getUserId());
+        }
+    }
+
+    /**
+     * 创建用户操作日志
+     * @param user
+     * @param action
+     */
+    public void createUserOpsLog(User user,String action){
+        UserOpsLog userOpsLog = new UserOpsLog(action,user.getId(),user.getName(),new Date());
+        userOpsLogRepo.save(userOpsLog);
+    }
+
+    /**
+     * 创建用户登录记录
+     * @param token
+     * @param user
+     */
+    public void createUserLogin(String token,User user){
+        UserLogin userLogin = new UserLogin();
+        userLogin.setLoginTime(new Date());
+        userLogin.setUserId(user.getId());
+        userLogin.setToken(token);
+        userLoginRepo.save(userLogin);
+    }
+
+    /**
+     * 创建访问用户并加入K/V缓存
+     * @param token
+     * @param user
+     */
+    public void createAccessUser(String token,User user,Long studentId)throws Exception{
+        AccessUser accessUser = new AccessUser();
+        Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());
+        Org org = orgService.findOne(user.getRootOrgId());
+        Map<String,Set<String>> rolesMap = userRoleSet.stream()
+                .collect(Collectors.groupingBy(UserRole::getAppCode,
+                        Collectors.mapping(UserRole::getRoleCode,Collectors.toSet())));
+        accessUser.setLoginName(user.getLoginName());
+        accessUser.setName(user.getName());
+        accessUser.setOrgId(user.getOrgId());
+        accessUser.setRootOrgId(user.getRootOrgId());
+        if(org != null){
+            accessUser.setRootOrgName(org.getName());
+        }
+        accessUser.setUserId(user.getId());
+        accessUser.setRoles(rolesMap);
+        accessUser.setToken(token);
+        accessUser.setStudentId(studentId);
+        accessUserOps.set(token,accessUser);
+    }
+
+    /**
+     * 获取用户信息DTO
+     * @param user
+     * @param token
+     * @return
+     */
+    public UserInfo getUserInfo(User user,String token)throws Exception{
+        UserInfo userInfo = new UserInfo();
+        Org org = orgService.findOne(user.getOrgId());
+        Org rootOrg = orgService.findOne(user.getRootOrgId());
+        userInfo.setUserId(user.getId());
+        userInfo.setOrgId(user.getOrgId());
+        userInfo.setRootOrgId(user.getRootOrgId());
+        userInfo.setName(user.getName());
+        userInfo.setAvatar(user.getAvatar());
+        userInfo.setLoginName(user.getLoginName());
+        if(org != null){
+            userInfo.setOrgName(org.getName());
+        }
+        if(rootOrg != null){
+            userInfo.setRootOrgLogo(rootOrg.getLogo());
+            userInfo.setRootOrgName(rootOrg.getName());
+        }
+        userInfo.setToken(token);
+        userInfo.setType(user.getType().toString());
+        userInfo.setUserRoles(user.getUserRoles());
+        userInfo.setRoleNames(getRoleNames(user.getUserRoles()));
+        return userInfo;
+    }
+
+    /**
+     * 获取角色名称
+     * @param userRoles
+     * @return
+     */
+    public List<String> getRoleNames(List<UserRole> userRoles){
+
+        List<String> roleNameList = userRoles.stream()
+                .map(userRole -> RoleMeta.valueOf(userRole.getRoleCode()).getCnName())
+                .collect(Collectors.toList());
+        return roleNameList;
+
+    }
+
+    /**
+     * 登出
+     * @param accessUser
+     */
+	public void logout(AccessUser accessUser) {
+        accessUserOps.delete(accessUser.getToken());
+        userLoginRepo.deleteByUserId(accessUser.getUserId());
+	}
+
+	public List<User> getMarker(Long rootOrgId) {
+		return userRepo.findMarkerByRootOrgId(rootOrgId);
+	}
+	
+	/**
+	 * 查询评卷员带分页
+	 * @param user
+	 * @param pageable
+	 * @return
+	 */
+	public Page<User> getAllMaker(User user,Pageable pageable){
+		Specification<User> specification = getSpecification(user);
+		return userRepo.findAll(specification,pageable);
+	}
+
+	public Specification<User> getSpecification(User user){
+		Specification<User> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("type"),UserType.NOT_STUDENT));
+            predicates.add(cb.equal(root.get("rootOrgId"),user.getRootOrgId()));
+            Join join = root.join("userRoles");
+            predicates.add(cb.equal(join.get("roleCode"), RoleMeta.MARKER.name()));
+            if(StringUtils.isNotEmpty(user.getLoginName())){
+                predicates.add(cb.like(root.get("loginName"),"%"+user.getLoginName()+"%"));
+            }
+            if(StringUtils.isNotEmpty(user.getName())){
+                predicates.add(cb.like(root.get("name"),"%"+user.getName()+"%"));
+            }
+            if(user.getEnable() != null){
+                predicates.add(cb.equal(root.get("enable"),user.getEnable()));
+            }
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+	
+	public User save(User user) throws Exception{
+        user.setScope(UserScope.ORG);
+        user.setCreateTime(new Date());
+		checkLoginName(user.getRootOrgId(), user.getLoginName());
+		return userRepo.save(user);
+	}
+
+	private void checkLoginName(Long rootOrgId,String loginName) {
+		User old = userRepo.findByRootOrgIdAndLoginName(rootOrgId,loginName);
+		if(old!=null){
+			throw new RuntimeException("用户名已存在");
+		}else if("admin".equalsIgnoreCase(loginName)){
+		    throw new RuntimeException("不能创建admin用户");
+        }
+	}
+
+	public User update(Long id, User user) {
+		User old =  userRepo.findOne(id);
+		if(!old.getLoginName().equals(user.getLoginName())){
+			checkLoginName(user.getRootOrgId(), user.getLoginName());
+		}
+		user.setUpdateTime(new Date());
+		return userRepo.save(user);
+	}
+
+	public User saveMarker(Long rootOrgId, String loginName,String name) {
+		User old = userRepo.findByRootOrgIdAndLoginName(rootOrgId,loginName);
+		if(old!=null){
+			return old;
+		}
+		User user = new User();
+		user.setName(name);
+		user.setLoginName(loginName);
+		user.setEnable(true);
+		user.setOrgId(rootOrgId);
+		user.setRootOrgId(rootOrgId);
+		user.setPassword(loginName);
+		UserRole userRole = new UserRole(RoleMeta.MARKER.getAppCode(), RoleMeta.MARKER.toString());
+		List<UserRole> userRoles = new LinkedList<UserRole>();
+		userRoles.add(userRole);
+		user.setUserRoles(userRoles);
+		user.setScope(UserScope.ORG);
+		user.setType(UserType.NOT_STUDENT);
+		user.setCreateTime(new Date());
+		return userRepo.save(user);
+	}
+
+}

+ 20 - 20
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataReceiveService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataReceiveService.java

@@ -1,20 +1,20 @@
-package cn.com.qmth.examcloud.service.core.service.sync;
-
-import com.qmth.commons.dataSync.core.service.DataSyncService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-/**
- * Created by songyue on 17/8/3.
- */
-@Service
-public class DataReceiveService {
-
-    private static final Logger log = LoggerFactory.getLogger(DataReceiveService.class);
-
-    @Autowired
-    DataSyncService dataSyncService;
-
-}
+package cn.com.qmth.examcloud.service.core.service.sync;
+
+import com.qmth.commons.dataSync.core.service.DataSyncService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Created by songyue on 17/8/3.
+ */
+@Service
+public class DataReceiveService {
+
+    private static final Logger log = LoggerFactory.getLogger(DataReceiveService.class);
+
+    @Autowired
+    DataSyncService dataSyncService;
+
+}

+ 46 - 46
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataSendService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/service/sync/DataSendService.java

@@ -1,46 +1,46 @@
-package cn.com.qmth.examcloud.service.core.service.sync;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import cn.com.qmth.examcloud.common.dto.core.CourseSync;
-import cn.com.qmth.examcloud.common.dto.core.OrgSync;
-import cn.com.qmth.examcloud.common.dto.core.SpecialtySync;
-import cn.com.qmth.examcloud.common.dto.core.StudentSync;
-import cn.com.qmth.examcloud.common.util.BeanCopierUtil;
-import cn.com.qmth.examcloud.service.core.entity.Course;
-import cn.com.qmth.examcloud.service.core.entity.Org;
-import cn.com.qmth.examcloud.service.core.entity.Specialty;
-import cn.com.qmth.examcloud.service.core.entity.Student;
-
-import com.qmth.commons.dataSync.core.service.DataSyncService;
-
-/**
- * Created by songyue on 17/8/3.
- */
-@Service
-public class DataSendService {
-
-    @Autowired
-    DataSyncService dataSyncService;
-
-    public void sendCourse(Course course){
-        CourseSync courseSync = BeanCopierUtil.copyProperties(course,CourseSync.class);
-        dataSyncService.send(courseSync);
-    }
-
-    public void sendOrg(Org org){
-        OrgSync orgSync = BeanCopierUtil.copyProperties(org,OrgSync.class);
-        dataSyncService.send(orgSync);
-    }
-    
-    public void sendStudent(Student student){
-    	StudentSync studentSync = BeanCopierUtil.copyProperties(student,StudentSync.class);
-        dataSyncService.send(studentSync);
-    }
-    
-    public void sendSpecialty(Specialty specialty){
-    	SpecialtySync specialtySync = BeanCopierUtil.copyProperties(specialty,SpecialtySync.class);
-        dataSyncService.send(specialtySync);
-    }
-}
+package cn.com.qmth.examcloud.service.core.service.sync;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.common.dto.core.CourseSync;
+import cn.com.qmth.examcloud.common.dto.core.OrgSync;
+import cn.com.qmth.examcloud.common.dto.core.SpecialtySync;
+import cn.com.qmth.examcloud.common.dto.core.StudentSync;
+import cn.com.qmth.examcloud.common.util.BeanCopierUtil;
+import cn.com.qmth.examcloud.service.core.entity.Course;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import cn.com.qmth.examcloud.service.core.entity.Specialty;
+import cn.com.qmth.examcloud.service.core.entity.Student;
+
+import com.qmth.commons.dataSync.core.service.DataSyncService;
+
+/**
+ * Created by songyue on 17/8/3.
+ */
+@Service
+public class DataSendService {
+
+    @Autowired
+    DataSyncService dataSyncService;
+
+    public void sendCourse(Course course){
+        CourseSync courseSync = BeanCopierUtil.copyProperties(course,CourseSync.class);
+        dataSyncService.send(courseSync);
+    }
+
+    public void sendOrg(Org org){
+        OrgSync orgSync = BeanCopierUtil.copyProperties(org,OrgSync.class);
+        dataSyncService.send(orgSync);
+    }
+    
+    public void sendStudent(Student student){
+    	StudentSync studentSync = BeanCopierUtil.copyProperties(student,StudentSync.class);
+        dataSyncService.send(studentSync);
+    }
+    
+    public void sendSpecialty(Specialty specialty){
+    	SpecialtySync specialtySync = BeanCopierUtil.copyProperties(specialty,SpecialtySync.class);
+        dataSyncService.send(specialtySync);
+    }
+}

+ 36 - 36
examcloud-core-basic-export/src/main/java/cn/com/qmth/examcloud/service/core/util/ExportUtils.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/service/core/util/ExportUtils.java

@@ -1,36 +1,36 @@
-package cn.com.qmth.examcloud.service.core.util;
-
-import java.net.URLEncoder;
-import java.util.Collection;
-
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletResponse;
-
-import cn.com.qmth.examcloud.common.util.excel.ExcelWriter;
-
-/*
- * excel导出工具
- */
-public class ExportUtils {
-
-    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();
-        }
-    }
-}
+package cn.com.qmth.examcloud.service.core.util;
+
+import java.net.URLEncoder;
+import java.util.Collection;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
+import cn.com.qmth.examcloud.common.util.excel.ExcelWriter;
+
+/*
+ * excel导出工具
+ */
+public class ExportUtils {
+
+    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();
+        }
+    }
+}