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
05beecd0
Commit
05beecd0
authored
Nov 12, 2018
by
Huang
Browse files
no commit message
parent
bc5dd330
Changes
368
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
8 of 368+
files are displayed.
Plain diff
Email patch
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/LoginController.java
0 → 100644
View file @
05beecd0
/**
* * Copyright © 2015-2020 <a href="https://gitee.com/JeeHuangBingGui/JeeSpring">JeeSpring</a> All rights reserved..
*/
package
com.jeespring.modules.sys.web
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.jeespring.modules.oa.entity.OaNotify
;
import
com.jeespring.modules.oa.service.OaNotifyService
;
import
com.jeespring.modules.sys.entity.Dict
;
import
com.jeespring.modules.sys.entity.SysConfig
;
import
com.jeespring.modules.sys.service.DictService
;
import
com.jeespring.modules.sys.service.SysConfigService
;
import
com.jeespring.modules.sys.service.SysUserOnlineService
;
import
org.apache.shiro.authz.UnauthorizedException
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.apache.shiro.web.util.SavedRequest
;
import
org.apache.shiro.web.util.WebUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
com.google.common.collect.Maps
;
import
com.jeespring.common.config.Global
;
import
com.jeespring.common.servlet.ValidateCodeServlet
;
import
com.jeespring.common.utils.CacheUtils
;
import
com.jeespring.common.utils.CookieUtils
;
import
com.jeespring.common.utils.IdGen
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.json.AjaxJson
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.security.shiro.session.SessionDAO
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.sys.security.FormAuthenticationFilter
;
import
com.jeespring.modules.sys.security.SystemAuthorizingRealm.Principal
;
import
com.jeespring.modules.sys.utils.UserUtils
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.support.RedirectAttributes
;
/**
* 登录Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-31
*/
@Controller
public
class
LoginController
extends
AbstractBaseController
{
@Autowired
private
SessionDAO
sessionDAO
;
@Autowired
private
OaNotifyService
oaNotifyService
;
@Autowired
private
SysConfigService
sysConfigService
;
@Autowired
private
DictService
dictService
;
/**
* 管理登录
* @throws IOException
*/
@RequestMapping
(
value
=
"${adminPath}/login"
,
method
=
RequestMethod
.
GET
)
public
String
login
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
throws
IOException
{
Principal
principal
=
UserUtils
.
getPrincipal
();
// 默认页签模式
String
tabmode
=
CookieUtils
.
getCookie
(
request
,
"tabmode"
);
if
(
tabmode
==
null
){
CookieUtils
.
setCookie
(
response
,
"tabmode"
,
"1"
);
}
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"login, active session size: {}"
,
sessionDAO
.
getActiveSessions
(
false
).
size
());
}
// 如果已登录,再次访问主页,则退出原账号。
if
(
Global
.
TRUE
.
equals
(
Global
.
getConfig
(
"notAllowRefreshIndex"
))){
CookieUtils
.
setCookie
(
response
,
"LOGINED"
,
"false"
);
}
// 如果已经登录,则跳转到管理首页
if
(
principal
!=
null
&&
!
principal
.
isMobileLogin
()){
return
"redirect:"
+
adminPath
;
}
SavedRequest
savedRequest
=
WebUtils
.
getSavedRequest
(
request
);
//获取跳转到login之前的URL
// 如果是手机没有登录跳转到到login,则返回JSON字符串
if
(
savedRequest
!=
null
){
String
queryStr
=
savedRequest
.
getQueryString
();
if
(
queryStr
!=
null
&&(
queryStr
.
contains
(
"__ajax"
)
||
queryStr
.
contains
(
"mobileLogin"
))){
AjaxJson
j
=
new
AjaxJson
();
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"0"
);
j
.
setMsg
(
"没有登录!"
);
return
renderString
(
response
,
j
);
}
}
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"loginImgUrl"
);
List
<
SysConfig
>
loginImgUrlSysConfig
=
sysConfigService
.
findList
(
sysConfig
);
String
loginImgUrl
=
""
;
if
(
loginImgUrlSysConfig
.
size
()>
0
){
Random
rand
=
new
Random
();
loginImgUrl
=
loginImgUrlSysConfig
.
get
(
rand
.
nextInt
(
loginImgUrlSysConfig
.
size
())).
getPicture
();
}
SysConfig
validateCodeSysConfig
=
new
SysConfig
();
validateCodeSysConfig
.
setType
(
"validateCode"
);
validateCodeSysConfig
=
sysConfigService
.
findListFirstCache
(
validateCodeSysConfig
);
SysConfig
versionSysConfig
=
new
SysConfig
();
versionSysConfig
.
setType
(
"version"
);
versionSysConfig
=
sysConfigService
.
findListFirstCache
(
versionSysConfig
);
model
.
addAttribute
(
"loginImgUrl"
,
loginImgUrl
);
model
.
addAttribute
(
"systemMode"
,
sysConfigService
.
systemMode
());
model
.
addAttribute
(
"validateCode"
,
validateCodeSysConfig
.
getValue
());
model
.
addAttribute
(
"version"
,
versionSysConfig
.
getValue
());
//return "modules/sys/sysLogin";
return
"base/login"
;
}
@RequestMapping
(
value
=
"${adminPath}/register"
,
method
=
RequestMethod
.
GET
)
public
String
register
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
,
RedirectAttributes
redirectAttributes
)
throws
IOException
{
Principal
principal
=
UserUtils
.
getPrincipal
();
// 默认页签模式
String
tabmode
=
CookieUtils
.
getCookie
(
request
,
"tabmode"
);
if
(
tabmode
==
null
){
CookieUtils
.
setCookie
(
response
,
"tabmode"
,
"1"
);
}
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"login, active session size: {}"
,
sessionDAO
.
getActiveSessions
(
false
).
size
());
}
// 如果已登录,再次访问主页,则退出原账号。
if
(
Global
.
TRUE
.
equals
(
Global
.
getConfig
(
"notAllowRefreshIndex"
))){
CookieUtils
.
setCookie
(
response
,
"LOGINED"
,
"false"
);
}
// 如果已经登录,则跳转到管理首页
if
(
principal
!=
null
&&
!
principal
.
isMobileLogin
()){
return
"redirect:"
+
adminPath
;
}
SavedRequest
savedRequest
=
WebUtils
.
getSavedRequest
(
request
);
//获取跳转到login之前的URL
// 如果是手机没有登录跳转到到login,则返回JSON字符串
if
(
savedRequest
!=
null
){
String
queryStr
=
savedRequest
.
getQueryString
();
if
(
queryStr
!=
null
&&(
queryStr
.
contains
(
"__ajax"
)
||
queryStr
.
contains
(
"mobileLogin"
))){
AjaxJson
j
=
new
AjaxJson
();
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"0"
);
j
.
setMsg
(
"没有登录!"
);
return
renderString
(
response
,
j
);
}
}
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/login"
;
}
//return "modules/sys/sysRegister";
return
"base/register"
;
}
/**
* 登录失败,真正登录的POST请求由Filter完成
*/
@RequestMapping
(
value
=
"${adminPath}/login"
,
method
=
RequestMethod
.
POST
)
public
String
loginFail
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Principal
principal
=
UserUtils
.
getPrincipal
();
// 如果已经登录,则跳转到管理首页
if
(
principal
!=
null
){
return
"redirect:"
+
adminPath
;
}
String
username
=
WebUtils
.
getCleanParam
(
request
,
FormAuthenticationFilter
.
DEFAULT_USERNAME_PARAM
);
boolean
rememberMe
=
WebUtils
.
isTrue
(
request
,
FormAuthenticationFilter
.
DEFAULT_REMEMBER_ME_PARAM
);
boolean
mobile
=
WebUtils
.
isTrue
(
request
,
FormAuthenticationFilter
.
DEFAULT_MOBILE_PARAM
);
String
exception
=
(
String
)
request
.
getAttribute
(
FormAuthenticationFilter
.
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
);
String
message
=
(
String
)
request
.
getAttribute
(
FormAuthenticationFilter
.
DEFAULT_MESSAGE_PARAM
);
if
(
StringUtils
.
isBlank
(
message
)
||
StringUtils
.
equals
(
message
,
"null"
)){
message
=
"用户或密码错误, 请重试."
;
}
model
.
addAttribute
(
FormAuthenticationFilter
.
DEFAULT_USERNAME_PARAM
,
username
);
model
.
addAttribute
(
FormAuthenticationFilter
.
DEFAULT_REMEMBER_ME_PARAM
,
rememberMe
);
model
.
addAttribute
(
FormAuthenticationFilter
.
DEFAULT_MOBILE_PARAM
,
mobile
);
model
.
addAttribute
(
FormAuthenticationFilter
.
DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
,
exception
);
model
.
addAttribute
(
FormAuthenticationFilter
.
DEFAULT_MESSAGE_PARAM
,
message
);
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"login fail, active session size: {}, message: {}, exception: {}"
,
sessionDAO
.
getActiveSessions
(
false
).
size
(),
message
,
exception
);
}
// 非授权异常,登录失败,验证码加1。
if
(!
UnauthorizedException
.
class
.
getName
().
equals
(
exception
)){
model
.
addAttribute
(
"isValidateCodeLogin"
,
isValidateCodeLogin
(
username
,
true
,
false
));
}
// 验证失败清空验证码
request
.
getSession
().
setAttribute
(
ValidateCodeServlet
.
VALIDATE_CODE
,
IdGen
.
uuid
());
model
.
addAttribute
(
"systemMode"
,
sysConfigService
.
systemMode
());
return
"base/login"
;
}
/**
* 管理登录
* @throws IOException
*/
@RequestMapping
(
value
=
"${adminPath}/logout"
,
method
=
RequestMethod
.
GET
)
public
String
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
throws
IOException
{
Principal
principal
=
UserUtils
.
getPrincipal
();
// 如果已经登录,则跳转到管理首页
if
(
principal
!=
null
){
UserUtils
.
getSubject
().
logout
();
}
// 如果是手机客户端退出跳转到login,则返回JSON字符串
String
ajax
=
request
.
getParameter
(
"__ajax"
);
if
(
ajax
!=
null
){
model
.
addAttribute
(
"success"
,
"1"
);
model
.
addAttribute
(
"msg"
,
"退出成功"
);
return
renderString
(
response
,
model
);
}
return
"redirect:"
+
adminPath
+
"/login"
;
}
/**
* 登录成功,进入管理首页
*/
@RequiresPermissions
(
"user"
)
@RequestMapping
(
value
=
"${adminPath}"
)
public
String
index
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
Principal
principal
=
UserUtils
.
getPrincipal
();
// 登录成功后,验证码计算器清零
isValidateCodeLogin
(
principal
.
getLoginName
(),
false
,
true
);
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"show index, active session size: {}"
,
sessionDAO
.
getActiveSessions
(
false
).
size
());
}
// 如果已登录,再次访问主页,则退出原账号。
if
(
Global
.
TRUE
.
equals
(
Global
.
getConfig
(
"notAllowRefreshIndex"
))){
String
logined
=
CookieUtils
.
getCookie
(
request
,
"LOGINED"
);
if
(
StringUtils
.
isBlank
(
logined
)
||
"false"
.
equals
(
logined
)){
CookieUtils
.
setCookie
(
response
,
"LOGINED"
,
"true"
);
}
else
if
(
StringUtils
.
equals
(
logined
,
"true"
)){
UserUtils
.
getSubject
().
logout
();
return
"redirect:"
+
adminPath
+
"/login"
;
}
}
SysConfig
sysConfig
=
new
SysConfig
();
sysConfig
.
setType
(
"IMEnable"
);
SysConfig
IMEnableSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
sysConfig
.
setType
(
"tabmode"
);
SysConfig
tabmodeSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
sysConfig
.
setType
(
"skinSetttings"
);
SysConfig
skinSetttingsSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
sysConfig
.
setType
(
"version"
);
SysConfig
versionSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
model
.
addAttribute
(
"IMEnable"
,
IMEnableSysConfig
.
getValue
());
model
.
addAttribute
(
"tabmode"
,
tabmodeSysConfig
.
getValue
());
model
.
addAttribute
(
"skinSetttings"
,
skinSetttingsSysConfig
.
getValue
());
model
.
addAttribute
(
"systemMode"
,
sysConfigService
.
systemMode
());
model
.
addAttribute
(
"version"
,
versionSysConfig
.
getValue
());
// 如果是手机登录,则返回JSON字符串
if
(
principal
.
isMobileLogin
()){
if
(
request
.
getParameter
(
"login"
)
!=
null
){
return
renderString
(
response
,
principal
);
}
if
(
request
.
getParameter
(
"index"
)
!=
null
){
return
"modules/sys/sysIndex"
;
}
return
"redirect:"
+
adminPath
+
"/login"
;
}
// // 登录成功后,获取上次登录的当前站点ID
// UserUtils.putCache("siteId", StringUtils.toLong(CookieUtils.getCookie(request, "siteId")));
// System.out.println("==========================a");
// try {
// byte[] bytes = com.jeespring.common.utils.FileUtils.readFileToByteArray(
// com.jeespring.common.utils.FileUtils.getFile("c:\\sxt.dmp"));
// UserUtils.getSession().setAttribute("kkk", bytes);
// UserUtils.getSession().setAttribute("kkk2", bytes);
// } catch (Exception e) {
// e.printStackTrace();
// }
//// for (int i=0; i<1000000; i++){
//// //UserUtils.getSession().setAttribute("a", "a");
//// request.getSession().setAttribute("aaa", "aa");
//// }
// System.out.println("==========================b");
//
//
//return "modules/sys/sysIndex";
return
"base/index"
;
}
/**
* 获取主题方案
*/
@RequestMapping
(
value
=
"/theme/{theme}"
)
public
String
getThemeInCookie
(
@PathVariable
String
theme
,
HttpServletRequest
request
,
HttpServletResponse
response
){
if
(
StringUtils
.
isNotBlank
(
theme
)){
CookieUtils
.
setCookie
(
response
,
"theme"
,
theme
);
}
else
{
theme
=
CookieUtils
.
getCookie
(
request
,
"theme"
);
}
return
"redirect:"
+
request
.
getParameter
(
"url"
);
}
/**
* 是否是验证码登录
* @param useruame 用户名
* @param isFail 计数加1
* @param clean 计数清零
* @return
*/
@SuppressWarnings
(
"unchecked"
)
public
static
boolean
isValidateCodeLogin
(
String
useruame
,
boolean
isFail
,
boolean
clean
){
Map
<
String
,
Integer
>
loginFailMap
=
(
Map
<
String
,
Integer
>)
CacheUtils
.
get
(
"loginFailMap"
);
if
(
loginFailMap
==
null
){
loginFailMap
=
Maps
.
newHashMap
();
CacheUtils
.
put
(
"loginFailMap"
,
loginFailMap
);
}
Integer
loginFailNum
=
loginFailMap
.
get
(
useruame
);
if
(
loginFailNum
==
null
){
loginFailNum
=
0
;
}
if
(
isFail
){
loginFailNum
++;
loginFailMap
.
put
(
useruame
,
loginFailNum
);
}
if
(
clean
){
loginFailMap
.
remove
(
useruame
);
}
return
loginFailNum
>=
3
;
}
/**
* 首页
* @throws IOException
*/
@RequestMapping
(
value
=
"${adminPath}/home"
)
public
String
home
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
,
RedirectAttributes
redirectAttributes
)
throws
IOException
{
SysConfig
sysConfig
=
new
SysConfig
();
//new一个新的xxx对象
sysConfig
.
setType
(
"homePageAboveInfomation"
);
//传值
List
<
SysConfig
>
indexSysConfig
=
sysConfigService
.
findList
(
sysConfig
);
//查询系统配置项
sysConfig
.
setType
(
"homePageTechnical"
);
//传值
SysConfig
homePageTechnicalSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
//查询系统配置项
sysConfig
.
setType
(
"homePageAuthorization"
);
//传值
SysConfig
homePageAuthorizationSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
//查询系统配置项
sysConfig
.
setType
(
"homePageContactInfo"
);
//传值
SysConfig
homePageContactInfoSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
//查询系统配置项
sysConfig
.
setType
(
"homePageInfomation"
);
//传值
SysConfig
homePageInfomationSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
//查询系统配置项
sysConfig
.
setType
(
"version"
);
//传值
SysConfig
versionSysConfig
=
sysConfigService
.
findListFirstCache
(
sysConfig
);
//查询系统配置项
model
.
addAttribute
(
"homePageTechnical"
,
homePageTechnicalSysConfig
.
getDescription
().
toString
());
model
.
addAttribute
(
"homePageAuthorization"
,
homePageAuthorizationSysConfig
.
getDescription
().
toString
());
model
.
addAttribute
(
"homePageContactInfo"
,
homePageContactInfoSysConfig
.
getDescription
().
toString
());
model
.
addAttribute
(
"homePageInfomation"
,
homePageInfomationSysConfig
.
getDescription
().
toString
());
model
.
addAttribute
(
"version"
,
versionSysConfig
.
getValue
());
if
(
indexSysConfig
.
size
()
==
0
)
{
indexSysConfig
.
add
(
new
SysConfig
());
}
OaNotify
oaNotify
=
new
OaNotify
();
Dict
dict
=
new
Dict
();
dict
.
setValue
(
"1"
);
//传一个数据值
//dict.setLabel("会议通知"); //传一个标签名
List
<
Dict
>
getDict
=
dictService
.
findList
(
dict
);
//按传的值查数据字典
if
(
getDict
!=
null
){
if
(
getDict
.
size
()
>
0
){
oaNotify
.
setType
(
getDict
.
get
(
0
).
getValue
());
}
}
Page
<
OaNotify
>
pageOaNotify
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
model
.
addAttribute
(
"pageOaNotify"
,
pageOaNotify
);
dict
=
new
Dict
();
oaNotify
=
new
OaNotify
();
dict
.
setValue
(
"4"
);
//dict.setLabel("升级日志");
List
<
Dict
>
getDictLog
=
dictService
.
findList
(
dict
);
if
(
getDictLog
!=
null
){
if
(
getDictLog
.
size
()
>
0
){
oaNotify
.
setType
(
getDictLog
.
get
(
0
).
getValue
());
}
}
Page
<
OaNotify
>
pageOaNotifyLog
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
model
.
addAttribute
(
"pageOaNotifyLog"
,
pageOaNotifyLog
);
dict
=
new
Dict
();
oaNotify
=
new
OaNotify
();
dict
.
setValue
(
"5"
);
//dict.setLabel("技术支持");
List
<
Dict
>
getDictTechnology
=
dictService
.
findList
(
dict
);
if
(
getDictTechnology
!=
null
){
if
(
getDictTechnology
.
size
()
>
0
){
oaNotify
.
setType
(
getDictTechnology
.
get
(
0
).
getValue
());
}
}
Page
<
OaNotify
>
pageOaNotifyTechnology
=
oaNotifyService
.
find
(
new
Page
<
OaNotify
>(
request
,
response
),
oaNotify
);
model
.
addAttribute
(
"pageOaNotifyTechnology"
,
pageOaNotifyTechnology
);
model
.
addAttribute
(
"indexSysConfig"
,
indexSysConfig
.
get
(
0
));
//return "modules/sys/sysHome";
return
"base/home"
;
}
}
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/MenuController.java
0 → 100644
View file @
05beecd0
/**
* * 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.Menu
;
import
com.jeespring.modules.sys.service.SystemService
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 菜单Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-3-23
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/menu"
)
public
class
MenuController
extends
AbstractBaseController
{
@Autowired
private
SystemService
systemService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
(
"menu"
)
public
Menu
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
systemService
.
getMenu
(
id
);
}
else
{
return
new
Menu
();
}
}
//RequiresPermissions("sys:menu:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Model
model
,
RedirectAttributes
redirectAttributes
)
{
List
<
Menu
>
list
=
Lists
.
newArrayList
();
List
<
Menu
>
sourcelist
=
systemService
.
findAllMenu
();
//if(sysConfigService.isDemoMode()){
// model.addAttribute("list", list);
// model.addAttribute("message", sysConfigService.isDemoModeDescription());
// return "modules/sys/menuList";
//}else{
Menu
.
sortList
(
list
,
sourcelist
,
Menu
.
getRootId
(),
true
);
//}
model
.
addAttribute
(
"list"
,
list
);
return
"modules/sys/menuList"
;
}
//RequiresPermissions(value={"sys:menu:view","sys:menu:add","sys:menu:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Menu
menu
,
Model
model
)
{
if
(
menu
.
getParent
()==
null
||
menu
.
getParent
().
getId
()==
null
){
menu
.
setParent
(
new
Menu
(
Menu
.
getRootId
()));
}
menu
.
setParent
(
systemService
.
getMenu
(
menu
.
getParent
().
getId
()));
// 获取排序号,最末节点排序号+30
if
(
StringUtils
.
isBlank
(
menu
.
getId
())){
List
<
Menu
>
list
=
Lists
.
newArrayList
();
List
<
Menu
>
sourcelist
=
systemService
.
findAllMenu
();
Menu
.
sortList
(
list
,
sourcelist
,
menu
.
getParentId
(),
false
);
if
(
list
.
size
()
>
0
){
menu
.
setSort
(
list
.
get
(
list
.
size
()-
1
).
getSort
()
+
30
);
}
}
model
.
addAttribute
(
"menu"
,
menu
);
return
"modules/sys/menuForm"
;
}
//RequiresPermissions(value={"sys:menu:add","sys:menu:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Menu
menu
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
UserUtils
.
getUser
().
isAdmin
()){
addMessage
(
redirectAttributes
,
"越权操作,只有超级管理员才能添加或修改数据!"
);
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
if
(!
beanValidator
(
model
,
menu
)){
return
form
(
menu
,
model
);
}
systemService
.
saveMenu
(
menu
);
addMessage
(
redirectAttributes
,
"保存菜单'"
+
menu
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
//RequiresPermissions("sys:menu:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Menu
menu
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
// if (Menu.isRoot(id)){
// addMessage(redirectAttributes, "删除菜单失败, 不允许删除顶级菜单或编号为空");
// }else{
systemService
.
deleteMenu
(
menu
);
addMessage
(
redirectAttributes
,
"删除菜单成功"
);
// }
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
//RequiresPermissions("sys:menu:del")
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
// if (Menu.isRoot(id)){
// addMessage(redirectAttributes, "删除菜单失败, 不允许删除顶级菜单或编号为空");
// }else{
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
Menu
menu
=
systemService
.
getMenu
(
id
);
if
(
menu
!=
null
){
systemService
.
deleteMenu
(
systemService
.
getMenu
(
id
));
}
}
addMessage
(
redirectAttributes
,
"删除菜单成功"
);
// }
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
//RequiresPermissions("user")
@RequestMapping
(
value
=
"tree"
)
public
String
tree
()
{
return
"modules/sys/menuTree"
;
}
//RequiresPermissions("user")
@RequestMapping
(
value
=
"treeselect"
)
public
String
treeselect
(
String
parentId
,
Model
model
)
{
model
.
addAttribute
(
"parentId"
,
parentId
);
return
"modules/sys/menuTreeselect"
;
}
/**
* 批量修改菜单排序
*/
//RequiresPermissions("sys:menu:updateSort")
@RequestMapping
(
value
=
"updateSort"
)
public
String
updateSort
(
String
[]
ids
,
Integer
[]
sorts
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
for
(
int
i
=
0
;
i
<
ids
.
length
;
i
++)
{
Menu
menu
=
new
Menu
(
ids
[
i
]);
menu
.
setSort
(
sorts
[
i
]);
systemService
.
updateMenuSort
(
menu
);
}
addMessage
(
redirectAttributes
,
"保存菜单排序成功!"
);
return
"redirect:"
+
adminPath
+
"/sys/menu/"
;
}
/**
* isShowHide是否显示隐藏菜单
* @param extId
* @param isShowHidden
* @param response
* @return
*/
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"treeData"
)
public
List
<
Map
<
String
,
Object
>>
treeData
(
@RequestParam
(
required
=
false
)
String
extId
,
@RequestParam
(
required
=
false
)
String
isShowHide
,
HttpServletResponse
response
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
List
<
Menu
>
list
=
systemService
.
findAllMenu
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Menu
e
=
list
.
get
(
i
);
if
(
StringUtils
.
isBlank
(
extId
)
||
(
extId
!=
null
&&
!
extId
.
equals
(
e
.
getId
())
&&
e
.
getParentIds
().
indexOf
(
","
+
extId
+
","
)==-
1
)){
if
(
isShowHide
!=
null
&&
"0"
.
equals
(
isShowHide
)
&&
"0"
.
equals
(
e
.
getIsShow
())){
continue
;
}
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/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/OfficeController.java
0 → 100644
View file @
05beecd0
/**
* * 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.Office
;
import
com.jeespring.modules.sys.entity.User
;
import
com.jeespring.modules.sys.service.OfficeService
;
import
com.jeespring.modules.sys.utils.DictUtils
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 机构Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-5-15
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/office"
)
public
class
OfficeController
extends
AbstractBaseController
{
@Autowired
private
OfficeService
officeService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
(
"office"
)
public
Office
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
officeService
.
get
(
id
);
}
else
{
return
new
Office
();
}
}
//RequiresPermissions("sys:office:index")
@RequestMapping
(
value
=
{
""
,
"index"
})
public
String
index
(
Office
office
,
Model
model
)
{
// model.addAttribute("list", officeService.findAll());
return
"modules/sys/officeIndex"
;
}
//RequiresPermissions("sys:office:index")
@RequestMapping
(
value
=
{
"list"
})
public
String
list
(
Office
office
,
Model
model
)
{
if
(
office
==
null
||
office
.
getParentIds
()
==
null
){
model
.
addAttribute
(
"list"
,
officeService
.
findList
(
false
));
}
else
{
model
.
addAttribute
(
"list"
,
officeService
.
findList
(
office
));
}
return
"modules/sys/officeList"
;
}
//RequiresPermissions(value={"sys:office:view","sys:office:add","sys:office:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Office
office
,
Model
model
)
{
User
user
=
UserUtils
.
getUser
();
if
(
office
.
getParent
()==
null
||
office
.
getParent
().
getId
()==
null
){
office
.
setParent
(
user
.
getOffice
());
}
office
.
setParent
(
officeService
.
get
(
office
.
getParent
().
getId
()));
if
(
office
.
getArea
()==
null
){
office
.
setArea
(
user
.
getOffice
().
getArea
());
}
// 自动获取排序号
if
(
StringUtils
.
isBlank
(
office
.
getId
())&&
office
.
getParent
()!=
null
){
int
size
=
0
;
List
<
Office
>
list
=
officeService
.
findAll
();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Office
e
=
list
.
get
(
i
);
if
(
e
.
getParent
()!=
null
&&
e
.
getParent
().
getId
()!=
null
&&
e
.
getParent
().
getId
().
equals
(
office
.
getParent
().
getId
())){
size
++;
}
}
office
.
setCode
(
office
.
getParent
().
getCode
()
+
StringUtils
.
leftPad
(
String
.
valueOf
(
size
>
0
?
size
+
1
:
1
),
3
,
"0"
));
}
model
.
addAttribute
(
"office"
,
office
);
return
"modules/sys/officeForm"
;
}
//RequiresPermissions(value={"sys:office:add","sys:office:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Office
office
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/office/"
;
}
if
(!
beanValidator
(
model
,
office
)){
return
form
(
office
,
model
);
}
officeService
.
save
(
office
);
if
(
office
.
getChildDeptList
()!=
null
){
Office
childOffice
=
null
;
for
(
String
id
:
office
.
getChildDeptList
()){
childOffice
=
new
Office
();
childOffice
.
setName
(
DictUtils
.
getDictLabel
(
id
,
"sys_office_common"
,
"未知"
));
childOffice
.
setParent
(
office
);
childOffice
.
setArea
(
office
.
getArea
());
childOffice
.
setType
(
"2"
);
childOffice
.
setGrade
(
String
.
valueOf
(
Integer
.
valueOf
(
office
.
getGrade
())+
1
));
childOffice
.
setUseable
(
Global
.
YES
);
officeService
.
save
(
childOffice
);
}
}
addMessage
(
redirectAttributes
,
"保存机构'"
+
office
.
getName
()
+
"'成功"
);
String
id
=
"0"
.
equals
(
office
.
getParentId
())
?
""
:
office
.
getParentId
();
return
"redirect:"
+
adminPath
+
"/sys/office/list?id="
+
id
+
"&parentIds="
+
office
.
getParentIds
();
}
//RequiresPermissions("sys:office:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Office
office
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/office/list"
;
}
// if (Office.isRoot(id)){
// addMessage(redirectAttributes, "删除机构失败, 不允许删除顶级机构或编号空");
// }else{
officeService
.
delete
(
office
);
addMessage
(
redirectAttributes
,
"删除机构成功"
);
// }
return
"redirect:"
+
adminPath
+
"/sys/office/list?id="
+
office
.
getParentId
()+
"&parentIds="
+
office
.
getParentIds
();
}
/**
* 获取机构JSON数据。
* @param extId 排除的ID
* @param type 类型(1:公司;2:部门/小组/其它:3:用户)
* @param grade 显示级别
* @param response
* @return
*/
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"treeData"
)
public
List
<
Map
<
String
,
Object
>>
treeData
(
@RequestParam
(
required
=
false
)
String
extId
,
@RequestParam
(
required
=
false
)
String
type
,
@RequestParam
(
required
=
false
)
Long
grade
,
@RequestParam
(
required
=
false
)
Boolean
isAll
,
HttpServletResponse
response
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
List
<
Office
>
list
=
officeService
.
findList
(
isAll
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
Office
e
=
list
.
get
(
i
);
if
((
StringUtils
.
isBlank
(
extId
)
||
(
extId
!=
null
&&
!
extId
.
equals
(
e
.
getId
())
&&
e
.
getParentIds
().
indexOf
(
","
+
extId
+
","
)==-
1
))
&&
(
type
==
null
||
(
type
!=
null
&&
(
"1"
.
equals
(
type
)
?
type
.
equals
(
e
.
getType
())
:
true
)))
&&
(
grade
==
null
||
(
grade
!=
null
&&
Integer
.
parseInt
(
e
.
getGrade
())
<=
grade
.
intValue
()))
&&
Global
.
YES
.
equals
(
e
.
getUseable
())){
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
e
.
getId
());
map
.
put
(
"pId"
,
e
.
getParentId
());
map
.
put
(
"pIds"
,
e
.
getParentIds
());
map
.
put
(
"name"
,
e
.
getName
());
if
(
type
!=
null
&&
"3"
.
equals
(
type
)){
map
.
put
(
"isParent"
,
true
);
}
mapList
.
add
(
map
);
}
}
return
mapList
;
}
}
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/RegisterController.java
0 → 100644
View file @
05beecd0
package
com.jeespring.modules.sys.web
;
import
java.io.IOException
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
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.jeespring.common.config.Global
;
import
com.jeespring.common.json.AjaxJson
;
import
com.jeespring.common.utils.FileUtils
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.web.AbstractBaseController
;
import
com.jeespring.modules.sys.dao.UserDao
;
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.service.OfficeService
;
import
com.jeespring.modules.sys.service.SystemService
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 用户Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-8-29
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/register"
)
public
class
RegisterController
extends
AbstractBaseController
{
@Autowired
private
SystemService
systemService
;
@Autowired
private
OfficeService
officeService
;
@Autowired
private
UserDao
userDao
;
@ModelAttribute
public
User
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
systemService
.
getUser
(
id
);
}
else
{
return
new
User
();
}
}
@RequestMapping
(
value
=
{
"index"
,
""
})
public
String
register
(
User
user
,
Model
model
)
{
//return "modules/sys/register";
//return "redirect:" + adminPath + "/login";
//return "redirect:" + adminPath + "/register";
model
.
addAttribute
(
"user"
,
user
);
return
"modules/sys/sysRegister"
;
}
@RequestMapping
(
value
=
"registerUser"
)
public
String
registerUser
(
HttpServletRequest
request
,
HttpServletResponse
response
,
boolean
mobileLogin
,
String
randomCode
,
String
roleName
,
User
user
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
//验证手机号是否已经注册
if
(
userDao
.
findUniqueByProperty
(
"mobile"
,
user
.
getMobile
())
!=
null
){
// 如果是手机登录,则返回JSON字符串
if
(
mobileLogin
){
AjaxJson
j
=
new
AjaxJson
();
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"1"
);
j
.
setMsg
(
"手机号已经被使用!"
);
return
renderString
(
response
,
j
.
getJsonStr
());
}
else
{
addMessage
(
redirectAttributes
,
"手机号已经被使用!"
);
model
.
addAttribute
(
"message"
,
"手机号已经被使用!"
);
return
register
(
user
,
model
);
}
}
//验证用户是否已经注册
if
(
userDao
.
findUniqueByProperty
(
"login_name"
,
user
.
getLoginName
())
!=
null
){
// 如果是手机登录,则返回JSON字符串
if
(
mobileLogin
){
AjaxJson
j
=
new
AjaxJson
();
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"2"
);
j
.
setMsg
(
"用户名已经被注册!"
);
return
renderString
(
response
,
j
.
getJsonStr
());
}
else
{
addMessage
(
redirectAttributes
,
"用户名已经被注册!"
);
model
.
addAttribute
(
"message"
,
"用户名已经被注册!"
);
return
register
(
user
,
model
);
}
}
//验证短信内容
/*if(!randomCode.equals(request.getSession().getServletContext().getAttribute(user.getMobile()))){
// 如果是手机登录,则返回JSON字符串
if (mobileLogin){
AjaxJson j = new AjaxJson();
j.setSuccess(false);
j.setErrorCode("3");
j.setMsg("手机验证码不正确!");
return renderString(response, j.getJsonStr());
}else{
addMessage(model, "手机验证码不正确!");
return register(user, model);
}
}*/
// 修正引用赋值问题,不知道为何,Company和Office引用的一个实例地址,修改了一个,另外一个跟着修改。
Role
role
=
systemService
.
getRoleByEnname
(
roleName
);
String
officeCode
=
"1000"
;
if
(
"patient"
.
equals
(
roleName
)){
officeCode
=
"1001"
;
}
Office
office
=
officeService
.
getByCode
(
officeCode
);
// 密码MD5加密
user
.
setPassword
(
SystemService
.
entryptPassword
(
user
.
getPassword
()));
if
(
systemService
.
getUserByLoginName
(
user
.
getLoginName
())
!=
null
){
addMessage
(
redirectAttributes
,
"注册用户'"
+
user
.
getLoginName
()
+
"'失败,用户名已存在"
);
model
.
addAttribute
(
"message"
,
"注册用户'"
+
user
.
getLoginName
()
+
"'失败,用户名已存在"
);
return
register
(
user
,
model
);
}
// 角色数据有效性验证,过滤不在授权内的角色
List
<
Role
>
roleList
=
Lists
.
newArrayList
();
roleList
.
add
(
role
);
user
.
setRoleList
(
roleList
);
//保存机构
user
.
setCompany
(
office
);
user
.
setOffice
(
office
);
//生成用户二维码,使用登录名
String
realPath
=
Global
.
getUserfilesBaseDir
()
+
Global
.
USERFILES_BASE_URL
+
user
.
getId
()
+
"/qrcode/"
;
FileUtils
.
createDirectory
(
realPath
);
String
name
=
user
.
getId
()+
".png"
;
//encoderImgId此处二维码的图片名
String
filePath
=
realPath
+
name
;
//存放路径
//TwoDimensionCode.encoderQRCode(user.getLoginName(), filePath, "png");//执行生成二维码
user
.
setQrCode
(
request
.
getContextPath
()+
Global
.
USERFILES_BASE_URL
+
user
.
getId
()
+
"/qrcode/"
+
name
);
// 保存用户信息
systemService
.
saveUser
(
user
);
// 清除当前用户缓存
if
(
user
.
getLoginName
().
equals
(
UserUtils
.
getUser
().
getLoginName
())){
UserUtils
.
clearCache
();
//UserUtils.getCacheMap().clear();
}
request
.
getSession
().
getServletContext
().
removeAttribute
(
user
.
getMobile
());
//清除验证码
// 如果是手机登录,则返回JSON字符串
if
(
mobileLogin
){
AjaxJson
j
=
new
AjaxJson
();
j
.
setSuccess
(
true
);
j
.
setMsg
(
"注册用户'"
+
user
.
getLoginName
()
+
"'成功"
);
return
renderString
(
response
,
j
);
}
addMessage
(
redirectAttributes
,
"注册用户'"
+
user
.
getLoginName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/login"
;
}
/**
* 获取验证码
* @param request
* @param response
* @param mobile
* @param model
* @param redirectAttributes
* @return
*/
@RequestMapping
(
value
=
"getRegisterCode"
)
@ResponseBody
public
AjaxJson
getRegisterCode
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
mobile
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
AjaxJson
j
=
new
AjaxJson
();
//验证手机号是否已经注册
if
(
userDao
.
findUniqueByProperty
(
"mobile"
,
mobile
)
!=
null
){
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"1"
);
j
.
setMsg
(
"手机号已经被使用!"
);
return
j
;
}
String
randomCode
=
String
.
valueOf
((
int
)
(
Math
.
random
()
*
9000
+
1000
));
try
{
String
result
=
UserUtils
.
sendRandomCode
(
mobile
,
randomCode
,
mobile
,
randomCode
);
if
(!
"100"
.
equals
(
result
))
{
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"2"
);
j
.
setMsg
(
"短信发送失败,错误代码:"
+
result
+
",请联系管理员。"
);
}
else
{
j
.
setSuccess
(
true
);
j
.
setErrorCode
(
"-1"
);
j
.
setMsg
(
"短信发送成功!"
);
request
.
getSession
().
getServletContext
().
setAttribute
(
mobile
,
randomCode
);
}
}
catch
(
IOException
e
)
{
j
.
setSuccess
(
false
);
j
.
setErrorCode
(
"3"
);
j
.
setMsg
(
"因未知原因导致短信发送失败,请联系管理员。"
);
}
return
j
;
}
/**
* web端ajax验证手机验证码是否正确
*/
@ResponseBody
@RequestMapping
(
value
=
"validateMobileCode"
)
public
boolean
validateMobileCode
(
HttpServletRequest
request
,
String
mobile
,
String
randomCode
)
{
if
(
randomCode
.
equals
(
request
.
getSession
().
getServletContext
().
getAttribute
(
mobile
)))
{
return
true
;
}
else
{
return
false
;
}
}
}
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/RoleController.java
0 → 100644
View file @
05beecd0
/**
* * 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.Collections3
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.common.persistence.Page
;
import
com.jeespring.common.web.AbstractBaseController
;
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.service.OfficeService
;
import
com.jeespring.modules.sys.service.SystemService
;
import
com.jeespring.modules.sys.utils.UserUtils
;
/**
* 角色Controller
* @author 黄炳桂 516821420@qq.com
* @version 2013-12-05
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/role"
)
public
class
RoleController
extends
AbstractBaseController
{
@Autowired
private
SystemService
systemService
;
@Autowired
private
OfficeService
officeService
;
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
(
"role"
)
public
Role
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
if
(
StringUtils
.
isNotBlank
(
id
)){
return
systemService
.
getRole
(
id
);
}
else
{
return
new
Role
();
}
}
//RequiresPermissions("sys:role:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
Role
role
,
Model
model
)
{
List
<
Role
>
list
=
systemService
.
findRole
(
role
);
model
.
addAttribute
(
"list"
,
list
);
return
"modules/sys/roleList"
;
}
//RequiresPermissions(value={"sys:role:view","sys:role:add","sys:role:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
Role
role
,
Model
model
)
{
if
(
role
.
getOffice
()==
null
){
role
.
setOffice
(
UserUtils
.
getUser
().
getOffice
());
}
model
.
addAttribute
(
"role"
,
role
);
model
.
addAttribute
(
"menuList"
,
systemService
.
findAllMenu
());
model
.
addAttribute
(
"officeList"
,
officeService
.
findAll
());
return
"modules/sys/roleForm"
;
}
//RequiresPermissions("sys:role:auth")
@RequestMapping
(
value
=
"auth"
)
public
String
auth
(
Role
role
,
Model
model
)
{
if
(
role
.
getOffice
()==
null
){
role
.
setOffice
(
UserUtils
.
getUser
().
getOffice
());
}
model
.
addAttribute
(
"role"
,
role
);
model
.
addAttribute
(
"menuList"
,
systemService
.
findAllMenu
());
model
.
addAttribute
(
"officeList"
,
officeService
.
findAll
());
return
"modules/sys/roleAuth"
;
}
//RequiresPermissions(value={"sys:role:assign","sys:role:auth","sys:role:add","sys:role:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
Role
role
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(!
UserUtils
.
getUser
().
isAdmin
()&&
role
.
getSysData
().
equals
(
Global
.
YES
)){
addMessage
(
redirectAttributes
,
"越权操作,只有超级管理员才能修改此数据!"
);
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
if
(!
beanValidator
(
model
,
role
)){
return
list
(
role
,
model
);
}
if
(!
"true"
.
equals
(
checkName
(
role
.
getOldName
(),
role
.
getName
()))){
addMessage
(
model
,
"保存角色'"
+
role
.
getName
()
+
"'失败, 角色名已存在"
);
return
list
(
role
,
model
);
}
if
(!
"true"
.
equals
(
checkEnname
(
role
.
getOldEnname
(),
role
.
getEnname
()))){
addMessage
(
model
,
"保存角色'"
+
role
.
getName
()
+
"'失败, 英文名已存在"
);
return
list
(
role
,
model
);
}
systemService
.
saveRole
(
role
);
addMessage
(
redirectAttributes
,
"保存角色'"
+
role
.
getName
()
+
"'成功"
);
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
//RequiresPermissions("sys:role:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
Role
role
,
RedirectAttributes
redirectAttributes
)
{
if
(!
UserUtils
.
getUser
().
isAdmin
()
&&
role
.
getSysData
().
equals
(
Global
.
YES
)){
addMessage
(
redirectAttributes
,
"越权操作,只有超级管理员才能修改此数据!"
);
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
// if (Role.isAdmin(id)){
// addMessage(redirectAttributes, "删除角色失败, 不允许内置角色或编号空");
//// }else if (UserUtils.getUser().getRoleIdList().contains(id)){
//// addMessage(redirectAttributes, "删除角色失败, 不能删除当前用户所在角色");
// }else{
systemService
.
deleteRole
(
role
);
addMessage
(
redirectAttributes
,
"删除角色成功"
);
// }
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
/**
* 批量删除角色
*/
//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/role/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
StringBuffer
msg
=
new
StringBuffer
();
for
(
String
id
:
idArray
){
Role
role
=
systemService
.
getRole
(
id
);
if
(!
UserUtils
.
getUser
().
isAdmin
()
&&
role
.
getSysData
().
equals
(
Global
.
YES
)){
msg
.
append
(
"越权操作,只有超级管理员才能修改["
+
role
.
getName
()+
"]数据!<br/>"
);
}
else
{
systemService
.
deleteRole
(
role
);
msg
.
append
(
"删除角色["
+
role
.
getName
()+
"]成功<br/>"
);
}
}
addMessage
(
redirectAttributes
,
msg
.
toString
());
return
"redirect:"
+
adminPath
+
"/sys/role/?repage"
;
}
/**
* 角色分配页面
* @param role
* @param model
* @return
*/
//RequiresPermissions("sys:role:assign")
@RequestMapping
(
value
=
"assign"
)
public
String
assign
(
Role
role
,
Model
model
)
{
List
<
User
>
userList
=
systemService
.
findUser
(
new
User
(
new
Role
(
role
.
getId
())));
model
.
addAttribute
(
"userList"
,
userList
);
return
"modules/sys/roleAssign"
;
}
/**
* 角色分配 -- 打开角色分配对话框
* @param role
* @param model
* @return
*/
//RequiresPermissions("sys:role:assign")
@RequestMapping
(
value
=
"usertorole"
)
public
String
selectUserToRole
(
Role
role
,
Model
model
)
{
List
<
User
>
userList
=
systemService
.
findUser
(
new
User
(
new
Role
(
role
.
getId
())));
model
.
addAttribute
(
"role"
,
role
);
model
.
addAttribute
(
"userList"
,
userList
);
model
.
addAttribute
(
"selectIds"
,
Collections3
.
extractToString
(
userList
,
"name"
,
","
));
model
.
addAttribute
(
"officeList"
,
officeService
.
findAll
());
return
"modules/sys/selectUserToRole"
;
}
/**
* 角色分配 -- 根据部门编号获取用户列表
* @param officeId
* @param response
* @return
*/
//RequiresPermissions("sys:role:assign")
@ResponseBody
@RequestMapping
(
value
=
"users"
)
public
List
<
Map
<
String
,
Object
>>
users
(
String
officeId
,
HttpServletResponse
response
)
{
List
<
Map
<
String
,
Object
>>
mapList
=
Lists
.
newArrayList
();
User
user
=
new
User
();
user
.
setOffice
(
new
Office
(
officeId
));
Page
<
User
>
page
=
systemService
.
findUser
(
new
Page
<
User
>(
1
,
-
1
),
user
);
for
(
User
e
:
page
.
getList
())
{
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"id"
,
e
.
getId
());
map
.
put
(
"pId"
,
0
);
map
.
put
(
"name"
,
e
.
getName
());
mapList
.
add
(
map
);
}
return
mapList
;
}
/**
* 角色分配 -- 从角色中移除用户
* @param userId
* @param roleId
* @param redirectAttributes
* @return
*/
//RequiresPermissions("sys:role:assign")
@RequestMapping
(
value
=
"outrole"
)
public
String
outrole
(
String
userId
,
String
roleId
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/role/assign?id="
+
roleId
;
}
Role
role
=
systemService
.
getRole
(
roleId
);
User
user
=
systemService
.
getUser
(
userId
);
if
(
UserUtils
.
getUser
().
getId
().
equals
(
userId
))
{
addMessage
(
redirectAttributes
,
"无法从角色【"
+
role
.
getName
()
+
"】中移除用户【"
+
user
.
getName
()
+
"】自己!"
);
}
else
{
if
(
user
.
getRoleList
().
size
()
<=
1
){
addMessage
(
redirectAttributes
,
"用户【"
+
user
.
getName
()
+
"】从角色【"
+
role
.
getName
()
+
"】中移除失败!这已经是该用户的唯一角色,不能移除。"
);
}
else
{
Boolean
flag
=
systemService
.
outUserInRole
(
role
,
user
);
if
(!
flag
)
{
addMessage
(
redirectAttributes
,
"用户【"
+
user
.
getName
()
+
"】从角色【"
+
role
.
getName
()
+
"】中移除失败!"
);
}
else
{
addMessage
(
redirectAttributes
,
"用户【"
+
user
.
getName
()
+
"】从角色【"
+
role
.
getName
()
+
"】中移除成功!"
);
}
}
}
return
"redirect:"
+
adminPath
+
"/sys/role/assign?id="
+
role
.
getId
();
}
/**
* 角色分配
* @param role
* @param idsArr
* @param redirectAttributes
* @return
*/
//RequiresPermissions("sys:role:assign")
@RequestMapping
(
value
=
"assignrole"
)
public
String
assignRole
(
Role
role
,
String
[]
idsArr
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/role/assign?id="
+
role
.
getId
();
}
StringBuilder
msg
=
new
StringBuilder
();
int
newNum
=
0
;
for
(
int
i
=
0
;
i
<
idsArr
.
length
;
i
++)
{
User
user
=
systemService
.
assignUserToRole
(
role
,
systemService
.
getUser
(
idsArr
[
i
]));
if
(
null
!=
user
)
{
msg
.
append
(
"<br/>新增用户【"
+
user
.
getName
()
+
"】到角色【"
+
role
.
getName
()
+
"】!"
);
newNum
++;
}
}
addMessage
(
redirectAttributes
,
"已成功分配 "
+
newNum
+
" 个用户"
+
msg
);
return
"redirect:"
+
adminPath
+
"/sys/role/assign?id="
+
role
.
getId
();
}
/**
* 验证角色名是否有效
* @param oldName
* @param name
* @return
*/
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"checkName"
)
public
String
checkName
(
String
oldName
,
String
name
)
{
if
(
name
!=
null
&&
name
.
equals
(
oldName
))
{
return
"true"
;
}
else
if
(
name
!=
null
&&
systemService
.
getRoleByName
(
name
)
==
null
)
{
return
"true"
;
}
return
"false"
;
}
/**
* 验证角色英文名是否有效
* @param oldName
* @param name
* @return
*/
//RequiresPermissions("user")
@ResponseBody
@RequestMapping
(
value
=
"checkEnname"
)
public
String
checkEnname
(
String
oldEnname
,
String
enname
)
{
if
(
enname
!=
null
&&
enname
.
equals
(
oldEnname
))
{
return
"true"
;
}
else
if
(
enname
!=
null
&&
systemService
.
getRoleByEnname
(
enname
)
==
null
)
{
return
"true"
;
}
return
"false"
;
}
}
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/SysConfigController.java
0 → 100644
View file @
05beecd0
/**
* * 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
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
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.SysConfig
;
import
com.jeespring.modules.sys.service.SysConfigService
;
/**
* 系统配置Controller
* @author 黄炳桂 516821420@qq.com
* @version 2017-11-17
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/sysConfig"
)
public
class
SysConfigController
extends
AbstractBaseController
{
@Autowired
private
SysConfigService
sysConfigService
;
@ModelAttribute
public
SysConfig
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
SysConfig
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysConfigService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
SysConfig
();
}
return
entity
;
}
/**
* 系统配置列表页面
*/
//RequiresPermissions("sys:sysConfig:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
SysConfig
sysConfig
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysConfig
>
page
=
sysConfigService
.
findPage
(
new
Page
<
SysConfig
>(
request
,
response
),
sysConfig
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/sys/sysConfigList"
;
}
/**
* 系统配置列表页面
*/
//RequiresPermissions("sys:sysConfig:select")
@RequestMapping
(
value
=
{
"select"
})
public
String
select
(
SysConfig
sysConfig
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
Page
<
SysConfig
>
page
=
sysConfigService
.
findPage
(
new
Page
<
SysConfig
>(
request
,
response
),
sysConfig
);
model
.
addAttribute
(
"page"
,
page
);
return
"modules/sys/sysConfigSelect"
;
}
/**
* 查看,增加,编辑系统配置表单页面
*/
//RequiresPermissions(value={"sys:sysConfig:view","sys:sysConfig:add","sys:sysConfig:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
SysConfig
sysConfig
,
Model
model
)
{
model
.
addAttribute
(
"sysConfig"
,
sysConfig
);
return
"modules/sys/sysConfigForm"
;
}
/**
* 保存系统配置
*/
//RequiresPermissions(value={"sys:sysConfig:add","sys:sysConfig:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
SysConfig
sysConfig
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfig/?repage"
;
}
if
(!
beanValidator
(
model
,
sysConfig
)){
return
form
(
sysConfig
,
model
);
}
sysConfigService
.
save
(
sysConfig
);
addMessage
(
redirectAttributes
,
"保存系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 删除系统配置
*/
//RequiresPermissions("sys:sysConfig:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
SysConfig
sysConfig
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfig/?repage"
;
}
sysConfigService
.
delete
(
sysConfig
);
addMessage
(
redirectAttributes
,
"删除系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 删除系统配置(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
//RequiresPermissions("sys:sysConfig:delByLogic")
@RequestMapping
(
value
=
"deleteByLogic"
)
public
String
deleteByLogic
(
SysConfig
sysConfig
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfig/?repage"
;
}
sysConfigService
.
deleteByLogic
(
sysConfig
);
addMessage
(
redirectAttributes
,
"逻辑删除系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 批量删除系统配置
*/
//RequiresPermissions("sys:sysConfig:del")
@RequestMapping
(
value
=
"deleteAll"
)
public
String
deleteAll
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfig/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysConfigService
.
delete
(
sysConfigService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 批量删除系统配置(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏)
*/
//RequiresPermissions("sys:sysConfig:delByLogic")
@RequestMapping
(
value
=
"deleteAllByLogic"
)
public
String
deleteAllByLogic
(
String
ids
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfig/?repage"
;
}
String
[]
idArray
=
ids
.
split
(
","
);
for
(
String
id
:
idArray
){
sysConfigService
.
deleteByLogic
(
sysConfigService
.
get
(
id
));
}
addMessage
(
redirectAttributes
,
"删除系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 导出excel文件
*/
//RequiresPermissions("sys:sysConfig:export")
@RequestMapping
(
value
=
"export"
,
method
=
RequestMethod
.
POST
)
public
String
exportFile
(
SysConfig
sysConfig
,
HttpServletRequest
request
,
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"系统配置"
+
DateUtils
.
getDate
(
"yyyyMMddHHmmss"
)+
".xlsx"
;
Page
<
SysConfig
>
page
=
sysConfigService
.
findPage
(
new
Page
<
SysConfig
>(
request
,
response
,
-
1
),
sysConfig
);
new
ExportExcel
(
"系统配置"
,
SysConfig
.
class
).
setDataList
(
page
.
getList
()).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导出系统配置记录失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 导入Excel数据
*/
//RequiresPermissions("sys:sysConfig:import")
@RequestMapping
(
value
=
"import"
,
method
=
RequestMethod
.
POST
)
public
String
importFile
(
MultipartFile
file
,
RedirectAttributes
redirectAttributes
)
{
try
{
int
successNum
=
0
;
ImportExcel
ei
=
new
ImportExcel
(
file
,
1
,
0
);
List
<
SysConfig
>
list
=
ei
.
getDataList
(
SysConfig
.
class
);
for
(
SysConfig
sysConfig
:
list
){
sysConfigService
.
save
(
sysConfig
);
}
addMessage
(
redirectAttributes
,
"已成功导入 "
+
successNum
+
" 条系统配置记录"
);
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入系统配置失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
/**
* 下载导入系统配置数据模板
*/
//RequiresPermissions("sys:sysConfig:import")
@RequestMapping
(
value
=
"import/template"
)
public
String
importFileTemplate
(
HttpServletResponse
response
,
RedirectAttributes
redirectAttributes
)
{
try
{
String
fileName
=
"系统配置数据导入模板.xlsx"
;
List
<
SysConfig
>
list
=
Lists
.
newArrayList
();
new
ExportExcel
(
"系统配置数据"
,
SysConfig
.
class
,
1
).
setDataList
(
list
).
write
(
response
,
fileName
).
dispose
();
return
null
;
}
catch
(
Exception
e
)
{
addMessage
(
redirectAttributes
,
"导入模板下载失败!失败信息:"
+
e
.
getMessage
());
}
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfig/?repage"
;
}
}
\ No newline at end of file
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/SysConfigTreeController.java
0 → 100644
View file @
05beecd0
/**
* * 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.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.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.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.sys.entity.SysConfigTree
;
import
com.jeespring.modules.sys.service.SysConfigTreeService
;
/**
* 系统配置Controller
* @author JeeSpring
* @version 2018-08-22
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/sysConfigTree"
)
public
class
SysConfigTreeController
extends
AbstractBaseController
{
@Autowired
private
SysConfigService
sysConfigService
;
@Autowired
private
SysConfigTreeService
sysConfigTreeService
;
@ModelAttribute
public
SysConfigTree
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
SysConfigTree
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysConfigTreeService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
SysConfigTree
();
}
return
entity
;
}
/**
* 系统配置列表页面
*/
//@RequiresPermissions("sys:sysConfig:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
SysConfigTree
sysConfig
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
List
<
SysConfigTree
>
list
=
sysConfigTreeService
.
findList
(
sysConfig
);
for
(
SysConfigTree
item:
list
){
if
(
item
.
getDescription
()==
null
)
{
item
.
setDescription
(
""
);
}
if
(
item
.
getDescription
().
length
()>
20
)
{
item
.
setDescription
(
item
.
getDescription
().
substring
(
0
,
20
));
}
}
model
.
addAttribute
(
"list"
,
list
);
return
"modules/sys/sysConfigTreeList"
;
}
/**
* 查看,增加,编辑系统配置表单页面
*/
//@RequiresPermissions(value={"sys:sysConfig:view","sys:sysConfig:add","sys:sysConfig:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
SysConfigTree
sysConfig
,
Model
model
)
{
if
(
sysConfig
.
getParent
()!=
null
&&
StringUtils
.
isNotBlank
(
sysConfig
.
getParent
().
getId
())){
sysConfig
.
setParent
(
sysConfigTreeService
.
get
(
sysConfig
.
getParent
().
getId
()));
// 获取排序号,最末节点排序号+30
if
(
StringUtils
.
isBlank
(
sysConfig
.
getId
())){
SysConfigTree
sysConfigChild
=
new
SysConfigTree
();
sysConfigChild
.
setParent
(
new
SysConfigTree
(
sysConfig
.
getParent
().
getId
()));
List
<
SysConfigTree
>
list
=
sysConfigTreeService
.
findList
(
sysConfig
);
if
(
list
.
size
()
>
0
){
sysConfig
.
setSort
(
list
.
get
(
list
.
size
()-
1
).
getSort
());
if
(
sysConfig
.
getSort
()
!=
null
){
sysConfig
.
setSort
(
sysConfig
.
getSort
()
+
30
);
}
}
}
}
if
(
sysConfig
.
getSort
()
==
null
){
sysConfig
.
setSort
(
30
);
}
model
.
addAttribute
(
"sysConfig"
,
sysConfig
);
return
"modules/sys/sysConfigTreeForm"
;
}
/**
* 保存系统配置
*/
//@RequiresPermissions(value={"sys:sysConfig:add","sys:sysConfig:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
SysConfigTree
sysConfig
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfigTree/?repage"
;
}
if
(!
beanValidator
(
model
,
sysConfig
)){
return
form
(
sysConfig
,
model
);
}
sysConfigTreeService
.
save
(
sysConfig
);
addMessage
(
redirectAttributes
,
"保存系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfigTree/?repage"
;
}
/**
* 删除系统配置
*/
//@RequiresPermissions("sys:sysConfig:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
SysConfigTree
sysConfig
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfigTree/?repage"
;
}
sysConfigTreeService
.
delete
(
sysConfig
);
addMessage
(
redirectAttributes
,
"删除系统配置成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysConfigTree/?repage"
;
}
//@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
<
SysConfigTree
>
list
=
sysConfigTreeService
.
findList
(
new
SysConfigTree
());
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
SysConfigTree
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
;
}
}
\ No newline at end of file
JeeSpringCloud/jeespring-framework/src/main/java/com/jeespring/modules/sys/web/SysDictTreeController.java
0 → 100644
View file @
05beecd0
/**
* * 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.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.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.web.AbstractBaseController
;
import
com.jeespring.common.utils.StringUtils
;
import
com.jeespring.modules.sys.entity.SysDictTree
;
import
com.jeespring.modules.sys.service.SysDictTreeService
;
/**
* 数据字典Controller
* @author JeeSpring
* @version 2018-08-22
*/
@Controller
@RequestMapping
(
value
=
"${adminPath}/sys/sysDictTree"
)
public
class
SysDictTreeController
extends
AbstractBaseController
{
@Autowired
private
SysConfigService
sysConfigService
;
@Autowired
private
SysDictTreeService
sysDictTreeService
;
@ModelAttribute
public
SysDictTree
get
(
@RequestParam
(
required
=
false
)
String
id
)
{
SysDictTree
entity
=
null
;
if
(
StringUtils
.
isNotBlank
(
id
)){
entity
=
sysDictTreeService
.
get
(
id
);
}
if
(
entity
==
null
){
entity
=
new
SysDictTree
();
}
return
entity
;
}
/**
* 数据字典列表页面
*/
//@RequiresPermissions("sys:sysDict:list")
@RequestMapping
(
value
=
{
"list"
,
""
})
public
String
list
(
SysDictTree
sysDict
,
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
List
<
SysDictTree
>
list
=
sysDictTreeService
.
findList
(
sysDict
);
model
.
addAttribute
(
"list"
,
list
);
return
"modules/sys/sysDictTreeList"
;
}
/**
* 查看,增加,编辑数据字典表单页面
*/
//@RequiresPermissions(value={"sys:sysDict:view","sys:sysDict:add","sys:sysDict:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"form"
)
public
String
form
(
SysDictTree
sysDict
,
Model
model
)
{
if
(
sysDict
.
getParent
()!=
null
&&
StringUtils
.
isNotBlank
(
sysDict
.
getParent
().
getId
())){
sysDict
.
setParent
(
sysDictTreeService
.
get
(
sysDict
.
getParent
().
getId
()));
// 获取排序号,最末节点排序号+30
if
(
StringUtils
.
isBlank
(
sysDict
.
getId
())){
SysDictTree
sysDictChild
=
new
SysDictTree
();
sysDictChild
.
setParent
(
new
SysDictTree
(
sysDict
.
getParent
().
getId
()));
List
<
SysDictTree
>
list
=
sysDictTreeService
.
findList
(
sysDict
);
if
(
list
.
size
()
>
0
){
sysDict
.
setSort
(
list
.
get
(
list
.
size
()-
1
).
getSort
());
if
(
sysDict
.
getSort
()
!=
null
){
sysDict
.
setSort
(
sysDict
.
getSort
()
+
30
);
}
}
}
}
if
(
sysDict
.
getSort
()
==
null
){
sysDict
.
setSort
(
30
);
}
model
.
addAttribute
(
"sysDict"
,
sysDict
);
return
"modules/sys/sysDictTreeForm"
;
}
/**
* 保存数据字典
*/
//@RequiresPermissions(value={"sys:sysDict:add","sys:sysDict:edit"},logical=Logical.OR)
@RequestMapping
(
value
=
"save"
)
public
String
save
(
SysDictTree
sysDict
,
Model
model
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfigTree/?repage"
;
}
if
(!
beanValidator
(
model
,
sysDict
)){
return
form
(
sysDict
,
model
);
}
sysDictTreeService
.
save
(
sysDict
);
addMessage
(
redirectAttributes
,
"保存数据字典成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysDictTree/?repage"
;
}
/**
* 删除数据字典
*/
//@RequiresPermissions("sys:sysDict:del")
@RequestMapping
(
value
=
"delete"
)
public
String
delete
(
SysDictTree
sysDict
,
RedirectAttributes
redirectAttributes
)
{
if
(
sysConfigService
.
isDemoMode
()){
addMessage
(
redirectAttributes
,
sysConfigService
.
isDemoModeDescription
());
return
"redirect:"
+
adminPath
+
"/sys/sysConfigTree/?repage"
;
}
sysDictTreeService
.
delete
(
sysDict
);
addMessage
(
redirectAttributes
,
"删除数据字典成功"
);
return
"redirect:"
+
Global
.
getAdminPath
()+
"/sys/sysDictTree/?repage"
;
}
//@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
<
SysDictTree
>
list
=
sysDictTreeService
.
findList
(
new
SysDictTree
());
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++){
SysDictTree
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
;
}
}
\ No newline at end of file
Prev
1
…
15
16
17
18
19
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