Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gsst-auth
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
gsst-backend
gsst-auth
Commits
52bb15fa
Commit
52bb15fa
authored
Jun 04, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parents
Show whitespace changes
Inline
Side-by-side
Showing
100 changed files
with
9751 additions
and
0 deletions
+9751
-0
.gitignore
.gitignore
+39
-0
pom.xml
pom.xml
+250
-0
CommonConstant.java
...java/cn/com/gsst/auth/common/constant/CommonConstant.java
+61
-0
FmxParamConfigConstant.java
...com/gsst/auth/common/constant/FmxParamConfigConstant.java
+74
-0
Member3ptLoginChannel.java
.../com/gsst/auth/common/constant/Member3ptLoginChannel.java
+33
-0
RedisKeyConstant.java
...va/cn/com/gsst/auth/common/constant/RedisKeyConstant.java
+23
-0
SmsDto.java
src/main/java/cn/com/gsst/auth/common/dto/SmsDto.java
+146
-0
GoogleConfigRest.java
...n/java/cn/com/gsst/auth/common/rest/GoogleConfigRest.java
+19
-0
JudgeCodeRest.java
...main/java/cn/com/gsst/auth/common/rest/JudgeCodeRest.java
+25
-0
SendEmailRest.java
...main/java/cn/com/gsst/auth/common/rest/SendEmailRest.java
+17
-0
SmsRest.java
src/main/java/cn/com/gsst/auth/common/rest/SmsRest.java
+22
-0
GoogleConfigRestImpl.java
.../com/gsst/auth/common/rest/impl/GoogleConfigRestImpl.java
+20
-0
JudgeCodeRestImpl.java
.../cn/com/gsst/auth/common/rest/impl/JudgeCodeRestImpl.java
+29
-0
SendEmailRestImpl.java
.../cn/com/gsst/auth/common/rest/impl/SendEmailRestImpl.java
+21
-0
SmsRestImpl.java
...n/java/cn/com/gsst/auth/common/rest/impl/SmsRestImpl.java
+36
-0
JudgeCodeService.java
...ava/cn/com/gsst/auth/common/service/JudgeCodeService.java
+19
-0
RedisService.java
...in/java/cn/com/gsst/auth/common/service/RedisService.java
+481
-0
SendEmailService.java
...ava/cn/com/gsst/auth/common/service/SendEmailService.java
+10
-0
SmsService.java
...main/java/cn/com/gsst/auth/common/service/SmsService.java
+13
-0
JudgeCodeServiceImpl.java
...m/gsst/auth/common/service/impl/JudgeCodeServiceImpl.java
+74
-0
RedisServiceImpl.java
...n/com/gsst/auth/common/service/impl/RedisServiceImpl.java
+979
-0
SendEmailServiceImpl.java
...m/gsst/auth/common/service/impl/SendEmailServiceImpl.java
+54
-0
SmsServiceImpl.java
.../cn/com/gsst/auth/common/service/impl/SmsServiceImpl.java
+41
-0
Assert.java
src/main/java/cn/com/gsst/auth/common/utils/Assert.java
+22
-0
BlContext.java
src/main/java/cn/com/gsst/auth/common/utils/BlContext.java
+65
-0
DateUtils.java
src/main/java/cn/com/gsst/auth/common/utils/DateUtils.java
+1631
-0
JsonUtils.java
src/main/java/cn/com/gsst/auth/common/utils/JsonUtils.java
+160
-0
RandomCodeUtils.java
...n/java/cn/com/gsst/auth/common/utils/RandomCodeUtils.java
+41
-0
RandomUtil.java
src/main/java/cn/com/gsst/auth/common/utils/RandomUtil.java
+74
-0
StringUtils.java
src/main/java/cn/com/gsst/auth/common/utils/StringUtils.java
+832
-0
UUIDTool.java
src/main/java/cn/com/gsst/auth/common/utils/UUIDTool.java
+20
-0
HttpClientFactory.java
...cn/com/gsst/auth/common/utils/http/HttpClientFactory.java
+185
-0
HttpUtils.java
...in/java/cn/com/gsst/auth/common/utils/http/HttpUtils.java
+246
-0
JsonResponseHandler.java
.../com/gsst/auth/common/utils/http/JsonResponseHandler.java
+67
-0
LocalResponseHandler.java
...com/gsst/auth/common/utils/http/LocalResponseHandler.java
+16
-0
SslUtils.java
...ain/java/cn/com/gsst/auth/common/utils/http/SslUtils.java
+56
-0
ThirdPlatformAuthService.java
...com/gsst/auth/support/login/ThirdPlatformAuthService.java
+19
-0
ThirdPlatformAuthServiceBuilder.java
...t/auth/support/login/ThirdPlatformAuthServiceBuilder.java
+31
-0
ThirdPlatformLoginService.java
...om/gsst/auth/support/login/ThirdPlatformLoginService.java
+14
-0
ThirdPlatformLoginServiceBuilder.java
.../auth/support/login/ThirdPlatformLoginServiceBuilder.java
+30
-0
DefaultLoginService.java
.../gsst/auth/support/login/channel/DefaultLoginService.java
+28
-0
IBTAuthService.java
...om/gsst/auth/support/login/channel/bl/IBTAuthService.java
+36
-0
IBTLoginService.java
...m/gsst/auth/support/login/channel/bl/IBTLoginService.java
+38
-0
AuthInfo.java
.../java/cn/com/gsst/auth/support/login/domain/AuthInfo.java
+23
-0
CodeAuth.java
.../java/cn/com/gsst/auth/support/login/domain/CodeAuth.java
+8
-0
ThirdPlatformRegisterService.java
...t/auth/support/register/ThirdPlatformRegisterService.java
+15
-0
ThirdPlatformRegisterServiceBuilder.java
...support/register/ThirdPlatformRegisterServiceBuilder.java
+37
-0
DefaultRegisterService.java
...auth/support/register/channel/DefaultRegisterService.java
+26
-0
BlMobileRegisterService.java
.../support/register/channel/bl/BlMobileRegisterService.java
+157
-0
BlWxMiniRegisterService.java
.../support/register/channel/bl/BlWxMiniRegisterService.java
+224
-0
DummyUserBaseModel.java
.../gsst/auth/support/security/oauth/DummyUserBaseModel.java
+43
-0
MultiDomainOauthTokenOperatorImplementor.java
...urity/oauth/MultiDomainOauthTokenOperatorImplementor.java
+111
-0
MultiDomainOauthUserManagerImplementor.java
...ecurity/oauth/MultiDomainOauthUserManagerImplementor.java
+75
-0
OauthConstants.java
...auth/support/security/oauth/constants/OauthConstants.java
+82
-0
MemberResponse.java
...st/auth/support/security/oauth/entity/MemberResponse.java
+49
-0
OpenPlatformEntity.java
...uth/support/security/oauth/entity/OpenPlatformEntity.java
+52
-0
UserBaseEntity.java
...st/auth/support/security/oauth/entity/UserBaseEntity.java
+80
-0
ThirdPlatformSmsService.java
...cn/com/gsst/auth/support/sms/ThirdPlatformSmsService.java
+18
-0
ThirdPlatformSmsServiceBuilder.java
...gsst/auth/support/sms/ThirdPlatformSmsServiceBuilder.java
+34
-0
DefaultSmsService.java
.../com/gsst/auth/support/sms/channel/DefaultSmsService.java
+29
-0
BaiDuThirdPlatformService.java
.../support/sms/channel/baidu/BaiDuThirdPlatformService.java
+59
-0
BlSmsService.java
...cn/com/gsst/auth/support/sms/channel/bl/BlSmsService.java
+81
-0
SmsConstant.java
...va/cn/com/gsst/auth/support/sms/constant/SmsConstant.java
+94
-0
MemberInfoService.java
.../cn/com/gsst/auth/user/aggregation/MemberInfoService.java
+29
-0
MemberInfoServiceImpl.java
...sst/auth/user/aggregation/impl/MemberInfoServiceImpl.java
+97
-0
EmailLoginChannel.java
...java/cn/com/gsst/auth/user/builder/EmailLoginChannel.java
+68
-0
GoogleLoginChannel.java
...ava/cn/com/gsst/auth/user/builder/GoogleLoginChannel.java
+103
-0
LoginChannelBuilder.java
...va/cn/com/gsst/auth/user/builder/LoginChannelBuilder.java
+40
-0
LoginChannelService.java
...va/cn/com/gsst/auth/user/builder/LoginChannelService.java
+21
-0
PwLoginChannel.java
...in/java/cn/com/gsst/auth/user/builder/PwLoginChannel.java
+50
-0
SmsLoginChannel.java
...n/java/cn/com/gsst/auth/user/builder/SmsLoginChannel.java
+77
-0
Member3rdPartyRelationConstants.java
.../auth/user/constants/Member3rdPartyRelationConstants.java
+18
-0
UserLoginConstants.java
...a/cn/com/gsst/auth/user/constants/UserLoginConstants.java
+19
-0
Member3rdPartyRelationConvert.java
...gsst/auth/user/convert/Member3rdPartyRelationConvert.java
+39
-0
MemberInfoConvert.java
...java/cn/com/gsst/auth/user/convert/MemberInfoConvert.java
+83
-0
MemberInfoDto.java
src/main/java/cn/com/gsst/auth/user/dto/MemberInfoDto.java
+136
-0
MemberLoginRequestDto.java
...java/cn/com/gsst/auth/user/dto/MemberLoginRequestDto.java
+64
-0
MemberLoginResponseDto.java
...ava/cn/com/gsst/auth/user/dto/MemberLoginResponseDto.java
+78
-0
MemberPasswordRequestDto.java
...a/cn/com/gsst/auth/user/dto/MemberPasswordRequestDto.java
+39
-0
Member3rdPartyRelationEntity.java
...m/gsst/auth/user/entity/Member3rdPartyRelationEntity.java
+85
-0
MemberInfoEntity.java
...n/java/cn/com/gsst/auth/user/entity/MemberInfoEntity.java
+137
-0
BizMember3rdPartyRelationModel.java
.../gsst/auth/user/model/BizMember3rdPartyRelationModel.java
+185
-0
BizMemberInfoModel.java
.../java/cn/com/gsst/auth/user/model/BizMemberInfoModel.java
+281
-0
CheckMemberInfoQuery.sql
...java/cn/com/gsst/auth/user/query/CheckMemberInfoQuery.sql
+13
-0
CheckMemberInfoQueryCondition.java
...m/gsst/auth/user/query/CheckMemberInfoQueryCondition.java
+46
-0
CheckMemberInfoQueryItem.java
...cn/com/gsst/auth/user/query/CheckMemberInfoQueryItem.java
+88
-0
BizMember3rdPartyRelationRepository.java
.../user/repository/BizMember3rdPartyRelationRepository.java
+8
-0
BizMemberInfoRepository.java
...om/gsst/auth/user/repository/BizMemberInfoRepository.java
+8
-0
BizMember3rdPartyRelationRest.java
...om/gsst/auth/user/rest/BizMember3rdPartyRelationRest.java
+11
-0
BizMemberInfoRest.java
...in/java/cn/com/gsst/auth/user/rest/BizMemberInfoRest.java
+64
-0
BizMember3rdPartyRelationRestImpl.java
...uth/user/rest/impl/BizMember3rdPartyRelationRestImpl.java
+17
-0
BizMemberInfoRestImpl.java
...n/com/gsst/auth/user/rest/impl/BizMemberInfoRestImpl.java
+146
-0
BizMember3rdPartyRelationService.java
...t/auth/user/service/BizMember3rdPartyRelationService.java
+23
-0
BizMemberInfoService.java
...a/cn/com/gsst/auth/user/service/BizMemberInfoService.java
+32
-0
BizMember3rdPartyRelationServiceImpl.java
...er/service/impl/BizMember3rdPartyRelationServiceImpl.java
+65
-0
BizMemberInfoServiceImpl.java
...gsst/auth/user/service/impl/BizMemberInfoServiceImpl.java
+132
-0
framemax-bundle.properties
src/main/resources/META-INF/framemax-bundle.properties
+8
-0
config.properties
src/main/resources/gsst-auth/config.properties
+2
-0
applicationContext.xml
src/main/resources/gsst-auth/spring/applicationContext.xml
+18
-0
applicationContext.xml
src/main/resources/spring/applicationContext.xml
+27
-0
No files found.
.gitignore
0 → 100644
View file @
52bb15fa
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
pom.xml
0 → 100644
View file @
52bb15fa
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.com.gsst
</groupId>
<artifactId>
auth
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-core
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-data-hibernate
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-common
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-security
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-frame
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
cn.com.yict.framemax
</groupId>
<artifactId>
framemax-webservice
</artifactId>
<version>
4.0.2
</version>
</dependency>
<dependency>
<groupId>
org.springframework.security
</groupId>
<artifactId>
spring-security-cas
</artifactId>
<version>
5.1.6.RELEASE
</version>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
jstl
</artifactId>
<version>
1.2
</version>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
8.0.28
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
<version>
4.5.10
</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.76
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.4
</version>
</dependency>
<dependency>
<groupId>
commons-collections
</groupId>
<artifactId>
commons-collections
</artifactId>
<version>
3.2.2
</version>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<version>
3.7.7
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-inline
</artifactId>
<version>
3.7.7
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-test
</artifactId>
<version>
4.3.2.RELEASE
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
javax.servlet-api
</artifactId>
<version>
3.1.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.9
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>
org.json
</groupId>
<artifactId>
json
</artifactId>
<version>
20210307
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-core
</artifactId>
<version>
2.17.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-api
</artifactId>
<version>
2.17.0
</version>
</dependency>
<!-- jedis依赖 -->
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
<version>
2.1.3.RELEASE
</version>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<version>
2.9.0
</version>
</dependency>
<dependency>
<groupId>
com.baidubce
</groupId>
<artifactId>
bce-java-sdk
</artifactId>
<version>
0.10.328
</version>
</dependency>
<dependency>
<groupId>
com.google.api-client
</groupId>
<artifactId>
google-api-client
</artifactId>
<version>
2.4.0
</version>
</dependency>
<dependency>
<groupId>
com.google.apis
</groupId>
<artifactId>
google-api-services-customsearch
</artifactId>
<version>
v1-rev20240821-2.0.0
</version>
</dependency>
</dependencies>
<build>
<finalName>
gsst-auth
</finalName>
<resources>
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.sql
</include>
</includes>
</resource>
<resource>
<directory>
src/main/resources/
</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-source-plugin
</artifactId>
<version>
3.2.1
</version>
<!-- 绑定source插件到Maven的生命周期,并在生命周期后执行绑定的source的goal -->
<executions>
<execution>
<!-- 绑定source插件到Maven的生命周期 -->
<phase>
package
</phase>
<!--在生命周期后执行绑定的source插件的goals -->
<goals>
<goal>
jar-no-fork
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>
aliyun
</id>
<name>
Nexus aliyun
</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public
</url>
</repository>
<repository>
<id>
yict
</id>
<name>
Nexus ISD
</name>
<url>
http://nexus3.gsstcloud.com:8090/nexus/content/groups/public
</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>
releases
</id>
<name>
Releases
</name>
<url>
http://nexus3.gsstcloud.com:8090/nexus/repository/maven-releases/
</url>
</repository>
<snapshotRepository>
<id>
snapshots
</id>
<name>
Snapshots
</name>
<url>
http://nexus3.gsstcloud.com:8090/nexus/repository/maven-snapshots/
</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
src/main/java/cn/com/gsst/auth/common/constant/CommonConstant.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
constant
;
/**
* @author Focan.Zhong
*/
public
interface
CommonConstant
{
/**
* 是否删除 Y-是 N-否
*/
interface
IsDeleted
{
String
Y
=
"Y"
;
String
N
=
"N"
;
}
/**
* 使用中 使用中,0:默认,非使用中|1:使用中
*/
interface
IsUsed
{
/**
* 使用中
*/
Integer
Y
=
0
;
/**
* 未使用
*/
Integer
N
=
1
;
}
/**
*
*/
interface
YOrN
{
String
Y
=
"Y"
;
String
N
=
"N"
;
}
/**
*
*/
interface
SYSTEM_FIELD
{
String
SYSTEM
=
"SYSTEM"
;
}
int
ZERO
=
0
;
}
src/main/java/cn/com/gsst/auth/common/constant/FmxParamConfigConstant.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
constant
;
/**
* @author Roger Wu
*/
public
interface
FmxParamConfigConstant
{
//token过期时间配置
String
TOKEN_EXPIRED_HOURS
=
"login.tokenExpiredHours"
;
interface
Prefix
{
/**
* 营销工具中台
*/
public
static
final
String
DG_TOOLS
=
"dg.tools.project"
;
}
/**
* 营销中台
*/
interface
Dgtools
{
/**
* 项目key
*/
public
static
final
String
PROJECT_KEY
=
"dg.tools.project.key"
;
/**
* 项目密钥
*/
public
static
final
String
PROJECT_SECRET
=
"dg.tools.project.secret"
;
/**
* 加密私钥
*/
public
static
final
String
PRIVATE_KEY
=
"dg.tools.project.private.key"
;
/**
* 加密偏移量
*/
public
static
final
String
VI
=
"dg.tools.project.vi"
;
}
/**
* String TOKEN_EXPIRED_HOURS = "login.tokenExpiredHours";
* <p>
* <p>
* /**
* 小程序设计轮播图、文字轮播配置
*/
interface
Design
{
String
PREFIX
=
"mp.design.config.list"
;
//跑马灯
String
MARQUEE
=
"marquee"
;
//轮播图
String
SLIDE_SHOW
=
"slideshow"
;
//content-detail
String
CONTENT_DETAIL
=
"content-detail"
;
//jumpType
String
JUMP_TYPE
=
"jumpType"
;
//jumpQuery
String
JUMP_QUERY
=
"jumpQuery"
;
//contentId
String
CONTENT_ID
=
"contentId"
;
}
}
src/main/java/cn/com/gsst/auth/common/constant/Member3ptLoginChannel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
constant
;
/**
* 第三方登录渠道
**/
public
enum
Member3ptLoginChannel
{
/**
* 微信小程序
*/
wx_mini
,
/**
* 公众号
*/
wx_pub
,
/**
* 手机验证码
*/
app_verification_code
,
/**
* 密码登录
*/
app_password
,
ibt
,
;
}
src/main/java/cn/com/gsst/auth/common/constant/RedisKeyConstant.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
constant
;
/**
*
*/
public
interface
RedisKeyConstant
{
public
class
Code
{
/**
* 验证码授权码
*/
public
final
static
String
AUTH_CODE
=
"auth_code:"
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/common/dto/SmsDto.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
dto
;
import
cn.com.gsst.auth.support.sms.constant.SmsConstant
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.io.Serializable
;
/**
* @author Focan.Zhong
*/
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SmsDto
implements
Serializable
{
private
SmsConstant
.
Channel
channel
;
/**
* 手机号
*/
private
String
mobilePhone
;
/**
* 手机验证码
*/
private
String
smsCode
;
//验证码请求体
/**
* verifyCodeType String 是 短信验证码类型(必传)
* * 1.发送快捷登录或注册短信,
* * 2.发送语音短信,
* * 4.重置密码发送短信,
* * 5.风控发送短信
* verifyImgType String 是 图形、滑块验证类型(必传) 2.图形验证码,3.滑块验证
* verifyImgCode String 否 图形验证码(verifyImgType=2时必填)
* uniqueFlag String 是 滑块唯一标识(verifyImgType=3时必填)
* xPercent String 是 滑块横坐标所占比例 (verifyImgType=3时必填) @mock=1
*/
private
String
verifyCodeType
;
private
String
verifyImgType
;
private
String
verifyImgCode
;
private
String
uniqueFlag
;
private
String
xPercent
;
/**
* 滑块开关
*/
private
String
captchaSwitch
;
/**
* 滑块大图
*/
private
String
oriCopyImages
;
/**
* 滑块图
*/
private
String
slideImages
;
public
SmsConstant
.
Channel
getChannel
()
{
return
channel
;
}
public
void
setChannel
(
SmsConstant
.
Channel
channel
)
{
this
.
channel
=
channel
;
}
public
String
getMobilePhone
()
{
return
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
)
{
this
.
mobilePhone
=
mobilePhone
;
}
public
String
getSmsCode
()
{
return
smsCode
;
}
public
void
setSmsCode
(
String
smsCode
)
{
this
.
smsCode
=
smsCode
;
}
public
String
getVerifyCodeType
()
{
return
verifyCodeType
;
}
public
void
setVerifyCodeType
(
String
verifyCodeType
)
{
this
.
verifyCodeType
=
verifyCodeType
;
}
public
String
getVerifyImgType
()
{
return
verifyImgType
;
}
public
void
setVerifyImgType
(
String
verifyImgType
)
{
this
.
verifyImgType
=
verifyImgType
;
}
public
String
getVerifyImgCode
()
{
return
verifyImgCode
;
}
public
void
setVerifyImgCode
(
String
verifyImgCode
)
{
this
.
verifyImgCode
=
verifyImgCode
;
}
public
String
getUniqueFlag
()
{
return
uniqueFlag
;
}
public
void
setUniqueFlag
(
String
uniqueFlag
)
{
this
.
uniqueFlag
=
uniqueFlag
;
}
public
String
getxPercent
()
{
return
xPercent
;
}
public
void
setxPercent
(
String
xPercent
)
{
this
.
xPercent
=
xPercent
;
}
public
String
getCaptchaSwitch
()
{
return
captchaSwitch
;
}
public
void
setCaptchaSwitch
(
String
captchaSwitch
)
{
this
.
captchaSwitch
=
captchaSwitch
;
}
public
String
getOriCopyImages
()
{
return
oriCopyImages
;
}
public
void
setOriCopyImages
(
String
oriCopyImages
)
{
this
.
oriCopyImages
=
oriCopyImages
;
}
public
String
getSlideImages
()
{
return
slideImages
;
}
public
void
setSlideImages
(
String
slideImages
)
{
this
.
slideImages
=
slideImages
;
}
}
src/main/java/cn/com/gsst/auth/common/rest/GoogleConfigRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
/**
* @author alex.yao
* @date 2024/12/24
*/
@Permission
(
Access
.
Anonymous
)
public
interface
GoogleConfigRest
extends
BaseRest
{
/**
* 获取谷歌client_id
*/
String
getClientId
();
}
src/main/java/cn/com/gsst/auth/common/rest/JudgeCodeRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
org.springframework.web.bind.annotation.RequestParam
;
@Permission
(
Access
.
Anonymous
)
public
interface
JudgeCodeRest
extends
BaseRest
{
/**
* 校验验证码是否正确
*
* @param account,code
* @throws Exception
*/
boolean
judgeCode
(
@RequestParam
String
account
,
@RequestParam
String
code
)
throws
Exception
;
/**
* 校验验证码是否正确,正确的话就返回授权码,可以给别的业务操作
*
* @param account,code
* @throws Exception
*/
String
judgeCodeReturnAuthCode
(
@RequestParam
String
account
,
@RequestParam
String
code
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/rest/SendEmailRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
org.springframework.web.bind.annotation.RequestParam
;
@Permission
(
Access
.
Anonymous
)
public
interface
SendEmailRest
extends
BaseRest
{
/**
* 发送邮件 验证码发送
* @param emailAddress
* @throws Exception
* */
void
sendEmailCode
(
@RequestParam
String
emailAddress
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/rest/SmsRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
org.springframework.web.bind.annotation.RequestParam
;
/**
* @author jennie.chen
* @date 2024/7/22
**/
@Permission
(
Access
.
Anonymous
)
public
interface
SmsRest
extends
BaseRest
{
/**
* 短信下发(获取验证码)
*
* @param phone
* @throws Exception
*/
void
smsDelivered
(
@RequestParam
String
phone
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/rest/impl/GoogleConfigRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
.
impl
;
import
cn.com.gsst.auth.common.rest.GoogleConfigRest
;
import
cn.com.yict.framemax.core.config.Config
;
import
org.springframework.stereotype.Component
;
/**
* @author alex.yao
* @date 2024/12/24
*/
@Component
public
class
GoogleConfigRestImpl
implements
GoogleConfigRest
{
private
final
String
CLIENT_ID
=
Config
.
get
(
"google.client.id"
);
@Override
public
String
getClientId
()
{
return
CLIENT_ID
;
}
}
src/main/java/cn/com/gsst/auth/common/rest/impl/JudgeCodeRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
.
impl
;
import
cn.com.gsst.auth.common.rest.JudgeCodeRest
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.service.JudgeCodeService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
@Service
public
class
JudgeCodeRestImpl
implements
JudgeCodeRest
{
@Resource
private
JudgeCodeService
judgeCodeService
;
@Override
public
boolean
judgeCode
(
String
account
,
String
code
)
throws
Exception
{
Assert
.
notBlank
(
account
);
Assert
.
notBlank
(
code
);
return
judgeCodeService
.
judgeCode
(
account
,
code
);
}
@Override
public
String
judgeCodeReturnAuthCode
(
String
account
,
String
code
)
throws
Exception
{
Assert
.
notBlank
(
account
);
Assert
.
notBlank
(
code
);
return
judgeCodeService
.
judgeCodeReturnAuthCode
(
account
,
code
);
}
}
src/main/java/cn/com/gsst/auth/common/rest/impl/SendEmailRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
.
impl
;
import
cn.com.gsst.auth.common.rest.SendEmailRest
;
import
cn.com.gsst.auth.common.service.SendEmailService
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
@Component
public
class
SendEmailRestImpl
implements
SendEmailRest
{
@Resource
private
SendEmailService
sendEmailService
;
@Override
public
void
sendEmailCode
(
String
emailAddress
)
throws
Exception
{
Assert
.
notBlank
(
emailAddress
);
sendEmailService
.
sendEmailCode
(
emailAddress
);
}
}
src/main/java/cn/com/gsst/auth/common/rest/impl/SmsRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
rest
.
impl
;
import
cn.com.gsst.auth.common.rest.SmsRest
;
import
cn.com.gsst.auth.common.service.SmsService
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.regex.Pattern
;
@Component
public
class
SmsRestImpl
implements
SmsRest
{
@Resource
private
SmsService
smsService
;
/**
* 短信下发(百度SMS)
*
* @param phone
* @throws Exception
*/
@Override
public
void
smsDelivered
(
String
phone
)
throws
Exception
{
Assert
.
notBlank
(
phone
);
//校验手机号格式(其中包含大陆和港澳台的校验)
//正则表达式使用了多个正则模式,每个模式使用|分隔,表示多个模式中的任何一个匹配即可。这样,它可以用于校验多种手机号的格式
boolean
matches
=
Pattern
.
matches
(
"(?:0|86|\\+86)?1[3-9]\\d{9}|"
+
//移动电话MOBILE
"(?:0|852|\\+852)?\\d{8}|"
+
//MOBILE_HK
"(?:0|886|\\+886)?(?:|-)09\\d{8}|"
+
//MOBILE_TW
"(?:0|853|\\+853)?(?:|-)6\\d{7}"
,
phone
);
//MOBILE_MO
Assert
.
isTrue
(
matches
);
smsService
.
smsDelivered
(
phone
);
}
}
src/main/java/cn/com/gsst/auth/common/service/JudgeCodeService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
;
public
interface
JudgeCodeService
{
/**
* 校验验证码是否正确
*
* @param account,code
* @throws Exception
*/
boolean
judgeCode
(
String
account
,
String
code
)
throws
Exception
;
/**
* 校验验证码是否正确,正确的话就返回授权码,可以给别的业务操作
*
* @param account,code
* @throws Exception
*/
String
judgeCodeReturnAuthCode
(
String
account
,
String
code
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/service/RedisService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
;
import
cn.com.yict.framemax.core.service.BaseService
;
import
org.springframework.data.redis.connection.RedisZSetCommands
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* Redis工具类
*/
public
interface
RedisService
extends
BaseService
{
/****************** common start ****************/
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public
boolean
expire
(
String
key
,
long
time
);
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public
long
getExpire
(
String
key
);
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public
boolean
hasKey
(
String
key
);
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
public
void
del
(
String
...
key
);
/**
* 根据key的前缀模糊删除数据
*
* @param keyPre redis中key的前缀
*/
public
void
delByPre
(
String
keyPre
);
/****************** common end ****************/
/****************** String start ****************/
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
);
/**
* 普通缓存获取 指定序列化对象
* @param key
* @param clazz
* @return
*/
<
T
>
T
get
(
String
key
,
Class
<
T
>
clazz
);
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public
boolean
set
(
String
key
,
Object
value
);
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public
boolean
set
(
String
key
,
Object
value
,
long
time
);
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public
long
incr
(
String
key
,
long
delta
);
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public
long
decr
(
String
key
,
long
delta
);
/****************** String end ****************/
/****************** Map start ****************/
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
);
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
);
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
);
/**
* 批量更新hash
*
* @param data 多个hash
* @param time 过期时间(秒),小于0时为不过期
* @return 是否成功操作
*/
public
boolean
hmSetBatch
(
Map
<
String
,
Map
<
String
,
Object
>>
data
,
long
time
);
/**
* 根据key前缀批量模糊批量查询hash类型的数据
*
* @param keyPre key前缀
* @return 有则返回数据,无则返回null
*/
public
Map
<
String
,
Map
<
String
,
Object
>>
hmDimMultiGet
(
String
keyPre
);
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
);
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
);
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
);
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public
void
hdel
(
String
key
,
Object
...
item
);
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public
boolean
hHasKey
(
String
key
,
String
item
);
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public
double
hincr
(
String
key
,
String
item
,
long
by
);
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public
double
hdecr
(
String
key
,
String
item
,
long
by
);
/****************** Map end ****************/
/****************** Set start ****************/
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public
Set
<
Object
>
sGet
(
String
key
);
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey
(
String
key
,
Object
value
);
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSet
(
String
key
,
Object
...
values
);
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
);
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public
long
sGetSetSize
(
String
key
);
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
long
setRemove
(
String
key
,
Object
...
values
);
/****************** Set end ****************/
/****************** ZSet start ****************/
/**
* @apiNote ZSet存放单个元素
* @param key 键
* @param value 值
* @param score 分数
* @return
*/
public
Boolean
zAdd
(
String
key
,
Object
value
,
Double
score
);
/**
* @apiNote 往ZSet中指定键批量插入数据
* @param key ZSet中键
* @param tuplesMap ZSet中value于score的映射,tuplesMap键为ZSet中的value,值为ZSet中的score
* @return
*/
public
Long
zBatchAdd
(
String
key
,
Map
<
Object
,
Double
>
tuplesMap
);
/**
* @apiNote 删除ZSet中指定键的一个或多个value
* @param key 键
* @param value ZSet中的一个或多个value
* @return
*/
public
Long
zRemove
(
String
key
,
Object
...
value
);
/**
* @apiNote 获取ZSet指定键的个数
* @param key 键
* @return
*/
public
Long
zGetSize
(
String
key
);
/**
* @apiNote 获取ZSet中指定键的指定分数段的value个数
* @param key 键
* @param minScore 分数范围左
* @param maxScore 分数范围右
* @return
*/
public
Long
zGetCount
(
String
key
,
Double
minScore
,
Double
maxScore
);
/**
* @apiNote 使用索引下标获取ZSet元素, [0,-1]表示全部元素,列表对于score顺数
* @param key 键
* @param start 开始索引
* @param end 结束索引
* @return
*/
public
Set
<
RedisZSetCommands
.
Tuple
>
zRangeWithScores
(
String
key
,
Integer
start
,
Integer
end
);
/**
* @apiNote 使用索引下标获取ZSet元素,[0,-1]表示全部元素,列表对于score倒数
* @param key 键
* @param start 开始索引
* @param end 结束索引
* @return
*/
public
Set
<
RedisZSetCommands
.
Tuple
>
zRevRangeWithScores
(
String
key
,
Integer
start
,
Integer
end
);
/**
* @apiNote 使用索引下标获取ZSet元素
* @param key 键
* @param start 索引开始
* @param end 索引结束
* @return
*/
public
Set
<
Object
>
zRange
(
String
key
,
Integer
start
,
Integer
end
);
/**
* @apiNote 使用索引下标获取ZSet元素,并从高到低排序
* @param key 键
* @param start 索引开始
* @param end 索引结束
* @return
*/
public
Set
<
Object
>
zReverseRange
(
String
key
,
Integer
start
,
Integer
end
);
/**
* @apiNote 获取ZSet中指定键指定value的分数
* @param key 键
* @param value ZSet中value
* @return
*/
public
Double
zGetScore
(
String
key
,
Object
value
);
/****************** ZSet end ****************/
/****************** List start ****************/
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
);
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public
long
lGetListSize
(
String
key
);
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public
Object
lGetIndex
(
String
key
,
long
index
);
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
);
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
);
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
);
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
);
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
);
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
long
lRemove
(
String
key
,
long
count
,
Object
value
);
/**
* 模糊匹配查询key
* @param key
* @return
*/
public
Set
<
String
>
keys
(
String
key
);
}
src/main/java/cn/com/gsst/auth/common/service/SendEmailService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
;
public
interface
SendEmailService
{
/**
* 发送邮箱 验证码发送
*
* */
void
sendEmailCode
(
String
emailAddress
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/service/SmsService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
;
public
interface
SmsService
{
/**
* 短信下发(获取验证码)
*
* @param phone
* @throws Exception
*/
void
smsDelivered
(
String
phone
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/common/service/impl/JudgeCodeServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
.
impl
;
import
cn.com.gsst.auth.common.constant.RedisKeyConstant
;
import
cn.com.gsst.auth.common.service.JudgeCodeService
;
import
cn.com.gsst.auth.common.service.RedisService
;
import
cn.com.gsst.auth.common.utils.UUIDTool
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.regex.Pattern
;
@Component
public
class
JudgeCodeServiceImpl
implements
JudgeCodeService
{
@Resource
private
RedisService
redisService
;
@Override
public
boolean
judgeCode
(
String
account
,
String
code
)
throws
Exception
{
//验证次数
String
accountKey
=
"JUDGE_CODE_COUNT:"
+
account
;
//校验校验验证码:从redis获取发送的验证码
String
mobileCode
=
(
String
)
redisService
.
get
(
account
);
if
(
StringUtils
.
isEmpty
(
mobileCode
))
{
throw
new
I18nMessageException
(
"exception/verification.code.has.expired.please.obtain.it.again"
);
}
// 防止撞库攻击
if
(!
redisService
.
hasKey
(
accountKey
))
{
redisService
.
set
(
accountKey
,
1
,
60
);
}
//如果没有验证过
int
verifyCount
=
Integer
.
parseInt
(
String
.
valueOf
(
redisService
.
get
(
accountKey
)));
if
(
verifyCount
>
5
)
{
throw
new
I18nMessageException
(
"exception/maximum.number.of.verifications.has.been.reached"
);
}
//验证次数自增
verifyCount
++;
redisService
.
set
(
accountKey
,
verifyCount
,
redisService
.
getExpire
(
accountKey
));
//验证逻辑
boolean
isValid
=
mobileCode
.
equals
(
code
);
//如果成功,删除验证码和验证码次数
if
(
isValid
)
{
redisService
.
del
(
account
);
redisService
.
del
(
accountKey
);
return
true
;
}
return
false
;
}
@Override
public
String
judgeCodeReturnAuthCode
(
String
account
,
String
code
)
throws
Exception
{
//验证验证码是否正确
if
(!
judgeCode
(
account
,
code
))
{
return
StringUtils
.
EMPTY
;
}
//验证次数
String
authCode
=
UUIDTool
.
getUUID
();
//校验手机号格式
boolean
matches
=
Pattern
.
matches
(
"(?:0|86|\\+86)?1[3-9]\\d{9}|"
+
"(?:0|852|\\+852)?\\d{8}|"
+
"(?:0|886|\\+886)?(?:|-)09\\d{8}|"
+
"(?:0|853|\\+853)?(?:|-)6\\d{7}"
,
account
);
if
(
matches
){
//是手机号
redisService
.
set
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
account
,
authCode
,
60
*
5
);
}
else
{
redisService
.
set
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
account
,
authCode
,
60
*
15
);
}
return
authCode
;
}
}
src/main/java/cn/com/gsst/auth/common/service/impl/RedisServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
.
impl
;
import
cn.com.gsst.auth.common.service.RedisService
;
import
cn.com.gsst.auth.common.utils.JsonUtils
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.connection.RedisZSetCommands
;
import
org.springframework.data.redis.core.*
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
@Component
public
class
RedisServiceImpl
implements
RedisService
{
@Resource
(
name
=
"redisTemplate"
)
private
RedisTemplate
redisTemplate
;
/****************** common start ****************/
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
@Override
public
boolean
expire
(
String
key
,
long
time
)
{
try
{
if
(
time
>
0
)
{
redisTemplate
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
@Override
public
long
getExpire
(
String
key
)
{
return
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
@Override
public
boolean
hasKey
(
String
key
)
{
try
{
return
redisTemplate
.
hasKey
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
@Override
public
void
del
(
String
...
key
)
{
if
(
key
!=
null
&&
key
.
length
>
0
)
{
if
(
key
.
length
==
1
)
{
redisTemplate
.
delete
(
key
[
0
]);
}
else
{
// redisTemplate.delete(CollectionUtils.arrayToList(key));
}
}
}
/**
* 根据key的前缀模糊删除数据
*
* @param keyPre redis中key的前缀
*/
@Override
public
void
delByPre
(
String
keyPre
)
{
keyPre
=
keyPre
+
"**"
;
Set
<
String
>
keys
=
redisTemplate
.
keys
(
keyPre
);
if
(
CollectionUtils
.
isNotEmpty
(
keys
))
{
redisTemplate
.
delete
(
keys
);
}
}
/****************** common end ****************/
/****************** String start ****************/
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
@SuppressWarnings
(
"unchecked"
)
@Override
public
Object
get
(
String
key
)
{
return
key
==
null
?
null
:
redisTemplate
.
opsForValue
().
get
(
key
);
}
/**
* 普通缓存获取 指定序列化对象
*
* @param key
* @param clazz
* @return
*/
@Override
public
<
T
>
T
get
(
String
key
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
key
))
{
return
null
;
}
Object
obj
=
redisTemplate
.
opsForValue
().
get
(
key
);
return
JsonUtils
.
convert
(
obj
,
clazz
);
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
@SuppressWarnings
(
"unchecked"
)
@Override
public
boolean
set
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
@Override
public
boolean
set
(
String
key
,
Object
value
,
long
time
)
{
try
{
if
(
time
>
0
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
else
{
set
(
key
,
value
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
@Override
public
long
incr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
try
{
return
redisTemplate
.
opsForValue
().
increment
(
key
,
delta
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
@Override
public
long
decr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
try
{
return
redisTemplate
.
opsForValue
().
increment
(
key
,
-
delta
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/****************** String end ****************/
/****************** Map start ****************/
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
@Override
public
Object
hget
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
@Override
public
Map
<
Object
,
Object
>
hmget
(
String
key
)
{
return
redisTemplate
.
opsForHash
().
entries
(
key
);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
@Override
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
)
{
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 批量更新hash
*
* @param data 多个hash
* @param time 过期时间(秒),小于0时为不过期
* @return 是否成功操作
*/
@Override
public
boolean
hmSetBatch
(
Map
<
String
,
Map
<
String
,
Object
>>
data
,
long
time
)
{
//参数判空
if
(
MapUtils
.
isEmpty
(
data
))
{
return
true
;
}
//管道批处理
redisTemplate
.
executePipelined
(
new
SessionCallback
<
Object
>()
{
@Override
public
<
K
,
V
>
Object
execute
(
RedisOperations
<
K
,
V
>
operations
)
throws
DataAccessException
{
RedisOperations
<
String
,
Object
>
redisOperations
=
(
RedisOperations
<
String
,
Object
>)
operations
;
for
(
String
key
:
data
.
keySet
())
{
//批量更新
redisOperations
.
opsForHash
().
putAll
(
key
,
data
.
get
(
key
));
//有设置过期时间时过期
if
(
time
>
0
)
{
redisOperations
.
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
}
return
null
;
}
});
return
true
;
}
/**
* 根据key前缀批量模糊批量查询hash类型的数据
*
* @param keyPre key前缀
* @return 有则返回数据,无则返回null
*/
@Override
public
Map
<
String
,
Map
<
String
,
Object
>>
hmDimMultiGet
(
String
keyPre
)
{
Map
<
String
,
Map
<
String
,
Object
>>
returnData
=
new
HashMap
<>();
//前缀
keyPre
=
keyPre
+
"**"
;
//获取所有的key
Set
<
String
>
keys
=
redisTemplate
.
keys
(
keyPre
);
if
(
CollectionUtils
.
isNotEmpty
(
keys
))
{
for
(
String
key
:
keys
)
{
//查询key的value
Map
<
Object
,
Object
>
hashObject
=
redisTemplate
.
opsForHash
().
entries
(
key
);
//类型转换,使用entrySet避免了使用keySet多次get()查找的效率损耗
Map
<
String
,
Object
>
hashString
=
new
HashMap
<>();
for
(
Map
.
Entry
<
Object
,
Object
>
entry
:
hashObject
.
entrySet
())
{
hashString
.
put
((
String
)
entry
.
getKey
(),
entry
.
getValue
());
}
returnData
.
put
(
key
,
hashString
);
}
return
returnData
;
}
return
null
;
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
@Override
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
)
{
try
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
map
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
@Override
public
boolean
hset
(
String
key
,
String
item
,
Object
value
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
@Override
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForHash
().
put
(
key
,
item
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
@Override
public
void
hdel
(
String
key
,
Object
...
item
)
{
try
{
redisTemplate
.
opsForHash
().
delete
(
key
,
item
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
@Override
public
boolean
hHasKey
(
String
key
,
String
item
)
{
return
redisTemplate
.
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
@Override
public
double
hincr
(
String
key
,
String
item
,
long
by
)
{
try
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
by
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
@Override
public
double
hdecr
(
String
key
,
String
item
,
long
by
)
{
try
{
return
redisTemplate
.
opsForHash
().
increment
(
key
,
item
,
-
by
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/****************** Map end ****************/
/****************** Set start ****************/
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
@Override
public
Set
<
Object
>
sGet
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
@Override
public
boolean
sHasKey
(
String
key
,
Object
value
)
{
try
{
return
redisTemplate
.
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
@Override
public
long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
@Override
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
add
(
key
,
values
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
count
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
@Override
public
long
sGetSetSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
@Override
public
long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
Long
count
=
redisTemplate
.
opsForSet
().
remove
(
key
,
values
);
return
count
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/****************** Set end ****************/
/**
* ZSet start
*
* Redis zset 和 set 一样也是string类型元素的集合,且不允许重复的成员。
* 不同的是每个元素都会关联一个double类型的分数。
* redis正是通过分数来为集合中的成员进行从小到大的排序。
* zset的成员是唯一的,但分数(score)却可以重复。
*/
/**
* @param key 键
* @param value 值
* @param score 分数
* @return
* @apiNote ZSet存放单个元素
*/
@Override
public
Boolean
zAdd
(
String
key
,
Object
value
,
Double
score
)
{
try
{
return
redisTemplate
.
opsForZSet
().
add
(
key
,
value
,
score
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* @param key ZSet中键
* @param tuplesMap ZSet中value于score的映射,tuplesMap键为ZSet中的value,值为ZSet中的score
* @return
* @apiNote 往ZSet中指定键批量插入数据
*/
@Override
public
Long
zBatchAdd
(
String
key
,
Map
<
Object
,
Double
>
tuplesMap
)
{
try
{
if
(
tuplesMap
.
size
()
==
0
)
{
return
0L
;
}
Set
<
ZSetOperations
.
TypedTuple
<
Object
>>
tuplesSet
=
new
HashSet
<>();
for
(
Map
.
Entry
<
Object
,
Double
>
tuplesMapEntry
:
tuplesMap
.
entrySet
())
{
tuplesSet
.
add
(
new
DefaultTypedTuple
<>(
tuplesMapEntry
.
getKey
(),
tuplesMapEntry
.
getValue
()));
}
return
redisTemplate
.
opsForZSet
().
add
(
key
,
tuplesSet
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* @param key 键
* @param value ZSet中的一个或多个value
* @return
* @apiNote 删除ZSet中指定键的一个或多个value
*/
@Override
public
Long
zRemove
(
String
key
,
Object
...
value
)
{
try
{
return
redisTemplate
.
opsForZSet
().
remove
(
key
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* @param key 键
* @return
* @apiNote 获取ZSet指定键的个数
*/
@Override
public
Long
zGetSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForZSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* @param key 键
* @param minScore 分数范围左
* @param maxScore 分数范围右
* @return
* @apiNote 获取ZSet中指定键的指定分数段的value个数
*/
@Override
public
Long
zGetCount
(
String
key
,
Double
minScore
,
Double
maxScore
)
{
try
{
return
redisTemplate
.
opsForZSet
().
count
(
key
,
minScore
,
maxScore
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0L
;
}
}
/**
* @param key 键
* @param start 开始索引
* @param end 结束索引
* @return
* @apiNote 使用索引下标获取ZSet元素, [0,-1]表示全部元素,列表对于score顺数
*/
@Override
public
Set
<
RedisZSetCommands
.
Tuple
>
zRangeWithScores
(
String
key
,
Integer
start
,
Integer
end
)
{
try
{
/**
* 从回调外部获取连接打开一个新连接,并在等待响应的情况下执行Redis命令-
* 没有流水线应用于任何外部获得的连接。
* 防止当流水线会话同步并executePipelined(…)终止时,不会在回调内收到结果值,而是在最后。
*/
RedisConnection
connection
=
redisTemplate
.
getConnectionFactory
().
getConnection
();
return
connection
.
zRangeWithScores
(
key
.
getBytes
(),
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* @param key 键
* @param start 开始索引
* @param end 结束索引
* @return
* @apiNote 使用索引下标获取ZSet元素, [0,-1]表示全部元素,列表对于score倒数
*/
@Override
public
Set
<
RedisZSetCommands
.
Tuple
>
zRevRangeWithScores
(
String
key
,
Integer
start
,
Integer
end
)
{
try
{
/**
* 从回调外部获取连接打开一个新连接,并在等待响应的情况下执行Redis命令-
* 没有流水线应用于任何外部获得的连接。
* 防止当流水线会话同步并executePipelined(…)终止时,不会在回调内收到结果值,而是在最后。
*/
RedisConnection
connection
=
redisTemplate
.
getConnectionFactory
().
getConnection
();
return
connection
.
zRevRangeWithScores
(
key
.
getBytes
(),
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* @param key 键
* @param start 索引开始
* @param end 索引结束
* @return
* @apiNote 使用索引下标获取ZSet元素的value值集合, [0,-1]表示全部元素
*/
@Override
public
Set
<
Object
>
zRange
(
String
key
,
Integer
start
,
Integer
end
)
{
try
{
return
redisTemplate
.
opsForZSet
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* @param key 键
* @param start 索引开始
* @param end 索引结束
* @return
* @apiNote 使用索引下标获取ZSet元素的value值集合, 并从高到低排序, [0,-1]表示全部元素
*/
@Override
public
Set
<
Object
>
zReverseRange
(
String
key
,
Integer
start
,
Integer
end
)
{
try
{
return
redisTemplate
.
opsForZSet
().
reverseRange
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* @param key 键
* @param value ZSet中value
* @return
* @apiNote 获取ZSet中指定键指定value的分数
*/
@Override
public
Double
zGetScore
(
String
key
,
Object
value
)
{
try
{
return
redisTemplate
.
opsForZSet
().
score
(
key
,
value
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/****************** ZSet end ****************/
/****************** List start ****************/
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
@Override
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
)
{
try
{
return
redisTemplate
.
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
@Override
public
long
lGetListSize
(
String
key
)
{
try
{
return
redisTemplate
.
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
0
;
}
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
@Override
public
Object
lGetIndex
(
String
key
,
long
index
)
{
try
{
return
redisTemplate
.
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
@Override
public
boolean
lSet
(
String
key
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
@Override
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPush
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
@Override
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
@Override
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
)
{
try
{
redisTemplate
.
opsForList
().
rightPushAll
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
@Override
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
)
{
try
{
redisTemplate
.
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
@Override
public
long
lRemove
(
String
key
,
long
count
,
Object
value
)
{
try
{
Long
remove
=
redisTemplate
.
opsForList
().
remove
(
key
,
count
,
value
);
return
remove
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
I18nMessageException
(
e
.
getMessage
());
}
}
/**
* 模糊匹配查询key
*
* @param key
* @return
*/
@Override
public
Set
<
String
>
keys
(
String
key
)
{
return
redisTemplate
.
keys
(
key
);
}
}
src/main/java/cn/com/gsst/auth/common/service/impl/SendEmailServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
.
impl
;
import
cn.com.gsst.auth.common.service.RedisService
;
import
cn.com.gsst.auth.common.service.SendEmailService
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.utils.DateUtils
;
import
cn.com.gsst.auth.common.utils.RandomCodeUtils
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.frame.entity.EmailSenderEntity
;
import
cn.com.yict.framemax.frame.service.EmailSenderService
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.LinkedList
;
import
java.util.List
;
@Service
public
class
SendEmailServiceImpl
implements
SendEmailService
{
@Resource
private
EmailSenderService
emailSenderService
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Resource
private
RedisService
redisService
;
@Override
public
void
sendEmailCode
(
String
emailAddress
)
throws
Exception
{
Assert
.
notBlank
(
emailAddress
);
EmailSenderEntity
entity
=
new
EmailSenderEntity
();
String
code
=
RandomCodeUtils
.
generateNumber
(
6
);
String
projectName
=
fmxParamConfigService
.
getParam
(
"project.name"
);
String
body
=
fmxParamConfigService
.
getParam
(
"login.email.send.body"
);
body
=
body
.
replaceAll
(
"\\$\\{projectName}"
,
projectName
)
.
replaceAll
(
"\\$\\{emailAddress}"
,
emailAddress
)
.
replaceAll
(
"\\$\\{authCode}"
,
code
)
.
replaceAll
(
"\\$\\{CurrDate}"
,
DateUtils
.
getCurrDate
());
entity
.
setBody
(
body
);
entity
.
setSubject
(
"用户邮箱校验"
);
List
<
String
>
list
=
new
LinkedList
<>();
list
.
add
(
emailAddress
);
entity
.
setTo
(
list
);
//接收者
try
{
// 如果成功发送,则把验证码存入redis当中,并设置15分钟的过期时间
emailSenderService
.
sendMail
(
entity
,
null
);
redisService
.
set
(
emailAddress
,
code
,
900
);
}
catch
(
Exception
e
)
{
throw
new
I18nMessageException
(
"exception/verification.code.sending.failed.please.try.again"
);
}
}
}
src/main/java/cn/com/gsst/auth/common/service/impl/SmsServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
service
.
impl
;
import
cn.com.gsst.auth.common.dto.SmsDto
;
import
cn.com.gsst.auth.common.service.SmsService
;
import
cn.com.gsst.auth.common.service.RedisService
;
import
cn.com.gsst.auth.support.sms.channel.baidu.BaiDuThirdPlatformService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Random
;
@Service
public
class
SmsServiceImpl
implements
SmsService
{
@Resource
private
BaiDuThirdPlatformService
baiDuThirdPlatformService
;
@Resource
private
RedisService
redisService
;
@Override
public
void
smsDelivered
(
String
phone
)
throws
Exception
{
SmsDto
smsDto
=
new
SmsDto
();
Random
random
=
new
Random
();
// 随机生成六位数的随机数字
int
randomNum
=
100000
+
random
.
nextInt
(
900000
);
// 生成[10000, 99999]范围内的随机数
String
code
=
Integer
.
toString
(
randomNum
);
smsDto
.
setMobilePhone
(
phone
);
smsDto
.
setSmsCode
(
code
);
boolean
isSend
=
baiDuThirdPlatformService
.
doSend
(
smsDto
);
if
(
isSend
)
{
// 如果成功发送,则把验证码存入redis当中,并设置五分钟的过期时间
redisService
.
set
(
phone
,
code
,
300
);
}
else
{
throw
new
I18nMessageException
(
"exception/verification.code.sending.failed.please.try.again"
);
}
}
}
src/main/java/cn/com/gsst/auth/common/utils/Assert.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
public
class
Assert
extends
org
.
springframework
.
util
.
Assert
{
public
static
void
notBlank
(
String
text
)
{
if
(
StringUtils
.
isBlank
(
text
))
{
throw
new
IllegalArgumentException
(
"缺少必要参数"
);
}
}
public
static
void
notBlank
(
String
text
,
String
message
)
{
if
(
StringUtils
.
isBlank
(
text
))
{
throw
new
IllegalArgumentException
(
"缺少必要参数-["
+
message
+
"]"
);
}
}
public
static
void
notNull
(
Object
text
,
String
message
)
{
if
(
text
==
null
)
{
throw
new
IllegalArgumentException
(
"缺少必要参数-["
+
message
+
"]"
);
}
}
}
src/main/java/cn/com/gsst/auth/common/utils/BlContext.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
cn.com.gsst.auth.support.security.oauth.constants.OauthConstants
;
import
cn.com.gsst.auth.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.yict.framemax.core.context.Context
;
import
cn.com.yict.framemax.data.model.UserBaseModel
;
import
cn.com.yict.framemax.security.oauth.exception.TokenExpiredException
;
import
org.springframework.beans.BeanUtils
;
/**
* @author Focan Zhong
* @create 2021/8/6
*/
public
class
BlContext
{
/**
* 获取上下文用户
*
* @return
*/
public
static
UserBaseEntity
getCurrentUser
()
{
UserBaseModel
userBaseModel
=
Context
.
get
().
getCurrentUser
();
if
(
userBaseModel
==
null
)
{
throw
new
TokenExpiredException
();
}
return
distinguishUserType
(
userBaseModel
);
}
/**
* 获取上下文用户 无异常
*
* @return
*/
public
static
UserBaseEntity
getCurrentUserNotException
()
{
UserBaseModel
userBaseModel
=
Context
.
get
().
getCurrentUser
();
if
(
userBaseModel
==
null
)
{
return
null
;
}
return
distinguishUserType
(
userBaseModel
);
}
/**
* 区分用户类型
*
* @param userBaseModel
* @return
*/
private
static
UserBaseEntity
distinguishUserType
(
UserBaseModel
userBaseModel
)
{
UserBaseEntity
userBaseEntity
=
new
UserBaseEntity
();
BeanUtils
.
copyProperties
(
userBaseModel
,
userBaseEntity
);
if
(
Context
.
get
().
getCurrentUser
()
instanceof
MemberInfoEntity
)
{
userBaseEntity
.
setType
(
OauthConstants
.
OauthEnum
.
MEMBER_DOMAIN
.
name
());
}
return
userBaseEntity
;
}
/**
* 获取当前系统语言[小写]
*/
public
static
String
getCurrentLocaleLanguageToLowerCase
()
{
return
Context
.
get
().
getMessageSource
().
getCurrentLocale
().
toLanguageTag
().
toLowerCase
();
}
}
src/main/java/cn/com/gsst/auth/common/utils/DateUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParsePosition
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* <p>
* Title: 基础类
* </p>
* <p>
* Description: 日期转换
* </p>
* <p>
* Copyright: Copyright (c) 2002
* </p>
* <p>
* Company:
* </p>
*
* @version 1.0
*/
public
class
DateUtils
{
public
static
class
DateFormats
{
public
static
final
String
ISO_DATETIME_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
ISO_DATETIME_TIME_ZONE_FORMAT
=
"yyyy-MM-dd HH:mm:ssZ"
;
public
static
final
String
ISO_DATETIME_NO_SECOND_FORMAT
=
"yyyy-MM-dd HH:mm"
;
public
static
final
String
CN_DATETIME_FORMAT
=
"yyyy年MM月dd日HH时mm分ss秒"
;
public
static
final
String
CN_SHORT_DATETIME_FORMAT
=
"yyyy年MM月dd日HH时mm分"
;
public
static
final
String
ISO_DATETIME_MILLISECOND_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ss.SSS"
;
public
static
final
String
ISO_DATETIME_T_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ss"
;
public
static
final
String
ISO_DATETIME_T_TIME_ZONE_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ssZ"
;
public
static
final
String
ISO_DATETIME_MILLISECOND_TIME_ZONE_FORMAT
=
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
;
public
static
final
String
ISO_DATETIME_NO_T_FORMAT
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
ISO_DATETIME_TIME_ZONE_NO_T_FORMAT
=
"yyyy-MM-dd HH:mm:ssZ"
;
public
static
final
String
ISO_DATETIME_NO_SECOND_NO_T_FORMAT
=
"yyyy-MM-dd HH:mm"
;
public
static
final
String
ISO_DATETIME_MILLISECOND_NO_T_FORMAT
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
public
static
final
String
ISO_DATETIME_MILLISECOND_TIME_ZONE_NO_T_FORMAT
=
"yyyy-MM-dd HH:mm:ss.SSSZ"
;
public
static
final
String
ISO_DATE_FORMAT
=
"yyyy-MM-dd"
;
public
static
final
String
CN_DATE_FORMAT
=
"yyyy年MM月dd日"
;
public
static
final
String
ISO_DATE_TIME_ZONE_FORMAT
=
"yyyy-MM-ddZ"
;
public
static
final
String
ISO_TIME_FORMAT
=
"'T'HH:mm:ss"
;
public
static
final
String
ISO_TIME_MILLISECOND_FORMAT
=
"'T'HH:mm:ss.SSS"
;
public
static
final
String
ISO_TIME_TIME_ZONE_FORMAT
=
"'T'HH:mm:ssZZ"
;
public
static
final
String
ISO_TIME_MILLISECOND_TIME_ZONE_FORMAT
=
"'T'HH:mm:ss.SSSZ"
;
public
static
final
String
ISO_TIME_NO_T_FORMAT
=
"HH:mm:ss"
;
public
static
final
String
ISO_TIME_MILLISECOND_NO_T_FORMAT
=
"HH:mm:ss.SSS"
;
public
static
final
String
CN_TIME_FORMAT
=
"HH时mm分ss秒"
;
public
static
final
String
ISO_TIME_NO_T_TIME_ZONE_FORMAT
=
"HH:mm:ssZZ"
;
public
static
final
String
ISO_TIME_MILLISECOND_NO_T_TIME_ZONE_FORMAT
=
"HH:mm:ss.SSSZ"
;
public
static
final
String
SMTP_DATETIME_FORMAT
=
"EEE, dd MMM yyyy HH:mm:ss Z"
;
public
static
final
String
SMTP_DATETIME_MILLISECOND_FORMAT
=
"EEE, dd MMM yyyy HH:mm:ss.SSS Z"
;
public
static
final
String
ISO_MONTH_FORMAT
=
"yyyy-MM"
;
public
static
final
String
CN_MONTH_FORMAT
=
"yyyy年MM月"
;
public
static
final
String
US_DATETIME_TIME_ZONE_FORMAT
=
"EEE MMM dd HH:mm:ss zzz yyyy"
;
}
public
static
org
.
apache
.
commons
.
lang3
.
time
.
DateUtils
commonDateUtils
;
/**
* Date Style
*/
public
static
final
String
DATESTYLE
=
"yyyyMMddHHmmss"
;
/**
* Date Style for Extention
*/
public
static
final
String
DATESTYLE_EX
=
"yyyy-MM-dd_HH-mm-ss"
;
/**
* Date Style for Extention
*/
public
static
final
String
DATESTYLE_
=
"yyyy-MM-dd"
;
/**
* Date Style for Year & Month
*/
public
static
final
String
DATESTYLE_YEAR_MONTH
=
"yyyyMM"
;
/**
* Date Style for Short
*/
public
static
final
String
DATESTYLE_SHORT
=
"yyyyMMdd"
;
/**
* Date Style for Extention
*/
public
static
final
String
DATESTYLE_SHORT_EX
=
"yyyy/MM/dd"
;
/**
* Date Style for Year & Month Extention
*/
public
static
final
String
DATESTYLE_YEAR_MONTH_EX
=
"yyyy/MM"
;
/**
* Date Style for detail
*/
public
static
final
String
DATESTYLE_DETAIL
=
"yyyyMMddHHmmssSSS"
;
public
static
final
String
yyyy_MM_dd_HH_mm_ss
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
yyyy_MM_dd
=
"yyyy-MM-dd"
;
public
static
final
String
yyyyMMdd
=
"yyyyMMdd"
;
public
static
final
String
HHmm
=
"HH:mm"
;
/**
* 日期转化为字符串
*
* @param date 时间
* @return yyyy-MM-dd HH:mm:ss 格式化的时间字符串
*/
public
static
String
dateToString
(
Date
date
)
{
if
(
date
==
null
)
{
return
""
;
}
return
formatDate
(
date
,
"yyyy-MM-dd HH:mm:ss"
);
}
/**
* 日期转化为字符串
*
* @param date 时间
* @return yyyy-MM-dd 格式化的时间字符串
*/
public
static
String
dateToStringShort
(
Date
date
)
{
if
(
date
==
null
)
{
return
""
;
}
return
formatDate
(
date
,
"yyyy-MM-dd"
);
}
/**
* 计算两个日期差(毫秒)
*
* @param date1 时间1
* @param date2 时间2
* @return 相差毫秒数
*/
public
static
long
diffTwoDate
(
Date
date1
,
Date
date2
)
{
long
l1
=
date1
.
getTime
();
long
l2
=
date2
.
getTime
();
return
(
l1
-
l2
);
}
/**
* 计算两个日期差(天)
*
* @param date1 时间1
* @param date2 时间2
* @return 相差天数
*/
public
static
int
diffTwoDateDay
(
Date
date1
,
Date
date2
)
{
long
l1
=
date1
.
getTime
();
long
l2
=
date2
.
getTime
();
int
diff
=
Integer
.
parseInt
(
""
+
(
l1
-
l2
)
/
3600
/
24
/
1000
);
return
diff
;
}
/**
* 计算两个日期差(天)
*
* @param date1 时间1
* @param date2 时间2
* @return 相差天数
*/
public
static
int
diffTwoDateNaturalDay
(
Date
date1
,
Date
date2
)
{
return
diffTwoDateDay
(
getDayStartTime
(
date1
),
getDayStartTime
(
date2
));
}
/**
* @return 相差时间 格式: XX天XX小时XX分钟
*/
public
static
String
diffTwoDateDHM
(
Date
start
,
Date
end
)
{
if
(
start
==
null
&&
end
==
null
)
{
return
"0天0小时0分"
;
}
if
(
start
==
null
||
end
==
null
)
{
return
null
;
}
int
diffMinutes
=
Integer
.
parseInt
((
end
.
getTime
()
-
start
.
getTime
())
/
1000
/
60
+
""
);
int
days
=
Integer
.
parseInt
(
diffMinutes
/
60
/
24
+
""
);
int
hours
=
Integer
.
parseInt
((
diffMinutes
-
60
*
24
*
days
)
/
60
+
""
);
int
minutes
=
diffMinutes
-
60
*
24
*
days
-
60
*
hours
;
return
days
+
"天"
+
hours
+
"小时"
+
minutes
+
"分"
;
}
/**
* 对日期进行格式化
*
* @param date 日期
* @param sf 日期格式
* @return 字符串
*/
public
static
String
formatDate
(
Date
date
,
String
sf
)
{
if
(
date
==
null
)
{
return
""
;
}
SimpleDateFormat
dateformat
=
new
SimpleDateFormat
(
sf
);
return
dateformat
.
format
(
date
);
}
/**
* 取得当前系统日期
*
* @return yyyy-MM-dd
*/
public
static
String
getCurrDate
()
{
Date
dateTime
=
new
Date
();
return
formatDate
(
dateTime
,
"yyyy-MM-dd"
);
}
// 取系统时间时一定要用这个方法,否则日期可能不动
public
static
Date
getCurrDateTime
()
{
return
new
Date
(
System
.
currentTimeMillis
());
}
/**
* 取得当前系统时间
*
* @return yyyy-MM-dd HH:mm:ss
*/
public
static
String
getCurrTime
()
{
Date
dateTime
=
new
Date
();
return
formatDate
(
dateTime
,
"yyyy-MM-dd HH:mm:ss"
);
}
/**
* 10位时间转为8时间
*
* @param str
* @return
*/
public
static
String
getDate10to8
(
String
str
)
{
String
y
=
str
.
substring
(
0
,
4
);
String
m
=
str
.
substring
(
5
,
7
);
String
d
=
str
.
substring
(
8
,
10
);
return
y
+
m
+
d
;
}
/**
* 8位时间转为10时间
*
* @param str
* @return
*/
public
static
String
getDate8to10
(
String
str
)
{
String
y
=
str
.
substring
(
0
,
4
);
String
m
=
str
.
substring
(
4
,
6
);
String
d
=
str
.
substring
(
6
,
8
);
return
y
+
"-"
+
m
+
"-"
+
d
;
}
/**
* 取得日期的天份
*
* @param date 日期
* @return dd 天字符串
*/
public
static
String
getDay
(
Date
date
)
{
return
formatDate
(
date
,
"dd"
);
}
/**
* 取得日期的小时
*
* @param date 日期
* @return hh 小时字符串
*/
public
static
String
getHour
(
Date
date
)
{
return
formatDate
(
date
,
"HH"
);
}
/**
* 取得日期的分钟
*
* @param date 时间
* @return mm 分钟字符串
*/
public
static
String
getMinute
(
Date
date
)
{
return
formatDate
(
date
,
"mm"
);
}
/**
* 取得日期的月份
*
* @param date 日期
* @return mm 月份字符串
*/
public
static
String
getMonth
(
Date
date
)
{
return
formatDate
(
date
,
"MM"
);
}
public
static
int
getMonth
(
Date
start
,
Date
end
)
{
if
(
start
.
after
(
end
))
{
Date
t
=
start
;
start
=
end
;
end
=
t
;
}
Calendar
startCalendar
=
Calendar
.
getInstance
();
startCalendar
.
setTime
(
start
);
Calendar
endCalendar
=
Calendar
.
getInstance
();
endCalendar
.
setTime
(
end
);
Calendar
temp
=
Calendar
.
getInstance
();
temp
.
setTime
(
end
);
temp
.
add
(
Calendar
.
DATE
,
1
);
int
year
=
endCalendar
.
get
(
Calendar
.
YEAR
)
-
startCalendar
.
get
(
Calendar
.
YEAR
);
int
month
=
endCalendar
.
get
(
Calendar
.
MONTH
)
-
startCalendar
.
get
(
Calendar
.
MONTH
);
if
((
startCalendar
.
get
(
Calendar
.
DATE
)
==
1
)
&&
(
temp
.
get
(
Calendar
.
DATE
)
==
1
))
{
return
year
*
12
+
month
+
1
;
}
else
if
((
startCalendar
.
get
(
Calendar
.
DATE
)
!=
1
)
&&
(
temp
.
get
(
Calendar
.
DATE
)
==
1
))
{
return
year
*
12
+
month
;
}
else
if
((
startCalendar
.
get
(
Calendar
.
DATE
)
==
1
)
&&
(
temp
.
get
(
Calendar
.
DATE
)
!=
1
))
{
return
year
*
12
+
month
;
}
else
{
return
(
year
*
12
+
month
-
1
)
<
0
?
0
:
(
year
*
12
+
month
);
}
}
/**
* 取得时间的秒
*
* @param date 时间
* @return ss 秒字符串
*/
public
static
String
getSecond
(
Date
date
)
{
return
formatDate
(
date
,
"ss"
);
}
/**
* 根据年、月取得月末的日期
*
* @param year 年
* @return time 返回日期格式"yyyy-mm-dd"
* @parm month 月
*/
public
static
String
getTime
(
String
year
,
String
month
)
{
String
time
=
""
;
int
len
=
31
;
int
iYear
=
Integer
.
parseInt
(
year
);
int
iMonth
=
Integer
.
parseInt
(
month
);
if
(
iMonth
==
4
||
iMonth
==
6
||
iMonth
==
9
||
iMonth
==
11
)
{
len
=
30
;
}
if
(
iMonth
==
2
)
{
len
=
28
;
if
((
iYear
%
4
==
0
&&
iYear
%
100
==
0
&&
iYear
%
400
==
0
)
||
(
iYear
%
4
==
0
&&
iYear
%
100
!=
0
))
{
len
=
29
;
}
}
time
=
year
+
"-"
+
month
+
"-"
+
String
.
valueOf
(
len
);
return
time
;
}
/**
* 取得日期的年份
*
* @param date 日期
* @return yyyy 年份字符串
*/
public
static
String
getYear
(
Date
date
)
{
return
formatDate
(
date
,
"yyyy"
);
}
/**
* 字符串转换为日期
*
* @param dateString yyyy-MM-dd HH:mm:ss
* @return 日期
*/
public
static
Date
stringToDate
(
String
dateString
)
{
if
(
dateString
==
null
||
dateString
.
trim
().
length
()
==
0
)
{
return
null
;
}
String
datestr
=
dateString
.
trim
();
String
sf
=
"yyyy-MM-dd HH:mm:ss"
;
Date
dt
=
stringToDate
(
datestr
,
sf
);
if
(
dt
==
null
)
{
dt
=
stringToDate
(
datestr
,
"yyyy-MM-dd"
);
}
if
(
dt
==
null
)
{
dt
=
stringToDate
(
datestr
,
"yyyyMMdd"
);
}
return
dt
;
}
/**
* 字符串转换为日期
*
* @param dateString 日期格式字符串
* @param sf 日期格式化定义
* @return 转换后的日期
*/
public
static
Date
stringToDate
(
String
dateString
,
String
sf
)
{
ParsePosition
pos
=
new
ParsePosition
(
0
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
sf
);
Date
dt
=
sdf
.
parse
(
dateString
,
pos
);
return
dt
;
}
/**
* 字符串转换为日期
*
* @param dateString yyyy-MM-dd
* @return 日期
*/
public
static
Date
stringToDateShort
(
String
dateString
)
{
String
sf
=
"yyyy-MM-dd"
;
Date
dt
=
stringToDate
(
dateString
,
sf
);
return
dt
;
}
/**
* 取得日以上粒度起始时间
*
* @param granularity 粒度
* @param statisticDate 结束时间
* @return 起始时间
*/
public
String
getBeginDate
(
String
granularity
,
String
statisticDate
)
{
String
beginDate
=
""
;
Date
date
=
stringToDateShort
(
statisticDate
);
Date
beginDateTemp
=
null
;
if
(
granularity
.
equals
(
"1"
))
{
// 日
beginDateTemp
=
date
;
}
if
(
granularity
.
equals
(
"2"
))
{
// 周
beginDateTemp
=
getWeekBegin
(
date
);
}
if
(
granularity
.
equals
(
"3"
))
{
// 旬
beginDateTemp
=
getPeriodBegin
(
date
);
}
else
if
(
granularity
.
equals
(
"4"
))
{
// 月
beginDateTemp
=
getMonthBegin
(
date
);
}
else
if
(
granularity
.
equals
(
"5"
))
{
// 季
beginDateTemp
=
getSeasonBegin
(
date
);
}
else
if
(
granularity
.
equals
(
"6"
))
{
// 半年
beginDateTemp
=
getHalfYearBegin
(
date
);
}
else
if
(
granularity
.
equals
(
"7"
))
{
// 年
beginDateTemp
=
getYearBegin
(
date
);
}
beginDate
=
dateToStringShort
(
beginDateTemp
);
return
beginDate
;
}
/**
* @param currentTime 计算日期
* @param type 偏移的类别
* @param iQuantity 偏移数量
* @return 偏移后的时间串
*/
public
String
getDateChangeALL
(
String
currentTime
,
String
type
,
int
iQuantity
)
{
Date
curr
=
null
;
String
newtype
=
""
;
if
(
currentTime
.
length
()
==
10
)
{
curr
=
stringToDateShort
(
currentTime
);
}
if
(
currentTime
.
length
()
>
10
)
{
curr
=
stringToDate
(
currentTime
);
}
// 日
if
(
type
.
equals
(
"1"
))
{
newtype
=
"d"
;
}
// 周,按照7天计算
else
if
(
type
.
equals
(
"2"
))
{
iQuantity
=
iQuantity
*
7
;
newtype
=
"d"
;
}
// 旬,按照10天计算
else
if
(
type
.
equals
(
"3"
))
{
iQuantity
=
iQuantity
*
10
;
newtype
=
"d"
;
}
// 月
else
if
(
type
.
equals
(
"4"
))
{
iQuantity
=
iQuantity
;
newtype
=
"m"
;
}
// 旬,按照3个月计算
else
if
(
type
.
equals
(
"5"
))
{
iQuantity
=
iQuantity
*
3
;
newtype
=
"m"
;
}
// 半年,按照六个月计算
else
if
(
type
.
equals
(
"6"
))
{
iQuantity
=
iQuantity
*
6
;
newtype
=
"m"
;
}
// 年
else
if
(
type
.
equals
(
"7"
))
{
newtype
=
"y"
;
}
else
{
iQuantity
=
iQuantity
;
newtype
=
"d"
;
}
Date
change
=
getDateChangeTime
(
curr
,
newtype
,
iQuantity
);
return
dateToStringShort
(
change
);
}
/**
* @param currentTime 计算的日期
* @param type 偏移的类别
* @param iQuantity 偏移数量
* @return 偏移后的时间
*/
public
Date
getDateChangeTime
(
Date
currentTime
,
String
type
,
int
iQuantity
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"MM"
));
// 月份修正
month
=
month
-
1
;
int
day
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"dd"
));
int
hour
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"HH"
));
int
mi
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"mm"
));
int
ss
=
Integer
.
parseInt
(
formatDate
(
currentTime
,
"ss"
));
GregorianCalendar
gc
=
new
GregorianCalendar
(
year
,
month
,
day
,
hour
,
mi
,
ss
);
// 月份修正
// gc.add(GregorianCalendar.MONTH, -1);
if
(
type
.
equalsIgnoreCase
(
"y"
))
{
gc
.
add
(
GregorianCalendar
.
YEAR
,
iQuantity
);
}
else
if
(
type
.
equalsIgnoreCase
(
"m"
))
{
gc
.
add
(
GregorianCalendar
.
MONTH
,
iQuantity
);
}
else
if
(
type
.
equalsIgnoreCase
(
"d"
))
{
gc
.
add
(
GregorianCalendar
.
DATE
,
iQuantity
);
}
else
if
(
type
.
equalsIgnoreCase
(
"h"
))
{
gc
.
add
(
GregorianCalendar
.
HOUR
,
iQuantity
);
}
else
if
(
type
.
equalsIgnoreCase
(
"mi"
))
{
gc
.
add
(
GregorianCalendar
.
MINUTE
,
iQuantity
);
}
else
if
(
type
.
equalsIgnoreCase
(
"s"
))
{
gc
.
add
(
GregorianCalendar
.
SECOND
,
iQuantity
);
}
return
gc
.
getTime
();
}
/**
* 将世界时间格式字符串转化成日期类型数据
* @param dateString yyyy-MM-dd'T'hh:mm:ss.SSS
* @return Date
*/
public
static
Date
getDateByWorldTimeFormatString
(
String
dateString
){
SimpleDateFormat
simpleDateFormatWorld
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'hh:mm:ss.SSS"
);
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
null
;
try
{
date
=
simpleDateFormatWorld
.
parse
(
dateString
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
String
returnDateString
=
simpleDateFormat
.
format
(
date
);
return
stringToDate
(
returnDateString
);
}
/**
* @param currentTime 计算的日期
* @param type 偏移的类别
* @param iQuantity 偏移数量
* @return 偏移后的时间串
*/
public
String
getDateChangeTime
(
String
currentTime
,
String
type
,
int
iQuantity
)
{
Date
curr
=
stringToDate
(
currentTime
);
curr
=
getDateChangeTime
(
curr
,
type
,
iQuantity
);
return
dateToString
(
curr
);
}
/**
* 取得日以上粒度起始时间
*
* @param granularity 粒度
* @param statisticDate 结束时间
* @return 起始时间
*/
public
String
getEndDate
(
String
granularity
,
String
statisticDate
)
{
String
beginDate
=
""
;
Date
date
=
stringToDateShort
(
statisticDate
);
Date
beginDateTemp
=
null
;
if
(
granularity
.
equals
(
"1"
))
{
// 日
beginDateTemp
=
date
;
}
if
(
granularity
.
equals
(
"2"
))
{
// 周
beginDateTemp
=
getWeekEnd
(
date
);
}
if
(
granularity
.
equals
(
"3"
))
{
// 旬
beginDateTemp
=
getPeriodEnd
(
date
);
}
else
if
(
granularity
.
equals
(
"4"
))
{
// 月
beginDateTemp
=
getMonthEnd
(
date
);
}
else
if
(
granularity
.
equals
(
"5"
))
{
// 季
beginDateTemp
=
getSeasonEnd
(
date
);
}
else
if
(
granularity
.
equals
(
"6"
))
{
// 半年
beginDateTemp
=
getHalfYearEnd
(
date
);
}
else
if
(
granularity
.
equals
(
"7"
))
{
// 年
beginDateTemp
=
getYearEnd
(
date
);
}
beginDate
=
dateToStringShort
(
beginDateTemp
);
return
beginDate
;
}
/**
* 取半年初
*
* @param date
* @return
*/
public
Date
getHalfYearBegin
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
;
if
(
month
<=
6
)
{
newDateStr
+=
"01-01"
;
}
else
{
newDateStr
+=
"07-01"
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取半年末
*
* @param date
* @return
*/
public
Date
getHalfYearEnd
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
;
if
(
month
<=
6
)
{
newDateStr
+=
"06-30"
;
}
else
{
newDateStr
+=
"12-31"
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取月初
*
* @param date
* @return
*/
public
static
Date
getMonthBegin
(
Date
date
)
{
String
newDateStr
=
formatDate
(
date
,
"yyyy-MM"
)
+
"-01"
;
// formatDate(date, "yyyy-MM-dd");
return
stringToDateShort
(
newDateStr
);
}
/**
* 取月末时间
*
* @param date 日期
* @return date
*/
public
static
Date
getMonthEnd
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
int
day
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
GregorianCalendar
calendar
=
new
GregorianCalendar
(
year
,
month
-
1
,
day
,
0
,
0
,
0
);
int
monthLength
=
calendar
.
getActualMaximum
(
calendar
.
DAY_OF_MONTH
);
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
+
formatDate
(
date
,
"MM"
)
+
"-"
;
if
(
monthLength
<
10
)
{
newDateStr
+=
"0"
+
monthLength
;
}
else
{
newDateStr
+=
""
+
monthLength
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取月末时间
*
* @param date 日期
* @return date
*/
public
static
Date
getMonthEndAndLastSecond
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
int
day
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
GregorianCalendar
calendar
=
new
GregorianCalendar
(
year
,
month
-
1
,
day
,
23
,
59
,
59
);
int
monthLength
=
calendar
.
getActualMaximum
(
calendar
.
DAY_OF_MONTH
);
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
+
formatDate
(
date
,
"MM"
)
+
"-"
;
if
(
monthLength
<
10
)
{
newDateStr
+=
"0"
+
monthLength
;
}
else
{
newDateStr
+=
""
+
monthLength
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取旬初
*
* @param date
* @return
*/
public
Date
getPeriodBegin
(
Date
date
)
{
int
days
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy-MM"
)
+
"-"
;
if
(
days
<=
10
)
{
newDateStr
+=
"01"
;
}
else
if
(
days
<=
20
)
{
newDateStr
+=
"11"
;
}
else
{
newDateStr
+=
"21"
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取旬末
*
* @param date
* @return
*/
public
Date
getPeriodEnd
(
Date
date
)
{
int
days
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy-MM"
)
+
"-"
;
if
(
days
<=
10
)
{
newDateStr
+=
"10"
;
}
else
if
(
days
<=
20
)
{
newDateStr
+=
"20"
;
}
else
{
newDateStr
=
formatDate
(
getMonthEnd
(
date
),
"yyyy-MM-dd"
);
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取季初
*
* @param date
* @return
*/
public
Date
getSeasonBegin
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
;
if
(
month
>=
1
&&
month
<=
3
)
{
newDateStr
+=
"01-01"
;
}
else
if
(
month
>=
4
&&
month
<=
6
)
{
newDateStr
+=
"04-01"
;
}
else
if
(
month
>=
7
&&
month
<=
9
)
{
newDateStr
+=
"07-01"
;
}
else
if
(
month
>=
10
&&
month
<=
12
)
{
newDateStr
+=
"10-01"
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取季度末时间
*
* @param date 日期
* @return date
*/
public
Date
getSeasonEnd
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-"
;
if
(
month
>=
1
&&
month
<=
3
)
{
newDateStr
+=
"03-31"
;
}
else
if
(
month
>=
4
&&
month
<=
6
)
{
newDateStr
+=
"06-30"
;
}
else
if
(
month
>=
7
&&
month
<=
9
)
{
newDateStr
+=
"09-30"
;
}
else
if
(
month
>=
10
&&
month
<=
12
)
{
newDateStr
+=
"12-31"
;
}
return
stringToDateShort
(
newDateStr
);
}
/**
* 取得时间描述 日 yyyy-mm-dd 月 yyyy年mm月 季 yyyy年第×季度 年 yyyy年
*
* @param granularity 粒度
* @param statisticDate 时间
* @return 时间对应粒度的描述
*/
public
String
getTimedes
(
String
granularity
,
String
statisticDate
)
{
String
timedes
=
""
;
Date
date
=
stringToDateShort
(
statisticDate
);
String
year
=
""
,
month
=
"01"
,
day
=
"01"
;
year
=
DateUtils
.
getYear
(
date
);
month
=
DateUtils
.
getMonth
(
date
);
day
=
DateUtils
.
getDay
(
date
);
if
(
granularity
.
equals
(
"1"
))
{
// 日
timedes
=
statisticDate
;
}
else
if
(
granularity
.
equals
(
"4"
))
{
// 月
timedes
=
year
+
"年"
+
month
+
"月"
;
}
else
if
(
granularity
.
equals
(
"8"
))
{
// 季
String
quarter
=
month
+
"-"
+
day
;
if
(
quarter
.
equals
(
"03-31"
))
{
timedes
=
year
+
"年 第1季度"
;
}
else
if
(
quarter
.
equals
(
"06-30"
))
{
timedes
=
year
+
"年 第2季度"
;
}
else
if
(
quarter
.
equals
(
"09-30"
))
{
timedes
=
year
+
"年 第3季度"
;
}
else
if
(
quarter
.
equals
(
"12-31"
))
{
timedes
=
year
+
"年 第4季度"
;
}
}
else
if
(
granularity
.
equals
(
"32"
))
{
// 年
timedes
=
year
+
"年"
;
}
return
timedes
;
}
/**
* 取周初
*
* @param date
* @return
*/
public
static
Date
getWeekBegin
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
// 月份修正
month
=
month
-
1
;
int
day
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
GregorianCalendar
gc
=
new
GregorianCalendar
(
year
,
month
,
day
);
int
week
=
GregorianCalendar
.
DAY_OF_WEEK
-
1
;
if
(
week
==
0
)
{
week
=
7
;
}
gc
.
add
(
GregorianCalendar
.
DATE
,
0
-
week
+
1
);
return
gc
.
getTime
();
}
/**
* 取周末
*
* @param date
* @return
*/
public
static
Date
getWeekEnd
(
Date
date
)
{
int
year
=
Integer
.
parseInt
(
formatDate
(
date
,
"yyyy"
));
int
month
=
Integer
.
parseInt
(
formatDate
(
date
,
"MM"
));
// 月份修正
month
=
month
-
1
;
int
day
=
Integer
.
parseInt
(
formatDate
(
date
,
"dd"
));
GregorianCalendar
gc
=
new
GregorianCalendar
(
year
,
month
,
day
);
int
week
=
GregorianCalendar
.
DAY_OF_WEEK
-
1
;
if
(
week
==
0
)
{
week
=
7
;
}
gc
.
add
(
GregorianCalendar
.
DATE
,
7
-
week
);
return
gc
.
getTime
();
}
/**
* 取得年初
*
* @param date
* @return
*/
public
Date
getYearBegin
(
Date
date
)
{
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-01-01"
;
return
stringToDateShort
(
newDateStr
);
}
/**
* 是否为年末
*
* @param date 时间
* @return
*/
public
Date
getYearEnd
(
Date
date
)
{
String
newDateStr
=
formatDate
(
date
,
"yyyy"
)
+
"-12-31"
;
return
stringToDateShort
(
newDateStr
);
}
/**
* 是否为旬末
*
* @param date 时间
* @return 是或否
*/
public
boolean
IsXperiodEnd
(
Date
date
)
{
boolean
flag
=
false
;
String
day
=
getDay
(
date
);
String
month
=
getMonth
(
date
);
if
(
day
.
equalsIgnoreCase
(
"10"
))
{
flag
=
true
;
}
else
if
(
day
.
equalsIgnoreCase
(
"20"
))
{
flag
=
true
;
}
return
flag
;
}
/**
* 日期加N天
* <p/>
* 时间
*
* @return 加后的日期
*/
public
static
String
addDay
(
String
s
,
int
n
)
{
try
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
sdf
.
parse
(
s
));
cd
.
add
(
Calendar
.
DATE
,
n
);
// 增加一天
// cd.add(Calendar.MONTH, n);//增加一个月
return
sdf
.
format
(
cd
.
getTime
());
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加N天
*
* @param date 时间
* @param n 天数
* @return 加后的Date
*/
public
static
Date
addDays
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
DATE
,
n
);
// 增加一天
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加N秒
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addSeconds
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
SECOND
,
n
);
// 增加一天
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加小时
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addHours
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
HOUR_OF_DAY
,
n
);
// 增加一小时
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加分钟
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addMinute
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
MINUTE
,
n
);
// 增加N分钟
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加N毫秒
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addMilltSeconds
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
MILLISECOND
,
n
);
//
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加N月
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addMonth
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
MONTH
,
n
);
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 时间加N年
*
* @param date 时间
* @return 加后的Date
*/
public
static
Date
addYear
(
Date
date
,
int
n
)
{
try
{
Calendar
cd
=
Calendar
.
getInstance
();
cd
.
setTime
(
date
);
cd
.
add
(
Calendar
.
YEAR
,
n
);
return
cd
.
getTime
();
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 获取本周第一天
*
* @param date 当前日期
* @return
*/
public
static
Date
getWeekBegin2
(
Date
date
)
{
Calendar
c
=
new
GregorianCalendar
();
c
.
setFirstDayOfWeek
(
Calendar
.
SUNDAY
);
c
.
setTime
(
date
);
c
.
set
(
Calendar
.
DAY_OF_WEEK
,
c
.
getFirstDayOfWeek
());
// SUNDAY
return
getDayBegin
(
c
.
getTime
());
}
/**
* 获取本周第一天
*
* @param date 当前日期
* @return
*/
public
static
Date
getWeekEnd2
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
getWeekBegin2
(
date
));
calendar
.
add
(
Calendar
.
DAY_OF_WEEK
,
7
);
return
getDayEnd
(
calendar
.
getTime
());
}
/**
* 返回当前日期减去毫秒数
*
* @param msec 毫秒数
* @return
*/
public
static
String
getNowTimeMinusMsec
(
long
msec
)
{
Date
now
=
new
Date
();
Date
nowMinusMsec
=
new
Date
(
now
.
getTime
()
-
msec
);
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
nowTime
=
dateFormat
.
format
(
nowMinusMsec
);
return
nowTime
;
}
/**
* 字符串转换为日期
*
* @param dateString yyyy-MM-dd HH:mm:ss
* @return 日期
*/
public
static
Date
getDateIncludeDateOrTime
(
String
dateString
)
{
SimpleDateFormat
dateTimeFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
result
=
null
;
if
(
dateString
==
null
||
""
.
equals
(
dateString
.
trim
()))
{
return
result
;
}
try
{
if
(
dateString
.
indexOf
(
":"
)
>
0
)
{
result
=
dateTimeFormat
.
parse
(
dateString
);
}
else
{
result
=
dateFormat
.
parse
(
dateString
);
}
}
catch
(
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
result
;
}
/**
* 获取当前日期是星期几<br>
*
* @param dt
* @return 当前日期是星期几
*/
public
static
String
getWeekOfDate
(
Date
dt
)
{
String
[]
weekDays
=
{
"7"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
};
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
dt
);
int
w
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
if
(
w
<
0
)
{
w
=
0
;
}
return
weekDays
[
w
];
}
/**
* 获取当前日期是星期几<br>
*
* @param dt
* @return 当前日期是星期几
*/
public
static
int
getWeekOfDateInt
(
Date
dt
)
{
int
[]
weekDays
=
{
7
,
1
,
2
,
3
,
4
,
5
,
6
};
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
dt
);
int
w
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
;
if
(
w
<
0
)
{
w
=
0
;
}
return
weekDays
[
w
];
}
/**
* 例如11:42转换为11.42,不足1分钟的时间当1分钟算<br>
*
* @param dt
* @return 例如11:42转换为11.42,不足1分钟的时间当1分钟算
*/
public
static
double
timeToDouble
(
Date
dt
)
{
return
(
dt
.
getMinutes
()
+
0.00d
)
/
100
+
dt
.
getHours
();
}
public
static
Date
getDateAfter
(
Date
date
,
int
day
)
{
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
date
);
now
.
set
(
Calendar
.
DATE
,
now
.
get
(
Calendar
.
DATE
)
+
day
);
return
now
.
getTime
();
}
public
static
Date
getMonthAfter
(
Date
date
,
int
month
)
{
Calendar
now
=
Calendar
.
getInstance
();
now
.
setTime
(
date
);
now
.
set
(
Calendar
.
MONTH
,
now
.
get
(
Calendar
.
MONTH
)
+
month
);
return
now
.
getTime
();
}
// 获取当月的第一天 2015-06-01 00:00:00
public
static
Date
getFirstDayOfThisMonth
()
{
Date
firstDayOfMonth
=
commonDateUtils
.
setDays
(
new
Date
(),
1
);
//设为当月第一天
firstDayOfMonth
=
commonDateUtils
.
truncate
(
firstDayOfMonth
,
Calendar
.
DAY_OF_MONTH
);
//截取日期
return
firstDayOfMonth
;
}
// 获取当月的最后一天 2015-06-30 23:59:59
public
static
Date
getLastDayOfThisMonth
()
{
Date
date
=
getFirstDayOfNextMonth
();
date
=
commonDateUtils
.
addDays
(
date
,
-
1
);
//减一天
date
=
commonDateUtils
.
setHours
(
date
,
23
);
date
=
commonDateUtils
.
setMinutes
(
date
,
59
);
date
=
commonDateUtils
.
setSeconds
(
date
,
59
);
return
date
;
}
// 获取下月的第一天 2015-06-01 00:00:00
public
static
Date
getFirstDayOfNextMonth
()
{
Date
firstDayOfMonth
=
commonDateUtils
.
addMonths
(
new
Date
(),
1
);
//加一个月
firstDayOfMonth
=
commonDateUtils
.
setDays
(
firstDayOfMonth
,
1
);
//设为当月第一天
firstDayOfMonth
=
commonDateUtils
.
truncate
(
firstDayOfMonth
,
Calendar
.
DAY_OF_MONTH
);
//截取日期
return
firstDayOfMonth
;
}
// 当前日期加一个月 2015-06-01 00:00:00
public
static
Date
getNextDayOfNextMonth
()
{
Date
nextDate
=
commonDateUtils
.
addMonths
(
new
Date
(),
1
);
//加一个月
nextDate
=
commonDateUtils
.
truncate
(
nextDate
,
Calendar
.
DAY_OF_MONTH
);
//截取日期
return
nextDate
;
}
// 当前日期加一个月 2015-06-01 23:59:59
public
static
Date
getThisDayOfNextMonth
()
{
Date
date
=
commonDateUtils
.
addMonths
(
new
Date
(),
1
);
//加一个月
date
=
commonDateUtils
.
addDays
(
date
,
-
1
);
//减一天
date
=
commonDateUtils
.
setHours
(
date
,
23
);
date
=
commonDateUtils
.
setMinutes
(
date
,
59
);
date
=
commonDateUtils
.
setSeconds
(
date
,
59
);
return
date
;
}
// 获取下一年相同月份的第一天
public
static
Date
getFirstDayOfNextYear
(
Date
d
)
{
Date
date
=
commonDateUtils
.
addYears
(
d
,
1
);
// 加一年
date
=
commonDateUtils
.
setDays
(
date
,
1
);
// 设为当月第一天
date
=
commonDateUtils
.
truncate
(
date
,
Calendar
.
DAY_OF_MONTH
);
// 截取日期
return
date
;
}
// 当前日期加一年
public
static
Date
getThisDayOfNextYear
(
Date
d
)
{
Date
date
=
commonDateUtils
.
addYears
(
d
,
1
);
// 加一年
date
=
commonDateUtils
.
addDays
(
date
,
-
1
);
// 减一天
date
=
commonDateUtils
.
setHours
(
date
,
23
);
date
=
commonDateUtils
.
setMinutes
(
date
,
59
);
date
=
commonDateUtils
.
setSeconds
(
date
,
59
);
return
date
;
}
// 获取今年1月1号
public
static
Date
getFirstDayThisYear
()
{
Date
firstDayThisYear
=
getFirstDayOfThisMonth
();
firstDayThisYear
.
setMonth
(
0
);
firstDayThisYear
=
commonDateUtils
.
setYears
(
firstDayThisYear
,
getNowYear
());
// 设为当月第一天
firstDayThisYear
=
commonDateUtils
.
truncate
(
firstDayThisYear
,
Calendar
.
DAY_OF_MONTH
);
// 截取日期
return
firstDayThisYear
;
}
// 获取今年12月31号
public
static
Date
getLastDayThisYear
()
{
Date
firstDayThisYear
=
getFirstDayOfThisMonth
();
firstDayThisYear
.
setMonth
(
0
);
firstDayThisYear
=
commonDateUtils
.
setYears
(
firstDayThisYear
,
getNowYear
());
// 设为当月第一天
Date
firstDayNextYear
=
commonDateUtils
.
addYears
(
firstDayThisYear
,
1
);
// 设为当月第一天
return
commonDateUtils
.
addSeconds
(
firstDayNextYear
,
-
1
);
// 设为当月第一天
}
// 获取当天日期零点
public
static
Date
getToday
()
{
return
commonDateUtils
.
truncate
(
new
Date
(),
Calendar
.
DAY_OF_MONTH
);
}
// 获取明天零点
public
static
Date
getTomorrow
()
{
Date
tmr
=
commonDateUtils
.
addDays
(
new
Date
(),
1
);
//加一天
return
commonDateUtils
.
truncate
(
tmr
,
Calendar
.
DAY_OF_MONTH
);
}
// 获取某个日期的零点
public
static
Date
getThatDay
(
Date
date
)
{
return
commonDateUtils
.
truncate
(
date
,
Calendar
.
DAY_OF_MONTH
);
}
// 获取某个日期第二天零点
public
static
Date
getThatTomorrow
(
Date
date
)
{
Date
tmr
=
commonDateUtils
.
addDays
(
date
,
1
);
// 加一天
return
commonDateUtils
.
truncate
(
tmr
,
Calendar
.
DAY_OF_MONTH
);
}
public
static
Date
getMinuteAfter
(
Date
date
,
Integer
minute
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
add
(
Calendar
.
MINUTE
,
minute
);
return
c
.
getTime
();
}
public
static
boolean
isSameDate
(
Date
date1
,
Date
date2
)
{
Calendar
cal1
=
Calendar
.
getInstance
();
cal1
.
setTime
(
date1
);
Calendar
cal2
=
Calendar
.
getInstance
();
cal2
.
setTime
(
date2
);
boolean
isSameYear
=
cal1
.
get
(
Calendar
.
YEAR
)
==
cal2
.
get
(
Calendar
.
YEAR
);
boolean
isSameMonth
=
isSameYear
&&
cal1
.
get
(
Calendar
.
MONTH
)
==
cal2
.
get
(
Calendar
.
MONTH
);
boolean
isSameDate
=
isSameMonth
&&
cal1
.
get
(
Calendar
.
DAY_OF_MONTH
)
==
cal2
.
get
(
Calendar
.
DAY_OF_MONTH
);
return
isSameDate
;
}
//获取当天的开始时间
public
static
Date
getDayBegin
(
Date
day
)
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
setTime
(
day
);
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
cal
.
getTime
();
}
//获取当天的结束时间
public
static
Date
getDayEnd
(
Date
day
)
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
setTime
(
day
);
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
cal
.
set
(
Calendar
.
MINUTE
,
59
);
cal
.
set
(
Calendar
.
SECOND
,
59
);
return
cal
.
getTime
();
}
//获取当天的开始时间
public
static
Date
getTodayBegin
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
cal
.
getTime
();
}
//获取当天的结束时间
public
static
Date
getTodayEnd
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
cal
.
set
(
Calendar
.
MINUTE
,
59
);
cal
.
set
(
Calendar
.
SECOND
,
59
);
return
cal
.
getTime
();
}
//获取本周的开始时间
public
static
Date
getBeginDayOfWeek
()
{
Date
date
=
new
Date
();
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
int
dayofweek
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
);
if
(
dayofweek
==
1
)
{
dayofweek
+=
7
;
}
cal
.
add
(
Calendar
.
DATE
,
2
-
dayofweek
);
return
getDayStartTime
(
cal
.
getTime
());
}
//获取本周的结束时间
public
static
Date
getEndDayOfWeek
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
getBeginDayOfWeek
());
cal
.
add
(
Calendar
.
DAY_OF_WEEK
,
6
);
Date
weekEndSta
=
cal
.
getTime
();
return
getDayEndTime
(
weekEndSta
);
}
//获取本月的开始时间
public
static
Date
getBeginDayOfMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
1
);
return
getDayStartTime
(
calendar
.
getTime
());
}
//获取本月的结束时间
public
static
Date
getEndDayOfMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
1
);
int
day
=
calendar
.
getActualMaximum
(
5
);
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
1
,
day
);
return
getDayEndTime
(
calendar
.
getTime
());
}
//获取某个日期的开始时间
public
static
Timestamp
getDayStartTime
(
Date
d
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
d
)
{
calendar
.
setTime
(
d
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
//获取某个日期的结束时间
public
static
Timestamp
getDayEndTime
(
Date
d
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
d
)
{
calendar
.
setTime
(
d
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
//获取某个日期的结束时间
public
static
Date
getThatDayEndTime
(
Date
d
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
d
)
{
calendar
.
setTime
(
d
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
new
Date
(
calendar
.
getTimeInMillis
());
}
//获取今年是哪一年
public
static
Integer
getNowYear
()
{
Date
date
=
new
Date
();
GregorianCalendar
gc
=
(
GregorianCalendar
)
Calendar
.
getInstance
();
gc
.
setTime
(
date
);
return
Integer
.
valueOf
(
gc
.
get
(
1
));
}
//获取本月是哪一月
public
static
int
getNowMonth
()
{
Date
date
=
new
Date
();
GregorianCalendar
gc
=
(
GregorianCalendar
)
Calendar
.
getInstance
();
gc
.
setTime
(
date
);
return
gc
.
get
(
2
)
+
1
;
}
public
static
int
getDayOfYear
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
return
c
.
get
(
Calendar
.
DAY_OF_YEAR
);
}
//获取上周的开始时间
@SuppressWarnings
(
"unused"
)
public
static
Date
getBeginDayOfLastWeek
()
{
Date
date
=
new
Date
();
if
(
date
==
null
)
{
return
null
;
}
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
int
dayofweek
=
cal
.
get
(
Calendar
.
DAY_OF_WEEK
);
if
(
dayofweek
==
1
)
{
dayofweek
+=
7
;
}
cal
.
add
(
Calendar
.
DATE
,
2
-
dayofweek
-
7
);
return
getDayStartTime
(
cal
.
getTime
());
}
//获取上月的开始时间
public
static
Date
getBeginDayOfLastMonth
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
set
(
getNowYear
(),
getNowMonth
()
-
2
,
1
);
return
getDayStartTime
(
calendar
.
getTime
());
}
public
static
String
toGMTString
(
Date
date
)
{
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"E, dd MMM yyyy HH:mm:ss z"
,
Locale
.
UK
);
df
.
setTimeZone
(
new
SimpleTimeZone
(
0
,
"GMT"
));
return
df
.
format
(
date
);
}
/**
* 切割時間段
*
* @param dateType 切割类型 M/D/H/N -->每月/每天/每小時/每分鐘
* @param dBegin yyyy-MM-dd HH:mm:ss
* @param dEnd yyyy-MM-dd HH:mm:ss
* @return
*/
public
static
List
<
String
>
findDates
(
String
dateType
,
Date
dBegin
,
Date
dEnd
,
String
dateFormat
)
throws
Exception
{
List
<
String
>
listDate
=
new
ArrayList
<>();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
Optional
.
ofNullable
(
dateFormat
).
orElse
(
"yyyy-MM-dd HH:mm:ss"
));
Date
dBeginDay
=
DateUtils
.
getThatDay
(
dBegin
);
Date
dEndDay
=
DateUtils
.
getThatDayEndTime
(
dEnd
);
listDate
.
add
(
sdf
.
format
(
dBeginDay
));
Calendar
calBegin
=
Calendar
.
getInstance
();
calBegin
.
setTime
(
dBeginDay
);
Calendar
calEnd
=
Calendar
.
getInstance
();
calEnd
.
setTime
(
dEndDay
);
while
(
calEnd
.
after
(
calBegin
))
{
switch
(
dateType
)
{
case
"M"
:
calBegin
.
add
(
Calendar
.
MONTH
,
1
);
break
;
case
"D"
:
calBegin
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
break
;
case
"H"
:
calBegin
.
add
(
Calendar
.
HOUR
,
1
);
break
;
case
"N"
:
calBegin
.
add
(
Calendar
.
SECOND
,
1
);
break
;
default
:
break
;
}
if
(
calEnd
.
after
(
calBegin
))
{
listDate
.
add
(
sdf
.
format
(
calBegin
.
getTime
()));
}
}
return
listDate
;
}
/**
* 日期与日期+时间比较
* @param date1 比较日期1
* @param date2 比较日期2
* @param dateTime 比较日期2的时分秒
* @return
* @throws Exception
*/
public
static
Boolean
dateAndTimeBefore
(
Date
date1
,
Date
date2
,
Date
dateTime
)
throws
Exception
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
date2Format
=
dateFormat
.
format
(
date2
);
SimpleDateFormat
bartDateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
String
dateTimeFormat
=
bartDateFormat
.
format
(
dateTime
);
SimpleDateFormat
dateFormat1
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
newDate
=
dateFormat1
.
parse
(
date2Format
+
" "
+
dateTimeFormat
);
return
date1
.
before
(
newDate
);
}
/**
* 获取两个日期之间的所有日期,默认日期格式为yyyy-MM-dd
* @param startTime
* @param endTime
* @return
*/
public
static
List
<
String
>
getTwoDateBetweenDayAllString
(
String
startTime
,
String
endTime
)
{
return
getTwoDateBetweenDayAllString
(
startTime
,
endTime
,
"yyyy-MM-dd"
);
}
/**
* 获取两个日期之间的所有日期,自定义日期格式
* @param startTime
* @param endTime
* @return
*/
public
static
List
<
String
>
getTwoDateBetweenDayAllString
(
String
startTime
,
String
endTime
,
String
definedDateFormat
)
{
// 返回的日期集合
List
<
String
>
days
=
new
ArrayList
<
String
>();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
SimpleDateFormat
definedSimpleDateFormat
=
new
SimpleDateFormat
(
definedDateFormat
);
try
{
Date
start
=
dateFormat
.
parse
(
startTime
);
Date
end
=
dateFormat
.
parse
(
endTime
);
Calendar
tempStart
=
Calendar
.
getInstance
();
tempStart
.
setTime
(
start
);
Calendar
tempEnd
=
Calendar
.
getInstance
();
tempEnd
.
setTime
(
end
);
tempEnd
.
add
(
Calendar
.
DATE
,
+
1
);
// 日期加1(包含结束)
while
(
tempStart
.
before
(
tempEnd
))
{
days
.
add
(
definedSimpleDateFormat
.
format
(
tempStart
.
getTime
()));
tempStart
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
days
;
}
public
static
Date
getNext
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
DATE
,
1
);
return
calendar
.
getTime
();
}
}
src/main/java/cn/com/gsst/auth/common/utils/JsonUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
cn.com.yict.framemax.core.utils.BeanUtils
;
import
cn.com.yict.framemax.core.utils.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONPath
;
import
org.apache.log4j.Logger
;
import
java.lang.reflect.Type
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
/**
* 系统Json 工具类
* <p>
*
* @see JSON
*/
public
final
class
JsonUtils
{
private
static
Logger
log
=
Logger
.
getLogger
(
JsonUtils
.
class
);
private
JsonUtils
()
{
}
/**
* 转换Java Bean 为 json
*/
public
static
String
serialize
(
Object
o
)
{
if
(
o
==
null
){
return
null
;
}
return
JSON
.
serialize
(
o
);
}
/**
* 转换Java Bean 为 json 附加了个时间格式参数
*
* @param o
* @param dateFormat
* @return
*//*
public static String serialize(Object o, String dateFormat) {
if(StringUtils.isEmpty(dateFormat)) {
return JSON.serialize(o);
}
return com.alibaba.fastjson.JSON.toJSONStringWithDateFormat(o, dateFormat);
}*/
/**
* json 转 javabean
*
* @param json
* @return
*/
public
static
<
T
>
T
deSerialize
(
String
json
,
Class
<
T
>
clazz
)
{
try
{
return
JSON
.
deSerialize
(
clazz
,
json
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
return
null
;
}
}
/**
* json 转 javabean
*
* @param json
* @return
*/
public
static
<
T
>
T
deSerialize
(
String
json
,
Type
type
)
{
try
{
return
JSON
.
deSerialize
(
type
,
json
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
return
null
;
}
}
/**
* 转换Java Bean 为 HashMap
*/
@SuppressWarnings
(
"unchecked"
)
public
static
Map
<
String
,
Object
>
beanToMap
(
Object
o
)
{
try
{
String
json
=
serialize
(
o
);
return
JSON
.
deSerialize
(
Map
.
class
,
json
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
return
null
;
}
}
/**
* 转换Json String 为 HashMap
*/
@SuppressWarnings
(
"unchecked"
)
public
static
Map
<
String
,
Object
>
jsonToMap
(
String
json
,
boolean
collToString
)
{
try
{
Map
<
String
,
Object
>
map
=
JSON
.
deSerialize
(
Map
.
class
,
json
);
if
(
collToString
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
map
.
entrySet
())
{
if
(
entry
.
getValue
()
instanceof
Collection
||
entry
.
getValue
()
instanceof
Map
)
{
entry
.
setValue
(
serialize
(
entry
.
getValue
()));
}
}
}
return
map
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
);
return
null
;
}
}
/**
* List 转换成json
*
* @param list
* @return
*/
public
static
String
listToJson
(
List
<?>
list
)
{
return
JSON
.
serialize
(
list
);
}
public
static
<
T
>
List
<
T
>
parseArray
(
String
json
,
String
jsonPath
,
Class
<
T
>
clazz
)
{
Object
read
=
JSONPath
.
read
(
json
,
jsonPath
);
if
(
read
instanceof
ArrayList
)
{
return
(
List
<
T
>)
read
;
}
return
JSONArray
.
parseArray
(
read
.
toString
(),
clazz
);
}
public
static
<
T
>
T
convert
(
Object
object
,
Type
type
)
{
if
(
object
instanceof
String
)
{
try
{
return
deSerialize
(
object
.
toString
(),
type
);
}
catch
(
Exception
e
)
{
}
}
if
(
BeanUtils
.
isSimpleValueType
(
object
.
getClass
()))
{
return
(
T
)
object
;
}
String
serialize
=
serialize
(
object
);
return
deSerialize
(
serialize
,
type
);
}
}
src/main/java/cn/com/gsst/auth/common/utils/RandomCodeUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
java.util.Random
;
public
class
RandomCodeUtils
{
public
static
final
String
ALLCHAR
=
"0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
;
public
static
final
String
ALLNUM
=
"0123456789"
;
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
ALLCHAR
.
charAt
(
random
.
nextInt
(
ALLCHAR
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的数字串
*
* @param length 随机字符串长度
* @return 随机数字串
*/
public
static
String
generateNumber
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
ALLNUM
.
charAt
(
random
.
nextInt
(
ALLNUM
.
length
())));
}
return
sb
.
toString
();
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/common/utils/RandomUtil.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
java.util.Random
;
/**
* @version:
* @function: 产生随机数字、随机字母、随机数字+字母。
*/
public
class
RandomUtil
{
/**
* 随机产生几位数字:例:maxLength=3,则结果可能是 012
*/
public
static
final
int
produceNumber
(
int
maxLength
)
{
Random
random
=
new
Random
();
return
random
.
nextInt
(
maxLength
);
}
/**
* 随机产生区间数字:例:minNumber=1,maxNumber=2,则结果可能是 1、2,包括首尾。
*/
public
static
int
produceRegionNumber
(
int
minNumber
,
int
maxNumber
)
{
return
minNumber
+
produceNumber
(
maxNumber
);
}
/**
* 随机产生几位字符串:例:maxLength=3,则结果可能是 aAz
*
* @param maxLength 传入数必须是正数。
*/
public
static
String
produceString
(
int
maxLength
)
{
String
source
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
return
doProduce
(
maxLength
,
source
);
}
/**
* 随机产生随机数字+字母:例:maxLength=3,则结果可能是 1Az
*
* @param maxLength 传入数必须是正数。
*/
public
static
String
produceStringAndNumber
(
int
maxLength
)
{
String
source
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
return
doProduce
(
maxLength
,
source
);
}
/**
* 自定义随机产生结果
*/
public
static
String
produceResultByCustom
(
String
customString
,
int
maxLength
)
{
return
doProduce
(
maxLength
,
customString
);
}
/**
* 生产结果
*/
private
static
String
doProduce
(
int
maxLength
,
String
source
)
{
StringBuffer
sb
=
new
StringBuffer
(
100
);
for
(
int
i
=
0
;
i
<
maxLength
;
i
++)
{
final
int
number
=
produceNumber
(
source
.
length
());
sb
.
append
(
source
.
charAt
(
number
));
}
return
sb
.
toString
();
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
RandomUtil
.
produceNumber
(
3
));
System
.
out
.
println
(
RandomUtil
.
produceRegionNumber
(
1
,
2
));
System
.
out
.
println
(
RandomUtil
.
produceString
(
3
));
System
.
out
.
println
(
RandomUtil
.
produceStringAndNumber
(
32
));
System
.
out
.
println
(
RandomUtil
.
produceResultByCustom
(
"demo."
,
8
));
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/common/utils/StringUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
java.io.UnsupportedEncodingException
;
import
java.math.BigDecimal
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
StringUtils
extends
org
.
apache
.
commons
.
lang3
.
StringUtils
{
private
final
static
Pattern
_HtmlTagPattern
=
Pattern
.
compile
(
"<.*>.*</\\w+>"
);
private
static
boolean
isNull
(
String
toString
)
{
return
StringUtils
.
isBlank
(
toString
);
}
public
static
String
toTrim
(
String
toString
)
{
String
result
;
if
(
isNull
(
toString
))
{
return
""
;
}
toString
=
StringUtils
.
trimToEmpty
(
toString
);
result
=
toString
.
replace
(
"\r"
,
" "
).
replace
(
"\n"
,
" "
).
replace
(
"\\"
,
""
).
replace
(
"\""
,
"\\\""
);
//
// result=replaceString(toString,"\\","");
// toString=result;
// result=replaceString(toString,"\"","\\\"");
// toString=result;
// result=replaceString(toString,"\n","");
return
result
;
}
public
static
String
StringNullToString
(
String
str
)
{
return
str
==
null
?
""
:
str
;
}
public
static
String
toUpper
(
String
toString
)
{
String
result
;
if
(
isNull
(
toString
))
{
return
""
;
}
toString
=
StringUtils
.
upperCase
(
StringUtils
.
trimToEmpty
(
toString
));
result
=
toString
.
replace
(
"\r"
,
" "
).
replace
(
"\n"
,
" "
).
replace
(
"\\"
,
""
).
replace
(
"\""
,
"\\\""
);
//
// result=replaceString(toString,"\\","");
// toString=result;
// result=replaceString(toString,"\"","\\\"");
// toString=result;
// result=replaceString(toString,"\n","");
return
result
;
}
public
static
String
ObjectToString
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
""
;
}
return
toTrim
(
String
.
valueOf
(
obj
));
}
public
static
Double
ObjectToDouble
(
Object
obj
,
int
bx
)
{
Double
result
=
null
;
if
(
obj
==
null
)
{
return
result
;
}
String
toString
=
toTrim
(
String
.
valueOf
(
obj
));
if
(
isNull
(
toString
))
{
return
result
;
}
result
=
(
new
BigDecimal
(
toString
)).
divide
(
new
BigDecimal
(
"1"
),
bx
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
result
;
}
public
static
Long
ObjectToLong
(
Object
obj
)
{
Long
result
=
null
;
if
(
obj
==
null
)
{
return
result
;
}
String
toString
=
toTrim
(
String
.
valueOf
(
obj
));
if
(
isNull
(
toString
))
{
return
result
;
}
result
=
Long
.
valueOf
(
toString
);
return
result
;
}
public
static
Date
ObjectToDate
(
Object
obj
,
String
formatPattern
)
{
if
(
obj
==
null
)
{
return
null
;
}
String
date
=
ObjectToString
(
obj
);
if
(
isNull
(
date
))
{
return
null
;
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
();
try
{
if
((
formatPattern
==
null
)
||
formatPattern
.
equals
(
""
))
{
formatPattern
=
"yyyy-MM-dd HH:mm:ss"
;
}
sdf
.
applyPattern
(
formatPattern
);
return
sdf
.
parse
(
date
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 计算日期,返回字符串
*
* @param date 日期
* @param n 加减的天数
* @param format 格式
* @return
*/
public
static
String
getCalculateDate
(
Date
date
,
int
n
,
String
format
)
{
long
d
=
date
.
getTime
()
+
n
*
24
*
60
*
60
*
1000
;
Date
newDate
=
new
Date
(
d
);
return
DateToString
(
newDate
,
format
);
}
public
static
Date
getCalculateDate
(
Date
date
,
int
n
)
{
long
d
=
date
.
getTime
()
+
n
*
24
*
60
*
60
*
1000
;
String
sDate
=
DateToString
(
new
Date
(
d
),
"yyyy-MM-dd"
);
return
StringToDate
(
sDate
,
"yyyy-MM-dd"
);
}
public
static
String
LongToString
(
Long
toLong
)
{
if
(
toLong
==
null
)
{
return
""
;
}
return
toLong
.
toString
();
}
public
static
Long
StringToLong
(
String
toString
)
{
toString
=
toTrim
(
toString
);
return
Long
.
parseLong
(
toString
);
}
public
static
Integer
StringToInteger
(
String
toString
)
{
if
(
toString
==
null
)
{
return
null
;
}
toString
=
toTrim
(
toString
);
return
Integer
.
parseInt
(
toString
);
}
public
static
String
IntegerToString
(
Integer
toInteger
)
{
String
result
=
""
;
if
(
toInteger
==
null
)
{
return
result
;
}
result
=
(
new
BigDecimal
(
toInteger
)).
divide
(
new
BigDecimal
(
"1"
),
0
,
BigDecimal
.
ROUND_HALF_UP
).
toString
();
return
result
;
}
public
static
String
DoubleToString
(
Double
toDouble
,
int
tobx
)
{
String
result
=
""
;
if
(
toDouble
==
null
)
{
return
result
;
}
result
=
(
new
BigDecimal
(
toDouble
)).
divide
(
new
BigDecimal
(
"1"
),
tobx
,
BigDecimal
.
ROUND_HALF_UP
).
toString
();
return
result
;
}
public
static
Double
StringToDouble
(
String
toString
,
int
bx
)
{
Double
result
=
null
;
if
(
isNull
(
toString
))
{
return
result
;
}
toString
=
toTrim
(
toString
);
result
=
(
new
BigDecimal
(
toString
)).
divide
(
new
BigDecimal
(
"1"
),
bx
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
result
;
}
public
static
String
DateToString
(
Date
toDate
)
{
if
(
toDate
==
null
)
{
return
""
;
}
return
DateUtils
.
formatDate
(
toDate
,
"yyyy-MM-dd"
);
}
public
static
String
DateToString
(
Date
toDate
,
String
toFormat
)
{
if
(
toDate
==
null
)
{
return
""
;
}
if
(
isNull
(
toFormat
))
{
return
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
)).
format
(
toDate
);
}
else
{
return
(
new
SimpleDateFormat
(
toFormat
)).
format
(
toDate
);
}
}
public
static
String
lastDateToString
(
String
toFormat
)
{
Date
date
=
null
;
if
(
isNull
(
toFormat
))
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
add
(
Calendar
.
MONTH
,
-
1
);
date
=
cal
.
getTime
();
}
return
(
new
SimpleDateFormat
(
"yyyy-MM-dd"
)).
format
(
date
);
}
public
static
String
DateToStringMinusDay
()
{
SimpleDateFormat
dft
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
beginDate
=
new
Date
();
Calendar
date
=
Calendar
.
getInstance
();
date
.
setTime
(
beginDate
);
date
.
set
(
Calendar
.
DATE
,
date
.
get
(
Calendar
.
DATE
)
-
1
);
return
dft
.
format
(
date
.
getTime
());
}
public
static
Date
StringToDate
(
String
date
,
String
formatPattern
)
{
if
(
isNull
(
date
))
{
return
null
;
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
();
try
{
if
((
formatPattern
==
null
)
||
formatPattern
.
equals
(
""
))
{
formatPattern
=
"yyyy-MM-dd"
;
}
sdf
.
applyPattern
(
formatPattern
);
return
sdf
.
parse
(
date
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
static
String
LRsubstr
(
String
Str
,
String
FinStr
,
String
LRtype
)
{
String
ReturnStr
=
""
;
int
n
=
0
;
int
bx
=
0
;
if
(
isNull
(
Str
))
{
return
ReturnStr
;
}
if
(
Str
.
indexOf
(
FinStr
)
>
-
1
)
{
bx
=
Str
.
length
();
n
=
Str
.
indexOf
(
FinStr
)
+
1
;
if
(!
isNull
(
LRtype
)
&&
LRtype
.
equals
(
"R"
))
{
ReturnStr
=
Str
.
substring
(
n
,
bx
);
}
else
{
ReturnStr
=
Str
.
substring
(
0
,
n
-
1
);
}
}
else
{
return
Str
;
}
return
ReturnStr
;
}
// ----fixKey("0000",20,"x")
// 补足20位x字符
public
static
String
fixKey
(
String
controlWord
,
int
len
,
String
defaultBit
)
{
if
(
controlWord
==
null
)
{
controlWord
=
""
;
}
if
(
StringUtils
.
isNull
(
defaultBit
))
{
defaultBit
=
"0"
;
}
while
(
controlWord
.
length
()
<
len
)
{
controlWord
=
controlWord
+
defaultBit
;
}
controlWord
=
controlWord
.
substring
(
0
,
len
);
return
controlWord
;
}
public
static
String
getUsedConditionNo
(
int
orderNo
,
int
len
)
{
String
standard
=
""
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
standard
+=
"0"
;
}
String
sOrderNo
=
orderNo
+
""
;
if
(
sOrderNo
.
length
()
>
len
)
{
return
""
;
}
else
{
return
standard
.
substring
(
0
,
len
-
sOrderNo
.
length
())
+
sOrderNo
;
}
}
public
static
String
splitString
(
String
inString
,
String
separator
,
int
sequence
)
{
String
ls_ret
=
""
;
int
li_point
;
int
li_pos
;
int
li_case
;
li_point
=
0
;
if
(
0
==
sequence
)
{
sequence
=
1
;
}
if
(!
isNull
(
inString
))
{
if
(
isNull
(
separator
))
{
ls_ret
=
inString
;
}
else
{
for
(
li_case
=
1
;
li_case
<=
sequence
;
li_case
++)
{
li_pos
=
inString
.
indexOf
(
separator
,
li_point
);
if
(
li_pos
>=
0
)
{
if
(
li_case
!=
sequence
)
{
li_point
=
li_pos
+
separator
.
length
();
}
else
{
if
(
sequence
==
1
)
{
ls_ret
=
inString
.
substring
(
0
,
li_pos
);
}
else
{
ls_ret
=
inString
.
substring
(
li_point
,
li_pos
);
}
}
}
else
{
ls_ret
=
inString
.
substring
(
li_point
);
}
}
}
}
return
ls_ret
;
}
@SuppressWarnings
(
"static-access"
)
public
static
long
StringTolong
(
String
value
)
{
long
result
=
0
;
if
(
isNull
(
value
))
{
return
result
;
}
value
=
value
.
trim
();
result
=
((
new
Long
(
0
)).
valueOf
(
value
)).
longValue
();
return
result
;
}
/**
* 截取一段字符的长度(汉、日、韩文字符长度为2),不区分中英文,如果数字不正好,则少取一个字符位
*
* @param str 原始字符串
* @param specialCharsLength 截取长度(汉、日、韩文字符长度为2)
* @return
*/
public
static
String
trim
(
String
str
,
int
specialCharsLength
)
{
if
(
str
==
null
||
""
.
equals
(
str
)
||
specialCharsLength
<
1
)
{
return
""
;
}
char
[]
chars
=
str
.
toCharArray
();
int
charsLength
=
getCharsLength
(
chars
,
specialCharsLength
);
return
new
String
(
chars
,
0
,
charsLength
);
}
/**
* 获取一段字符的长度,输入长度中汉、日、韩文字符长度为2,输出长度中所有字符均长度为1
*
* @param chars 一段字符
* @param specialCharsLength 输入长度,汉、日、韩文字符长度为2
* @return 输出长度,所有字符均长度为1
*/
private
static
int
getCharsLength
(
char
[]
chars
,
int
specialCharsLength
)
{
int
count
=
0
;
int
normalCharsLength
=
0
;
for
(
int
i
=
0
;
i
<
chars
.
length
;
i
++)
{
int
specialCharLength
=
getSpecialCharLength
(
chars
[
i
]);
if
(
count
<=
specialCharsLength
-
specialCharLength
)
{
count
+=
specialCharLength
;
normalCharsLength
++;
}
else
{
break
;
}
}
return
normalCharsLength
;
}
/**
* 获取字符长度:汉、日、韩文字符长度为2,ASCII码等字符长度为1
*
* @param c 字符
* @return 字符长度
*/
private
static
int
getSpecialCharLength
(
char
c
)
{
if
(
isLetter
(
c
))
{
return
1
;
}
else
{
return
2
;
}
}
/**
* 判断一个字符是Ascill字符还是其它字符(如汉,日,韩文字符)
*
* @param c 需要判断的字符
* @return 返回true, Ascill字符
*/
public
static
boolean
isLetter
(
char
c
)
{
int
k
=
0x80
;
return
c
/
k
==
0
?
true
:
false
;
}
/**
* 得到一个字符串的长度,显示的长度,一个汉字或日韩文长度为2,英文字符长度为1
*
* @param s 需要得到长度的字符串
* @return i得到的字符串长度
*/
public
static
int
length
(
String
s
)
{
if
(
s
==
null
)
{
return
0
;
}
char
[]
c
=
s
.
toCharArray
();
int
len
=
0
;
for
(
int
i
=
0
;
i
<
c
.
length
;
i
++)
{
len
++;
if
(!
isLetter
(
c
[
i
]))
{
len
++;
}
}
return
len
;
}
/**
* 截取一段字符的长度,不区分中英文,如果数字不正好,则少取一个字符位
*
* @param inString 原始字符串
* @param len 截取长度(一个汉字长度按2算的)
* @param c 后缀
* @return 返回的字符串
*/
public
static
String
substringBytes
(
String
inString
,
int
beginPos
,
int
len
,
String
c
)
{
if
(
inString
==
null
||
inString
.
equals
(
""
)
||
len
<
1
)
{
return
""
;
}
byte
[]
strByte
=
new
byte
[
len
];
if
(
len
>
(
length
(
inString
)
-
beginPos
))
{
len
=
length
(
inString
)
-
beginPos
;
}
if
(
len
>
length
(
inString
)
||
beginPos
>
length
(
inString
)
||
beginPos
<
0
)
{
// return inString+c;
return
""
+
c
;
}
try
{
System
.
arraycopy
(
inString
.
getBytes
(
"GBK"
),
beginPos
,
strByte
,
0
,
len
);
int
count
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
value
=
(
int
)
strByte
[
i
];
if
(
value
<
0
)
{
count
++;
}
}
if
(
count
%
2
!=
0
)
{
len
=
(
len
==
1
)
?
++
len
:
--
len
;
}
if
(
len
==
0
||
len
>
strByte
.
length
)
{
return
""
+
c
;
}
else
{
return
new
String
(
strByte
,
0
,
len
,
"GBK"
)
+
c
;
}
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
int
lengthUtf
(
String
s
)
{
byte
[]
bytes
=
null
;
try
{
bytes
=
s
.
getBytes
(
"utf-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
if
(
bytes
!=
null
)
{
return
bytes
.
length
;
}
return
0
;
}
public
static
String
substringBytesUtf
(
String
inString
,
int
beginPos
,
int
len
,
String
c
)
{
if
(
inString
==
null
||
inString
.
equals
(
""
)
||
len
<
1
)
{
return
""
;
}
byte
[]
strByte
=
new
byte
[
len
];
if
(
len
>
(
lengthUtf
(
inString
)
-
beginPos
))
{
len
=
lengthUtf
(
inString
)
-
beginPos
;
}
if
(
len
>
lengthUtf
(
inString
)
||
beginPos
>
lengthUtf
(
inString
)
||
beginPos
<
0
)
{
// return inString+c;
return
""
+
c
;
}
try
{
System
.
arraycopy
(
inString
.
getBytes
(
"utf-8"
),
beginPos
,
strByte
,
0
,
len
);
int
count
=
0
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
value
=
(
int
)
strByte
[
i
];
if
(
value
<
0
)
{
count
++;
}
}
if
(
count
==
1
)
{
len
=
len
-
1
;
}
else
if
(
count
==
2
)
{
len
=
len
-
2
;
}
else
if
(
count
/
3
!=
0
)
{
if
(
count
%
3
==
1
)
{
len
=
len
-
1
;
}
else
if
(
count
%
3
==
2
)
{
len
=
len
-
2
;
}
}
return
(
new
String
(
strByte
,
0
,
len
,
"utf-8"
)
+
c
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
String
replaceString
(
String
inString
,
String
regex
,
String
replacement
)
{
String
outString
;
outString
=
""
;
if
(
inString
!=
null
&&
(!
inString
.
equals
(
""
))
&&
regex
!=
null
&&
(!
regex
.
equals
(
""
)))
{
replacement
=
replacement
==
null
?
""
:
replacement
;
int
posAt
=
0
;
while
(
inString
.
indexOf
(
regex
)
>=
0
)
{
posAt
=
inString
.
indexOf
(
regex
);
outString
=
outString
+
inString
.
substring
(
0
,
posAt
)
+
replacement
;
inString
=
inString
.
substring
(
posAt
+
regex
.
length
());
}
outString
=
outString
+
inString
;
}
return
outString
;
}
/**
* 获得当前日期的字符串,形式如"2010分隔符01分隔符27"
*
* @return
*/
public
static
String
getCurrentDate
(
String
sep
)
{
Calendar
c
=
Calendar
.
getInstance
();
int
year
=
c
.
get
(
Calendar
.
YEAR
);
int
month
=
c
.
get
(
Calendar
.
MONTH
)
+
1
;
int
day
=
c
.
get
(
Calendar
.
DAY_OF_MONTH
);
String
sMonth
,
sDay
;
if
(
month
<
10
)
{
sMonth
=
"0"
+
month
;
}
else
{
sMonth
=
""
+
month
;
}
if
(
day
<
10
)
{
sDay
=
"0"
+
day
;
}
else
{
sDay
=
""
+
day
;
}
return
""
+
year
+
sep
+
sMonth
+
sep
+
sDay
;
}
public
static
String
getField
(
String
inString
,
String
separator
,
int
sequence
)
{
String
ls_ret
=
""
;
int
li_point
;
int
li_pos
;
int
li_case
;
li_point
=
0
;
if
(
0
==
sequence
)
{
sequence
=
1
;
}
if
(!
isNull
(
inString
))
{
if
(
isNull
(
separator
))
{
ls_ret
=
inString
;
}
else
{
for
(
li_case
=
1
;
li_case
<=
sequence
;
li_case
++)
{
li_pos
=
inString
.
indexOf
(
separator
,
li_point
);
if
(
li_pos
>=
0
)
{
if
(
li_case
!=
sequence
)
{
li_point
=
li_pos
+
separator
.
length
();
}
else
{
if
(
sequence
==
1
)
{
ls_ret
=
inString
.
substring
(
0
,
li_pos
);
}
else
{
ls_ret
=
inString
.
substring
(
li_point
,
li_pos
);
}
}
}
else
{
ls_ret
=
inString
.
substring
(
li_point
);
}
}
}
}
return
ls_ret
;
}
@SuppressWarnings
(
"static-access"
)
public
static
int
getInt
(
String
value
)
{
int
result
=
0
;
if
(
isNull
(
value
))
{
return
result
;
}
value
=
value
.
trim
();
result
=
((
new
Integer
(
0
)).
valueOf
(
value
)).
intValue
();
return
result
;
}
public
static
double
doubleTo0
(
Double
value
)
{
if
(
value
==
null
)
{
value
=
new
Double
(
0
);
}
return
value
;
}
public
static
boolean
equalsDouble
(
Double
d1
,
Double
d2
)
{
return
d1
==
null
?
d2
==
null
:
d1
.
equals
(
d2
);
}
public
static
String
toJsonArray
(
Map
<
String
,
String
>
keyMap
)
{
StringBuffer
sb
=
new
StringBuffer
();
Set
<
Entry
<
String
,
String
>>
set
=
keyMap
.
entrySet
();
for
(
Entry
<
String
,
String
>
entry
:
set
)
{
sb
.
append
(
"{\"id\":\""
+
entry
.
getKey
()
+
"\",\"text\":\""
+
entry
.
getValue
()
+
"\"},"
);
}
String
result
=
sb
.
toString
().
substring
(
0
,
sb
.
toString
().
length
()
-
1
);
return
result
;
}
/**
* crg 获取指定长度的随机数
*
* @param len
* @return
*/
public
static
String
getRandomNum
(
int
len
)
{
String
value
=
""
;
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
value
+=
random
.
nextInt
(
10
);
}
return
value
;
}
/**
* replace a character at a specified position.
*
* @param s
* @param pos
* @param c
* @return
*/
public
static
String
replaceCharAt
(
String
s
,
int
pos
,
char
c
)
{
return
s
.
substring
(
0
,
pos
)
+
c
+
s
.
substring
(
pos
+
1
);
}
public
static
String
replaceCharAt
(
String
s
,
int
pos
,
String
c
)
{
return
s
.
substring
(
0
,
pos
)
+
c
+
s
.
substring
(
pos
+
1
);
}
public
static
String
getCharAt
(
String
s
,
int
pos
)
{
return
s
.
substring
(
pos
,
pos
+
1
);
}
public
static
Date
trimDate
(
Date
date
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
clear
();
// as per BalusC comment.
cal
.
setTime
(
date
);
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
cal
.
getTime
();
}
public
static
String
toTrimAndTab
(
String
str
)
{
if
(
StringUtils
.
isNotBlank
(
str
)
&&
str
!=
"null"
)
{
str
=
str
.
replaceAll
(
"\\?"
,
""
).
replaceAll
(
"\\?"
,
""
).
replaceAll
(
"\\!"
,
""
)
.
replaceAll
(
"\\!"
,
""
);
char
[]
ch
=
str
.
toCharArray
();
String
s
=
""
;
for
(
char
c
:
ch
)
{
// Character cha = new Character(c);
// System.out.println(cha.hashCode());
if
(
c
!=
32
&&
c
!=
9
&&
c
!=
13
&&
c
!=
10
&&
c
!=
12288
&&
c
!=
160
)
{
s
+=
c
;
}
}
return
s
;
}
else
{
return
""
;
}
}
/**
* 获取当月的第一天
*
* @param toFormat
* @return
*/
public
static
String
firstDateToString
(
String
toFormat
)
{
Date
date
=
null
;
if
(
isNull
(
toFormat
))
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
date
=
cal
.
getTime
();
}
return
(
new
SimpleDateFormat
(
"yyyy-MM-dd"
)).
format
(
date
);
}
/**
* 获取当前时间前一个月的月份
*
* @return
*/
public
static
String
getLastMonthString
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
add
(
Calendar
.
MONTH
,
-
1
);
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
return
month
+
""
;
}
/**
* 获取当前时间的月份
*
* @return
*/
public
static
String
getNowMonthString
()
{
Calendar
cal
=
Calendar
.
getInstance
();
int
month
=
cal
.
get
(
Calendar
.
MONTH
)
+
1
;
return
month
+
""
;
}
/**
* 获取前一个月的第一天
*
* @return
*/
public
static
String
getFirstdayInLastMonth
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Calendar
cal_1
=
Calendar
.
getInstance
();
//获取当前日期
cal_1
.
add
(
Calendar
.
MONTH
,
-
1
);
cal_1
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
//设置为1号,当前日期既为本月第一天
return
format
.
format
(
cal_1
.
getTime
());
}
/**
* 获取前一个月的最后一天
*
* @return
*/
public
static
String
getLastdayInLastMonth
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Calendar
cal_1
=
Calendar
.
getInstance
();
//获取当前日期
cal_1
.
set
(
Calendar
.
DAY_OF_MONTH
,
0
);
return
format
.
format
(
cal_1
.
getTime
());
}
public
static
String
isNullStr
(
String
name
)
{
if
(
null
==
name
||
""
.
equals
(
name
)
||
"null"
.
equals
(
name
))
{
return
""
;
}
else
{
return
name
;
}
}
/**
* clear Html tags
*
* @param source
* @return
*/
public
static
String
clearHtml
(
String
source
)
{
Matcher
match
=
_HtmlTagPattern
.
matcher
(
source
);
return
match
.
replaceAll
(
""
);
}
public
static
String
sensitive
(
String
source
)
{
return
sensitive
(
source
,
4
);
}
public
static
String
sensitive
(
String
source
,
int
leftLen
,
int
rightLen
)
{
return
StringUtils
.
isBlank
(
source
)
?
null
:
StringUtils
.
left
(
source
,
leftLen
).
concat
(
StringUtils
.
removeStart
(
StringUtils
.
leftPad
(
StringUtils
.
right
(
source
,
rightLen
),
StringUtils
.
length
(
source
),
"*"
),
"***"
));
}
public
static
String
sensitive
(
String
source
,
int
rightLen
)
{
return
sensitive
(
source
,
0
,
rightLen
);
}
/**
* 字符串占位替换
* 占位格式:{XXX}
*
* @param str
* @return
*/
public
static
String
convertPlaceholder
(
String
str
,
Map
<
String
,
String
>
data
)
{
if
(
StringUtils
.
isBlank
(
str
)
||
data
==
null
||
data
.
size
()
==
0
)
{
return
str
;
}
String
regex
=
"\\$\\{([^}]*)\\}"
;
Pattern
pattern
=
Pattern
.
compile
(
regex
);
Matcher
matcher
=
pattern
.
matcher
(
str
);
while
(
matcher
.
find
())
{
String
key
=
matcher
.
group
().
substring
(
2
,
matcher
.
group
().
length
()
-
1
);
if
(
data
.
containsKey
(
key
))
{
str
=
str
.
replace
(
matcher
.
group
(),
data
.
get
(
key
));
}
else
{
str
=
""
;
}
}
return
str
;
}
}
src/main/java/cn/com/gsst/auth/common/utils/UUIDTool.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
;
import
java.util.UUID
;
/**
* uuid工具类
*
* @author Sean.Chan
*
*/
public
class
UUIDTool
{
/**
* 返回uuid 去掉"-"符号
* @return
*/
public
static
String
getUUID
()
{
return
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
}
}
src/main/java/cn/com/gsst/auth/common/utils/http/HttpClientFactory.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
.
http
;
import
org.apache.http.HttpEntityEnclosingRequest
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.client.HttpRequestRetryHandler
;
import
org.apache.http.client.protocol.HttpClientContext
;
import
org.apache.http.config.SocketConfig
;
import
org.apache.http.conn.ssl.NoopHostnameVerifier
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLContexts
;
import
org.apache.http.conn.ssl.TrustStrategy
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.apache.http.protocol.HttpContext
;
import
org.apache.http.ssl.SSLContextBuilder
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLException
;
import
javax.net.ssl.SSLSession
;
import
java.io.IOException
;
import
java.io.InterruptedIOException
;
import
java.net.UnknownHostException
;
import
java.security.*
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
/**
* httpclient 4.5.x
*/
public
class
HttpClientFactory
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpClientFactory
.
class
);
private
static
final
String
[]
SUPPORTED_PROTOCOLS
=
new
String
[]{
"TLSv1"
};
public
static
CloseableHttpClient
createHttpClient
()
{
return
createHttpClient
(
100
,
10
,
5000
,
2
);
}
/**
* @param maxTotal maxTotal
* @param maxPerRoute maxPerRoute
* @param timeout timeout
* @param retryExecutionCount retryExecutionCount
* @return CloseableHttpClient
*/
public
static
CloseableHttpClient
createHttpClient
(
int
maxTotal
,
int
maxPerRoute
,
int
timeout
,
int
retryExecutionCount
)
{
try
{
// SSLContext sslContext = SSLContexts.custom().useSSL().loadTrustMaterial(null, new TrustStrategy() {
// // 信任所有证书
// public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// return true;
// }
// }).build();
// SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
// // 信任所有
// public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
// return true;
// }
// }).build();
SSLContext
sslContext
=
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustStrategy
()
{
// 信任所有
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
}).
build
();
//NoopHostnameVerifier类: 作为主机名验证工具,实质上关闭了主机名验证,它接受任何
//有效的SSL会话并匹配到目标主机。
HostnameVerifier
hostnameVerifier
=
NoopHostnameVerifier
.
INSTANCE
;
SSLConnectionSocketFactory
sslsf
=
new
SSLConnectionSocketFactory
(
sslContext
,
hostnameVerifier
);
PoolingHttpClientConnectionManager
poolingHttpClientConnectionManager
=
new
PoolingHttpClientConnectionManager
();
poolingHttpClientConnectionManager
.
setMaxTotal
(
maxTotal
);
poolingHttpClientConnectionManager
.
setDefaultMaxPerRoute
(
maxPerRoute
);
SocketConfig
socketConfig
=
SocketConfig
.
custom
().
setSoTimeout
(
timeout
).
build
();
poolingHttpClientConnectionManager
.
setDefaultSocketConfig
(
socketConfig
);
return
HttpClientBuilder
.
create
()
.
setConnectionManager
(
poolingHttpClientConnectionManager
)
.
setSSLSocketFactory
(
sslsf
)
.
setSSLHostnameVerifier
(
new
HostnameVerifier
()
{
// 所有hostName验证返回true 不安全
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
})
.
setRetryHandler
(
new
HttpRequestRetryHandlerImpl
(
retryExecutionCount
))
.
build
();
}
catch
(
KeyManagementException
|
KeyStoreException
|
NoSuchAlgorithmException
e
)
{
logger
.
error
(
""
,
e
);
}
return
null
;
}
/**
* Key store 类型HttpClient
*
* @param keystore keystore
* @param keyPassword keyPassword
* @param timeout timeout
* @param retryExecutionCount retryExecutionCount
* @return CloseableHttpClient
*/
public
static
CloseableHttpClient
createKeyMaterialHttpClient
(
KeyStore
keystore
,
String
keyPassword
,
int
timeout
,
int
retryExecutionCount
)
{
return
createKeyMaterialHttpClient
(
keystore
,
keyPassword
,
SUPPORTED_PROTOCOLS
,
timeout
,
retryExecutionCount
);
}
/**
* Key store 类型HttpClient
*
* @param keystore keystore
* @param keyPassword keyPassword
* @param supportedProtocols supportedProtocols
* @param timeout timeout
* @param retryExecutionCount retryExecutionCount
* @return CloseableHttpClient
*/
public
static
CloseableHttpClient
createKeyMaterialHttpClient
(
KeyStore
keystore
,
String
keyPassword
,
String
[]
supportedProtocols
,
int
timeout
,
int
retryExecutionCount
)
{
try
{
SSLContext
sslContext
=
SSLContexts
.
custom
().
useSSL
().
loadKeyMaterial
(
keystore
,
keyPassword
.
toCharArray
()).
build
();
SSLConnectionSocketFactory
sf
=
new
SSLConnectionSocketFactory
(
sslContext
,
supportedProtocols
,
null
,
SSLConnectionSocketFactory
.
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
);
SocketConfig
socketConfig
=
SocketConfig
.
custom
().
setSoTimeout
(
timeout
).
build
();
return
HttpClientBuilder
.
create
()
.
setDefaultSocketConfig
(
socketConfig
)
.
setSSLSocketFactory
(
sf
)
.
setRetryHandler
(
new
HttpRequestRetryHandlerImpl
(
retryExecutionCount
))
.
build
();
}
catch
(
KeyManagementException
|
NoSuchAlgorithmException
|
UnrecoverableKeyException
|
KeyStoreException
e
)
{
logger
.
error
(
""
,
e
);
}
return
null
;
}
/**
* HttpClient 超时重试
*
* @author LiYi
*/
private
static
class
HttpRequestRetryHandlerImpl
implements
HttpRequestRetryHandler
{
private
int
retryExecutionCount
;
public
HttpRequestRetryHandlerImpl
(
int
retryExecutionCount
)
{
this
.
retryExecutionCount
=
retryExecutionCount
;
}
@Override
public
boolean
retryRequest
(
IOException
exception
,
int
executionCount
,
HttpContext
context
)
{
if
(
executionCount
>
retryExecutionCount
)
{
return
false
;
}
if
(
exception
instanceof
InterruptedIOException
)
{
return
false
;
}
if
(
exception
instanceof
UnknownHostException
)
{
return
false
;
}
if
(
exception
instanceof
SSLException
)
{
return
false
;
}
HttpClientContext
clientContext
=
HttpClientContext
.
adapt
(
context
);
HttpRequest
request
=
clientContext
.
getRequest
();
boolean
idempotent
=
!(
request
instanceof
HttpEntityEnclosingRequest
);
if
(
idempotent
)
{
// Retry if the request is considered idempotent
return
true
;
}
return
false
;
}
}
;
}
src/main/java/cn/com/gsst/auth/common/utils/http/HttpUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
.
http
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Map
;
import
java.util.Set
;
/**
* http请求工具类
*/
public
class
HttpUtils
{
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
HttpUtils
.
class
);
public
static
String
postForm
(
String
url
,
Map
<
String
,
String
>
parameters
)
{
String
result
=
""
;
// 返回的结果
BufferedReader
in
=
null
;
// 读取响应输入流
PrintWriter
out
=
null
;
//输出流
String
params
=
""
;
// 编码之后的参数
try
{
// 编码请求参数
for
(
Map
.
Entry
<
String
,
String
>
entry
:
parameters
.
entrySet
())
{
params
=
params
+
entry
.
getKey
()
+
"="
+
entry
.
getValue
()
+
"&"
;
}
params
=
params
.
substring
(
0
,
params
.
length
()
-
1
);
// 创建URL对象
URL
connURL
=
new
URL
(
url
);
// 打开URL连接
HttpURLConnection
httpConn
=
(
HttpURLConnection
)
connURL
.
openConnection
();
// 设置通用属性
httpConn
.
setRequestProperty
(
"Accept"
,
"*/*"
);
httpConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
httpConn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"
);
httpConn
.
setRequestProperty
(
"Accept-Charset"
,
"UTF-8"
);
httpConn
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded;charset=UTF-8"
);
httpConn
.
setRequestProperty
(
"Authorization"
,
"Basic MzYgOiBTdXBlcmxpbmsx"
);
// 设置POST方式
httpConn
.
setDoInput
(
true
);
httpConn
.
setDoOutput
(
true
);
// 获取HttpURLConnection对象对应的输出流
out
=
new
PrintWriter
(
httpConn
.
getOutputStream
());
// 发送请求参数
System
.
out
.
println
(
"requers parms::"
+
params
);
out
.
write
(
params
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应,设置编码方式
in
=
new
BufferedReader
(
new
InputStreamReader
(
httpConn
.
getInputStream
(),
StandardCharsets
.
UTF_8
));
String
line
;
// 读取返回的内容
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
+
"\r\n"
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
return
result
;
}
public
static
String
postForm
(
String
url
,
Map
<
String
,
String
>
parameters
,
Map
<
String
,
String
>
headers
)
{
String
result
=
""
;
// 返回的结果
BufferedReader
in
=
null
;
// 读取响应输入流
PrintWriter
out
=
null
;
//输出流
String
params
=
""
;
// 编码之后的参数
try
{
// 编码请求参数
for
(
Map
.
Entry
<
String
,
String
>
entry
:
parameters
.
entrySet
())
{
params
=
params
+
entry
.
getKey
()
+
"="
+
entry
.
getValue
()
+
"&"
;
}
// 创建URL对象
URL
connURL
=
new
URL
(
url
);
// 打开URL连接
HttpURLConnection
httpConn
=
(
HttpURLConnection
)
connURL
.
openConnection
();
// 设置通用属性
httpConn
.
setRequestProperty
(
"Accept"
,
"*/*"
);
httpConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
httpConn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"
);
httpConn
.
setRequestProperty
(
"Accept-Charset"
,
"UTF-8"
);
httpConn
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded;charset=UTF-8"
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
headers
.
entrySet
())
{
httpConn
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
// 设置POST方式
httpConn
.
setDoInput
(
true
);
httpConn
.
setDoOutput
(
true
);
// 获取HttpURLConnection对象对应的输出流
out
=
new
PrintWriter
(
httpConn
.
getOutputStream
());
// 发送请求参数
System
.
out
.
println
(
"requers parms::"
+
params
);
out
.
write
(
params
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应,设置编码方式
in
=
new
BufferedReader
(
new
InputStreamReader
(
httpConn
.
getInputStream
(),
StandardCharsets
.
UTF_8
));
String
line
;
// 读取返回的内容
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
+
"\r\n"
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
return
result
;
}
public
static
String
postMethod
(
String
url
,
String
param
)
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
String
result
=
""
;
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
URLConnection
conn
=
realUrl
.
openConnection
();
// 设置通用的请求属性
conn
.
setRequestProperty
(
"accept"
,
"*/*"
);
conn
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送 POST 请求出现异常!"
+
e
.
getMessage
(),
e
);
}
// 使用finally块来关闭输出流、输入流
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
logger
.
error
(
"发送 POST 请求出现异常!"
+
ex
.
getMessage
(),
ex
);
// ex.printStackTrace();
}
}
return
result
;
}
public
static
String
postJson
(
String
url
,
String
params
,
Map
<
String
,
String
>
headers
)
{
URL
uUrl
=
null
;
HttpURLConnection
conn
=
null
;
BufferedWriter
out
=
null
;
BufferedReader
in
=
null
;
try
{
//创建和初始化连接
uUrl
=
new
URL
(
url
);
conn
=
(
HttpURLConnection
)
uUrl
.
openConnection
();
conn
.
setRequestProperty
(
"content-type"
,
"application/json;charset=UTF-8"
);
conn
.
setRequestMethod
(
"POST"
);
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
//指定请求header参数
if
(
headers
!=
null
&&
headers
.
size
()
>
0
)
{
Set
<
String
>
headerSet
=
headers
.
keySet
();
for
(
String
key
:
headerSet
)
{
conn
.
setRequestProperty
(
key
,
headers
.
get
(
key
));
}
}
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
conn
.
getOutputStream
(),
StandardCharsets
.
UTF_8
));
out
.
write
(
params
);
out
.
flush
();
//接收返回结果
StringBuilder
result
=
new
StringBuilder
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
(),
StandardCharsets
.
UTF_8
));
if
(
in
!=
null
)
{
String
line
=
""
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
}
return
result
.
toString
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送 POST 请求出现异常!"
+
e
.
getMessage
(),
e
);
}
// 使用finally块来关闭输出流、输入流
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
logger
.
error
(
"发送 POST 请求出现异常!"
+
ex
.
getMessage
(),
ex
);
// ex.printStackTrace();
}
}
return
null
;
}
}
src/main/java/cn/com/gsst/auth/common/utils/http/JsonResponseHandler.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
.
http
;
import
com.alibaba.fastjson.JSON
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.ResponseHandler
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
public
class
JsonResponseHandler
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JsonResponseHandler
.
class
);
public
static
<
T
>
ResponseHandler
<
T
>
createResponseHandler
(
final
Class
<
T
>
clazz
)
{
return
new
JsonResponseHandlerImpl
<
T
>(
null
,
clazz
);
}
public
static
class
JsonResponseHandlerImpl
<
T
>
extends
LocalResponseHandler
implements
ResponseHandler
<
T
>
{
private
Class
<
T
>
clazz
;
public
JsonResponseHandlerImpl
(
String
uriId
,
Class
<
T
>
clazz
)
{
this
.
uriId
=
uriId
;
this
.
clazz
=
clazz
;
}
@Override
public
T
handleResponse
(
HttpResponse
response
)
throws
ClientProtocolException
,
IOException
{
int
status
=
response
.
getStatusLine
().
getStatusCode
();
if
(
status
>=
200
&&
status
<
300
)
{
HttpEntity
entity
=
response
.
getEntity
();
String
str
=
EntityUtils
.
toString
(
entity
,
"utf-8"
);
if
(
str
.
length
()
<
300
)
{
logger
.
info
(
"URI[{}] elapsed time:{} ms RESPONSE DATA:{}"
,
super
.
uriId
,
System
.
currentTimeMillis
()
-
super
.
startTime
,
str
);
}
else
{
logger
.
info
(
"URI[{}] elapsed time:{} ms RESPONSE DATA:{}"
,
super
.
uriId
,
System
.
currentTimeMillis
()
-
super
.
startTime
,
"返回结果过长,忽略输出"
);
}
if
(
isJson
(
str
))
{
return
JSON
.
parseObject
(
str
,
clazz
);
}
else
{
return
null
;
}
}
else
{
throw
new
ClientProtocolException
(
"Unexpected response status: "
+
status
);
}
}
/**
* f**k json parse
* @param str
* @return
*/
private
boolean
isJson
(
String
str
){
try
{
JSON
.
parseObject
(
str
,
clazz
);
}
catch
(
Exception
e
){
return
false
;
}
return
true
;
}
}
}
src/main/java/cn/com/gsst/auth/common/utils/http/LocalResponseHandler.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
.
http
;
public
abstract
class
LocalResponseHandler
{
protected
String
uriId
;
protected
long
startTime
=
System
.
currentTimeMillis
();
public
String
getUriId
()
{
return
uriId
;
}
public
void
setUriId
(
String
uriId
)
{
this
.
uriId
=
uriId
;
}
}
src/main/java/cn/com/gsst/auth/common/utils/http/SslUtils.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
common
.
utils
.
http
;
import
javax.net.ssl.*
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
public
class
SslUtils
{
private
static
void
trustAllHttpsCertificates
()
throws
Exception
{
TrustManager
[]
trustAllCerts
=
new
TrustManager
[
1
];
TrustManager
tm
=
new
miTM
();
trustAllCerts
[
0
]
=
tm
;
SSLContext
sc
=
SSLContext
.
getInstance
(
"SSL"
);
sc
.
init
(
null
,
trustAllCerts
,
null
);
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
}
static
class
miTM
implements
TrustManager
,
X509TrustManager
{
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
public
boolean
isServerTrusted
(
X509Certificate
[]
certs
)
{
return
true
;
}
public
boolean
isClientTrusted
(
X509Certificate
[]
certs
)
{
return
true
;
}
public
void
checkServerTrusted
(
X509Certificate
[]
certs
,
String
authType
)
throws
CertificateException
{
return
;
}
public
void
checkClientTrusted
(
X509Certificate
[]
certs
,
String
authType
)
throws
CertificateException
{
return
;
}
}
/**
* 忽略HTTPS请求的SSL证书,必须在openConnection之前调用
*
* @throws Exception
*/
public
static
void
ignoreSsl
()
throws
Exception
{
HostnameVerifier
hv
=
new
HostnameVerifier
()
{
public
boolean
verify
(
String
urlHostName
,
SSLSession
session
)
{
// System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return
true
;
}
};
trustAllHttpsCertificates
();
HttpsURLConnection
.
setDefaultHostnameVerifier
(
hv
);
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/support/login/ThirdPlatformAuthService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
;
import
cn.com.gsst.auth.support.login.domain.AuthInfo
;
import
cn.com.gsst.auth.support.login.domain.CodeAuth
;
/**
* 第三方授权服务
**/
public
interface
ThirdPlatformAuthService
{
/**
* 登录凭证校验
*
* @param codeAuth
* @return
*/
AuthInfo
doAuth
(
CodeAuth
codeAuth
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/support/login/ThirdPlatformAuthServiceBuilder.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
;
import
cn.com.gsst.auth.common.constant.Member3ptLoginChannel
;
import
cn.com.gsst.auth.support.login.channel.bl.IBTAuthService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
@Component
public
class
ThirdPlatformAuthServiceBuilder
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
public
ThirdPlatformAuthService
getService
(
Member3ptLoginChannel
channel
)
throws
Exception
{
if
(
Member3ptLoginChannel
.
ibt
.
equals
(
channel
))
{
return
applicationContext
.
getBean
(
IBTAuthService
.
class
);
}
throw
new
I18nMessageException
(
"exception/third.party.authorization.channel.abnormal"
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
src/main/java/cn/com/gsst/auth/support/login/ThirdPlatformLoginService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
;
import
cn.com.gsst.auth.support.login.domain.AuthInfo
;
public
interface
ThirdPlatformLoginService
{
/**
* 第三方平台登录
*
* @reurn
*/
Object
doLogin
(
AuthInfo
authInfo
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/support/login/ThirdPlatformLoginServiceBuilder.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
;
import
cn.com.gsst.auth.common.constant.Member3ptLoginChannel
;
import
cn.com.gsst.auth.support.login.channel.bl.IBTLoginService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
@Component
public
class
ThirdPlatformLoginServiceBuilder
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
public
ThirdPlatformLoginService
getService
(
Member3ptLoginChannel
channel
)
throws
Exception
{
if
(
Member3ptLoginChannel
.
ibt
.
equals
(
channel
))
{
return
applicationContext
.
getBean
(
IBTLoginService
.
class
);
}
throw
new
I18nMessageException
(
"exception/third.party.login.channel.abnormality"
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
src/main/java/cn/com/gsst/auth/support/login/channel/DefaultLoginService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
.
channel
;
import
cn.com.gsst.auth.support.login.domain.AuthInfo
;
import
cn.com.gsst.auth.support.login.ThirdPlatformLoginService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
@Service
public
class
DefaultLoginService
implements
ThirdPlatformLoginService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
/**
* 第三方平台登录
*
* @return
*/
@Override
public
Object
doLogin
(
AuthInfo
authInfo
)
throws
Exception
{
throw
new
I18nMessageException
(
"exception/default.login.channel.login.is.currently.not.supported"
);
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/support/login/channel/bl/IBTAuthService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
.
channel
.
bl
;
import
cn.com.gsst.auth.support.login.ThirdPlatformAuthService
;
import
cn.com.gsst.auth.support.login.domain.AuthInfo
;
import
cn.com.gsst.auth.support.login.domain.CodeAuth
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
/**
* 授权
*
* @author Focan.Zhong
*/
@Service
public
class
IBTAuthService
implements
ThirdPlatformAuthService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
/**
* 后台授权
*
* @param codeAuth
* @return
* @throws Exception
*/
@Override
public
AuthInfo
doAuth
(
CodeAuth
codeAuth
)
throws
Exception
{
AuthInfo
result
=
new
AuthInfo
();
return
result
;
}
}
src/main/java/cn/com/gsst/auth/support/login/channel/bl/IBTLoginService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
.
channel
.
bl
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.support.login.ThirdPlatformLoginService
;
import
cn.com.gsst.auth.support.login.domain.AuthInfo
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
/**
* @author Focan.Zhong
*/
@Service
public
class
IBTLoginService
implements
ThirdPlatformLoginService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
/**
* 后台登录
*
* @return
*/
@Override
public
Object
doLogin
(
AuthInfo
authInfo
)
throws
Exception
{
//todo 登录逻辑
Assert
.
notBlank
(
authInfo
.
getUsername
());
Assert
.
notBlank
(
authInfo
.
getPassword
());
return
null
;
}
}
src/main/java/cn/com/gsst/auth/support/login/domain/AuthInfo.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
.
domain
;
public
class
AuthInfo
{
private
String
username
;
private
String
password
;
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
src/main/java/cn/com/gsst/auth/support/login/domain/CodeAuth.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
login
.
domain
;
import
java.io.Serializable
;
public
class
CodeAuth
implements
Serializable
{
}
src/main/java/cn/com/gsst/auth/support/register/ThirdPlatformRegisterService.java
0 → 100644
View file @
52bb15fa
//package cn.com.gsst.support.register;
//
//
///**
// * @author Focan.Zhong
// */
//public interface ThirdPlatformRegisterService {
//
// /**
// * 第三方平台注册
// *
// * @return
// */
// MemberInfoDto doRegister(MemberInfoDto memberInfoDto) throws Exception;
//}
src/main/java/cn/com/gsst/auth/support/register/ThirdPlatformRegisterServiceBuilder.java
0 → 100644
View file @
52bb15fa
//package cn.com.gsst.support.register;
//
//
//import cn.com.blo.common.constant.Member3ptRegisterChannel;
//import cn.com.blo.support.register.channel.bl.BlMobileRegisterService;
//import cn.com.blo.support.register.channel.bl.BlWxMiniRegisterService;
//import cn.com.yict.framemax.core.i18n.I18nMessageException;
//import org.springframework.beans.BeansException;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.stereotype.Component;
//
//
///**
// * @author Focan.Zhong
// */
//@Component
//public class ThirdPlatformRegisterServiceBuilder implements ApplicationContextAware {
//
// private ApplicationContext applicationContext;
//
// public ThirdPlatformRegisterService getService(Member3ptRegisterChannel channel) throws Exception {
//
// if (Member3ptRegisterChannel.bl_wx_mini.equals(channel)) {
// return applicationContext.getBean(BlWxMiniRegisterService.class);
// } else if (Member3ptRegisterChannel.bl_mobile.equals(channel)) {
// return applicationContext.getBean(BlMobileRegisterService.class);
// }
//
// throw new I18nMessageException("注册渠道异常");
// }
//
// @Override
// public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// this.applicationContext = applicationContext;
// }
//}
src/main/java/cn/com/gsst/auth/support/register/channel/DefaultRegisterService.java
0 → 100644
View file @
52bb15fa
//package cn.com.gsst.support.register.channel;
//
//
//import cn.com.blo.support.register.ThirdPlatformRegisterService;
//import cn.com.blo.user.dto.MemberInfoDto;
//import cn.com.yict.framemax.core.i18n.I18nMessageException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//
//@Service
//public class DefaultRegisterService implements ThirdPlatformRegisterService {
//
// private Logger logger = LoggerFactory.getLogger(this.getClass());
//
// /**
// * 第三方平台注册
// *
// * @param memberInfoDto
// * @return
// */
// @Override
// public MemberInfoDto doRegister(MemberInfoDto memberInfoDto) throws Exception {
// throw new I18nMessageException("暂无默认注册渠道登录!");
// }
//}
src/main/java/cn/com/gsst/auth/support/register/channel/bl/BlMobileRegisterService.java
0 → 100644
View file @
52bb15fa
//package cn.com.gsst.support.register.channel.bl;
//
//
//import cn.com.blo.common.constant.BloCommonConstant;
//import cn.com.blo.common.constant.BloRedisKeyConstant;
//import cn.com.blo.common.service.CommonParamConfigService;
//import cn.com.blo.common.utils.NumberUtils;
//import cn.com.blo.support.register.ThirdPlatformRegisterService;
//import cn.com.blo.thirdParty.bl.api.BlMemberApi;
//import cn.com.blo.thirdParty.bl.domain.BlConfigEntity;
//import cn.com.blo.thirdParty.bl.request.BlMemberInfoRequest;
//import cn.com.blo.thirdParty.bl.request.BlMemberRequest;
//import cn.com.blo.thirdParty.bl.result.BlMemberAuthResult;
//import cn.com.blo.thirdParty.bl.result.BlMemberInfoResult;
//import cn.com.blo.thirdParty.bl.utils.BlAbstractHttpClient;
//import cn.com.blo.user.constant.Member3rdPartyRelationEnum;
//import cn.com.blo.user.dto.MemberInfoDto;
//import cn.com.blo.user.entity.BizMember3rdPartyRelationEntity;
//import cn.com.blo.user.model.BizMemberInfoModel;
//import cn.com.blo.user.service.BizMember3rdPartyRelationService;
//import cn.com.blo.user.service.BizMemberInfoService;
//import cn.com.gsst.marketing.tools.service.RedisService;
//import cn.com.yict.framemax.core.i18n.I18nMessageException;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.util.Assert;
//
//import javax.annotation.Resource;
//import java.util.Optional;
//
///**
// * @author Focan.Zhong
// */
//@Service
//public class BlMobileRegisterService implements ThirdPlatformRegisterService {
//
// private Logger logger = LoggerFactory.getLogger(this.getClass());
//
// @Resource
// private BizMemberInfoService bizMemberInfoService;
//
// @Resource
// private BizMember3rdPartyRelationService bizMember3rdPartyRelationService;
//
// @Resource
// private CommonParamConfigService commonParamConfigService;
//
// @Resource
// private RedisService redisService;
//
// @Resource
// private BlAbstractHttpClient blAbstractHttpClient;
//
// private final static String DEFAULT_AVATAR_URL = "";
//
// /**
// * 第三方平台注册
// *
// * @param memberInfoDto
// * @return
// */
// @Override
// public MemberInfoDto doRegister(MemberInfoDto memberInfoDto) throws Exception {
//
// //参数校验
// check(memberInfoDto);
//
// //查询配置
// BlConfigEntity blThirdPartyConfig = commonParamConfigService.getBlThirdPartyConfig();
// if (blThirdPartyConfig == null
// || StringUtils.isBlank(blThirdPartyConfig.getAppKey())
// || StringUtils.isBlank(blThirdPartyConfig.getAppSecret())
// || StringUtils.isBlank(blThirdPartyConfig.getChannelIdWechat())
// || StringUtils.isBlank(blThirdPartyConfig.getSysId())) {
// throw new I18nMessageException("百联通开放平台配置异常!");
// }
//
// //调百联通手机号注册接口
// BlMemberRequest regRequest = new BlMemberRequest();
// regRequest.setMobile(memberInfoDto.getMobilePhone());
// regRequest.setSmsCode(memberInfoDto.getSmsCode());
// regRequest.setChannelId(blThirdPartyConfig.getChannelIdWechat());
// regRequest.setSysid(blThirdPartyConfig.getSysId());
// BlMemberAuthResult blMemberAuthResult = blAbstractHttpClient.doRequest(
// blThirdPartyConfig.getAppKey(),
// blThirdPartyConfig.getAppSecret(),
// BlMemberApi.MOBILE_LOGIN_OR_REG, regRequest);
//
// String encodeMemberId = blMemberAuthResult.getEncodeMemberId();
// String memberToken = blMemberAuthResult.getMemberToken();
//
//
// //查询奥拉会员信息
// BlMemberInfoRequest memberInfoRequest = new BlMemberInfoRequest();
// memberInfoRequest.setMemberToken(memberToken);
// BlMemberInfoResult memberInfoResult = blAbstractHttpClient.doRequest(BlMemberApi.MEMBER_INFO, memberInfoRequest);
//
// //保存会员信息
// BizMemberInfoModel memberInfoModel = new BizMemberInfoModel();
// memberInfoModel.setMemberLevel(memberInfoResult.getMemberLevel());
// memberInfoModel.setMemberLevelName(memberInfoResult.getMemberLevelName());
// memberInfoModel.setMobileMask(memberInfoResult.getMobileMask());
// memberInfoModel.setRemainPoints(NumberUtils.defaultZeroIfNull(memberInfoResult.getRemainPoints()));
// memberInfoModel.setCurrGrowthValue(memberInfoResult.getCurrGrowthValue());
// memberInfoModel.setNextMemberLevel(memberInfoResult.getNextMemberLevel());
// memberInfoModel.setNextMemberLevelName(memberInfoResult.getNextMemberLevelName());
// memberInfoModel.setNextMemLevelGrowthVal(memberInfoResult.getNextMemLevelGrowthVal());
//
// memberInfoModel.setNickName(memberInfoResult.getNickName());
// memberInfoModel.setAvatarUrl(Optional.ofNullable(memberInfoResult.getAvatarUrl()).orElse(DEFAULT_AVATAR_URL));
// memberInfoModel.setIsDeleted(BloCommonConstant.IsDeleted.N);
//
// memberInfoModel = bizMemberInfoService.save(memberInfoModel);
// Integer memberId = memberInfoModel.getMemberId();
//
// //检查是否已有绑定关系
// BizMember3rdPartyRelationEntity blRelationItem = bizMember3rdPartyRelationService.getByRelationIdAndPlatform(encodeMemberId, Member3rdPartyRelationEnum.BL_OPEN);
// //绑定第三方关系表
// if (blRelationItem == null) {
// BizMember3rdPartyRelationEntity blRelation = new BizMember3rdPartyRelationEntity();
// blRelation.setMemberId(memberId);
// blRelation.setRelationId(encodeMemberId);
// blRelation.setRelationPlatform(Member3rdPartyRelationEnum.BL_OPEN.name());
// bizMember3rdPartyRelationService.save(blRelation);
// }
//
// //缓存会员token 有效期30天
// String key = BloRedisKeyConstant.MEMBER_TOKEN + ":" + memberId;
// logger.info("缓存会员token:key:[{}],memberToken:[{}]", key, memberToken);
// //25天
// redisService.set(key, memberToken, 2160000);
//
// MemberInfoDto memberInfo = new MemberInfoDto();
// BeanUtils.copyProperties(memberInfoModel, memberInfo);
// memberInfo.setBlEncodeMemberId(encodeMemberId);
// memberInfo.setBlMemberToken(memberToken);
// return memberInfo;
// }
//
// /**
// * 检查参数
// *
// * @param memberInfoDto
// */
// private void check(MemberInfoDto memberInfoDto) {
// Assert.notNull(memberInfoDto);
// Assert.notNull(memberInfoDto.getMobilePhone());
// Assert.notNull(memberInfoDto.getSmsCode());
// }
//
//}
//
//
//
src/main/java/cn/com/gsst/auth/support/register/channel/bl/BlWxMiniRegisterService.java
0 → 100644
View file @
52bb15fa
//package cn.com.gsst.support.register.channel.bl;
//
//
//import cn.com.blo.common.constant.BloCommonConstant;
//import cn.com.blo.common.constant.BloRedisKeyConstant;
//import cn.com.blo.common.service.CommonParamConfigService;
//import cn.com.blo.common.utils.NumberUtils;
//import cn.com.blo.common.utils.StringUtils;
//import cn.com.blo.support.register.ThirdPlatformRegisterService;
//import cn.com.blo.thirdParty.bl.api.BlMemberApi;
//import cn.com.blo.thirdParty.bl.domain.BlConfigEntity;
//import cn.com.blo.thirdParty.bl.request.BlMemberInfoRequest;
//import cn.com.blo.thirdParty.bl.request.BlMemberRequest;
//import cn.com.blo.thirdParty.bl.result.BlMemberAuthResult;
//import cn.com.blo.thirdParty.bl.result.BlMemberInfoResult;
//import cn.com.blo.thirdParty.bl.utils.BlAbstractHttpClient;
//import cn.com.blo.user.constant.Member3rdPartyRelationEnum;
//import cn.com.blo.user.dto.MemberInfoDto;
//import cn.com.blo.user.entity.BizMember3rdPartyRelationEntity;
//import cn.com.blo.user.model.BizMemberInfoModel;
//import cn.com.blo.user.service.BizMember3rdPartyRelationService;
//import cn.com.blo.user.service.BizMemberInfoService;
//import cn.com.blo.wx.constant.BloWxAppSceneCodeConstant;
//import cn.com.blo.wx.entity.BizWxAppInfo;
//import cn.com.blo.wx.service.BizWxAppInfoService;
//import cn.com.gsst.marketing.tools.service.RedisService;
//import cn.com.yict.framemax.core.i18n.I18nMessageException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.util.Assert;
//
//import javax.annotation.Resource;
//import java.util.Optional;
//
//@Service
//public class BlWxMiniRegisterService implements ThirdPlatformRegisterService {
//
// private Logger logger = LoggerFactory.getLogger(this.getClass());
//
// @Resource
// private BizMemberInfoService bizMemberInfoService;
//
// @Resource
// private BizMember3rdPartyRelationService bizMember3rdPartyRelationService;
//
// @Resource
// private BizWxAppInfoService bizWxAppInfoService;
//
// @Resource
// private CommonParamConfigService commonParamConfigService;
//
// @Resource
// private RedisService redisService;
//
// @Resource
// private BlAbstractHttpClient blAbstractHttpClient;
//
// private final static String DEFAULT_AVATAR_URL = "https://blo-prod.obs.cn-east-3.myhuaweicloud.com/mini/icon/mini-dafault-avatar.png";
//
//
// /**
// * 第三方平台注册
// *
// * @param memberInfoDto
// * @return
// */
// @Override
// public MemberInfoDto doRegister(MemberInfoDto memberInfoDto) throws Exception {
//
// //参数校验
// check(memberInfoDto);
//
// BizWxAppInfo wxAppInfo = bizWxAppInfoService.getBySceneCode(BloWxAppSceneCodeConstant.BLO_MINI);
// if (wxAppInfo == null) {
// throw new I18nMessageException("获取小程序信息异常!请检查配置是否正确!");
// }
//
// //查询配置
// BlConfigEntity blThirdPartyConfig = commonParamConfigService.getBlThirdPartyConfig();
// if (blThirdPartyConfig == null
// || StringUtils.isBlank(blThirdPartyConfig.getAppKey())
// || StringUtils.isBlank(blThirdPartyConfig.getAppSecret())
// || StringUtils.isBlank(blThirdPartyConfig.getThirdPartyIdTypeMini())
// || StringUtils.isBlank(blThirdPartyConfig.getSysId())) {
// throw new I18nMessageException("百联通开放平台配置异常!");
// }
//
// //调百联小程序注册接口
// BlMemberRequest regRequest = new BlMemberRequest();
// regRequest.setThirdPartyIdType(blThirdPartyConfig.getThirdPartyIdTypeMini());
// regRequest.setWxAppId(wxAppInfo.getAppId());
// regRequest.setWxLoginCode(memberInfoDto.getAuthorizeCode());
// regRequest.setUserInfoEncryptedData(memberInfoDto.getUserInfoEncryptedData());
// regRequest.setWxGetUserInfoIv(memberInfoDto.getWxGetUserInfoIv());
// regRequest.setPhoneNumberEncryptedData(memberInfoDto.getPhoneNumberEncryptedData());
// regRequest.setWxGetPhoneNumberIv(memberInfoDto.getWxGetPhoneNumberIv());
// regRequest.setSysid(blThirdPartyConfig.getSysId());
// regRequest.setAdChannel("CRM_HZALTF");
// regRequest.setBatchid("MD1627875917460");
// regRequest.setComBizId(blThirdPartyConfig.getOperationTypeId());
// regRequest.setShopCode(blThirdPartyConfig.getShopCode());
// if (StringUtils.isNotBlank(blThirdPartyConfig.getMemberRegAdChannel())
// && StringUtils.isNotBlank(blThirdPartyConfig.getMemberRegBatchId())) {
// regRequest.setAdChannel(blThirdPartyConfig.getMemberRegAdChannel());
// regRequest.setBatchid(blThirdPartyConfig.getMemberRegBatchId());
// }
//
// BlMemberAuthResult blMemberAuthResult = blAbstractHttpClient.doRequest(blThirdPartyConfig.getAppKey(),
// blThirdPartyConfig.getAppSecret(), BlMemberApi.MINI_AUTH, regRequest);
//
// String encodeMemberId = blMemberAuthResult.getEncodeMemberId();
// String memberToken = blMemberAuthResult.getMemberToken();
// BlMemberAuthResult.BlWxUserInfo userInfo = blMemberAuthResult.getUserInfo();
//
// //查询百联会员信息
// BlMemberInfoRequest memberInfoRequest = new BlMemberInfoRequest();
// memberInfoRequest.setMemberToken(memberToken);
// BlMemberInfoResult memberInfoResult = blAbstractHttpClient.doRequest(BlMemberApi.MEMBER_INFO, memberInfoRequest);
//
// //检查是否已有绑定关系
// BizMember3rdPartyRelationEntity blRelationItem = bizMember3rdPartyRelationService.getByRelationIdAndPlatform(encodeMemberId, Member3rdPartyRelationEnum.BL_OPEN);
//
// BizMemberInfoModel memberInfoModel = null;
// Integer memberId = null;
// if (blRelationItem != null) {
// //已存在会员信息,则更新
// memberId = blRelationItem.getMemberId();
// memberInfoModel = bizMemberInfoService.get(memberId);
// memberInfoModel.setMemberLevel(memberInfoResult.getMemberLevel());
// memberInfoModel.setMemberLevelName(memberInfoResult.getMemberLevelName());
// memberInfoModel.setMobilePhone(memberInfoResult.getMobileMask());
// memberInfoModel.setMobileMask(memberInfoResult.getMobileMask());
// memberInfoModel.setRemainPoints(NumberUtils.defaultZeroIfNull(memberInfoResult.getRemainPoints()));
// memberInfoModel.setCurrGrowthValue(memberInfoResult.getCurrGrowthValue());
// memberInfoModel.setNextMemberLevel(memberInfoResult.getNextMemberLevel());
// memberInfoModel.setNextMemberLevelName(memberInfoResult.getNextMemberLevelName());
// memberInfoModel.setNextMemLevelGrowthVal(memberInfoResult.getNextMemLevelGrowthVal());
// memberInfoModel.setAvatarUrl(Optional.ofNullable(memberInfoResult.getAvatarUrl()).orElse(DEFAULT_AVATAR_URL));
// memberInfoModel = bizMemberInfoService.save(memberInfoModel);
//
// } else {
// //保存会员信息
// memberInfoModel = new BizMemberInfoModel();
// memberInfoModel.setMemberLevel(memberInfoResult.getMemberLevel());
// memberInfoModel.setMemberLevelName(memberInfoResult.getMemberLevelName());
// memberInfoModel.setMobilePhone(memberInfoResult.getMobileMask());
// memberInfoModel.setMobileMask(memberInfoResult.getMobileMask());
// memberInfoModel.setRemainPoints(NumberUtils.defaultZeroIfNull(memberInfoResult.getRemainPoints()));
// memberInfoModel.setCurrGrowthValue(memberInfoResult.getCurrGrowthValue());
// memberInfoModel.setNextMemberLevel(memberInfoResult.getNextMemberLevel());
// memberInfoModel.setNextMemberLevelName(memberInfoResult.getNextMemberLevelName());
// memberInfoModel.setNextMemLevelGrowthVal(memberInfoResult.getNextMemLevelGrowthVal());
//
// memberInfoModel.setNickName(memberInfoResult.getNickName());
// memberInfoModel.setAvatarUrl(DEFAULT_AVATAR_URL);
// memberInfoModel.setIsDeleted(BloCommonConstant.IsDeleted.N);
//
// memberInfoModel = bizMemberInfoService.save(memberInfoModel);
// memberId = memberInfoModel.getMemberId();
//
// BizMember3rdPartyRelationEntity blRelation = new BizMember3rdPartyRelationEntity();
// blRelation.setMemberId(memberId);
// blRelation.setRelationId(encodeMemberId);
// blRelation.setRelationPlatform(Member3rdPartyRelationEnum.BL_OPEN.name());
// bizMember3rdPartyRelationService.save(blRelation);
// }
//
// if (userInfo != null) {
// String openId = userInfo.getOpenId();
// String unionId = userInfo.getUnionId();
// if (StringUtils.isNotBlank(openId)) {
// BizMember3rdPartyRelationEntity wxMiniRelationItem = bizMember3rdPartyRelationService.getByRelationIdAndPlatform(openId, Member3rdPartyRelationEnum.WX_MINI);
// if (wxMiniRelationItem == null) {
// BizMember3rdPartyRelationEntity openIdRelation = new BizMember3rdPartyRelationEntity();
// openIdRelation.setMemberId(memberId);
// openIdRelation.setRelationId(openId);
// openIdRelation.setRelationPlatform(Member3rdPartyRelationEnum.WX_MINI.name());
// bizMember3rdPartyRelationService.save(openIdRelation);
// }
// }
// if (StringUtils.isNotBlank(unionId)) {
// BizMember3rdPartyRelationEntity wxOpenRelationItem = bizMember3rdPartyRelationService.getByRelationIdAndPlatform(openId, Member3rdPartyRelationEnum.WX_MINI);
// if (wxOpenRelationItem == null) {
// BizMember3rdPartyRelationEntity unionIdRelation = new BizMember3rdPartyRelationEntity();
// unionIdRelation.setMemberId(memberId);
// unionIdRelation.setRelationId(unionId);
// unionIdRelation.setRelationPlatform(Member3rdPartyRelationEnum.WX_OPEN.name());
// bizMember3rdPartyRelationService.save(unionIdRelation);
// }
// }
// }
//
// //缓存会员token 有效期30天
// String key = BloRedisKeyConstant.MEMBER_TOKEN + ":" + memberId;
// logger.info("缓存会员token:key:[{}],memberToken:[{}]", key, memberToken);
// //25天
// redisService.set(key, memberToken, 2160000);
//
// MemberInfoDto memberInfo = new MemberInfoDto();
// BeanUtils.copyProperties(memberInfoModel, memberInfo);
// memberInfo.setBlEncodeMemberId(encodeMemberId);
// memberInfo.setBlMemberToken(memberToken);
// return memberInfo;
// }
//
// /**
// * 检查参数
// *
// * @param memberInfoDto
// */
// private void check(MemberInfoDto memberInfoDto) {
// Assert.notNull(memberInfoDto);
// Assert.notNull(memberInfoDto.getAuthorizeCode());
// Assert.notNull(memberInfoDto.getUserInfoEncryptedData());
// Assert.notNull(memberInfoDto.getWxGetUserInfoIv());
// Assert.notNull(memberInfoDto.getPhoneNumberEncryptedData());
// Assert.notNull(memberInfoDto.getWxGetPhoneNumberIv());
// }
//}
//
//
//
src/main/java/cn/com/gsst/auth/support/security/oauth/DummyUserBaseModel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
;
import
cn.com.yict.framemax.data.model.UserBaseModel
;
public
class
DummyUserBaseModel
implements
UserBaseModel
{
private
String
userAccount
=
"oonU65AbRQjmV3XQo10POJewbjxE"
;
@Override
public
Long
getUserId
()
{
return
999L
;
}
@Override
public
String
getUserName
()
{
return
"张三"
;
}
public
void
setUserAccount
(
String
userAccount
)
{
this
.
userAccount
=
userAccount
;
}
@Override
public
String
getUserAccount
()
{
return
this
.
userAccount
;
}
@Override
public
String
getCentralAccount
()
{
return
null
;
}
@Override
public
String
getPassword
()
{
return
null
;
}
@Override
public
String
getUserBuId
()
{
return
null
;
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/MultiDomainOauthTokenOperatorImplementor.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
;
import
cn.com.gsst.auth.common.constant.FmxParamConfigConstant
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
cn.com.yict.framemax.security.oauth.OauthTokenOperator
;
import
cn.com.yict.framemax.security.oauth.entity.OauthTokenEntity
;
import
cn.com.yict.framemax.security.oauth.entity.TokenEntity
;
import
cn.com.yict.framemax.security.oauth.exception.TokenExpiredException
;
import
cn.com.yict.framemax.security.oauth.support.OauthTokenOperatorImplementor
;
import
cn.com.yict.framemax.security.oauth.support.OauthTokenStorage
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.util.Date
;
public
class
MultiDomainOauthTokenOperatorImplementor
extends
OauthTokenOperatorImplementor
implements
OauthTokenOperator
{
@Resource
private
OauthTokenStorage
tokenStorage
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
OauthTokenEntity
genOauthToken
(
String
user
)
{
if
(
fmxParamConfigService
.
getConfig
(
FmxParamConfigConstant
.
TOKEN_EXPIRED_HOURS
)
==
null
)
{
throw
new
I18nMessageException
(
"exception/login.expiration.time.configured.as.empty"
);
}
super
.
tokenExpiredHours
=
Long
.
valueOf
(
fmxParamConfigService
.
getConfig
(
FmxParamConfigConstant
.
TOKEN_EXPIRED_HOURS
).
getParamValue
());
Assert
.
hasText
(
user
);
TokenEntity
oauthToken
=
super
.
newBaseOauthToken
(
user
,
null
);
TokenEntity
refreshToken
=
super
.
newBaseRefreshToken
(
user
);
oauthToken
.
setToken1
(
refreshToken
.
getToken
());
refreshToken
.
setToken1
(
oauthToken
.
getToken
());
this
.
tokenStorage
.
persistToken
(
oauthToken
,
refreshToken
);
OauthTokenEntity
result
=
new
OauthTokenEntity
();
result
.
setCreatedOn
(
oauthToken
.
getCreatedOn
());
result
.
setExpiredOn
(
oauthToken
.
getExpiredOn
());
result
.
setUser
(
oauthToken
.
getUser
());
result
.
setOauthToken
(
oauthToken
.
getToken
());
result
.
setRefreshToken
(
refreshToken
.
getToken
());
return
result
;
}
@Override
public
OauthTokenEntity
refreshOauthToken
(
String
refreshToken
)
throws
TokenExpiredException
{
TokenEntity
refreshTokenEntity
=
this
.
tokenStorage
.
readRefreshToken
(
refreshToken
);
if
(
refreshTokenEntity
==
null
||
StringUtils
.
isEmpty
(
refreshTokenEntity
.
getUser
()))
{
throw
new
TokenExpiredException
();
}
this
.
verifyTokenEntity
(
refreshTokenEntity
);
this
.
evcitOauthToken
(
refreshTokenEntity
.
getToken1
());
TokenEntity
oauthTokenEntity
=
super
.
newBaseOauthToken
(
refreshTokenEntity
.
getUser
(),
null
);
refreshTokenEntity
.
setToken1
(
oauthTokenEntity
.
getToken
());
oauthTokenEntity
.
setToken1
(
refreshTokenEntity
.
getToken
());
//延长refreshToken过期时间
long
refreshTokenExpiredOn
=
System
.
currentTimeMillis
()
+
1000
*
60
*
60
*
super
.
refreshTokenExpiredHours
;
refreshTokenEntity
.
setExpiredOn
(
new
Date
(
refreshTokenExpiredOn
));
this
.
tokenStorage
.
persistToken
(
oauthTokenEntity
,
refreshTokenEntity
);
OauthTokenEntity
result
=
new
OauthTokenEntity
();
result
.
setCreatedOn
(
oauthTokenEntity
.
getCreatedOn
());
result
.
setExpiredOn
(
oauthTokenEntity
.
getExpiredOn
());
result
.
setUser
(
oauthTokenEntity
.
getUser
());
result
.
setOauthToken
(
oauthTokenEntity
.
getToken
());
result
.
setRefreshToken
(
refreshToken
);
return
result
;
}
@Override
public
OauthTokenEntity
decodeOauthToken
(
String
oauthToken
)
throws
TokenExpiredException
{
if
(
StringUtils
.
isEmpty
(
oauthToken
))
{
throw
new
TokenExpiredException
();
}
TokenEntity
entity
=
null
;
if
(
oauthToken
.
indexOf
(
'.'
)
>
-
1
)
{
entity
=
super
.
decodeBaseOauthToken
(
oauthToken
,
true
);
String
refreshToken
=
tokenStorage
.
getRefreshTokenByOauthToken
(
entity
);
if
(
StringUtils
.
isEmpty
(
refreshToken
))
{
throw
new
TokenExpiredException
();
}
entity
.
setToken1
(
refreshToken
);
}
else
{
entity
=
this
.
tokenStorage
.
readOauthToken
(
oauthToken
);
verifyTokenEntity
(
entity
);
}
OauthTokenEntity
result
=
new
OauthTokenEntity
();
result
.
setCreatedOn
(
entity
.
getCreatedOn
());
result
.
setExpiredOn
(
entity
.
getExpiredOn
());
result
.
setOauthToken
(
entity
.
getToken
());
result
.
setRefreshToken
(
entity
.
getToken1
());
result
.
setUser
(
entity
.
getUser
());
return
result
;
}
@Override
public
void
evcitOauthToken
(
String
oauthToken
)
{
TokenEntity
tokenEntity
=
super
.
decodeBaseOauthToken
(
oauthToken
,
false
);
this
.
tokenStorage
.
evictOauthToken
(
tokenEntity
);
}
@Override
public
void
evcitRefreshToken
(
String
refreshToken
)
{
this
.
tokenStorage
.
evictRefreshToken
(
refreshToken
);
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/MultiDomainOauthUserManagerImplementor.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
;
import
cn.com.gsst.auth.support.security.oauth.constants.OauthConstants
;
import
cn.com.gsst.auth.support.security.oauth.entity.MemberResponse
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.security.authentication.SecurityAuthenticationToken
;
import
cn.com.yict.framemax.security.oauth.OauthUserManager
;
import
cn.com.yict.framemax.security.oauth.entity.OauthTokenEntity
;
import
cn.com.yict.framemax.security.oauth.support.OauthUserManagerImplementor
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.security.core.AuthenticationException
;
import
javax.annotation.Resource
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
public
class
MultiDomainOauthUserManagerImplementor
extends
OauthUserManagerImplementor
implements
OauthUserManager
{
private
static
final
int
MAX_SIZE
=
50
;
private
Map
<
String
,
SecurityAuthenticationToken
>
securityTokenCache
=
new
LinkedHashMap
<
String
,
SecurityAuthenticationToken
>()
{
protected
boolean
removeEldestEntry
(
Entry
<
String
,
SecurityAuthenticationToken
>
eldest
)
{
return
this
.
size
()
>=
50
;
}
};
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
public
MultiDomainOauthUserManagerImplementor
()
{
}
@Override
public
SecurityAuthenticationToken
authUser
(
String
oauthCode
,
String
password
,
String
key
)
throws
AuthenticationException
{
if
(
oauthCode
.
startsWith
(
OauthConstants
.
TypePrefix
.
MEMBER_DOMAIN
))
{
return
doMemberPlatformSecurityAuthenticationToken
(
oauthCode
);
}
else
{
return
super
.
authUser
(
oauthCode
,
password
,
key
);
}
}
@Override
public
SecurityAuthenticationToken
loadSecurityToken
(
OauthTokenEntity
tokenEntity
)
{
if
(
tokenEntity
.
getUser
().
startsWith
(
OauthConstants
.
TypePrefix
.
MEMBER_DOMAIN
))
{
return
doMemberPlatformSecurityAuthenticationToken
(
tokenEntity
.
getUser
());
}
else
{
return
super
.
loadSecurityToken
(
tokenEntity
);
}
}
public
SecurityAuthenticationToken
doMemberPlatformSecurityAuthenticationToken
(
String
userAccount
)
{
SecurityAuthenticationToken
securityToken
=
null
;
String
cuttedUserAccount
=
String
.
valueOf
(
StringUtils
.
substringAfterLast
(
userAccount
,
OauthConstants
.
TypePrefix
.
MEMBER_DOMAIN
));
try
{
MemberInfoEntity
memberInfoModel
=
bizMemberInfoService
.
getById
(
Integer
.
valueOf
(
cuttedUserAccount
));
if
(
memberInfoModel
!=
null
)
{
MemberResponse
response
=
new
MemberResponse
();
BeanUtils
.
copyProperties
(
memberInfoModel
,
response
);
response
.
setUserAccount
(
userAccount
);
response
.
setUserName
(
memberInfoModel
.
getNickName
());
securityToken
=
new
SecurityAuthenticationToken
(
response
,
null
,
null
);
}
}
catch
(
Exception
e
)
{
throw
new
I18nMessageException
(
e
.
getMessage
());
}
return
securityToken
;
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/constants/OauthConstants.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
.
constants
;
public
class
OauthConstants
{
/**
* 类型前缀
*/
public
class
TypePrefix
{
public
static
final
String
MEMBER_DOMAIN
=
"/member_platform/"
;
// public static final String STAFF_DOMAIN = "/staff/";
//
// public static final String OPEN_PLATFORM = "/open_platform/";
//
// public static final String EXPOSE_USER_DOMAIN = "/expose_user/";
//
// public static final String EXPOSE_STAFF_DOMAIN = "/expose_staff/";
}
/**
* 用户类型
*/
public
class
UserType
{
public
static
final
String
MEMBER_DOMAIN
=
"member_platform"
;
// public static final String STAFF_DOMAIN = "staff";
//
// public static final String OPEN_PLATFORM = "open_platform";
//
// public static final String SYSTEM_USER = "system_user";
//
// public static final String EXPOSE_USER_DOMAIN = "expose_user";
//
// public static final String EXPOSE_STAFF_DOMAIN = "expose_staff";
}
public
enum
OauthEnum
{
MEMBER_DOMAIN
(
UserType
.
MEMBER_DOMAIN
,
"会员"
);
// STAFF_DOMAIN(UserType.STAFF_DOMAIN,"员工"),
//
// OPEN_PLATFORM(UserType.OPEN_PLATFORM,"第三方开放平台"),
//
// SYSTEM_USER(UserType.SYSTEM_USER,"系统用户"),
//
// EXPOSE_USER_DOMAIN(UserType.EXPOSE_USER_DOMAIN,"第三方系统用户"),
//
// EXPOSE_STAFF_DOMAIN(UserType.EXPOSE_STAFF_DOMAIN,"第三方员工");
String
userType
;
String
userTypeName
;
OauthEnum
(
String
userType
,
String
userTypeName
)
{
this
.
userType
=
userType
;
this
.
userTypeName
=
userTypeName
;
}
public
String
getUserType
()
{
return
userType
;
}
public
void
setUserType
(
String
userType
)
{
this
.
userType
=
userType
;
}
public
String
getUserTypeName
()
{
return
userTypeName
;
}
public
void
setUserTypeName
(
String
userTypeName
)
{
this
.
userTypeName
=
userTypeName
;
}
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/entity/MemberResponse.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
.
entity
;
import
cn.com.gsst.auth.user.model.BizMemberInfoModel
;
import
cn.com.yict.framemax.data.model.UserBaseModel
;
public
class
MemberResponse
extends
BizMemberInfoModel
implements
UserBaseModel
{
private
String
userAccount
;
private
String
userName
;
@Override
public
Long
getUserId
()
{
return
super
.
getMemberId
().
longValue
();
}
@Override
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
@Override
public
String
getUserAccount
()
{
return
userAccount
;
}
public
void
setUserAccount
(
String
userAccount
)
{
this
.
userAccount
=
userAccount
;
}
@Override
public
String
getCentralAccount
()
{
return
null
;
}
@Override
public
String
getPassword
()
{
return
null
;
}
@Override
public
String
getUserBuId
()
{
return
null
;
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/entity/OpenPlatformEntity.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
.
entity
;
import
cn.com.yict.framemax.data.model.UserBaseModel
;
/**
* @author alex.yao
* @date 2023/11/23
**/
public
class
OpenPlatformEntity
implements
UserBaseModel
{
private
String
appKey
;
@Override
public
Long
getUserId
()
{
return
null
;
}
@Override
public
String
getUserName
()
{
return
appKey
;
}
public
void
setUserName
(
String
userName
)
{
this
.
appKey
=
userName
;
}
@Override
public
String
getUserAccount
()
{
return
appKey
;
}
public
void
setUserAccount
(
String
userAccount
)
{
this
.
appKey
=
appKey
;
}
@Override
public
String
getCentralAccount
()
{
return
null
;
}
@Override
public
String
getPassword
()
{
return
null
;
}
@Override
public
String
getUserBuId
()
{
return
null
;
}
}
src/main/java/cn/com/gsst/auth/support/security/oauth/entity/UserBaseEntity.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
security
.
oauth
.
entity
;
import
cn.com.yict.framemax.data.model.UserBaseModel
;
public
class
UserBaseEntity
implements
UserBaseModel
{
public
String
type
;
public
Long
userId
;
public
String
userName
;
public
String
userAccount
;
public
String
centralAccount
;
public
String
password
;
public
String
userBuId
;
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
@Override
public
Long
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
Long
userId
)
{
this
.
userId
=
userId
;
}
@Override
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
@Override
public
String
getUserAccount
()
{
return
userAccount
;
}
public
void
setUserAccount
(
String
userAccount
)
{
this
.
userAccount
=
userAccount
;
}
@Override
public
String
getCentralAccount
()
{
return
centralAccount
;
}
public
void
setCentralAccount
(
String
centralAccount
)
{
this
.
centralAccount
=
centralAccount
;
}
@Override
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
@Override
public
String
getUserBuId
()
{
return
userBuId
;
}
}
src/main/java/cn/com/gsst/auth/support/sms/ThirdPlatformSmsService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
;
import
cn.com.gsst.auth.common.dto.SmsDto
;
/**
* @author Focan.Zhong
*/
public
interface
ThirdPlatformSmsService
{
/**
* 第三方平台验证码
*
* @param smsDto
* @return
*/
boolean
doSend
(
SmsDto
smsDto
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/support/sms/ThirdPlatformSmsServiceBuilder.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
;
import
cn.com.gsst.auth.support.sms.constant.SmsConstant
;
import
cn.com.gsst.auth.support.sms.channel.baidu.BaiDuThirdPlatformService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
/**
* @author Focan.Zhong
*/
@Component
public
class
ThirdPlatformSmsServiceBuilder
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
public
ThirdPlatformSmsService
getService
(
SmsConstant
.
Channel
channel
)
throws
Exception
{
if
(
SmsConstant
.
Channel
.
baidu
.
equals
(
channel
))
{
return
applicationContext
.
getBean
(
BaiDuThirdPlatformService
.
class
);
}
throw
new
I18nMessageException
(
"exception/verification.code.channel.abnormality"
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
src/main/java/cn/com/gsst/auth/support/sms/channel/DefaultSmsService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
.
channel
;
import
cn.com.gsst.auth.common.dto.SmsDto
;
import
cn.com.gsst.auth.support.sms.ThirdPlatformSmsService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
/**
* @author Focan.Zhong
*/
@Service
public
class
DefaultSmsService
implements
ThirdPlatformSmsService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
/**
* 第三方平台验证码
*
* @param smsDto
* @return
*/
@Override
public
boolean
doSend
(
SmsDto
smsDto
)
throws
Exception
{
throw
new
I18nMessageException
(
"exception/there.is.currently.no.default.verification.code.channel.login"
);
}
}
src/main/java/cn/com/gsst/auth/support/sms/channel/baidu/BaiDuThirdPlatformService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
.
channel
.
baidu
;
import
cn.com.gsst.auth.common.dto.SmsDto
;
import
cn.com.gsst.auth.support.sms.ThirdPlatformSmsService
;
import
cn.com.yict.framemax.core.config.Config
;
import
com.baidubce.auth.DefaultBceCredentials
;
import
com.baidubce.services.sms.SmsClient
;
import
com.baidubce.services.sms.SmsClientConfiguration
;
import
com.baidubce.services.sms.model.SendMessageV3Request
;
import
com.baidubce.services.sms.model.SendMessageV3Response
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
/**
* @author Jennie.Chen
*/
@Component
public
class
BaiDuThirdPlatformService
implements
ThirdPlatformSmsService
{
@Override
public
boolean
doSend
(
SmsDto
smsDto
)
throws
Exception
{
String
ACCESS_KEY_ID
=
Config
.
get
(
"baidu.code.keyId"
);
String
SECRET_ACCESS_KEY
=
Config
.
get
(
"baidu.code.keySecret"
);
String
ENDPOINT
=
"http://smsv3.bj.baidubce.com"
;
String
code
=
smsDto
.
getSmsCode
();
SmsClientConfiguration
config
=
new
SmsClientConfiguration
();
config
.
setCredentials
(
new
DefaultBceCredentials
(
ACCESS_KEY_ID
,
SECRET_ACCESS_KEY
));
config
.
setEndpoint
(
ENDPOINT
);
SmsClient
client
=
new
SmsClient
(
config
);
SendMessageV3Request
request
=
new
SendMessageV3Request
();
request
.
setMobile
(
smsDto
.
getMobilePhone
());
//判断手机号码是不是大陆的
boolean
matches
=
Pattern
.
matches
(
"(?:0|86|\\+86)?1[3-9]\\d{9}"
,
smsDto
.
getMobilePhone
());
if
(
matches
){
request
.
setSignatureId
(
Config
.
get
(
"baidu.code.mainLand.signatureId"
));
request
.
setTemplate
(
Config
.
get
(
"baidu.code.mainLand.template"
));
}
else
{
request
.
setSignatureId
(
Config
.
get
(
"baidu.code.gangAo.signatureId"
));
request
.
setTemplate
(
Config
.
get
(
"baidu.code.gangAo.template"
));
}
Map
<
String
,
String
>
contentVar
=
new
HashMap
<>();
contentVar
.
put
(
"SMSvCode"
,
code
);
request
.
setContentVar
(
contentVar
);
SendMessageV3Response
response
=
client
.
sendMessage
(
request
);
// 解析请求响应 response.isSuccess()为true 表示成功
if
(
response
!=
null
&&
response
.
isSuccess
())
{
return
true
;
}
else
{
return
false
;
}
}
}
src/main/java/cn/com/gsst/auth/support/sms/channel/bl/BlSmsService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
.
channel
.
bl
;
//package cn.com.gsst.support.sms.channel.bl;
//
//
//
//import cn.com.gsst.support.sms.constant.SmsConstant;
//import cn.com.gsst.common.dto.SmsDto;
//import cn.com.gsst.support.sms.ThirdPlatformSmsService;
//import cn.com.yict.framemax.core.i18n.I18nMessageException;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//
///**
// * @author Focan.Zhong
// */
//@Service
//public class BlSmsService implements ThirdPlatformSmsService {
//
// private Logger logger = LoggerFactory.getLogger(this.getClass());
//
// @Resource
// private CommonParamConfigService commonParamConfigService;
//
// @Resource
// private BlAbstractHttpClient blAbstractHttpClient;
//
// /**
// * 第三方平台验证码
// *
// * @param smsDto
// * @return
// */
// @Override
// public void doSend(SmsDto smsDto) throws Exception {
//
// //查询配置
// BlConfigEntity blThirdPartyConfig = commonParamConfigService.getBlThirdPartyConfig();
// if (blThirdPartyConfig == null
// || StringUtils.isBlank(blThirdPartyConfig.getAppKey())
// || StringUtils.isBlank(blThirdPartyConfig.getAppSecret())
// || StringUtils.isBlank(blThirdPartyConfig.getSysId())) {
// throw new I18nMessageException("百联通开放平台配置异常!");
// }
//
// //调百联通手机号注册接口
// BlMemberRequest request = new BlMemberRequest();
// request.setVerifyCodeType(smsDto.getVerifyCodeType());
// //滑块验证类型(必传) 2.图形验证码,3.滑块验证
// request.setVerifyImgType(smsDto.getVerifyImgType());
// // VerifyImgType = 2
// request.setVerifyImgCode(smsDto.getVerifyImgCode());
// // VerifyImgType = 3
// request.setTimestamp(System.currentTimeMillis() + "");
// request.setUniqueFlag(smsDto.getUniqueFlag());
// request.setxPercent(smsDto.getxPercent());
//
// request.setMobile(smsDto.getMobilePhone());
// request.setSysid(blThirdPartyConfig.getSysId());
//
// BlMemberAuthResult blMemberAuthResult = blAbstractHttpClient.doRequest(
// blThirdPartyConfig.getAppKey(),
// blThirdPartyConfig.getAppSecret(),
// BlMemberApi.CHECK_AND_SEND_SMS,
// request);
//
// // FAIL("0","滑块校验失败") INVALID("2","无效已过期的滑块验证码"),
// // SEND_CODE_SUCCESS("3","发送短信验证码成功"),
// // SEND_CODE_FAIL("4","发送短信验证码失败"),
// // OPERATING_FREQUENCY("5","操作过于频繁,请稍后再试!"),
// // VERIFY_CODE_FAIL("6","验证码错误")
// if (!SmsConstant.Status.BL.SEND_CODE_SUCCESS.getCode().equals(blMemberAuthResult.getStatus())) {
// throw new I18nMessageException(SmsConstant.Status.BL.getByStatus(blMemberAuthResult.getStatus()), blMemberAuthResult.getMsg());
// }
//
// }
//}
//
//
//
src/main/java/cn/com/gsst/auth/support/sms/constant/SmsConstant.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
support
.
sms
.
constant
;
/**
* 短信常量
*
* @author Focan.Zhong
*/
public
interface
SmsConstant
{
/**
* 第三方短信渠道
*/
enum
Channel
{
/**
* 百度
*/
baidu
,
;
}
/**
* 短信发送状态
*/
interface
Status
{
/**
* 百联状态
* <p>
* FAIL("0","滑块校验失败")
* INVALID("2","无效已过期的滑块验证码"),
* SEND_CODE_SUCCESS("3","发送短信验证码成功"),
* SEND_CODE_FAIL("4","发送短信验证码失败"),
* OPERATING_FREQUENCY("5","操作过于频繁,请稍后再试!"),
* VERIFY_CODE_FAIL("6","验证码错误")
*/
enum
BL
{
FAIL
(
"FAIL"
,
"0"
,
""
),
INVALID
(
"INVALID"
,
"2"
,
""
),
SEND_CODE_SUCCESS
(
"SEND_CODE_SUCCESS"
,
"3"
,
""
),
SEND_CODE_FAIL
(
"SEND_CODE_FAIL"
,
"4"
,
""
),
OPERATING_FREQUENCY
(
"OPERATING_FREQUENCY"
,
"5"
,
""
),
VERIFY_CODE_FAIL
(
"VERIFY_CODE_FAIL"
,
"6"
,
""
),
;
private
String
code
;
private
String
status
;
private
String
msg
;
BL
(
String
code
,
String
status
,
String
msg
)
{
this
.
code
=
code
;
this
.
status
=
status
;
this
.
msg
=
msg
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getStatus
()
{
return
status
;
}
public
String
getMsg
()
{
return
msg
;
}
public
static
BL
getByStatus
(
String
status
)
{
if
(
FAIL
.
getStatus
().
equals
(
status
))
{
return
FAIL
;
}
if
(
INVALID
.
getStatus
().
equals
(
status
))
{
return
INVALID
;
}
if
(
SEND_CODE_SUCCESS
.
getStatus
().
equals
(
status
))
{
return
SEND_CODE_SUCCESS
;
}
if
(
SEND_CODE_FAIL
.
getStatus
().
equals
(
status
))
{
return
SEND_CODE_FAIL
;
}
if
(
OPERATING_FREQUENCY
.
getStatus
().
equals
(
status
))
{
return
OPERATING_FREQUENCY
;
}
if
(
VERIFY_CODE_FAIL
.
getStatus
().
equals
(
status
))
{
return
VERIFY_CODE_FAIL
;
}
return
null
;
}
}
}
}
src/main/java/cn/com/gsst/auth/user/aggregation/MemberInfoService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
aggregation
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.dto.MemberPasswordRequestDto
;
import
cn.com.yict.framemax.core.service.BaseService
;
/**
* @Author:Roger Wu
* @name:aggregation
* @Date:2024-07-26 9:40
*/
public
interface
MemberInfoService
extends
BaseService
{
/**
* @param memberPasswordRequestDto
*/
void
configureMemberPassword
(
MemberPasswordRequestDto
memberPasswordRequestDto
)
throws
Exception
;
/**
* 更新用户信息
*
* @param memberInfoEntity
* @return
* @throws Exception
*/
MemberInfoEntity
updateMemberInfo
(
MemberInfoEntity
memberInfoEntity
);
}
src/main/java/cn/com/gsst/auth/user/aggregation/impl/MemberInfoServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
aggregation
.
impl
;
import
cn.com.gsst.auth.common.constant.RedisKeyConstant
;
import
cn.com.gsst.auth.common.service.RedisService
;
import
cn.com.gsst.auth.common.utils.StringUtils
;
import
cn.com.gsst.auth.user.aggregation.MemberInfoService
;
import
cn.com.gsst.auth.user.entity.Member3rdPartyRelationEntity
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.gsst.auth.user.constants.Member3rdPartyRelationConstants
;
import
cn.com.gsst.auth.user.dto.MemberPasswordRequestDto
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.gsst.auth.user.service.BizMember3rdPartyRelationService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.service.impl.BaseServiceImpl
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* @Author:Roger Wu
* @name:aggregation
* @Date:2024-07-26 9:40
*/
@Component
public
class
MemberInfoServiceImpl
extends
BaseServiceImpl
implements
MemberInfoService
{
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
@Resource
private
BizMember3rdPartyRelationService
bizMember3rdPartyRelationService
;
@Resource
private
RedisService
redisService
;
/**
* @param memberPasswordRequestDto
*/
@Override
public
void
configureMemberPassword
(
MemberPasswordRequestDto
memberPasswordRequestDto
)
throws
Exception
{
MemberInfoEntity
memberInfoEntity
=
bizMemberInfoService
.
getMemberEntityByAccount
(
memberPasswordRequestDto
.
getAccount
());
if
(
memberInfoEntity
==
null
)
{
throw
new
I18nMessageException
(
"exception/user.cannot.be.found"
);
}
String
authCode
=
(
String
)
redisService
.
get
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
memberPasswordRequestDto
.
getAccount
());
if
(
StringUtils
.
isBlank
(
authCode
)
&&
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getMobilePhone
()))
{
authCode
=
(
String
)
redisService
.
get
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
memberInfoEntity
.
getMobilePhone
());
}
if
(
StringUtils
.
isBlank
(
authCode
)
&&
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getEmail
()))
{
authCode
=
(
String
)
redisService
.
get
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
memberInfoEntity
.
getEmail
());
}
if
(!
memberPasswordRequestDto
.
getAuthCode
().
equals
(
authCode
))
{
throw
new
I18nMessageException
(
"exception/re-verify.the.user.identity"
);
}
Member3rdPartyRelationEntity
member3rdPartyRelationEntity
=
bizMember3rdPartyRelationService
.
getPwRelationByMemberId
(
memberInfoEntity
.
getMemberId
());
if
(
member3rdPartyRelationEntity
==
null
)
{
member3rdPartyRelationEntity
=
new
Member3rdPartyRelationEntity
();
member3rdPartyRelationEntity
.
setRelationPlatform
(
Member3rdPartyRelationConstants
.
RelationType
.
PW
);
member3rdPartyRelationEntity
.
setMemberId
(
memberInfoEntity
.
getMemberId
());
}
member3rdPartyRelationEntity
.
setRelationKey
(
memberPasswordRequestDto
.
getPassword
());
bizMember3rdPartyRelationService
.
createOrUpdateRelation
(
member3rdPartyRelationEntity
);
redisService
.
del
(
RedisKeyConstant
.
Code
.
AUTH_CODE
+
memberPasswordRequestDto
.
getAccount
());
}
@Override
public
MemberInfoEntity
updateMemberInfo
(
MemberInfoEntity
memberInfoEntity
)
{
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getMobilePhone
()))
{
CheckMemberInfoQueryCondition
condition
=
new
CheckMemberInfoQueryCondition
();
condition
.
setMemberId
(
memberInfoEntity
.
getMemberId
().
longValue
());
condition
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoQueryItems
=
bizMemberInfoService
.
checkMemberInfoIsExist
(
condition
);
if
(
CollectionUtils
.
isNotEmpty
(
checkMemberInfoQueryItems
))
{
throw
new
I18nMessageException
(
"exception/phone.is.exist"
);
}
}
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getEmail
()))
{
CheckMemberInfoQueryCondition
condition
=
new
CheckMemberInfoQueryCondition
();
condition
.
setMemberId
(
memberInfoEntity
.
getMemberId
().
longValue
());
condition
.
setEmail
(
memberInfoEntity
.
getEmail
());
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoQueryItems
=
bizMemberInfoService
.
checkMemberInfoIsExist
(
condition
);
if
(
CollectionUtils
.
isNotEmpty
(
checkMemberInfoQueryItems
))
{
throw
new
I18nMessageException
(
"exception/email.is.exist"
);
}
}
return
bizMemberInfoService
.
updateMemberInfo
(
memberInfoEntity
);
}
}
src/main/java/cn/com/gsst/auth/user/builder/EmailLoginChannel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.common.service.JudgeCodeService
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.utils.StringUtils
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.data.model.BaseModel
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Component
public
class
EmailLoginChannel
implements
LoginChannelService
{
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
@Resource
private
JudgeCodeService
judgeCodeService
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
BaseModel
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
Assert
.
notBlank
(
memberLoginRequest
.
getAccount
());
Assert
.
notBlank
(
memberLoginRequest
.
getAuthCode
());
if
(!
judgeCodeService
.
judgeCode
(
memberLoginRequest
.
getAccount
(),
memberLoginRequest
.
getAuthCode
()))
{
throw
new
I18nMessageException
(
"exception/verification.code.is.incorrect.please.re-enter"
);
}
MemberInfoEntity
result
=
bizMemberInfoService
.
getMemberEntityByAccount
(
memberLoginRequest
.
getAccount
());
if
(
result
==
null
)
{
CheckMemberInfoQueryCondition
condition
=
new
CheckMemberInfoQueryCondition
();
condition
.
setEmail
(
memberLoginRequest
.
getAccount
());
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoQueryItems
=
bizMemberInfoService
.
checkMemberInfoIsExist
(
condition
);
if
(
CollectionUtils
.
isEmpty
(
checkMemberInfoQueryItems
))
{
//用户没有注册过 需要注册
result
=
registerByEmail
(
memberLoginRequest
);
}
else
{
//用户已经注册过 直接登录
CheckMemberInfoQueryItem
checkMemberInfoQueryItem
=
checkMemberInfoQueryItems
.
get
(
0
);
Integer
memberId
=
checkMemberInfoQueryItem
.
getMemberId
();
result
=
bizMemberInfoService
.
getById
(
memberId
);
}
}
return
result
;
}
private
MemberInfoEntity
registerByEmail
(
MemberLoginRequestDto
memberLoginRequest
)
{
MemberInfoEntity
result
;
MemberInfoEntity
memberInfoEntity
=
new
MemberInfoEntity
();
memberInfoEntity
.
setAccount
(
memberLoginRequest
.
getAccount
());
memberInfoEntity
.
setNickName
(
memberLoginRequest
.
getAccount
());
memberInfoEntity
.
setEmail
(
memberLoginRequest
.
getAccount
());
String
param
=
fmxParamConfigService
.
getParam
(
"member.default.avatar"
);
if
(
StringUtils
.
isNoneBlank
(
param
))
{
memberInfoEntity
.
setAvatarUrl
(
param
);
}
result
=
bizMemberInfoService
.
createMemberInfo
(
memberInfoEntity
);
return
result
;
}
}
src/main/java/cn/com/gsst/auth/user/builder/GoogleLoginChannel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.common.utils.StringUtils
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.yict.framemax.core.config.Config
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.data.model.BaseModel
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
;
import
com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager
;
import
com.google.api.client.http.HttpTransport
;
import
com.google.api.client.http.apache.v2.ApacheHttpTransport
;
import
com.google.api.client.json.JsonFactory
;
import
com.google.api.client.json.gson.GsonFactory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author alex.yao
* @date 2024/12/24
*/
@Component
public
class
GoogleLoginChannel
implements
LoginChannelService
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
GoogleLoginChannel
.
class
);
private
static
final
String
CLIENT_ID
=
Config
.
get
(
"google.client.id"
);
private
final
HttpTransport
transport
=
new
ApacheHttpTransport
();
private
final
JsonFactory
jsonFactory
=
new
GsonFactory
();
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
BaseModel
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
GooglePublicKeysManager
.
Builder
builder
=
new
GooglePublicKeysManager
.
Builder
(
transport
,
jsonFactory
);
builder
.
setPublicCertsEncodedUrl
(
"https://google-api.gsstcloud.com/oauth2/v1/certs"
);
GoogleIdTokenVerifier
verifier
=
new
GoogleIdTokenVerifier
.
Builder
(
builder
.
build
())
.
setAudience
(
Collections
.
singletonList
(
CLIENT_ID
))
.
build
();
String
idTokenString
=
memberLoginRequest
.
getAuthCode
();
GoogleIdToken
idToken
=
verifier
.
verify
(
idTokenString
);
if
(
idToken
!=
null
)
{
Payload
payload
=
idToken
.
getPayload
();
String
userId
=
payload
.
getSubject
();
logger
.
info
(
"User ID: {}"
,
userId
);
String
email
=
payload
.
getEmail
();
String
name
=
(
String
)
payload
.
get
(
"name"
);
String
pictureUrl
=
(
String
)
payload
.
get
(
"picture"
);
MemberInfoEntity
result
=
bizMemberInfoService
.
getMemberEntityByAccount
(
email
);
if
(
result
==
null
)
{
CheckMemberInfoQueryCondition
condition
=
new
CheckMemberInfoQueryCondition
();
condition
.
setEmail
(
email
);
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoQueryItems
=
bizMemberInfoService
.
checkMemberInfoIsExist
(
condition
);
if
(
CollectionUtils
.
isEmpty
(
checkMemberInfoQueryItems
))
{
//用户没有注册过 需要注册
result
=
register
(
email
,
name
,
pictureUrl
);
}
else
{
//用户已经注册过 直接登录
CheckMemberInfoQueryItem
checkMemberInfoQueryItem
=
checkMemberInfoQueryItems
.
get
(
0
);
Integer
memberId
=
checkMemberInfoQueryItem
.
getMemberId
();
result
=
bizMemberInfoService
.
getById
(
memberId
);
}
}
return
result
;
}
else
{
logger
.
error
(
"Google id token is null"
);
throw
new
I18nMessageException
(
"exception/system.error"
);
}
}
private
MemberInfoEntity
register
(
String
email
,
String
name
,
String
avatar
)
{
MemberInfoEntity
result
;
MemberInfoEntity
memberInfoEntity
=
new
MemberInfoEntity
();
memberInfoEntity
.
setAccount
(
email
);
memberInfoEntity
.
setNickName
(
name
);
memberInfoEntity
.
setEmail
(
email
);
if
(
StringUtils
.
isBlank
(
avatar
))
{
avatar
=
fmxParamConfigService
.
getParam
(
"member.default.avatar"
);
}
memberInfoEntity
.
setAvatarUrl
(
avatar
);
result
=
bizMemberInfoService
.
createMemberInfo
(
memberInfoEntity
);
return
result
;
}
}
src/main/java/cn/com/gsst/auth/user/builder/LoginChannelBuilder.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.user.constants.UserLoginConstants
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
/**
* @Author:Roger Wu
* @name:LoginChannelBuilder
* @Date:2024-07-23 18:10
*/
@Component
public
class
LoginChannelBuilder
implements
ApplicationContextAware
{
private
ApplicationContext
applicationContext
;
public
LoginChannelService
getService
(
String
loginChannel
)
throws
Exception
{
Assert
.
notBlank
(
loginChannel
);
if
(
UserLoginConstants
.
LoginType
.
MEMBER_PLATFOMR_SMS
.
equals
(
loginChannel
))
{
return
applicationContext
.
getBean
(
SmsLoginChannel
.
class
);
}
else
if
(
UserLoginConstants
.
LoginType
.
MEMBER_PLATFOMR_PW
.
equals
(
loginChannel
))
{
return
applicationContext
.
getBean
(
PwLoginChannel
.
class
);
}
else
if
(
UserLoginConstants
.
LoginType
.
MEMBER_PLATFOMR_EMAIL
.
equals
(
loginChannel
))
{
return
applicationContext
.
getBean
(
EmailLoginChannel
.
class
);
}
else
if
(
UserLoginConstants
.
LoginType
.
MEMBER_PLATFOMR_GOOGLE
.
equals
(
loginChannel
)){
return
applicationContext
.
getBean
(
GoogleLoginChannel
.
class
);
}
throw
new
I18nMessageException
(
"exception/third.party.authorization.channel.abnormal"
);
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
this
.
applicationContext
=
applicationContext
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/builder/LoginChannelService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.yict.framemax.data.model.BaseModel
;
/**
* @Author:Roger Wu
* @name:LoginChannelBuilder
* @Date:2024-07-23 17:59
*/
public
interface
LoginChannelService
{
/**
* 登录方法
*
* @return
*/
public
BaseModel
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
;
}
src/main/java/cn/com/gsst/auth/user/builder/PwLoginChannel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.entity.Member3rdPartyRelationEntity
;
import
cn.com.gsst.auth.user.service.BizMember3rdPartyRelationService
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* @Author:Roger Wu
* @name:SmsLoginChannel
* @Date:2024-07-23 18:01
*/
@Component
public
class
PwLoginChannel
implements
LoginChannelService
{
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
@Resource
private
BizMember3rdPartyRelationService
bizMember3rdPartyRelationService
;
@Override
public
MemberInfoEntity
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
Assert
.
notBlank
(
memberLoginRequest
.
getPassword
());
MemberInfoEntity
memberEntityByAccount
=
bizMemberInfoService
.
getMemberEntityByAccount
(
memberLoginRequest
.
getAccount
());
if
(
memberEntityByAccount
==
null
)
{
//用户没有注册过 需要注册
throw
new
I18nMessageException
(
"exception/user.does.not.exist"
);
}
Integer
memberId
=
memberEntityByAccount
.
getMemberId
();
Member3rdPartyRelationEntity
relationByMemberIdEntity
=
bizMember3rdPartyRelationService
.
getPwRelationByMemberId
(
memberId
);
if
(
relationByMemberIdEntity
==
null
||
!
memberLoginRequest
.
getPassword
().
equals
(
relationByMemberIdEntity
.
getRelationKey
()))
{
throw
new
I18nMessageException
(
"exception/password.error.please.re-enter"
);
}
return
memberEntityByAccount
;
}
}
src/main/java/cn/com/gsst/auth/user/builder/SmsLoginChannel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
builder
;
import
cn.com.gsst.auth.common.service.JudgeCodeService
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.utils.StringUtils
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
/**
* @Author:Roger Wu
* @name:SmsLoginChannel
* @Date:2024-07-23 18:01
*/
@Service
public
class
SmsLoginChannel
implements
LoginChannelService
{
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
@Resource
private
JudgeCodeService
judgeCodeService
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
MemberInfoEntity
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
Assert
.
notBlank
(
memberLoginRequest
.
getAccount
());
Assert
.
notBlank
(
memberLoginRequest
.
getAuthCode
());
//验证验证码
if
(!
judgeCodeService
.
judgeCode
(
memberLoginRequest
.
getAccount
(),
memberLoginRequest
.
getAuthCode
()))
{
throw
new
I18nMessageException
(
"exception/verification.code.is.incorrect.please.re-enter"
);
}
MemberInfoEntity
result
=
bizMemberInfoService
.
getMemberEntityByAccount
(
memberLoginRequest
.
getAccount
());
if
(
result
==
null
)
{
//用户没有注册过 需要注册
CheckMemberInfoQueryCondition
condition
=
new
CheckMemberInfoQueryCondition
();
condition
.
setMobilePhone
(
memberLoginRequest
.
getAccount
());
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoQueryItems
=
bizMemberInfoService
.
checkMemberInfoIsExist
(
condition
);
if
(
CollectionUtils
.
isEmpty
(
checkMemberInfoQueryItems
))
{
result
=
registerByMobilePhone
(
memberLoginRequest
);
}
else
{
//用户已经注册过 直接登录
CheckMemberInfoQueryItem
checkMemberInfoQueryItem
=
checkMemberInfoQueryItems
.
get
(
0
);
Integer
memberId
=
checkMemberInfoQueryItem
.
getMemberId
();
result
=
bizMemberInfoService
.
getById
(
memberId
);
}
}
return
result
;
}
private
MemberInfoEntity
registerByMobilePhone
(
MemberLoginRequestDto
memberLoginRequest
)
{
MemberInfoEntity
result
;
MemberInfoEntity
memberInfoEntity
=
new
MemberInfoEntity
();
memberInfoEntity
.
setAccount
(
memberLoginRequest
.
getAccount
());
memberInfoEntity
.
setNickName
(
memberLoginRequest
.
getAccount
());
String
param
=
fmxParamConfigService
.
getParam
(
"member.default.avatar"
);
if
(
StringUtils
.
isNoneBlank
(
param
))
{
memberInfoEntity
.
setAvatarUrl
(
param
);
}
memberInfoEntity
.
setMobilePhone
(
memberLoginRequest
.
getAccount
());
result
=
bizMemberInfoService
.
createMemberInfo
(
memberInfoEntity
);
return
result
;
}
}
src/main/java/cn/com/gsst/auth/user/constants/Member3rdPartyRelationConstants.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
constants
;
/**
* @Author:Roger Wu
* @name:Member3rdPartyRelationConstants
* @Date:2024-07-28 23:28
*/
public
class
Member3rdPartyRelationConstants
{
public
static
class
RelationType
{
// 账号密码
public
final
static
String
PW
=
"PW"
;
}
}
src/main/java/cn/com/gsst/auth/user/constants/UserLoginConstants.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
constants
;
/**
* @Author:Roger Wu
* @name:UserLoginConstants
* @Date:2024-07-25 14:18
*/
public
class
UserLoginConstants
{
public
class
LoginType
{
public
final
static
String
MEMBER_PLATFOMR_SMS
=
"MEMBER_PLATFOMR_SMS"
;
public
final
static
String
MEMBER_PLATFOMR_PW
=
"MEMBER_PLATFOMR_PW"
;
public
final
static
String
MEMBER_PLATFOMR_EMAIL
=
"MEMBER_PLATFOMR_EMAIL"
;
public
final
static
String
MEMBER_PLATFOMR_GOOGLE
=
"MEMBER_PLATFOMR_GOOGLE"
;
}
}
src/main/java/cn/com/gsst/auth/user/convert/Member3rdPartyRelationConvert.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
convert
;
import
cn.com.gsst.auth.user.entity.Member3rdPartyRelationEntity
;
import
cn.com.gsst.auth.user.model.BizMember3rdPartyRelationModel
;
/**
* @Author:Roger Wu
* @name:MemberInfoConvert
* @Date:2024-07-25 11:15
*/
public
class
Member3rdPartyRelationConvert
{
public
static
BizMember3rdPartyRelationModel
convertEntity2Model
(
Member3rdPartyRelationEntity
member3rdPartyRelationEntity
)
{
if
(
member3rdPartyRelationEntity
==
null
)
{
return
null
;
}
BizMember3rdPartyRelationModel
bizMember3rdPartyRelationModel
=
new
BizMember3rdPartyRelationModel
();
bizMember3rdPartyRelationModel
.
setId
(
member3rdPartyRelationEntity
.
getId
());
bizMember3rdPartyRelationModel
.
setMemberId
(
member3rdPartyRelationEntity
.
getMemberId
());
bizMember3rdPartyRelationModel
.
setRelationKey
(
member3rdPartyRelationEntity
.
getRelationKey
());
bizMember3rdPartyRelationModel
.
setRelationPlatform
(
member3rdPartyRelationEntity
.
getRelationPlatform
());
bizMember3rdPartyRelationModel
.
setModelState
(
member3rdPartyRelationEntity
.
getModelState
());
return
bizMember3rdPartyRelationModel
;
}
public
static
Member3rdPartyRelationEntity
convertModel2Entity
(
BizMember3rdPartyRelationModel
bizMember3rdPartyRelationModel
)
{
if
(
bizMember3rdPartyRelationModel
==
null
)
{
return
null
;
}
Member3rdPartyRelationEntity
member3rdPartyRelationEntity
=
new
Member3rdPartyRelationEntity
();
member3rdPartyRelationEntity
.
setId
(
bizMember3rdPartyRelationModel
.
getId
());
member3rdPartyRelationEntity
.
setMemberId
(
bizMember3rdPartyRelationModel
.
getMemberId
());
member3rdPartyRelationEntity
.
setRelationKey
(
bizMember3rdPartyRelationModel
.
getRelationKey
());
member3rdPartyRelationEntity
.
setRelationPlatform
(
bizMember3rdPartyRelationModel
.
getRelationPlatform
());
member3rdPartyRelationEntity
.
setModelState
(
bizMember3rdPartyRelationModel
.
getModelState
());
return
member3rdPartyRelationEntity
;
}
}
src/main/java/cn/com/gsst/auth/user/convert/MemberInfoConvert.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
convert
;
import
cn.com.gsst.auth.user.dto.MemberInfoDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.model.BizMemberInfoModel
;
/**
* @Author:Roger Wu
* @name:MemberInfoConvert
* @Date:2024-07-25 11:15
*/
public
class
MemberInfoConvert
{
public
static
BizMemberInfoModel
convertEntity2Model
(
MemberInfoEntity
memberInfoEntity
)
{
if
(
memberInfoEntity
==
null
)
{
return
null
;
}
BizMemberInfoModel
bizMemberInfoModel
=
new
BizMemberInfoModel
();
bizMemberInfoModel
.
setMemberId
(
memberInfoEntity
.
getMemberId
());
bizMemberInfoModel
.
setAccount
(
memberInfoEntity
.
getAccount
());
bizMemberInfoModel
.
setNickName
(
memberInfoEntity
.
getNickName
());
bizMemberInfoModel
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
bizMemberInfoModel
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
bizMemberInfoModel
.
setEmail
(
memberInfoEntity
.
getEmail
());
bizMemberInfoModel
.
setLastLoginTime
(
memberInfoEntity
.
getLastLoginTime
());
bizMemberInfoModel
.
setShareCode
(
memberInfoEntity
.
getShareCode
());
bizMemberInfoModel
.
setRemark
(
memberInfoEntity
.
getRemark
());
return
bizMemberInfoModel
;
}
public
static
MemberInfoEntity
convertModel2Entity
(
BizMemberInfoModel
bizMemberInfoModel
)
{
if
(
bizMemberInfoModel
==
null
)
{
return
null
;
}
MemberInfoEntity
memberInfoEntity
=
new
MemberInfoEntity
();
memberInfoEntity
.
setMemberId
(
bizMemberInfoModel
.
getMemberId
());
memberInfoEntity
.
setAccount
(
bizMemberInfoModel
.
getAccount
());
memberInfoEntity
.
setNickName
(
bizMemberInfoModel
.
getNickName
());
memberInfoEntity
.
setAvatarUrl
(
bizMemberInfoModel
.
getAvatarUrl
());
memberInfoEntity
.
setMobilePhone
(
bizMemberInfoModel
.
getMobilePhone
());
memberInfoEntity
.
setEmail
(
bizMemberInfoModel
.
getEmail
());
memberInfoEntity
.
setLastLoginTime
(
bizMemberInfoModel
.
getLastLoginTime
());
memberInfoEntity
.
setRemark
(
bizMemberInfoModel
.
getRemark
());
memberInfoEntity
.
setShareCode
(
bizMemberInfoModel
.
getShareCode
());
return
memberInfoEntity
;
}
public
static
MemberInfoDto
converEntity2Dto
(
MemberInfoEntity
memberInfoEntity
)
{
if
(
memberInfoEntity
==
null
)
{
return
null
;
}
MemberInfoDto
memberInfoDto
=
new
MemberInfoDto
();
memberInfoDto
.
setMemberId
(
memberInfoEntity
.
getMemberId
());
memberInfoDto
.
setAccount
(
memberInfoEntity
.
getAccount
());
memberInfoDto
.
setNickName
(
memberInfoEntity
.
getNickName
());
memberInfoDto
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
memberInfoDto
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
memberInfoDto
.
setEmail
(
memberInfoEntity
.
getEmail
());
memberInfoDto
.
setRemark
(
memberInfoEntity
.
getRemark
());
memberInfoDto
.
setLastLoginTime
(
memberInfoEntity
.
getLastLoginTime
());
memberInfoDto
.
setShareCode
(
memberInfoEntity
.
getShareCode
());
memberInfoDto
.
setModelState
(
memberInfoEntity
.
getModelState
());
return
memberInfoDto
;
}
public
static
MemberInfoEntity
convertDto2Entity
(
MemberInfoDto
memberInfoDto
)
{
if
(
memberInfoDto
==
null
)
{
return
null
;
}
MemberInfoEntity
memberInfoEntity
=
new
MemberInfoEntity
();
memberInfoEntity
.
setMemberId
(
memberInfoDto
.
getMemberId
());
memberInfoEntity
.
setAccount
(
memberInfoDto
.
getAccount
());
memberInfoEntity
.
setNickName
(
memberInfoDto
.
getNickName
());
memberInfoEntity
.
setAvatarUrl
(
memberInfoDto
.
getAvatarUrl
());
memberInfoEntity
.
setMobilePhone
(
memberInfoDto
.
getMobilePhone
());
memberInfoEntity
.
setEmail
(
memberInfoDto
.
getEmail
());
memberInfoEntity
.
setRemark
(
memberInfoDto
.
getRemark
());
memberInfoEntity
.
setLastLoginTime
(
memberInfoDto
.
getLastLoginTime
());
memberInfoEntity
.
setShareCode
(
memberInfoDto
.
getShareCode
());
memberInfoEntity
.
setModelState
(
memberInfoDto
.
getModelState
());
return
memberInfoEntity
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/dto/MemberInfoDto.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
dto
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
java.util.Date
;
/**
* @Author:Roger Wu
* @Date:2024-07-25 11:06
*/
public
class
MemberInfoDto
extends
BaseModelClass
{
/**
* member_id
* 会员id
*/
private
Integer
memberId
;
public
Integer
getMemberId
()
{
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
)
{
this
.
memberId
=
memberId
;
}
/**
* account
* 账号
*/
private
String
account
;
public
String
getAccount
()
{
return
this
.
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
/**
* nick_name
* 用户昵称
*/
private
String
nickName
;
public
String
getNickName
()
{
return
this
.
nickName
;
}
public
void
setNickName
(
String
nickName
)
{
this
.
nickName
=
nickName
;
}
/**
* avatar_url
* 用户头像图片的 URL
*/
private
String
avatarUrl
;
public
String
getAvatarUrl
()
{
return
this
.
avatarUrl
;
}
public
void
setAvatarUrl
(
String
avatarUrl
)
{
this
.
avatarUrl
=
avatarUrl
;
}
/**
* mobile_phone
* 用户手机号
*/
private
String
mobilePhone
;
public
String
getMobilePhone
()
{
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
)
{
this
.
mobilePhone
=
mobilePhone
;
}
/**
* email
* 用户邮箱
*/
private
String
email
;
public
String
getEmail
()
{
return
this
.
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
/**
* remark
* 备注
*/
private
String
remark
;
public
String
getRemark
()
{
return
this
.
remark
;
}
public
void
setRemark
(
String
remark
)
{
this
.
remark
=
remark
;
}
/** last_login_time
*用户账号
*/
private
Date
lastLoginTime
;
public
Date
getLastLoginTime
()
{
return
lastLoginTime
;
}
public
void
setLastLoginTime
(
Date
lastLoginTime
)
{
this
.
lastLoginTime
=
lastLoginTime
;
}
private
String
shareCode
;
public
String
getShareCode
()
{
return
shareCode
;
}
public
void
setShareCode
(
String
shareCode
)
{
this
.
shareCode
=
shareCode
;
}
}
src/main/java/cn/com/gsst/auth/user/dto/MemberLoginRequestDto.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
dto
;
/**
* @Author:Roger Wu
* @name:MemberLoginRequestDto
* @Date:2024-07-23 17:25
*/
public
class
MemberLoginRequestDto
{
/**
* 账号
*/
private
String
account
;
/**
* 登录渠道
*/
private
String
loginChannel
;
/**
* 短信验证码
*/
private
String
authCode
;
/**
* 密码(md5)
*/
private
String
password
;
public
String
getLoginChannel
()
{
return
loginChannel
;
}
public
void
setLoginChannel
(
String
loginChannel
)
{
this
.
loginChannel
=
loginChannel
;
}
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
public
String
getAuthCode
()
{
return
authCode
;
}
public
void
setAuthCode
(
String
authCode
)
{
this
.
authCode
=
authCode
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
}
src/main/java/cn/com/gsst/auth/user/dto/MemberLoginResponseDto.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
dto
;
/**
* @Author:Roger Wu
* @name:MemberLoginResponseDto
* @Date:2024-07-25 10:43
*/
public
class
MemberLoginResponseDto
{
/**
* member_id
* 会员id
*/
private
Integer
memberId
;
public
Integer
getMemberId
()
{
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
)
{
this
.
memberId
=
memberId
;
}
/**
* nick_name
* 用户昵称
*/
private
String
nickName
;
public
String
getNickName
()
{
return
this
.
nickName
;
}
public
void
setNickName
(
String
nickName
)
{
this
.
nickName
=
nickName
;
}
/**
* avatar_url
* 用户头像图片的 URL
*/
private
String
avatarUrl
;
public
String
getAvatarUrl
()
{
return
this
.
avatarUrl
;
}
public
void
setAvatarUrl
(
String
avatarUrl
)
{
this
.
avatarUrl
=
avatarUrl
;
}
/**
* mobile_phone
* 用户手机号
*/
private
String
mobilePhone
;
public
String
getMobilePhone
()
{
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
)
{
this
.
mobilePhone
=
mobilePhone
;
}
private
String
token
;
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
}
src/main/java/cn/com/gsst/auth/user/dto/MemberPasswordRequestDto.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
dto
;
/**
* @Author:Roger Wu
* @name:MemberPasswordRequestDto
* @Date:2024-07-31 17:51
*/
public
class
MemberPasswordRequestDto
{
private
String
account
;
private
String
password
;
private
String
authCode
;
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getAuthCode
()
{
return
authCode
;
}
public
void
setAuthCode
(
String
authCode
)
{
this
.
authCode
=
authCode
;
}
}
src/main/java/cn/com/gsst/auth/user/entity/Member3rdPartyRelationEntity.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
entity
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
java.io.Serializable
;
public
class
Member3rdPartyRelationEntity
extends
BaseModelClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/** id
*
*/
private
Integer
id
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
/** memberId
*会员id
*/
private
Integer
memberId
;
public
Integer
getMemberId
(){
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
){
this
.
memberId
=
memberId
;
}
/** relation_key
*
*/
private
String
relationKey
;
public
String
getRelationKey
(){
return
this
.
relationKey
;
}
public
void
setRelationKey
(
String
relationKey
){
this
.
relationKey
=
relationKey
;
}
/** relation_platform
*
*/
private
String
relationPlatform
;
public
String
getRelationPlatform
(){
return
this
.
relationPlatform
;
}
public
void
setRelationPlatform
(
String
relationPlatform
){
this
.
relationPlatform
=
relationPlatform
;
}
/** remark
*备注
*/
private
String
remark
;
public
String
getRemark
(){
return
this
.
remark
;
}
public
void
setRemark
(
String
remark
){
this
.
remark
=
remark
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/entity/MemberInfoEntity.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
entity
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
java.util.Date
;
/**
* @Author:Roger Wu
* @name:MemberInfoEntity
* @Date:2024-07-25 11:06
*/
public
class
MemberInfoEntity
extends
BaseModelClass
{
/**
* member_id
* 会员id
*/
private
Integer
memberId
;
public
Integer
getMemberId
()
{
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
)
{
this
.
memberId
=
memberId
;
}
/**
* account
* 账号
*/
private
String
account
;
public
String
getAccount
()
{
return
this
.
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
/**
* nick_name
* 用户昵称
*/
private
String
nickName
;
public
String
getNickName
()
{
return
this
.
nickName
;
}
public
void
setNickName
(
String
nickName
)
{
this
.
nickName
=
nickName
;
}
/**
* avatar_url
* 用户头像图片的 URL
*/
private
String
avatarUrl
;
public
String
getAvatarUrl
()
{
return
this
.
avatarUrl
;
}
public
void
setAvatarUrl
(
String
avatarUrl
)
{
this
.
avatarUrl
=
avatarUrl
;
}
/**
* mobile_phone
* 用户手机号
*/
private
String
mobilePhone
;
public
String
getMobilePhone
()
{
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
)
{
this
.
mobilePhone
=
mobilePhone
;
}
/**
* email
* 用户邮箱
*/
private
String
email
;
public
String
getEmail
()
{
return
this
.
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
/**
* remark
* 备注
*/
private
String
remark
;
public
String
getRemark
()
{
return
this
.
remark
;
}
public
void
setRemark
(
String
remark
)
{
this
.
remark
=
remark
;
}
/** last_login_time
*用户账号
*/
private
Date
lastLoginTime
;
public
Date
getLastLoginTime
()
{
return
lastLoginTime
;
}
public
void
setLastLoginTime
(
Date
lastLoginTime
)
{
this
.
lastLoginTime
=
lastLoginTime
;
}
private
String
shareCode
;
public
String
getShareCode
()
{
return
shareCode
;
}
public
void
setShareCode
(
String
shareCode
)
{
this
.
shareCode
=
shareCode
;
}
}
src/main/java/cn/com/gsst/auth/user/model/BizMember3rdPartyRelationModel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
model
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
javax.persistence.*
;
import
java.io.Serializable
;
/**
* Model class for biz_member_3rd_party_relation
* 用户信息关联表
*/
@Entity
@Table
(
name
=
"biz_member_3rd_party_relation"
)
@DynamicInsert
@DynamicUpdate
public
class
BizMember3rdPartyRelationModel
extends
BaseModelClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/** id
*
*/
private
Integer
id
;
@Column
(
name
=
"id"
,
length
=
10
)
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
/** memberId
*会员id
*/
private
Integer
memberId
;
@Column
(
name
=
"member_id"
,
length
=
50
)
public
Integer
getMemberId
(){
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
){
this
.
memberId
=
memberId
;
super
.
addValidField
(
"memberId"
);
}
/** relation_key
*
*/
private
String
relationKey
;
@Column
(
name
=
"relation_key"
,
length
=
255
)
public
String
getRelationKey
(){
return
this
.
relationKey
;
}
public
void
setRelationKey
(
String
relationKey
){
this
.
relationKey
=
relationKey
;
super
.
addValidField
(
"relationKey"
);
}
/** relation_platform
*
*/
private
String
relationPlatform
;
@Column
(
name
=
"relation_platform"
,
length
=
50
)
public
String
getRelationPlatform
(){
return
this
.
relationPlatform
;
}
public
void
setRelationPlatform
(
String
relationPlatform
){
this
.
relationPlatform
=
relationPlatform
;
super
.
addValidField
(
"relationPlatform"
);
}
/** is_deleted
*是否删除 Y-是 N-否
*/
private
String
isDeleted
;
@Column
(
name
=
"is_deleted"
,
length
=
50
)
public
String
getIsDeleted
(){
return
this
.
isDeleted
;
}
public
void
setIsDeleted
(
String
isDeleted
){
this
.
isDeleted
=
isDeleted
;
super
.
addValidField
(
"isDeleted"
);
}
/** CREATOR
*创建人
*/
private
String
creator
;
@Column
(
name
=
"CREATOR"
,
length
=
50
)
public
String
getCreator
(){
return
this
.
creator
;
}
public
void
setCreator
(
String
creator
){
this
.
creator
=
creator
;
super
.
addValidField
(
"creator"
);
}
/** CREATED_TIME
*创建时间
*/
private
java
.
util
.
Date
createdTime
;
@Column
(
name
=
"CREATED_TIME"
,
length
=
19
)
public
java
.
util
.
Date
getCreatedTime
(){
return
this
.
createdTime
;
}
public
void
setCreatedTime
(
java
.
util
.
Date
createdTime
){
this
.
createdTime
=
createdTime
;
super
.
addValidField
(
"createdTime"
);
}
/** MODIFIER
*修改人
*/
private
String
modifier
;
@Column
(
name
=
"MODIFIER"
,
length
=
50
)
public
String
getModifier
(){
return
this
.
modifier
;
}
public
void
setModifier
(
String
modifier
){
this
.
modifier
=
modifier
;
super
.
addValidField
(
"modifier"
);
}
/** MODIFIED_TIME
*修改时间
*/
private
java
.
util
.
Date
modifiedTime
;
@Column
(
name
=
"MODIFIED_TIME"
,
length
=
19
)
public
java
.
util
.
Date
getModifiedTime
(){
return
this
.
modifiedTime
;
}
public
void
setModifiedTime
(
java
.
util
.
Date
modifiedTime
){
this
.
modifiedTime
=
modifiedTime
;
super
.
addValidField
(
"modifiedTime"
);
}
/** SYS_VERSION
*乐观锁,版本号
*/
private
Integer
sysVersion
;
@Column
(
name
=
"SYS_VERSION"
,
length
=
10
)
@Version
public
Integer
getSysVersion
(){
return
this
.
sysVersion
;
}
public
void
setSysVersion
(
Integer
sysVersion
){
this
.
sysVersion
=
sysVersion
;
super
.
addValidField
(
"sysVersion"
);
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/model/BizMemberInfoModel.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
model
;
import
cn.com.yict.framemax.data.model.BaseModelClass
;
import
org.hibernate.annotations.DynamicInsert
;
import
org.hibernate.annotations.DynamicUpdate
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* Model class for biz_member_info
* 用户信息表
*/
@Entity
@Table
(
name
=
"biz_member_info"
)
@DynamicInsert
@DynamicUpdate
public
class
BizMemberInfoModel
extends
BaseModelClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* member_id
* 会员id
*/
private
Integer
memberId
;
@Column
(
name
=
"member_id"
,
length
=
10
)
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
public
Integer
getMemberId
()
{
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
)
{
this
.
memberId
=
memberId
;
super
.
addValidField
(
"memberId"
);
}
/**
* account
* 用户账号
*/
private
String
account
;
@Column
(
name
=
"account"
,
length
=
50
)
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
super
.
addValidField
(
"account"
);
}
/**
* nick_name
* 用户昵称
*/
private
String
nickName
;
@Column
(
name
=
"nick_name"
,
length
=
50
)
public
String
getNickName
()
{
return
this
.
nickName
;
}
public
void
setNickName
(
String
nickName
)
{
this
.
nickName
=
nickName
;
super
.
addValidField
(
"nickName"
);
}
/**
* avatar_url
* 用户头像图片的 URL
*/
private
String
avatarUrl
;
@Column
(
name
=
"avatar_url"
,
length
=
255
)
public
String
getAvatarUrl
()
{
return
this
.
avatarUrl
;
}
public
void
setAvatarUrl
(
String
avatarUrl
)
{
this
.
avatarUrl
=
avatarUrl
;
super
.
addValidField
(
"avatarUrl"
);
}
/**
* mobile_phone
* 用户手机号
*/
private
String
mobilePhone
;
@Column
(
name
=
"mobile_phone"
,
length
=
50
)
public
String
getMobilePhone
()
{
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
)
{
this
.
mobilePhone
=
mobilePhone
;
super
.
addValidField
(
"mobilePhone"
);
}
/**
* email
* 用户邮箱
*/
private
String
email
;
@Column
(
name
=
"email"
,
length
=
150
)
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
super
.
addValidField
(
"email"
);
}
/**
* is_deleted
* 是否删除 Y-是 N-否
*/
private
String
isDeleted
;
@Column
(
name
=
"is_deleted"
,
length
=
50
)
public
String
getIsDeleted
()
{
return
this
.
isDeleted
;
}
public
void
setIsDeleted
(
String
isDeleted
)
{
this
.
isDeleted
=
isDeleted
;
super
.
addValidField
(
"isDeleted"
);
}
/**
* remark
* 备注
*/
private
String
remark
;
@Column
(
name
=
"remark"
,
length
=
255
)
public
String
getRemark
()
{
return
this
.
remark
;
}
public
void
setRemark
(
String
remark
)
{
this
.
remark
=
remark
;
super
.
addValidField
(
"remark"
);
}
/**
* last_login_time
* 用户账号
*/
private
Date
lastLoginTime
;
@Column
(
name
=
"last_login_time"
,
length
=
50
)
public
Date
getLastLoginTime
()
{
return
lastLoginTime
;
}
public
void
setLastLoginTime
(
Date
lastLoginTime
)
{
this
.
lastLoginTime
=
lastLoginTime
;
super
.
addValidField
(
"lastLoginTime"
);
}
/**
* share_code
* 分享码
*/
private
String
shareCode
;
@Column
(
name
=
"share_code"
,
length
=
50
)
public
String
getShareCode
()
{
return
shareCode
;
}
public
void
setShareCode
(
String
shareCode
)
{
this
.
shareCode
=
shareCode
;
super
.
addValidField
(
"shareCode"
);
}
/**
* CREATOR
* 创建人
*/
private
String
creator
;
@Column
(
name
=
"CREATOR"
,
length
=
50
)
public
String
getCreator
()
{
return
this
.
creator
;
}
public
void
setCreator
(
String
creator
)
{
this
.
creator
=
creator
;
super
.
addValidField
(
"creator"
);
}
/**
* CREATED_TIME
* 创建时间
*/
private
Date
createdTime
;
@Column
(
name
=
"CREATED_TIME"
,
length
=
19
)
public
Date
getCreatedTime
()
{
return
this
.
createdTime
;
}
public
void
setCreatedTime
(
Date
createdTime
)
{
this
.
createdTime
=
createdTime
;
super
.
addValidField
(
"createdTime"
);
}
/**
* MODIFIER
* 修改人
*/
private
String
modifier
;
@Column
(
name
=
"MODIFIER"
,
length
=
50
)
public
String
getModifier
()
{
return
this
.
modifier
;
}
public
void
setModifier
(
String
modifier
)
{
this
.
modifier
=
modifier
;
super
.
addValidField
(
"modifier"
);
}
/**
* MODIFIED_TIME
* 修改时间
*/
private
Date
modifiedTime
;
@Column
(
name
=
"MODIFIED_TIME"
,
length
=
19
)
public
Date
getModifiedTime
()
{
return
this
.
modifiedTime
;
}
public
void
setModifiedTime
(
Date
modifiedTime
)
{
this
.
modifiedTime
=
modifiedTime
;
super
.
addValidField
(
"modifiedTime"
);
}
/**
* SYS_VERSION
* 乐观锁,版本号
*/
private
Integer
sysVersion
;
@Column
(
name
=
"SYS_VERSION"
,
length
=
10
)
@Version
public
Integer
getSysVersion
()
{
return
this
.
sysVersion
;
}
public
void
setSysVersion
(
Integer
sysVersion
)
{
this
.
sysVersion
=
sysVersion
;
super
.
addValidField
(
"sysVersion"
);
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/query/CheckMemberInfoQuery.sql
0 → 100644
View file @
52bb15fa
select
member_id
,
account
,
mobile_phone
,
email
,
is_deleted
from
biz_member_info
where
is_deleted
=
'N'
<<
and
member_id
!=
:
memberId
>>
<<
and
mobile_phone
=
:
mobilePhone
or
account
=
:
mobilePhone
>>
<<
and
email
=
:
email
or
account
=
:
email
>>
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/query/CheckMemberInfoQueryCondition.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
query
;
import
java.io.Serializable
;
/**
* Query Condition class for CheckMemberInfoQuery
*/
public
class
CheckMemberInfoQueryCondition
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
Long
memberId
;
public
Long
getMemberId
(){
return
this
.
memberId
;
}
public
void
setMemberId
(
Long
memberId
){
this
.
memberId
=
memberId
;
}
private
String
mobilePhone
;
public
String
getMobilePhone
(){
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
){
this
.
mobilePhone
=
mobilePhone
;
}
private
String
email
;
public
String
getEmail
(){
return
this
.
email
;
}
public
void
setEmail
(
String
email
){
this
.
email
=
email
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/query/CheckMemberInfoQueryItem.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
query
;
import
cn.com.yict.framemax.data.model.BaseItemClass
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
java.io.Serializable
;
/**
* Query Item class for CheckMemberInfoQuery
*/
@Entity
public
class
CheckMemberInfoQueryItem
extends
BaseItemClass
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/** member_id
*member_id
*/
private
Integer
memberId
;
@Column
(
name
=
"member_id"
)
public
Integer
getMemberId
(){
return
this
.
memberId
;
}
public
void
setMemberId
(
Integer
memberId
){
this
.
memberId
=
memberId
;
}
/** account
*account
*/
private
String
account
;
@Column
(
name
=
"account"
)
public
String
getAccount
(){
return
this
.
account
;
}
public
void
setAccount
(
String
account
){
this
.
account
=
account
;
}
/** mobile_phone
*mobile_phone
*/
private
String
mobilePhone
;
@Column
(
name
=
"mobile_phone"
)
public
String
getMobilePhone
(){
return
this
.
mobilePhone
;
}
public
void
setMobilePhone
(
String
mobilePhone
){
this
.
mobilePhone
=
mobilePhone
;
}
/** email
*email
*/
private
String
email
;
@Column
(
name
=
"email"
)
public
String
getEmail
(){
return
this
.
email
;
}
public
void
setEmail
(
String
email
){
this
.
email
=
email
;
}
/** is_deleted
*is_deleted
*/
private
String
isDeleted
;
@Column
(
name
=
"is_deleted"
)
public
String
getIsDeleted
(){
return
this
.
isDeleted
;
}
public
void
setIsDeleted
(
String
isDeleted
){
this
.
isDeleted
=
isDeleted
;
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/repository/BizMember3rdPartyRelationRepository.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
repository
;
import
cn.com.gsst.auth.user.model.BizMember3rdPartyRelationModel
;
import
cn.com.yict.framemax.data.repository.Repository
;
public
interface
BizMember3rdPartyRelationRepository
extends
Repository
<
BizMember3rdPartyRelationModel
,
Integer
>
{
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/repository/BizMemberInfoRepository.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
repository
;
import
cn.com.gsst.auth.user.model.BizMemberInfoModel
;
import
cn.com.yict.framemax.data.repository.Repository
;
public
interface
BizMemberInfoRepository
extends
Repository
<
BizMemberInfoModel
,
Integer
>
{
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/rest/BizMember3rdPartyRelationRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
rest
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
public
interface
BizMember3rdPartyRelationRest
extends
BaseRest
{
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/rest/BizMemberInfoRest.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
rest
;
import
cn.com.gsst.auth.user.dto.MemberInfoDto
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.dto.MemberLoginResponseDto
;
import
cn.com.gsst.auth.user.dto.MemberPasswordRequestDto
;
import
cn.com.yict.framemax.core.rest.BaseRest
;
import
cn.com.yict.framemax.web.permission.Access
;
import
cn.com.yict.framemax.web.permission.Permission
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
@Permission
(
Access
.
Safety
)
public
interface
BizMemberInfoRest
extends
BaseRest
{
/**
* 用户登录
*/
@Permission
(
Access
.
Anonymous
)
MemberLoginResponseDto
doLogin
(
@RequestBody
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
;
/**
* 用户配置密码
*/
void
configureMemberPassword
(
@RequestBody
MemberPasswordRequestDto
memberPasswordRequestDto
)
throws
Exception
;
/**
* 用户更改密码
*
* @param authCode 校验码
* @param password 新密码
*/
void
changeMemberPassword
(
@RequestParam
String
authCode
,
@RequestParam
String
password
)
throws
Exception
;
/**
* 用户忘记密码
*/
// @Permission(Access.Anonymous)
// void forgetMemberPassword(@RequestBody MemberPasswordRequestDto memberPasswordRequestDto) throws Exception;
@Permission
(
Access
.
Anonymous
)
void
forgetMemberPassword
(
@RequestParam
String
account
,
@RequestParam
String
password
,
@RequestParam
String
authCode
)
throws
Exception
;
/**
* 获取用户信息
*
* @return
*/
MemberInfoDto
getCurrentMemberInfo
()
throws
Exception
;
/**
* 获取用户昵称
*/
@Permission
(
Access
.
Anonymous
)
MemberInfoDto
getMemberNickName
(
@RequestParam
Long
memberId
)
throws
Exception
;
/**
* 修改用户信息
*/
MemberInfoDto
updateMemberInfo
(
@RequestBody
MemberInfoDto
memberInfoDto
);
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/rest/impl/BizMember3rdPartyRelationRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
rest
.
impl
;
import
cn.com.gsst.auth.user.rest.BizMember3rdPartyRelationRest
;
import
cn.com.gsst.auth.user.service.BizMember3rdPartyRelationService
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
@Component
public
class
BizMember3rdPartyRelationRestImpl
implements
BizMember3rdPartyRelationRest
{
@Resource
private
BizMember3rdPartyRelationService
service
;
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/rest/impl/BizMemberInfoRestImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
rest
.
impl
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.utils.BlContext
;
import
cn.com.gsst.auth.support.security.oauth.constants.OauthConstants
;
import
cn.com.gsst.auth.support.security.oauth.entity.UserBaseEntity
;
import
cn.com.gsst.auth.user.aggregation.MemberInfoService
;
import
cn.com.gsst.auth.user.builder.LoginChannelBuilder
;
import
cn.com.gsst.auth.user.convert.MemberInfoConvert
;
import
cn.com.gsst.auth.user.dto.MemberInfoDto
;
import
cn.com.gsst.auth.user.dto.MemberLoginRequestDto
;
import
cn.com.gsst.auth.user.dto.MemberLoginResponseDto
;
import
cn.com.gsst.auth.user.dto.MemberPasswordRequestDto
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.rest.BizMemberInfoRest
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.security.oauth.OauthAccesstokenManager
;
import
cn.com.yict.framemax.security.oauth.entity.OauthResultEntity
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
@Component
public
class
BizMemberInfoRestImpl
implements
BizMemberInfoRest
{
@Resource
private
LoginChannelBuilder
loginChannelBuilder
;
@Resource
private
OauthAccesstokenManager
tokenManager
;
@Resource
private
MemberInfoService
memberInfoService
;
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
/**
* 用户登录
*/
@Override
public
MemberLoginResponseDto
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
Assert
.
notBlank
(
memberLoginRequest
.
getLoginChannel
());
String
loginChannel
=
memberLoginRequest
.
getLoginChannel
();
MemberInfoEntity
memberInfoEntity
=
(
MemberInfoEntity
)
loginChannelBuilder
.
getService
(
loginChannel
).
doLogin
(
memberLoginRequest
);
if
(
memberInfoEntity
==
null
)
{
throw
new
Exception
(
"登录异常,请稍后再试"
);
}
OauthResultEntity
auth
=
tokenManager
.
auth
(
OauthConstants
.
TypePrefix
.
MEMBER_DOMAIN
+
memberInfoEntity
.
getMemberId
(),
null
,
null
);
MemberLoginResponseDto
memberLoginResponseDto
=
new
MemberLoginResponseDto
();
memberLoginResponseDto
.
setMemberId
(
memberInfoEntity
.
getMemberId
());
memberLoginResponseDto
.
setNickName
(
memberInfoEntity
.
getNickName
());
memberLoginResponseDto
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
memberLoginResponseDto
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
memberLoginResponseDto
.
setToken
(
auth
.
getToken
());
return
memberLoginResponseDto
;
}
/**
* 用户配置密码
*
* @param memberPasswordRequestDto
*/
@Override
public
void
configureMemberPassword
(
MemberPasswordRequestDto
memberPasswordRequestDto
)
throws
Exception
{
Assert
.
notBlank
(
memberPasswordRequestDto
.
getAccount
());
Assert
.
notBlank
(
memberPasswordRequestDto
.
getPassword
());
Assert
.
notBlank
(
memberPasswordRequestDto
.
getAuthCode
());
memberInfoService
.
configureMemberPassword
(
memberPasswordRequestDto
);
}
/**
* 用户更改密码
*/
@Override
public
void
changeMemberPassword
(
String
authCode
,
String
password
)
throws
Exception
{
Assert
.
notBlank
(
password
);
Assert
.
notBlank
(
authCode
);
UserBaseEntity
currentUser
=
BlContext
.
getCurrentUser
();
MemberInfoEntity
memberInfoEntity
=
bizMemberInfoService
.
getById
(
currentUser
.
getUserId
().
intValue
());
MemberPasswordRequestDto
memberPasswordRequestDto
=
new
MemberPasswordRequestDto
();
memberPasswordRequestDto
.
setAccount
(
memberInfoEntity
.
getAccount
());
memberPasswordRequestDto
.
setPassword
(
password
);
memberPasswordRequestDto
.
setAuthCode
(
authCode
);
memberInfoService
.
configureMemberPassword
(
memberPasswordRequestDto
);
}
/**
* 用户忘记密码
*
*/
@Override
public
void
forgetMemberPassword
(
String
account
,
String
password
,
String
authCode
)
throws
Exception
{
MemberPasswordRequestDto
memberPasswordRequestDto
=
new
MemberPasswordRequestDto
();
memberPasswordRequestDto
.
setAccount
(
account
);
memberPasswordRequestDto
.
setPassword
(
password
);
memberPasswordRequestDto
.
setAuthCode
(
authCode
);
memberInfoService
.
configureMemberPassword
(
memberPasswordRequestDto
);
}
/**
* 获取用户信息
*
* @return
*/
@Override
public
MemberInfoDto
getCurrentMemberInfo
()
throws
Exception
{
MemberInfoEntity
memberInfoEntity
=
bizMemberInfoService
.
getById
(
BlContext
.
getCurrentUser
().
getUserId
().
intValue
());
return
MemberInfoConvert
.
converEntity2Dto
(
memberInfoEntity
);
}
@Override
public
MemberInfoDto
getMemberNickName
(
Long
memberId
)
throws
Exception
{
MemberInfoEntity
memberInfoEntity
=
bizMemberInfoService
.
getById
(
memberId
.
intValue
());
if
(
memberInfoEntity
==
null
)
{
throw
new
I18nMessageException
(
"exception/user.does.not.exist"
);
}
MemberInfoDto
memberInfoDto
=
new
MemberInfoDto
();
memberInfoDto
.
setNickName
(
memberInfoEntity
.
getNickName
());
memberInfoDto
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
return
memberInfoDto
;
}
@Override
public
MemberInfoDto
updateMemberInfo
(
MemberInfoDto
memberInfoDto
)
{
UserBaseEntity
userBaseEntity
=
BlContext
.
getCurrentUserNotException
();
if
(
userBaseEntity
==
null
)
{
throw
new
I18nMessageException
(
"exception/user.not.login"
);
}
MemberInfoEntity
memberInfoEntity
=
MemberInfoConvert
.
convertDto2Entity
(
memberInfoDto
);
memberInfoEntity
.
setMemberId
(
userBaseEntity
.
getUserId
().
intValue
());
MemberInfoEntity
entity
=
memberInfoService
.
updateMemberInfo
(
memberInfoEntity
);
return
MemberInfoConvert
.
converEntity2Dto
(
entity
);
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/service/BizMember3rdPartyRelationService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
service
;
import
cn.com.gsst.auth.user.entity.Member3rdPartyRelationEntity
;
import
cn.com.yict.framemax.core.service.BaseService
;
public
interface
BizMember3rdPartyRelationService
extends
BaseService
{
/**
* 创建和更新
* @param member3rdPartyRelationEntity
* @throws Exception
*/
void
createOrUpdateRelation
(
Member3rdPartyRelationEntity
member3rdPartyRelationEntity
)
throws
Exception
;
/**
* @param memberId
* @return
* @throws Exception
*/
public
Member3rdPartyRelationEntity
getPwRelationByMemberId
(
Integer
memberId
)
throws
Exception
;
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/service/BizMemberInfoService.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
service
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.yict.framemax.core.service.BaseService
;
import
java.util.List
;
public
interface
BizMemberInfoService
extends
BaseService
{
MemberInfoEntity
getById
(
Integer
memberId
)
throws
Exception
;
MemberInfoEntity
getMemberEntityByAccount
(
String
account
)
throws
Exception
;
/**
* @param memberInfoEntity
* @return
*/
MemberInfoEntity
createMemberInfo
(
MemberInfoEntity
memberInfoEntity
);
MemberInfoEntity
updateMemberInfo
(
MemberInfoEntity
memberInfoEntity
);
/**
* 查询会员信息是否存在
*
* @param condition
* @return
*/
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoIsExist
(
CheckMemberInfoQueryCondition
condition
);
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/service/impl/BizMember3rdPartyRelationServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
service
.
impl
;
import
cn.com.gsst.auth.common.constant.CommonConstant
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.user.convert.Member3rdPartyRelationConvert
;
import
cn.com.gsst.auth.user.entity.Member3rdPartyRelationEntity
;
import
cn.com.gsst.auth.user.model.BizMember3rdPartyRelationModel
;
import
cn.com.gsst.auth.user.repository.BizMember3rdPartyRelationRepository
;
import
cn.com.gsst.auth.user.service.BizMember3rdPartyRelationService
;
import
cn.com.gsst.auth.user.constants.Member3rdPartyRelationConstants
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.service.impl.BaseServiceImpl
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
BizMember3rdPartyRelationServiceImpl
extends
BaseServiceImpl
implements
BizMember3rdPartyRelationService
{
@Resource
private
BizMember3rdPartyRelationRepository
repository
;
@Override
public
void
createOrUpdateRelation
(
Member3rdPartyRelationEntity
member3rdPartyRelationEntity
)
throws
Exception
{
BizMember3rdPartyRelationModel
model
=
new
BizMember3rdPartyRelationModel
();
if
(
member3rdPartyRelationEntity
.
getId
()
!=
null
)
{
BizMember3rdPartyRelationModel
bizMember3rdPartyRelationModel
=
repository
.
get
(
member3rdPartyRelationEntity
.
getId
());
if
(
bizMember3rdPartyRelationModel
==
null
)
{
throw
new
I18nMessageException
(
"exception/unable.find.user.association.relationship"
);
}
model
=
bizMember3rdPartyRelationModel
;
model
.
setRelationKey
(
member3rdPartyRelationEntity
.
getRelationKey
());
}
else
{
model
.
setMemberId
(
member3rdPartyRelationEntity
.
getMemberId
());
model
.
setRelationKey
(
member3rdPartyRelationEntity
.
getRelationKey
());
model
.
setRelationPlatform
(
member3rdPartyRelationEntity
.
getRelationPlatform
());
}
repository
.
save
(
model
);
}
/**
* @param memberId
* @return
* @throws Exception
*/
@Override
public
Member3rdPartyRelationEntity
getPwRelationByMemberId
(
Integer
memberId
)
throws
Exception
{
Assert
.
notNull
(
memberId
);
BizMember3rdPartyRelationModel
example
=
new
BizMember3rdPartyRelationModel
();
example
.
setMemberId
(
memberId
);
example
.
setRelationPlatform
(
Member3rdPartyRelationConstants
.
RelationType
.
PW
);
example
.
setIsDeleted
(
CommonConstant
.
IsDeleted
.
N
);
List
<
BizMember3rdPartyRelationModel
>
bizMember3rdPartyRelationModelList
=
repository
.
findByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
bizMember3rdPartyRelationModelList
))
{
return
null
;
}
return
Member3rdPartyRelationConvert
.
convertModel2Entity
(
bizMember3rdPartyRelationModelList
.
get
(
0
));
}
}
\ No newline at end of file
src/main/java/cn/com/gsst/auth/user/service/impl/BizMemberInfoServiceImpl.java
0 → 100644
View file @
52bb15fa
package
cn
.
com
.
gsst
.
auth
.
user
.
service
.
impl
;
import
cn.com.gsst.auth.common.constant.CommonConstant
;
import
cn.com.gsst.auth.common.utils.Assert
;
import
cn.com.gsst.auth.common.utils.StringUtils
;
import
cn.com.gsst.auth.common.utils.UUIDTool
;
import
cn.com.gsst.auth.user.entity.MemberInfoEntity
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryCondition
;
import
cn.com.gsst.auth.user.repository.BizMemberInfoRepository
;
import
cn.com.gsst.auth.user.service.BizMemberInfoService
;
import
cn.com.gsst.auth.user.convert.MemberInfoConvert
;
import
cn.com.gsst.auth.user.model.BizMemberInfoModel
;
import
cn.com.gsst.auth.user.query.CheckMemberInfoQueryItem
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.service.impl.BaseServiceImpl
;
import
cn.com.yict.framemax.frame.service.FmxParamConfigService
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
@Service
public
class
BizMemberInfoServiceImpl
extends
BaseServiceImpl
implements
BizMemberInfoService
{
@Resource
private
BizMemberInfoRepository
repository
;
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
MemberInfoEntity
getById
(
Integer
memberId
)
throws
Exception
{
BizMemberInfoModel
bizMemberInfoModel
=
this
.
repository
.
get
(
memberId
);
if
(
bizMemberInfoModel
==
null
)
{
return
null
;
}
return
MemberInfoConvert
.
convertModel2Entity
(
bizMemberInfoModel
);
}
@Override
public
MemberInfoEntity
getMemberEntityByAccount
(
String
account
)
throws
Exception
{
Assert
.
notBlank
(
account
);
BizMemberInfoModel
example
=
new
BizMemberInfoModel
();
example
.
setIsDeleted
(
CommonConstant
.
IsDeleted
.
N
);
example
.
setAccount
(
account
);
List
<
BizMemberInfoModel
>
bizMemberInfoModelList
=
repository
.
findByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
bizMemberInfoModelList
))
{
return
null
;
}
BizMemberInfoModel
bizMemberInfoModel
=
bizMemberInfoModelList
.
get
(
0
);
return
MemberInfoConvert
.
convertModel2Entity
(
bizMemberInfoModel
);
}
/**
* @param memberInfoEntity
* @return
*/
@Override
public
MemberInfoEntity
createMemberInfo
(
MemberInfoEntity
memberInfoEntity
)
{
BizMemberInfoModel
model
=
new
BizMemberInfoModel
();
model
.
setAccount
(
memberInfoEntity
.
getAccount
());
model
.
setNickName
(
memberInfoEntity
.
getNickName
());
model
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
model
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
model
.
setEmail
(
memberInfoEntity
.
getEmail
());
if
(
checkVaildAccountExist
(
memberInfoEntity
.
getAccount
()))
{
throw
new
I18nMessageException
(
"exception/account.has.already"
);
}
if
(
StringUtils
.
isBlank
(
memberInfoEntity
.
getAvatarUrl
()))
{
String
param
=
fmxParamConfigService
.
getParam
(
"member.default.avatar"
);
if
(
StringUtils
.
isNoneBlank
(
param
))
{
model
.
setAvatarUrl
(
param
);
}
}
if
(
StringUtils
.
isBlank
(
memberInfoEntity
.
getShareCode
()))
{
model
.
setShareCode
(
UUIDTool
.
getUUID
());
}
return
MemberInfoConvert
.
convertModel2Entity
(
repository
.
save
(
model
));
}
@Override
public
MemberInfoEntity
updateMemberInfo
(
MemberInfoEntity
memberInfoEntity
)
{
Assert
.
notNull
(
memberInfoEntity
.
getMemberId
());
BizMemberInfoModel
bizMemberInfoModel
=
repository
.
get
(
memberInfoEntity
.
getMemberId
());
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getNickName
()))
{
if
(
memberInfoEntity
.
getNickName
().
length
()
>
20
)
{
throw
new
I18nMessageException
(
"exception/nickName.max.len"
);
}
bizMemberInfoModel
.
setNickName
(
memberInfoEntity
.
getNickName
());
}
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getAvatarUrl
()))
{
bizMemberInfoModel
.
setAvatarUrl
(
memberInfoEntity
.
getAvatarUrl
());
}
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getMobilePhone
()))
{
bizMemberInfoModel
.
setMobilePhone
(
memberInfoEntity
.
getMobilePhone
());
}
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getEmail
()))
{
bizMemberInfoModel
.
setEmail
(
memberInfoEntity
.
getEmail
());
}
if
(
StringUtils
.
isNotBlank
(
memberInfoEntity
.
getRemark
()))
{
if
(
memberInfoEntity
.
getRemark
().
length
()
>
200
)
{
throw
new
I18nMessageException
(
"exception/remark.max.len"
);
}
bizMemberInfoModel
.
setRemark
(
memberInfoEntity
.
getRemark
());
}
BizMemberInfoModel
saveModel
=
this
.
repository
.
save
(
bizMemberInfoModel
);
return
MemberInfoConvert
.
convertModel2Entity
(
saveModel
);
}
@Override
public
List
<
CheckMemberInfoQueryItem
>
checkMemberInfoIsExist
(
CheckMemberInfoQueryCondition
condition
)
{
return
this
.
sqlDao
.
query
(
condition
,
CheckMemberInfoQueryItem
.
class
);
}
private
boolean
checkVaildAccountExist
(
String
account
)
{
BizMemberInfoModel
example
=
new
BizMemberInfoModel
();
example
.
setAccount
(
account
);
example
.
setIsDeleted
(
CommonConstant
.
IsDeleted
.
N
);
List
<
BizMemberInfoModel
>
bizMemberInfoModelList
=
repository
.
findByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
bizMemberInfoModelList
))
{
return
false
;
}
return
true
;
}
}
\ No newline at end of file
src/main/resources/META-INF/framemax-bundle.properties
0 → 100644
View file @
52bb15fa
#framemax bundle properties file
bundle.name
=
gsst-auth
bundle.description
=
Ӫ
#配置文件路径-支持使用${}表达?
bundle.configLocation
=
classpath:/gsst-auth/config.properties
#context或servlet context配置初始化监听器-支持使用${}表达?
bundle.configListener
=
\ No newline at end of file
src/main/resources/gsst-auth/config.properties
0 → 100644
View file @
52bb15fa
#package name
gsst-auth.basePackage
=
cn.com.gsst.auth
src/main/resources/gsst-auth/spring/applicationContext.xml
0 → 100644
View file @
52bb15fa
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:util=
"http://www.springframework.org/schema/util"
xsi:schemaLocation=
"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"
>
<bean
class=
"cn.com.yict.framemax.security.SafetyUrls"
>
<property
name=
"urlPatterns"
>
<list>
<value>
/pages/**
</value>
</list>
</property>
</bean>
</beans>
src/main/resources/spring/applicationContext.xml
0 → 100644
View file @
52bb15fa
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:util=
"http://www.springframework.org/schema/util"
xsi:schemaLocation=
"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"
>
<bean
id=
"framemax-security.oauth.oauthUserManager"
class=
"cn.com.gsst.auth.support.security.oauth.MultiDomainOauthUserManagerImplementor"
/>
<bean
id=
"framemax-security.oauth.oauthTokenOperator"
class=
"cn.com.gsst.auth.support.security.oauth.MultiDomainOauthTokenOperatorImplementor"
/>
<bean
class=
"cn.com.yict.framemax.web.resource.JsCssModule"
>
<property
name=
"pagePattern"
value=
"/**"
/>
<property
name=
"jsLinks"
>
<set>
<value>
/js/global.js
</value>
</set>
</property>
</bean>
</beans>
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