Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
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
姚本章
dm_project
Commits
7f7bda24
Commit
7f7bda24
authored
Dec 03, 2020
by
ysongq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
4b65d01d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
286 additions
and
23 deletions
+286
-23
RedisMessageConstant.java
...ain/java/com/jz/common/constant/RedisMessageConstant.java
+2
-0
UserTypeEnum.java
...ommon/src/main/java/com/jz/common/enums/UserTypeEnum.java
+36
-0
SessionUtils.java
...ommon/src/main/java/com/jz/common/utils/SessionUtils.java
+2
-2
LoginController.java
...z/dm/mall/moduls/controller/customer/LoginController.java
+1
-8
MallCustomerApiDto.java
...l/moduls/controller/customer/bean/MallCustomerApiDto.java
+82
-0
MallCustomerServiceImpl.java
.../dm/mall/moduls/service/impl/MallCustomerServiceImpl.java
+30
-2
LoginController.java
.../com/jz/manage/moduls/controller/sys/LoginController.java
+2
-6
SysUserDto.java
.../com/jz/manage/moduls/controller/sys/bean/SysUserDto.java
+89
-0
SysUserServiceImpl.java
...com/jz/manage/moduls/service/impl/SysUserServiceImpl.java
+42
-5
No files found.
jz-dm-common/src/main/java/com/jz/common/constant/RedisMessageConstant.java
View file @
7f7bda24
...
...
@@ -3,4 +3,6 @@ package com.jz.common.constant;
public
interface
RedisMessageConstant
{
static
final
String
SENDTYPE_GETPWD
=
"001"
;
//用于缓存找回密码时发送的验证码
static
final
String
SENDTYPE_LOGIN
=
"002"
;
// 用于缓存注册用户时发送的验证码
static
final
String
SENDTYPE_LOGIN_CUSTOMER
=
"003"
;
static
final
String
SENDTYPE_LOGIN_SYS
=
"004"
;
}
\ No newline at end of file
jz-dm-common/src/main/java/com/jz/common/enums/UserTypeEnum.java
0 → 100644
View file @
7f7bda24
package
com
.
jz
.
common
.
enums
;
/**
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
public
enum
UserTypeEnum
{
COMPANY_ROLE
(
"商城的id"
,
"1"
),
BACKGROUND_ROLE
(
"企业的id"
,
"2"
),
;
private
String
code
;
private
String
value
;
private
UserTypeEnum
(
String
code
,
String
value
)
{
this
.
code
=
code
;
this
.
value
=
value
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getValue
()
{
return
value
;
}
}
jz-dm-common/src/main/java/com/jz/common/utils/SessionUtils.java
View file @
7f7bda24
...
...
@@ -19,7 +19,7 @@ public class SessionUtils {
* @param objName 存储到session中的对象的变量名
* @param o 存储的任意数据
*/
public
static
void
push
(
String
objName
,
Object
o
)
{
public
static
void
setUserCurrent
(
String
objName
,
Object
o
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
request
.
getSession
().
setAttribute
(
objName
,
o
);
...
...
@@ -29,7 +29,7 @@ public class SessionUtils {
* 从session中获取数据
* @param objName 存储到session中的对象的变量名
*/
public
static
Object
pop
(
String
objName
)
{
public
static
Object
getUserCurrent
(
String
objName
)
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
return
request
.
getSession
().
getAttribute
(
objName
);
...
...
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/controller/customer/LoginController.java
View file @
7f7bda24
...
...
@@ -12,8 +12,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpSession
;
/**
* @ClassName:
...
...
@@ -40,17 +38,14 @@ public class LoginController {
* @return
*/
@PostMapping
(
value
=
"/login"
)
public
Result
<
MallCustomer
>
login
(
String
username
,
String
password
,
HttpServletRequest
request
)
{
public
Result
<
MallCustomer
>
login
(
String
username
,
String
password
)
{
// 手机
String
ph
=
"^[1][34578]\\d{9}$"
;
HttpSession
session
=
request
.
getSession
();
// 如果是手机验证
if
(
username
.
matches
(
username
))
{
MallCustomer
mallCustomer
=
mallCustomerService
.
selectByPhone
(
username
);
if
(
mallCustomer
!=
null
)
{
if
(
mallCustomer
.
getCustomerPhone
().
equals
(
username
)
&&
mallCustomer
.
getPassword
().
equals
(
password
)){
session
.
setAttribute
(
"customer_id"
,
mallCustomer
.
getCustomerId
());
session
.
setAttribute
(
"customer_account"
,
mallCustomer
.
getCustomerAccount
());
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
}
return
new
Result
<>(
false
,
"用户名或密码错误!"
,
StatusCode
.
ERROR
);
...
...
@@ -59,8 +54,6 @@ public class LoginController {
MallCustomer
mallCustomer
=
mallCustomerService
.
selectByAccount
(
username
);
if
(
mallCustomer
!=
null
)
{
if
(
mallCustomer
.
getCustomerAccount
().
equals
(
username
)
&&
mallCustomer
.
getPassword
().
equals
(
password
)){
session
.
setAttribute
(
"customer_id"
,
mallCustomer
.
getCustomerId
());
session
.
setAttribute
(
"customer_account"
,
mallCustomer
.
getCustomerAccount
());
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
}
}
...
...
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/controller/customer/bean/MallCustomerApiDto.java
0 → 100644
View file @
7f7bda24
package
com
.
jz
.
dm
.
mall
.
moduls
.
controller
.
customer
.
bean
;
import
com.jz.common.enums.UserTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
/**
* @ClassName: 商城用户状态信息
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
@ApiModel
public
class
MallCustomerApiDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
8769496459018372044L
;
@ApiModelProperty
(
value
=
"用户id"
)
private
Long
customerId
;
@ApiModelProperty
(
value
=
"用户类型"
)
private
UserTypeEnum
userTypeEnum
;
@ApiModelProperty
(
value
=
"企业id"
)
private
Long
departmentId
;
/**
* 账户
*/
private
String
customerAccount
;
/**
* 用户真实姓名
*/
private
String
customerName
;
public
static
long
getSerialVersionUID
()
{
return
serialVersionUID
;
}
public
Long
getCustomerId
()
{
return
customerId
;
}
public
void
setCustomerId
(
Long
customerId
)
{
this
.
customerId
=
customerId
;
}
public
UserTypeEnum
getUserTypeEnum
()
{
return
userTypeEnum
;
}
public
void
setUserTypeEnum
(
UserTypeEnum
userTypeEnum
)
{
this
.
userTypeEnum
=
userTypeEnum
;
}
public
Long
getDepartmentId
()
{
return
departmentId
;
}
public
void
setDepartmentId
(
Long
departmentId
)
{
this
.
departmentId
=
departmentId
;
}
public
String
getCustomerAccount
()
{
return
customerAccount
;
}
public
void
setCustomerAccount
(
String
customerAccount
)
{
this
.
customerAccount
=
customerAccount
;
}
public
String
getCustomerName
()
{
return
customerName
;
}
public
void
setCustomerName
(
String
customerName
)
{
this
.
customerName
=
customerName
;
}
}
jz-dm-mall/src/main/java/com/jz/dm/mall/moduls/service/impl/MallCustomerServiceImpl.java
View file @
7f7bda24
package
com
.
jz
.
dm
.
mall
.
moduls
.
service
.
impl
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.enums.UserTypeEnum
;
import
com.jz.common.utils.SessionUtils
;
import
com.jz.dm.mall.moduls.controller.customer.bean.MallCustomerApiDto
;
import
com.jz.dm.mall.moduls.entity.MallCustomer
;
import
com.jz.dm.mall.moduls.mapper.MallCustomerDao
;
import
com.jz.dm.mall.moduls.service.MallCustomerService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
java.util.concurrent.TimeUnit
;
/**
* 商城用户(TMallCustomer)表服务实现类
...
...
@@ -18,6 +25,9 @@ public class MallCustomerServiceImpl implements MallCustomerService {
@Autowired
private
MallCustomerDao
tMallCustomerDao
;
@Autowired
private
RedisTemplate
redisTemplate
;
/**
* 通过用户账号进行查询
*
...
...
@@ -26,7 +36,23 @@ public class MallCustomerServiceImpl implements MallCustomerService {
*/
@Override
public
MallCustomer
selectByAccount
(
String
username
)
{
return
tMallCustomerDao
.
selectByAccount
(
username
);
MallCustomer
mallCustomer
=
tMallCustomerDao
.
selectByAccount
(
username
);
// String customer = JSON.toJSONString(mallCustomer);
if
(
mallCustomer
!=
null
)
{
MallCustomerApiDto
mallCustomerApiDto
=
new
MallCustomerApiDto
();
// 赋值
mallCustomerApiDto
.
setCustomerId
(
mallCustomer
.
getCustomerId
());
mallCustomerApiDto
.
setDepartmentId
(
mallCustomer
.
getDepartmentId
());
mallCustomerApiDto
.
setUserTypeEnum
(
UserTypeEnum
.
COMPANY_ROLE
);
mallCustomerApiDto
.
setCustomerAccount
(
mallCustomer
.
getCustomerAccount
());
mallCustomerApiDto
.
setCustomerName
(
mallCustomer
.
getCustomerName
());
// 存入到session
SessionUtils
.
setUserCurrent
(
"mallCustomer"
,
mallCustomerApiDto
);
// 存入到redis
redisTemplate
.
opsForValue
().
set
(
"user_"
+
RedisMessageConstant
.
SENDTYPE_LOGIN_CUSTOMER
,
mallCustomerApiDto
,
3
,
TimeUnit
.
DAYS
);
}
return
mallCustomer
;
}
/**
...
...
@@ -37,7 +63,9 @@ public class MallCustomerServiceImpl implements MallCustomerService {
*/
@Override
public
MallCustomer
selectByPhone
(
String
username
)
{
return
tMallCustomerDao
.
selectByPhone
(
username
);
MallCustomer
mallCustomer
=
tMallCustomerDao
.
selectByPhone
(
username
);
return
mallCustomer
;
}
...
...
jz-dm-manage/src/main/java/com/jz/manage/moduls/controller/sys/LoginController.java
View file @
7f7bda24
...
...
@@ -3,6 +3,7 @@ package com.jz.manage.moduls.controller.sys;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.entity.SysUser
;
import
com.jz.common.utils.Result
;
import
com.jz.common.utils.SessionUtils
;
import
com.jz.common.utils.StatusCode
;
import
com.jz.manage.moduls.controller.BaseController
;
import
com.jz.manage.moduls.service.SysUserService
;
...
...
@@ -38,14 +39,12 @@ public class LoginController extends BaseController {
public
Result
login
(
String
username
,
String
password
,
HttpServletRequest
request
)
{
// 手机
String
ph
=
"^[1][34578]\\d{9}$"
;
HttpSession
session
=
request
.
getSession
();
// 如果是手机验证
if
(
username
.
matches
(
username
))
{
SysUser
sysUser
=
sysUserService
.
selectByPhone
(
username
);
if
(
sysUser
!=
null
)
{
if
(
sysUser
.
getTelephone
().
equals
(
username
)
&&
sysUser
.
getPassword
().
equals
(
password
)){
session
.
setAttribute
(
"account"
,
sysUser
.
getAccount
());
session
.
setAttribute
(
"password"
,
sysUser
.
getPassword
());
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
}
return
new
Result
<>(
false
,
"用户名或密码错误!"
,
StatusCode
.
ERROR
);
...
...
@@ -54,8 +53,6 @@ public class LoginController extends BaseController {
SysUser
sysUser
=
sysUserService
.
selectByUsername
(
username
);
if
(
sysUser
!=
null
)
{
if
(
sysUser
.
getAccount
().
equals
(
username
)
&&
sysUser
.
getPassword
().
equals
(
password
)){
session
.
setAttribute
(
"account"
,
sysUser
.
getAccount
());
session
.
setAttribute
(
"password"
,
sysUser
.
getPassword
());
return
new
Result
<>(
true
,
"登录成功!"
,
StatusCode
.
OK
);
}
}
...
...
@@ -64,7 +61,6 @@ public class LoginController extends BaseController {
/**
* 手机号码校验
* @param paramMap
...
...
jz-dm-manage/src/main/java/com/jz/manage/moduls/controller/sys/bean/SysUserDto.java
0 → 100644
View file @
7f7bda24
package
com
.
jz
.
manage
.
moduls
.
controller
.
sys
.
bean
;
import
com.jz.common.enums.UserTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
/**
* @ClassName: 后台用户状态信息
* @Author: Carl
* @Date: 2020/12/3
* @Version:
*/
@ApiModel
public
class
SysUserDto
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
8194718171444972705L
;
/**
* 平台用户id
*/
@ApiModelProperty
(
value
=
"平台用户id"
)
private
Long
userId
;
/**
* 组织机构id
*/
@ApiModelProperty
(
value
=
"组织机构id"
)
private
Long
orgId
;
/**
* 用户姓名
*/
@ApiModelProperty
(
value
=
"用户姓名"
)
private
String
userName
;
/**
* 账户
*/
@ApiModelProperty
(
value
=
"账户"
)
private
String
account
;
/**
* 电话
*/
@ApiModelProperty
(
value
=
"账号类型"
)
private
UserTypeEnum
userTypeEnum
;
public
static
long
getSerialVersionUID
()
{
return
serialVersionUID
;
}
public
Long
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
Long
userId
)
{
this
.
userId
=
userId
;
}
public
Long
getOrgId
()
{
return
orgId
;
}
public
void
setOrgId
(
Long
orgId
)
{
this
.
orgId
=
orgId
;
}
public
String
getUserName
()
{
return
userName
;
}
public
void
setUserName
(
String
userName
)
{
this
.
userName
=
userName
;
}
public
String
getAccount
()
{
return
account
;
}
public
void
setAccount
(
String
account
)
{
this
.
account
=
account
;
}
public
UserTypeEnum
getUserTypeEnum
()
{
return
userTypeEnum
;
}
public
void
setUserTypeEnum
(
UserTypeEnum
userTypeEnum
)
{
this
.
userTypeEnum
=
userTypeEnum
;
}
}
jz-dm-manage/src/main/java/com/jz/manage/moduls/service/impl/SysUserServiceImpl.java
View file @
7f7bda24
package
com
.
jz
.
manage
.
moduls
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.jz.common.constant.RedisMessageConstant
;
import
com.jz.common.entity.SysUser
;
import
com.jz.common.enums.UserTypeEnum
;
import
com.jz.common.utils.SessionUtils
;
import
com.jz.manage.moduls.controller.sys.bean.SysUserDto
;
import
com.jz.manage.moduls.mapper.SysUserDao
;
import
com.jz.manage.moduls.service.SysUserService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
/**
* 平台系统用户表(SysUser)表服务实现类
...
...
@@ -23,19 +29,50 @@ public class SysUserServiceImpl implements SysUserService {
@Autowired
private
SysUserDao
sysUserDao
;
@Autowired
private
RedisTemplate
redisTemplate
;
@Override
public
SysUser
selectByUsername
(
String
account
)
{
public
SysUser
selectByUsername
(
String
username
)
{
QueryWrapper
queryWrapper
=
new
QueryWrapper
();
queryWrapper
.
eq
(
"account"
,
account
);
return
sysUserDao
.
selectOne
(
queryWrapper
);
}
queryWrapper
.
eq
(
"account"
,
username
);
SysUser
sysUser
=
sysUserDao
.
selectOne
(
queryWrapper
);
if
(
sysUser
!=
null
)
{
SysUserDto
SysUserDto
=
new
SysUserDto
();
// 赋值
SysUserDto
.
setUserId
(
sysUser
.
getUserId
());
SysUserDto
.
setOrgId
(
sysUser
.
getOrgId
());
SysUserDto
.
setAccount
(
sysUser
.
getAccount
());
SysUserDto
.
setUserTypeEnum
(
UserTypeEnum
.
BACKGROUND_ROLE
);
SysUserDto
.
setUserName
(
sysUser
.
getUserName
());
// 存入到session
SessionUtils
.
setUserCurrent
(
"sysUser"
,
SysUserDto
);
// 存入到redis
redisTemplate
.
opsForValue
().
set
(
"user_"
+
RedisMessageConstant
.
SENDTYPE_LOGIN_SYS
,
SysUserDto
,
3
,
TimeUnit
.
DAYS
);
}
return
sysUser
;
}
@Override
public
SysUser
selectByPhone
(
String
username
)
{
QueryWrapper
queryWrapper
=
new
QueryWrapper
();
queryWrapper
.
eq
(
"telephone"
,
username
);
return
sysUserDao
.
selectOne
(
queryWrapper
);
SysUser
sysUser
=
sysUserDao
.
selectOne
(
queryWrapper
);
if
(
sysUser
!=
null
)
{
SysUserDto
SysUserDto
=
new
SysUserDto
();
// 赋值
SysUserDto
.
setUserId
(
sysUser
.
getUserId
());
SysUserDto
.
setOrgId
(
sysUser
.
getOrgId
());
SysUserDto
.
setAccount
(
sysUser
.
getAccount
());
SysUserDto
.
setUserTypeEnum
(
UserTypeEnum
.
BACKGROUND_ROLE
);
SysUserDto
.
setUserName
(
sysUser
.
getUserName
());
// 存入到session
SessionUtils
.
setUserCurrent
(
"sysUser"
,
SysUserDto
);
// 存入到redis
redisTemplate
.
opsForValue
().
set
(
"user_"
+
RedisMessageConstant
.
SENDTYPE_LOGIN_SYS
,
SysUserDto
,
3
,
TimeUnit
.
DAYS
);
}
return
sysUser
;
}
@Override
...
...
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