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

小程序注册接口添加租户

parent 52cb1d0e
......@@ -101,7 +101,7 @@ public class PasswordFreeAccessValidateAdvisor {
// 如果头部没有tenantId参数
if (StringUtils.isBlank(tenantId)) {
// 如果 token Session tenantId 不是默认羊小咩, 那么拒绝登陆
if (!loginProperties.getTenantId().toString().equals(TenantUtil.TENANT_DEFAULT)) {
if (!loginProperties.getTenantId().equals(TenantUtil.TENANT_DEFAULT)) {
log.info("非法请求 - 错误租户, token={}, phoneNo={}, userId={}, clientIp={}, tenantId={}, loginTenantId={}", token, phoneNo, userId, clientIp, tenantId, loginProperties.getTenantId().toString());
return false;
}
......
......@@ -76,4 +76,8 @@ public class AppletParamEntry {
*/
private String utmSource;
/**
* 租户ID
*/
private Integer tenantId;
}
......@@ -74,6 +74,9 @@ public class AppletServiceImpl implements IAppletService {
//如果不存在就去注册一下
if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile());
if (appletParamEntry.getTenantId() != null) {
iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
}
}
wechatUserInfo.setUserId(user.getId());
}
......
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
/**
* Created by Li Jianhua on 2017/1/3.
*/
public interface IOauthLoginInfoService {
void addLoginInfo(User user, Integer tenantId);
void addRegisterInfo(User user, AppletParamEntry appletParamEntry);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry;
import cn.quantgroup.xyqb.repository.ICustomerInfoRepository;
import cn.quantgroup.xyqb.repository.ICustomerLoginRepository;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
......@@ -40,7 +41,6 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addLoginInfo(User user, Integer tenantId) {
System.out.println(atomicSequencer.nextId());
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(tenantId);
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
......@@ -99,4 +99,74 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
}
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addRegisterInfo(User user, AppletParamEntry appletParamEntry) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(appletParamEntry.getTenantId());
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId();
String phoneNo = user.getPhoneNo();
Long userId = user.getId();
ProductLoginEntity productLoginEntity = productLoginRepository.findFirstByInstitutionIdAndProductIdAndPhoneNo(institutionId, productId, phoneNo);
long uuid = 0L;
// 如果找不到该用户就创建
if ("".equals(productLoginEntity) || productLoginEntity == null) {
// 添加用户到产品登录表
long customerId = atomicSequencer.nextId();
long id = atomicSequencer.nextId();
String customerName = customerId + "";
uuid = RandomSequencer.randomUUID(customerId);
ProductLoginEntity entity = new ProductLoginEntity();
Integer partitionKey = atomicSequencer.partitionKey(customerId);
productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId);
productLoginRepository.save(productLoginEntity);
// 根据customerId 获取uuid
CustomerLoginEntity customerLoginEntity = customerLoginRepository.findFirstByCustomerId(productLoginEntity.getCustomerId());
if (null != customerLoginEntity) {
uuid = customerLoginEntity.getUuid();
}
// 添加用户到登录表
CustomerLoginEntity customerLogin = new CustomerLoginEntity();
customerLogin.setId(atomicSequencer.nextId());
customerLogin.setInstitutionId(institutionId);
customerLogin.setProductId(productId);
customerLogin.setCustomerId(customerId);
customerLogin.setUuid(uuid);
customerLogin.setPartitionKey(partitionKey);
customerLogin.setCreatedDate(new Date());
customerLogin.setModifiedDate(new Date());
customerLogin.setCreatedBy("");
customerLogin.setModifiedBy("");
customerLoginRepository.save(customerLogin);
// 添加用户信息表
CustomerInfoEntity customerInfo = new CustomerInfoEntity();
customerInfo.setId(atomicSequencer.nextId());
customerInfo.setCustomerId(customerId);
customerInfo.setInstitutionId(institutionId);
customerInfo.setAvatarUrl(appletParamEntry.getAvatarUrl());
customerInfo.setNickName(appletParamEntry.getNickName());
customerInfo.setCity(appletParamEntry.getCity());
customerInfo.setCountry(appletParamEntry.getCountry());
customerInfo.setProvince(appletParamEntry.getProvince());
customerInfo.setLanguage(appletParamEntry.getLanguage());
customerInfo.setSourceOpenId(appletParamEntry.getOpenId());
customerInfo.setSex(cn.quantgroup.xyqb.model.Gender.class.getEnumConstants()[appletParamEntry.getGender()]);
customerInfo.setUnionId(appletParamEntry.getUnionId());
customerInfo.setUtmSource(appletParamEntry.getUtmSource());
customerInfo.setProductId(productId);
customerInfo.setPartitionKey(partitionKey);
customerInfo.setCreatedDate(new Date());
customerInfo.setModifiedDate(new Date());
customerInfo.setCreatedBy("");
customerInfo.setModifiedBy("");
customerInfoRepository.save(customerInfo);
}
}
}
}
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