|
@@ -0,0 +1,74 @@
|
|
|
+package com.keao.edu.user.service.impl;
|
|
|
+
|
|
|
+import com.keao.edu.auth.api.entity.SysUser;
|
|
|
+import com.keao.edu.common.dal.BaseDAO;
|
|
|
+import com.keao.edu.common.exception.BizException;
|
|
|
+import com.keao.edu.common.service.impl.BaseServiceImpl;
|
|
|
+import com.keao.edu.im.api.entity.ImResult;
|
|
|
+import com.keao.edu.im.api.entity.ImUserModel;
|
|
|
+import com.keao.edu.user.dao.ExamSongDao;
|
|
|
+import com.keao.edu.user.dao.StudentDao;
|
|
|
+import com.keao.edu.user.dao.SysUserDao;
|
|
|
+import com.keao.edu.user.entity.ExamSong;
|
|
|
+import com.keao.edu.user.entity.Student;
|
|
|
+import com.keao.edu.user.service.StudentService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author Joburgess
|
|
|
+ * @Date 2020.06.18
|
|
|
+ */
|
|
|
+public class StudentServiceImpl extends BaseServiceImpl<Integer, Student> implements StudentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserDao sysUserDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, Student> getDAO() {
|
|
|
+ return studentDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addStudent(Student student) {
|
|
|
+ SysUser sysUser = student.getSysUser();
|
|
|
+ if (sysUser == null || StringUtils.isEmpty(sysUser.getPhone())) {
|
|
|
+ throw new BizException("参数校验失败");
|
|
|
+ }
|
|
|
+ SysUser sysUser1 = sysUserDao.queryByPhone(sysUser.getPhone());
|
|
|
+ if (sysUser1 != null) {
|
|
|
+ if (sysUser1.getUserType().contains("STUDENT")) {
|
|
|
+ throw new BizException("手机号已被占用");
|
|
|
+ } else {
|
|
|
+ sysUser.setId(sysUser1.getId());
|
|
|
+ sysUser.setUserType(sysUser1.getUserType() + ",STUDENT");
|
|
|
+ sysUserDao.update(sysUser);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sysUser.setUserType("STUDENT");
|
|
|
+ sysUserDao.insert(sysUser);
|
|
|
+ studentDao.insert(student);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateStudent(Student student) {
|
|
|
+ Integer userId = student.getUserId();
|
|
|
+ SysUser sysUser = student.getSysUser();
|
|
|
+ if (userId == null || StringUtils.isEmpty(sysUser.getPhone())) {
|
|
|
+ throw new BizException("参数校验失败");
|
|
|
+ }
|
|
|
+ SysUser sysUser1 = sysUserDao.queryByPhone(sysUser.getPhone());
|
|
|
+ if (sysUser1 != null && !userId.equals(sysUser1.getId())) {
|
|
|
+ throw new BizException("手机号已被占用");
|
|
|
+ }
|
|
|
+ sysUserDao.update(sysUser);
|
|
|
+ studentDao.update(student);
|
|
|
+ }
|
|
|
+}
|