Commit eb095ae9 authored by 李健华's avatar 李健华

小程序注册登陆,极光登陆

parent 9a3b67f0
...@@ -70,8 +70,12 @@ public class AppController implements IBaseController { ...@@ -70,8 +70,12 @@ public class AppController implements IBaseController {
@RequestParam(required = false) Long registerFrom, @RequestParam(required = false) Long registerFrom,
@RequestParam(required = true) Long channelId, @RequestParam(required = true) Long channelId,
@RequestParam(required = true) String appChannel, @RequestParam(required = true) String appChannel,
@RequestParam(required = false) Integer tenantId,
HttpServletRequest request) { HttpServletRequest request) {
if (tenantId == null) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
JsonResult result = null; JsonResult result = null;
Authentication authentication = AuthorityManager.authentication(); Authentication authentication = AuthorityManager.authentication();
if(authentication.isAuthenticated()){ if(authentication.isAuthenticated()){
...@@ -87,6 +91,9 @@ public class AppController implements IBaseController { ...@@ -87,6 +91,9 @@ public class AppController implements IBaseController {
isRegister = true; isRegister = true;
user = userRegisterService.register(registerFrom, phoneNumber, idNo, name, channelId, createdFrom); user = userRegisterService.register(registerFrom, phoneNumber, idNo, name, channelId, createdFrom);
} }
// 无论是否注册过都添加映射
oauthLoginInfoService.addLoginInfo(user, tenantId);
if (user == null) { if (user == null) {
result = JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null); result = JsonResult.buildErrorStateResult(USER_ERROR_OR_PASSWORD_ERROR, null);
} else if (!user.getEnable()) { } else if (!user.getEnable()) {
......
package cn.quantgroup.xyqb.controller.middleoffice.applet; package cn.quantgroup.xyqb.controller.middleoffice.applet;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule; import cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule;
import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo; import cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry; import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
...@@ -18,6 +7,12 @@ import cn.quantgroup.xyqb.exception.DataException; ...@@ -18,6 +7,12 @@ import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService; import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
/** /**
* @author :dongjianhua * @author :dongjianhua
...@@ -68,7 +63,7 @@ public class AppletController { ...@@ -68,7 +63,7 @@ public class AppletController {
*/ */
@Validated @Validated
@PostMapping("/login") @PostMapping("/login")
public JsonResult login(@RequestParam String appName, @RequestParam String openId, @RequestParam(required = false) Integer tenantId, String utmSource) { public JsonResult login(@RequestParam String appName, @RequestParam String openId, @RequestParam(required = false) Integer tenantId, String utmSource, @RequestParam(required = false) Integer appNo) {
if (!containsAppName(appName)) { if (!containsAppName(appName)) {
throw new DataException("appName不合法"); throw new DataException("appName不合法");
} }
......
...@@ -80,4 +80,9 @@ public class AppletParamEntry { ...@@ -80,4 +80,9 @@ public class AppletParamEntry {
* 租户ID * 租户ID
*/ */
private Integer tenantId; private Integer tenantId;
/**
* 小程序编号
*/
private Integer appNo;
} }
...@@ -10,4 +10,6 @@ import org.springframework.stereotype.Repository; ...@@ -10,4 +10,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface ICustomerInfoRepository extends JpaRepository<CustomerInfoEntity, Long> { public interface ICustomerInfoRepository extends JpaRepository<CustomerInfoEntity, Long> {
CustomerInfoEntity findByCustomerId(Long customerId); CustomerInfoEntity findByCustomerId(Long customerId);
CustomerInfoEntity findByInstitutionIdAndProductIdAndSourceOpenId(String institutionId, String productId, String OpenId);
} }
\ No newline at end of file
...@@ -31,4 +31,6 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit ...@@ -31,4 +31,6 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit
* @return Arraylist * @return Arraylist
*/ */
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId); List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
ProductLoginEntity findFirstByInstitutionIdAndProductIdAndCustomerId(String institutionId, String productId, long customerId);
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import cn.quantgroup.xyqb.repository.IWeChatUserRepository; ...@@ -10,6 +10,7 @@ import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService; import cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService; import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.ITenantService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -39,6 +40,9 @@ public class AppletServiceImpl implements IAppletService { ...@@ -39,6 +40,9 @@ public class AppletServiceImpl implements IAppletService {
@Autowired @Autowired
private IOauthLoginInfoService iOauthLoginInfoService; private IOauthLoginInfoService iOauthLoginInfoService;
@Autowired
private ITenantService tenantService;
@Autowired @Autowired
public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository, public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository,
IUserRegisterService iUserRegisterService, IUserRegisterService iUserRegisterService,
...@@ -53,61 +57,91 @@ public class AppletServiceImpl implements IAppletService { ...@@ -53,61 +57,91 @@ public class AppletServiceImpl implements IAppletService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Long relevance(AppletParamEntry appletParamEntry) { public Long relevance(AppletParamEntry appletParamEntry) {
if (appletParamEntry.getTenantId() == null ) {
appletParamEntry.setTenantId(TenantUtil.TENANT_DEFAULT);
}
if (appletParamEntry.getTenantId().equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(appletParamEntry.getOpenId(), appletParamEntry.getAppName());
//这个接口先不考虑更换手机号的情况
wechatUserInfo = (wechatUserInfo == null ? new WechatUserInfo() : wechatUserInfo);
wechatUserInfo.setNickName(appletParamEntry.getNickName());
wechatUserInfo.setCity(appletParamEntry.getCity());
wechatUserInfo.setCountry(appletParamEntry.getCountry());
wechatUserInfo.setProvince(appletParamEntry.getProvince());
wechatUserInfo.setAppName(appletParamEntry.getAppName());
wechatUserInfo.setHeadImgUrl(appletParamEntry.getAvatarUrl());
wechatUserInfo.setLanguage(appletParamEntry.getLanguage());
wechatUserInfo.setOpenId(appletParamEntry.getOpenId());
wechatUserInfo.setSex(appletParamEntry.getGender());
wechatUserInfo.setUnionId(appletParamEntry.getUnionId());
wechatUserInfo.setPhoneNo(appletParamEntry.getMobile());
wechatUserInfo.setUtmSource(appletParamEntry.getUtmSource());
if (null == wechatUserInfo.getUserId()) {//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下
if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile());
}
iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
wechatUserInfo.setUserId(user.getId());
}
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(appletParamEntry.getOpenId(), appletParamEntry.getAppName()); //如果存在就更新在微信表里
//这个接口先不考虑更换手机号的情况 iWeChatUserRepository.save(wechatUserInfo);
return wechatUserInfo.getUserId();
wechatUserInfo = (wechatUserInfo == null ? new WechatUserInfo() : wechatUserInfo); } else {
wechatUserInfo.setNickName(appletParamEntry.getNickName());
wechatUserInfo.setCity(appletParamEntry.getCity());
wechatUserInfo.setCountry(appletParamEntry.getCountry());
wechatUserInfo.setProvince(appletParamEntry.getProvince());
wechatUserInfo.setAppName(appletParamEntry.getAppName());
wechatUserInfo.setHeadImgUrl(appletParamEntry.getAvatarUrl());
wechatUserInfo.setLanguage(appletParamEntry.getLanguage());
wechatUserInfo.setOpenId(appletParamEntry.getOpenId());
wechatUserInfo.setSex(appletParamEntry.getGender());
wechatUserInfo.setUnionId(appletParamEntry.getUnionId());
wechatUserInfo.setPhoneNo(appletParamEntry.getMobile());
wechatUserInfo.setUtmSource(appletParamEntry.getUtmSource());
if (null == wechatUserInfo.getUserId()) {//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
User user = userService.findByPhoneInDb(appletParamEntry.getMobile()); User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下 //如果不存在就去注册一下
if (null == user) { if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile()); user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile());
if (appletParamEntry.getTenantId() != null) {
iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
}
} }
wechatUserInfo.setUserId(user.getId()); iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
return user.getId();
} }
//如果存在就更新在微信表里
iWeChatUserRepository.save(wechatUserInfo);
return wechatUserInfo.getUserId();
} }
@Override @Override
public LoginVo login(String appName, String openId, Integer tenantId, String utmSource) { public LoginVo login(String appName, String openId, Integer tenantId, String utmSource) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName); if (tenantId == null) {
if (null == wechatUserInfo) { tenantId = TenantUtil.TENANT_DEFAULT;
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401");
}
if (null == wechatUserInfo.getUserId()) {
log.warn("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户绑定信息","0401");
} }
User user = userService.findById(wechatUserInfo.getUserId()); User user = null;
if (null == user) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId); if (TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
throw new AppletException("未找到此用户","0401"); WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName);
} if (null == wechatUserInfo) {
//校验租户ID tenantId log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
if (TenantUtil.checkoutTenantIsDefault(tenantId)) { throw new AppletException("未找到此用户","0401");
}
if (null == wechatUserInfo.getUserId()) {
log.warn("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户绑定信息","0401");
}
user = userService.findById(wechatUserInfo.getUserId());
if (null == user) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401");
}
iOauthLoginInfoService.addLoginInfo(user, tenantId); iOauthLoginInfoService.addLoginInfo(user, tenantId);
} else {
// 通过租户id和openId查询是否有关联
Long userId = tenantService.getTenantCustomerInfoByOpenId(openId, tenantId);
if (null == userId) {
log.warn("未找到此用户,tenantId:{} ,openId:{}", tenantId, openId);
throw new AppletException("未找到此用户","0401");
}
user = userService.findById(userId);
if (null == user) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401");
}
} }
LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(), LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(),
utmSource == null ? "" : utmSource, user.getId(), tenantId); utmSource == null ? "" : utmSource, user.getId(), tenantId);
return loginVo; return loginVo;
......
...@@ -7,4 +7,6 @@ import cn.quantgroup.xyqb.entity.CustomerInfoEntity; ...@@ -7,4 +7,6 @@ import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
*/ */
public interface ICustomerInfoService { public interface ICustomerInfoService {
CustomerInfoEntity findSlaveByCustomerId(Long customerId); CustomerInfoEntity findSlaveByCustomerId(Long customerId);
CustomerInfoEntity findSlaveByOpenId(String openId, String institutionId, String productId);
} }
...@@ -20,4 +20,6 @@ public interface IProductLoginService { ...@@ -20,4 +20,6 @@ public interface IProductLoginService {
* @return Arraylist * @return Arraylist
*/ */
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId); List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId);
} }
...@@ -26,4 +26,6 @@ public interface ITenantService { ...@@ -26,4 +26,6 @@ public interface ITenantService {
* @return Arraylist * @return Arraylist
*/ */
List<User> selectUsersByTenantId(List<User> users, Integer tenantId); List<User> selectUsersByTenantId(List<User> users, Integer tenantId);
Long getTenantCustomerInfoByOpenId(String openId, Integer tenantId);
} }
...@@ -24,4 +24,11 @@ public class CustomerInfoServiceImpl implements ICustomerInfoService { ...@@ -24,4 +24,11 @@ public class CustomerInfoServiceImpl implements ICustomerInfoService {
CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(customerId); CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(customerId);
return customerInfo; return customerInfo;
} }
@Override
@TargetDataSource(type = DSType.SLAVE)//查询从库
public CustomerInfoEntity findSlaveByOpenId(String openId, String institutionId, String productId) {
CustomerInfoEntity customerInfo = customerInfoRepository.findByInstitutionIdAndProductIdAndSourceOpenId(institutionId, productId, openId);
return customerInfo;
}
} }
...@@ -38,4 +38,9 @@ public class ProductLoginServiceImpl implements IProductLoginService { ...@@ -38,4 +38,9 @@ public class ProductLoginServiceImpl implements IProductLoginService {
public List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId) { public List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId) {
return productLoginRepository.findProductLoginsByInstitutionIdAndProductId(institutionId, productId); return productLoginRepository.findProductLoginsByInstitutionIdAndProductId(institutionId, productId);
} }
@Override
public ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId) {
return productLoginRepository.findFirstByInstitutionIdAndProductIdAndCustomerId(institutionId, productId, customerId);
}
} }
...@@ -120,4 +120,20 @@ public class TenantServiceImpl implements ITenantService { ...@@ -120,4 +120,20 @@ public class TenantServiceImpl implements ITenantService {
} }
return result; return result;
} }
@Override
public Long getTenantCustomerInfoByOpenId(String openId, Integer tenantId) {
// 通过租户Id确认产品和机构Id
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
CustomerInfoEntity customerInfo = customerInfoService.findSlaveByOpenId(openId, oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId());
if (customerInfo != null ) {
ProductLoginEntity productLogin = productLoginService.findSlaveByCustomerInfo(customerInfo.getCustomerId(), oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId());
if (productLogin != null) {
return productLogin.getExtensionAccountId();
}
}
}
return null;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment