增加根据手机号获取token的接口,同步用户的接口改成微服务调用
This commit is contained in:
		| @ -18,6 +18,6 @@ public interface SystemConstants { | ||||
| 	/*** | ||||
| 	 * feign客户端所在包路径 | ||||
| 	 */ | ||||
| 	String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.app.thirdpart.facade"; | ||||
| 	String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.user.thirdpart.facade"; | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -76,4 +76,10 @@ public class AuthController { | ||||
|         userService.authUser(authRequest); | ||||
|         return Result.ok(true); | ||||
|     } | ||||
|  | ||||
|     @ApiOperation(value = "根据手机号获取token", notes = "根据手机号获取token") | ||||
|     @GetMapping("/getLoginTokenByMobile") | ||||
|     public Result<LoginResponse> getLoginTokenByMobile(@RequestParam("mobile") String mobile) {; | ||||
|         return Result.ok(userService.getLoginTokenByMobile(mobile)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -69,4 +69,11 @@ public interface IUserService { | ||||
|      * @param authRequest 认证请求 | ||||
|      */ | ||||
|     void authUser(AuthRequest authRequest); | ||||
|  | ||||
|     /** | ||||
|      * 根据手机号获取登录token | ||||
|      * @param mobile 手机号 | ||||
|      * @return 登录token | ||||
|      */ | ||||
|     LoginResponse getLoginTokenByMobile(String mobile); | ||||
| } | ||||
|  | ||||
| @ -16,10 +16,11 @@ import com.sczx.user.service.IUserService; | ||||
| import com.sczx.user.thirdpart.dto.WechatDecryptedPhoneInfo; | ||||
| import com.sczx.user.thirdpart.dto.WechatMiniProgramResponse; | ||||
| import com.sczx.user.thirdpart.integration.AlipayInteg; | ||||
| import com.sczx.user.thirdpart.integration.SyncInteg; | ||||
| import com.sczx.user.thirdpart.integration.WeichatInteg; | ||||
| import com.sczx.user.util.DataPushApi; | ||||
| import com.sczx.user.util.JwtUtil; | ||||
| import com.sczx.user.util.RedisUtil; | ||||
| import com.sczx.user.util.ThreadPoolUtils; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| @ -57,8 +58,11 @@ public class UserServiceImpl implements IUserService { | ||||
|     @Autowired | ||||
|     private BaseUserReferralRepo baseUserReferralRepo; | ||||
|  | ||||
| //    @Autowired | ||||
| //    private DataPushApi dataPushApi; | ||||
|  | ||||
|     @Autowired | ||||
|     private DataPushApi dataPushApi; | ||||
|     private SyncInteg syncInteg; | ||||
|  | ||||
|     @Override | ||||
|     public String getWxOpenId(String code) { | ||||
| @ -227,7 +231,10 @@ public class UserServiceImpl implements IUserService { | ||||
|             } | ||||
|             // 推送用户ID | ||||
|             if (isNewUser)  { | ||||
|                 dataPushApi.sendAddUser(baseUserPO.getId()); | ||||
|                 BaseUserPO finalBaseUserPO = baseUserPO; | ||||
|                 ThreadPoolUtils.getThreadPool().execute(() -> { | ||||
|                     syncInteg.sendUserInfoToBattery(finalBaseUserPO.getId().toString()); | ||||
|                 }); | ||||
|             } | ||||
|             return getLoginResponse(baseUserPO,MiniProgramTypeEnum.WECHAT); | ||||
|         }catch (Exception e){ | ||||
| @ -293,7 +300,10 @@ public class UserServiceImpl implements IUserService { | ||||
|             } | ||||
|             // 推送用户ID | ||||
|             if (isNewUser)  { | ||||
|                 dataPushApi.sendAddUser(baseUserPO.getId()); | ||||
|                 BaseUserPO finalBaseUserPO = baseUserPO; | ||||
|                 ThreadPoolUtils.getThreadPool().execute(() -> { | ||||
|                     syncInteg.sendUserInfoToBattery(finalBaseUserPO.getId().toString()); | ||||
|                 }); | ||||
|             } | ||||
|             // 5. 返回登录信息 | ||||
|             return getLoginResponse(baseUserPO,MiniProgramTypeEnum.ALIPAY); | ||||
| @ -335,6 +345,14 @@ public class UserServiceImpl implements IUserService { | ||||
|         baseUserRepo.update(updateWrapper); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public LoginResponse getLoginTokenByMobile(String mobile) { | ||||
|         LambdaQueryWrapper<BaseUserPO> queryWrapper = new LambdaQueryWrapper<>(); | ||||
|         queryWrapper.eq(BaseUserPO::getPhoneNumber, mobile).last( " limit 1"); | ||||
|         BaseUserPO baseUserPO = baseUserRepo.getOne(queryWrapper); | ||||
|         return getLoginResponse(baseUserPO,MiniProgramTypeEnum.WECHAT); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取登录信息 | ||||
|      * @param programId | ||||
|  | ||||
							
								
								
									
										15
									
								
								src/main/java/com/sczx/user/thirdpart/facade/SyncFacade.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/main/java/com/sczx/user/thirdpart/facade/SyncFacade.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| package com.sczx.user.thirdpart.facade; | ||||
|  | ||||
|  | ||||
| import com.sczx.user.common.Result; | ||||
| import org.springframework.cloud.openfeign.FeignClient; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.PathVariable; | ||||
|  | ||||
| @FeignClient(name = "sczx-sync", url = "${sczx-sync.ribbon.listOfServers:}") | ||||
| public interface SyncFacade { | ||||
|  | ||||
|     @GetMapping("/userinfo/{id}") | ||||
|     Result<Boolean> sendUserInfoToBattery(@PathVariable String id); | ||||
|  | ||||
| } | ||||
| @ -0,0 +1,26 @@ | ||||
| package com.sczx.user.thirdpart.integration; | ||||
|  | ||||
| import com.sczx.user.common.Result; | ||||
| import com.sczx.user.exception.InnerException; | ||||
| import com.sczx.user.thirdpart.facade.SyncFacade; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
|  | ||||
| @Slf4j | ||||
| public class SyncInteg { | ||||
|  | ||||
|     @Autowired | ||||
|     private SyncFacade syncFacade; | ||||
|     public Boolean sendUserInfoToBattery(String userId) { | ||||
|         try{ | ||||
|             Result<Boolean> result = syncFacade.sendUserInfoToBattery(userId); | ||||
|             if(result.isSuccess()){ | ||||
|                 return result.getData(); | ||||
|             } | ||||
|         } catch (Exception e){ | ||||
|             log.error("同步用户到租电平台失败",e); | ||||
|             throw new InnerException("同步用户到租电平台失败"); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										57
									
								
								src/main/java/com/sczx/user/util/ThreadPoolUtils.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/main/java/com/sczx/user/util/ThreadPoolUtils.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,57 @@ | ||||
| package com.sczx.user.util; | ||||
|  | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import java.util.concurrent.*; | ||||
|  | ||||
| /** | ||||
|  * 线程池工具类,用于执行异步任务 | ||||
|  * Created by zengji on 2019/5/13. | ||||
|  * | ||||
|  */ | ||||
| @Service | ||||
| public class ThreadPoolUtils { | ||||
|  | ||||
|     public static ThreadPoolExecutor threadPool; | ||||
|     //核心线程大小 | ||||
|     private static int corePoolSize=120; | ||||
|     //最大线程个数 | ||||
|     private static int maximumPoolSize=180; | ||||
|     //空闲线程存活时间 | ||||
|     private static long keepAliveTime=300; | ||||
|     //队列容量 | ||||
|     private static int capacity=200; | ||||
|  | ||||
|     /** | ||||
|      * 无返回值 | ||||
|      */ | ||||
|     public  static void execute(Runnable runnable){ | ||||
|         getThreadPool().execute(runnable); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 有返回值 | ||||
|      */ | ||||
|     public  static <T> Future<T> submit(Callable<T> callable){ | ||||
|         return   getThreadPool().submit(callable); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * dcs获取线程池 | ||||
|      * @return 线程池对象 | ||||
|      */ | ||||
|     public static ThreadPoolExecutor getThreadPool() { | ||||
|         if (threadPool != null) { | ||||
|             return threadPool; | ||||
|         } else { | ||||
|             synchronized (ThreadPoolUtils.class) { | ||||
|                 if (threadPool == null) { | ||||
|                     threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, | ||||
|                             new LinkedBlockingQueue<>(capacity), new ThreadPoolExecutor.CallerRunsPolicy()); | ||||
|                 } | ||||
|                 return threadPool; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -26,4 +26,8 @@ spring: | ||||
|         max-wait: 2000ms | ||||
|         max-idle: 4 | ||||
|         min-idle: 1 | ||||
|         max-life-time: 300000ms | ||||
|         max-life-time: 300000ms | ||||
|  | ||||
| sczx-user: | ||||
|   ribbon: | ||||
|     listOfServers: http://115.190.8.52:8016 | ||||
		Reference in New Issue
	
	Block a user