ting.yin 8 år sedan
förälder
incheckning
8266fd9432

+ 22 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/CourseApi.java

@@ -10,10 +10,12 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -46,27 +48,34 @@ public class CourseApi {
     @Autowired
     CourseAssembler courseAssembler;
 
-    @ApiOperation(value="查询所有课程",notes="enable为查询条件,可为空")
-    @GetMapping
-    public ResponseEntity getAllCourse(@RequestParam Long orgId,@RequestParam(required = false) Boolean enable){
-    	List<Course> list = null;
-    	if(enable!=null){
-    		list = courseRepo.findByOrgIdAndEnable(orgId,enable);
-    	}else{
-    		list = courseRepo.findByOrgId(orgId);
-    	}
-    	return new ResponseEntity(list, HttpStatus.OK);
+    @ApiOperation(value="查询课程分页带查询",notes="分页带查询")
+    @GetMapping("/all/{curPage}/{pageSize}")
+    public ResponseEntity getAllOrg(@ModelAttribute Course course, @PathVariable Integer curPage,@PathVariable Integer pageSize){
+        return new ResponseEntity(courseService.findAlL(course,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
     }
-
+    
+    @ApiOperation(value="查询课程不分页带查询",notes = "不分页带查询")
+    @GetMapping("/all")
+    public ResponseEntity getAllExam(@ModelAttribute Course course){
+        return new ResponseEntity(courseService.findAlL(course), HttpStatus.OK);
+    }
+    
     @ApiOperation(value="按ID查询课程",notes="ID查询")
     @GetMapping("/{id}")
     public ResponseEntity getCourseById(@PathVariable Long id){
         return new ResponseEntity(courseRepo.findOne(id),HttpStatus.OK);
     }
+    
+    @ApiOperation(value="按code查询课程",notes="code查询")
+    @GetMapping()
+    public ResponseEntity getCourseByCode(@RequestParam Long orgId,@RequestParam String code){
+        return new ResponseEntity(courseRepo.findByOrgIdAndCode(orgId, code),HttpStatus.OK);
+    }
 
     @ApiOperation(value="新增课程",notes="新增")
     @PostMapping
     public ResponseEntity addCourse(@RequestBody Course course){
+    	course.setCreateTime(new Date());
         return new ResponseEntity(courseRepo.save(course),HttpStatus.CREATED);
     }
 
@@ -98,9 +107,9 @@ public class CourseApi {
     
     @ApiOperation(value="导出课程",notes = "导出")
     @GetMapping("/export")
-    public void exportCourse(@RequestParam Long orgId,HttpServletResponse response){
+    public void exportCourse(@ModelAttribute Course orgCriteria,HttpServletResponse response){
     	List<CourseDTO> list = new ArrayList<CourseDTO>();
-    	courseRepo.findByOrgId(orgId).forEach(c -> {
+    	courseService.findAlL(orgCriteria).forEach(c -> {
     		list.add(courseAssembler.toDTO(c));
         });
     	ExportUtils.exportEXCEL("课程列表", CourseDTO.class, list, response);

+ 31 - 17
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/OrgApi.java

@@ -7,10 +7,12 @@ import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -39,29 +41,35 @@ public class OrgApi {
     @Autowired
     OrgService orgService;
 
-//    @ApiOperation(value="查询所有机构")
-//    @GetMapping
-//    public ResponseEntity getAllOrg(){
-//        return new ResponseEntity(orgRepo.findAll(), HttpStatus.OK);
-//    }
+    @ApiOperation(value="查询机构分页带查询",notes="分页带查询")
+    @GetMapping("/all/{curPage}/{pageSize}")
+    public ResponseEntity getAllOrg(@ModelAttribute Org orgCriteria, @PathVariable Integer curPage,@PathVariable Integer pageSize){
+        return new ResponseEntity(orgService.findAlL(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+    }
+    
+    @ApiOperation(value="查询机构不分页带查询",notes = "不分页带查询")
+    @GetMapping("/all")
+    public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria){
+        return new ResponseEntity(orgService.findAlL(orgCriteria), HttpStatus.OK);
+    }
 
     @ApiOperation(value="按ID查询机构",notes="ID查询")
     @GetMapping("/{id}")
     public ResponseEntity<Org> getOrgById(@PathVariable Long id){
-        return new ResponseEntity(orgRepo.findById(id),HttpStatus.OK);
-    }
-
-    @ApiOperation(value="按parentId查询下属机构",notes="下属机构查询")
-    @GetMapping("/sub/{parentId}")
-    public ResponseEntity<Org> getOrgByParentId(@PathVariable Long parentId){
-        return new ResponseEntity(orgRepo.findByParentId(parentId),HttpStatus.OK);
+        return new ResponseEntity(orgRepo.findOne(id),HttpStatus.OK);
     }
 
-    @ApiOperation(value="按rootId查询下属机构",notes="下属机构查询")
-    @GetMapping("/allSub/{rootId}")
-    public ResponseEntity<Org> getOrgByRootId(@PathVariable Long rootId){
-        return new ResponseEntity(orgRepo.findByRootId(rootId),HttpStatus.OK);
-    }
+//    @ApiOperation(value="按parentId查询下属机构不带分页",notes="下属机构查询不带分页")
+//    @GetMapping("/sub/{parentId}")
+//    public ResponseEntity<Org> getOrgByParentId(@PathVariable Long parentId){
+//        return new ResponseEntity(orgRepo.findByParentId(parentId),HttpStatus.OK);
+//    }
+//
+//    @ApiOperation(value="按rootId查询下属机构不带分页",notes="下属机构查询不带分页")
+//    @GetMapping("/allSub/{rootId}")
+//    public ResponseEntity<Org> getOrgByRootId(@PathVariable Long rootId){
+//        return new ResponseEntity(orgRepo.findByRootId(rootId),HttpStatus.OK);
+//    }
 
     @ApiOperation(value="新增机构",notes="新增")
     @PostMapping
@@ -100,4 +108,10 @@ public class OrgApi {
     public ResponseEntity enableSchool(@PathVariable Long id,@RequestParam boolean enable){
         return new ResponseEntity(orgService.enableSchool(id,enable),HttpStatus.OK);
     }
+    
+    @ApiOperation(value="按code查询机构(学习中心)",notes="code查询")
+    @GetMapping()
+    public ResponseEntity getCourseByCode(@RequestParam Long parentId,@RequestParam String code){
+        return new ResponseEntity(orgRepo.findByParentIdAndCode(parentId, code),HttpStatus.OK);
+    }
 }

+ 15 - 12
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/StudentApi.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.service.core.api;
 import io.swagger.annotations.ApiOperation;
 
 import java.io.File;
+import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -39,17 +40,17 @@ public class StudentApi {
     @Autowired
     StudentService studentService;
 
-//    @ApiOperation(value="查询所有学生",notes="分页")
-//    @GetMapping("/{curPage}/{pageSize}")
-//    public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
-//        return new ResponseEntity(studentService.getAllStudent(studentCriteria,new PageRequest(curPage - 1,pageSize)),HttpStatus.OK);
-//    }
-//
-//    @ApiOperation(value="查询所有学生",notes="不分页")
-//    @GetMapping
-//    public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria){
-//        return new ResponseEntity(studentService.getAllStudent(studentCriteria),HttpStatus.OK);
-//    }
+    @ApiOperation(value="查询所有学生",notes="分页")
+    @GetMapping("/{curPage}/{pageSize}")
+    public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria, @PathVariable Integer curPage, @PathVariable Integer pageSize){
+        return new ResponseEntity(studentService.getAllStudent(studentCriteria,new PageRequest(curPage - 1,pageSize)),HttpStatus.OK);
+    }
+
+    @ApiOperation(value="查询所有学生",notes="不分页")
+    @GetMapping
+    public ResponseEntity getAllStudent(@ModelAttribute Student studentCriteria){
+        return new ResponseEntity(studentService.getAllStudent(studentCriteria),HttpStatus.OK);
+    }
 
     @ApiOperation(value="按ID查询学生",notes="ID查询")
     @GetMapping("/{id}")
@@ -60,12 +61,14 @@ public class StudentApi {
     @ApiOperation(value="新增学生",notes="新增")
     @PostMapping
     public ResponseEntity addStudent(@RequestBody Student student){
-        return new ResponseEntity(studentRepo.save(student),HttpStatus.CREATED);
+    	student.setCreateTime(new Date());
+        return new ResponseEntity(studentService.save(student),HttpStatus.CREATED);
     }
 
     @ApiOperation(value="更新学生",notes="更新")
     @PutMapping
     public ResponseEntity updateStudent(@RequestBody Student student){
+    	student.setUpdateTime(new Date());
         return new ResponseEntity(studentRepo.save(student),HttpStatus.OK);
     }
 

+ 23 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java

@@ -1,10 +1,16 @@
 package cn.com.qmth.examcloud.service.core.service;
 
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
+
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.common.util.excel.ExcelError;
@@ -57,5 +63,22 @@ public class CourseService {
 		}
 		return null;
 	}
+	
+	public Page<Course> findAlL(Course orgCriteria, Pageable pageable) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", startsWith())
+				.withMatcher("code", startsWith());
+		Example<Course> examExamStudentple = Example.of(orgCriteria,
+				exampleMatcher);
+		return courseRepo.findAll(examExamStudentple, pageable);
+	}
+
+	public List<Course> findAlL(Course orgCriteria) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", startsWith())
+				.withMatcher("code", startsWith());
+        Example<Course> examExample = Example.of(orgCriteria,exampleMatcher);
+        return courseRepo.findAll(examExample);
+	}
 
 }

+ 23 - 1
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java

@@ -1,4 +1,5 @@
 package cn.com.qmth.examcloud.service.core.service;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
 
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -6,6 +7,10 @@ import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -28,7 +33,7 @@ public class OrgService {
     @Transactional
 	public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
 		List<Org> list = new ArrayList<Org>();
-		Org parentOrg = orgRepo.findById(orgId);
+		Org parentOrg = orgRepo.findOne(orgId);
 		ExcelReader excelReader = new ExcelReader(Org.class);
         List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
             @Override
@@ -79,4 +84,21 @@ public class OrgService {
 		return org;
 	}
 
+	public Page<Org> findAlL(Org orgCriteria, Pageable pageable) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", startsWith())
+				.withMatcher("code", startsWith());
+		Example<Org> examExamStudentple = Example.of(orgCriteria,
+				exampleMatcher);
+		return orgRepo.findAll(examExamStudentple, pageable);
+	}
+
+	public List<Org> findAlL(Org orgCriteria) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", startsWith())
+				.withMatcher("code", startsWith());
+        Example<Org> examExample = Example.of(orgCriteria,exampleMatcher);
+        return orgRepo.findAll(examExample);
+	}
+
 }

+ 23 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -10,10 +10,15 @@ 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.util.ErrorMsg;
 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.enums.UserScope;
+import cn.com.qmth.examcloud.service.core.enums.UserType;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
 
 /**
  * 学生服务类
@@ -24,6 +29,8 @@ public class StudentService {
 	
     @Autowired
     StudentRepo studentRepo;
+    @Autowired
+    UserRepo userRepo;
     
     private static final String JPG = ".jpg";
 
@@ -78,4 +85,20 @@ public class StudentService {
 		return list;
 	}
 
+	public Student save(Student student) {
+		if(student.getUser()==null || null==student.getUser().getId()){
+			User user=new User(student.getName(), UserScope.ORG, student.getUser().getRootOrgId(), student.getUser().getOrgId(), UserType.STUDENT);
+			String password = null;
+			if(!StringUtils.isEmpty(student.getStudentCode())){//学号后6位
+				password = student.getStudentCode().substring(student.getStudentCode().length()-6, student.getStudentCode().length());
+			}else{
+				password = student.getIdentityNumber().substring(student.getIdentityNumber().length()-6,student.getIdentityNumber().length());
+			}
+			user.setPassword(password);
+			userRepo.save(user);
+			student.setUser(user);
+		}
+		return studentRepo.save(student);
+	}
+
 }

+ 2 - 2
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java

@@ -139,8 +139,8 @@ public class UserService {
      */
     public UserInfo getUserInfo(User user,String token){
         UserInfo userInfo = new UserInfo();
-        Org org = orgRepo.findById(user.getOrgId());
-        Org rootOrg = orgRepo.findById(user.getRootOrgId());
+        Org org = orgRepo.findOne(user.getOrgId());
+        Org rootOrg = orgRepo.findOne(user.getRootOrgId());
         userInfo.setUserId(user.getId());
         userInfo.setOrgId(user.getOrgId());
         userInfo.setRootOrgId(user.getRootOrgId());

+ 1 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/assemble/CourseAssembler.java

@@ -15,6 +15,7 @@ public class CourseAssembler {
 			dto.setName(course.getName());
 			dto.setCode(course.getCode());
 			dto.setLevel(course.getLevel().getName());
+//			dto.setEnable(course.getEnable()?"启用":"禁用");
 		}
 		return dto;
 	}

+ 11 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/dto/CourseDTO.java

@@ -21,6 +21,9 @@ public class CourseDTO{
 	
     @ExcelProperty(index = 2,name = "层次")
 	private String level;
+    
+//    @ExcelProperty(index = 3,name = "状态",type = 1)
+	private String enable;
 
 	public String getCode() {
 		return code;
@@ -54,6 +57,14 @@ public class CourseDTO{
 		this.level = level;
 	}
 
+	public String getEnable() {
+		return enable;
+	}
+
+	public void setEnable(String enable) {
+		this.enable = enable;
+	}
+
 	public CourseDTO() {
 	}
 }

+ 12 - 10
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Course.java

@@ -9,8 +9,6 @@ import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.Table;
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
 import javax.validation.constraints.NotNull;
 
 import org.springframework.format.annotation.DateTimeFormat;
@@ -54,7 +52,7 @@ public class Course implements Serializable{
 	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 	private Date updateTime;
 
-	private boolean enable;
+	private Boolean enable;
 
 	public static long getSerialVersionUID() {
 		return serialVersionUID;
@@ -100,15 +98,19 @@ public class Course implements Serializable{
 		this.updateTime = updateTime;
 	}
 
-    public boolean isEnable() {
-        return enable;
-    }
+    public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
 
-    public void setEnable(boolean enable) {
-        this.enable = enable;
-    }
+	public static long getSerialversionuid() {
+		return serialVersionUID;
+	}
 
-    public Long getOrgId() {
+	public Long getOrgId() {
 		return orgId;
 	}
 

+ 3 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Org.java

@@ -56,7 +56,7 @@ public class Org implements Serializable{
     private String apps;
 
     @NotNull
-    private boolean enable;
+    private Boolean enable;
     
     /**
      * 联系电话
@@ -145,11 +145,11 @@ public class Org implements Serializable{
         this.apps = apps;
     }
 
-    public boolean isEnable() {
+	public Boolean getEnable() {
 		return enable;
 	}
 
-	public void setEnable(boolean enable) {
+	public void setEnable(Boolean enable) {
 		this.enable = enable;
 	}
 

+ 2 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Student.java

@@ -4,6 +4,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 
 import javax.persistence.*;
 import javax.validation.constraints.NotNull;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -29,6 +30,7 @@ public class Student implements Serializable {
 
 	private String studentCode;
 
+	@Column(unique=true)
 	private String identityNumber;
 
 	private String photoPath;

+ 24 - 7
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/User.java

@@ -1,14 +1,23 @@
 package cn.com.qmth.examcloud.service.core.entity;
 
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.validation.constraints.NotNull;
+
+import org.springframework.format.annotation.DateTimeFormat;
+
 import cn.com.qmth.examcloud.service.core.enums.Gender;
 import cn.com.qmth.examcloud.service.core.enums.UserScope;
 import cn.com.qmth.examcloud.service.core.enums.UserType;
-import org.springframework.format.annotation.DateTimeFormat;
-
-import javax.persistence.*;
-import javax.validation.constraints.NotNull;
-import java.io.Serializable;
-import java.util.Date;
 
 /**
  * Created by songyue on 17/1/13.
@@ -30,7 +39,6 @@ public class User implements Serializable{
     @NotNull
     private String name;
 
-    @NotNull
     private String loginName;
 
     @NotNull
@@ -180,4 +188,13 @@ public class User implements Serializable{
 
     public User() {
     }
+    
+    public User(String name,UserScope scope,Long rootOrgId,Long orgId,UserType type) {
+    	this.name = name;
+    	this.scope = scope;
+    	this.rootOrgId = rootOrgId;
+    	this.orgId = orgId;
+    	this.type = type;
+    	this.createTime = new Date();
+    }
 }

+ 1 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/CourseRepo.java

@@ -9,10 +9,8 @@ import cn.com.qmth.examcloud.service.core.entity.Course;
 
 public interface CourseRepo extends JpaRepository<Course, Long>,QueryByExampleExecutor<Course> {
 
-    Course findByOrgIdAndCode(Long orgId,String code);
-
 	List<Course> findByOrgId(Long orgId);
 
-	List<Course> findByOrgIdAndEnable(Long orgId, Boolean enable);
+	Course findByOrgIdAndCode(Long orgId, String code);
 
 }

+ 5 - 9
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/OrgRepo.java

@@ -1,24 +1,20 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
-import cn.com.qmth.examcloud.service.core.entity.Org;
-
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import java.util.List;
+import cn.com.qmth.examcloud.service.core.entity.Org;
 
 /**
  * Created by songyue on 17/1/13.
  */
 public interface OrgRepo extends JpaRepository<Org,Long>,QueryByExampleExecutor<Org>{
 
-    Org findById(long id);
-
-    List<Org> findByRootId(long rootId);
-
-    List<Org> findByParentId(long parentId);
+//    List<Org> findByRootId(long rootId);
+//
+//    List<Org> findByParentId(long parentId);
 
-    List<Org> findByLevel(int level);
+//    List<Org> findByLevel(int level);
 
 	Org findByParentIdAndCode(Long parentId, String code);
 }

+ 1 - 0
core-main/src/main/resources/application.properties

@@ -25,5 +25,6 @@ spring.http.multipart.max-file-size=10Mb
 spring.application.name=ExamCloud-service-core
 server.port=8000
 eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
+hystrix.command.default.execution.timeout.enabled=false
 app.api.root=/api/ecs_core