Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
eb095ae9
Commit
eb095ae9
authored
Nov 18, 2021
by
李健华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
小程序注册登陆,极光登陆
parent
9a3b67f0
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
131 additions
and
52 deletions
+131
-52
AppController.java
...antgroup/xyqb/controller/internal/user/AppController.java
+7
-0
AppletController.java
...xyqb/controller/middleoffice/applet/AppletController.java
+7
-12
AppletParamEntry.java
...quantgroup/xyqb/entity/middleoffice/AppletParamEntry.java
+5
-0
ICustomerInfoRepository.java
...n/quantgroup/xyqb/repository/ICustomerInfoRepository.java
+2
-0
IProductLoginRepository.java
...n/quantgroup/xyqb/repository/IProductLoginRepository.java
+2
-0
AppletServiceImpl.java
...b/service/middleoffice/applet/impl/AppletServiceImpl.java
+74
-40
ICustomerInfoService.java
...cn/quantgroup/xyqb/service/user/ICustomerInfoService.java
+2
-0
IProductLoginService.java
...cn/quantgroup/xyqb/service/user/IProductLoginService.java
+2
-0
ITenantService.java
.../java/cn/quantgroup/xyqb/service/user/ITenantService.java
+2
-0
CustomerInfoServiceImpl.java
...group/xyqb/service/user/impl/CustomerInfoServiceImpl.java
+7
-0
ProductLoginServiceImpl.java
...group/xyqb/service/user/impl/ProductLoginServiceImpl.java
+5
-0
TenantServiceImpl.java
.../quantgroup/xyqb/service/user/impl/TenantServiceImpl.java
+16
-0
No files found.
src/main/java/cn/quantgroup/xyqb/controller/internal/user/AppController.java
View file @
eb095ae9
...
...
@@ -70,8 +70,12 @@ public class AppController implements IBaseController {
@RequestParam
(
required
=
false
)
Long
registerFrom
,
@RequestParam
(
required
=
true
)
Long
channelId
,
@RequestParam
(
required
=
true
)
String
appChannel
,
@RequestParam
(
required
=
false
)
Integer
tenantId
,
HttpServletRequest
request
)
{
if
(
tenantId
==
null
)
{
tenantId
=
TenantUtil
.
TENANT_DEFAULT
;
}
JsonResult
result
=
null
;
Authentication
authentication
=
AuthorityManager
.
authentication
();
if
(
authentication
.
isAuthenticated
()){
...
...
@@ -87,6 +91,9 @@ public class AppController implements IBaseController {
isRegister
=
true
;
user
=
userRegisterService
.
register
(
registerFrom
,
phoneNumber
,
idNo
,
name
,
channelId
,
createdFrom
);
}
// 无论是否注册过都添加映射
oauthLoginInfoService
.
addLoginInfo
(
user
,
tenantId
);
if
(
user
==
null
)
{
result
=
JsonResult
.
buildErrorStateResult
(
USER_ERROR_OR_PASSWORD_ERROR
,
null
);
}
else
if
(!
user
.
getEnable
())
{
...
...
src/main/java/cn/quantgroup/xyqb/controller/middleoffice/applet/AppletController.java
View file @
eb095ae9
package
cn
.
quantgroup
.
xyqb
.
controller
.
middleoffice
.
applet
;
import
java.util.Arrays
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
cn.quantgroup.xyqb.controller.middleoffice.login.ILoginModule
;
import
cn.quantgroup.xyqb.controller.middleoffice.login.LoginVo
;
import
cn.quantgroup.xyqb.entity.middleoffice.AppletParamEntry
;
...
...
@@ -18,6 +7,12 @@ import cn.quantgroup.xyqb.exception.DataException;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Arrays
;
/**
* @author :dongjianhua
...
...
@@ -68,7 +63,7 @@ public class AppletController {
*/
@Validated
@PostMapping
(
"/login"
)
public
JsonResult
login
(
@RequestParam
String
appName
,
@RequestParam
String
openId
,
@RequestParam
(
required
=
false
)
Integer
tenantId
,
String
utmSource
)
{
public
JsonResult
login
(
@RequestParam
String
appName
,
@RequestParam
String
openId
,
@RequestParam
(
required
=
false
)
Integer
tenantId
,
String
utmSource
,
@RequestParam
(
required
=
false
)
Integer
appNo
)
{
if
(!
containsAppName
(
appName
))
{
throw
new
DataException
(
"appName不合法"
);
}
...
...
src/main/java/cn/quantgroup/xyqb/entity/middleoffice/AppletParamEntry.java
View file @
eb095ae9
...
...
@@ -80,4 +80,9 @@ public class AppletParamEntry {
* 租户ID
*/
private
Integer
tenantId
;
/**
* 小程序编号
*/
private
Integer
appNo
;
}
src/main/java/cn/quantgroup/xyqb/repository/ICustomerInfoRepository.java
View file @
eb095ae9
...
...
@@ -10,4 +10,6 @@ import org.springframework.stereotype.Repository;
@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
src/main/java/cn/quantgroup/xyqb/repository/IProductLoginRepository.java
View file @
eb095ae9
...
...
@@ -31,4 +31,6 @@ public interface IProductLoginRepository extends JpaRepository<ProductLoginEntit
* @return Arraylist
*/
List
<
ProductLoginEntity
>
findProductLoginsByInstitutionIdAndProductId
(
String
institutionId
,
String
productId
);
ProductLoginEntity
findFirstByInstitutionIdAndProductIdAndCustomerId
(
String
institutionId
,
String
productId
,
long
customerId
);
}
\ No newline at end of file
src/main/java/cn/quantgroup/xyqb/service/middleoffice/applet/impl/AppletServiceImpl.java
View file @
eb095ae9
...
...
@@ -10,6 +10,7 @@ import cn.quantgroup.xyqb.repository.IWeChatUserRepository;
import
cn.quantgroup.xyqb.service.middleoffice.applet.IAppletService
;
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.util.TenantUtil
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -39,6 +40,9 @@ public class AppletServiceImpl implements IAppletService {
@Autowired
private
IOauthLoginInfoService
iOauthLoginInfoService
;
@Autowired
private
ITenantService
tenantService
;
@Autowired
public
AppletServiceImpl
(
IWeChatUserRepository
iWeChatUserRepository
,
IUserRegisterService
iUserRegisterService
,
...
...
@@ -53,61 +57,91 @@ public class AppletServiceImpl implements IAppletService {
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Long
relevance
(
AppletParamEntry
appletParamEntry
)
{
if
(
appletParamEntry
.
getTenantId
()
==
null
)
{
appletParamEntry
.
setTenantId
(
TenantUtil
.
TENANT_DEFAULT
);
}
if
(
appletParamEntry
.
getTenantId
().
equals
(
TenantUtil
.
TENANT_DEFAULT
))
{
WechatUserInfo
wechatUserInfo
=
iWeChatUserRepository
.
findByOpenIdAndAppName
(
appletParamEntry
.
getOpenId
(),
appletParamEntry
.
getAppName
());
//这个接口先不考虑更换手机号的情况
wechatUserInfo
=
(
wechatUserInfo
==
null
?
new
WechatUserInfo
()
:
wechatUserInfo
);
wechatUserInfo
.
setNickName
(
appletParamEntry
.
getNickName
());
wechatUserInfo
.
setCity
(
appletParamEntry
.
getCity
());
wechatUserInfo
.
setCountry
(
appletParamEntry
.
getCountry
());
wechatUserInfo
.
setProvince
(
appletParamEntry
.
getProvince
());
wechatUserInfo
.
setAppName
(
appletParamEntry
.
getAppName
());
wechatUserInfo
.
setHeadImgUrl
(
appletParamEntry
.
getAvatarUrl
());
wechatUserInfo
.
setLanguage
(
appletParamEntry
.
getLanguage
());
wechatUserInfo
.
setOpenId
(
appletParamEntry
.
getOpenId
());
wechatUserInfo
.
setSex
(
appletParamEntry
.
getGender
());
wechatUserInfo
.
setUnionId
(
appletParamEntry
.
getUnionId
());
wechatUserInfo
.
setPhoneNo
(
appletParamEntry
.
getMobile
());
wechatUserInfo
.
setUtmSource
(
appletParamEntry
.
getUtmSource
());
if
(
null
==
wechatUserInfo
.
getUserId
())
{
//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
User
user
=
userService
.
findByPhoneInDb
(
appletParamEntry
.
getMobile
());
//如果不存在就去注册一下
if
(
null
==
user
)
{
user
=
iUserRegisterService
.
register
(
appletParamEntry
.
getChannelId
(),
appletParamEntry
.
getMobile
());
}
iOauthLoginInfoService
.
addRegisterInfo
(
user
,
appletParamEntry
);
wechatUserInfo
.
setUserId
(
user
.
getId
());
}
WechatUserInfo
wechatUserInfo
=
iWeChatUserRepository
.
findByOpenIdAndAppName
(
appletParamEntry
.
getOpenId
(),
appletParamEntry
.
getAppName
());
//这个接口先不考虑更换手机号的情况
wechatUserInfo
=
(
wechatUserInfo
==
null
?
new
WechatUserInfo
()
:
wechatUserInfo
);
wechatUserInfo
.
setNickName
(
appletParamEntry
.
getNickName
());
wechatUserInfo
.
setCity
(
appletParamEntry
.
getCity
());
wechatUserInfo
.
setCountry
(
appletParamEntry
.
getCountry
());
wechatUserInfo
.
setProvince
(
appletParamEntry
.
getProvince
());
wechatUserInfo
.
setAppName
(
appletParamEntry
.
getAppName
());
wechatUserInfo
.
setHeadImgUrl
(
appletParamEntry
.
getAvatarUrl
());
wechatUserInfo
.
setLanguage
(
appletParamEntry
.
getLanguage
());
wechatUserInfo
.
setOpenId
(
appletParamEntry
.
getOpenId
());
wechatUserInfo
.
setSex
(
appletParamEntry
.
getGender
());
wechatUserInfo
.
setUnionId
(
appletParamEntry
.
getUnionId
());
wechatUserInfo
.
setPhoneNo
(
appletParamEntry
.
getMobile
());
wechatUserInfo
.
setUtmSource
(
appletParamEntry
.
getUtmSource
());
if
(
null
==
wechatUserInfo
.
getUserId
())
{
//只要存在userid 就说明已经在用户表里了 不考虑小程序这边换手机号了
//如果存在就更新在微信表里
iWeChatUserRepository
.
save
(
wechatUserInfo
);
return
wechatUserInfo
.
getUserId
();
}
else
{
User
user
=
userService
.
findByPhoneInDb
(
appletParamEntry
.
getMobile
());
//如果不存在就去注册一下
if
(
null
==
user
)
{
user
=
iUserRegisterService
.
register
(
appletParamEntry
.
getChannelId
(),
appletParamEntry
.
getMobile
());
if
(
appletParamEntry
.
getTenantId
()
!=
null
)
{
iOauthLoginInfoService
.
addRegisterInfo
(
user
,
appletParamEntry
);
}
}
wechatUserInfo
.
setUserId
(
user
.
getId
());
iOauthLoginInfoService
.
addRegisterInfo
(
user
,
appletParamEntry
);
return
user
.
getId
();
}
//如果存在就更新在微信表里
iWeChatUserRepository
.
save
(
wechatUserInfo
);
return
wechatUserInfo
.
getUserId
();
}
@Override
public
LoginVo
login
(
String
appName
,
String
openId
,
Integer
tenantId
,
String
utmSource
)
{
WechatUserInfo
wechatUserInfo
=
iWeChatUserRepository
.
findByOpenIdAndAppName
(
openId
,
appName
);
if
(
null
==
wechatUserInfo
)
{
log
.
warn
(
"未找到此用户,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
if
(
null
==
wechatUserInfo
.
getUserId
())
{
log
.
warn
(
"用户未绑定到xyqb,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户绑定信息"
,
"0401"
);
if
(
tenantId
==
null
)
{
tenantId
=
TenantUtil
.
TENANT_DEFAULT
;
}
User
user
=
userService
.
findById
(
wechatUserInfo
.
getUserId
());
if
(
null
==
user
)
{
log
.
warn
(
"未找到此用户,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
//校验租户ID tenantId
if
(
TenantUtil
.
checkoutTenantIsDefault
(
tenantId
))
{
User
user
=
null
;
if
(
TenantUtil
.
TENANT_DEFAULT
.
equals
(
tenantId
))
{
WechatUserInfo
wechatUserInfo
=
iWeChatUserRepository
.
findByOpenIdAndAppName
(
openId
,
appName
);
if
(
null
==
wechatUserInfo
)
{
log
.
warn
(
"未找到此用户,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
if
(
null
==
wechatUserInfo
.
getUserId
())
{
log
.
warn
(
"用户未绑定到xyqb,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户绑定信息"
,
"0401"
);
}
user
=
userService
.
findById
(
wechatUserInfo
.
getUserId
());
if
(
null
==
user
)
{
log
.
warn
(
"未找到此用户,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
iOauthLoginInfoService
.
addLoginInfo
(
user
,
tenantId
);
}
else
{
// 通过租户id和openId查询是否有关联
Long
userId
=
tenantService
.
getTenantCustomerInfoByOpenId
(
openId
,
tenantId
);
if
(
null
==
userId
)
{
log
.
warn
(
"未找到此用户,tenantId:{} ,openId:{}"
,
tenantId
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
user
=
userService
.
findById
(
userId
);
if
(
null
==
user
)
{
log
.
warn
(
"未找到此用户,appName:{} ,openId:{}"
,
appName
,
openId
);
throw
new
AppletException
(
"未找到此用户"
,
"0401"
);
}
}
LoginVo
loginVo
=
loginModule
.
loginByUserId
(
user
.
getRegisteredFrom
(),
utmSource
==
null
?
""
:
utmSource
,
user
.
getId
(),
tenantId
);
return
loginVo
;
...
...
src/main/java/cn/quantgroup/xyqb/service/user/ICustomerInfoService.java
View file @
eb095ae9
...
...
@@ -7,4 +7,6 @@ import cn.quantgroup.xyqb.entity.CustomerInfoEntity;
*/
public
interface
ICustomerInfoService
{
CustomerInfoEntity
findSlaveByCustomerId
(
Long
customerId
);
CustomerInfoEntity
findSlaveByOpenId
(
String
openId
,
String
institutionId
,
String
productId
);
}
src/main/java/cn/quantgroup/xyqb/service/user/IProductLoginService.java
View file @
eb095ae9
...
...
@@ -20,4 +20,6 @@ public interface IProductLoginService {
* @return Arraylist
*/
List
<
ProductLoginEntity
>
findProductLoginsByInstitutionIdAndProductId
(
String
institutionId
,
String
productId
);
ProductLoginEntity
findSlaveByCustomerInfo
(
long
customerId
,
String
institutionId
,
String
productId
);
}
src/main/java/cn/quantgroup/xyqb/service/user/ITenantService.java
View file @
eb095ae9
...
...
@@ -26,4 +26,6 @@ public interface ITenantService {
* @return Arraylist
*/
List
<
User
>
selectUsersByTenantId
(
List
<
User
>
users
,
Integer
tenantId
);
Long
getTenantCustomerInfoByOpenId
(
String
openId
,
Integer
tenantId
);
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/CustomerInfoServiceImpl.java
View file @
eb095ae9
...
...
@@ -24,4 +24,11 @@ public class CustomerInfoServiceImpl implements ICustomerInfoService {
CustomerInfoEntity
customerInfo
=
customerInfoRepository
.
findByCustomerId
(
customerId
);
return
customerInfo
;
}
@Override
@TargetDataSource
(
type
=
DSType
.
SLAVE
)
//查询从库
public
CustomerInfoEntity
findSlaveByOpenId
(
String
openId
,
String
institutionId
,
String
productId
)
{
CustomerInfoEntity
customerInfo
=
customerInfoRepository
.
findByInstitutionIdAndProductIdAndSourceOpenId
(
institutionId
,
productId
,
openId
);
return
customerInfo
;
}
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/ProductLoginServiceImpl.java
View file @
eb095ae9
...
...
@@ -38,4 +38,9 @@ public class ProductLoginServiceImpl implements IProductLoginService {
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
);
}
}
src/main/java/cn/quantgroup/xyqb/service/user/impl/TenantServiceImpl.java
View file @
eb095ae9
...
...
@@ -120,4 +120,20 @@ public class TenantServiceImpl implements ITenantService {
}
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment