wangwei 7 سال پیش
والد
کامیت
2ab39a0cdc

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

@@ -23,12 +23,9 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
@@ -70,59 +67,31 @@ public class OrgController extends ControllerSupport {
 	@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);
-			}
-		}
-		return new ResponseEntity(null, HttpStatus.OK);
-	}
-
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param id
+	 * @return
+	 */
 	@ApiOperation(value = "按ID查询机构", notes = "ID查询")
 	@GetMapping("/{id}")
-	public ResponseEntity<Org> getOrgById(@PathVariable Long id) {
-		return new ResponseEntity(orgService.findOne(id), HttpStatus.OK);
+	public Org getOrg(@PathVariable Long id) {
+		Org org = orgService.findOne(id);
+		return org;
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param parentId
+	 * @return
+	 */
 	@ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
 	@GetMapping("/sub/{parentId}")
-	public List<Org> getOrgByParentId(@PathVariable Long parentId, HttpServletRequest request) {
-		List<Org> orgList = orgRepo.findByParentId(parentId);
-		return orgList;
-	}
-
-	@ApiOperation(value = "查询下属机构不带分页", notes = "不分页")
-	@GetMapping("/sub/both/{parentId}")
-	public List<Org> getBothOrg(@PathVariable Long parentId, HttpServletRequest request) {
-		List<Org> orgList = orgRepo.findBothByParentId(parentId);
+	public List<Org> getSubOrgList(@PathVariable Long parentId) {
+		List<Org> orgList = orgRepo.findByParentIdAndEnable(parentId, true);
 		return orgList;
 	}
 
@@ -251,11 +220,7 @@ public class OrgController extends ControllerSupport {
 		}
 
 		org.setParentId(null);
-		// 临时
-		org.setRootId(-1L);
 		Org saved = orgService.save(org);
-		saved.setRootId(saved.getId());
-		saved = orgService.save(org);
 		return saved;
 	}
 
@@ -276,8 +241,8 @@ public class OrgController extends ControllerSupport {
 
 		org.setParentId(null);
 		org.setRootId(org.getId());
-		Org updated = orgService.update(org.getId(), org);
-		return updated;
+		Org saved = orgService.save(org);
+		return saved;
 	}
 
 	/**
@@ -312,8 +277,8 @@ public class OrgController extends ControllerSupport {
 
 		org.setParentId(accessUser.getRootOrgId());
 		org.setRootId(accessUser.getRootOrgId());
-		Org updated = orgService.update(org.getId(), org);
-		return updated;
+		Org saved = orgService.save(org);
+		return saved;
 	}
 
 	@ApiOperation(value = "按ID删除机构", notes = "删除")
@@ -360,48 +325,25 @@ public class OrgController extends ControllerSupport {
 		}
 	}
 
-	@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查询")
+	@ApiOperation(value = "查询logo")
 	@GetMapping("/logo")
-	public void logo(@RequestParam("domain") String domain, HttpServletResponse response)
+	public void getLogo(@RequestParam("domain") String domain, HttpServletResponse response)
 			throws IOException {
-		Org org = orgRepo.findFirstByParentIdAndCode(0L, domain);
+		Org org = orgRepo.findRootOrg(domain);
 		String logo = org.getLogo();
 		IOUtils.copy(new FileInputStream(logo), response.getOutputStream());
 		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("/getAllParentOrg")
-	public List<Org> getAllParentOrg() {
-		List<Org> list = orgRepo.findAllParentOrg();
-		return list;
-	}
-
-	@ApiOperation(value = "查询所有印刷机构", notes = "查询所有印刷机构")
-	// @GetMapping("/allPrint")
-	public List<Org> getAllPrintOrg() {
-		List<Org> orgList = orgRepo.findAllPrintByParentId(0L);
-		return orgList;
-	}
-
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param id
+	 * @param request
+	 * @param file
+	 * @throws IOException
+	 */
 	@ApiOperation(value = "导入logo", notes = "导入logo")
 	@PostMapping("/importLogo/{id}")
 	public void importLogo(@PathVariable Long id, HttpServletRequest request,
@@ -427,15 +369,6 @@ public class OrgController extends ControllerSupport {
 		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) {
-		User accessUser = getAccessUser();
-		orgName = "%" + orgName + "%";
-		List<Org> list = orgRepo.findByRootIdAndNameLike(accessUser.getRootOrgId(), orgName);
-		return list;
-	}
-
 	/**
 	 * 修改请通知作者
 	 *

+ 57 - 71
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/StudentController.java

@@ -36,21 +36,20 @@ import cn.com.qmth.examcloud.core.basic.service.impl.StudentServiceImpl;
 import javax.servlet.http.HttpServletRequest;
 
 /**
- * 学生服务API
- * Created by songyue on 17/1/14.
+ * 学生服务API Created by songyue on 17/1/14.
  */
 @RestController
 @RequestMapping("${$rmp.ctr.basic}/student")
-public class StudentController extends ControllerSupport{
+public class StudentController extends ControllerSupport {
 
-    @Autowired
-    StudentRepo studentRepo;
+	@Autowired
+	StudentRepo studentRepo;
 
-    @Autowired
-    StudentServiceImpl studentService;
+	@Autowired
+	StudentServiceImpl studentService;
 
-    @Autowired
-    UserRepo userRepo;
+	@Autowired
+	UserRepo userRepo;
 
 	@ApiOperation(value = "查询所有学生", notes = "分页")
 	@GetMapping("/{curPage}/{pageSize}")
@@ -68,70 +67,57 @@ public class StudentController extends ControllerSupport{
 		return studentList;
 	}
 
-    @ApiOperation(value="查询所有学生",notes="不分页")
-    @GetMapping
-    public ResponseEntity getAllStudent(HttpServletRequest request,
-                                        @ModelAttribute Student studentCriteria){
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        if(accessUser != null){
-            if(accessUser.getRootOrgId().longValue() == accessUser.getOrgId().longValue()){
-                studentCriteria.setRootOrgId(accessUser.getRootOrgId());
-            }else{
-                studentCriteria.setOrgId(accessUser.getOrgId());
-            }
-        }
-        return new ResponseEntity(studentService.getAllStudent(studentCriteria),HttpStatus.OK);
-    }
-
-    @ApiOperation(value="按ID查询学生",notes="ID查询")
-    @GetMapping("/{id}")
-    public ResponseEntity getStudentById(@PathVariable Long id){
-        return new ResponseEntity(studentRepo.findOne(id),HttpStatus.OK);
-    }
-
-    @ApiOperation(value="新增学生",notes="新增")
-    @PostMapping
-    public ResponseEntity addStudent(@RequestBody Student student){
-    	student.setCreateTime(new Date());
-        return new ResponseEntity(studentService.save(student),HttpStatus.CREATED);
-    }
-
-    @ApiOperation(value="更新学生",notes="更新")
-    @PutMapping
-    public ResponseEntity updateStudent(@RequestBody Student student){
-        return new ResponseEntity(studentService.update(student),HttpStatus.OK);
-    }
-
-    @ApiOperation(value="按ID删除学生",notes="删除")
-    @DeleteMapping("/{id}")
-    public ResponseEntity deleteStudent(@PathVariable Long id){
-        studentRepo.delete(id);
-        return new ResponseEntity(HttpStatus.OK);
-    }
-    
-    @ApiOperation(value="学生照片绑定",notes = "照片绑定")
-    @PostMapping("/photo")
-    public ResponseEntity photopBundled (@RequestParam Long orgId,@RequestParam File file){
-    	try {
-    		List<ErrorMsg> errorMsgs = studentService.photopBundled(orgId,file);
-    		return new ResponseEntity(errorMsgs,HttpStatus.OK);
+	@ApiOperation(value = "查询所有学生", notes = "不分页")
+	@GetMapping
+	public ResponseEntity getAllStudent(HttpServletRequest request,
+			@ModelAttribute Student studentCriteria) {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		if (accessUser != null) {
+			if (accessUser.getRootOrgId().longValue() == accessUser.getOrgId().longValue()) {
+				studentCriteria.setRootOrgId(accessUser.getRootOrgId());
+			} else {
+				studentCriteria.setOrgId(accessUser.getOrgId());
+			}
+		}
+		return new ResponseEntity(studentService.getAllStudent(studentCriteria), HttpStatus.OK);
+	}
+
+	@ApiOperation(value = "按ID查询学生", notes = "ID查询")
+	@GetMapping("/{id}")
+	public ResponseEntity getStudentById(@PathVariable Long id) {
+		return new ResponseEntity(studentRepo.findOne(id), HttpStatus.OK);
+	}
+
+	@ApiOperation(value = "新增学生", notes = "新增")
+	@PostMapping
+	public ResponseEntity addStudent(@RequestBody Student student) {
+		student.setCreateTime(new Date());
+		return new ResponseEntity(studentService.save(student), HttpStatus.CREATED);
+	}
+
+	@ApiOperation(value = "更新学生", notes = "更新")
+	@PutMapping
+	public ResponseEntity updateStudent(@RequestBody Student student) {
+		return new ResponseEntity(studentService.update(student), HttpStatus.OK);
+	}
+
+	@ApiOperation(value = "按ID删除学生", notes = "删除")
+	@DeleteMapping("/{id}")
+	public ResponseEntity deleteStudent(@PathVariable Long id) {
+		studentRepo.delete(id);
+		return new ResponseEntity(HttpStatus.OK);
+	}
+
+	@ApiOperation(value = "学生照片绑定", notes = "照片绑定")
+	@PostMapping("/photo")
+	public ResponseEntity photopBundled(@RequestParam Long orgId, @RequestParam File file) {
+		try {
+			List<ErrorMsg> errorMsgs = studentService.photopBundled(orgId, file);
+			return new ResponseEntity(errorMsgs, HttpStatus.OK);
 		} catch (Exception e) {
 			e.printStackTrace();
 			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
 		}
-    }
-    
-    @ApiOperation(value="学生登录",notes="学生登录")
-    @PostMapping("/login")
-    public ResponseEntity login(@RequestParam String orgCode,
-                                @RequestParam String loginName,
-                                @RequestParam String password,
-                                @RequestParam LoginType loginType){
-        try{
-            UserInfo userInfo = studentService.login(orgCode,loginName,password,loginType);
-            return new ResponseEntity(userInfo,HttpStatus.OK);
-        }catch (Exception e){
-            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
-        }
-    }
+	}
+
 }

+ 10 - 8
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/OrgCloudServiceProvider.java

@@ -40,17 +40,19 @@ public class OrgCloudServiceProvider extends ControllerSupport implements OrgClo
 	@PostMapping("saveOrg")
 	@Override
 	public SaveOrgResp saveOrg(SaveOrgReq orgReq) {
-		SaveOrgResp orgResp = new SaveOrgResp();
-		Org org = orgService.findFirstByParentIdAndCode(orgReq.getRootOrgId(), orgReq.getOrgCode());
+		Org org = orgRepo.findByRootIdAndCode(orgReq.getRootOrgId(), orgReq.getOrgCode());
 		if (org == null) {
 			org = new Org();
-			org.setName(orgReq.getOrgName());
-			org.setCode(orgReq.getOrgCode());
-			org.setParentId(orgReq.getRootOrgId());
-			org.setRootId(orgReq.getRootOrgId());
-			org.setEnable(true);
-			org = orgService.save(org);
 		}
+		org = new Org();
+		org.setName(orgReq.getOrgName());
+		org.setCode(orgReq.getOrgCode());
+		org.setParentId(orgReq.getRootOrgId());
+		org.setRootId(orgReq.getRootOrgId());
+		org.setEnable(true);
+		org = orgService.save(org);
+
+		SaveOrgResp orgResp = new SaveOrgResp();
 		orgResp.setId(org.getId());
 		orgResp.setName(org.getName());
 		return orgResp;

+ 2 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/OrgRepo.java

@@ -27,6 +27,8 @@ public interface OrgRepo
 
 	Org findByRootIdAndCode(Long rootId, String code);
 
+	List<Org> findByRootIdAndNameLike(Long rootId, String name);
+
 	List<Org> findByParentIdAndEnable(Long parentId, Boolean enable);
 
 	@Query(nativeQuery = true, value = "select * from ecs_core_org t where t.parent_id is null and t.code=:code ")

+ 1 - 1
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -82,7 +82,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 
 			try {
-				rootOrg = orgRepo.findFirstByParentIdAndCode(0L, loginInfo.getDomain());
+				rootOrg = orgRepo.findRootOrg(loginInfo.getDomain());
 				rootOrgId = String.valueOf(rootOrg.getId());
 			} catch (Exception e) {
 				throw new StatusException("B-001002", "机构不存在", e);

+ 1 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgService.java

@@ -260,6 +260,7 @@ public class OrgService {
 
 			// 新增
 			if (null == org.getId()) {
+				org.setRootId(-1L);
 				Org saved = orgRepo.save(org);
 				org.setId(saved.getId());
 				org.setRootId(saved.getId());

+ 17 - 59
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -19,7 +19,6 @@ import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
-import cn.com.qmth.examcloud.commons.web.security.AccessCtrlUtil;
 import cn.com.qmth.examcloud.core.basic.base.enums.UserType;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
@@ -29,11 +28,9 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
 import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
-import cn.com.qmth.examcloud.core.basic.dao.enums.LoginType;
 import cn.com.qmth.examcloud.core.basic.dao.enums.UserScope;
 import cn.com.qmth.examcloud.core.basic.service.StudentService;
 import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
-import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
 
 /**
  * 学生服务类 Created by songyue on 17/1/14.
@@ -55,6 +52,9 @@ public class StudentServiceImpl implements StudentService {
 
 	@Autowired
 	DataSendService dataSendService;
+	
+	@Autowired
+	OrgService orgService;
 
 	private static final String JPG = ".jpg";
 
@@ -185,52 +185,6 @@ public class StudentServiceImpl implements StudentService {
 		return student;
 	}
 
-	/**
-	 * 二级登录
-	 *
-	 * @param orgId
-	 * @param loginName
-	 * @param password
-	 * @return
-	 */
-	public UserInfo login(String orgId, String loginName, String password, LoginType loginType)
-			throws Exception {
-		Org org = orgRepo.findFirstByParentIdAndCode((long) 0, orgId);
-		if (org == null) {
-			throw new RuntimeException("学校不存在");
-		}
-		Student student = null;
-		if (LoginType.STUDENT_CODE.equals(loginType)) {
-			student = studentRepo.findByStudentCodeAndRootOrgId(loginName, org.getId());
-		} else if (LoginType.IDENTITY_NUMBER.equals(loginType)) {
-			student = studentRepo.findByIdentityNumberAndRootOrgId(loginName, org.getId());
-		}
-		if (student == null) {
-			throw new RuntimeException("该用户不存在");
-		}
-		return this.loginProcess(student, password);
-	}
-
-	private UserInfo loginProcess(Student student, String password) throws Exception {
-		if (student.getUser() == null) {
-			throw new RuntimeException("该用户不存在");
-		} else if (!student.getUser().getPassword().equals(password)) {
-			throw new RuntimeException("密码错误");
-		} else if (!student.getUser().getEnable()) {
-			throw new RuntimeException("该用户被禁用");
-		} else {
-			String token = AccessCtrlUtil.buildToken();
-			userService.initUserLogin(student.getUser());
-			userService.createAccessUser(token, student.getUser(), student.getId());
-			userService.createUserLogin(token, student.getUser());
-			UserInfo userInfo = userService.getUserInfo(student.getUser(), token);
-			userInfo.setStudentId(student.getId());
-			userInfo.setIdentityNumber(student.getIdentityNumber());
-			userInfo.setStudentCode(student.getStudentCode());
-			return userInfo;
-		}
-	}
-
 	public Student update(Student student) {
 		student.setUpdateTime(new Date());
 		UserEntity user = userRepo.findOne(student.getUser().getId());
@@ -261,16 +215,20 @@ public class StudentServiceImpl implements StudentService {
 				throw new StatusException("B-160002", "机构错误");
 			}
 		} else {
-			if (StringUtils.isBlank(orgName) || StringUtils.isBlank(orgCode)) {
-				Org org = orgRepo.findFirstByParentIdAndCode(rootOrgId, orgCode);
-				if (null == org) {
-					org = new Org();
-					org.setParentId(rootOrgId);
-					org.setCode(orgCode);
-					org.setName(orgName);
-					Org saved = orgRepo.save(org);
-					orgId = saved.getId();
-				}
+			if (StringUtils.isBlank(orgName)) {
+				throw new StatusException("B-160003", "orgName is blank");
+			}
+			if (StringUtils.isBlank(orgName)) {
+				throw new StatusException("B-160004", "orgName is blank");
+			}
+			Org org = orgRepo.findByRootIdAndCode(rootOrgId, orgCode);
+			if (null == org) {
+				org = new Org();
+				org.setParentId(rootOrgId);
+				org.setCode(orgCode);
+				org.setName(orgName);
+				Org saved = orgRepo.save(org);
+				orgId = saved.getId();
 			}
 		}