|
@@ -1,22 +1,75 @@
|
|
|
package com.keao.edu.user.service.impl;
|
|
|
|
|
|
|
|
|
+import com.keao.edu.auth.api.client.SysUserFeignService;
|
|
|
+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.client.ImFeignService;
|
|
|
+import com.keao.edu.im.api.entity.ImResult;
|
|
|
+import com.keao.edu.im.api.entity.ImUserModel;
|
|
|
+import com.keao.edu.user.dao.SysUserDao;
|
|
|
import com.keao.edu.user.dao.TeacherDao;
|
|
|
import com.keao.edu.user.entity.Teacher;
|
|
|
+import com.keao.edu.user.enums.YesOrNoEnum;
|
|
|
import com.keao.edu.user.service.TeacherService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
@Service
|
|
|
public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher> implements TeacherService {
|
|
|
|
|
|
@Autowired
|
|
|
private TeacherDao teacherDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserDao sysUserDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+ @Autowired
|
|
|
+ private ImFeignService imFeignService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, Teacher> getDAO() {
|
|
|
return teacherDao;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int add(Teacher teacher) {
|
|
|
+ SysUser sysUser = teacher.getSysUser();
|
|
|
+ SysUser user = sysUserFeignService.queryUserByMobile(sysUser.getPhone());
|
|
|
+ Date date = new Date();
|
|
|
+ if(user != null && user.getId() != null){
|
|
|
+ if(user.getUserType().contains("TEACHER")){
|
|
|
+ throw new BizException("此手机号已被占用");
|
|
|
+ }
|
|
|
+ Integer id = user.getId();
|
|
|
+ Teacher teacher1 = teacherDao.get(id);
|
|
|
+ if(teacher1 == null || teacher1.getUserId() == null){
|
|
|
+ teacher.setUserId(id);
|
|
|
+ teacher.setDelFlag(YesOrNoEnum.NO);
|
|
|
+ teacherDao.insert(teacher);
|
|
|
+ sysUser.setUserType(user.getUserType() + ",TEACHER");
|
|
|
+ sysUser.setUpdateTime(date);
|
|
|
+ sysUserDao.update(sysUser);
|
|
|
+ }else {
|
|
|
+ throw new BizException("用户已存在");
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+ sysUser.setUserType("TEACHER");
|
|
|
+ sysUser.setUsername(sysUser.getRealName());
|
|
|
+ sysUserDao.insert(sysUser);
|
|
|
+ Integer userId = sysUser.getId();
|
|
|
+ teacher.setUserId(userId);
|
|
|
+ teacherDao.insert(teacher);
|
|
|
+ ImResult imResult = imFeignService.register(new ImUserModel(userId.toString(), sysUser.getUsername(), sysUser.getAvatar()));
|
|
|
+ if(imResult != null){
|
|
|
+ sysUser.setImToken(imResult.getToken());
|
|
|
+ sysUserDao.update(sysUser);
|
|
|
+ }
|
|
|
+ return userId;
|
|
|
+ }
|
|
|
}
|