Commit a92e9c3f authored by 王亮's avatar 王亮

Merge branch 'feature-upgrade-20230621' into 'master'

delete tables of oauth_client_details、customer_info、product_login、customer_login。

See merge request !121
parents 904e15ef beb25389
...@@ -81,9 +81,6 @@ public class UserController implements IBaseController { ...@@ -81,9 +81,6 @@ public class UserController implements IBaseController {
@Autowired @Autowired
private IUserRegisterService userRegisterService; private IUserRegisterService userRegisterService;
@Autowired
private ITenantService tenantService;
@Value("${xyqb.user.service.host}") @Value("${xyqb.user.service.host}")
private String userHost; private String userHost;
...@@ -528,22 +525,7 @@ public class UserController implements IBaseController { ...@@ -528,22 +525,7 @@ public class UserController implements IBaseController {
} }
} }
User user = sessionStruct.getValues().getUser(); User user = sessionStruct.getValues().getUser();
Integer sessionTenantId = sessionStruct.getValues().getLoginProperties().getTenantId();
//默认羊小咩租户
if (TenantUtil.validationTenantIdIsNullOrZero(sessionTenantId)) {
sessionTenantId = TenantUtil.TENANT_DEFAULT;
}
//校验非羊小咩租户
if (!sessionTenantId.equals(TenantUtil.TENANT_DEFAULT)) {
if (sessionTenantId.equals(tenantId)) {
user = tenantService.getTenantUser(user, tenantId);
if (user == null) {
return JsonResult.buildSuccessResult(null, result);
}
}else {
return JsonResult.buildSuccessResult(null, result);
}
}
String phoneNo = user.getPhoneNo(); String phoneNo = user.getPhoneNo();
result.put("phoneNo", phoneNo); result.put("phoneNo", phoneNo);
result.put("userId", user.getId()); result.put("userId", user.getId());
...@@ -647,10 +629,6 @@ public class UserController implements IBaseController { ...@@ -647,10 +629,6 @@ public class UserController implements IBaseController {
return JsonResult.buildSuccessResult("", brief); return JsonResult.buildSuccessResult("", brief);
} }
String tenantId = getCurrentTenantIdRedis();
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(Integer.parseInt(tenantId))) {
brief = tenantService.getTenantCustomerInfo(userDetail, Integer.parseInt(tenantId));
}
return JsonResult.buildSuccessResult(null, brief); return JsonResult.buildSuccessResult(null, brief);
} }
......
...@@ -15,7 +15,6 @@ import cn.quantgroup.xyqb.security.AuthorizationPoint; ...@@ -15,7 +15,6 @@ import cn.quantgroup.xyqb.security.AuthorizationPoint;
import cn.quantgroup.xyqb.service.merchant.IMerchantService; import cn.quantgroup.xyqb.service.merchant.IMerchantService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.IOauthLoginInfoService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.IpUtil; import cn.quantgroup.xyqb.util.IpUtil;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
...@@ -53,8 +52,7 @@ public class AppController implements IBaseController { ...@@ -53,8 +52,7 @@ public class AppController implements IBaseController {
private ISessionService sessionService; private ISessionService sessionService;
@Autowired @Autowired
private IUserService userService; private IUserService userService;
@Autowired
private IOauthLoginInfoService oauthLoginInfoService;
@Autowired @Autowired
private IMerchantService merchantService; private IMerchantService merchantService;
@Autowired @Autowired
...@@ -94,8 +92,7 @@ public class AppController implements IBaseController { ...@@ -94,8 +92,7 @@ public class AppController implements IBaseController {
isRegister = true; isRegister = true;
user = userRegisterService.register(registerFrom, phoneNumber, name, channelId, createdFrom, tenantId); user = userRegisterService.register(registerFrom, phoneNumber, name, channelId, createdFrom, tenantId);
} }
// 无论是否注册过都添加映射
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);
...@@ -239,9 +236,6 @@ public class AppController implements IBaseController { ...@@ -239,9 +236,6 @@ public class AppController implements IBaseController {
return JsonResult.buildErrorStateResult("无效的商户", null); return JsonResult.buildErrorStateResult("无效的商户", null);
} }
//租户下新增用户
oauthLoginInfoService.addLoginInfo(user, tenantId);
log.info("=addLoginInfo end"); log.info("=addLoginInfo end");
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName(), tenantId); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, merchant.getId(), merchant.getName(), tenantId);
AuthBean bean = sessionService.createSession(user, loginProperties, LoginType.SUPERLOGIN.ordinal()); AuthBean bean = sessionService.createSession(user, loginProperties, LoginType.SUPERLOGIN.ordinal());
...@@ -339,8 +333,7 @@ public class AppController implements IBaseController { ...@@ -339,8 +333,7 @@ public class AppController implements IBaseController {
if (!user.getEnable()) { if (!user.getEnable()) {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_ENABLE_ERROR, null); return JsonResult.buildErrorStateResult(USER_ERROR_OR_ENABLE_ERROR, null);
} }
//校验租户ID tenantId
oauthLoginInfoService.addLoginInfo(user, tenantId);
LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, null, "", tenantId); LoginProperties loginProperties = new LoginProperties("", 4, channelId, registerFrom, appChannel, null, "", tenantId);
AuthBean bean = sessionService.createSession(user, loginProperties, LoginType.SUPERLOGINTWO.ordinal()); AuthBean bean = sessionService.createSession(user, loginProperties, LoginType.SUPERLOGINTWO.ordinal());
// 不同渠道用户补签不同模板合同 // 不同渠道用户补签不同模板合同
......
...@@ -18,7 +18,9 @@ import cn.quantgroup.xyqb.service.register.IUserDeregisterService; ...@@ -18,7 +18,9 @@ import cn.quantgroup.xyqb.service.register.IUserDeregisterService;
import cn.quantgroup.xyqb.service.register.IUserRegisterService; import cn.quantgroup.xyqb.service.register.IUserRegisterService;
import cn.quantgroup.xyqb.service.session.ISessionService; import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.sms.ISmsService; import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.*; import cn.quantgroup.xyqb.service.user.IUserBtRegisterService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.service.user.vo.UserDetailVO; import cn.quantgroup.xyqb.service.user.vo.UserDetailVO;
import cn.quantgroup.xyqb.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.util.*; import cn.quantgroup.xyqb.util.*;
...@@ -86,12 +88,6 @@ public class InnerController implements IBaseController { ...@@ -86,12 +88,6 @@ public class InnerController implements IBaseController {
@Autowired @Autowired
private StmsRemoteService stmsRemoteService; private StmsRemoteService stmsRemoteService;
@Autowired
private ITenantService tenantService;
@Autowired
private IOauthLoginInfoService iOauthLoginInfoService;
@Autowired @Autowired
private IUserDeregisterService userDeregisterService; private IUserDeregisterService userDeregisterService;
@Autowired @Autowired
...@@ -130,13 +126,7 @@ public class InnerController implements IBaseController { ...@@ -130,13 +126,7 @@ public class InnerController implements IBaseController {
if (user == null) { if (user == null) {
return JsonResult.buildErrorStateResult("查无此人", null, 4L); return JsonResult.buildErrorStateResult("查无此人", null, 4L);
} }
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
// userId 查询对应productLogin 获取手机号和customerId
user = tenantService.getTenantUser(user, tenantId);
if (user == null) {
return JsonResult.buildErrorStateResult("查无此人", null, 4L);
}
}
return JsonResult.buildSuccessResult("", new UserRet(user)); return JsonResult.buildSuccessResult("", new UserRet(user));
} }
...@@ -150,14 +140,6 @@ public class InnerController implements IBaseController { ...@@ -150,14 +140,6 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("查无此人", null); return JsonResult.buildErrorStateResult("查无此人", null);
} }
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
// userId 查询对应productLogin 获取手机号和customerId
user = tenantService.getTenantUser(user, tenantId);
if (user == null) {
return JsonResult.buildErrorStateResult("查无此人", null);
}
}
return JsonResult.buildSuccessResult("", new UserRet(user)); return JsonResult.buildSuccessResult("", new UserRet(user));
} }
...@@ -254,16 +236,13 @@ public class InnerController implements IBaseController { ...@@ -254,16 +236,13 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult(USER_ERROR_OR_ENABLE_ERROR, null); return JsonResult.buildErrorStateResult(USER_ERROR_OR_ENABLE_ERROR, null);
} }
// 插入关联数据
iOauthLoginInfoService.addLoginInfo(user, tenantId);
//已存在用户 //已存在用户
return JsonResult.buildSuccessResult(null, new UserRet(user)); return JsonResult.buildSuccessResult(null, new UserRet(user));
} }
//注册新用户 //注册新用户
user = userRegisterService.register(registeredFrom, phoneNo, null, 0L, 0L, tenantId); user = userRegisterService.register(registeredFrom, phoneNo, null, 0L, 0L, tenantId);
//校验租户ID tenantId
iOauthLoginInfoService.addLoginInfo(user, tenantId);
return JsonResult.buildSuccessResult(null, new UserRet(user)); return JsonResult.buildSuccessResult(null, new UserRet(user));
} }
...@@ -351,12 +330,6 @@ public class InnerController implements IBaseController { ...@@ -351,12 +330,6 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("该用户无实名信息", null); return JsonResult.buildErrorStateResult("该用户无实名信息", null);
} }
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
userDetail = tenantService.getTenantUserDetail(userDetail, tenantId);
if (userDetail == null) {
return JsonResult.buildErrorStateResult("该用户详情信息不存在", null);
}
}
return JsonResult.buildSuccessResult("用户实名信息", UserDetailRet.getUserDetail(userDetail)); return JsonResult.buildSuccessResult("用户实名信息", UserDetailRet.getUserDetail(userDetail));
} }
...@@ -366,17 +339,9 @@ public class InnerController implements IBaseController { ...@@ -366,17 +339,9 @@ public class InnerController implements IBaseController {
@RequestMapping("/user/search/userId") @RequestMapping("/user/search/userId")
public JsonResult findUserByUserId(Long userId, Integer tenantId) { public JsonResult findUserByUserId(Long userId, Integer tenantId) {
User user = userService.findById(userId); User user = userService.findById(userId);
if (user != null) {
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
// userId 查询对应productLogin 获取手机号和customerId
user = tenantService.getTenantUser(user, tenantId);
if (user != null) { if (user != null) {
return JsonResult.buildSuccessResult(null, new UserRet(user)); return JsonResult.buildSuccessResult(null, new UserRet(user));
} }
}else{
return JsonResult.buildSuccessResult(null, new UserRet(user));
}
}
return JsonResult.buildErrorStateResult("查无此人", null); return JsonResult.buildErrorStateResult("查无此人", null);
} }
...@@ -390,12 +355,6 @@ public class InnerController implements IBaseController { ...@@ -390,12 +355,6 @@ public class InnerController implements IBaseController {
UserDetail userDetail = null; UserDetail userDetail = null;
userDetail = userDetailService.findSlaveByPhoneNo(phoneNo); userDetail = userDetailService.findSlaveByPhoneNo(phoneNo);
if (userDetail != null) { if (userDetail != null) {
if (tenantId != null && !TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
userDetail = tenantService.getTenantUserDetail(userDetail, tenantId);
if (userDetail == null) {
return JsonResult.buildErrorStateResult("该用户详情信息不存在", null);
}
}
return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail)); return JsonResult.buildSuccessResult(null, UserDetailRet.getUserDetail(userDetail));
} }
......
package cn.quantgroup.xyqb.controller.middleoffice.wx; package cn.quantgroup.xyqb.controller.middleoffice.wx;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.WechatUserInfo; import cn.quantgroup.xyqb.entity.WechatUserInfo;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
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.service.wechat.IWechatService; import cn.quantgroup.xyqb.service.wechat.IWechatService;
import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -28,9 +24,6 @@ public class WxController { ...@@ -28,9 +24,6 @@ public class WxController {
@Resource @Resource
private IWechatService wechatService; private IWechatService wechatService;
@Autowired
private ITenantService tenantService;
@Autowired @Autowired
private IUserService userService; private IUserService userService;
...@@ -43,20 +36,10 @@ public class WxController { ...@@ -43,20 +36,10 @@ public class WxController {
@GetMapping("/userId/{userId}") @GetMapping("/userId/{userId}")
public JsonResult openId(@PathVariable Long userId, @RequestParam(required = false) Integer tenantId) { public JsonResult openId(@PathVariable Long userId, @RequestParam(required = false) Integer tenantId) {
String openId = null; String openId = null;
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId) || tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId); WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
if (wechatUserInfo != null) { if (wechatUserInfo != null) {
openId = wechatUserInfo.getOpenId(); openId = wechatUserInfo.getOpenId();
} }
} else {
User user = userService.findById(userId);
if (user != null) {
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo != null) {
openId = tenantCustomerInfo.getSourceOpenId();
}
}
}
return JsonResult.buildSuccessResultGeneric(openId); return JsonResult.buildSuccessResultGeneric(openId);
} }
...@@ -69,28 +52,11 @@ public class WxController { ...@@ -69,28 +52,11 @@ public class WxController {
*/ */
@GetMapping("/userId/{userId}/{appName}") @GetMapping("/userId/{userId}/{appName}")
public JsonResult openId(@PathVariable Long userId, @PathVariable String appName, @RequestParam(required = false) Integer tenantId) { public JsonResult openId(@PathVariable Long userId, @PathVariable String appName, @RequestParam(required = false) Integer tenantId) {
//默认羊小咩租户
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId, appName); WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId, appName);
if (wechatUserInfo == null) { if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult(); return JsonResult.buildSuccessResult();
} }
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId()); return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
} else {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
} }
/** /**
...@@ -101,26 +67,12 @@ public class WxController { ...@@ -101,26 +67,12 @@ public class WxController {
*/ */
@GetMapping("/phoneNo/{phoneNo}") @GetMapping("/phoneNo/{phoneNo}")
public JsonResult openId(@PathVariable String phoneNo, @RequestParam(required = false) Integer tenantId) { public JsonResult openId(@PathVariable String phoneNo, @RequestParam(required = false) Integer tenantId) {
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
if (tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo); WechatUserInfo wechatUserInfo = wechatService.findWechatUserInfoByPhoneNo(phoneNo);
if (wechatUserInfo == null) { if (wechatUserInfo == null) {
return JsonResult.buildSuccessResult(); return JsonResult.buildSuccessResult();
} }
return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId()); return JsonResult.buildSuccessResultGeneric(wechatUserInfo.getOpenId());
} else {
User user = userService.findByPhoneInDb(phoneNo);
if (user == null) {
return JsonResult.buildSuccessResult();
}
CustomerInfoEntity tenantCustomerInfo = tenantService.getTenantCustomerInfo(user, tenantId);
if (tenantCustomerInfo == null) {
return JsonResult.buildSuccessResult();
}
return JsonResult.buildSuccessResultGeneric(tenantCustomerInfo.getSourceOpenId());
}
} }
@RequestMapping("/code/{key}/{extdata}") @RequestMapping("/code/{key}/{extdata}")
......
package cn.quantgroup.xyqb.controller.tenant;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/tenant")
public class TenantController {
@Autowired
private IProductLoginService productLoginService;
@Autowired
private IOauthClientDetailsService oauthClientDetailsService;
@Autowired
private IUserService userService;
/**
* 根据用户ID查询租户列表
* @param userId
* @return
* @Yapi http://yapi.quantgroups.com/project/17/interface/api/30068
*/
@PostMapping("/userIdTenantList")
public JsonResult findTenantByUserId(Long userId) {
// 通过userId获取租户机构和产品
List<ProductLoginEntity> productLoginEntityList = productLoginService.findSlaveByUserId(userId);
List<Integer> tenantList = new ArrayList<>();
if (!productLoginEntityList.isEmpty()) {
// 通过机构和产品Id 获取租户id
tenantList = oauthClientDetailsService.findTenantList(productLoginEntityList);
}
if (tenantList.isEmpty()) {
User user = userService.findById(userId);
if (user == null) {
return JsonResult.buildErrorStateResult("该用户不存在", null);
}
tenantList.add(TenantUtil.TENANT_DEFAULT);
}
return JsonResult.buildSuccessResult("租户列表", tenantList);
}
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.baseEntity.PartitionEntity;
import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.util.StringUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
* Created with IntelliJ IDEA.
*
* @author: Li JianHua
* @Date: 2021/9/23
* @Time: 11:02
* Description: No Description
*/
@Entity
@Table(name = "customer_info")
public class CustomerInfoEntity extends PartitionEntity implements Serializable {
private static final long serialVersionUID = -3639362579605273102L;
private final static String CLASS_NAME = CustomerInfoEntity.class.getSimpleName();
@Id
@Column(name = "ID", nullable = false)
// @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "CUSTOMER_ID", nullable = false)
private long customerId;
@Column(name = "INSTITUTION_ID", nullable = false, length = 4)
private String institutionId;
@Column(name = "AVATAR_URL", nullable = true, length = 255)
private String avatarUrl;
@Column(name = "NICK_NAME", nullable = true, length = 50)
private String nickName;
@Column(name = "APP_NAME", nullable = true, length = 50)
private String appName;
@Column(name = "CITY", nullable = true, length = 36)
private String city;
@Column(name = "CITY_CODE", nullable = true)
private Long cityCode;
@Column(name = "COUNTRY", nullable = true, length = 50)
private String country;
@Column(name = "LANGUAGE", nullable = true, length = 30)
private String language;
@Column(name = "SOURCE_OPEN_ID", nullable = true, length = 128)
private String sourceOpenId;
@Column(name = "PRIVILEAGE", nullable = true, length = 255)
private String privileage;
@Column(name = "PROVINCE", nullable = true, length = 30)
private String province;
@Column(name = "PROVINCE_CODE", nullable = true)
private Long provinceCode;
@Column(name = "SEX", nullable = true)
private Gender sex;
@Column(name = "UNION_ID", nullable = true, length = 128)
private String unionId;
@Column(name = "UTM_SOURCE", nullable = true, length = 50)
private String utmSource;
@Column(name = "NAME", nullable = true, length = 50)
private String name;
@Column(name = "ID_CARD_NO", nullable = true, length = 32)
private String idCardNo;
@Column(name = "ID_CARD_TYPE", nullable = true)
private Byte idCardType;
@Column(name = "BIRTHDAY", nullable = true, length = 30)
private String birthday;
@Column(name = "PRODUCT_ID", nullable = false)
private String productId;
@Column(name = "SOURCE_TYPE", nullable = true, length = 255)
private String sourceType;
@Column(name = "TELEPHONE", nullable = true, length = 32)
private String telephone;
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Long getCityCode() {
return cityCode;
}
public void setCityCode(Long cityCode) {
this.cityCode = cityCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getSourceOpenId() {
return sourceOpenId;
}
public void setSourceOpenId(String sourceOpenId) {
this.sourceOpenId = sourceOpenId;
}
public String getPrivileage() {
return privileage;
}
public void setPrivileage(String privileage) {
this.privileage = privileage;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public Long getProvinceCode() {
return provinceCode;
}
public void setProvinceCode(Long provinceCode) {
this.provinceCode = provinceCode;
}
public Gender getSex() {
return sex;
}
public void setSex(Gender sex) {
this.sex = sex;
}
public String getUnionId() {
return unionId;
}
public void setUnionId(String unionId) {
this.unionId = unionId;
}
public String getUtmSource() {
return utmSource;
}
public void setUtmSource(String utmSource) {
this.utmSource = utmSource;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdCardNo() {
return idCardNo;
}
public void setIdCardNo(String idCardNo) {
this.idCardNo = idCardNo;
}
public Byte getIdCardType() {
return idCardType;
}
public void setIdCardType(Byte idCardType) {
this.idCardType = idCardType;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getSourceType() {
return sourceType;
}
public void setSourceType(String sourceType) {
this.sourceType = sourceType;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
@Override
public String getPersistentKey() {
return StringUtils.toDelimitedString(CLASS_NAME, customerId, institutionId);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.baseEntity.PartitionEntity;
import cn.quantgroup.xyqb.util.StringUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;
/**
* Created with IntelliJ IDEA.
*
* @author: Li JianHua
* @Date: 2021/9/23
* @Time: 11:02
* Description: No Description
*/
@Entity
@Table(name = "customer_login")
public class CustomerLoginEntity extends PartitionEntity implements Serializable {
private static final long serialVersionUID = -6859480785575072675L;
private final static String CLASS_NAME = CustomerLoginEntity.class.getSimpleName();
@Id
@Column(name = "ID", nullable = false)
// @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "INSTITUTION_ID", nullable = false, length = 4)
private String institutionId;
@Column(name = "PRODUCT_ID", nullable = false, length = 4)
private String productId;
@Column(name = "CUSTOMER_ID", nullable = false)
private long customerId;
@Column(name = "UUID", nullable = true)
private Long uuid;
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customerId) {
this.customerId = customerId;
}
public Long getUuid() {
return uuid;
}
public void setUuid(Long uuid) {
this.uuid = uuid;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CustomerLoginEntity that = (CustomerLoginEntity) o;
return customerId == that.customerId;
}
@Override
public int hashCode() {
return Objects.hash(institutionId, productId, customerId, uuid);
}
@Override
public String getPersistentKey() {
return StringUtils.toDelimitedString(CLASS_NAME, institutionId, productId, customerId);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
package cn.quantgroup.xyqb.entity;
import java.util.Date;
/**
* Created by Administrator on 2021/8/27 0027.
*/
public class EntityBuilder {
public static ProductLoginEntity productLogin(String productId, String institutionId, String phoneNo,
Long customerId, String customerName, Integer partitionKey, Long id) {
ProductLoginEntity entity = new ProductLoginEntity();
// entity.setId(id);
entity.setCustomerId(customerId);
entity.setCustomerName(customerName);
entity.setPhoneNo(phoneNo);
entity.setProductId(productId);
entity.setInstitutionId(institutionId);
entity.setPartitionKey(partitionKey);
entity.setPassword("");
entity.setSaltValue("");
entity.setStatus("");
entity.setBatchNo(1);
entity.setCreatedDate(new Date());
entity.setModifiedDate(new Date());
entity.setCreatedBy("");
entity.setModifiedBy("");
return entity;
}
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.baseEntity.OptimisticEntity;
import cn.quantgroup.xyqb.util.StringUtils;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;
/**
* Created with IntelliJ IDEA.
*
* @author: Li JianHua
* @Date: 2021/9/23
* @Time: 11:02
* Description: No Description
*/
@Entity
@Table(name = "oauth_client_details")
public class OauthClientDetailsEntity extends OptimisticEntity implements Serializable {
private static final long serialVersionUID = 3521505570429896355L;
private final static String CLASS_NAME = OauthClientDetailsEntity.class.getSimpleName();
@Id
@Column(name = "CLIENT_ID", nullable = false)
private Integer clientId;
@Column(name = "INSTITUTION_ID", nullable = false, length = 4)
private String institutionId;
@Column(name = "PRODUCT_ID", nullable = false, length = 4)
private String productId;
@Column(name = "ENCRYPTION_TYPE", nullable = false, length = 4)
private String encryptionType;
@Column(name = "ENABLE", nullable = false, length = 4)
private String enable;
@Column(name = "RESOURCE_IDS", nullable = true, length = 255)
private String resourceIds;
@Column(name = "CLIENT_SECRET", nullable = false, length = 255)
private String clientSecret;
@Column(name = "SCOPE", nullable = true, length = 255)
private String scope;
@Column(name = "AUTHORIZED_GRANT_TYPES", nullable = true, length = 255)
private String authorizedGrantTypes;
@Column(name = "WEB_SERVER_REDIRECT_URI", nullable = true, length = 255)
private String webServerRedirectUri;
@Column(name = "AUTHORITIES", nullable = true, length = 255)
private String authorities;
@Column(name = "ACCESS_TOKEN_VALIDITY", nullable = true)
private Integer accessTokenValidity;
@Column(name = "REFRESH_TOKEN_VALIDITY", nullable = true)
private Integer refreshTokenValidity;
@Column(name = "ADDITIONAL_INFORMATION", nullable = true, length = 4096)
private String additionalInformation;
@Column(name = "AUTOAPPROVE", nullable = true, length = 255)
private String autoapprove;
@Column(name = "SMS_REGISTER_TEMPLATE", nullable = true, length = 255)
private String smsRegisterTemplate;
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getEncryptionType() {
return encryptionType;
}
public void setEncryptionType(String encryptionType) {
this.encryptionType = encryptionType;
}
public String getEnable() {
return enable;
}
public void setEnable(String enable) {
this.enable = enable;
}
public String getResourceIds() {
return resourceIds;
}
public void setResourceIds(String resourceIds) {
this.resourceIds = resourceIds;
}
public String getClientSecret() {
return clientSecret;
}
public void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getAuthorizedGrantTypes() {
return authorizedGrantTypes;
}
public void setAuthorizedGrantTypes(String authorizedGrantTypes) {
this.authorizedGrantTypes = authorizedGrantTypes;
}
public String getWebServerRedirectUri() {
return webServerRedirectUri;
}
public void setWebServerRedirectUri(String webServerRedirectUri) {
this.webServerRedirectUri = webServerRedirectUri;
}
public String getAuthorities() {
return authorities;
}
public void setAuthorities(String authorities) {
this.authorities = authorities;
}
public Integer getAccessTokenValidity() {
return accessTokenValidity;
}
public void setAccessTokenValidity(Integer accessTokenValidity) {
this.accessTokenValidity = accessTokenValidity;
}
public Integer getRefreshTokenValidity() {
return refreshTokenValidity;
}
public void setRefreshTokenValidity(Integer refreshTokenValidity) {
this.refreshTokenValidity = refreshTokenValidity;
}
public String getAdditionalInformation() {
return additionalInformation;
}
public void setAdditionalInformation(String additionalInformation) {
this.additionalInformation = additionalInformation;
}
public String getAutoapprove() {
return autoapprove;
}
public void setAutoapprove(String autoapprove) {
this.autoapprove = autoapprove;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OauthClientDetailsEntity that = (OauthClientDetailsEntity) o;
return Objects.equals(clientId, that.clientId) && Objects.equals(institutionId, that.institutionId) && Objects.equals(productId, that.productId) && Objects.equals(encryptionType, that.encryptionType) && Objects.equals(enable, that.enable) && Objects.equals(resourceIds, that.resourceIds) && Objects.equals(clientSecret, that.clientSecret) && Objects.equals(scope, that.scope) && Objects.equals(authorizedGrantTypes, that.authorizedGrantTypes) && Objects.equals(webServerRedirectUri, that.webServerRedirectUri) && Objects.equals(authorities, that.authorities) && Objects.equals(accessTokenValidity, that.accessTokenValidity) && Objects.equals(refreshTokenValidity, that.refreshTokenValidity) && Objects.equals(additionalInformation, that.additionalInformation) && Objects.equals(autoapprove, that.autoapprove);
}
@Override
public int hashCode() {
return Objects.hash(clientId, institutionId, productId, encryptionType, enable, resourceIds, clientSecret, scope, authorizedGrantTypes, webServerRedirectUri, authorities, accessTokenValidity, refreshTokenValidity, additionalInformation, autoapprove);
}
@Override
public String getPersistentKey() {
return StringUtils.toDelimitedString(CLASS_NAME, clientId);
}
public String getSmsRegisterTemplate() {
return smsRegisterTemplate;
}
public void setSmsRegisterTemplate(String smsRegisterTemplate) {
this.smsRegisterTemplate = smsRegisterTemplate;
}
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.xyqb.entity.baseEntity.PartitionEntity;
import cn.quantgroup.xyqb.entity.converter.EncryptConverter;
import cn.quantgroup.xyqb.util.StringUtils;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Objects;
/**
* Created with IntelliJ IDEA.
*
* @author: Li JianHua
* @Date: 2021/9/23
* @Time: 11:03
* Description: No Description
*/
@Entity
@Table(name = "product_login")
public class ProductLoginEntity extends PartitionEntity implements Serializable {
private static final long serialVersionUID = 6495491112527859057L;
private final static String CLASS_NAME = ProductLoginEntity.class.getSimpleName();
@Id
@Column(name = "ID", nullable = false)
// @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "CUSTOMER_ID", nullable = false)
private long customerId;
@Column(name = "CUSTOMER_NAME", nullable = false, length = 255)
private String customerName;
@Column(name = "INSTITUTION_ID", nullable = false, length = 4)
private String institutionId;
@Column(name = "PHONE_NO", nullable = false, length = 15)
private String phoneNo;
@Column(name = "PASSWORD", nullable = true, length = 256)
private String password;
@Column(name = "SALT_VALUE", nullable = true, length = 128)
private String saltValue;
@Column(name = "STATUS", nullable = false, length = 4)
private String status;
@Column(name = "STATUS_DATE", nullable = false)
private LocalDate statusDate;
@Column(name = "LAST_STATUS", nullable = true, length = 4)
private String lastStatus;
@Column(name = "LAST_LOGIN_TIME", nullable = true)
private Integer lastLoginTime;
@Column(name = "BATCH_NO", nullable = true)
private Integer batchNo;
@Column(name = "PRODUCT_ID", nullable = false, length = 4)
private String productId;
@Column(name = "EXTENSION_ACCOUNT_ID", nullable = true)
private Long extensionAccountId;
@Column(name = "encrypted_phone_no")
@Convert(converter = EncryptConverter.class)
private String encryptedPhoneNo;
public long getCustomerId() {
return customerId;
}
public void setCustomerId(long customrId) {
this.customerId = customrId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getInstitutionId() {
return institutionId;
}
public void setInstitutionId(String institutionId) {
this.institutionId = institutionId;
}
public String getPhoneNo() {
return getEncryptedPhoneNo();
}
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSaltValue() {
return saltValue;
}
public void setSaltValue(String saltValue) {
this.saltValue = saltValue;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public LocalDate getStatusDate() {
return statusDate;
}
public void setStatusDate(LocalDate statusDate) {
this.statusDate = statusDate;
}
public String getLastStatus() {
return lastStatus;
}
public void setLastStatus(String lastStatus) {
this.lastStatus = lastStatus;
}
public Integer getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Integer lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public Long getExtensionAccountId() {
return extensionAccountId;
}
public void setExtensionAccountId(Long extensionAccountId) {
this.extensionAccountId = extensionAccountId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProductLoginEntity that = (ProductLoginEntity) o;
return customerId == that.customerId && statusDate == that.statusDate&& Objects.equals(customerName, that.customerName) && Objects.equals(institutionId, that.institutionId) && Objects.equals(phoneNo, that.phoneNo) && Objects.equals(password, that.password) && Objects.equals(saltValue, that.saltValue) && Objects.equals(status, that.status) && Objects.equals(lastStatus, that.lastStatus) && Objects.equals(lastLoginTime, that.lastLoginTime) && Objects.equals(productId, that.productId) && Objects.equals(extensionAccountId, that.extensionAccountId);
}
@Override
public int hashCode() {
return Objects.hash(customerId, customerName, institutionId, phoneNo, password, saltValue, status, statusDate, lastStatus, lastLoginTime, productId, extensionAccountId);
}
@Override
public String getPersistentKey() {
return StringUtils.toDelimitedString(CLASS_NAME, institutionId, productId, phoneNo);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Integer getBatchNo() {
return batchNo;
}
public void setBatchNo(Integer batchNo) {
this.batchNo = batchNo;
}
public String getEncryptedPhoneNo() {
return org.apache.commons.lang.StringUtils.isBlank(encryptedPhoneNo) ? phoneNo : encryptedPhoneNo;
}
public void setEncryptedPhoneNo(String encryptedPhoneNo) {
this.encryptedPhoneNo = encryptedPhoneNo;
}
}
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by Li Jianhua
*/
@Repository
public interface ICustomerInfoRepository extends JpaRepository<CustomerInfoEntity, Long> {
CustomerInfoEntity findByCustomerId(Long customerId);
CustomerInfoEntity findByInstitutionIdAndProductIdAndSourceOpenId(String institutionId, String productId, String OpenId);
}
\ No newline at end of file
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.CustomerLoginEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by hechao on 2020/2/17.
*/
@Repository
public interface ICustomerLoginRepository extends JpaRepository<CustomerLoginEntity, Long> {
CustomerLoginEntity findFirstByCustomerId(long customerId);
}
\ No newline at end of file
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by hechao on 2020/2/17.
*/
@Repository
public interface IOauthClientDetailsRepository extends JpaRepository<OauthClientDetailsEntity, Long> {
OauthClientDetailsEntity findFirstByClientId(Integer clientID);
OauthClientDetailsEntity findFirstByInstitutionIdAndProductId(String institutionId, String productId);
}
\ No newline at end of file
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
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.transaction.annotation.Transactional;
import java.util.List;
/**
* Li Jianhua
*/
@Repository
public interface IProductLoginRepository extends JpaRepository<ProductLoginEntity, Long> {
ProductLoginEntity findFirstByInstitutionIdAndProductIdAndPhoneNo(String institutionId, String productId, String phoneNo);
ProductLoginEntity findFirstByInstitutionIdAndProductIdAndEncryptedPhoneNo(String institutionId, String productId, String phoneNo);
ProductLoginEntity findFirstByPhoneNo(String phoneNo);
ProductLoginEntity findByInstitutionIdAndProductIdAndExtensionAccountId(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findByInstitutionIdAndProductIdAndExtensionAccountIdIn(String institutionId, String productId, List<Long> userIds);
List<ProductLoginEntity> findAllByExtensionAccountId(Long userId);
List<ProductLoginEntity> findAllByExtensionAccountIdIn(List<Long> userId);
/**
* @author -REYLI
* @createTime 2021-11-17
* @description 根据条件获取租户下用户列表
* @param institutionId
* @param productId
* @return Arraylist
*/
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
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
...@@ -11,11 +11,6 @@ import java.util.List; ...@@ -11,11 +11,6 @@ import java.util.List;
public interface IWeChatInfoRelationRepository extends JpaRepository<WechatInfoRelation, Long> { public interface IWeChatInfoRelationRepository extends JpaRepository<WechatInfoRelation, Long> {
@Transactional(rollbackFor = Exception.class)
@Modifying
@Query(value = "update wechat_info_relation as wir set wir.is_follow_wechat = 1 where wir.open_id IN (?1)", nativeQuery = true)
void updateIsFollowWechatInOpenIdList(List<String> openIdList);
List<WechatInfoRelation> findByUnionIdInAndTaskPeriodAndType(List<String> unionIdList, String period, Integer type); List<WechatInfoRelation> findByUnionIdInAndTaskPeriodAndType(List<String> unionIdList, String period, Integer type);
} }
...@@ -9,10 +9,7 @@ import cn.quantgroup.xyqb.exception.AppletException; ...@@ -9,10 +9,7 @@ import cn.quantgroup.xyqb.exception.AppletException;
import cn.quantgroup.xyqb.repository.IWeChatUserRepository; 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.ITenantService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -39,11 +36,6 @@ public class AppletServiceImpl implements IAppletService { ...@@ -39,11 +36,6 @@ public class AppletServiceImpl implements IAppletService {
private final IUserService userService; private final IUserService userService;
private ILoginModule loginModule; private ILoginModule loginModule;
@Autowired
private IOauthLoginInfoService iOauthLoginInfoService;
@Autowired
private ITenantService tenantService;
@Autowired @Autowired
public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository, public AppletServiceImpl(IWeChatUserRepository iWeChatUserRepository,
...@@ -59,11 +51,6 @@ public class AppletServiceImpl implements IAppletService { ...@@ -59,11 +51,6 @@ 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 = iWeChatUserRepository.findByOpenIdAndAppName(appletParamEntry.getOpenId(), appletParamEntry.getAppName());
//这个接口先不考虑更换手机号的情况 //这个接口先不考虑更换手机号的情况
...@@ -91,51 +78,29 @@ public class AppletServiceImpl implements IAppletService { ...@@ -91,51 +78,29 @@ public class AppletServiceImpl implements IAppletService {
log.warn("已冻结 userId--{}", user.getId()); log.warn("已冻结 userId--{}", user.getId());
throw new AppletException(USER_FREEZE_ERROR, "0402"); throw new AppletException(USER_FREEZE_ERROR, "0402");
} }
iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
wechatUserInfo.setUserId(user.getId()); wechatUserInfo.setUserId(user.getId());
} }
//如果存在就更新在微信表里 //如果存在就更新在微信表里
iWeChatUserRepository.save(wechatUserInfo); iWeChatUserRepository.save(wechatUserInfo);
return wechatUserInfo.getUserId(); return wechatUserInfo.getUserId();
} else {
User user = userService.findByPhoneInDb(appletParamEntry.getMobile());
//如果不存在就去注册一下
if (null == user) {
user = iUserRegisterService.register(appletParamEntry.getChannelId(), appletParamEntry.getMobile(), appletParamEntry.getTenantId());
}
if (!user.getEnable()) {
log.warn("已冻结 userId--{}", user.getId());
throw new AppletException(USER_FREEZE_ERROR, "0402");
}
iOauthLoginInfoService.addRegisterInfo(user, appletParamEntry);
return user.getId();
}
} }
@Override @Override
public LoginVo login(String appName, String openId, Integer tenantId, String utmSource, String unionId) { public LoginVo login(String appName, String openId, Integer tenantId, String utmSource, String unionId) {
if (TenantUtil.validationTenantIdIsNullOrZero(tenantId)) {
tenantId = TenantUtil.TENANT_DEFAULT;
}
User user = null;
if (TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName); WechatUserInfo wechatUserInfo = iWeChatUserRepository.findByOpenIdAndAppName(openId, appName);
if (null == wechatUserInfo) { if (null == wechatUserInfo) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId); log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户","0401"); throw new AppletException("未找到此用户", "0401");
} }
if (null == wechatUserInfo.getUserId()) { if (null == wechatUserInfo.getUserId()) {
log.warn("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId); log.warn("用户未绑定到xyqb,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户绑定信息","0401"); throw new AppletException("未找到此用户绑定信息", "0401");
} }
user = userService.findById(wechatUserInfo.getUserId()); User user = userService.findById(wechatUserInfo.getUserId());
if (null == user ) { if (null == user) {
log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId); log.warn("未找到此用户,appName:{} ,openId:{}", appName, openId);
throw new AppletException("未找到此用户", "0401"); throw new AppletException("未找到此用户", "0401");
} }
...@@ -145,34 +110,12 @@ public class AppletServiceImpl implements IAppletService { ...@@ -145,34 +110,12 @@ public class AppletServiceImpl implements IAppletService {
throw new AppletException(USER_FREEZE_ERROR, "0402"); throw new AppletException(USER_FREEZE_ERROR, "0402");
} }
iOauthLoginInfoService.addLoginInfo(user, tenantId); if (unionId != null && !unionId.equals(wechatUserInfo.getUnionId())) {
if (unionId != null && !unionId.equals(wechatUserInfo.getUnionId()) ) {
iWeChatUserRepository.updateUserUnionId(wechatUserInfo.getUserId(), appName, unionId); iWeChatUserRepository.updateUserUnionId(wechatUserInfo.getUserId(), appName, unionId);
} }
} else { return loginModule.loginByUserId(user.getRegisteredFrom(),
// 通过租户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");
}
if (!user.getEnable()) {
log.warn("已冻结,appName:{} ,openId:{}", appName, openId);
throw new AppletException(USER_FREEZE_ERROR, "0402");
}
}
LoginVo loginVo = loginModule.loginByUserId(user.getRegisteredFrom(),
utmSource == null ? "" : utmSource, user.getId(), tenantId); utmSource == null ? "" : utmSource, user.getId(), tenantId);
return loginVo;
} }
......
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
/**
* Created by 11 on 2016/12/29.
*/
public interface ICustomerInfoService {
CustomerInfoEntity findSlaveByCustomerId(Long customerId);
CustomerInfoEntity findSlaveByOpenId(String openId, String institutionId, String productId);
}
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.CustomerLoginEntity;
/**
* Created by 11 on 2016/12/29.
*/
public interface ICustomerLoginService {
CustomerLoginEntity findSlaveByCustomerId(Long customerId);
}
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/**
* Created by Miraculous on 2017/1/3.
*/
public interface IOauthClientDetailsService {
OauthClientDetailsEntity findFirstByClientId(Integer clientId);
List<Integer> findTenantList(List<ProductLoginEntity> productLoginEntityList);
}
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;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
public interface IProductLoginService {
ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId);
List<ProductLoginEntity> findSlaveByProductLoginInfoList(String institutionId, String productId, List<Long> userId);
List<ProductLoginEntity> findSlaveByUserId(Long userId);
List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds);
/**
* @author -REYLI
* @createTime 2021-11-17
* @description 根据条件获取租户下用户列表
* @param institutionId
* @param productId
* @return Arraylist
*/
List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId);
ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId);
ProductLoginEntity findTenantAndPhoneNo(String institutionId, String productId, String phoneNo);
}
package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.UserBrief;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
public interface ITenantService {
User getTenantUser(User user, Integer tenantId);
UserDetail getTenantUserDetail(UserDetail userDetail, Integer tenantId);
UserBrief getTenantCustomerInfo(UserDetail userDetail, Integer tenantId);
CustomerInfoEntity getTenantCustomerInfo(User user, Integer tenantId);
/**
* @author -REYLI
* @createTime 2021-11-17
* @description 根据条件获取租户下用户列表
* @param users
* @param tenantId
* @return Arraylist
*/
List<User> selectUsersByTenantId(List<User> users, Integer tenantId);
Long getTenantCustomerInfoByOpenId(String openId, Integer tenantId);
List<User> validationTentIdByTentId(List<User> users, Integer tenantId);
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
import cn.quantgroup.xyqb.repository.ICustomerInfoRepository;
import cn.quantgroup.xyqb.service.user.ICustomerInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class CustomerInfoServiceImpl implements ICustomerInfoService {
@Autowired
private ICustomerInfoRepository customerInfoRepository;
@Override
public CustomerInfoEntity findSlaveByCustomerId(Long customerId) {
CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(customerId);
return customerInfo;
}
@Override
public CustomerInfoEntity findSlaveByOpenId(String openId, String institutionId, String productId) {
CustomerInfoEntity customerInfo = customerInfoRepository.findByInstitutionIdAndProductIdAndSourceOpenId(institutionId, productId, openId);
return customerInfo;
}
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.CustomerLoginEntity;
import cn.quantgroup.xyqb.repository.ICustomerLoginRepository;
import cn.quantgroup.xyqb.service.user.ICustomerLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class CustomerLoginServiceImpl implements ICustomerLoginService {
@Autowired
private ICustomerLoginRepository customerLoginRepository;
@Override
public CustomerLoginEntity findSlaveByCustomerId(Long customerId) {
CustomerLoginEntity customerLogin = customerLoginRepository.findFirstByCustomerId(customerId);
return customerLogin;
}
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.OauthClientDetailsEntity;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.repository.IOauthClientDetailsRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class OauthClientDetailsServiceImpl implements IOauthClientDetailsService {
@Autowired
private final IOauthClientDetailsRepository oauthClientDetailsRepository;
private final LoadingCache<Integer, OauthClientDetailsEntity> cache;
public OauthClientDetailsServiceImpl(IOauthClientDetailsRepository oauthClientDetailsRepository) {
this.oauthClientDetailsRepository = oauthClientDetailsRepository;
cache = Caffeine.newBuilder()
.expireAfterWrite(8, TimeUnit.HOURS)
.maximumSize(1_000)
.build(this.oauthClientDetailsRepository::findFirstByClientId);
}
@Override
public OauthClientDetailsEntity findFirstByClientId(Integer clientId) {
return cache.get(clientId);
}
@Override
public List<Integer> findTenantList(List<ProductLoginEntity> productLoginEntityList) {
List<Integer> tenantList = new ArrayList<>();
for (ProductLoginEntity ple : productLoginEntityList) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsRepository.findFirstByInstitutionIdAndProductId(ple.getInstitutionId(), ple.getProductId());
if (null != oauthClientDetails) {
tenantList.add(oauthClientDetails.getClientId());
}
}
return tenantList;
}
}
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;
import cn.quantgroup.xyqb.repository.IProductLoginRepository;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
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.RandomSequencer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class OauthLoginInfoServiceImpl implements IOauthLoginInfoService {
@Autowired
private IOauthClientDetailsService oauthClientDetailsService;
@Autowired
private IProductLoginRepository productLoginRepository;
@Autowired
private ICustomerInfoRepository customerInfoRepository;
@Autowired
private ICustomerLoginRepository customerLoginRepository;
@Autowired
private IProductLoginService productLoginService;
@Autowired
private AtomicSequencer atomicSequencer;
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void addLoginInfo(User user, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId();
String phoneNo = user.getPhoneNo();
Long userId = user.getId();
ProductLoginEntity findProductLoginEntity = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId);
ProductLoginEntity findProductLoginByPhoneEntity = productLoginService.findTenantAndPhoneNo(institutionId, productId, phoneNo);
long uuid = 0L;
if (findProductLoginEntity == null && findProductLoginByPhoneEntity == null) {
// 添加用户到产品登录表
long customerId = atomicSequencer.nextId();
// long id = session.nextId();
long id = atomicSequencer.nextId();
String customerName = customerId + "";
uuid = RandomSequencer.randomUUID(customerId);
Integer partitionKey = atomicSequencer.partitionKey(customerId);
ProductLoginEntity productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId);
productLoginEntity.setEncryptedPhoneNo(phoneNo);
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.setProductId(productId);
customerInfo.setPartitionKey(partitionKey);
customerInfo.setCreatedDate(new Date());
customerInfo.setModifiedDate(new Date());
customerInfo.setCreatedBy("");
customerInfo.setModifiedBy("");
customerInfoRepository.save(customerInfo);
}
}
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addRegisterInfo(User user, AppletParamEntry appletParamEntry) {
OauthClientDetailsEntity oauthClientDetailsEntity = oauthClientDetailsService.findFirstByClientId(appletParamEntry.getTenantId());
if (oauthClientDetailsEntity != null) {
String institutionId = oauthClientDetailsEntity.getInstitutionId();
String productId = oauthClientDetailsEntity.getProductId();
String phoneNo = user.getPhoneNo();
Long userId = user.getId();
ProductLoginEntity productLoginEntity = productLoginService.findTenantAndPhoneNo(institutionId, productId, phoneNo);
long uuid = 0L;
// 如果找不到该用户就创建
if (productLoginEntity == null) {
// 添加用户到产品登录表
long customerId = atomicSequencer.nextId();
long id = atomicSequencer.nextId();
String customerName = customerId + "";
uuid = RandomSequencer.randomUUID(customerId);
Integer partitionKey = atomicSequencer.partitionKey(customerId);
productLoginEntity = EntityBuilder.productLogin(productId, institutionId, phoneNo, customerId, customerName, partitionKey, id);
productLoginEntity.setExtensionAccountId(userId);
productLoginEntity.setEncryptedPhoneNo(phoneNo);
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.setAppName(appletParamEntry.getAppName());
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);
} else {
// 如果产品登陆表有信息,查询用户信息表
CustomerInfoEntity customerInfo = customerInfoRepository.findByCustomerId(productLoginEntity.getCustomerId());
customerInfo = (customerInfo == null ? new CustomerInfoEntity() : customerInfo);
customerInfo.setAvatarUrl(appletParamEntry.getAvatarUrl());
customerInfo.setNickName(appletParamEntry.getNickName());
customerInfo.setAppName(appletParamEntry.getAppName());
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.setCreatedDate(new Date());
customerInfo.setModifiedDate(new Date());
customerInfo.setCreatedBy("");
customerInfo.setModifiedBy("");
customerInfoRepository.save(customerInfo);
}
}
}
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.ProductLoginEntity;
import cn.quantgroup.xyqb.repository.IProductLoginRepository;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class ProductLoginServiceImpl implements IProductLoginService {
@Autowired
private IProductLoginRepository productLoginRepository;
@Override
public ProductLoginEntity findSlaveByPloginInfo(String institutionId, String productId, Long userId) {
ProductLoginEntity productLogin = productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountId(institutionId, productId, userId);
return productLogin;
}
@Override
public List<ProductLoginEntity> findSlaveByProductLoginInfoList(String institutionId, String productId, List<Long> userIds) {
return productLoginRepository.findByInstitutionIdAndProductIdAndExtensionAccountIdIn(institutionId, productId, userIds);
}
@Override
public List<ProductLoginEntity> findSlaveByUserId(Long userId) {
List<ProductLoginEntity> productLoginEntityList = productLoginRepository.findAllByExtensionAccountId(userId);
return productLoginEntityList;
}
@Override
public List<ProductLoginEntity> findSlaveByUserIds(List<Long> userIds) {
return productLoginRepository.findAllByExtensionAccountIdIn(userIds);
}
@Override
public List<ProductLoginEntity> findProductLoginsByInstitutionIdAndProductId(String institutionId, String productId) {
return productLoginRepository.findProductLoginsByInstitutionIdAndProductId(institutionId, productId);
}
@Override
public ProductLoginEntity findSlaveByCustomerInfo(long customerId, String institutionId, String productId) {
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;
}
}
package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.model.UserBrief;
import cn.quantgroup.xyqb.service.user.ICustomerInfoService;
import cn.quantgroup.xyqb.service.user.IOauthClientDetailsService;
import cn.quantgroup.xyqb.service.user.IProductLoginService;
import cn.quantgroup.xyqb.service.user.ITenantService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by 11 on 2016/12/29.
*/
@Slf4j
@Service
public class TenantServiceImpl implements ITenantService {
@Autowired
private IProductLoginService productLoginService;
@Autowired
private ICustomerInfoService customerInfoService;
@Autowired
private IOauthClientDetailsService oauthClientDetailsService;
@Override
public User getTenantUser(User user, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), user.getId());
if (productLogin != null) {
if (user.getEncryptedPhoneNo().equals(productLogin.getEncryptedPhoneNo())) {
user.setPassword(productLogin.getPassword());
return user;
}
}
}
return null;
}
@Override
public UserDetail getTenantUserDetail(UserDetail userDetail, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userDetail.getUserId());
if (productLogin != null) {
if (!userDetail.getPhoneNo().equals(productLogin.getPhoneNo())) {
return null;
}
CustomerInfoEntity customerInfo = customerInfoService.findSlaveByCustomerId(productLogin.getCustomerId());
if (customerInfo == null) {
return null;
}
UserDetail tenantUserDetail = new UserDetail();
tenantUserDetail.setUserId(userDetail.getUserId());
tenantUserDetail.setPhoneNo(userDetail.getPhoneNo());
tenantUserDetail.setName(customerInfo.getName());
tenantUserDetail.setCreatedAt(userDetail.getCreatedAt());
tenantUserDetail.setUpdatedAt(userDetail.getUpdatedAt());
return tenantUserDetail;
}
}
return null;
}
@Override
public UserBrief getTenantCustomerInfo(UserDetail userDetail, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userDetail.getUserId());
if (productLogin != null) {
if (!userDetail.getPhoneNo().equals(productLogin.getEncryptedPhoneNo())) {
return null;
}
CustomerInfoEntity customerInfo = customerInfoService.findSlaveByCustomerId(productLogin.getCustomerId());
if (customerInfo == null) {
return null;
}
UserBrief tenantUserBrief = new UserBrief();
tenantUserBrief.setAvatar(customerInfo.getAvatarUrl());
tenantUserBrief.setNick(customerInfo.getNickName());
tenantUserBrief.setName(customerInfo.getName());
tenantUserBrief.setSex(Optional.ofNullable(customerInfo.getSex()).orElse(cn.quantgroup.xyqb.model.Gender.UNKNOWN).ordinal() + "");
tenantUserBrief.setPhoneNo(productLogin.getPhoneNo().substring(0, 3) + "****" + productLogin.getPhoneNo().substring(7, 11));
return tenantUserBrief;
}
}
return null;
}
@Override
public CustomerInfoEntity getTenantCustomerInfo(User user, Integer tenantId) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
ProductLoginEntity productLogin = productLoginService.findSlaveByPloginInfo(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), user.getId());
if (productLogin != null) {
if (user.getPhoneNo().equals(productLogin.getPhoneNo())) {
return customerInfoService.findSlaveByCustomerId(productLogin.getCustomerId());
}
}
}
return null;
}
@Override
public List<User> selectUsersByTenantId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>();
if (CollectionUtils.isNotEmpty(users)) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
if (oauthClientDetails != null) {
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByProductLoginInfoList(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
if (CollectionUtils.isNotEmpty(productLoginEntities)) {
List<String> phoneNos = productLoginEntities.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
result = users.stream().filter(i -> phoneNos.contains(i.getPhoneNo())).collect(Collectors.toList());
}
}
}
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;
}
@Override
public List<User> validationTentIdByTentId(List<User> users, Integer tenantId) {
List<User> result = new ArrayList<>();
if (CollectionUtils.isNotEmpty(users)) {
OauthClientDetailsEntity oauthClientDetails = oauthClientDetailsService.findFirstByClientId(tenantId);
List<Long> userIds = users.stream().map(User::getId).collect(Collectors.toList());
if (oauthClientDetails != null) {
//1、查询出在product_login手机号码相同的用户
List<ProductLoginEntity> productLoginEntities = productLoginService.findSlaveByProductLoginInfoList(oauthClientDetails.getInstitutionId(), oauthClientDetails.getProductId(), userIds);
List<String> phoneNos = productLoginEntities.stream().map(ProductLoginEntity::getPhoneNo).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(productLoginEntities)) {
result = users.stream().filter(i -> phoneNos.contains(i.getPhoneNo())).collect(Collectors.toList());
}
} else {
//2、查询用户id不在product_login的扩展账户ID的用户
List<ProductLoginEntity> slaveByUserIds = productLoginService.findSlaveByUserIds(userIds);
List<Long> extensionAccountIds = slaveByUserIds.stream().map(ProductLoginEntity::getExtensionAccountId).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(slaveByUserIds)) {
result = users.stream().filter(i -> extensionAccountIds.contains(i.getId())).collect(Collectors.toList());
}
}
}
return result;
}
}
...@@ -4,7 +4,6 @@ import cn.quantgroup.xyqb.entity.User; ...@@ -4,7 +4,6 @@ import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserAttached; import cn.quantgroup.xyqb.entity.UserAttached;
import cn.quantgroup.xyqb.repository.IUserAttachedRepository; import cn.quantgroup.xyqb.repository.IUserAttachedRepository;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.user.ITenantService;
import cn.quantgroup.xyqb.service.user.UserCenterService; import cn.quantgroup.xyqb.service.user.UserCenterService;
import cn.quantgroup.xyqb.util.EmojiUtil; import cn.quantgroup.xyqb.util.EmojiUtil;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
...@@ -35,9 +34,6 @@ public class UserCenterServiceImpl implements UserCenterService { ...@@ -35,9 +34,6 @@ public class UserCenterServiceImpl implements UserCenterService {
@Autowired @Autowired
private IUserRepository userRepository; private IUserRepository userRepository;
@Autowired
private ITenantService tenantService;
@Override @Override
// @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager") // @Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public UserAttached searchUserAttachedByUserId(long userId) { public UserAttached searchUserAttachedByUserId(long userId) {
...@@ -46,21 +42,7 @@ public class UserCenterServiceImpl implements UserCenterService { ...@@ -46,21 +42,7 @@ public class UserCenterServiceImpl implements UserCenterService {
@Override @Override
public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) { public List<UserAttached> searchUserAttachedListByUserId(List<Long> userIds, Integer tenantId) {
List<UserAttached> resultProductUsers = new ArrayList<>(); return userAttachedRepository.findByUserIdIn(userIds);
List<UserAttached> userAttachedList = userAttachedRepository.findByUserIdIn(userIds);
List<User> users = userRepository.findByIdIn(userIds);
List<User> productUsers;
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
productUsers = tenantService.selectUsersByTenantId(users, tenantId);
} else {
productUsers = tenantService.validationTentIdByTentId(users, tenantId);
}
if (CollectionUtils.isNotEmpty(userAttachedList) && CollectionUtils.isNotEmpty(productUsers)) {
List<Long> productUserIds = productUsers.stream().map(User::getId).collect(Collectors.toList());
resultProductUsers = userAttachedList.stream().filter(i -> productUserIds.contains(i.getUserId())).collect(Collectors.toList());
}
return resultProductUsers;
} }
@Override @Override
......
...@@ -87,12 +87,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -87,12 +87,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Resource @Resource
private ILockIpv4Service lockIpv4Service; private ILockIpv4Service lockIpv4Service;
@Autowired
private IOauthLoginInfoService oauthLoginInfoService;
@Autowired
private ITenantService tenantService;
@Autowired @Autowired
private IUserDeregisterService userDeregisterService; private IUserDeregisterService userDeregisterService;
...@@ -105,9 +99,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -105,9 +99,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
@Resource @Resource
private IWeChatUserRepository weChatUserRepository; private IWeChatUserRepository weChatUserRepository;
@Resource
private IProductLoginRepository productLoginRepository;
@Resource @Resource
private IGeetestLogService geetestLogService; private IGeetestLogService geetestLogService;
...@@ -153,12 +144,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -153,12 +144,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
return Maps.newHashMap(); return Maps.newHashMap();
} }
List<User> users = userRepository.findByIdIn(userIds); List<User> users = userRepository.findByIdIn(userIds);
//校验租户ID
if (!TenantUtil.TENANT_DEFAULT.equals(tenantId)) {
users = tenantService.selectUsersByTenantId(users, tenantId);
} else {
users = tenantService.validationTentIdByTentId(users, tenantId);
}
return users.stream().collect(Collectors.toMap(User::getId, User::getPhoneNo)); return users.stream().collect(Collectors.toMap(User::getId, User::getPhoneNo));
} }
...@@ -402,7 +387,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -402,7 +387,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
} }
} }
oauthLoginInfoService.addLoginInfo(user, tenantId);
// 更新极验用户userID // 更新极验用户userID
if (geetestLogId != null) { if (geetestLogId != null) {
geetestLogService.updateByUidGeetestLog(geetestLogId, user.getId()); geetestLogService.updateByUidGeetestLog(geetestLogId, user.getId());
...@@ -484,11 +468,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -484,11 +468,6 @@ public class UserServiceImpl implements IUserService, IBaseController {
users = userRepository.findByUuidIn(vals); users = userRepository.findByUuidIn(vals);
} }
if (!tenantId.equals(TenantUtil.TENANT_DEFAULT)) {
users = tenantService.selectUsersByTenantId(users, tenantId);
} else {
users = tenantService.validationTentIdByTentId(users, tenantId);
}
return users; return users;
} }
...@@ -535,9 +514,6 @@ public class UserServiceImpl implements IUserService, IBaseController { ...@@ -535,9 +514,6 @@ 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());
} }
@Override @Override
......
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