ソースを参照

Merge branch 'master' into v1.0.1

# Conflicts:
#	core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java
宋悦 8 年 前
コミット
e59c067b1d

+ 85 - 62
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/OrgApi.java

@@ -3,12 +3,17 @@ package cn.com.qmth.examcloud.service.core.api;
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import io.swagger.annotations.ApiOperation;
 
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import io.swagger.models.Response;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
@@ -32,6 +37,7 @@ import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
 import cn.com.qmth.examcloud.service.core.service.OrgService;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * 机构服务API
@@ -41,62 +47,64 @@ import javax.servlet.http.HttpServletRequest;
 @RequestMapping("${app.api.root}/org")
 public class OrgApi {
 
+    private static final Logger LOG = LoggerFactory.getLogger(OrgApi.class);
+
     @Autowired
     OrgRepo orgRepo;
 
     @Autowired
     OrgService orgService;
 
-    @ApiOperation(value="查询机构分页带查询",notes="分页带查询")
+    @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);
+                                    @PathVariable Integer pageSize) {
+        return new ResponseEntity(orgService.findAll(orgCriteria, new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
     }
 
-    @ApiOperation(value="查询顶层机构分页带查询",notes="分页带查询")
+    @ApiOperation(value = "查询顶层机构分页带查询", notes = "分页带查询")
     @GetMapping("/parent/{curPage}/{pageSize}")
     public ResponseEntity getParentOrg(@ModelAttribute Org orgCriteria,
                                        @PathVariable Integer curPage,
-                                       @PathVariable Integer pageSize){
+                                       @PathVariable Integer pageSize) {
         orgCriteria.setParentId(0L);
         orgCriteria.setRootId(0L);
-        return new ResponseEntity(orgService.findAll(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+        return new ResponseEntity(orgService.findAll(orgCriteria, new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
     }
-    
-    @ApiOperation(value="查询机构不分页带查询",notes = "不分页带查询")
+
+    @ApiOperation(value = "查询机构不分页带查询", notes = "不分页带查询")
     @GetMapping("/all")
     public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria,
-                                     HttpServletRequest request){
+                                     HttpServletRequest request) {
         AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-        if(accessUser != null){
+        if (accessUser != null) {
             return new ResponseEntity(orgRepo.findAllByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
         }
         return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
     }
 
-    @ApiOperation(value="按ID查询机构",notes="ID查询")
+    @ApiOperation(value = "按ID查询机构", notes = "ID查询")
     @GetMapping("/{id}")
-    public ResponseEntity<Org> getOrgById(@PathVariable Long id){
-        return new ResponseEntity(orgRepo.findOne(id),HttpStatus.OK);
+    public ResponseEntity<Org> getOrgById(@PathVariable Long id) {
+        return new ResponseEntity(orgRepo.findOne(id), HttpStatus.OK);
     }
 
-    @ApiOperation(value="查询下属机构不带分页",notes="不分页")
+    @ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
     @GetMapping("/sub/{parentId}")
-    public ResponseEntity getOrgByParentId(@PathVariable Long parentId){
-        return new ResponseEntity(orgRepo.findByParentId(parentId),HttpStatus.OK);
+    public ResponseEntity getOrgByParentId(@PathVariable Long parentId) {
+        return new ResponseEntity(orgRepo.findByParentId(parentId), HttpStatus.OK);
     }
 
-    @ApiOperation(value="查询下属机构分页带查询",notes="分页")
+    @ApiOperation(value = "查询下属机构分页带查询", notes = "分页")
     @GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
     public ResponseEntity getAllSubOrg(@ModelAttribute Org orgCriteria,
                                        @PathVariable Long parentId,
                                        @PathVariable Integer curPage,
-                                       @PathVariable Integer pageSize){
+                                       @PathVariable Integer pageSize) {
 
         orgCriteria.setParentId(parentId);
-        return new ResponseEntity(orgService.findAll(orgCriteria,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
+        return new ResponseEntity(orgService.findAll(orgCriteria, new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
     }
 
 //    @ApiOperation(value="按rootId查询下属机构不带分页",notes="下属机构查询不带分页")
@@ -105,82 +113,97 @@ public class OrgApi {
 //        return new ResponseEntity(orgRepo.findByRootId(rootId),HttpStatus.OK);
 //    }
 
-    @ApiOperation(value="新增机构",notes="新增")
+    @ApiOperation(value = "新增机构", notes = "新增")
     @PostMapping
-    public ResponseEntity addSchool(@RequestBody Org org, HttpServletRequest request){
-    	org.setCreateTime(new Date());
+    public ResponseEntity addSchool(@RequestBody Org org, HttpServletRequest request) {
+        org.setCreateTime(new Date());
         AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-        if(accessUser != null){
+        if (accessUser != null) {
             org.setParentId(accessUser.getOrgId());
             org.setRootId(accessUser.getRootOrgId());
         }
         try {
-			return new ResponseEntity(orgService.save(org), HttpStatus.CREATED);
-		} catch (Exception e) {
-		    e.printStackTrace();
-			return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
-		}
+            return new ResponseEntity(orgService.save(org), HttpStatus.CREATED);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
-    @ApiOperation(value="更新机构",notes="更新")
+    @ApiOperation(value = "更新机构", notes = "更新")
     @PutMapping
-    public ResponseEntity updateSchool(@RequestBody Org org,HttpServletRequest request){
+    public ResponseEntity updateSchool(@RequestBody Org org, HttpServletRequest request) {
         AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-        if(accessUser != null){
+        if (accessUser != null) {
             org.setParentId(accessUser.getOrgId());
             org.setRootId(accessUser.getRootOrgId());
         }
         try {
-			return new ResponseEntity(orgService.update(org.getId(),org), HttpStatus.OK);
-		} catch (Exception e) {
-			return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
-		}
+            return new ResponseEntity(orgService.update(org.getId(), org), HttpStatus.OK);
+        } catch (Exception e) {
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
 
-    @ApiOperation(value="按ID删除机构",notes="删除")
+    @ApiOperation(value = "按ID删除机构", notes = "删除")
     @DeleteMapping("/{id}")
-    public ResponseEntity deleteSchool(@PathVariable Long id){
+    public ResponseEntity deleteSchool(@PathVariable Long id) {
         orgRepo.delete(id);
         return new ResponseEntity(HttpStatus.OK);
     }
-    
-    @ApiOperation(value="按父ID导入子机构",notes="导入子机构")
+
+    @ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
     @PostMapping("/{id}/import")
-    public ResponseEntity importLearnCenter(@PathVariable Long id,@RequestParam MultipartFile file){
-    	try {
-			List<ExcelError> excelErrors = orgService.importLearnCenter(id,file.getInputStream());
-			return new ResponseEntity(excelErrors,HttpStatus.OK);
-		} catch (IOException e) {
-			e.printStackTrace();
-			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
-		}
+    public ResponseEntity importLearnCenter(@PathVariable Long id, @RequestParam MultipartFile file) {
+        try {
+            List<ExcelError> excelErrors = orgService.importLearnCenter(id, file.getInputStream());
+            return new ResponseEntity(excelErrors, HttpStatus.OK);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
+        }
     }
-    
-    @ApiOperation(value="启用机构",notes="启用")
+
+    @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()))
+    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);
+        for (Long orgId : orgIds) {
+            orgService.enableSchool(orgId, true);
         }
         return new ResponseEntity(HttpStatus.OK);
     }
 
-    @ApiOperation(value="禁用机构",notes="禁用")
+    @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()))
+    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);
+        for (Long orgId : orgIds) {
+            orgService.enableSchool(orgId, false);
         }
         return new ResponseEntity(HttpStatus.OK);
     }
-    
-    @ApiOperation(value="按code查询机构(学习中心)",notes="code查询")
+
+    @ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
     @GetMapping()
-    public ResponseEntity getCourseByCode(@RequestParam Long parentId,@RequestParam String code){
-        return new ResponseEntity(orgRepo.findFirstByParentIdAndCode(parentId, code),HttpStatus.OK);
+    public ResponseEntity getCourseByCode(@RequestParam Long parentId, @RequestParam String code) {
+        return new ResponseEntity(orgRepo.findFirstByParentIdAndCode(parentId, code), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
+    @GetMapping("/logo")
+    public void logo(@RequestParam("domain") String domain, HttpServletResponse response) {
+        Org org = orgRepo.findFirstByParentIdAndCode(0L, domain);
+
+        String logo = org.getLogo();
+        try {
+            IOUtils.copy(new FileInputStream(logo), response.getOutputStream());
+            response.flushBuffer();
+        } catch (IOException e) {
+            LOG.error("下载LOGO失败,", e);
+        }
+
     }
 }

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

@@ -304,14 +304,14 @@ public class UserService {
 		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用户");
+	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);