宋悦 пре 8 година
родитељ
комит
48e6fd2de9

+ 14 - 6
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/CourseApi.java

@@ -52,10 +52,10 @@ public class CourseApi {
 
     @ApiOperation(value="查询课程分页带查询",notes="分页带查询")
     @GetMapping("/all/{curPage}/{pageSize}")
-    public ResponseEntity getAllOrg(@ModelAttribute Course course, 
-    		@PathVariable Integer curPage,
-    		@PathVariable Integer pageSize,
-    		HttpServletRequest request){
+    public ResponseEntity getAllOrg(@ModelAttribute Course course,
+                                    @PathVariable Integer curPage,
+                                    @PathVariable Integer pageSize,
+                                    HttpServletRequest request){
     	if(null == course.getOrgId()){
     		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
     		course.setOrgId(accessUser.getRootOrgId());
@@ -87,15 +87,23 @@ public class CourseApi {
 
     @ApiOperation(value="新增课程",notes="新增")
     @PostMapping
-    public ResponseEntity addCourse(@RequestBody Course course){
+    public ResponseEntity addCourse(@RequestBody Course course,HttpServletRequest request){
     	course.setCreateTime(new Date());
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            course.setOrgId(accessUser.getRootOrgId());
+        }
         return new ResponseEntity(courseRepo.save(course),HttpStatus.CREATED);
     }
 
     @ApiOperation(value="更新课程",notes="更新")
     @PutMapping
-    public ResponseEntity updateCourse(@RequestBody Course course){
+    public ResponseEntity updateCourse(@RequestBody Course course,HttpServletRequest request){
     	course.setUpdateTime(new Date());
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            course.setOrgId(accessUser.getRootOrgId());
+        }
         return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
     }
 

+ 42 - 12
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/OrgApi.java

@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiOperation;
 import java.io.IOException;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
@@ -43,14 +45,16 @@ public class OrgApi {
 
     @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);
+    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);
+        return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
     }
 
     @ApiOperation(value="按ID查询机构",notes="ID查询")
@@ -59,11 +63,21 @@ public class OrgApi {
         return new ResponseEntity(orgRepo.findOne(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);
-//    }
+    @ApiOperation(value="查询下属机构不带分页",notes="不分页")
+    @GetMapping("/sub/{parentId}")
+    public ResponseEntity getOrgByParentId(@PathVariable Long parentId){
+        return new ResponseEntity(orgRepo.findByParentId(parentId),HttpStatus.OK);
+    }
+
+    @ApiOperation(value="查询下属机构分页带查询",notes="分页")
+    @GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
+    public ResponseEntity getAllSubOrg(@ModelAttribute Org orgCriteria,
+                                       @PathVariable Long parentId,
+                                       @PathVariable Integer curPage,
+                                       @PathVariable Integer pageSize){
+        orgCriteria.setParentId(parentId);
+        return new ResponseEntity(orgService.findAll(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+    }
 //
 //    @ApiOperation(value="按rootId查询下属机构不带分页",notes="下属机构查询不带分页")
 //    @GetMapping("/allSub/{rootId}")
@@ -104,10 +118,26 @@ public class OrgApi {
 		}
     }
     
-    @ApiOperation(value="禁用/启用机构",notes="禁用/启用")
-    @PutMapping("/{id}")
-    public ResponseEntity enableSchool(@PathVariable Long id,@RequestParam boolean enable){
-        return new ResponseEntity(orgService.enableSchool(id,enable),HttpStatus.OK);
+    @ApiOperation(value="启用机构",notes="启用")
+    @PutMapping("/enable/{ids}")
+    public ResponseEntity enableSchool(@PathVariable String ids){
+        List<Long> orgIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long orgId:orgIds){
+            orgService.enableSchool(orgId,true);
+        }
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    @ApiOperation(value="禁用机构",notes="禁用")
+    @PutMapping("/disable/{ids}")
+    public ResponseEntity disableSchool(@PathVariable String ids){
+        List<Long> orgIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long orgId:orgIds){
+            orgService.enableSchool(orgId,false);
+        }
+        return new ResponseEntity(HttpStatus.OK);
     }
     
     @ApiOperation(value="按code查询机构(学习中心)",notes="code查询")

+ 63 - 11
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/UserApi.java

@@ -2,17 +2,21 @@ package cn.com.qmth.examcloud.service.core.api;
 
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 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.UserRepo;
 import cn.com.qmth.examcloud.service.core.service.UserService;
 import io.swagger.annotations.ApiOperation;
 
 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.*;
 
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -31,11 +35,19 @@ public class UserApi {
     UserRepo userRepo;
 
 
-//    @ApiOperation(value="查询所有用户")
-//    @GetMapping
-//    public ResponseEntity getAllUser(){
-//        return new ResponseEntity(userRepo.findAll(), HttpStatus.OK);
-//    }
+    @ApiOperation(value="查询所有用户",notes="分页带查询")
+    @GetMapping("/all/{curPage}/{pageSize}")
+    public ResponseEntity getAllUser(@ModelAttribute User userCriteria,
+                                     @PathVariable Integer curPage,
+                                     @PathVariable Integer pageSize,
+                                     HttpServletRequest request){
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            userCriteria.setRootOrgId(accessUser.getRootOrgId());
+        }
+        return new ResponseEntity(userService.findAll(userCriteria,
+                new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+    }
 
     @ApiOperation(value="按id查询用户",notes="id查询")
     @GetMapping("/{id}")
@@ -59,7 +71,13 @@ public class UserApi {
 
     @ApiOperation(value="新增用户",notes="新增")
     @PostMapping
-    public ResponseEntity addUser(@RequestBody User user){
+    public ResponseEntity addUser(@RequestBody User user,HttpServletRequest request){
+        AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
+        if(accessUser != null){
+            user.setRootOrgId(accessUser.getRootOrgId());
+        }
+        user.setScope(UserScope.ORG);
+        user.setType(UserType.NOT_STUDENT);
         return new ResponseEntity(userRepo.save(user), HttpStatus.CREATED);
     }
 
@@ -71,8 +89,38 @@ public class UserApi {
 
     @ApiOperation(value="重置用户密码",notes="重置密码")
     @PutMapping("/resetPass/{id}")
-    public ResponseEntity resetPass(@PathVariable long id){
-        userService.initPassword(id);
+    public ResponseEntity resetPass(@PathVariable String id){
+        List<Long> ids = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long userId:ids){
+            userService.initPassword(userId);
+        }
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    @ApiOperation(value="启用用户",notes="启用用户")
+    @PutMapping("/enable/{ids}")
+    public ResponseEntity enableUser(@PathVariable String ids){
+        List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long userId:userIds){
+            User user = userRepo.findOne(userId);
+            user.setEnable(true);
+            userRepo.save(user);
+        }
+        return new ResponseEntity(HttpStatus.OK);
+    }
+
+    @ApiOperation(value="禁用用户",notes="禁用用户")
+    @PutMapping("/disable/{ids}")
+    public ResponseEntity disableUser(@PathVariable String ids){
+        List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long userId:userIds){
+            User user = userRepo.findOne(userId);
+            user.setEnable(false);
+            userRepo.save(user);
+        }
         return new ResponseEntity(HttpStatus.OK);
     }
 
@@ -84,9 +132,13 @@ public class UserApi {
     }
 
     @ApiOperation(value="按id删除用户",notes="删除")
-    @DeleteMapping("/{id}")
-    public ResponseEntity deleteUser(@PathVariable long id){
-        userRepo.delete(id);
+    @DeleteMapping("/{ids}")
+    public ResponseEntity deleteUser(@PathVariable String ids){
+        List<Long> userIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        for(Long userId:userIds){
+            userRepo.delete(userId);
+        }
         return new ResponseEntity(HttpStatus.OK);
     }
 

+ 7 - 6
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.contains;
 import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
 
 import java.io.InputStream;
@@ -84,19 +85,19 @@ public class OrgService {
 		return org;
 	}
 
-	public Page<Org> findAlL(Org orgCriteria, Pageable pageable) {
+	public Page<Org> findAll(Org orgCriteria, Pageable pageable) {
 		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-				.withMatcher("name", startsWith())
-				.withMatcher("code", startsWith());
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
 		Example<Org> examExamStudentple = Example.of(orgCriteria,
 				exampleMatcher);
 		return orgRepo.findAll(examExamStudentple, pageable);
 	}
 
-	public List<Org> findAlL(Org orgCriteria) {
+	public List<Org> findAll(Org orgCriteria) {
 		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-				.withMatcher("name", startsWith())
-				.withMatcher("code", startsWith());
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
         Example<Org> examExample = Example.of(orgCriteria,exampleMatcher);
         return orgRepo.findAll(examExample);
 	}

+ 5 - 1
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -28,6 +28,8 @@ 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 static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+
 /**
  * 学生服务类
  * Created by songyue on 17/1/14.
@@ -53,7 +55,9 @@ public class StudentService {
      * @return
      */
     public Page<Student> getAllStudent(Student studentCriteria, Pageable pageable){
-        ExampleMatcher exampleMatcher = ExampleMatcher.matching();
+        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name",contains())
+				.withMatcher("studentCode",contains()).withIgnoreNullValues();
         Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
         return studentRepo.findAll(studentExample,pageable);
     }

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

@@ -6,6 +6,10 @@ import java.util.stream.Collectors;
 
 import org.apache.commons.lang.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.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
@@ -26,6 +30,8 @@ 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.repo.UserRoleRepo;
 
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+
 /**
  * 用户服务类
  * Created by songyue on 17/1/13.
@@ -45,6 +51,15 @@ public class UserService {
     @Autowired
     UserRoleRepo userRoleRepo;
 
+    public Page<User> findAll(User userCriteria, Pageable pageable){
+        ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+                .withMatcher("name", contains())
+                .withMatcher("loginName", contains()).withIgnoreNullValues();
+        Example<User> example = Example.of(userCriteria, exampleMatcher);
+        Page<User> users = userRepo.findAll(example, pageable);
+        return users;
+    }
+
     /**
      * 初始化密码
      * @param userId
@@ -123,6 +138,7 @@ public class UserService {
                 .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());
         accessUser.setUserId(user.getId());

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

@@ -37,6 +37,8 @@ public class Student implements Serializable {
 
 	private String remark;
 
+	private Boolean enable;
+
 	@Temporal(value = TemporalType.DATE)
 	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 	private Date createTime;
@@ -121,6 +123,14 @@ public class Student implements Serializable {
 		this.updateTime = updateTime;
 	}
 
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
 	public Student() {
 	}
 }

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

@@ -2,15 +2,9 @@ package cn.com.qmth.examcloud.service.core.entity;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
-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.persistence.*;
 import javax.validation.constraints.NotNull;
 
 import org.springframework.format.annotation.DateTimeFormat;
@@ -61,7 +55,10 @@ public class User implements Serializable{
     private UserType type;
 
     @NotNull
-    private boolean enable;
+    private Boolean enable;
+
+    @OneToMany(cascade = { CascadeType.ALL })
+    private List<UserRole> userRoles;
 
     @Temporal(value = TemporalType.DATE)
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -163,11 +160,11 @@ public class User implements Serializable{
         this.type = type;
     }
 
-    public boolean isEnable() {
+    public Boolean getEnable() {
         return enable;
     }
 
-    public void setEnable(boolean enable) {
+    public void setEnable(Boolean enable) {
         this.enable = enable;
     }
 

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

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
+import java.util.List;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
@@ -10,9 +11,9 @@ import cn.com.qmth.examcloud.service.core.entity.Org;
  */
 public interface OrgRepo extends JpaRepository<Org,Long>,QueryByExampleExecutor<Org>{
 
-//    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);
 

+ 8 - 0
core-main/src/main/java/cn/com/qmth/examcloud/service/core/AccessControlConfig.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.service.core;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
@@ -25,4 +26,11 @@ public class AccessControlConfig extends WebMvcConfigurerAdapter {
 	public void addInterceptors(InterceptorRegistry registry) {
 		registry.addInterceptor(getInterceptor()).addPathPatterns("/**").excludePathPatterns("/**/swagger-ui.html#/**");
 	}
+	@Override
+	public void addCorsMappings(CorsRegistry registry) {
+		registry.addMapping("/**")
+				.allowedOrigins("*")
+				.allowedMethods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE")
+				.allowedHeaders("*");
+	}
 }

+ 0 - 16
core-main/src/main/java/cn/com/qmth/examcloud/service/core/Application.java

@@ -17,20 +17,4 @@ public class Application {
     public static void main(String[] args) throws Exception {
         SpringApplication.run(Application.class, args);
     }
-
-    @Bean
-    public WebMvcConfigurer corsConfigurer() {
-        return new WebMvcConfigurerAdapter() {
-            public void addCorsMappings(CorsRegistry registry) {
-                registry.addMapping("/**");
-
-//                registry.addMapping("/**")
-//                        .allowedOrigins("*")
-//                        .allowedMethods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE")
-//                        .allowedHeaders("*")
-//                        .exposedHeaders("access_token", "credentials", "refresh_token")
-//                        .allowCredentials(true).maxAge(3600);
-            }
-        };
-    }
 }