wangwei 7 years ago
parent
commit
ecdb85d740

+ 64 - 78
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -17,7 +17,10 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -117,61 +120,44 @@ public class OrgController extends ControllerSupport{
 		return orgList;
 	}
 
-    @ApiOperation(value = "查询下属机构分页带查询", notes = "分页")
-    @GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
-    public ResponseEntity getAllSubOrg(@ModelAttribute Org orgCriteria,
-                                       @PathVariable Long parentId,
-                                       @PathVariable Integer curPage,
-                                       @PathVariable Integer pageSize) {
+	@ApiOperation(value = "查询下属机构分页带查询", notes = "分页")
+	@GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
+	public Page<Org> 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);
-    }
+		orgCriteria.setParentId(parentId);
+		Pageable pageable = new PageRequest(curPage-1, pageSize, Sort.Direction.DESC, "updateTime");
+		Page<Org> ret = orgService.findAll(orgCriteria, pageable);
+		return ret;
+	}
 
-//    @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
+	public Org addOrg(@RequestBody Org org, HttpServletRequest request) {
+		org.setCreateTime(new Date());
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		org.setParentId(accessUser.getRootOrgId());
+		org.setRootId(accessUser.getOrgId());
+		Org saved = orgService.save(org);
+		return saved;
+	}
 
-    @ApiOperation(value = "新增机构", notes = "新增")
-    @PostMapping
-    public ResponseEntity addSchool(@RequestBody Org org, HttpServletRequest request) {
-        org.setCreateTime(new Date());
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        if (accessUser != null) {
-            org.setParentId(accessUser.getRootOrgId());
-            org.setRootId(accessUser.getOrgId());
-        }
-        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);
-        }
-    }
+	@ApiOperation(value = "更新机构", notes = "更新")
+	@PutMapping
+	public Org updateOrg(@RequestBody Org org, HttpServletRequest request) {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
 
-    @ApiOperation(value = "更新机构", notes = "更新")
-    @PutMapping
-    public ResponseEntity updateSchool(@RequestBody Org org, HttpServletRequest request) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        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);
-        }
-    }
+		org.setParentId(accessUser.getOrgId());
+		org.setRootId(accessUser.getRootOrgId());
+		Org updated = orgService.update(org.getId(), org);
+		return updated;
+	}
 
-    @ApiOperation(value = "按ID删除机构", notes = "删除")
-    @DeleteMapping("/{id}")
-    public ResponseEntity deleteSchool(@PathVariable Long id) {
-        orgRepo.delete(id);
-        return new ResponseEntity(HttpStatus.OK);
-    }
+	@ApiOperation(value = "按ID删除机构", notes = "删除")
+	@DeleteMapping("/{id}")
+	public void deleteSchool(@PathVariable Long id) {
+		orgRepo.delete(id);
+	}
 
     @ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
     @PostMapping("/import")
@@ -202,32 +188,30 @@ public class OrgController extends ControllerSupport{
 
     @ApiOperation(value = "启用机构", notes = "启用")
     @PutMapping("/enable/{ids}")
-    public ResponseEntity enableSchool(@PathVariable String ids) {
+    public void 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 = "禁用机构", notes = "禁用")
+	@PutMapping("/disable/{ids}")
+	public void 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);
+		}
+	}
 
-    @ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
-    @GetMapping()
-    public ResponseEntity getCourseByCode(@RequestParam Long parentId, @RequestParam String code) {
-    	Org org = orgRepo.findFirstByParentIdAndCode(parentId, code);
-        return new ResponseEntity(org, HttpStatus.OK);
-    }
+	@ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
+	@GetMapping()
+	public Org getCourseByCode(@RequestParam Long parentId, @RequestParam String code) {
+		Org org = orgRepo.findFirstByParentIdAndCode(parentId, code);
+		return org;
+	}
 
 	@ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
 	@GetMapping("/logo")
@@ -251,17 +235,19 @@ public class OrgController extends ControllerSupport{
     }
     
     
-    @ApiOperation(value = "查询所有学校", notes = "查询所有学校")
-    @GetMapping("/getAllParentOrg")
-    public ResponseEntity getAllParentOrg(){
-    	return new ResponseEntity(orgRepo.findAllParentOrg(), HttpStatus.OK);
-    }
+	@ApiOperation(value = "查询所有学校", notes = "查询所有学校")
+	@GetMapping("/getAllParentOrg")
+	public List<Org> getAllParentOrg() {
+		List<Org> list = orgRepo.findAllParentOrg();
+		return list;
+	}
 
-    @ApiOperation(value = "查询所有印刷机构", notes = "查询所有印刷机构")
-    @GetMapping("/allPrint")
-    public ResponseEntity getAllPrintOrg() {
-        return new ResponseEntity(orgRepo.findAllPrintByParentId(0L), HttpStatus.OK);
-    }
+	@ApiOperation(value = "查询所有印刷机构", notes = "查询所有印刷机构")
+	@GetMapping("/allPrint")
+	public List<Org> getAllPrintOrg() {
+		List<Org> orgList = orgRepo.findAllPrintByParentId(0L);
+		return orgList;
+	}
     
 	@ApiOperation(value = "导入logo", notes = "导入logo")
 	@PostMapping("/importLogo/{id}")