Commit 6a1471f5 authored by 李健华's avatar 李健华

注销用户多删除租户对应表

parent 9506266d
...@@ -2,8 +2,12 @@ package cn.quantgroup.xyqb.repository; ...@@ -2,8 +2,12 @@ package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.ProductLoginEntity; import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List; import java.util.List;
...@@ -36,4 +40,11 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit ...@@ -36,4 +40,11 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId); List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
ProductLoginEntity findFirstByInstitutionIdAndProductIdAndCustomerId(String institutionId, String productId, long customerId); ProductLoginEntity findFirstByInstitutionIdAndProductIdAndCustomerId(String institutionId, String productId, long customerId);
@Transactional
@Query(value = "delete from product_login where INSTITUTION_ID = ?1 and PRODUCT_ID = ?2 and PHONE_NO = ?3", nativeQuery = true)
@Modifying
void deleteTenantAndPhoneNo(String qtg, String yxm, String phoneNo);
} }
\ No newline at end of file
...@@ -24,4 +24,6 @@ public interface IProductLoginService { ...@@ -24,4 +24,6 @@ public interface IProductLoginService {
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId); List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId); ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId);
ProductLoginEntity findTenantAndPhoneNo(String institutionId, String productId, String phoneNo);
} }
...@@ -7,6 +7,7 @@ import cn.quantgroup.xyqb.repository.ICustomerLoginRepository; ...@@ -7,6 +7,7 @@ import cn.quantgroup.xyqb.repository.ICustomerLoginRepository;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository; import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.repository.IProductLoginRepository; import cn.quantgroup.xyqb.repository.IProductLoginRepository;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService; import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import cn.quantgroup.xyqb.util.AtomicSequencer; import cn.quantgroup.xyqb.util.AtomicSequencer;
import cn.quantgroup.xyqb.util.RandomSequencer; import cn.quantgroup.xyqb.util.RandomSequencer;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -36,13 +37,15 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -36,13 +37,15 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Autowired @Autowired
private ICustomerLoginRepository customerLoginRepository; private ICustomerLoginRepository customerLoginRepository;
@Autowired
private IProductLoginService productLoginService;
@Autowired @Autowired
private AtomicSequencer atomicSequencer; private AtomicSequencer atomicSequencer;
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void addLoginInfo(User user, Integer tenantId) { public void addLoginInfo(User user, Integer tenantId) {
log.info("=addLoginInfo -> user={}, tenetId={}", JSON.toJSONString(user), tenantId);
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(tenantId); OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(tenantId);
if (oauthClientDetailsEntity != null) { if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId(); String institutionId = oauthClientDetailsEntity.getInstitutionId();
...@@ -50,11 +53,8 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -50,11 +53,8 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
String phoneNo = user.getPhoneNo(); String phoneNo = user.getPhoneNo();
Long userId = user.getId(); Long userId = user.getId();
ProductLoginEntity findProductLoginEntity = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId); ProductLoginEntity findProductLoginEntity = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId);
ProductLoginEntity findProductLoginByPhoneEntity = productLoginRepository.findFirstByInstitutionIdAndProductIdAndEncryptedPhoneNo(institutionId, productId, phoneNo); ProductLoginEntity findProductLoginByPhoneEntity = productLoginService.findTenantAndPhoneNo(institutionId, productId, phoneNo);
log.info("=findProductLoginEntity -> {}", JSON.toJSONString(findProductLoginEntity));
log.info("=findProductLoginPhoneEntity -> {}", JSON.toJSONString(findProductLoginByPhoneEntity));
long uuid = 0L; long uuid = 0L;
// 如果找不到该用户就创建
if (findProductLoginEntity == null && findProductLoginByPhoneEntity == null) { if (findProductLoginEntity == null && findProductLoginByPhoneEntity == null) {
// 添加用户到产品登录表 // 添加用户到产品登录表
long customerId = atomicSequencer.nextId(); long customerId = atomicSequencer.nextId();
...@@ -67,9 +67,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -67,9 +67,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
ProductLoginEntity productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id); ProductLoginEntity productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId); productLoginEntity.setExtensionAccountId(userId);
productLoginEntity.setEncryptedPhoneNo(phoneNo); productLoginEntity.setEncryptedPhoneNo(phoneNo);
log.info("=addLoginInfo=save begin productLoginRepository={}", JSON.toJSONString(productLoginEntity));
productLoginRepository.save(productLoginEntity); productLoginRepository.save(productLoginEntity);
log.info("=addLoginInfo=save end productLoginRepository={}", JSON.toJSONString(productLoginEntity));
// 根据customerId 获取uuid // 根据customerId 获取uuid
CustomerLoginEntity customerLoginEntity = customerLoginRepository.findFirstByCustomerId(productLoginEntity.getCustomerId()); CustomerLoginEntity customerLoginEntity = customerLoginRepository.findFirstByCustomerId(productLoginEntity.getCustomerId());
if (null != customerLoginEntity) { if (null != customerLoginEntity) {
...@@ -88,9 +86,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -88,9 +86,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
customerLogin.setModifiedDate(new Date()); customerLogin.setModifiedDate(new Date());
customerLogin.setCreatedBy(""); customerLogin.setCreatedBy("");
customerLogin.setModifiedBy(""); customerLogin.setModifiedBy("");
log.info("=addLoginInfo=save begin customerLoginRepository={}", JSON.toJSONString(customerLogin));
customerLoginRepository.save(customerLogin); customerLoginRepository.save(customerLogin);
log.info("=addLoginInfo=save end customerLoginRepository={}", JSON.toJSONString(customerLogin));
// 添加用户信息表 // 添加用户信息表
CustomerInfoEntity customerInfo = new CustomerInfoEntity(); CustomerInfoEntity customerInfo = new CustomerInfoEntity();
// customerInfo.setId(atomicSequencer.nextId()); // customerInfo.setId(atomicSequencer.nextId());
...@@ -102,9 +98,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -102,9 +98,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
customerInfo.setModifiedDate(new Date()); customerInfo.setModifiedDate(new Date());
customerInfo.setCreatedBy(""); customerInfo.setCreatedBy("");
customerInfo.setModifiedBy(""); customerInfo.setModifiedBy("");
log.info("=addLoginInfo=save begin customerInfoRepository={}", JSON.toJSONString(customerInfo));
customerInfoRepository.save(customerInfo); customerInfoRepository.save(customerInfo);
log.info("=addLoginInfo=save end customerInfoRepository={}", JSON.toJSONString(customerInfo));
} }
} }
} }
...@@ -112,14 +106,13 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -112,14 +106,13 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Override @Override
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public void addRegisterInfo(User user, AppletParamEntry appletParamEntry) { public void addRegisterInfo(User user, AppletParamEntry appletParamEntry) {
log.info("=addRegisterInfo= -> User={}, AppletParamEntry={}", JSON.toJSONString(user), appletParamEntry);
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(appletParamEntry.getTenantId()); OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsRepository.findFirstByClientId(appletParamEntry.getTenantId());
if (oauthClientDetailsEntity != null) { if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId(); String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId(); String productId = oauthClientDetailsEntity.getProductId();
String phoneNo = user.getPhoneNo(); String phoneNo = user.getPhoneNo();
Long userId = user.getId(); Long userId = user.getId();
ProductLoginEntity productLoginEntity = productLoginRepository.findFirstByInstitutionIdAndProductIdAndEncryptedPhoneNo(institutionId, productId, phoneNo); ProductLoginEntity productLoginEntity = productLoginService.findTenantAndPhoneNo(institutionId, productId, phoneNo);
long uuid = 0L; long uuid = 0L;
// 如果找不到该用户就创建 // 如果找不到该用户就创建
if ("".equals(productLoginEntity) || productLoginEntity == null) { if ("".equals(productLoginEntity) || productLoginEntity == null) {
...@@ -133,9 +126,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -133,9 +126,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id); productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId); productLoginEntity.setExtensionAccountId(userId);
productLoginEntity.setEncryptedPhoneNo(phoneNo); productLoginEntity.setEncryptedPhoneNo(phoneNo);
log.info("=addRegisterInfo=save begin productLoginRepository= {}", JSON.toJSONString(productLoginEntity));
productLoginRepository.save(productLoginEntity); productLoginRepository.save(productLoginEntity);
log.info("=addRegisterInfo=save end productLoginRepository= {}", JSON.toJSONString(productLoginEntity));
// 根据customerId 获取uuid // 根据customerId 获取uuid
CustomerLoginEntity customerLoginEntity = customerLoginRepository.findFirstByCustomerId(productLoginEntity.getCustomerId()); CustomerLoginEntity customerLoginEntity = customerLoginRepository.findFirstByCustomerId(productLoginEntity.getCustomerId());
if (null != customerLoginEntity) { if (null != customerLoginEntity) {
...@@ -154,9 +145,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -154,9 +145,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
customerLogin.setModifiedDate(new Date()); customerLogin.setModifiedDate(new Date());
customerLogin.setCreatedBy(""); customerLogin.setCreatedBy("");
customerLogin.setModifiedBy(""); customerLogin.setModifiedBy("");
log.info("=addRegisterInfo=save begin customerLoginRepository= {}", JSON.toJSONString(customerLogin));
customerLoginRepository.save(customerLogin); customerLoginRepository.save(customerLogin);
log.info("=addRegisterInfo=save end customerLoginRepository= {}", JSON.toJSONString(customerLogin));
// 添加用户信息表 // 添加用户信息表
CustomerInfoEntity customerInfo = new CustomerInfoEntity(); CustomerInfoEntity customerInfo = new CustomerInfoEntity();
// customerInfo.setId(atomicSequencer.nextId()); // customerInfo.setId(atomicSequencer.nextId());
...@@ -179,9 +168,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService { ...@@ -179,9 +168,7 @@ public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
customerInfo.setModifiedDate(new Date()); customerInfo.setModifiedDate(new Date());
customerInfo.setCreatedBy(""); customerInfo.setCreatedBy("");
customerInfo.setModifiedBy(""); customerInfo.setModifiedBy("");
log.info("=addRegisterInfo=save begin customerInfoRepository= {}", JSON.toJSONString(customerInfo));
customerInfoRepository.save(customerInfo); customerInfoRepository.save(customerInfo);
log.info("=addRegisterInfo=save end customerInfoRepository= {}", JSON.toJSONString(customerInfo));
} else { } else {
// 如果产品登陆表有信息,查询用户信息表 // 如果产品登陆表有信息,查询用户信息表
CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(productLoginEntity.getCustomerId()); CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(productLoginEntity.getCustomerId());
......
...@@ -55,4 +55,13 @@ public class ProductLoginServiceImpl implements IProductLoginService { ...@@ -55,4 +55,13 @@ public class ProductLoginServiceImpl implements IProductLoginService {
public ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId) { public ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId) {
return productLoginRepository.findFirstByInstitutionIdAndProductIdAndCustomerId(institutionId, productId, customerId); return productLoginRepository.findFirstByInstitutionIdAndProductIdAndCustomerId(institutionId, productId, customerId);
} }
@Override
public ProductLoginEntity findTenantAndPhoneNo(String institutionId, String productId, String phoneNo) {
ProductLoginEntity productLogin = productLoginRepository.findFirstByInstitutionIdAndProductIdAndEncryptedPhoneNo(institutionId, productId, phoneNo);
if (productLogin == null) {
productLogin = productLoginRepository.findFirstByInstitutionIdAndProductIdAndPhoneNo(institutionId, productId, phoneNo);
}
return productLogin;
}
} }
...@@ -106,6 +106,9 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -106,6 +106,9 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Resource @Resource
private IWeChatUserRepository weChatUserRepository; private IWeChatUserRepository weChatUserRepository;
@Resource
private IProductLoginRepository productLoginRepository;
@Override @Override
// @Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager") // @Cacheable(value = "usercache", key = "'xyqbuser' + #phone", unless = "#result == null", cacheManager = "cacheManager")
public User findByPhoneInDb(String phone) { public User findByPhoneInDb(String phone) {
...@@ -599,5 +602,8 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -599,5 +602,8 @@ public class UserServiceImpl implements IUserService, IBaseController {
/* 禁用微信 Or 删除?*/ /* 禁用微信 Or 删除?*/
// wechatService.forbiddenXyqbAndWuxiUserByUserId(user.getId()); // wechatService.forbiddenXyqbAndWuxiUserByUserId(user.getId());
weChatUserRepository.deleteByUserId(userId); weChatUserRepository.deleteByUserId(userId);
/* 删除用户租户关联 羊小咩租户*/
productLoginRepository.deleteTenantAndPhoneNo("qtg", "yxm", user.getPhoneNo());
} }
} }
...@@ -37,6 +37,6 @@ public final class Md5Util { ...@@ -37,6 +37,6 @@ public final class Md5Util {
} }
public static void main(String[] args){ public static void main(String[] args){
System.out.println(Md5Util.build("13718656985")); System.out.println(Md5Util.build("15010826659"));
} }
} }
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