Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JeeSpringCloud
Commits
8b643e22
Commit
8b643e22
authored
Oct 12, 2018
by
HuangBingGui
Browse files
no commit message
parent
563ff060
Changes
385
Show whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 385+
files are displayed.
Plain diff
Email patch
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/rest/SysUserOnlineRestController.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.rest
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.authz.annotation.Logical
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.jeespring.common.utils.DateUtils
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.utils.excel.ExportExcel
;
import
com.jeespring.common.utils.excel.ImportExcel
;
import
com.jeespring.modules.sys.entity.SysUserOnline
;
import
com.jeespring.modules.sys.service.SysUserOnlineService
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.jeespring.common.web.Result
;
import
com.jeespring.common.web.ResultFactory
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.*
;
/**
* 在线用户记录Controller
* @author JeeSpring
* @version 2018-08-16
*/
@RestController
@RequestMapping
(
value
=
"/rest/sys/sysUserOnline"
)
@Api
(
value
=
"在线用户记录接口"
,
description
=
"在线用户记录接口"
)
public
class
SysUserOnlineRestController
extends
AbstractBaseController
{
@Autowired
private
SysUserOnlineService
sysUserOnlineService
;
/**
* 在线用户记录信息
*/
@RequestMapping
(
value
=
{
"get"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户记录信息(Content-Type为text/html)"
,
notes
=
"在线用户记录信息(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"在线用户记录id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
getRequestParam
(
@RequestParam
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
@RequestMapping
(
value
=
{
"get/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"在线用户记录信息(Content-Type为application/json)"
,
notes
=
"在线用户记录信息(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"id"
,
value
=
"在线用户记录id"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
getRequestBody
(
@RequestBody
(
required
=
false
)
String
id
)
{
return
get
(
id
);
}
private
Result
get
(
String
id
)
{
SysUserOnline
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysUserOnlineService
.
getCache
(
id
);
//entity = sysUserOnlineService.get(id);
}
if
(
entity
==
null
){
entity
=
new
SysUserOnline
();
}
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
entity
);
return
result
;
}
/**
* 在线用户记录列表(不包含页信息)
*/
//RequiresPermissions("sys:sysUserOnline:findList")
@RequestMapping
(
value
=
{
"findList"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户记录列表(不包含页信息)(Content-Type为text/html)"
,
notes
=
"在线用户记录列表(不包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
findListRequestParam
(
SysUserOnline
sysUserOnline
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
findList
(
sysUserOnline
,
model
);
}
@RequestMapping
(
value
=
{
"findList/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"在线用户记录列表(不包含页信息)(Content-Type为application/json)"
,
notes
=
"在线用户记录列表(不包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
findListRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
Model
model
)
{
return
findList
(
sysUserOnline
,
model
);
}
private
Result
findList
(
SysUserOnline
sysUserOnline
,
Model
model
)
{
List
<
SysUserOnline
>
list
=
sysUserOnlineService
.
findListCache
(
sysUserOnline
);
//List<SysUserOnline> list = sysUserOnlineService.findList(sysUserOnline);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
list
);
return
result
;
}
/**
* 在线用户记录列表(包含页信息)
*/
//RequiresPermissions("sys:sysUserOnline:list")
@RequestMapping
(
value
=
{
"list"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户记录列表(包含页信息)(Content-Type为text/html)"
,
notes
=
"在线用户记录列表(包含页信息)(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
listRequestParam
(
SysUserOnline
sysUserOnline
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
list
(
sysUserOnline
,
model
);
}
@RequestMapping
(
value
=
{
"list/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"在线用户记录列表(包含页信息)(Content-Type为application/json)"
,
notes
=
"在线用户记录列表(包含页信息)(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
listRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
Model
model
)
{
return
list
(
sysUserOnline
,
model
);
}
private
Result
list
(
SysUserOnline
sysUserOnline
,
Model
model
)
{
Page
<
SysUserOnline
>
page
=
sysUserOnlineService
.
findPageCache
(
new
Page
<
SysUserOnline
>(
sysUserOnline
.
getPageNo
(),
sysUserOnline
.
getPageSize
(),
sysUserOnline
.
getOrderBy
()),
sysUserOnline
);
//Page<SysUserOnline> page = sysUserOnlineService.findPage(new Page<SysUserOnline>(sysUserOnline.getPageNo(),sysUserOnline.getPageSize(),sysUserOnline.getOrderBy()), sysUserOnline);
Result
result
=
ResultFactory
.
getSuccessResult
();
result
.
setResultObject
(
page
);
return
result
;
}
/**
* 在线用户记录获取列表第一条记录
*/
//RequiresPermissions("sys:sysUserOnline:listFrist")
@RequestMapping
(
value
=
{
"listFrist"
},
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"在线用户记录获取列表第一条记录(Content-Type为text/html)"
,
notes
=
"在线用户记录获取列表第一条记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
listFristRequestParam
(
SysUserOnline
sysUserOnline
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
return
listFrist
(
sysUserOnline
,
model
);
}
@RequestMapping
(
value
=
{
"listFrist/json"
},
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"在线用户记录获取列表第一条记录(Content-Type为application/json)"
,
notes
=
"在线用户记录获取列表第一条记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
listFristRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
Model
model
)
{
return
listFrist
(
sysUserOnline
,
model
);
}
private
Result
listFrist
(
SysUserOnline
sysUserOnline
,
Model
model
)
{
Page
<
SysUserOnline
>
page
=
sysUserOnlineService
.
findPageCache
(
new
Page
<
SysUserOnline
>(
sysUserOnline
.
getPageNo
(),
sysUserOnline
.
getPageSize
(),
sysUserOnline
.
getOrderBy
()),
sysUserOnline
);
//Page<SysUserOnline> page = sysUserOnlineService.findPage(new Page<SysUserOnline>(sysUserOnline.getPageNo(),sysUserOnline.getPageSize(),sysUserOnline.getOrderBy()), sysUserOnline);
Result
result
=
ResultFactory
.
getSuccessResult
();
if
(
page
.
getList
().
size
()>
0
){
result
.
setResultObject
(
page
.
getList
().
get
(
0
));
}
else
{
result
=
ResultFactory
.
getErrorResult
(
"没有记录!"
);
}
return
result
;
}
/**
* 保存在线用户记录
*/
//RequiresPermissions(value={"sys:sysUserOnline:add","sys:sysUserOnline:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"保存在线用户记录(Content-Type为text/html)"
,
notes
=
"保存在线用户记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
saveRequestParam
(
SysUserOnline
sysUserOnline
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysUserOnline
,
model
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"save/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"保存在线用户记录(Content-Type为application/json)"
,
notes
=
"保存在线用户记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
saveRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
return
save
(
sysUserOnline
,
model
,
redirectAttributes
);
}
private
Result
save
(
SysUserOnline
sysUserOnline
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
beanValidator
(
model
,
sysUserOnline
)){
Result
result
=
ResultFactory
.
getErrorResult
(
"数据验证失败"
);
}
sysUserOnlineService
.
save
(
sysUserOnline
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"保存在线用户记录成功"
);
return
result
;
}
/**
* 删除在线用户记录
*/
//RequiresPermissions("sys:sysUserOnline:del")
@RequestMapping
(
value
=
"delete"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"删除在线用户记录(Content-Type为text/html)"
,
notes
=
"删除在线用户记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
deleteRequestParam
(
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysUserOnline
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"delete/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"删除在线用户记录(Content-Type为application/json)"
,
notes
=
"删除在线用户记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
deleteRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
return
delete
(
sysUserOnline
,
redirectAttributes
);
}
private
Result
delete
(
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
sysUserOnlineService
.
delete
(
sysUserOnline
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除在线用户记录成功"
);
return
result
;
}
/**
* 删除在线用户记录(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑删除在线用户记录(Content-Type为text/html)"
,
notes
=
"逻辑删除在线用户记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"query"
)
public
Result
deleteByLogicRequestParam
(
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysUserOnline
,
redirectAttributes
);
}
/**
* 删除在线用户记录(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑删除在线用户记录(Content-Type为application/json)"
,
notes
=
"逻辑删除在线用户记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"sysUserOnline"
,
value
=
"在线用户记录"
,
dataType
=
"SysUserOnline"
,
paramType
=
"body"
)
public
Result
deleteByLogicRequestBody
(
@RequestBody
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
return
deleteByLogic
(
sysUserOnline
,
redirectAttributes
);
}
private
Result
deleteByLogic
(
SysUserOnline
sysUserOnline
,
RedirectAttributes
redirectAttributes
)
{
sysUserOnlineService
.
deleteByLogic
(
sysUserOnline
);
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除在线用户记录成功"
);
return
result
;
}
/**
* 批量删除在线用户记录
*/
//RequiresPermissions("sys:sysUserOnline:del")
@RequestMapping
(
value
=
"deleteAll"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"批量删除在线用户记录(Content-Type为text/html)"
,
notes
=
"批量删除在线用户记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"在线用户记录ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
@RequestMapping
(
value
=
"deleteAll/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"批量删除在线用户记录(Content-Type为application/json)"
,
notes
=
"批量删除在线用户记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"在线用户记录ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAll
(
ids
,
redirectAttributes
);
}
private
Result
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
idArray
[]
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysUserOnlineService
.
delete
(
sysUserOnlineService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除在线用户记录成功"
);
return
result
;
}
/**
* 批量删除在线用户记录(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic"
,
method
={
RequestMethod
.
POST
,
RequestMethod
.
GET
})
@ApiOperation
(
value
=
"逻辑批量删除在线用户记录(Content-Type为text/html)"
,
notes
=
"逻辑批量删除在线用户记录(Content-Type为text/html)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"在线用户记录ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"query"
)
public
Result
deleteAllByLogicRequestParam
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
/**
* 批量删除在线用户记录(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
@RequestMapping
(
value
=
"deleteAllByLogic/json"
,
method
={
RequestMethod
.
POST
})
@ApiOperation
(
value
=
"逻辑批量删除在线用户记录(Content-Type为application/json)"
,
notes
=
"逻辑批量删除在线用户记录(Content-Type为application/json)"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"在线用户记录ids,用,隔开"
,
required
=
false
,
dataType
=
"String"
,
paramType
=
"body"
)
public
Result
deleteAllByLogicRequestBody
(
@RequestBody
String
ids
,
RedirectAttributes
redirectAttributes
)
{
return
deleteAllByLogic
(
ids
,
redirectAttributes
);
}
private
Result
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
String
idArray
[]
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysUserOnlineService
.
deleteByLogic
(
sysUserOnlineService
.
get
(
id
));
}
Result
result
=
ResultFactory
.
getSuccessResult
(
"删除在线用户记录成功"
);
return
result
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/security/FormAuthenticationFilter.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.security
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationToken
;
import
org.apache.shiro.authc.IncorrectCredentialsException
;
import
org.apache.shiro.authc.UnknownAccountException
;
import
org.apache.shiro.web.util.WebUtils
;
import
org.springframework.stereotype.Service
;
import
com.jeespring.common.utils.StringUtils
;
/**
* 表单验证(包含验证码)过滤类
* @author 黄炳桂 516821420@qq.com
* @version 2014-5-19
*/
@Service
public
class
FormAuthenticationFilter
extends
org
.
apache
.
shiro
.
web
.
filter
.
authc
.
FormAuthenticationFilter
{
public
static
final
String
DEFAULT_CAPTCHA_PARAM
=
"validateCode"
;
public
static
final
String
DEFAULT_MOBILE_PARAM
=
"mobileLogin"
;
public
static
final
String
DEFAULT_MESSAGE_PARAM
=
"message"
;
private
String
captchaParam
=
DEFAULT_CAPTCHA_PARAM
;
private
String
mobileLoginParam
=
DEFAULT_MOBILE_PARAM
;
private
String
messageParam
=
DEFAULT_MESSAGE_PARAM
;
@Override
protected
AuthenticationToken
createToken
(
ServletRequest
request
,
ServletResponse
response
)
{
String
username
=
getUsername
(
request
);
String
password
=
getPassword
(
request
);
if
(
password
==
null
){
password
=
""
;
}
boolean
rememberMe
=
isRememberMe
(
request
);
String
host
=
StringUtils
.
getRemoteAddr
((
HttpServletRequest
)
request
);
String
captcha
=
getCaptcha
(
request
);
boolean
mobile
=
isMobileLogin
(
request
);
return
new
UsernamePasswordToken
(
username
,
password
.
toCharArray
(),
rememberMe
,
host
,
captcha
,
mobile
);
}
public
String
getCaptchaParam
()
{
return
captchaParam
;
}
protected
String
getCaptcha
(
ServletRequest
request
)
{
return
WebUtils
.
getCleanParam
(
request
,
getCaptchaParam
());
}
public
String
getMobileLoginParam
()
{
return
mobileLoginParam
;
}
protected
boolean
isMobileLogin
(
ServletRequest
request
)
{
return
WebUtils
.
isTrue
(
request
,
getMobileLoginParam
());
}
public
String
getMessageParam
()
{
return
messageParam
;
}
/**
* 登录成功之后跳转URL
*/
@Override
public
String
getSuccessUrl
()
{
return
super
.
getSuccessUrl
();
}
@Override
protected
void
issueSuccessRedirect
(
ServletRequest
request
,
ServletResponse
response
)
throws
Exception
{
// Principal p = UserUtils.getPrincipal();
// if (p != null && !p.isMobileLogin()){
WebUtils
.
issueRedirect
(
request
,
response
,
getSuccessUrl
(),
null
,
true
);
// }else{
// super.issueSuccessRedirect(request, response);
// }
}
/**
* 登录失败调用事件
*/
@Override
protected
boolean
onLoginFailure
(
AuthenticationToken
token
,
AuthenticationException
e
,
ServletRequest
request
,
ServletResponse
response
)
{
String
className
=
e
.
getClass
().
getName
(),
message
=
""
;
if
(
IncorrectCredentialsException
.
class
.
getName
().
equals
(
className
)
||
UnknownAccountException
.
class
.
getName
().
equals
(
className
)){
message
=
"用户或密码错误, 请重试."
;
}
else
if
(
e
.
getMessage
()
!=
null
&&
StringUtils
.
startsWith
(
e
.
getMessage
(),
"msg:"
)){
message
=
StringUtils
.
replace
(
e
.
getMessage
(),
"msg:"
,
""
);
}
else
{
message
=
"系统出现点问题,请稍后再试!"
;
e
.
printStackTrace
();
// 输出到控制台
}
request
.
setAttribute
(
getFailureKeyAttribute
(),
className
);
request
.
setAttribute
(
getMessageParam
(),
message
);
return
true
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/security/SystemAuthorizingRealm.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.security
;
import
java.io.Serializable
;
import
java.util.Collection
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.AuthenticationInfo
;
import
org.apache.shiro.authc.AuthenticationToken
;
import
org.apache.shiro.authc.SimpleAuthenticationInfo
;
import
org.apache.shiro.authc.credential.HashedCredentialsMatcher
;
import
org.apache.shiro.authz.AuthorizationInfo
;
import
org.apache.shiro.authz.Permission
;
import
org.apache.shiro.authz.SimpleAuthorizationInfo
;
import
org.apache.shiro.realm.AuthorizingRealm
;
import
org.apache.shiro.session.Session
;
import
org.apache.shiro.subject.PrincipalCollection
;
import
org.apache.shiro.util.ByteSource
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.servlet.ValidateCodeServlet
;
import
com.jeespring.common.utils.Encodes
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.common.web.Servlets
;
import
com.jeespring.modules.sys.entity.Menu
;
import
com.jeespring.modules.sys.entity.Role
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.service.SystemService
;
import
com.jeespring.modules.sys.utils.LogUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
import
com.jeespring.modules.sys.web.LoginController
;
/**
* 系统安全认证实现类
* @author 黄炳桂 516821420@qq.com
* @version 2014-7-5
*/
@Service
//@DependsOn({"userDao","roleDao","menuDao"})
public
class
SystemAuthorizingRealm
extends
AuthorizingRealm
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
SystemService
systemService
;
/**
* 认证回调函数, 登录时调用
*/
@Override
protected
AuthenticationInfo
doGetAuthenticationInfo
(
AuthenticationToken
authcToken
)
{
UsernamePasswordToken
token
=
(
UsernamePasswordToken
)
authcToken
;
int
activeSessionSize
=
getSystemService
().
getSessionDao
().
getActiveSessions
(
false
).
size
();
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"login submit, active session size: {}, username: {}"
,
activeSessionSize
,
token
.
getUsername
());
}
// 校验登录验证码
if
(
LoginController
.
isValidateCodeLogin
(
token
.
getUsername
(),
false
,
false
)){
Session
session
=
UserUtils
.
getSession
();
String
code
=
(
String
)
session
.
getAttribute
(
ValidateCodeServlet
.
VALIDATE_CODE
);
if
(
token
.
getCaptcha
()
==
null
||
!
token
.
getCaptcha
().
toUpperCase
().
equals
(
code
)){
//throw new AuthenticationException("msg:验证码错误, 请重试.");
}
}
// 校验用户名密码
User
user
=
getSystemService
().
getUserByLoginName
(
token
.
getUsername
());
if
(
user
!=
null
)
{
if
(
Global
.
NO
.
equals
(
user
.
getLoginFlag
())){
throw
new
AuthenticationException
(
"msg:该帐号已禁止登录."
);
}
byte
[]
salt
=
Encodes
.
decodeHex
(
user
.
getPassword
().
substring
(
0
,
16
));
return
new
SimpleAuthenticationInfo
(
new
Principal
(
user
,
token
.
isMobileLogin
()),
user
.
getPassword
().
substring
(
16
),
ByteSource
.
Util
.
bytes
(
salt
),
getName
());
}
else
{
return
null
;
}
}
/**
* 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用
*/
@Override
protected
AuthorizationInfo
doGetAuthorizationInfo
(
PrincipalCollection
principals
)
{
Principal
principal
=
(
Principal
)
getAvailablePrincipal
(
principals
);
User
user
=
getSystemService
().
getUserByLoginName
(
principal
.
getLoginName
());
if
(
user
!=
null
)
{
SimpleAuthorizationInfo
info
=
new
SimpleAuthorizationInfo
();
List
<
Menu
>
list
=
UserUtils
.
getMenuList
();
for
(
Menu
menu
:
list
){
if
(
StringUtils
.
isNotBlank
(
menu
.
getPermission
())){
// 添加基于Permission的权限信息
for
(
String
permission
:
StringUtils
.
split
(
menu
.
getPermission
(),
","
)){
info
.
addStringPermission
(
permission
);
}
}
}
// 添加用户权限
info
.
addStringPermission
(
"user"
);
// 添加用户角色信息
for
(
Role
role
:
user
.
getRoleList
()){
info
.
addRole
(
role
.
getEnname
());
}
// 更新登录IP和时间
getSystemService
().
updateUserLoginInfo
(
user
);
// 记录登录日志
LogUtils
.
saveLog
(
Servlets
.
getRequest
(),
"系统登录"
);
return
info
;
}
else
{
return
null
;
}
}
@Override
protected
void
checkPermission
(
Permission
permission
,
AuthorizationInfo
info
)
{
authorizationValidate
(
permission
);
super
.
checkPermission
(
permission
,
info
);
}
@Override
protected
boolean
[]
isPermitted
(
List
<
Permission
>
permissions
,
AuthorizationInfo
info
)
{
if
(
permissions
!=
null
&&
!
permissions
.
isEmpty
())
{
for
(
Permission
permission
:
permissions
)
{
authorizationValidate
(
permission
);
}
}
return
super
.
isPermitted
(
permissions
,
info
);
}
@Override
public
boolean
isPermitted
(
PrincipalCollection
principals
,
Permission
permission
)
{
authorizationValidate
(
permission
);
return
super
.
isPermitted
(
principals
,
permission
);
}
@Override
protected
boolean
isPermittedAll
(
Collection
<
Permission
>
permissions
,
AuthorizationInfo
info
)
{
if
(
permissions
!=
null
&&
!
permissions
.
isEmpty
())
{
for
(
Permission
permission
:
permissions
)
{
authorizationValidate
(
permission
);
}
}
return
super
.
isPermittedAll
(
permissions
,
info
);
}
/**
* 授权验证方法
* @param permission
*/
private
void
authorizationValidate
(
Permission
permission
){
// 模块授权预留接口
}
/**
* 设定密码校验的Hash算法与迭代次数
*/
@PostConstruct
public
void
initCredentialsMatcher
()
{
HashedCredentialsMatcher
matcher
=
new
HashedCredentialsMatcher
(
SystemService
.
HASH_ALGORITHM
);
matcher
.
setHashIterations
(
SystemService
.
HASH_INTERATIONS
);
setCredentialsMatcher
(
matcher
);
}
// /**
// * 清空用户关联权限认证,待下次使用时重新加载
// */
// public void clearCachedAuthorizationInfo(Principal principal) {
// SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
// clearCachedAuthorizationInfo(principals);
// }
/**
* 清空所有关联认证
* @Deprecated 不需要清空,授权缓存保存到session中
*/
@Deprecated
public
void
clearAllCachedAuthorizationInfo
()
{
// Cache<Object, AuthorizationInfo> cache = getAuthorizationCache();
// if (cache != null) {
// for (Object key : cache.keys()) {
// cache.remove(key);
// }
// }
}
/**
* 获取系统业务对象
*/
public
SystemService
getSystemService
()
{
if
(
systemService
==
null
){
systemService
=
SpringContextHolder
.
getBean
(
SystemService
.
class
);
}
return
systemService
;
}
/**
* 授权用户信息
*/
public
static
class
Principal
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
id
;
// 编号
private
String
loginName
;
// 登录名
private
String
name
;
// 姓名
private
boolean
mobileLogin
;
// 是否手机登录
// private Map<String, Object> cacheMap;
public
Principal
(
User
user
,
boolean
mobileLogin
)
{
this
.
id
=
user
.
getId
();
this
.
loginName
=
user
.
getLoginName
();
this
.
name
=
user
.
getName
();
this
.
mobileLogin
=
mobileLogin
;
}
public
String
getId
()
{
return
id
;
}
public
String
getLoginName
()
{
return
loginName
;
}
public
String
getName
()
{
return
name
;
}
public
boolean
isMobileLogin
()
{
return
mobileLogin
;
}
// @JsonIgnore
// public Map<String, Object> getCacheMap() {
// if (cacheMap==null){
// cacheMap = new HashMap<String, Object>();
// }
// return cacheMap;
// }
/**
* 获取SESSIONID
*/
public
String
getSessionid
()
{
try
{
return
(
String
)
UserUtils
.
getSession
().
getId
();
}
catch
(
Exception
e
)
{
return
""
;
}
}
@Override
public
String
toString
()
{
return
id
;
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/security/UsernamePasswordToken.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.security
;
/**
* 用户和密码(包含验证码)令牌类
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-19
*/
public
class
UsernamePasswordToken
extends
org
.
apache
.
shiro
.
authc
.
UsernamePasswordToken
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
captcha
;
private
boolean
mobileLogin
;
public
UsernamePasswordToken
()
{
super
();
}
public
UsernamePasswordToken
(
String
username
,
char
[]
password
,
boolean
rememberMe
,
String
host
,
String
captcha
,
boolean
mobileLogin
)
{
super
(
username
,
password
,
rememberMe
,
host
);
this
.
captcha
=
captcha
;
this
.
mobileLogin
=
mobileLogin
;
}
public
String
getCaptcha
()
{
return
captcha
;
}
public
void
setCaptcha
(
String
captcha
)
{
this
.
captcha
=
captcha
;
}
public
boolean
isMobileLogin
()
{
return
mobileLogin
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/AreaService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.service.TreeService
;
import
com.jeespring.modules.sys.dao.AreaDao
;
import
com.jeespring.modules.sys.entity.Area
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 区域Service
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
AreaService
extends
TreeService
<
AreaDao
,
Area
>
{
public
List
<
Area
>
findAll
(){
return
UserUtils
.
getAreaList
();
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
Area
area
)
{
super
.
save
(
area
);
UserUtils
.
removeCache
(
UserUtils
.
CACHE_AREA_LIST
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Area
area
)
{
super
.
delete
(
area
);
UserUtils
.
removeCache
(
UserUtils
.
CACHE_AREA_LIST
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/DictService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.sys.dao.DictDao
;
import
com.jeespring.modules.sys.entity.Dict
;
import
com.jeespring.modules.sys.utils.DictUtils
;
/**
* 字典Service
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
DictService
extends
AbstractBaseService
<
DictDao
,
Dict
>
{
/**
* 查询字段类型列表
* @return
*/
public
List
<
String
>
findTypeList
(){
return
dao
.
findTypeList
(
new
Dict
());
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
Dict
dict
)
{
super
.
save
(
dict
);
CacheUtils
.
remove
(
DictUtils
.
CACHE_DICT_MAP
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Dict
dict
)
{
super
.
delete
(
dict
);
CacheUtils
.
remove
(
DictUtils
.
CACHE_DICT_MAP
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/LogService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.modules.sys.dao.LogDao
;
import
com.jeespring.modules.sys.entity.Log
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.common.utils.DateUtils
;
/**
* 日志Service
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
LogService
extends
AbstractBaseService
<
LogDao
,
Log
>
{
@Autowired
private
LogDao
logDao
;
public
Page
<
Log
>
findPage
(
Page
<
Log
>
page
,
Log
log
)
{
// 设置默认时间范围,默认当前月
if
(
log
.
getBeginDate
()
==
null
){
log
.
setBeginDate
(
DateUtils
.
setDays
(
DateUtils
.
parseDate
(
DateUtils
.
getDate
()),
1
));
}
if
(
log
.
getEndDate
()
==
null
){
log
.
setEndDate
(
DateUtils
.
addMonths
(
log
.
getBeginDate
(),
1
));
}
return
super
.
findPage
(
page
,
log
);
}
/**
* 删除全部数据
* @param entity
*/
@Transactional
(
readOnly
=
false
)
public
void
empty
(){
logDao
.
empty
();
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/OfficeService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.service.TreeService
;
import
com.jeespring.modules.sys.dao.OfficeDao
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 机构Service
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
OfficeService
extends
TreeService
<
OfficeDao
,
Office
>
{
public
List
<
Office
>
findAll
(){
return
UserUtils
.
getOfficeList
();
}
public
List
<
Office
>
findList
(
Boolean
isAll
){
if
(
isAll
!=
null
&&
isAll
){
return
UserUtils
.
getOfficeAllList
();
}
else
{
return
UserUtils
.
getOfficeList
();
}
}
@Transactional
(
readOnly
=
true
)
public
List
<
Office
>
findList
(
Office
office
){
office
.
setParentIds
(
office
.
getParentIds
()+
"%"
);
return
dao
.
findByParentIdsLike
(
office
);
}
@Transactional
(
readOnly
=
true
)
public
Office
getByCode
(
String
code
){
return
dao
.
getByCode
(
code
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
Office
office
)
{
super
.
save
(
office
);
UserUtils
.
removeCache
(
UserUtils
.
CACHE_OFFICE_LIST
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
Office
office
)
{
super
.
delete
(
office
);
UserUtils
.
removeCache
(
UserUtils
.
CACHE_OFFICE_LIST
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SysConfigService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
com.jeespring.common.config.Global
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.sys.entity.SysConfig
;
import
com.jeespring.modules.sys.dao.SysConfigDao
;
import
com.alibaba.fastjson.JSON
;
import
com.jeespring.common.redis.RedisUtils
;
/**
* 系统配置Service
* @author 黄炳桂 516821420@qq.com
* @version 2017-11-17
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysConfigService
extends
AbstractBaseService
<
SysConfigDao
,
SysConfig
>
{
/**
* redis caches
*/
@Autowired
private
RedisUtils
redisUtils
;
public
SysConfig
get
(
String
id
)
{
//获取缓存数据
SysConfig
sysConfig
=(
SysConfig
)
redisUtils
.
get
(
RedisUtils
.
getIdKey
(
SysConfigService
.
class
.
getName
(),
id
));
if
(
sysConfig
!=
null
)
return
sysConfig
;
//获取数据库数据
sysConfig
=
super
.
get
(
id
);
//设置缓存数据
redisUtils
.
set
(
RedisUtils
.
getIdKey
(
SysConfigService
.
class
.
getName
(),
id
),
sysConfig
);
return
sysConfig
;
}
public
SysConfig
findListFirst
(
SysConfig
sysConfig
)
{;
//获取数据库数据
List
<
SysConfig
>
sysConfigList
=
super
.
findList
(
sysConfig
);
if
(
sysConfigList
.
size
()>
0
)
sysConfig
=
sysConfigList
.
get
(
0
);
return
sysConfig
;
}
public
SysConfig
findListFirstCache
(
SysConfig
sysConfig
)
{
//获取缓存数据
String
findListFirstKey
=
RedisUtils
.
getFindListFirstKey
(
SysConfigService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysConfig
));
SysConfig
sysConfigRedis
=(
SysConfig
)
redisUtils
.
get
(
findListFirstKey
);
if
(
sysConfigRedis
!=
null
)
return
sysConfigRedis
;
//获取数据库数据
List
<
SysConfig
>
tfTicketList
=
super
.
findList
(
sysConfig
);
if
(
tfTicketList
.
size
()>
0
)
sysConfig
=
tfTicketList
.
get
(
0
);
else
sysConfig
=
new
SysConfig
();
//设置缓存数据
redisUtils
.
set
(
findListFirstKey
,
sysConfig
);
return
sysConfig
;
}
public
List
<
SysConfig
>
findList
(
SysConfig
sysConfig
)
{
//获取缓存数据
String
findListKey
=
RedisUtils
.
getFindListKey
(
SysConfigService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysConfig
));
List
<
SysConfig
>
sysConfigList
=(
List
<
SysConfig
>)
redisUtils
.
get
(
findListKey
);
if
(
sysConfigList
!=
null
)
return
sysConfigList
;
//获取数据库数据
sysConfigList
=
super
.
findList
(
sysConfig
);
//设置缓存数据
redisUtils
.
set
(
findListKey
,
sysConfigList
);
return
sysConfigList
;
}
public
Page
<
SysConfig
>
findPage
(
Page
<
SysConfig
>
page
,
SysConfig
sysConfig
)
{
//获取缓存数据
String
findPageKey
=
RedisUtils
.
getFindPageKey
(
SysConfigService
.
class
.
getName
(),
JSON
.
toJSONString
(
page
)+
JSON
.
toJSONString
(
sysConfig
));
Page
<
SysConfig
>
pageReuslt
=(
Page
<
SysConfig
>)
redisUtils
.
get
(
findPageKey
);
if
(
pageReuslt
!=
null
)
return
pageReuslt
;
//获取数据库数据
pageReuslt
=
super
.
findPage
(
page
,
sysConfig
);
//设置缓存数据
redisUtils
.
set
(
findPageKey
,
pageReuslt
);
return
pageReuslt
;
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysConfig
sysConfig
)
{
//保存数据库记录
super
.
save
(
sysConfig
);
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysConfigService
.
class
.
getName
(),
sysConfig
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysConfigService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysConfigService
.
class
.
getName
()));
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysConfig
sysConfig
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysConfigService
.
class
.
getName
(),
sysConfig
.
getId
()));
//删除数据库记录
super
.
delete
(
sysConfig
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysConfigService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysConfigService
.
class
.
getName
()));
}
@Transactional
(
readOnly
=
false
)
public
void
deleteByLogic
(
SysConfig
sysConfig
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysConfigService
.
class
.
getName
(),
sysConfig
.
getId
()));
//逻辑删除数据库记录
super
.
deleteByLogic
(
sysConfig
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysConfigService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysConfigService
.
class
.
getName
()));
}
/**
* 是否是演示模式,演示模式下不能修改用户、角色、密码、菜单、授权
*/
public
Boolean
isDemoMode
()
{
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"demoMode"
);
sysConfig
=
this
.
findListFirstCache
(
sysConfig
);
if
(
sysConfig
.
getValue
().
equals
(
"true"
)
&&
Global
.
isDemoMode
())
return
true
;
return
false
;
}
public
String
isDemoModeDescription
()
{
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"demoMode"
);
sysConfig
=
this
.
findListFirstCache
(
sysConfig
);
if
(
sysConfig
==
null
)
return
Global
.
isDemoModeDescription
();
return
sysConfig
.
getDescription
();
}
public
String
systemMode
(){
if
(
this
.
isDemoMode
())
return
"演示版"
;
return
"正式版"
;
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SysConfigTreeService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.service.TreeService
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.sys.entity.SysConfigTree
;
import
com.jeespring.modules.sys.dao.SysConfigTreeDao
;
/**
* 系统配置Service
* @author JeeSpring
* @version 2018-08-22
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysConfigTreeService
extends
TreeService
<
SysConfigTreeDao
,
SysConfigTree
>
{
public
SysConfigTree
get
(
String
id
)
{
return
super
.
get
(
id
);
}
public
List
<
SysConfigTree
>
findList
(
SysConfigTree
sysConfig
)
{
if
(
StringUtils
.
isNotBlank
(
sysConfig
.
getParentIds
())){
sysConfig
.
setParentIds
(
","
+
sysConfig
.
getParentIds
()+
","
);
}
return
super
.
findList
(
sysConfig
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysConfigTree
sysConfig
)
{
super
.
save
(
sysConfig
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysConfigTree
sysConfig
)
{
super
.
delete
(
sysConfig
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SysDictTreeService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.service.TreeService
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.sys.entity.SysDictTree
;
import
com.jeespring.modules.sys.dao.SysDictTreeDao
;
/**
* 数据字典Service
* @author JeeSpring
* @version 2018-08-22
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysDictTreeService
extends
TreeService
<
SysDictTreeDao
,
SysDictTree
>
{
public
SysDictTree
get
(
String
id
)
{
return
super
.
get
(
id
);
}
public
List
<
SysDictTree
>
findList
(
SysDictTree
sysDict
)
{
if
(
StringUtils
.
isNotBlank
(
sysDict
.
getParentIds
())){
sysDict
.
setParentIds
(
","
+
sysDict
.
getParentIds
()+
","
);
}
return
super
.
findList
(
sysDict
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysDictTree
sysDict
)
{
super
.
save
(
sysDict
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysDictTree
sysDict
)
{
super
.
delete
(
sysDict
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SysUserOnlineService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.Date
;
import
java.util.List
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.monitor.entity.OnlineSession
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.utils.UserUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.sys.entity.SysUserOnline
;
import
com.jeespring.modules.sys.dao.SysUserOnlineDao
;
import
com.alibaba.fastjson.JSON
;
import
com.jeespring.common.redis.RedisUtils
;
import
com.jeespring.common.security.MD5Tools
;
/**
* 在线用户记录Service
* @author JeeSpring
* @version 2018-08-16
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SysUserOnlineService
extends
AbstractBaseService
<
SysUserOnlineDao
,
SysUserOnline
>
{
/**
* redis caches
*/
@Autowired
private
RedisUtils
redisUtils
;
@Value
(
"${spring.redis.run}"
)
String
redisRun
;
/**
* 同步session到数据库的周期 单位为毫秒(默认1分钟)
*/
@Value
(
"${shiro.session.dbSyncPeriod}"
)
private
int
dbSyncPeriod
=
1
;
/**
* 上次同步数据库的时间戳
*/
private
static
final
String
LAST_SYNC_DB_TIMESTAMP
=
SysUserOnlineService
.
class
.
getName
()
+
"LAST_SYNC_DB_TIMESTAMP"
;
public
SysUserOnline
get
(
String
id
)
{
//获取数据库数据
SysUserOnline
sysUserOnline
=
super
.
get
(
id
);
return
sysUserOnline
;
}
public
SysUserOnline
getCache
(
String
id
)
{
//获取缓存数据
SysUserOnline
sysUserOnline
=(
SysUserOnline
)
redisUtils
.
get
(
RedisUtils
.
getIdKey
(
SysUserOnlineService
.
class
.
getName
(),
id
));
if
(
sysUserOnline
!=
null
)
return
sysUserOnline
;
//获取数据库数据
sysUserOnline
=
super
.
get
(
id
);
//设置缓存数据
redisUtils
.
set
(
RedisUtils
.
getIdKey
(
SysUserOnlineService
.
class
.
getName
(),
id
),
sysUserOnline
);
return
sysUserOnline
;
}
public
List
<
SysUserOnline
>
total
(
SysUserOnline
sysUserOnline
)
{
//获取数据库数据
List
<
SysUserOnline
>
sysUserOnlineList
=
super
.
total
(
sysUserOnline
);
return
sysUserOnlineList
;
}
public
List
<
SysUserOnline
>
totalCache
(
SysUserOnline
sysUserOnline
)
{
//获取缓存数据
String
totalKey
=
RedisUtils
.
getTotalKey
(
SysUserOnlineService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysUserOnline
));
List
<
SysUserOnline
>
sysUserOnlineList
=(
List
<
SysUserOnline
>)
redisUtils
.
get
(
totalKey
);
if
(
sysUserOnlineList
!=
null
)
return
sysUserOnlineList
;
//获取数据库数据
sysUserOnlineList
=
super
.
total
(
sysUserOnline
);
//设置缓存数据
redisUtils
.
set
(
totalKey
,
sysUserOnlineList
);
return
sysUserOnlineList
;
}
public
List
<
SysUserOnline
>
findList
(
SysUserOnline
sysUserOnline
)
{
//获取数据库数据
List
<
SysUserOnline
>
sysUserOnlineList
=
super
.
findList
(
sysUserOnline
);
//设置缓存数据
return
sysUserOnlineList
;
}
public
List
<
SysUserOnline
>
findListCache
(
SysUserOnline
sysUserOnline
)
{
//获取缓存数据
String
findListKey
=
RedisUtils
.
getFindListKey
(
SysUserOnlineService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysUserOnline
));
List
<
SysUserOnline
>
sysUserOnlineList
=(
List
<
SysUserOnline
>)
redisUtils
.
get
(
findListKey
);
if
(
sysUserOnlineList
!=
null
)
return
sysUserOnlineList
;
//获取数据库数据
sysUserOnlineList
=
super
.
findList
(
sysUserOnline
);
//设置缓存数据
redisUtils
.
set
(
findListKey
,
sysUserOnlineList
);
return
sysUserOnlineList
;
}
public
SysUserOnline
findListFirst
(
SysUserOnline
sysUserOnline
)
{;
//获取数据库数据
List
<
SysUserOnline
>
sysUserOnlineList
=
super
.
findList
(
sysUserOnline
);
if
(
sysUserOnlineList
.
size
()>
0
)
sysUserOnline
=
sysUserOnlineList
.
get
(
0
);
return
sysUserOnline
;
}
public
SysUserOnline
findListFirstCache
(
SysUserOnline
sysUserOnline
)
{
//获取缓存数据
String
findListFirstKey
=
RedisUtils
.
getFindListFirstKey
(
SysUserOnlineService
.
class
.
getName
(),
JSON
.
toJSONString
(
sysUserOnline
));
SysUserOnline
sysUserOnlineRedis
=(
SysUserOnline
)
redisUtils
.
get
(
findListFirstKey
);
if
(
sysUserOnlineRedis
!=
null
)
return
sysUserOnlineRedis
;
//获取数据库数据
List
<
SysUserOnline
>
sysUserOnlineList
=
super
.
findList
(
sysUserOnline
);
if
(
sysUserOnlineList
.
size
()>
0
)
sysUserOnline
=
sysUserOnlineList
.
get
(
0
);
else
sysUserOnline
=
new
SysUserOnline
();
//设置缓存数据
redisUtils
.
set
(
findListFirstKey
,
sysUserOnline
);
return
sysUserOnline
;
}
public
Page
<
SysUserOnline
>
findPage
(
Page
<
SysUserOnline
>
page
,
SysUserOnline
sysUserOnline
)
{
//获取数据库数据
Page
<
SysUserOnline
>
pageReuslt
=
super
.
findPage
(
page
,
sysUserOnline
);
return
pageReuslt
;
}
@Transactional
(
readOnly
=
false
)
public
Page
<
SysUserOnline
>
findPageCache
(
Page
<
SysUserOnline
>
page
,
SysUserOnline
sysUserOnline
)
{
//获取缓存数据
String
findPageKey
=
RedisUtils
.
getFindPageKey
(
SysUserOnlineService
.
class
.
getName
(),
JSON
.
toJSONString
(
page
)+
JSON
.
toJSONString
(
sysUserOnline
));
Page
<
SysUserOnline
>
pageReuslt
=(
Page
<
SysUserOnline
>)
redisUtils
.
get
(
findPageKey
);
if
(
pageReuslt
!=
null
)
return
pageReuslt
;
//获取数据库数据
pageReuslt
=
super
.
findPage
(
page
,
sysUserOnline
);
for
(
SysUserOnline
item:
pageReuslt
.
getList
())
{
if
(
redisRun
.
equals
(
"true"
)){
try
{
if
(!
redisUtils
.
exists
(
RedisUtils
.
SHIRO_REDIS
+
":"
+
item
.
getId
())){
item
.
setStatus
(
OnlineSession
.
OnlineStatus
.
off_line
.
toString
());
super
.
save
(
item
);
}
}
catch
(
Exception
e
){}
}
}
//设置缓存数据
redisUtils
.
set
(
findPageKey
,
pageReuslt
);
return
pageReuslt
;
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
SysUserOnline
sysUserOnline
)
{
//保存数据库记录
super
.
save
(
sysUserOnline
);
//设置清除缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysUserOnlineService
.
class
.
getName
(),
sysUserOnline
.
getId
()));
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SysUserOnline
sysUserOnline
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysUserOnlineService
.
class
.
getName
(),
sysUserOnline
.
getId
()));
//删除数据库记录
super
.
delete
(
sysUserOnline
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
}
@Transactional
(
readOnly
=
false
)
public
void
deleteByLogic
(
SysUserOnline
sysUserOnline
)
{
//清除记录缓存数据
redisUtils
.
remove
(
RedisUtils
.
getIdKey
(
SysUserOnlineService
.
class
.
getName
(),
sysUserOnline
.
getId
()));
//逻辑删除数据库记录
super
.
deleteByLogic
(
sysUserOnline
);
//清除列表和页面缓存数据
redisUtils
.
removePattern
(
RedisUtils
.
getFindListKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
redisUtils
.
removePattern
(
RedisUtils
.
getFinPageKeyPattern
(
SysUserOnlineService
.
class
.
getName
()));
}
/**
* 更新会话;如更新会话最后访问时间/停止会话/设置超时时间/设置移除属性等会调用
*/
@Transactional
(
readOnly
=
false
)
public
void
syncToDb
(
OnlineSession
onlineSession
)
{
Date
lastSyncTimestamp
=
(
Date
)
onlineSession
.
getAttribute
(
LAST_SYNC_DB_TIMESTAMP
);
if
(
lastSyncTimestamp
!=
null
)
{
boolean
needSync
=
true
;
long
deltaTime
=
onlineSession
.
getLastAccessTime
().
getTime
()
-
lastSyncTimestamp
.
getTime
();
if
(
deltaTime
<
dbSyncPeriod
*
60
*
1000
)
{
// 时间差不足 无需同步
needSync
=
false
;
}
boolean
isGuest
=
onlineSession
.
getUserId
()
==
null
||
onlineSession
.
getUserId
()
==
""
;
// session 数据变更了 同步
if
(
isGuest
==
false
&&
onlineSession
.
isAttributeChanged
())
{
needSync
=
true
;
}
if
(
needSync
==
false
)
{
return
;
}
}
onlineSession
.
setAttribute
(
LAST_SYNC_DB_TIMESTAMP
,
onlineSession
.
getLastAccessTime
());
// 更新完后 重置标识
if
(
onlineSession
.
isAttributeChanged
())
{
onlineSession
.
resetAttributeChanged
();
}
try
{
SysUserOnline
sysUserOnline
=
SysUserOnline
.
fromOnlineSession
(
onlineSession
);
SysUserOnline
sysUserOnlineDb
=
this
.
get
(
sysUserOnline
.
getId
());
if
(
sysUserOnlineDb
==
null
){
sysUserOnline
.
setIsNewRecord
(
true
);
}
else
{
sysUserOnline
.
setStartTimestsamp
(
sysUserOnlineDb
.
getStartTimestsamp
());
}
if
(
StringUtils
.
isEmpty
(
sysUserOnline
.
getDeptName
())){
User
user
=
UserUtils
.
getByLoginName
(
sysUserOnline
.
getLoginName
());
if
(
user
.
getCompany
()!=
null
&&
user
.
getOffice
()!=
null
)
sysUserOnline
.
setDeptName
(
user
.
getCompany
().
getName
()+
"-"
+
user
.
getOffice
().
getName
());
else
if
(
user
.
getCompany
()!=
null
)
sysUserOnline
.
setDeptName
(
user
.
getCompany
().
getName
());
else
if
(
user
.
getOffice
()!=
null
)
sysUserOnline
.
setDeptName
(
user
.
getOffice
().
getName
());
}
this
.
save
(
sysUserOnline
);
}
catch
(
Exception
e
){
//System.out.println(e.getMessage());
}
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SystemConfigService.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2015-2020 <a href="http://www.jeespring.org/">JeeSpring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.service
;
import
java.util.List
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.service.AbstractBaseService
;
import
com.jeespring.modules.sys.entity.SystemConfig
;
import
com.jeespring.modules.sys.dao.SystemConfigDao
;
/**
* 系统配置Service
* @author liugf
* @version 2016-02-07
*/
@Service
@Transactional
(
readOnly
=
true
)
public
class
SystemConfigService
extends
AbstractBaseService
<
SystemConfigDao
,
SystemConfig
>
{
public
SystemConfig
get
(
String
id
)
{
return
super
.
get
(
id
);
}
public
List
<
SystemConfig
>
findList
(
SystemConfig
systemConfig
)
{
return
super
.
findList
(
systemConfig
);
}
public
Page
<
SystemConfig
>
findPage
(
Page
<
SystemConfig
>
page
,
SystemConfig
systemConfig
)
{
return
super
.
findPage
(
page
,
systemConfig
);
}
@Transactional
(
readOnly
=
false
)
public
void
save
(
SystemConfig
systemConfig
)
{
super
.
save
(
systemConfig
);
}
@Transactional
(
readOnly
=
false
)
public
void
delete
(
SystemConfig
systemConfig
)
{
super
.
delete
(
systemConfig
);
}
}
\ No newline at end of file
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/service/SystemService.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.service
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.List
;
import
org.apache.shiro.session.Session
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.Encodes
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.security.Digests
;
import
com.jeespring.common.security.shiro.session.SessionDAO
;
import
com.jeespring.common.service.AbstractService
;
import
com.jeespring.common.service.ServiceException
;
import
com.jeespring.modules.sys.dao.MenuDao
;
import
com.jeespring.modules.sys.dao.RoleDao
;
import
com.jeespring.modules.sys.dao.UserDao
;
import
com.jeespring.modules.sys.entity.Menu
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.entity.Role
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.security.SystemAuthorizingRealm
;
import
com.jeespring.modules.sys.utils.LogUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 系统管理,安全相关实体的管理类,包括用户、角色、菜单.
* @author 黄炳桂 516821420@qq.com
* @version 2013-12-05
*/
@org
.
springframework
.
stereotype
.
Service
@Transactional
(
readOnly
=
true
)
public
class
SystemService
extends
AbstractService
implements
InitializingBean
{
public
static
final
String
HASH_ALGORITHM
=
"SHA-1"
;
public
static
final
int
HASH_INTERATIONS
=
1024
;
public
static
final
int
SALT_SIZE
=
8
;
@Autowired
private
UserDao
userDao
;
@Autowired
private
RoleDao
roleDao
;
@Autowired
private
MenuDao
menuDao
;
@Autowired
private
SessionDAO
sessionDao
;
@Autowired
private
SystemAuthorizingRealm
systemRealm
;
public
SessionDAO
getSessionDao
()
{
return
sessionDao
;
}
//-- User Service --//
/**
* 获取用户
* @param id
* @return
*/
public
User
getUser
(
String
id
)
{
return
UserUtils
.
get
(
id
);
}
/**
* 根据登录名获取用户
* @param loginName
* @return
*/
public
User
getUserByLoginName
(
String
loginName
)
{
return
UserUtils
.
getByLoginName
(
loginName
);
}
public
Page
<
User
>
findUser
(
Page
<
User
>
page
,
User
user
)
{
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
user
.
getSqlMap
().
put
(
"dsf"
,
dataScopeFilter
(
user
.
getCurrentUser
(),
"o"
,
"a"
));
// 设置分页参数
user
.
setPage
(
page
);
// 执行分页查询
page
.
setList
(
userDao
.
findList
(
user
));
return
page
;
}
/**
* 无分页查询人员列表
* @param user
* @return
*/
public
List
<
User
>
findUser
(
User
user
){
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
user
.
getSqlMap
().
put
(
"dsf"
,
dataScopeFilter
(
user
.
getCurrentUser
(),
"o"
,
"a"
));
List
<
User
>
list
=
userDao
.
findList
(
user
);
return
list
;
}
/**
* 通过部门ID获取用户列表,仅返回用户id和name(树查询用户时用)
* @param user
* @return
*/
@SuppressWarnings
(
"unchecked"
)
public
List
<
User
>
findUserByOfficeId
(
String
officeId
)
{
List
<
User
>
list
=
(
List
<
User
>)
CacheUtils
.
get
(
UserUtils
.
USER_CACHE
,
UserUtils
.
USER_CACHE_LIST_BY_OFFICE_ID_
+
officeId
);
if
(
list
==
null
){
User
user
=
new
User
();
user
.
setOffice
(
new
Office
(
officeId
));
list
=
userDao
.
findUserByOfficeId
(
user
);
CacheUtils
.
put
(
UserUtils
.
USER_CACHE
,
UserUtils
.
USER_CACHE_LIST_BY_OFFICE_ID_
+
officeId
,
list
);
}
return
list
;
}
@Transactional
(
readOnly
=
false
)
public
void
saveUser
(
User
user
)
{
if
(
StringUtils
.
isBlank
(
user
.
getId
())){
user
.
preInsert
();
userDao
.
insert
(
user
);
}
else
{
// 清除原用户机构用户缓存
User
oldUser
=
userDao
.
get
(
user
.
getId
());
if
(
oldUser
.
getOffice
()
!=
null
&&
oldUser
.
getOffice
().
getId
()
!=
null
){
CacheUtils
.
remove
(
UserUtils
.
USER_CACHE
,
UserUtils
.
USER_CACHE_LIST_BY_OFFICE_ID_
+
oldUser
.
getOffice
().
getId
());
}
// 更新用户数据
user
.
preUpdate
();
userDao
.
update
(
user
);
}
if
(
StringUtils
.
isNotBlank
(
user
.
getId
())){
// 更新用户与角色关联
userDao
.
deleteUserRole
(
user
);
if
(
user
.
getRoleList
()
!=
null
&&
user
.
getRoleList
().
size
()
>
0
){
userDao
.
insertUserRole
(
user
);
}
else
{
throw
new
ServiceException
(
user
.
getLoginName
()
+
"没有设置角色!"
);
}
// 清除用户缓存
UserUtils
.
clearCache
(
user
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
}
@Transactional
(
readOnly
=
false
)
public
void
updateUserInfo
(
User
user
)
{
user
.
preUpdate
();
userDao
.
updateUserInfo
(
user
);
// 清除用户缓存
UserUtils
.
clearCache
(
user
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
@Transactional
(
readOnly
=
false
)
public
void
deleteUser
(
User
user
)
{
userDao
.
delete
(
user
);
// 清除用户缓存
UserUtils
.
clearCache
(
user
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
@Transactional
(
readOnly
=
false
)
public
void
updatePasswordById
(
String
id
,
String
loginName
,
String
newPassword
)
{
User
user
=
new
User
(
id
);
user
.
setPassword
(
entryptPassword
(
newPassword
));
userDao
.
updatePasswordById
(
user
);
// 清除用户缓存
user
.
setLoginName
(
loginName
);
UserUtils
.
clearCache
(
user
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
@Transactional
(
readOnly
=
false
)
public
void
updateUserLoginInfo
(
User
user
)
{
// 保存上次登录信息
user
.
setOldLoginIp
(
user
.
getLoginIp
());
user
.
setOldLoginDate
(
user
.
getLoginDate
());
// 更新本次登录信息
user
.
setLoginIp
(
UserUtils
.
getSession
().
getHost
());
user
.
setLoginDate
(
new
Date
());
userDao
.
updateLoginInfo
(
user
);
}
/**
* 生成安全的密码,生成随机的16位salt并经过1024次 sha-1 hash
*/
public
static
String
entryptPassword
(
String
plainPassword
)
{
byte
[]
salt
=
Digests
.
generateSalt
(
SALT_SIZE
);
byte
[]
hashPassword
=
Digests
.
sha1
(
plainPassword
.
getBytes
(),
salt
,
HASH_INTERATIONS
);
return
Encodes
.
encodeHex
(
salt
)+
Encodes
.
encodeHex
(
hashPassword
);
}
/**
* 验证密码
* @param plainPassword 明文密码
* @param password 密文密码
* @return 验证成功返回true
*/
public
static
boolean
validatePassword
(
String
plainPassword
,
String
password
)
{
byte
[]
salt
=
Encodes
.
decodeHex
(
password
.
substring
(
0
,
16
));
byte
[]
hashPassword
=
Digests
.
sha1
(
plainPassword
.
getBytes
(),
salt
,
HASH_INTERATIONS
);
return
password
.
equals
(
Encodes
.
encodeHex
(
salt
)+
Encodes
.
encodeHex
(
hashPassword
));
}
/**
* 获得活动会话
* @return
*/
public
Collection
<
Session
>
getActiveSessions
(){
return
sessionDao
.
getActiveSessions
(
false
);
}
//-- Role Service --//
public
Role
getRole
(
String
id
)
{
return
roleDao
.
get
(
id
);
}
public
Role
getRoleByName
(
String
name
)
{
Role
r
=
new
Role
();
r
.
setName
(
name
);
return
roleDao
.
getByName
(
r
);
}
public
Role
getRoleByEnname
(
String
enname
)
{
Role
r
=
new
Role
();
r
.
setEnname
(
enname
);
return
roleDao
.
getByEnname
(
r
);
}
public
List
<
Role
>
findRole
(
Role
role
){
return
roleDao
.
findList
(
role
);
}
public
List
<
Role
>
findAllRole
(){
return
UserUtils
.
getRoleList
();
}
@Transactional
(
readOnly
=
false
)
public
void
saveRole
(
Role
role
)
{
if
(
StringUtils
.
isBlank
(
role
.
getId
())){
role
.
preInsert
();
roleDao
.
insert
(
role
);
}
else
{
role
.
preUpdate
();
roleDao
.
update
(
role
);
}
// 更新角色与菜单关联
roleDao
.
deleteRoleMenu
(
role
);
if
(
role
.
getMenuList
().
size
()
>
0
){
roleDao
.
insertRoleMenu
(
role
);
}
// 更新角色与部门关联
roleDao
.
deleteRoleOffice
(
role
);
if
(
role
.
getOfficeList
().
size
()
>
0
){
roleDao
.
insertRoleOffice
(
role
);
}
// 清除用户角色缓存
UserUtils
.
removeCache
(
UserUtils
.
CACHE_ROLE_LIST
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
@Transactional
(
readOnly
=
false
)
public
void
deleteRole
(
Role
role
)
{
roleDao
.
delete
(
role
);
// 清除用户角色缓存
UserUtils
.
removeCache
(
UserUtils
.
CACHE_ROLE_LIST
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
}
@Transactional
(
readOnly
=
false
)
public
Boolean
outUserInRole
(
Role
role
,
User
user
)
{
List
<
Role
>
roles
=
user
.
getRoleList
();
for
(
Role
e
:
roles
){
if
(
e
.
getId
().
equals
(
role
.
getId
())){
roles
.
remove
(
e
);
saveUser
(
user
);
return
true
;
}
}
return
false
;
}
@Transactional
(
readOnly
=
false
)
public
User
assignUserToRole
(
Role
role
,
User
user
)
{
if
(
user
==
null
){
return
null
;
}
List
<
String
>
roleIds
=
user
.
getRoleIdList
();
if
(
roleIds
.
contains
(
role
.
getId
()))
{
return
null
;
}
user
.
getRoleList
().
add
(
role
);
saveUser
(
user
);
return
user
;
}
//-- Menu Service --//
public
Menu
getMenu
(
String
id
)
{
return
menuDao
.
get
(
id
);
}
public
List
<
Menu
>
findAllMenu
(){
return
UserUtils
.
getMenuList
();
}
@Transactional
(
readOnly
=
false
)
public
void
saveMenu
(
Menu
menu
)
{
// 获取父节点实体
menu
.
setParent
(
this
.
getMenu
(
menu
.
getParent
().
getId
()));
// 获取修改前的parentIds,用于更新子节点的parentIds
String
oldParentIds
=
menu
.
getParentIds
();
// 设置新的父节点串
menu
.
setParentIds
(
menu
.
getParent
().
getParentIds
()+
menu
.
getParent
().
getId
()+
","
);
// 保存或更新实体
if
(
StringUtils
.
isBlank
(
menu
.
getId
())){
menu
.
preInsert
();
menuDao
.
insert
(
menu
);
}
else
{
menu
.
preUpdate
();
menuDao
.
update
(
menu
);
}
// 更新子节点 parentIds
Menu
m
=
new
Menu
();
m
.
setParentIds
(
"%,"
+
menu
.
getId
()+
",%"
);
List
<
Menu
>
list
=
menuDao
.
findByParentIdsLike
(
m
);
for
(
Menu
e
:
list
){
e
.
setParentIds
(
e
.
getParentIds
().
replace
(
oldParentIds
,
menu
.
getParentIds
()));
menuDao
.
updateParentIds
(
e
);
}
// 清除用户菜单缓存
UserUtils
.
removeCache
(
UserUtils
.
CACHE_MENU_LIST
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
// 清除日志相关缓存
CacheUtils
.
remove
(
LogUtils
.
CACHE_MENU_NAME_PATH_MAP
);
}
@Transactional
(
readOnly
=
false
)
public
void
updateMenuSort
(
Menu
menu
)
{
menuDao
.
updateSort
(
menu
);
// 清除用户菜单缓存
UserUtils
.
removeCache
(
UserUtils
.
CACHE_MENU_LIST
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
// 清除日志相关缓存
CacheUtils
.
remove
(
LogUtils
.
CACHE_MENU_NAME_PATH_MAP
);
}
@Transactional
(
readOnly
=
false
)
public
void
deleteMenu
(
Menu
menu
)
{
menuDao
.
delete
(
menu
);
// 清除用户菜单缓存
UserUtils
.
removeCache
(
UserUtils
.
CACHE_MENU_LIST
);
// // 清除权限缓存
// systemRealm.clearAllCachedAuthorizationInfo();
// 清除日志相关缓存
CacheUtils
.
remove
(
LogUtils
.
CACHE_MENU_NAME_PATH_MAP
);
}
/**
* 获取Key加载信息
*/
public
static
boolean
printKeyLoadMessage
(){
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"\r\n======================================================================\r\n"
);
sb
.
append
(
"\r\n 欢迎使用 "
+
Global
.
getConfig
(
"productName"
)+
" - Powered By http://www.jeespring.org\r\n"
);
sb
.
append
(
"\r\n======================================================================\r\n"
);
System
.
out
.
println
(
sb
.
toString
());
return
true
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
// TODO Auto-generated method stub
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/utils/DictUtils.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.utils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.mapper.JsonMapper
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.modules.sys.dao.DictDao
;
import
com.jeespring.modules.sys.entity.Dict
;
/**
* 字典工具类
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-29
*/
public
class
DictUtils
{
private
static
DictDao
dictDao
=
SpringContextHolder
.
getBean
(
DictDao
.
class
);
public
static
final
String
CACHE_DICT_MAP
=
"dictMap"
;
public
static
String
getDictLabel
(
String
value
,
String
type
,
String
defaultValue
){
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
value
)){
for
(
Dict
dict
:
getDictList
(
type
)){
if
(
type
.
equals
(
dict
.
getType
())
&&
value
.
equals
(
dict
.
getValue
())){
return
dict
.
getLabel
();
}
}
}
return
defaultValue
;
}
public
static
String
getDictLabel
(
Long
value
,
String
type
,
String
defaultValue
){
if
(
value
==
null
)
return
""
;
return
getDictLabel
(
value
.
toString
(),
type
,
defaultValue
);
}
public
static
String
getDictPicture
(
String
value
,
String
type
,
String
defaultValue
){
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
value
)){
for
(
Dict
dict
:
getDictList
(
type
)){
if
(
type
.
equals
(
dict
.
getType
())
&&
value
.
equals
(
dict
.
getValue
())){
return
dict
.
getPicture
();
}
}
}
return
defaultValue
;
}
public
static
String
getDictPicture
(
Long
value
,
String
type
,
String
defaultValue
){
if
(
value
==
null
)
return
""
;
return
getDictPicture
(
value
.
toString
(),
type
,
defaultValue
);
}
public
static
String
getDictLabels
(
String
values
,
String
type
,
String
defaultValue
){
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
values
)){
List
<
String
>
valueList
=
Lists
.
newArrayList
();
for
(
String
value
:
StringUtils
.
split
(
values
,
","
)){
valueList
.
add
(
getDictLabel
(
value
,
type
,
defaultValue
));
}
return
StringUtils
.
join
(
valueList
,
","
);
}
return
defaultValue
;
}
public
static
String
getDictValue
(
String
label
,
String
type
,
String
defaultLabel
){
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
label
)){
for
(
Dict
dict
:
getDictList
(
type
)){
if
(
type
.
equals
(
dict
.
getType
())
&&
label
.
equals
(
dict
.
getLabel
())){
return
dict
.
getValue
();
}
}
}
return
defaultLabel
;
}
public
static
List
<
Dict
>
getDictList
(
String
type
){
@SuppressWarnings
(
"unchecked"
)
Map
<
String
,
List
<
Dict
>>
dictMap
=
(
Map
<
String
,
List
<
Dict
>>)
CacheUtils
.
get
(
CACHE_DICT_MAP
);
if
(
dictMap
==
null
){
dictMap
=
Maps
.
newHashMap
();
for
(
Dict
dict
:
dictDao
.
findAllList
(
new
Dict
())){
List
<
Dict
>
dictList
=
dictMap
.
get
(
dict
.
getType
());
if
(
dictList
!=
null
){
dictList
.
add
(
dict
);
}
else
{
dictMap
.
put
(
dict
.
getType
(),
Lists
.
newArrayList
(
dict
));
}
}
CacheUtils
.
put
(
CACHE_DICT_MAP
,
dictMap
);
}
List
<
Dict
>
dictList
=
dictMap
.
get
(
type
);
if
(
dictList
==
null
){
dictList
=
Lists
.
newArrayList
();
}
//if(dictList!=null && dictList.size()!=0 && "".equals(dictList.get(dictList.size()-1).getValue())){
// dictList.remove(dictList.size()-1);
//}
return
dictList
;
}
//增加全部项
public
static
List
<
Dict
>
getDictListAddAll
(
String
type
){
List
<
Dict
>
dictListResult
=
new
ArrayList
<
Dict
>();
List
<
Dict
>
dictList
=
getDictList
(
type
);
dictListResult
.
addAll
(
dictList
);
//if(dictList!=null && "".equals(dictList.get(dictList.size()-1).getValue())){
// return dictList;
//}
Dict
dict
=
new
Dict
();
dict
.
setValue
(
""
);
dict
.
setLabel
(
"全部"
);
dictListResult
.
add
(
dict
);
return
dictListResult
;
}
/**
* 返回字典列表(JSON)
* @param type
* @return
*/
public
static
String
getDictListJson
(
String
type
){
return
JsonMapper
.
toJsonString
(
getDictList
(
type
));
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/utils/LogUtils.java
0 → 100644
View file @
8b643e22
/**
* Copyright © 2012-2016 <a href="https://github.com/HuangBingGui/jeespring">jeespring</a> All rights reserved.
*/
package
com.jeespring.modules.sys.utils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.sys.entity.Log
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.interceptor.InterceptorLogEntity
;
import
com.jeespring.modules.sys.interceptor.LogThread
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.util.Date
;
import
java.util.Map
;
/**
* 字典工具类
*
* @author 黄炳桂 516821420@qq.com
* @version 2014-11-7
*/
public
class
LogUtils
{
public
static
final
String
CACHE_MENU_NAME_PATH_MAP
=
"menuNamePathMap"
;
/**
* 保存日志
*/
public
static
void
saveLog
(
HttpServletRequest
request
,
String
title
)
{
saveLog
(
request
,
null
,
null
,
title
);
}
/**
* 保存日志
*/
public
static
void
saveLog
(
HttpServletRequest
request
,
Object
handler
,
Exception
ex
,
String
title
)
{
User
user
=
UserUtils
.
getUser
();
if
(
user
!=
null
&&
user
.
getId
()
!=
null
)
{
Log
log
=
new
Log
();
log
.
setTitle
(
title
);
log
.
setType
(
ex
==
null
?
Log
.
TYPE_ACCESS
:
Log
.
TYPE_EXCEPTION
);
log
.
setRemoteAddr
(
StringUtils
.
getRemoteAddr
(
request
));
log
.
setUserAgent
(
request
.
getHeader
(
"user-agent"
));
log
.
setRequestUri
(
request
.
getRequestURI
());
log
.
setParams
(
getParameterString
(
request
));
log
.
setMethod
(
request
.
getMethod
());
log
.
setCreateBy
(
user
);
log
.
setUpdateBy
(
user
);
log
.
setUpdateDate
(
new
Date
());
log
.
setCreateDate
(
new
Date
());
// 异步保存日志
try
{
InterceptorLogEntity
entiry
=
new
InterceptorLogEntity
(
log
,
handler
,
ex
);
LogThread
.
interceptorLogQueue
.
put
(
entiry
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
System
.
out
);
}
}
}
public
static
String
getParameterString
(
HttpServletRequest
request
){
if
(
request
.
getQueryString
()!=
null
){
if
(
request
.
getQueryString
().
length
()>
0
){
return
request
.
getQueryString
();
}
}
Map
map
=
request
.
getParameterMap
();
java
.
util
.
Enumeration
enumx
=
request
.
getParameterNames
();
String
result
=
""
;
while
(
enumx
.
hasMoreElements
()){
String
paramName
=(
String
)
enumx
.
nextElement
();
String
[]
values
=
request
.
getParameterValues
(
paramName
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++){
result
+=
paramName
+
"="
+
values
[
i
]+
"&"
;
}
}
if
(
result
==
""
)
{
try
{
BufferedReader
br
=
request
.
getReader
();
String
str
=
""
;
while
((
str
=
br
.
readLine
())
!=
null
)
{
result
+=
str
;
}
}
catch
(
Exception
e
){}
}
return
result
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/utils/UserUtils.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.utils
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
com.jeespring.common.sms.SMSUtils
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.UnavailableSecurityManagerException
;
import
org.apache.shiro.session.InvalidSessionException
;
import
org.apache.shiro.session.Session
;
import
org.apache.shiro.subject.Subject
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.SpringContextHolder
;
import
com.jeespring.common.service.AbstractService
;
import
com.jeespring.modules.sys.dao.AreaDao
;
import
com.jeespring.modules.sys.dao.MenuDao
;
import
com.jeespring.modules.sys.dao.OfficeDao
;
import
com.jeespring.modules.sys.dao.RoleDao
;
import
com.jeespring.modules.sys.dao.UserDao
;
import
com.jeespring.modules.sys.entity.Area
;
import
com.jeespring.modules.sys.entity.Menu
;
import
com.jeespring.modules.sys.entity.Office
;
import
com.jeespring.modules.sys.entity.Role
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.security.SystemAuthorizingRealm.Principal
;
/**
* 用户工具类
* @author 黄炳桂 516821420@qq.com
* @version 2013-12-05
*/
public
class
UserUtils
{
private
static
UserDao
userDao
=
SpringContextHolder
.
getBean
(
UserDao
.
class
);
private
static
RoleDao
roleDao
=
SpringContextHolder
.
getBean
(
RoleDao
.
class
);
private
static
MenuDao
menuDao
=
SpringContextHolder
.
getBean
(
MenuDao
.
class
);
private
static
AreaDao
areaDao
=
SpringContextHolder
.
getBean
(
AreaDao
.
class
);
private
static
OfficeDao
officeDao
=
SpringContextHolder
.
getBean
(
OfficeDao
.
class
);
public
static
final
String
USER_CACHE
=
"userCache"
;
public
static
final
String
USER_CACHE_ID_
=
"id_"
;
public
static
final
String
USER_CACHE_LOGIN_NAME_
=
"ln"
;
public
static
final
String
USER_CACHE_LIST_BY_OFFICE_ID_
=
"oid_"
;
public
static
final
String
CACHE_ROLE_LIST
=
"roleList"
;
public
static
final
String
CACHE_MENU_LIST
=
"menuList"
;
public
static
final
String
CACHE_AREA_LIST
=
"areaList"
;
public
static
final
String
CACHE_OFFICE_LIST
=
"officeList"
;
public
static
final
String
CACHE_OFFICE_ALL_LIST
=
"officeAllList"
;
/**
* 根据ID获取用户
* @param id
* @return 取不到返回null
*/
public
static
User
get
(
String
id
){
User
user
=
(
User
)
CacheUtils
.
get
(
USER_CACHE
,
USER_CACHE_ID_
+
id
);
if
(
user
==
null
){
user
=
userDao
.
get
(
id
);
if
(
user
==
null
){
return
null
;
}
user
.
setRoleList
(
roleDao
.
findList
(
new
Role
(
user
)));
CacheUtils
.
put
(
USER_CACHE
,
USER_CACHE_ID_
+
user
.
getId
(),
user
);
CacheUtils
.
put
(
USER_CACHE
,
USER_CACHE_LOGIN_NAME_
+
user
.
getLoginName
(),
user
);
}
return
user
;
}
/**
* 根据登录名获取用户
* @param loginName
* @return 取不到返回null
*/
public
static
User
getByLoginName
(
String
loginName
){
User
user
=
(
User
)
CacheUtils
.
get
(
USER_CACHE
,
USER_CACHE_LOGIN_NAME_
+
loginName
);
if
(
user
==
null
){
user
=
userDao
.
getByLoginName
(
new
User
(
null
,
loginName
));
if
(
user
==
null
){
return
null
;
}
user
.
setRoleList
(
roleDao
.
findList
(
new
Role
(
user
)));
CacheUtils
.
put
(
USER_CACHE
,
USER_CACHE_ID_
+
user
.
getId
(),
user
);
CacheUtils
.
put
(
USER_CACHE
,
USER_CACHE_LOGIN_NAME_
+
user
.
getLoginName
(),
user
);
}
return
user
;
}
/**
* 清除当前用户缓存
*/
public
static
void
clearCache
(){
removeCache
(
CACHE_ROLE_LIST
);
removeCache
(
CACHE_MENU_LIST
);
removeCache
(
CACHE_AREA_LIST
);
removeCache
(
CACHE_OFFICE_LIST
);
removeCache
(
CACHE_OFFICE_ALL_LIST
);
UserUtils
.
clearCache
(
getUser
());
}
/**
* 清除指定用户缓存
* @param user
*/
public
static
void
clearCache
(
User
user
){
CacheUtils
.
remove
(
USER_CACHE
,
USER_CACHE_ID_
+
user
.
getId
());
CacheUtils
.
remove
(
USER_CACHE
,
USER_CACHE_LOGIN_NAME_
+
user
.
getLoginName
());
CacheUtils
.
remove
(
USER_CACHE
,
USER_CACHE_LOGIN_NAME_
+
user
.
getOldLoginName
());
if
(
user
.
getOffice
()
!=
null
&&
user
.
getOffice
().
getId
()
!=
null
){
CacheUtils
.
remove
(
USER_CACHE
,
USER_CACHE_LIST_BY_OFFICE_ID_
+
user
.
getOffice
().
getId
());
}
}
/**
* 获取当前用户
* @return 取不到返回 new User()
*/
public
static
User
getUser
(){
Principal
principal
=
getPrincipal
();
if
(
principal
!=
null
){
User
user
=
get
(
principal
.
getId
());
if
(
user
!=
null
){
return
user
;
}
return
new
User
();
}
// 如果没有登录,则返回实例化空的User对象。
return
new
User
();
}
/**
* 获取当前用户角色列表
* @return
*/
public
static
List
<
Role
>
getRoleList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Role
>
roleList
=
(
List
<
Role
>)
getCache
(
CACHE_ROLE_LIST
);
if
(
roleList
==
null
){
User
user
=
getUser
();
if
(
user
.
isAdmin
()){
roleList
=
roleDao
.
findAllList
(
new
Role
());
}
else
{
Role
role
=
new
Role
();
role
.
getSqlMap
().
put
(
"dsf"
,
AbstractService
.
dataScopeFilter
(
user
.
getCurrentUser
(),
"o"
,
"u"
));
roleList
=
roleDao
.
findList
(
role
);
}
putCache
(
CACHE_ROLE_LIST
,
roleList
);
}
return
roleList
;
}
/**
* 获取当前用户授权菜单
* @return
*/
public
static
List
<
Menu
>
getMenuList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Menu
>
menuList
=
(
List
<
Menu
>)
getCache
(
CACHE_MENU_LIST
);
if
(
menuList
==
null
){
User
user
=
getUser
();
if
(
user
.
isAdmin
()){
menuList
=
menuDao
.
findAllList
(
new
Menu
());
}
else
{
Menu
m
=
new
Menu
();
m
.
setUserId
(
user
.
getId
());
menuList
=
menuDao
.
findByUserId
(
m
);
}
putCache
(
CACHE_MENU_LIST
,
menuList
);
}
return
menuList
;
}
/**
* 获取当前用户授权菜单
* @return
*/
public
static
Menu
getTopMenu
(){
@SuppressWarnings
(
"unchecked"
)
Menu
topMenu
=
menuDao
.
findUniqueByProperty
(
"parent_id"
,
"'0'"
);
return
topMenu
;
}
/**
* 获取当前用户授权的区域
* @return
*/
public
static
List
<
Area
>
getAreaList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Area
>
areaList
=
(
List
<
Area
>)
getCache
(
CACHE_AREA_LIST
);
if
(
areaList
==
null
){
areaList
=
areaDao
.
findAllList
(
new
Area
());
putCache
(
CACHE_AREA_LIST
,
areaList
);
}
return
areaList
;
}
/**
* 获取当前用户有权限访问的部门
* @return
*/
public
static
List
<
Office
>
getOfficeList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Office
>
officeList
=
(
List
<
Office
>)
getCache
(
CACHE_OFFICE_LIST
);
if
(
officeList
==
null
){
User
user
=
getUser
();
if
(
user
.
isAdmin
()){
officeList
=
officeDao
.
findAllList
(
new
Office
());
}
else
{
Office
office
=
new
Office
();
office
.
getSqlMap
().
put
(
"dsf"
,
AbstractService
.
dataScopeFilter
(
user
,
"a"
,
""
));
officeList
=
officeDao
.
findList
(
office
);
}
putCache
(
CACHE_OFFICE_LIST
,
officeList
);
}
return
officeList
;
}
/**
* 获取当前用户有权限访问的部门
* @return
*/
public
static
List
<
Office
>
getOfficeAllList
(){
@SuppressWarnings
(
"unchecked"
)
List
<
Office
>
officeList
=
(
List
<
Office
>)
getCache
(
CACHE_OFFICE_ALL_LIST
);
if
(
officeList
==
null
){
officeList
=
officeDao
.
findAllList
(
new
Office
());
}
return
officeList
;
}
/**
* 获取授权主要对象
*/
public
static
Subject
getSubject
(){
return
SecurityUtils
.
getSubject
();
}
/**
* 获取当前登录者对象
*/
public
static
Principal
getPrincipal
(){
try
{
Subject
subject
=
SecurityUtils
.
getSubject
();
Principal
principal
=
(
Principal
)
subject
.
getPrincipal
();
if
(
principal
!=
null
){
return
principal
;
}
// subject.logout();
}
catch
(
UnavailableSecurityManagerException
e
)
{
}
catch
(
InvalidSessionException
e
){
}
return
null
;
}
public
static
Session
getSession
(){
try
{
Subject
subject
=
SecurityUtils
.
getSubject
();
Session
session
=
subject
.
getSession
(
false
);
if
(
session
==
null
){
session
=
subject
.
getSession
();
}
if
(
session
!=
null
){
return
session
;
}
// subject.logout();
}
catch
(
InvalidSessionException
e
){
}
return
null
;
}
// ============== User Cache ==============
public
static
Object
getCache
(
String
key
)
{
return
getCache
(
key
,
null
);
}
public
static
Object
getCache
(
String
key
,
Object
defaultValue
)
{
// Object obj = getCacheMap().get(key);
Object
obj
=
getSession
().
getAttribute
(
key
);
return
obj
==
null
?
defaultValue:
obj
;
}
public
static
void
putCache
(
String
key
,
Object
value
)
{
// getCacheMap().put(key, value);
getSession
().
setAttribute
(
key
,
value
);
}
public
static
void
removeCache
(
String
key
)
{
// getCacheMap().remove(key);
getSession
().
removeAttribute
(
key
);
}
public
static
String
getTime
(
Date
date
){
StringBuffer
time
=
new
StringBuffer
();
Date
date2
=
new
Date
();
long
temp
=
date2
.
getTime
()
-
date
.
getTime
();
long
days
=
temp
/
1000
/
3600
/
24
;
//相差小时数
if
(
days
>
0
){
time
.
append
(
days
+
"天"
);
}
long
temp1
=
temp
%
(
1000
*
3600
*
24
);
long
hours
=
temp1
/
1000
/
3600
;
//相差小时数
if
(
days
>
0
||
hours
>
0
){
time
.
append
(
hours
+
"小时"
);
}
long
temp2
=
temp1
%
(
1000
*
3600
);
long
mins
=
temp2
/
1000
/
60
;
//相差分钟数
time
.
append
(
mins
+
"分钟"
);
return
time
.
toString
();
}
// public static Map<String, Object> getCacheMap(){
// Principal principal = getPrincipal();
// if(principal!=null){
// return principal.getCacheMap();
// }
// return new HashMap<String, Object>();
// }
//发送注册码
public
static
String
sendRandomCode
(
String
uid
,
String
pwd
,
String
tel
,
String
randomCode
)
throws
IOException
{
//发送内容
String
content
=
"您的验证码是:"
+
randomCode
+
",有效期30分钟,请在有效期内使用。"
;
try
{
return
SMSUtils
.
send
(
uid
,
pwd
,
tel
,
content
);
}
catch
(
Exception
e
){
return
""
;
}
}
//注册用户重置密码
public
static
String
sendPass
(
String
uid
,
String
pwd
,
String
tel
,
String
password
)
throws
IOException
{
//发送内容
String
content
=
"您的新密码是:"
+
password
+
",请登录系统,重新设置密码。"
;
try
{
return
SMSUtils
.
send
(
uid
,
pwd
,
tel
,
content
);
}
catch
(
Exception
e
){
return
""
;
}
}
/**
* 导出Excel调用,根据姓名转换为ID
*/
public
static
User
getByUserName
(
String
name
){
User
u
=
new
User
();
u
.
setName
(
name
);
List
<
User
>
list
=
userDao
.
findList
(
u
);
if
(
list
.
size
()>
0
){
return
list
.
get
(
0
);
}
else
{
return
new
User
();
}
}
/**
* 导出Excel使用,根据名字转换为id
*/
public
static
Office
getByOfficeName
(
String
name
){
Office
o
=
new
Office
();
o
.
setName
(
name
);
List
<
Office
>
list
=
officeDao
.
findList
(
o
);
if
(
list
.
size
()>
0
){
return
list
.
get
(
0
);
}
else
{
return
new
Office
();
}
}
/**
* 导出Excel使用,根据名字转换为id
*/
public
static
Area
getByAreaName
(
String
name
){
Area
a
=
new
Area
();
a
.
setName
(
name
);
List
<
Area
>
list
=
areaDao
.
findList
(
a
);
if
(
list
.
size
()>
0
){
return
list
.
get
(
0
);
}
else
{
return
new
Area
();
}
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/web/AreaController.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.web
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.sys.entity.Area
;
import
com.jeespring.modules.sys.service.AreaService
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 区域Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-15
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/area"
)
public
class
AreaController
extends
AbstractBaseController
{
@Autowired
private
AreaService
areaService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
(
"area"
)
public
Area
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
areaService
.
get
(
id
);
}
else
{
return
new
Area
();
}
}
//RequiresPermissions("sys:area:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Area
area
,
Model
model
)
{
model
.
addAttribute
(
"list"
,
areaService
.
findAll
());
return
"modules/sys/areaList"
;
}
//RequiresPermissions(value={"sys:area:view","sys:area:add","sys:area:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Area
area
,
Model
model
)
{
if
(
area
.
getParent
()==
null
||
area
.
getParent
().
getId
()==
null
){
area
.
setParent
(
UserUtils
.
getUser
().
getOffice
().
getArea
());
}
else
{
area
.
setParent
(
areaService
.
get
(
area
.
getParent
().
getId
()));
}
// // 自动获取排序号
// if (StringUtils.isBlank(area.getId())){
// int size = 0;
// List<Area> list = areaService.findAll();
// for (int i=0; i<list.size(); i++){
// Area e = list.get(i);
// if (e.getParent()!=null && e.getParent().getId()!=null
// && e.getParent().getId().equals(area.getParent().getId())){
// size++;
// }
// }
// area.setCode(area.getParent().getCode() + StringUtils.leftPad(String.valueOf(size > 0 ? size : 1), 4, "0"));
// }
model
.
addAttribute
(
"area"
,
area
);
return
"modules/sys/areaForm"
;
}
//RequiresPermissions(value={"sys:area:add","sys:area:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Area
area
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/area"
;
}
if
(!
beanValidator
(
model
,
area
)){
return
form
(
area
,
model
);
}
areaService
.
save
(
area
);
addMessage
(
redirectAttributes
,
"保存区域'"
+
area
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/sys/area/"
;
}
//RequiresPermissions("sys:area:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Area
area
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/area"
;
}
// if (Area.isRoot(id)){
// addMessage(redirectAttributes, "删除区域失败, 不允许删除顶级区域或编号为空");
// }else{
areaService
.
delete
(
area
);
addMessage
(
redirectAttributes
,
"删除区域成功"
);
// }
return
"redirect:"
+
adminPath
+
"/sys/area/"
;
}
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"treeData"
)
public
List
<
Map
<
String
,
Object
>>
treeData
(
@RequestParam
(
required
=
false
)
String
extId
,
HttpServletResponse
response
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
List
<
Area
>
list
=
areaService
.
findAll
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Area
e
=
list
.
get
(
i
);
if
(
StringUtils
.
isBlank
(
extId
)
||
(
extId
!=
null
&&
!
extId
.
equals
(
e
.
getId
())
&&
e
.
getParentIds
().
indexOf
(
","
+
extId
+
","
)==-
1
)){
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
e
.
getId
());
map
.
put
(
"pId"
,
e
.
getParentId
());
map
.
put
(
"name"
,
e
.
getName
());
mapList
.
add
(
map
);
}
}
return
mapList
;
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/web/DictController.java
0 → 100644
View file @
8b643e22
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.web
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.sys.entity.Dict
;
import
com.jeespring.modules.sys.service.DictService
;
/**
* 字典Controller
* @author 黄炳桂 516821420@qq.com
* @version 2014-05-16
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/dict"
)
public
class
DictController
extends
AbstractBaseController
{
@Autowired
private
DictService
dictService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
public
Dict
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
dictService
.
get
(
id
);
}
else
{
return
new
Dict
();
}
}
//RequiresPermissions("sys:dict:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Dict
dict
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
List
<
String
>
typeList
=
dictService
.
findTypeList
();
model
.
addAttribute
(
"typeList"
,
typeList
);
Page
<
Dict
>
page
=
dictService
.
findPage
(
new
Page
<
Dict
>(
request
,
response
),
dict
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/sys/dictList"
;
}
//RequiresPermissions(value={"sys:dict:view","sys:dict:add","sys:dict:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Dict
dict
,
Model
model
)
{
model
.
addAttribute
(
"dict"
,
dict
);
return
"modules/sys/dictForm"
;
}
//RequiresPermissions(value={"sys:dict:add","sys:dict:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
//@Valid
public
String
save
(
Dict
dict
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage&type="
+
dict
.
getType
();
}
if
(!
beanValidator
(
model
,
dict
)){
return
form
(
dict
,
model
);
}
dictService
.
save
(
dict
);
addMessage
(
redirectAttributes
,
"保存字典'"
+
dict
.
getLabel
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage&type="
+
dict
.
getType
();
}
//RequiresPermissions("sys:dict:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Dict
dict
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage"
;
}
dictService
.
delete
(
dict
);
model
.
addAttribute
(
"dict"
,
dict
);
addMessage
(
redirectAttributes
,
"删除字典成功"
);
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage&type="
+
dict
.
getType
();
}
/**
* 批量删除角色
*/
//RequiresPermissions("sys:role:del")
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage"
;
}
String
idArray
[]
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
Dict
dict
=
dictService
.
get
(
id
);
dictService
.
delete
(
dict
);
}
addMessage
(
redirectAttributes
,
"删除字典成功"
);
return
"redirect:"
+
adminPath
+
"/sys/dict/?repage"
;
}
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"treeData"
)
public
List
<
Map
<
String
,
Object
>>
treeData
(
@RequestParam
(
required
=
false
)
String
type
,
HttpServletResponse
response
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
Dict
dict
=
new
Dict
();
dict
.
setType
(
type
);
List
<
Dict
>
list
=
dictService
.
findList
(
dict
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Dict
e
=
list
.
get
(
i
);
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
e
.
getId
());
map
.
put
(
"pId"
,
e
.
getParentId
());
map
.
put
(
"name"
,
StringUtils
.
replace
(
e
.
getLabel
(),
" "
,
""
));
mapList
.
add
(
map
);
}
return
mapList
;
}
@ResponseBody
@RequestMapping
(
value
=
"listData"
)
public
List
<
Dict
>
listData
(
@RequestParam
(
required
=
false
)
String
type
)
{
Dict
dict
=
new
Dict
();
dict
.
setType
(
type
);
return
dictService
.
findList
(
dict
);
}
}
JeeSpringCloud/src/main/java/com/jeespring/modules/sys/web/IndexConteoller.java
0 → 100644
View file @
8b643e22
package
com.jeespring.modules.sys.web
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
/**
* 主页
* Created by zhao.weiwei
* create on 2017/1/11 15:15
* the email is zhao.weiwei@jyall.com.
*/
@Controller
public
class
IndexConteoller
{
@Value
(
"${adminPath:/a}"
)
private
String
adminpath
;
@RequestMapping
(
value
=
"/"
,
method
=
RequestMethod
.
GET
)
public
String
index
()
{
return
"redirect:"
+
adminpath
+
"/login"
;
}
@RequestMapping
(
value
=
"/2"
,
method
=
RequestMethod
.
GET
)
public
String
index2
()
{
return
"index2"
;
}
}
Prev
1
…
14
15
16
17
18
19
20
Next
Write
Preview
Supports
Markdown
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