Ver código fonte

Merge branch 'master' of https://git.oschina.net/qmthcloud/ExamCloud-service-core.git

ting.yin 8 anos atrás
pai
commit
a3509890b7

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

@@ -54,10 +54,25 @@ public class OrgApi {
                                     @PathVariable Integer pageSize){
         return new ResponseEntity(orgService.findAll(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
     }
+
+    @ApiOperation(value="查询顶层机构分页带查询",notes="分页带查询")
+    @GetMapping("/parent/{curPage}/{pageSize}")
+    public ResponseEntity getParentOrg(@ModelAttribute Org orgCriteria,
+                                       @PathVariable Integer curPage,
+                                       @PathVariable Integer pageSize){
+        orgCriteria.setParentId(0L);
+        orgCriteria.setRootId(0L);
+        return new ResponseEntity(orgService.findAll(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+    }
     
     @ApiOperation(value="查询机构不分页带查询",notes = "不分页带查询")
     @GetMapping("/all")
-    public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria){
+    public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria,
+                                     HttpServletRequest request){
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if(accessUser != null){
+            return new ResponseEntity(orgRepo.findAllByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
+        }
         return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
     }
 
@@ -79,6 +94,7 @@ public class OrgApi {
                                        @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);
     }
@@ -165,6 +181,6 @@ public class OrgApi {
     @ApiOperation(value="按code查询机构(学习中心)",notes="code查询")
     @GetMapping()
     public ResponseEntity getCourseByCode(@RequestParam Long parentId,@RequestParam String code){
-        return new ResponseEntity(orgRepo.findByParentIdAndCode(parentId, code),HttpStatus.OK);
+        return new ResponseEntity(orgRepo.findFirstByParentIdAndCode(parentId, code),HttpStatus.OK);
     }
 }

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

@@ -91,7 +91,11 @@ public class UserApi {
     public ResponseEntity addUser(@RequestBody User user,HttpServletRequest request){
         AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
         if(accessUser != null){
-            user.setRootOrgId(accessUser.getRootOrgId());
+            if(accessUser.getRootOrgId() != 0){
+                user.setRootOrgId(accessUser.getRootOrgId());
+            }else{
+                user.setRootOrgId(user.getOrgId());
+            }
         }
         try {
 			return new ResponseEntity(userService.save(user), HttpStatus.CREATED);

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

@@ -56,7 +56,7 @@ public class OrgService {
 	}
 
 	private ExcelError importCheck(Org dto) {
-		Org org = orgRepo.findByParentIdAndCode(dto.getParentId(),dto.getCode());
+		Org org = orgRepo.findFirstByParentIdAndCode(dto.getParentId(),dto.getCode());
 		if(org!=null){
 			return new ExcelError("代码已存在");
 		}
@@ -108,7 +108,7 @@ public class OrgService {
 	}
 
 	private void checkCode(Long parentId,String code) {
-		Org old = orgRepo.findByParentIdAndCode(parentId,code);
+		Org old = orgRepo.findFirstByParentIdAndCode(parentId,code);
 		if(old!=null){
 			throw new RuntimeException("代码已存在");
 		}

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

@@ -155,7 +155,7 @@ public class StudentService {
                           String loginName,
                           String password,
                           LoginType loginType) throws Exception{
-        Org org = orgRepo.findByParentIdAndCode((long) 0, orgId);
+        Org org = orgRepo.findFirstByParentIdAndCode((long) 0, orgId);
         if (org == null) {
         	throw new RuntimeException("学校不存在");
         }

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

@@ -172,7 +172,7 @@ public class UserService {
      * @param token
      * @param user
      */
-    public void createAccessUser(String token,User user,Long studentId){
+    public void createAccessUser(String token,User user,Long studentId)throws Exception{
         AccessUser accessUser = new AccessUser();
         Set<UserRole> userRoleSet = new HashSet<UserRole>(user.getUserRoles());
         Map<String,Set<String>> rolesMap = userRoleSet.stream()
@@ -195,7 +195,7 @@ public class UserService {
      * @param token
      * @return
      */
-    public UserInfo getUserInfo(User user,String token){
+    public UserInfo getUserInfo(User user,String token)throws Exception{
         UserInfo userInfo = new UserInfo();
         Org org = orgRepo.findOne(user.getOrgId());
         Org rootOrg = orgRepo.findOne(user.getRootOrgId());
@@ -205,9 +205,13 @@ public class UserService {
         userInfo.setName(user.getName());
         userInfo.setAvatar(user.getAvatar());
         userInfo.setLoginName(user.getLoginName());
-        userInfo.setOrgName(org.getName());
-        userInfo.setRootOrgLogo(rootOrg.getLogo());
-        userInfo.setRootOrgName(rootOrg.getName());
+        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());

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

@@ -2,6 +2,8 @@ package cn.com.qmth.examcloud.service.core.repo;
 
 import java.util.List;
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.service.core.entity.Org;
@@ -15,7 +17,8 @@ public interface OrgRepo extends JpaRepository<Org,Long>,QueryByExampleExecutor<
 
     List<Org> findByParentId(long parentId);
 
-//    List<Org> findByLevel(int level);
+    @Query(nativeQuery = true,value = "select *from ecs_core_org where id=:parentId or parent_id=:parentId")
+    List<Org> findAllByParentId(@Param("parentId") long parentId);
 
-	Org findByParentIdAndCode(Long parentId, String code);
+	Org findFirstByParentIdAndCode(Long parentId, String code);
 }