Parcourir la source

Merge branch 'feature/0721-tenant'

yuanliang il y a 1 an
Parent
commit
05b47d3e72

+ 6 - 0
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/api/client/SysUserFeignService.java

@@ -70,6 +70,12 @@ public interface SysUserFeignService {
 	@ApiOperation(value = "退出登录")
 	HttpResponseResult<String> logout(@PathVariable("clientId") String clientId, @PathVariable("phone") String phone);
 
+	@PostMapping(value = "exit/{clientId}/{phone}/{openId}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+	@ApiOperation(value = "指定机构用户退出登录")
+	HttpResponseResult<String> exitByPhoneAndOpenId(@PathVariable("clientId") String clientId,
+														   @PathVariable("phone") String phone,
+														   @PathVariable("openId") String openId);
+
 	@PostMapping(value = "user/list")
 	HttpResponseResult<List<SysUser>> page(@RequestBody SysUserQueryInfo queryInfo);
 

+ 5 - 0
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/api/client/fallback/SysUserFeignServiceFallback.java

@@ -83,6 +83,11 @@ public class SysUserFeignServiceFallback implements SysUserFeignService {
 	}
 
 	@Override
+	public HttpResponseResult<String> exitByPhoneAndOpenId(String clientId, String phone, String openId) {
+		return null;
+	}
+
+	@Override
 	public HttpResponseResult<List<SysUser>> page(SysUserQueryInfo queryInfo) {
 		return HttpResponseResult.failed("请求失败");
 	}

+ 22 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/core/service/CustomTokenServices.java

@@ -30,6 +30,7 @@ import org.springframework.security.web.authentication.preauth.PreAuthenticatedA
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
+import java.text.MessageFormat;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Set;
@@ -294,6 +295,27 @@ public class CustomTokenServices implements AuthorizationServerTokenServices, Re
 		return true;
 	}
 
+
+    public boolean revokeTokenByOpenId(String clientId, String phone,String openId) {
+        Collection<OAuth2AccessToken> list = tokenStore.findTokensByClientIdAndUserName(clientId, SecurityConstants.PHONE_PRINCIPAL_PREFIX + phone);
+
+        if (list == null || list.size() == 0) {
+            list = tokenStore.findTokensByClientIdAndUserName(clientId, MessageFormat.format("{0}:{1}:{2}", SecurityConstants.MA_PRINCIPAL_PREFIX, openId, phone));
+        }
+
+        if (list != null) {
+            for (OAuth2AccessToken accessToken : list) {
+                if (accessToken != null) {
+                    if (accessToken.getRefreshToken() != null) {
+                        tokenStore.removeRefreshToken(accessToken.getRefreshToken());
+                    }
+                    tokenStore.removeAccessToken(accessToken);
+                }
+            }
+        }
+        return true;
+    }
+
 	public void revokeTokenByPhone(String phone) {
 		String[] clientIds = new String[] {"system", "student", "teacher","website"};
 		for (String cId : clientIds) {

+ 11 - 0
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/web/controller/TokenController.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.auth.web.controller;
 
+import cn.hutool.core.net.URLEncodeUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -189,6 +190,16 @@ public class TokenController extends BaseController {
         return tokenService.revokeToken(clientId, phone) ? succeed("退出成功") : failed();
     }
 
+
+    @PostMapping(value = "exit/{clientId}/{phone}/{openId}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+    @ApiOperation(value = "指定机构用户退出登录")
+    public HttpResponseResult<String> exitByPhoneAndOpenId(@PathVariable("clientId") String clientId,
+                                                           @PathVariable("phone") String phone,@PathVariable("openId") String openId) {
+
+        return tokenService.revokeTokenByOpenId(clientId, phone,openId) ? succeed("退出成功") : failed();
+    }
+
+
     @GetMapping(value = "/checkToken", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
     @ApiOperation(value = "检查token")
     public HttpResponseResult<Object> checkToken(HttpServletRequest request) throws IOException {

+ 10 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -232,4 +232,14 @@ public class StudentController extends BaseController {
         studentService.save(student);
         return succeed();
     }
+
+    @PostMapping("/update")
+    @ApiOperation(value = "修改", notes = "传入Student")
+    public HttpResponseResult<Boolean> update(@Validated @RequestBody StudentWrapper.Student student) {
+        if (student.getId() == null) {
+            throw new BizException("id 不能为空");
+        }
+        studentService.save(student);
+        return succeed();
+    }
 }

+ 29 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -21,6 +21,8 @@ import com.yonge.cooleshow.biz.dal.dto.search.QueryMyFollowSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
 import com.yonge.cooleshow.biz.dal.entity.*;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
+import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
+import com.yonge.cooleshow.biz.dal.enums.ImGroupType;
 import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper;
@@ -621,6 +623,33 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         if (student == null) {
             throw new BizException("学生信息不存在");
         }
+        // 是否有修改机构
+        Long newTenantId = studentInfo.getTenantId();
+        if(newTenantId != null && !newTenantId.equals(student.getTenantId())){
+            // 退群
+            List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery()
+                    .eq(ImGroupMember::getRoleType, ImGroupMemberRoleType.STUDENT)
+                    .eq(ImGroupMember::getIsAdmin, false)
+                    .eq(ImGroupMember::getUserId, student.getUserId())
+                    .list();
+            List<String> groupIdList = groupMembers.stream().map(ImGroupMember::getGroupId)
+                    .distinct().collect(Collectors.toList());
+            if(groupIdList.isEmpty()){
+//                imGroupService.listByIds(groupIdList).stream().filter(next-> ImGroupType.ORG.equals(next.getType())).map(next->)
+
+            }
+            groupIdList.forEach(groupId -> {
+                try {
+                    imGroupService.quit(groupId, student.getUserId(), ClientEnum.STUDENT);
+                } catch (Exception e) {
+                    log.error("学生注册,切换机构退群失败:{}", e.getMessage());
+                }
+            });
+            // 删除好友
+//            imUserFriendService.delTeacherFriendByTenantId(tenantId, one.getUserId(),ClientEnum.TEACHER.getCode());
+        }
+
+
         // 手机号码修改
         if (!student.getPhone().equals(studentInfo.getPhone())) {
             com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo);

+ 5 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantInfoServiceImpl.java

@@ -432,7 +432,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         //判断修改手机号后所属
         if (!info.getPhone().equals(oldTenantInfo.getPhone())) {
             // 清除登录token信息
-            sysUserFeignService.logout(ClientEnum.ORGANIZATION.getCode().toLowerCase(), oldTenantInfo.getPhone());
+            TenantStaff tenantStaff = tenantStaffMapper.selectByUserId(sysUser.getId());
+            if(tenantStaff != null){
+                sysUserFeignService.exitByPhoneAndOpenId(ClientEnum.ORGANIZATION.getCode().toLowerCase(),
+                        oldTenantInfo.getPhone(),tenantStaff.getWxOpenid());
+            }
         }
         tenantInfoMapper.update(null, Wrappers.<TenantInfo>lambdaUpdate()
                 .set(TenantInfo::getName, info.getName())