Browse Source

Merge branch 'master' of git.dayaedu.com:yonge/mec

chengpeng 5 years ago
parent
commit
f2f8f22198

+ 2 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TeacherServiceImpl.java

@@ -60,9 +60,8 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher>  imple
 		teacher.setUserType(SysUserType.TEACHER);
 		teacherDao.addSysUser(teacher);
 		teacherDao.insert(teacher);
-		Object register = imFeignService.register(new ImUserModel(teacher.getId().toString(), teacher.getUsername(), teacher.getAvatar()));
-		if(register instanceof ImResult){
-			ImResult imResult = (ImResult)register;
+		ImResult imResult = imFeignService.register(new ImUserModel(teacher.getId().toString(), teacher.getUsername(), teacher.getAvatar()));
+		if(imResult != null){
 			teacher.setImToken(imResult.getToken());
 			teacherDao.updateUser(teacher);
 		}

+ 43 - 40
mec-client-api/src/main/java/com/ym/mec/im/ImFeignService.java

@@ -1,53 +1,56 @@
 package com.ym.mec.im;
 
-import com.ym.mec.im.fallback.ImFeignServiceFallback;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+
 import com.ym.mec.common.config.FeignConfiguration;
 import com.ym.mec.common.entity.ImGroupModel;
+import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
+import com.ym.mec.im.fallback.ImFeignServiceFallback;
 
 @FeignClient(name = "im-server", configuration = FeignConfiguration.class, fallback = ImFeignServiceFallback.class)
 public interface ImFeignService {
 
-    /**
-     * 用户注册
-     * @param userModel
-     * @return
-     */
-    @PostMapping(value = "user/register")
-    Object register(@RequestBody ImUserModel userModel);
-
-    /**
-     * 创建群组
-     * @param groupModel
-     * @return
-     */
-    @PostMapping(value = "group/create")
-    Object groupCreate(@RequestBody ImGroupModel groupModel);
-
-    /**
-     * 加入群组
-     * @param groupModel
-     * @return
-     */
-    @PostMapping(value = "group/join")
-    Object groupJoin(@RequestBody ImGroupModel groupModel);
-
-    /**
-     * 退出群组
-     * @param groupModel
-     * @return
-     */
-    @PostMapping(value = "group/quit")
-    Object groupQuit(@RequestBody ImGroupModel groupModel);
-
-    /**
-     * 解散群组
-     * @param groupModel
-     * @return
-     */
-    @PostMapping(value = "group/dismiss")
-    Object groupDismiss(@RequestBody ImGroupModel groupModel);
+	/**
+	 * 用户注册
+	 * @param userModel
+	 * @return
+	 */
+	@PostMapping(value = "user/register", consumes = MediaType.APPLICATION_JSON_VALUE)
+	ImResult register(@RequestBody ImUserModel userModel);
+
+	/**
+	 * 创建群组
+	 * @param groupModel
+	 * @return
+	 */
+	@PostMapping(value = "group/create")
+	Object groupCreate(@RequestBody ImGroupModel groupModel);
+
+	/**
+	 * 加入群组
+	 * @param groupModel
+	 * @return
+	 */
+	@PostMapping(value = "group/join")
+	Object groupJoin(@RequestBody ImGroupModel groupModel);
+
+	/**
+	 * 退出群组
+	 * @param groupModel
+	 * @return
+	 */
+	@PostMapping(value = "group/quit")
+	Object groupQuit(@RequestBody ImGroupModel groupModel);
+
+	/**
+	 * 解散群组
+	 * @param groupModel
+	 * @return
+	 */
+	@PostMapping(value = "group/dismiss")
+	Object groupDismiss(@RequestBody ImGroupModel groupModel);
 }

+ 7 - 3
mec-client-api/src/main/java/com/ym/mec/im/fallback/ImFeignServiceFallback.java

@@ -1,14 +1,18 @@
 package com.ym.mec.im.fallback;
 
-import com.ym.mec.im.ImFeignService;
+import org.springframework.stereotype.Component;
+
 import com.ym.mec.common.entity.ImGroupModel;
+import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
-import org.springframework.stereotype.Component;
+import com.ym.mec.im.ImFeignService;
 
 @Component
 public class ImFeignServiceFallback implements ImFeignService {
     @Override
-    public Object register(ImUserModel userModel) {
+    public ImResult register(ImUserModel userModel) {
+    	
+    	System.out.println("*******************");
         return null;
     }
 

+ 7 - 1
mec-common/common-core/src/main/java/com/ym/mec/common/security/BaseAccessDeniedHandler.java

@@ -6,6 +6,7 @@ import java.io.PrintWriter;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,8 +32,13 @@ public class BaseAccessDeniedHandler extends OAuth2AccessDeniedHandler {
 		response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
 		response.setStatus(HttpServletResponse.SC_OK);
 		PrintWriter printWriter = response.getWriter();
+		
+		Throwable e = ExceptionUtils.getRootCause(authException);
+		if (e == null) {
+			e = authException;
+		}
 
-		HttpResponseResult result = new HttpResponseResult(false, HttpServletResponse.SC_FORBIDDEN, null, "禁止访问");
+		HttpResponseResult result = new HttpResponseResult(false, HttpServletResponse.SC_FORBIDDEN, null, e.getMessage());
 
 		ObjectMapper objectMapper = new ObjectMapper();
 

+ 14 - 2
mec-common/common-core/src/main/java/com/ym/mec/common/security/BaseAuthenticationEntryPoint.java

@@ -7,9 +7,11 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.springframework.http.MediaType;
 import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
 import org.springframework.security.web.AuthenticationEntryPoint;
 import org.springframework.stereotype.Component;
 
@@ -25,8 +27,18 @@ public class BaseAuthenticationEntryPoint implements AuthenticationEntryPoint {
 		response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
 		response.setStatus(HttpServletResponse.SC_OK);
 		PrintWriter printWriter = response.getWriter();
-
-		HttpResponseResult result = new HttpResponseResult(false, HttpServletResponse.SC_FORBIDDEN, null, authException.getMessage());
+		
+		Throwable e = ExceptionUtils.getRootCause(authException);
+		if (e == null) {
+			e = authException;
+		}
+		
+		int errorCode = 500;
+		if(e instanceof InvalidTokenException){
+			errorCode = HttpServletResponse.SC_FORBIDDEN;
+		}
+
+		HttpResponseResult result = new HttpResponseResult(false, errorCode, null, e.getMessage());
 
 		ObjectMapper objectMapper = new ObjectMapper();
 

+ 1 - 1
mec-education/src/main/java/com/ym/mec/education/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -41,7 +41,7 @@ public class ClassGroupStudentMapperServiceImpl extends ServiceImpl<ClassGroupSt
 
     @Override
     public PageResponse getPage(ClassGroupReq classGroupReq) {
-        Page<ClassGroupStudentMapper> classGroupStudentMapperPage = new Page<>(classGroupReq.getPageNo(), classGroupReq.getPageSize());
+        Page<ClassGroupStudentMapper> classGroupStudentMapperPage = new Page<ClassGroupStudentMapper>(classGroupReq.getPageNo(), classGroupReq.getPageSize());
         QueryWrapper<ClassGroupStudentMapper> classGroupStudentMapperQueryWrapper = new QueryWrapper<>();
         classGroupStudentMapperQueryWrapper.lambda().eq(true, ClassGroupStudentMapper::getClassGroupId, classGroupReq.getGroupId());
         IPage<ClassGroupStudentMapper> page = page(classGroupStudentMapperPage, classGroupStudentMapperQueryWrapper);

+ 1 - 1
mec-education/src/main/java/com/ym/mec/education/service/impl/CourseScheduleServiceImpl.java

@@ -45,7 +45,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleMapper,
 
     @Override
     public PageResponse getPage(ClassGroupReq classGroupReq) {
-        Page<CourseSchedule> courseSchedulePage = new Page<>(classGroupReq.getPageNo(), classGroupReq.getPageSize());
+        Page<CourseSchedule> courseSchedulePage = new Page<CourseSchedule>(classGroupReq.getPageNo(), classGroupReq.getPageSize());
         QueryWrapper<CourseSchedule> courseScheduleQueryWrapper = new QueryWrapper<>();
         courseScheduleQueryWrapper.lambda().eq(true, CourseSchedule::getClassGroupId, classGroupReq.getGroupId());
         IPage<CourseSchedule> courseScheduleIPage = page(courseSchedulePage, courseScheduleQueryWrapper);