wangwei 7 years ago
parent
commit
d7be7c9e4a

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

@@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
 import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
@@ -51,60 +50,62 @@ import cn.com.qmth.examcloud.core.basic.service.impl.OrgService;
 import io.swagger.annotations.ApiOperation;
 
 /**
- * 机构服务API
- * Created by songyue on 17/1/14.
+ * 机构服务API Created by songyue on 17/1/14.
  */
 @RestController
 @RequestMapping("${$rmp.ctr.basic}/org")
-public class OrgController extends ControllerSupport{
+public class OrgController extends ControllerSupport {
 
-    @Autowired
-    OrgRepo orgRepo;
+	@Autowired
+	OrgRepo orgRepo;
+
+	@Autowired
+	OrgService orgService;
 
-    @Autowired
-    OrgService orgService;
-    
 	@Autowired
 	private JdbcTemplate jdbcTemplate;
 
-    @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);
-    }
-
-    @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("/alls/{type}")
-    public ResponseEntity getAllExam(@PathVariable String type,
-                                     HttpServletRequest request) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        if (accessUser != null) {
-        	if(type.equals("school")){
-        		return new ResponseEntity(orgRepo.findAllSchoolByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
-        	}else {
-        		return new ResponseEntity(orgRepo.findAllPrintByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
+	@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);
+	}
+
+	@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("/alls/{type}")
+	public ResponseEntity getAllExam(@PathVariable String type, HttpServletRequest request) {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		if (accessUser != null) {
+			if (type.equals("school")) {
+				return new ResponseEntity(
+						orgRepo.findAllSchoolByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
+			} else {
+				return new ResponseEntity(orgRepo.findAllPrintByParentId(accessUser.getRootOrgId()),
+						HttpStatus.OK);
 			}
-        }
-        return new ResponseEntity(null, HttpStatus.OK);
-    }
+		}
+		return new ResponseEntity(null, HttpStatus.OK);
+	}
 
-    @ApiOperation(value = "按ID查询机构", notes = "ID查询")
-    @GetMapping("/{id}")
-    public ResponseEntity<Org> getOrgById(@PathVariable Long id) {
-        return new ResponseEntity(orgService.findOne(id), HttpStatus.OK);
-    }
+	@ApiOperation(value = "按ID查询机构", notes = "ID查询")
+	@GetMapping("/{id}")
+	public ResponseEntity<Org> getOrgById(@PathVariable Long id) {
+		return new ResponseEntity(orgService.findOne(id), HttpStatus.OK);
+	}
 
 	@ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
 	@GetMapping("/sub/{parentId}")
@@ -126,7 +127,8 @@ public class OrgController extends ControllerSupport{
 			@PathVariable Integer curPage, @PathVariable Integer pageSize) {
 
 		orgCriteria.setParentId(parentId);
-		Pageable pageable = new PageRequest(curPage-1, pageSize, Sort.Direction.DESC, "updateTime");
+		Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
+				"updateTime");
 		Page<Org> ret = orgService.findAll(orgCriteria, pageable);
 		return ret;
 	}
@@ -159,42 +161,33 @@ public class OrgController extends ControllerSupport{
 		orgRepo.delete(id);
 	}
 
-    @ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
-    @PostMapping("/import")
-    public ResponseEntity<?> importLearnCenter(HttpServletRequest request,
-                                            @RequestParam CommonsMultipartFile file) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        Long orgId = null;
-        if(accessUser != null){
-            orgId = accessUser.getRootOrgId();
-        }else{
-            return new ResponseEntity<>(new ErrorMsg("用户token不存在或已失效"),HttpStatus.NOT_FOUND);
-        }
-        try {
-            List<ExcelError> excelErrors = orgService.importLearnCenter(orgId, file.getInputStream());
-            return new ResponseEntity<>(excelErrors, HttpStatus.OK);
-        } catch (IOException e) {
-        	log.error(e.getMessage(), e);
-            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-    }
-
-    @ApiOperation(value="下载导入模板",notes = "下载导入模板")
-    @GetMapping("/download")
-    public void importFileTemplate(HttpServletResponse response){
-        List<OrgDto> list= new ArrayList<OrgDto>();
-        ExportService.exportEXCEL("学习中心导入模板", OrgDto.class, list, response);
-    }
-
-    @ApiOperation(value = "启用机构", notes = "启用")
-    @PutMapping("/enable/{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);
-        }
-    }
+	@ApiOperation(value = "按父ID导入子机构", notes = "导入子机构")
+	@PostMapping("/import")
+	public List<ExcelError> importLearnCenter(HttpServletRequest request,
+			@RequestParam CommonsMultipartFile file) throws Exception {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+
+		List<ExcelError> excelErrors = orgService.importLearnCenter(accessUser.getRootOrgId(),
+				file.getInputStream());
+		return excelErrors;
+	}
+
+	@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
+	@GetMapping("/download")
+	public void importFileTemplate(HttpServletResponse response) {
+		List<OrgDto> list = new ArrayList<OrgDto>();
+		ExportService.exportEXCEL("学习中心导入模板", OrgDto.class, list, response);
+	}
+
+	@ApiOperation(value = "启用机构", notes = "启用")
+	@PutMapping("/enable/{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);
+		}
+	}
 
 	@ApiOperation(value = "禁用机构", notes = "禁用")
 	@PutMapping("/disable/{ids}")
@@ -223,18 +216,17 @@ public class OrgController extends ControllerSupport{
 		response.flushBuffer();
 	}
 
-    @ApiOperation(value = "查询机构不分页带查询", notes = "不分页带查询")
-    @GetMapping("/all")
-    public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria,
-                                     HttpServletRequest request) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        if (accessUser != null) {
-            return new ResponseEntity(orgRepo.findAllSchoolByParentId(accessUser.getRootOrgId()), HttpStatus.OK);
-        }
-        return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
-    }
-    
-    
+	@ApiOperation(value = "查询机构不分页带查询", notes = "不分页带查询")
+	@GetMapping("/all")
+	public ResponseEntity getAllExam(@ModelAttribute Org orgCriteria, HttpServletRequest request) {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		if (accessUser != null) {
+			return new ResponseEntity(orgRepo.findAllSchoolByParentId(accessUser.getRootOrgId()),
+					HttpStatus.OK);
+		}
+		return new ResponseEntity(orgService.findAll(orgCriteria), HttpStatus.OK);
+	}
+
 	@ApiOperation(value = "查询所有学校", notes = "查询所有学校")
 	@GetMapping("/getAllParentOrg")
 	public List<Org> getAllParentOrg() {
@@ -248,7 +240,7 @@ public class OrgController extends ControllerSupport{
 		List<Org> orgList = orgRepo.findAllPrintByParentId(0L);
 		return orgList;
 	}
-    
+
 	@ApiOperation(value = "导入logo", notes = "导入logo")
 	@PostMapping("/importLogo/{id}")
 	public void importLogo(@PathVariable Long id, HttpServletRequest request,
@@ -273,7 +265,7 @@ public class OrgController extends ControllerSupport{
 		FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
 		jdbcTemplate.update("update ecs_core_org t set  t.logo=? where t.id=?", filePath, id);
 	}
-	
+
 	@ApiOperation(value = "按机构名称模糊查询机构列表", notes = "")
 	@PostMapping("getOrgListByNameLike")
 	public List<Org> getOrgListByNameLike(@RequestParam String orgName) {
@@ -282,5 +274,5 @@ public class OrgController extends ControllerSupport{
 		List<Org> list = orgRepo.findByRootIdAndNameLike(accessUser.getRootOrgId(), orgName);
 		return list;
 	}
-	
+
 }