Ver código fonte

Merge remote-tracking branch 'origin/master'

Joburgess 5 anos atrás
pai
commit
7d10ee0602

+ 8 - 7
edu-user/edu-user-server/src/main/java/com/keao/edu/user/controller/TeacherController.java

@@ -2,6 +2,8 @@ package com.keao.edu.user.controller;
 
 
 import com.keao.edu.common.controller.BaseController;
+import com.keao.edu.common.entity.HttpResponseResult;
+import com.keao.edu.common.page.PageInfo;
 import com.keao.edu.common.page.QueryInfo;
 import com.keao.edu.user.entity.Teacher;
 import com.keao.edu.user.service.TeacherService;
@@ -28,14 +30,14 @@ public class TeacherController extends BaseController {
 	@ApiOperation(value = "教师列表")
 	@GetMapping(value = "list")
     @PreAuthorize("@pcs.hasPermissions('teacher/list')")
-	public Object configList(QueryInfo queryInfo) {
+	public HttpResponseResult<PageInfo<Teacher>> configList(QueryInfo queryInfo) {
 		return succeed(teacherService.queryPage(queryInfo));
 	}
 
 	@ApiOperation(value = "修改教师")
 	@PostMapping(value = "update")
     @PreAuthorize("@pcs.hasPermissions('teacher/update')")
-	public Object update(Teacher teacher) {
+	public HttpResponseResult update(Teacher teacher) {
 		teacherService.update(teacher);
 		return succeed();
 	}
@@ -43,15 +45,14 @@ public class TeacherController extends BaseController {
 	@ApiOperation(value = "新增教师")
 	@PostMapping(value = "add")
     @PreAuthorize("@pcs.hasPermissions('teacher/add')")
-	public Object add(Teacher teacher) {
-		teacherService.insert(teacher);
-		return succeed();
+	public HttpResponseResult add(Teacher teacher) {
+		return succeed(teacherService.add(teacher));
 	}
 
-	@ApiOperation(value = "查询参数")
+	@ApiOperation(value = "查询教师")
 	@GetMapping(value = "get")
     @PreAuthorize("@pcs.hasPermissions('teacher/get')")
-	public Object getConfig(Integer id) {
+	public HttpResponseResult<Teacher> getConfig(Integer id) {
 		return succeed(teacherService.get(id));
 	}
 }

+ 4 - 3
edu-user/edu-user-server/src/main/java/com/keao/edu/user/entity/Teacher.java

@@ -1,6 +1,7 @@
 package com.keao.edu.user.entity;
 
 import com.keao.edu.auth.api.entity.SysUser;
+import com.keao.edu.user.enums.YesOrNoEnum;
 import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
@@ -25,7 +26,7 @@ public class Teacher {
 	private java.math.BigDecimal salary;
 
 	@ApiModelProperty(value = "是否删除",required = false)
-	private Integer delFlag;
+	private YesOrNoEnum delFlag;
 	
 	/**  */
 	private java.util.Date createTime;
@@ -36,11 +37,11 @@ public class Teacher {
 	@ApiModelProperty(value = "用户编号",required = false)
 	private SysUser sysUser;
 
-	public Integer getDelFlag() {
+	public YesOrNoEnum getDelFlag() {
 		return delFlag;
 	}
 
-	public void setDelFlag(Integer delFlag) {
+	public void setDelFlag(YesOrNoEnum delFlag) {
 		this.delFlag = delFlag;
 	}
 

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

@@ -6,4 +6,9 @@ import com.keao.edu.user.entity.Teacher;
 
 public interface TeacherService extends BaseService<Integer, Teacher> {
 
+    /**
+     * 新增教师
+     * @param teacher
+     */
+    int add(Teacher teacher);
 }

+ 53 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/TeacherServiceImpl.java

@@ -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;
+	}
 }

+ 17 - 3
edu-user/edu-user-server/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -87,14 +87,28 @@
 	<update id="delete">
 		UPDATE teacher SET del_flag_ = 1,update_time_ = NOW() WHERE id_ = #{id}
 	</update>
-	
+	<sql id="teacherQueryPage">
+		<where>
+			t.del_flag_ = 0
+			<if test="search != null and search != ''">
+				AND (t.user_id_ = 1
+				OR su.real_name_ LIKE CONCAT('%','','%')
+				OR su.phone_ LIKE CONCAT('%','','%'))
+			</if>
+		</where>
+	</sql>
 	<!-- 分页查询 -->
 	<select id="queryPage" resultMap="Teacher" parameterType="map">
-		SELECT * FROM teacher <include refid="global.limit"/>
+		SELECT * FROM teacher t
+		LEFT JOIN sys_user su ON t.user_id_ = su.id_
+		<include refid="teacherQueryPage"/>
+		<include refid="global.limit"/>
 	</select>
 	
 	<!-- 查询当前表的总记录数 -->
 	<select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM teacher
+		SELECT COUNT(DISTINCT t.user_id_) FROM teacher t
+		LEFT JOIN sys_user su ON t.user_id_ = su.id_
+		<include refid="teacherQueryPage"/>
 	</select>
 </mapper>