|
@@ -3,12 +3,17 @@ package cn.com.qmth.examcloud.service.core.api;
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
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.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.http.HttpStatus;
|
|
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 cn.com.qmth.examcloud.service.core.service.OrgService;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 机构服务API
|
|
* 机构服务API
|
|
@@ -41,62 +47,64 @@ import javax.servlet.http.HttpServletRequest;
|
|
@RequestMapping("${app.api.root}/org")
|
|
@RequestMapping("${app.api.root}/org")
|
|
public class OrgApi {
|
|
public class OrgApi {
|
|
|
|
|
|
|
|
+ private static final Logger LOG = LoggerFactory.getLogger(OrgApi.class);
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
OrgRepo orgRepo;
|
|
OrgRepo orgRepo;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
OrgService orgService;
|
|
OrgService orgService;
|
|
|
|
|
|
- @ApiOperation(value="查询机构分页带查询",notes="分页带查询")
|
|
|
|
|
|
+ @ApiOperation(value = "查询机构分页带查询", notes = "分页带查询")
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
public ResponseEntity getAllOrg(@ModelAttribute Org orgCriteria,
|
|
public ResponseEntity getAllOrg(@ModelAttribute Org orgCriteria,
|
|
@PathVariable Integer curPage,
|
|
@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}")
|
|
@GetMapping("/parent/{curPage}/{pageSize}")
|
|
public ResponseEntity getParentOrg(@ModelAttribute Org orgCriteria,
|
|
public ResponseEntity getParentOrg(@ModelAttribute Org orgCriteria,
|
|
@PathVariable Integer curPage,
|
|
@PathVariable Integer curPage,
|
|
- @PathVariable Integer pageSize){
|
|
|
|
|
|
+ @PathVariable Integer pageSize) {
|
|
orgCriteria.setParentId(0L);
|
|
orgCriteria.setParentId(0L);
|
|
orgCriteria.setRootId(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")
|
|
@GetMapping("/all")
|
|
public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria,
|
|
public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria,
|
|
- HttpServletRequest request){
|
|
|
|
|
|
+ HttpServletRequest request) {
|
|
AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
- if(accessUser != null){
|
|
|
|
|
|
+ if (accessUser != null) {
|
|
return new ResponseEntity(orgRepo.findAllByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
|
|
return new ResponseEntity(orgRepo.findAllByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
|
|
}
|
|
}
|
|
return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
|
|
return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="按ID查询机构",notes="ID查询")
|
|
|
|
|
|
+ @ApiOperation(value = "按ID查询机构", notes = "ID查询")
|
|
@GetMapping("/{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}")
|
|
@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}")
|
|
@GetMapping("/sub/{parentId}/{curPage}/{pageSize}")
|
|
public ResponseEntity getAllSubOrg(@ModelAttribute Org orgCriteria,
|
|
public ResponseEntity getAllSubOrg(@ModelAttribute Org orgCriteria,
|
|
@PathVariable Long parentId,
|
|
@PathVariable Long parentId,
|
|
@PathVariable Integer curPage,
|
|
@PathVariable Integer curPage,
|
|
- @PathVariable Integer pageSize){
|
|
|
|
|
|
+ @PathVariable Integer pageSize) {
|
|
|
|
|
|
orgCriteria.setParentId(parentId);
|
|
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="下属机构查询不带分页")
|
|
// @ApiOperation(value="按rootId查询下属机构不带分页",notes="下属机构查询不带分页")
|
|
@@ -105,82 +113,97 @@ public class OrgApi {
|
|
// return new ResponseEntity(orgRepo.findByRootId(rootId),HttpStatus.OK);
|
|
// return new ResponseEntity(orgRepo.findByRootId(rootId),HttpStatus.OK);
|
|
// }
|
|
// }
|
|
|
|
|
|
- @ApiOperation(value="新增机构",notes="新增")
|
|
|
|
|
|
+ @ApiOperation(value = "新增机构", notes = "新增")
|
|
@PostMapping
|
|
@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");
|
|
AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
- if(accessUser != null){
|
|
|
|
|
|
+ if (accessUser != null) {
|
|
org.setParentId(accessUser.getOrgId());
|
|
org.setParentId(accessUser.getOrgId());
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
}
|
|
}
|
|
try {
|
|
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
|
|
@PutMapping
|
|
- public ResponseEntity updateSchool(@RequestBody Org org,HttpServletRequest request){
|
|
|
|
|
|
+ public ResponseEntity updateSchool(@RequestBody Org org, HttpServletRequest request) {
|
|
AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
- if(accessUser != null){
|
|
|
|
|
|
+ if (accessUser != null) {
|
|
org.setParentId(accessUser.getOrgId());
|
|
org.setParentId(accessUser.getOrgId());
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
org.setRootId(accessUser.getRootOrgId());
|
|
}
|
|
}
|
|
try {
|
|
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}")
|
|
@DeleteMapping("/{id}")
|
|
- public ResponseEntity deleteSchool(@PathVariable Long id){
|
|
|
|
|
|
+ public ResponseEntity deleteSchool(@PathVariable Long id) {
|
|
orgRepo.delete(id);
|
|
orgRepo.delete(id);
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
}
|
|
}
|
|
-
|
|
|
|
- @ApiOperation(value="按父ID导入子机构",notes="导入子机构")
|
|
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
|
|
@PostMapping("/{id}/import")
|
|
@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}")
|
|
@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());
|
|
.collect(Collectors.toList());
|
|
- for(Long orgId:orgIds){
|
|
|
|
- orgService.enableSchool(orgId,true);
|
|
|
|
|
|
+ for (Long orgId : orgIds) {
|
|
|
|
+ orgService.enableSchool(orgId, true);
|
|
}
|
|
}
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="禁用机构",notes="禁用")
|
|
|
|
|
|
+ @ApiOperation(value = "禁用机构", notes = "禁用")
|
|
@PutMapping("/disable/{ids}")
|
|
@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());
|
|
.collect(Collectors.toList());
|
|
- for(Long orgId:orgIds){
|
|
|
|
- orgService.enableSchool(orgId,false);
|
|
|
|
|
|
+ for (Long orgId : orgIds) {
|
|
|
|
+ orgService.enableSchool(orgId, false);
|
|
}
|
|
}
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
}
|
|
}
|
|
-
|
|
|
|
- @ApiOperation(value="按code查询机构(学习中心)",notes="code查询")
|
|
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "按code查询机构(学习中心)", notes = "code查询")
|
|
@GetMapping()
|
|
@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);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|