zouxuan před 5 roky
rodič
revize
bf0dfe1c49

+ 11 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/TeacherController.java

@@ -30,7 +30,7 @@ public class TeacherController extends BaseController {
 	@ApiOperation(value = "教师列表")
 	@GetMapping(value = "list")
     @PreAuthorize("@pcs.hasPermissions('teacher/list')")
-	public HttpResponseResult<PageInfo<Teacher>> configList(QueryInfo queryInfo) {
+	public HttpResponseResult<PageInfo<Teacher>> list(QueryInfo queryInfo) {
 		return succeed(teacherService.queryPage(queryInfo));
 	}
 
@@ -38,7 +38,7 @@ public class TeacherController extends BaseController {
 	@PostMapping(value = "update")
     @PreAuthorize("@pcs.hasPermissions('teacher/update')")
 	public HttpResponseResult update(Teacher teacher) {
-		teacherService.update(teacher);
+		teacherService.updateTeacher(teacher);
 		return succeed();
 	}
 
@@ -52,7 +52,15 @@ public class TeacherController extends BaseController {
 	@ApiOperation(value = "查询教师")
 	@GetMapping(value = "get")
     @PreAuthorize("@pcs.hasPermissions('teacher/get')")
-	public HttpResponseResult<Teacher> getConfig(Integer id) {
+	public HttpResponseResult<Teacher> get(Integer id) {
 		return succeed(teacherService.get(id));
 	}
+
+	@ApiOperation(value = "删除教师")
+	@GetMapping(value = "del")
+    @PreAuthorize("@pcs.hasPermissions('teacher/del')")
+	public HttpResponseResult<Teacher> del(Integer id) {
+		teacherService.delete(id);
+		return succeed();
+	}
 }

+ 6 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/EmployeeDao.java

@@ -9,6 +9,12 @@ import java.util.List;
 public interface EmployeeDao extends BaseDAO<Integer, Employee> {
 
     /**
+     * 删除用户角色
+     * @param userId
+     */
+    void delEmployeeRole(Integer userId);
+
+    /**
      * 批量新增用户角色
      * @param id
      * @param roles

+ 6 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/TeacherService.java

@@ -11,4 +11,10 @@ public interface TeacherService extends BaseService<Integer, Teacher> {
      * @param teacher
      */
     int add(Teacher teacher);
+
+    /**
+     * 修改教师基本信息
+     * @param teacher
+     */
+    void updateTeacher(Teacher teacher);
 }

+ 15 - 7
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/EmployeeServiceImpl.java

@@ -18,8 +18,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-
 @Service
 public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> implements EmployeeService {
 	
@@ -74,13 +72,23 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> impl
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void updateEmployee(Employee employee) {
-		Date date = new Date();
 		SysUser sysUser = employee.getSysUser();
-		sysUser.setId(employee.getUserId());
-		employee.setUpdateTime(date);
-		sysUser.setUpdateTime(date);
-		sysUserDao.update(sysUser);
+		if(null == employeeDao.get(sysUser.getId())){
+			throw new BizException("员工信息不存在");
+		}
+		employee.setUserId(sysUser.getId());
+		if(StringUtils.isNotEmpty(sysUser.getPhone())){
+			SysUser queryByPhone = sysUserDao.queryByPhone(sysUser.getPhone());
+			if(queryByPhone != null && !sysUser.getId().equals(queryByPhone.getId())){
+				throw new BizException("手机号已存在");
+			}
+		}
 		employeeDao.update(employee);
+		//删除当前用户角色
+		employeeDao.delEmployeeRole(sysUser.getId());
+		//新增用户角色
 		employeeDao.batchAddEmployeeRole(sysUser.getId(),sysUser.getRoles());
+		sysUserDao.update(sysUser);
+		imFeignService.update(new ImUserModel(sysUser.getId().toString(),sysUser.getRealName(),sysUser.getAvatar()));
 	}
 }

+ 24 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/TeacherServiceImpl.java

@@ -14,8 +14,10 @@ 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.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
 
@@ -27,8 +29,6 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher> implem
 	@Autowired
 	private SysUserDao sysUserDao;
 	@Autowired
-	private SysUserFeignService sysUserFeignService;
-	@Autowired
 	private ImFeignService imFeignService;
 
 	@Override
@@ -37,9 +37,10 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher> implem
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public int add(Teacher teacher) {
 		SysUser sysUser = teacher.getSysUser();
-		SysUser user = sysUserFeignService.queryUserByMobile(sysUser.getPhone());
+		SysUser user = sysUserDao.queryByPhone(sysUser.getPhone());
 		Date date = new Date();
 		if(user != null && user.getId() != null){
 			if(user.getUserType().contains("TEACHER")){
@@ -72,4 +73,24 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher> implem
 		}
 		return userId;
 	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void updateTeacher(Teacher teacher) {
+		SysUser sysUser = teacher.getSysUser();
+		if(null == teacherDao.get(sysUser.getId())){
+			throw new BizException("教师信息不存在");
+		}
+		if(StringUtils.isNotEmpty(sysUser.getPhone())){
+			SysUser queryUserByMobile = sysUserDao.queryByPhone(sysUser.getPhone());
+			if(queryUserByMobile != null && !sysUser.getId().equals(queryUserByMobile.getId())){
+				throw new BizException("手机号已存在");
+			}
+		}
+		Date date = new Date();
+		teacher.setUpdateTime(date);
+		teacherDao.update(teacher);
+		sysUserDao.update(sysUser);
+		imFeignService.update(new ImUserModel(sysUser.getId().toString(),sysUser.getRealName(),sysUser.getAvatar()));
+	}
 }

+ 6 - 2
edu-user/edu-user-server/src/main/resources/config/mybatis/EmployeeMapper.xml

@@ -48,8 +48,12 @@
 			<result column="is_super_admin_" property="isSuperAdmin"/>
 		</association>
 	</resultMap>
-	
-	<!-- 根据主键查询一条记录 -->
+
+	<delete id="delEmployeeRole">
+        DELETE FROM sys_user_role WHERE user_id_ = #{userId}
+    </delete>
+
+    <!-- 根据主键查询一条记录 -->
 	<select id="get" resultMap="Employee" >
 		SELECT * FROM employee WHERE user_id_ = #{userId} 
 	</select>