Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
civil-bigdata
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
civil
civil-bigdata
Commits
6c3690cc
Commit
6c3690cc
authored
Aug 09, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
把user-server的内容移到sys-server
parent
f9ce7555
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
778 additions
and
22 deletions
+778
-22
api-server/src/main/java/com/zq/api/controller/ApiController.java
+2
-2
api-server/src/main/java/com/zq/api/feign/SysFeign.java
+10
-4
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
+8
-8
common-utils/src/main/java/com/zq/common/config/interceptor/UserInfoInterceptor.java
+6
-2
common-utils/src/main/java/com/zq/common/config/redis/BaseCacheKeys.java
+8
-2
pom.xml
+1
-1
sys-server/src/main/java/com/zq/system/config/CacheKeys.java
+40
-0
sys-server/src/main/java/com/zq/system/modules/system/domain/vo/AppVersionFindVo.java
+64
-0
sys-server/src/main/java/com/zq/system/modules/system/domain/vo/LoginVo.java
+34
-0
sys-server/src/main/java/com/zq/system/modules/system/repository/AppVersionDao.java
+16
-0
sys-server/src/main/java/com/zq/system/modules/system/repository/PfuserDao.java
+19
-0
sys-server/src/main/java/com/zq/system/modules/system/rest/UserController.java
+1
-1
sys-server/src/main/java/com/zq/system/modules/system/rest/app/AppUserController.java
+73
-0
sys-server/src/main/java/com/zq/system/modules/system/rest/app/VersionController.java
+48
-0
sys-server/src/main/java/com/zq/system/modules/system/service/UserService.java
+39
-0
sys-server/src/main/java/com/zq/system/modules/system/service/VersionService.java
+38
-0
sys-server/src/main/java/com/zq/system/modules/system/service/impl/UserServiceImpl.java
+177
-2
sys-server/src/main/java/com/zq/system/utils/MobileSmsUtils.java
+194
-0
No files found.
api-server/src/main/java/com/zq/api/controller/ApiController.java
View file @
6c3690cc
...
...
@@ -108,8 +108,8 @@ public class ApiController {
// 调试日志
if
(
ApiUtils
.
DEBUG
)
{
System
.
out
.
println
(
"API DEBUG ACTION \n[from="
+
form
+
"]"
//
+
"\n[resp="
+
JSON
.
toJSONString
(
resp
)
+
"]"
//
System
.
out
.
println
(
"API DEBUG ACTION \n[from="
+
form
+
"]"
+
"\n[resp="
+
JSON
.
toJSONString
(
resp
)
+
"]"
+
"\n[time="
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms]"
);
}
...
...
api-server/src/main/java/com/zq/api/feign/
User
Feign.java
→
api-server/src/main/java/com/zq/api/feign/
Sys
Feign.java
View file @
6c3690cc
...
...
@@ -3,13 +3,19 @@ package com.zq.api.feign;
import
com.zq.api.config.FeignConfig
;
import
com.zq.common.vo.ResultVo
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
java.util.Map
;
@FeignClient
(
name
=
"USER-SERVER"
,
configuration
=
FeignConfig
.
class
)
//指定调用哪个微服务
@RequestMapping
(
"/user/app"
)
public
interface
UserFeign
{
/**
* @author wilmiam
* @since 2021-08-09 10:48
*/
@FeignClient
(
name
=
"SYS-SERVER"
,
path
=
"/sys/app"
,
configuration
=
FeignConfig
.
class
)
public
interface
SysFeign
{
@GetMapping
(
"/user/sendCode"
)
ResultVo
sendCode
(
@RequestParam
String
phone
);
...
...
api-server/src/main/java/com/zq/api/service/impl/ApiV100Logic.java
View file @
6c3690cc
package
com
.
zq
.
api
.
service
.
impl
;
import
com.zq.api.feign.PortalFeign
;
import
com.zq.api.feign.
User
Feign
;
import
com.zq.api.feign.
Sys
Feign
;
import
com.zq.api.form.ApiForm
;
import
com.zq.api.form.ApiResp
;
import
com.zq.api.service.IApiLogic
;
...
...
@@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
public
class
ApiV100Logic
extends
BaseApiLogic
implements
IApiLogic
{
@Autowired
private
UserFeign
user
Feign
;
private
SysFeign
sys
Feign
;
@Autowired
private
PortalFeign
portalFeign
;
...
...
@@ -26,32 +26,32 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
@Override
public
ApiResp
sendCode
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
sendCode
(
form
.
get
(
"phone"
)));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
sendCode
(
form
.
get
(
"phone"
)));
}
@Override
public
ApiResp
resetPassword
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
resetPassword
(
form
.
getParamsMap
()));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
resetPassword
(
form
.
getParamsMap
()));
}
@Override
public
ApiResp
phoneLogin
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
phoneLogin
(
form
.
getParamsMap
()));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
phoneLogin
(
form
.
getParamsMap
()));
}
@Override
public
ApiResp
passwdLogin
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
passwdLogin
(
form
.
getParamsMap
()));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
passwdLogin
(
form
.
getParamsMap
()));
}
@Override
public
ApiResp
modifyPasswd
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
modifyPasswd
(
form
.
getParamsMap
()));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
modifyPasswd
(
form
.
getParamsMap
()));
}
@Override
public
ApiResp
getAppVersion
(
ApiForm
form
)
{
return
ApiUtils
.
toApiResp
(
form
,
user
Feign
.
getAppVersion
(
form
.
get
(
"appName"
)));
return
ApiUtils
.
toApiResp
(
form
,
sys
Feign
.
getAppVersion
(
form
.
get
(
"appName"
)));
}
@Override
...
...
common-utils/src/main/java/com/zq/common/config/interceptor/UserInfoInterceptor.java
View file @
6c3690cc
package
com
.
zq
.
common
.
config
.
interceptor
;
import
com.zq.common.config.redis.CacheKeys
;
import
com.zq.common.config.redis.
Base
CacheKeys
;
import
com.zq.common.config.redis.RedisUtils
;
import
com.zq.common.config.security.SecurityProperties
;
import
com.zq.common.context.ContextUtils
;
...
...
@@ -14,6 +14,10 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* @author wilmiam
* @since 2021-08-09 09:40
*/
@Slf4j
@Component
@RequiredArgsConstructor
...
...
@@ -27,7 +31,7 @@ public class UserInfoInterceptor extends HandlerInterceptorAdapter {
if
(
request
.
getRequestURI
().
contains
(
"/app/"
))
{
String
token
=
getToken
(
request
);
log
.
info
(
">> [UserInfo token] {}"
,
token
);
ApiTokenVo
tokenVo
=
redisUtils
.
getObj
(
CacheKeys
.
appTokenKey
(
token
),
ApiTokenVo
.
class
);
ApiTokenVo
tokenVo
=
redisUtils
.
getObj
(
Base
CacheKeys
.
appTokenKey
(
token
),
ApiTokenVo
.
class
);
ContextUtils
.
setUserContext
(
tokenVo
);
}
return
true
;
...
...
common-utils/src/main/java/com/zq/common/config/redis/CacheKeys.java
→
common-utils/src/main/java/com/zq/common/config/redis/
Base
CacheKeys.java
View file @
6c3690cc
package
com
.
zq
.
common
.
config
.
redis
;
public
abstract
class
CacheKeys
{
/**
* @author wilmiam
* @since 2021-08-09 09:39
*/
public
abstract
class
BaseCacheKeys
{
public
static
final
String
PREFIX
=
"drug."
;
public
static
final
long
APP_TOKEN_EXPIRE_MINUTES
=
60
*
24
*
2
;
public
static
final
String
PREFIX
=
"civil."
;
private
static
final
String
APP_TOKEN
=
PREFIX
+
"app-token."
;
...
...
pom.xml
View file @
6c3690cc
...
...
@@ -25,7 +25,7 @@
<mybatis.plus.version>
3.4.0
</mybatis.plus.version>
<pagehelper.version>
5.2.0
</pagehelper.version>
<jjwt.version>
0.9.1
</jjwt.version>
<fastjson.version>
1.2.7
4
</fastjson.version>
<fastjson.version>
1.2.7
6
</fastjson.version>
<hutool.version>
5.3.4
</hutool.version>
</properties>
...
...
sys-server/src/main/java/com/zq/system/config/CacheKeys.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
config
;
import
com.zq.common.config.redis.BaseCacheKeys
;
/**
* @author wilmiam
* @since 2021-08-09 09:42
*/
public
class
CacheKeys
extends
BaseCacheKeys
{
private
static
final
String
AUTH_CODE
=
PREFIX
+
"auth-code."
;
private
static
final
String
ADMIN_TOKEN
=
PREFIX
+
"admin-token."
;
private
static
final
String
LIVE_ADMIN_TOKEN
=
PREFIX
+
"live-admin-token."
;
private
static
final
String
LIVE_APP_TOKEN
=
PREFIX
+
"live-app-token."
;
/**
* 构建手机验证码的缓存key
*
* @param phone 手机号码
* @return
*/
public
static
String
authCodeKey
(
String
phone
)
{
return
AUTH_CODE
+
phone
;
}
/**
* 用户当前apptoken的缓存key
*
* @param userId
* @return
*/
public
static
String
liveAppTokenKey
(
Long
userId
)
{
return
LIVE_APP_TOKEN
+
userId
;
}
}
sys-server/src/main/java/com/zq/system/modules/system/domain/vo/AppVersionFindVo.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
domain
.
vo
;
import
com.zq.common.vo.PageReqVo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.*
;
import
java.util.Date
;
/**
* (TAppVersion)实体类
*
* @author wilmiam
* @since 2021-03-02 09:44:35
*/
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public
class
AppVersionFindVo
extends
PageReqVo
{
/**
* ID
*/
@ApiModelProperty
(
"ID"
)
private
Long
id
;
/**
* 版本号
*/
@ApiModelProperty
(
"版本号"
)
private
String
version
;
/**
* 安卓下载链接
*/
@ApiModelProperty
(
"安卓下载链接"
)
private
String
androidLink
;
/**
* iOS下载链接
*/
@ApiModelProperty
(
"iOS下载链接"
)
private
String
iosLink
;
/**
* 更新内容
*/
@ApiModelProperty
(
"更新内容"
)
private
String
content
;
/**
* 是否当前版本
*/
@ApiModelProperty
(
"是否当前版本"
)
private
Boolean
isCurrentVersion
;
/**
* 更新时间
*/
@ApiModelProperty
(
"更新时间"
)
private
Date
createTime
;
}
sys-server/src/main/java/com/zq/system/modules/system/domain/vo/LoginVo.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
domain
.
vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* 用户表(TMember)实体类
*
* @author wilmiam
* @since 2020-10-20 12:05:16
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public
class
LoginVo
{
private
Long
userId
;
@ApiModelProperty
(
"手机号"
)
private
String
phone
;
@ApiModelProperty
(
"验证码"
)
private
String
verifyCode
;
private
String
passwd
;
@ApiModelProperty
(
"登录类型"
)
private
String
loginType
;
}
sys-server/src/main/java/com/zq/system/modules/system/repository/AppVersionDao.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
repository
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.zq.common.entity.AppVersion
;
import
org.springframework.stereotype.Repository
;
/**
* (TAppVersion)表数据库访问层
*
* @author wilmiam
* @since 2021-03-02 09:44:35
*/
@Repository
public
interface
AppVersionDao
extends
BaseMapper
<
AppVersion
>
{
}
sys-server/src/main/java/com/zq/system/modules/system/repository/PfuserDao.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
repository
;
import
com.baomidou.dynamic.datasource.annotation.DS
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.zq.common.constant.DBName
;
import
com.zq.common.entity.Pfuser
;
import
org.springframework.stereotype.Repository
;
/**
* 存放系统所有用户的基本信息(Pfuser)表数据库访问层
*
* @author makejava
* @since 2021-06-23 17:56:31
*/
@DS
(
DBName
.
GXSHZZ
)
@Repository
public
interface
PfuserDao
extends
BaseMapper
<
Pfuser
>
{
}
sys-server/src/main/java/com/zq/system/modules/system/rest/UserController.java
View file @
6c3690cc
...
...
@@ -106,7 +106,7 @@ public class UserController {
public
ResponseEntity
<
Object
>
create
(
@Validated
@RequestBody
User
resources
){
checkLevel
(
resources
);
// 默认密码 123456
resources
.
setPassword
(
passwordEncoder
.
encode
(
"
123456
"
));
resources
.
setPassword
(
passwordEncoder
.
encode
(
"
gxmz!23
"
));
userService
.
create
(
resources
);
return
new
ResponseEntity
<>(
HttpStatus
.
CREATED
);
}
...
...
sys-server/src/main/java/com/zq/system/modules/system/rest/app/AppUserController.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
rest
.
app
;
import
com.zq.common.utils.AssertUtils
;
import
com.zq.common.utils.ValidateUtil
;
import
com.zq.common.vo.ApiTokenVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.system.modules.system.domain.vo.LoginVo
;
import
com.zq.system.modules.system.service.UserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author wilmiam
* @since 2021-08-09 09:28
*/
@Api
(
tags
=
"用户相关接口"
)
@RequiredArgsConstructor
@RestController
@RequestMapping
(
value
=
"/sys/app/user"
)
public
class
AppUserController
{
private
final
UserService
userService
;
@ApiOperation
(
"发送验证码"
)
@GetMapping
(
value
=
"/sendCode"
)
public
ResultVo
sendCode
(
String
phone
)
{
AssertUtils
.
hasText
(
phone
,
"手机号不能为空"
);
AssertUtils
.
isTrue
(
ValidateUtil
.
isMobilePhoneNo
(
phone
),
"手机号格式不正确"
);
userService
.
sendCode
(
phone
);
return
ResultVo
.
success
();
}
@ApiOperation
(
"重置登录密码"
)
@PostMapping
(
value
=
"/resetPassword"
)
public
ResultVo
resetPassword
(
@RequestBody
LoginVo
vo
)
{
AssertUtils
.
hasText
(
vo
.
getPhone
(),
"手机号不能为空"
);
AssertUtils
.
isTrue
(
ValidateUtil
.
isMobilePhoneNo
(
vo
.
getPhone
()),
"手机号格式不正确"
);
AssertUtils
.
hasText
(
vo
.
getVerifyCode
(),
"请输入验证码"
);
userService
.
resetPassword
(
vo
);
return
ResultVo
.
success
();
}
@ApiOperation
(
"修改登录密码"
)
@PostMapping
(
value
=
"/modifyPasswd"
)
public
ResultVo
modifyPasswd
(
@RequestBody
LoginVo
vo
)
{
AssertUtils
.
hasText
(
vo
.
getPhone
(),
"手机号不能为空"
);
AssertUtils
.
isTrue
(
ValidateUtil
.
isMobilePhoneNo
(
vo
.
getPhone
()),
"手机号格式不正确"
);
AssertUtils
.
hasText
(
vo
.
getVerifyCode
(),
"请输入验证码"
);
AssertUtils
.
hasText
(
vo
.
getPasswd
(),
"请输入密码"
);
userService
.
modifyPasswd
(
vo
);
return
ResultVo
.
success
();
}
@ApiOperation
(
"手机号登录"
)
@PostMapping
(
value
=
"/phoneLogin"
)
public
ResultVo
<
ApiTokenVo
>
phoneLogin
(
@RequestBody
LoginVo
vo
)
{
AssertUtils
.
hasText
(
vo
.
getPhone
(),
"手机号不能为空"
);
AssertUtils
.
hasText
(
vo
.
getVerifyCode
(),
"请输入验证码"
);
return
ResultVo
.
success
(
userService
.
phoneLogin
(
vo
));
}
@ApiOperation
(
"密码登录"
)
@PostMapping
(
value
=
"/passwdLogin"
)
public
ResultVo
<
ApiTokenVo
>
passwdLogin
(
@RequestBody
LoginVo
vo
)
{
AssertUtils
.
hasText
(
vo
.
getPhone
(),
"手机号不能为空"
);
AssertUtils
.
hasText
(
vo
.
getPasswd
(),
"请输入密码"
);
return
ResultVo
.
success
(
userService
.
passwdLogin
(
vo
));
}
}
sys-server/src/main/java/com/zq/system/modules/system/rest/app/VersionController.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
rest
.
app
;
import
com.zq.common.annotation.AnonymousAccess
;
import
com.zq.common.entity.AppVersion
;
import
com.zq.common.vo.PageVo
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.system.modules.system.domain.vo.AppVersionFindVo
;
import
com.zq.system.modules.system.service.VersionService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.*
;
/**
* @author wilmiam
* @since 2021-08-09 09:27
*/
@Api
(
tags
=
"App版本相关接口"
)
@RequiredArgsConstructor
@RestController
@RequestMapping
(
value
=
"/sys/app/version"
)
public
class
VersionController
{
private
final
VersionService
versionService
;
@AnonymousAccess
@ApiOperation
(
"获取最新版本"
)
@GetMapping
(
"/getAppVersion"
)
public
ResultVo
<
AppVersion
>
getAppVersion
(
@RequestParam
String
appName
)
{
return
ResultVo
.
success
(
versionService
.
getVersion
(
appName
));
}
@AnonymousAccess
@ApiOperation
(
"获取版本号列表"
)
@PostMapping
(
"/getAppVersionList"
)
public
ResultVo
<
PageVo
<
AppVersion
>>
getAppVersionList
(
@RequestBody
AppVersionFindVo
vo
)
{
return
ResultVo
.
success
(
versionService
.
getAppVersionList
(
vo
));
}
@AnonymousAccess
@ApiOperation
(
"添加版本号"
)
@PostMapping
(
"/addVersion"
)
public
ResultVo
addVersion
(
@RequestBody
AppVersion
vo
)
{
versionService
.
addVersion
(
vo
);
return
ResultVo
.
success
();
}
}
sys-server/src/main/java/com/zq/system/modules/system/service/UserService.java
View file @
6c3690cc
...
...
@@ -15,7 +15,9 @@
*/
package
com
.
zq
.
system
.
modules
.
system
.
service
;
import
com.zq.common.vo.ApiTokenVo
;
import
com.zq.system.modules.system.domain.User
;
import
com.zq.system.modules.system.domain.vo.LoginVo
;
import
com.zq.system.modules.system.service.dto.UserDto
;
import
com.zq.system.modules.system.service.dto.UserQueryCriteria
;
import
org.springframework.data.domain.Pageable
;
...
...
@@ -126,4 +128,41 @@ public interface UserService {
* @param resources /
*/
void
updateCenter
(
User
resources
);
/**
* 发送手机验证码
*
* @param phone
*/
void
sendCode
(
String
phone
);
/**
* 重置密码
*
* @param vo
*/
void
resetPassword
(
LoginVo
vo
);
/**
* 修改密码
*
* @param vo
*/
void
modifyPasswd
(
LoginVo
vo
);
/**
* 手机号登录
*
* @param vo
* @return
*/
ApiTokenVo
phoneLogin
(
LoginVo
vo
);
/**
* 密码登录
*
* @param vo
* @return
*/
ApiTokenVo
passwdLogin
(
LoginVo
vo
);
}
sys-server/src/main/java/com/zq/system/modules/system/service/VersionService.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
modules
.
system
.
service
;
import
cn.hutool.core.date.DateUtil
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.zq.common.entity.AppVersion
;
import
com.zq.common.utils.PagingUtils
;
import
com.zq.common.vo.PageVo
;
import
com.zq.system.modules.system.domain.vo.AppVersionFindVo
;
import
com.zq.system.modules.system.repository.AppVersionDao
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.stereotype.Service
;
/**
* @author wilmiam
* @since 2021-08-09 09:28
*/
@Service
@RequiredArgsConstructor
public
class
VersionService
{
private
final
AppVersionDao
appVersionDao
;
public
AppVersion
getVersion
(
String
appName
)
{
return
appVersionDao
.
selectOne
(
Wrappers
.
lambdaQuery
(
AppVersion
.
builder
().
appName
(
appName
).
isCurrentVersion
(
true
).
build
()));
}
public
PageVo
<
AppVersion
>
getAppVersionList
(
AppVersionFindVo
vo
)
{
return
PagingUtils
.
paging
(
vo
,
appVersionDao
,
AppVersion
.
class
);
}
public
void
addVersion
(
AppVersion
vo
)
{
appVersionDao
.
update
(
AppVersion
.
builder
().
isCurrentVersion
(
false
).
build
(),
Wrappers
.
lambdaUpdate
(
AppVersion
.
builder
().
build
()));
vo
.
setIsCurrentVersion
(
true
);
vo
.
setCreateTime
(
DateUtil
.
date
());
appVersionDao
.
insert
(
vo
);
}
}
sys-server/src/main/java/com/zq/system/modules/system/service/impl/UserServiceImpl.java
View file @
6c3690cc
...
...
@@ -15,15 +15,29 @@
*/
package
com
.
zq
.
system
.
modules
.
system
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.zq.common.config.redis.RedisUtils
;
import
com.zq.common.config.security.ApiTokenUtils
;
import
com.zq.common.constant.SystemName
;
import
com.zq.common.entity.AppUser
;
import
com.zq.common.entity.Pfuser
;
import
com.zq.common.http.HttpRequestUtils
;
import
com.zq.common.utils.AssertUtils
;
import
com.zq.common.utils.StringUtils
;
import
com.zq.common.utils.UploadUtils
;
import
com.zq.common.vo.ApiTokenVo
;
import
com.zq.system.config.CacheKeys
;
import
com.zq.system.config.FileProperties
;
import
com.zq.system.exception.EntityExistException
;
import
com.zq.system.exception.EntityNotFoundException
;
import
com.zq.system.modules.system.domain.Job
;
import
com.zq.system.modules.system.domain.Role
;
import
com.zq.system.modules.system.domain.User
;
import
com.zq.system.modules.system.repository.UserRepository
;
import
com.zq.system.modules.system.domain.vo.LoginVo
;
import
com.zq.system.modules.system.repository.*
;
import
com.zq.system.modules.system.service.OnlineUserService
;
import
com.zq.system.modules.system.service.UserCacheClean
;
import
com.zq.system.modules.system.service.UserService
;
...
...
@@ -34,12 +48,15 @@ import com.zq.system.modules.system.service.dto.UserQueryCriteria;
import
com.zq.system.modules.system.service.mapstruct.UserMapper
;
import
com.zq.system.utils.*
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -52,6 +69,7 @@ import java.util.stream.Collectors;
* @author Zheng Jie
* @date 2018-11-23
*/
@Slf4j
@Service
@RequiredArgsConstructor
@CacheConfig
(
cacheNames
=
"user"
)
...
...
@@ -63,6 +81,11 @@ public class UserServiceImpl implements UserService {
private
final
RedisUtils
redisUtils
;
private
final
UserCacheClean
userCacheClean
;
private
final
OnlineUserService
onlineUserService
;
private
final
PfuserDao
pfuserDao
;
private
final
PasswordEncoder
passwordEncoder
;
private
final
DeptRepository
deptRepository
;
private
final
RoleRepository
roleRepository
;
private
final
JobRepository
jobRepository
;
@Override
public
Object
queryAll
(
UserQueryCriteria
criteria
,
Pageable
pageable
)
{
...
...
@@ -91,7 +114,7 @@ public class UserServiceImpl implements UserService {
if
(
userRepository
.
findByUsername
(
resources
.
getUsername
())
!=
null
)
{
throw
new
EntityExistException
(
User
.
class
,
"username"
,
resources
.
getUsername
());
}
if
(
userRepository
.
findByEmail
(
resources
.
getEmail
())
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
resources
.
getEmail
())
&&
userRepository
.
findByEmail
(
resources
.
getEmail
())
!=
null
)
{
throw
new
EntityExistException
(
User
.
class
,
"email"
,
resources
.
getEmail
());
}
if
(
userRepository
.
findByPhone
(
resources
.
getPhone
())
!=
null
)
{
...
...
@@ -251,4 +274,156 @@ public class UserServiceImpl implements UserService {
private
void
flushCache
(
String
username
)
{
userCacheClean
.
cleanUserCache
(
username
);
}
@Override
public
void
sendCode
(
String
phone
)
{
User
user
=
userRepository
.
findByUsername
(
phone
);
if
(
user
==
null
)
{
Pfuser
pfuser
=
pfuserDao
.
selectOne
(
Wrappers
.
lambdaQuery
(
Pfuser
.
builder
().
phone
(
phone
).
build
()));
AssertUtils
.
notNull
(
pfuser
,
"手机号不存在"
);
}
String
code
=
RandomUtil
.
randomNumbers
(
6
);
String
content
=
"您的验证码为:"
+
code
+
"(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。"
;
boolean
sendMsg
=
MobileSmsUtils
.
sendMsg
(
phone
,
content
);
log
.
info
(
">> phone: {}, sendCode: {}, success: {}"
,
phone
,
code
,
sendMsg
);
redisUtils
.
setStr
(
CacheKeys
.
authCodeKey
(
phone
),
code
,
5
);
}
@Override
public
void
resetPassword
(
LoginVo
vo
)
{
verificationCode
(
vo
.
getPhone
(),
vo
.
getVerifyCode
());
User
user
=
userRepository
.
findByUsername
(
vo
.
getPhone
());
if
(
user
==
null
)
{
user
=
addUser
(
vo
.
getPhone
());
}
AssertUtils
.
notNull
(
user
,
"手机号不存在"
);
updatePass
(
user
.
getUsername
(),
passwordEncoder
.
encode
(
vo
.
getPasswd
()));
}
/**
* 保存用户
*
* @param phone
* @return
*/
private
User
addUser
(
String
phone
)
{
Pfuser
pfuser
=
pfuserDao
.
selectOne
(
Wrappers
.
lambdaQuery
(
Pfuser
.
builder
().
phone
(
phone
).
build
()));
if
(
pfuser
==
null
)
{
return
null
;
}
User
user
=
userRepository
.
findByUsername
(
phone
);
if
(
user
==
null
)
{
user
=
new
User
();
List
<
Role
>
roleList
=
roleRepository
.
findAllById
(
Collections
.
singletonList
(
2L
));
user
.
setRoles
(
new
HashSet
<>(
roleList
));
List
<
Job
>
jobList
=
jobRepository
.
findAllById
(
Collections
.
singletonList
(
13L
));
user
.
setJobs
(
new
HashSet
<>(
jobList
));
deptRepository
.
findById
(
8L
).
ifPresent
(
user:
:
setDept
);
user
.
setUsername
(
phone
);
user
.
setNickName
(
pfuser
.
getUsername
());
user
.
setGender
(
pfuser
.
getSex
()
==
null
?
"未知"
:
pfuser
.
getSex
()
==
0
?
"男"
:
"女"
);
user
.
setPhone
(
phone
);
user
.
setEmail
(
pfuser
.
getSourcemail
());
user
.
setPassword
(
passwordEncoder
.
encode
(
"gxmz!23"
));
user
.
setIsAdmin
(
false
);
user
.
setEnabled
(
true
);
user
.
setCreateBy
(
"admin"
);
user
.
setUpdatedBy
(
"admin"
);
user
.
setCreateTime
(
DateUtil
.
date
().
toTimestamp
());
user
.
setUpdateTime
(
DateUtil
.
date
().
toTimestamp
());
create
(
user
);
}
return
user
;
}
/**
* 判断验证码
*
* @param phone
* @param code
*/
public
void
verificationCode
(
String
phone
,
String
code
)
{
String
cacheCode
=
redisUtils
.
getStr
(
CacheKeys
.
authCodeKey
(
phone
));
AssertUtils
.
isTrue
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
(
cacheCode
)
&&
cacheCode
.
equalsIgnoreCase
(
code
),
"验证码错误"
);
redisUtils
.
deleteStr
(
CacheKeys
.
authCodeKey
(
phone
));
}
@Override
public
void
modifyPasswd
(
LoginVo
vo
)
{
verificationCode
(
vo
.
getPhone
(),
vo
.
getVerifyCode
());
User
user
=
userRepository
.
findByUsername
(
vo
.
getPhone
());
AssertUtils
.
notNull
(
user
,
"手机号不存在"
);
updatePass
(
user
.
getUsername
(),
passwordEncoder
.
encode
(
vo
.
getPasswd
()));
}
@Override
public
ApiTokenVo
phoneLogin
(
LoginVo
vo
)
{
User
user
=
userRepository
.
findByUsername
(
vo
.
getPhone
());
if
(
user
==
null
)
{
user
=
addUser
(
vo
.
getPhone
());
}
AssertUtils
.
notNull
(
user
,
"手机号不存在"
);
verificationCode
(
vo
.
getPhone
(),
vo
.
getVerifyCode
());
AssertUtils
.
isTrue
(
user
.
getEnabled
(),
"账号已禁用"
);
return
getApiToken
(
user
);
}
/**
* 获取ApiToken
*
* @param user
* @return
*/
private
ApiTokenVo
getApiToken
(
User
user
)
{
ApiTokenVo
tokenVo
=
ApiTokenVo
.
builder
()
.
userId
(
user
.
getId
())
.
phone
(
user
.
getPhone
())
.
name
(
user
.
getNickName
())
.
nickname
(
user
.
getNickName
())
.
sex
(
user
.
getGender
())
.
avatar
(
user
.
getAvatarPath
())
.
build
();
String
token
=
ApiTokenUtils
.
createToken
(
tokenVo
,
CacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
tokenVo
.
setToken
(
token
);
// 缓存登录用户
redisUtils
.
setObj
(
CacheKeys
.
appTokenKey
(
token
),
tokenVo
,
CacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
// 重新登录删除前一个token实现单点登录
redisUtils
.
deleteStr
(
CacheKeys
.
liveAppTokenKey
(
user
.
getId
()));
// 限制同一时间同一帐号只能在一个设备上登录
redisUtils
.
setStr
(
CacheKeys
.
liveAppTokenKey
(
user
.
getId
()),
token
,
CacheKeys
.
APP_TOKEN_EXPIRE_MINUTES
);
return
tokenVo
;
}
@Override
public
ApiTokenVo
passwdLogin
(
LoginVo
vo
)
{
User
user
=
userRepository
.
findByUsername
(
vo
.
getPhone
());
AssertUtils
.
notNull
(
user
,
"手机号不存在"
);
AssertUtils
.
hasText
(
user
.
getPassword
(),
"未设置密码"
);
AssertUtils
.
isTrue
(
passwordEncoder
.
matches
(
vo
.
getPasswd
(),
user
.
getPassword
()),
"密码错误"
);
AssertUtils
.
isTrue
(
user
.
getEnabled
(),
"账号已禁用"
);
return
getApiToken
(
user
);
}
}
sys-server/src/main/java/com/zq/system/utils/MobileSmsUtils.java
0 → 100644
View file @
6c3690cc
package
com
.
zq
.
system
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
lombok.Data
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.util.DigestUtils
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.nio.charset.StandardCharsets
;
public
class
MobileSmsUtils
{
/**
* 账号
*/
private
static
String
apId
=
"sjfx"
;
/**
* 密码
*/
private
static
String
secretKey
=
"Shujufenxi!2345"
;
/**
* 集团名称
*/
private
static
String
ecName
=
"广西壮族自治区民政厅"
;
/**
* 网关签名编码
*/
private
static
String
sign
=
"nMbQzvoRh"
;
/**
* 拓展码(可以为空)
*/
private
static
String
addSerial
=
""
;
/**
* url
*/
private
static
String
url
=
"http://112.35.1.155:1992/sms/norsubmit"
;
/**
* 多用户发送短信信息
*
* @param mobiles 手机号码逗号分隔
* @param content 短信内容
* @return 返回1表示成功,0表示失败
*/
public
static
boolean
sendMsg
(
String
mobiles
,
String
content
)
{
SendReq
sendReq
=
new
SendReq
();
sendReq
.
setApId
(
apId
);
sendReq
.
setEcName
(
ecName
);
sendReq
.
setSecretKey
(
secretKey
);
sendReq
.
setContent
(
content
);
sendReq
.
setMobiles
(
mobiles
);
sendReq
.
setAddSerial
(
addSerial
);
sendReq
.
setSign
(
sign
);
String
stringBuffer
=
sendReq
.
getEcName
()
+
sendReq
.
getApId
()
+
sendReq
.
getSecretKey
()
+
sendReq
.
getMobiles
()
+
sendReq
.
getContent
()
+
sendReq
.
getSign
()
+
sendReq
.
getAddSerial
();
sendReq
.
setMac
(
DigestUtils
.
md5DigestAsHex
(
stringBuffer
.
getBytes
()).
toLowerCase
());
String
reqText
=
JSON
.
toJSONString
(
sendReq
);
// BASE64编码
String
encode
=
Base64
.
encodeBase64String
(
reqText
.
getBytes
(
StandardCharsets
.
UTF_8
));
// System.out.println(encode);
String
resStr
=
sendPost
(
url
,
encode
);
// System.out.println("发送短信结果:" + resStr);
SendRes
sendRes
=
JSON
.
parseObject
(
resStr
,
SendRes
.
class
);
return
sendRes
.
getSuccess
()
&&
!
""
.
equals
(
sendRes
.
getMsgGroup
())
&&
"success"
.
equals
(
sendRes
.
getRspcod
());
}
/**
* main方法测试发送短信,返回1表示成功,0表示失败
*
* @param args
* @throws IOException
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
{
String
msg
=
"这是发送短信的内容!"
;
sendMsg
(
"15224553696"
,
msg
);
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数
* @return 所代表远程资源的响应结果
*/
private
static
String
sendPost
(
String
url
,
String
param
)
{
OutputStreamWriter
out
=
null
;
BufferedReader
in
=
null
;
StringBuilder
result
=
new
StringBuilder
();
try
{
URL
realUrl
=
new
URL
(
url
);
URLConnection
conn
=
realUrl
.
openConnection
();
conn
.
setRequestProperty
(
"accept"
,
"*/*"
);
conn
.
setRequestProperty
(
"contentType"
,
"utf-8"
);
conn
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
);
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
out
=
new
OutputStreamWriter
(
conn
.
getOutputStream
());
out
.
write
(
param
);
out
.
flush
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
"\n"
).
append
(
line
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
}
return
result
.
toString
();
}
@Data
public
static
class
SendReq
{
/**
* 集团客户名称
*/
private
String
ecName
;
/**
* 用户名
*/
private
String
apId
;
/**
* 密码
*/
private
String
secretKey
;
/**
* 手机号码逗号分隔。(如“1813728****,1813728****,1813728****”)
*/
private
String
mobiles
;
/**
* 发送短信内容
*/
private
String
content
;
/**
* 网关签名编码,必填,签名编码在中国移动集团开通帐号后分配,可以在云MAS网页端管理子系统-SMS接口管理功能中下载。
*/
private
String
sign
;
/**
* 扩展码,根据向移动公司申请的通道填写,如果申请的精确匹配通道,则填写空字符串(""),否则添加移动公司允许的扩展码。
*/
private
String
addSerial
;
/**
* 按文档要求加密后的mac
*/
private
String
mac
;
}
@Data
public
static
class
SendRes
{
/**
* 响应状态码
*/
private
String
rspcod
;
/**
* 消息批次号,由云MAS平台生成,用于验证短信提交报告和状态报告的一致性(取值msgGroup)注:如果数据验证不通过msgGroup为空
*/
private
String
msgGroup
;
/**
* 数据校验结果
*/
private
Boolean
success
;
}
}
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