wangwei 6 gadi atpakaļ
vecāks
revīzija
93eedd21a0

+ 185 - 174
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/StudentCloudServiceProvider.java

@@ -1,174 +1,185 @@
-package cn.com.qmth.examcloud.core.basic.api.provider;
-
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
-import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
-import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.SaveStudentReq;
-import cn.com.qmth.examcloud.core.basic.api.request.UnbindStudentCodeReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentResp;
-import cn.com.qmth.examcloud.core.basic.api.response.UnbindStudentCodeResp;
-import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
-import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
-import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
-import cn.com.qmth.examcloud.core.basic.service.StudentService;
-import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
-import io.swagger.annotations.ApiOperation;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年8月14日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Transactional
-@RestController
-@RequestMapping("${$rmp.cloud.basic}" + "student")
-public class StudentCloudServiceProvider extends ControllerSupport implements StudentCloudService {
-
-	private static final long serialVersionUID = -571041158847398070L;
-
-	@Autowired
-	OrgRepo orgRepo;
-
-	@Autowired
-	UserRepo userRepo;
-
-	@Autowired
-	StudentService studentService;
-
-	@Autowired
-	StudentRepo studentRepo;
-
-	@ApiOperation(value = "保存学生")
-	@PostMapping("saveStudent")
-	@Override
-	public SaveStudentResp saveStudent(@RequestBody SaveStudentReq req) {
-
-		trim(req);
-
-		StudentInfo studentInfo = new StudentInfo();
-		studentInfo.setName(req.getName());
-		studentInfo.setIdentityNumber(req.getIdentityNumber());
-		studentInfo.setStudentCode(req.getStudentCode());
-		studentInfo.setRootOrgId(req.getRootOrgId());
-
-		studentInfo.setOrgId(req.getOrgId());
-		studentInfo.setOrgCode(req.getOrgCode());
-		studentInfo.setOrgName(req.getOrgName());
-
-		studentInfo.setPhoneNumber(req.getPhoneNumber());
-		studentInfo.setPhotoPath(req.getPhotoPath());
-		studentInfo.setRemark(req.getRemark());
-
-		StudentEntity student = studentService.saveStudent(studentInfo);
-
-		SaveStudentResp resp = new SaveStudentResp();
-		resp.setStudentId(student.getId());
-		resp.setRootOrgId(student.getRootOrgId());
-
-		if (null != student.getOrgId()) {
-			OrgEntity org = orgRepo.findOne(student.getOrgId());
-			resp.setOrgId(org.getId());
-			resp.setOrgName(org.getName());
-		}
-
-		return resp;
-	}
-
-	@ApiOperation(value = "查询学生")
-	@PostMapping("getStudent")
-	@Override
-	public GetStudentResp getStudent(@RequestBody GetStudentReq req) {
-		Long studentId = req.getStudentId();
-		Long rootOrgId = req.getRootOrgId();
-		String identityNumber = req.getIdentityNumber();
-
-		StudentEntity student = null;
-		if (null != studentId) {
-			student = studentRepo.findOne(studentId);
-		} else {
-
-			if (null == rootOrgId) {
-				throw new StatusException("B-150000", "rootOrgId is null");
-			}
-			if (StringUtils.isBlank(identityNumber)) {
-				throw new StatusException("B-150004", "identityNumber is null");
-			}
-
-			OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
-			if (null == rootOrg) {
-				throw new StatusException("B-150001", "机构不存在");
-			}
-			if (null != rootOrg.getParentId()) {
-				throw new StatusException("B-150002", "机构错误");
-			}
-
-			student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
-		}
-
-		if (null == student) {
-			throw new StatusException("B-150005", "学生不存在");
-		}
-
-		StudentBean studentBean = new StudentBean();
-		studentBean.setId(student.getId());
-		studentBean.setName(student.getName());
-		studentBean.setIdentityNumber(student.getIdentityNumber());
-		studentBean.setStudentCode(student.getStudentCode());
-		studentBean.setRootOrgId(student.getRootOrgId());
-		if (null != student.getOrgId()) {
-			OrgEntity org = orgRepo.findOne(student.getOrgId());
-			studentBean.setOrgId(org.getId());
-			studentBean.setOrgCode(org.getCode());
-			studentBean.setOrgName(org.getName());
-		}
-		studentBean.setPhoneNumber(student.getPhoneNumber());
-		studentBean.setPhotoPath(student.getPhotoPath());
-		studentBean.setRemark(student.getRemark());
-		studentBean.setSecurityPhone(student.getSecurityPhone());
-
-		GetStudentResp resp = new GetStudentResp();
-		resp.setStudentInfo(studentBean);
-		return resp;
-	}
-
-	@ApiOperation(value = "解绑学号")
-	@PostMapping("unbindStudentCode")
-	@Override
-	public UnbindStudentCodeResp unbindStudentCode(@RequestBody UnbindStudentCodeReq req) {
-		Long rootOrgId = req.getRootOrgId();
-		String studentCode = req.getStudentCode();
-		String identityNumber = req.getIdentityNumber();
-
-		if (null == rootOrgId) {
-			throw new StatusException("B-160001", "rootOrgId is null");
-		}
-		if (StringUtils.isBlank(studentCode)) {
-			throw new StatusException("B-160002", "studentCode is blank");
-		}
-
-		List<Long> studentIdList = studentService.unbindStudentCode(rootOrgId, studentCode, identityNumber);
-
-		UnbindStudentCodeResp resp = new UnbindStudentCodeResp();
-		resp.setStudentIdList(studentIdList);
-
-		return resp;
-	}
-
-}
+package cn.com.qmth.examcloud.core.basic.api.provider;
+
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
+import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
+import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.request.SaveStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.request.UnbindStudentCodeReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
+import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentResp;
+import cn.com.qmth.examcloud.core.basic.api.response.UnbindStudentCodeResp;
+import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
+import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
+import cn.com.qmth.examcloud.core.basic.service.StudentService;
+import cn.com.qmth.examcloud.core.basic.service.bean.StudentInfo;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月14日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Transactional
+@RestController
+@RequestMapping("${$rmp.cloud.basic}" + "student")
+public class StudentCloudServiceProvider extends ControllerSupport implements StudentCloudService {
+
+	private static final long serialVersionUID = -571041158847398070L;
+
+	@Autowired
+	OrgRepo orgRepo;
+
+	@Autowired
+	UserRepo userRepo;
+
+	@Autowired
+	StudentService studentService;
+
+	@Autowired
+	StudentRepo studentRepo;
+
+	@ApiOperation(value = "保存学生")
+	@PostMapping("saveStudent")
+	@Override
+	public SaveStudentResp saveStudent(@RequestBody SaveStudentReq req) {
+
+		trim(req);
+
+		StudentInfo studentInfo = new StudentInfo();
+		studentInfo.setName(req.getName());
+		studentInfo.setIdentityNumber(req.getIdentityNumber());
+		studentInfo.setStudentCode(req.getStudentCode());
+		studentInfo.setRootOrgId(req.getRootOrgId());
+
+		studentInfo.setOrgId(req.getOrgId());
+		studentInfo.setOrgCode(req.getOrgCode());
+		studentInfo.setOrgName(req.getOrgName());
+
+		studentInfo.setPhoneNumber(req.getPhoneNumber());
+		studentInfo.setPhotoPath(req.getPhotoPath());
+		studentInfo.setRemark(req.getRemark());
+
+		StudentEntity student = studentService.saveStudent(studentInfo);
+
+		SaveStudentResp resp = new SaveStudentResp();
+		resp.setStudentId(student.getId());
+		resp.setRootOrgId(student.getRootOrgId());
+
+		if (null != student.getOrgId()) {
+			OrgEntity org = orgRepo.findOne(student.getOrgId());
+			resp.setOrgId(org.getId());
+			resp.setOrgName(org.getName());
+		}
+
+		return resp;
+	}
+
+	@ApiOperation(value = "查询学生")
+	@PostMapping("getStudent")
+	@Override
+	public GetStudentResp getStudent(@RequestBody GetStudentReq req) {
+		Long studentId = req.getStudentId();
+		Long rootOrgId = req.getRootOrgId();
+		String identityNumber = req.getIdentityNumber();
+
+		StudentEntity student = null;
+		if (null != studentId) {
+			student = studentRepo.findOne(studentId);
+		} else {
+
+			if (null == rootOrgId) {
+				throw new StatusException("B-150000", "rootOrgId is null");
+			}
+			if (StringUtils.isBlank(identityNumber)) {
+				throw new StatusException("B-150004", "identityNumber is null");
+			}
+
+			OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
+			if (null == rootOrg) {
+				throw new StatusException("B-150001", "机构不存在");
+			}
+			if (null != rootOrg.getParentId()) {
+				throw new StatusException("B-150002", "机构错误");
+			}
+
+			student = studentRepo.findByIdentityNumberAndRootOrgId(identityNumber, rootOrgId);
+		}
+
+		if (null == student) {
+			throw new StatusException("B-150005", "学生不存在");
+		}
+
+		StudentBean studentBean = new StudentBean();
+		studentBean.setId(student.getId());
+		studentBean.setName(student.getName());
+		studentBean.setIdentityNumber(student.getIdentityNumber());
+		studentBean.setStudentCode(student.getStudentCode());
+		studentBean.setRootOrgId(student.getRootOrgId());
+		if (null != student.getOrgId()) {
+			OrgEntity org = orgRepo.findOne(student.getOrgId());
+			studentBean.setOrgId(org.getId());
+			studentBean.setOrgCode(org.getCode());
+			studentBean.setOrgName(org.getName());
+		}
+		studentBean.setPhoneNumber(student.getPhoneNumber());
+		if (null != student.getPhotoPath()) {
+			String urlPrefix = PropertiesUtil.getString(PropKeys.STUDENT_PHOTO_URL_PREFIX);
+			if (StringUtils.isBlank(urlPrefix)) {
+				throw new StatusException("B-560111",
+						"property[$studentPhoto.url.prefix] is not configured");
+			}
+			studentBean.setPhotoPath(urlPrefix + student.getPhotoPath());
+		}
+
+		studentBean.setRemark(student.getRemark());
+		studentBean.setSecurityPhone(student.getSecurityPhone());
+
+		GetStudentResp resp = new GetStudentResp();
+		resp.setStudentInfo(studentBean);
+		return resp;
+	}
+
+	@ApiOperation(value = "解绑学号")
+	@PostMapping("unbindStudentCode")
+	@Override
+	public UnbindStudentCodeResp unbindStudentCode(@RequestBody UnbindStudentCodeReq req) {
+		Long rootOrgId = req.getRootOrgId();
+		String studentCode = req.getStudentCode();
+		String identityNumber = req.getIdentityNumber();
+
+		if (null == rootOrgId) {
+			throw new StatusException("B-160001", "rootOrgId is null");
+		}
+		if (StringUtils.isBlank(studentCode)) {
+			throw new StatusException("B-160002", "studentCode is blank");
+		}
+
+		List<Long> studentIdList = studentService.unbindStudentCode(rootOrgId, studentCode,
+				identityNumber);
+
+		UnbindStudentCodeResp resp = new UnbindStudentCodeResp();
+		resp.setStudentIdList(studentIdList);
+
+		return resp;
+	}
+
+}